From 809a73019836f95385891c2bba5c72b0610ffcb1 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:11:12 +0200 Subject: [PATCH] fix(ios): ensure onBandwidthUpdate is reported only when value change (#4149) * fix(ios): ensure onBandwidthUpdate is reported only when value change * chore: fix PodFile.lock --- examples/basic/ios/Podfile.lock | 24 ++++++++++++------------ ios/Video/RCTVideo.swift | 8 ++++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/basic/ios/Podfile.lock b/examples/basic/ios/Podfile.lock index 5d670dfb..5149fb84 100644 --- a/examples/basic/ios/Podfile.lock +++ b/examples/basic/ios/Podfile.lock @@ -46,9 +46,9 @@ PODS: - FBLazyVector (0.74.5) - fmt (9.1.0) - glog (0.3.5) - - hermes-engine (0.74.3): - - hermes-engine/Pre-built (= 0.74.3) - - hermes-engine/Pre-built (0.74.3) + - hermes-engine (0.74.5): + - hermes-engine/Pre-built (= 0.74.5) + - hermes-engine/Pre-built (0.74.5) - libavif/core (0.11.1) - libavif/libdav1d (0.11.1): - libavif/core @@ -994,7 +994,7 @@ PODS: - React-Mapbuffer (0.74.5): - glog - React-debug - - react-native-video (6.4.5): + - react-native-video (6.5.0): - DoubleConversion - glog - hermes-engine @@ -1008,7 +1008,7 @@ PODS: - React-featureflags - React-graphics - React-ImageManager - - react-native-video/Video (= 6.4.5) + - react-native-video/Video (= 6.5.0) - React-NativeModulesApple - React-RCTFabric - React-rendererdebug @@ -1038,7 +1038,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-video/Video (6.4.5): + - react-native-video/Video (6.5.0): - DoubleConversion - glog - hermes-engine @@ -1290,9 +1290,9 @@ PODS: - React-utils (= 0.74.5) - RNCPicker (2.7.5): - React-Core - - SDWebImage (5.19.2): - - SDWebImage/Core (= 5.19.2) - - SDWebImage/Core (5.19.2) + - SDWebImage (5.19.7): + - SDWebImage/Core (= 5.19.7) + - SDWebImage/Core (5.19.7) - SDWebImageAVIFCoder (0.11.0): - libavif/core (>= 0.11.0) - SDWebImage (~> 5.10) @@ -1531,7 +1531,7 @@ SPEC CHECKSUMS: FBLazyVector: ac12dc084d1c8ec4cc4d7b3cf1b0ebda6dab85af fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f - hermes-engine: 1f547997900dd0752dc0cc0ae6dd16173c49e09b + hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8 libavif: 84bbb62fb232c3018d6f1bab79beea87e35de7b7 libdav1d: 23581a4d8ec811ff171ed5e2e05cd27bad64c39f libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009 @@ -1559,7 +1559,7 @@ SPEC CHECKSUMS: React-jsitracing: c83efb63c8e9e1dff72a3c56e88ae1c530a87795 React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c React-Mapbuffer: dce508662b995ffefd29e278a16b78217039d43d - react-native-video: c5cd8b71116762c5a4ceee7f7961587d99aae8e3 + react-native-video: 9f0b3c888537f9ded698f762f541b13573dd3686 react-native-video-plugin-sample: d3a93b7ad777cad7fa2c30473de75a2635ce5feb React-nativeconfig: f326487bc61eba3f0e328da6efb2711533dcac46 React-NativeModulesApple: d89733f5baed8b9249ca5a8e497d63c550097312 @@ -1585,7 +1585,7 @@ SPEC CHECKSUMS: React-utils: 3f1fcffc14893afb9a7e5b7c736353873cc5fc95 ReactCommon: f79ae672224dc1e6c2d932062176883c98eebd57 RNCPicker: 3e2c37a8328f368ce14da050cdc8231deb5fc9f9 - SDWebImage: dfe95b2466a9823cf9f0c6d01217c06550d7b29a + SDWebImage: 8a6b7b160b4d710e2a22b6900e25301075c34cb3 SDWebImageAVIFCoder: 00310d246aab3232ce77f1d8f0076f8c4b021d90 SDWebImageSVGCoder: 15a300a97ec1c8ac958f009c02220ac0402e936c SDWebImageWebPCoder: e38c0a70396191361d60c092933e22c20d5b1380 diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index a26f7601..345acbf0 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -63,6 +63,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH private var _presentingViewController: UIViewController? private var _startPosition: Float64 = -1 private var _showNotificationControls = false + // Buffer last bitrate value received. Initialized to -2 to ensure -1 (sometimes reported by AVPlayer) is not missed + private var _lastBitrate = -2.0 private var _pictureInPictureEnabled = false { didSet { #if os(iOS) @@ -1662,9 +1664,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH guard let accessLog = (notification.object as? AVPlayerItem)?.accessLog() else { return } - guard let lastEvent = accessLog.events.last else { return } - onVideoBandwidthUpdate?(["bitrate": lastEvent.indicatedBitrate, "target": reactTag]) + if lastEvent.indicatedBitrate != _lastBitrate { + _lastBitrate = lastEvent.indicatedBitrate + onVideoBandwidthUpdate?(["bitrate": _lastBitrate, "target": reactTag]) + } } func handleTracksChange(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<[AVPlayerItemTrack]>) {