Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the video tile mapping entry when video is removed instead of when video is unbound #179

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
@objcMembers public class DefaultVideoTileController: NSObject, VideoTileController {
private let logger: Logger
private var videoTileMap = [Int: VideoTile]()
private var videoViewToTileMap = [NSValue: Int]()
private var videoViewToTileMap = [NSValue: VideoTile]()
private let videoTileObservers = ConcurrentMutableSet()
private let videoClientController: VideoClientController

Expand Down Expand Up @@ -84,30 +84,33 @@ import UIKit
logger.info(msg: "Binding VideoView to Tile with tileId = \(tileId)")
let videoRenderKey = NSValue(nonretainedObject: videoView)

// If tileId was already bound to another videoRenderView,
// unbind it first to prevent side effects
unbindVideoView(tileId: tileId, removeTile: false)

// Previously there was another video tile that registered with different tileId
if let matchedTileId = videoViewToTileMap[videoRenderKey] {
unbindVideoView(tileId: matchedTileId, removeTile: false)
// Previously there was another videoTile that bounded to the videoView, unbind it
if let matchedTile = videoViewToTileMap[videoRenderKey] {
logger.info(msg: "Override the binding from \(matchedTile.state.tileId) to \(tileId)")
removeVideoViewBindMapping(tileId: matchedTile.state.tileId)
}

let videoTile = videoTileMap[tileId]
videoTile?.bind(videoRenderView: videoView)
videoViewToTileMap[videoRenderKey] = tileId
if let videoTile = videoTileMap[tileId] {
if videoTile.videoRenderView != nil {
// If tileId was already bound to another videoRenderView, unbind it
logger.info(msg: "tileId = \(tileId) already had a different video view. Unbinding the old one and associating the new one")
removeVideoViewBindMapping(tileId: tileId)
}
videoTile.bind(videoRenderView: videoView)
videoViewToTileMap[videoRenderKey] = videoTile
}
}

private func unbindVideoView(tileId: Int, removeTile: Bool) {
let videoTile = removeTile ? videoTileMap.removeValue(forKey: tileId) : videoTileMap[tileId]
let videoRenderKey = NSValue(nonretainedObject: videoTile?.videoRenderView)
videoViewToTileMap.removeValue(forKey: videoRenderKey)
videoTile?.unbind()
private func removeVideoViewBindMapping(tileId: Int) {
videoViewToTileMap.first(where: { $1.state.tileId == tileId }).map { videoRenderKey, videoTile in
videoTile.unbind()
videoViewToTileMap.removeValue(forKey: videoRenderKey)
}
}

public func unbindVideoView(tileId: Int) {
logger.info(msg: "Unbinding VideoView to Tile with tileId = \(tileId)")
unbindVideoView(tileId: tileId, removeTile: true)
removeVideoViewBindMapping(tileId: tileId)
}

private func onAddTrack(tileId: Int,
Expand Down Expand Up @@ -142,6 +145,7 @@ import UIKit
ObserverUtils.forEach(observers: videoTileObservers) { (videoTileObserver: VideoTileObserver) in
videoTileObserver.videoTileDidRemove(tileState: tileState)
}
videoTileMap.removeValue(forKey: tileState.tileId)
}

public func addVideoTileObserver(observer: VideoTileObserver) {
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## Unreleased

### Changed
* **Breaking** Changed SDK behavior to remove the internal video tile mapping entry when video is removed, instead of when video is unbound. This provides better API symmetry so that the video metadata will be added in `videoTileDidAdd(tileState)` callback and removed in `videoTileDidRemove(tileState)` callback.

## [0.12.1] - 2020-11-20

## [0.12.0] - 2020-11-17

### Added
* Added new APIs in `RealtimeControllerFacade` to enable/disable Voice Focus (ML-based noise suppression) and get the on/off status of Voice Focus.
* Added Voice Focus feature in Swift demo app.
Expand All @@ -21,9 +27,7 @@
* **Breaking** Changed behavior to no longer call `videoTileSizeDidChange` when a video is paused to fix a bug where pausing triggered this callback with width=0 and height=0.
* Fixed `videoTileDidAdd` not being called for paused tiles.


### Changed

* **Breaking** Changed default log level of `ConsoleLogger` to INFO.
* The render path has been changed to use `VideoFrame`s for consistency with the send side, this includes:
* **Breaking** `VideoTileController.onReceiveFrame` now takes `VideoFrame?` instead of `CVPixelBuffer?`.
Expand Down