Skip to content

Commit

Permalink
Merge pull request #36 from DolbyIO/bugfix/video_freezing_orientation…
Browse files Browse the repository at this point in the history
…_change

Video freezing when switching orientation from portrait to landscape and vice versa
  • Loading branch information
aravind-raveendran authored Sep 27, 2023
2 parents 5624d85 + 1c2827b commit 4b6bc69
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import DolbyIORTSCore
import Foundation

final class ViewRendererProvider: ObservableObject {
private var rendererDictionary: [UUID: StreamSourceViewRenderer] = [:]

private var rendererDictionary: [String: StreamSourceViewRenderer] = [:]

func renderer(for source: StreamSource) -> StreamSourceViewRenderer {
if let renderer = rendererDictionary[source.id] {
func renderer(for source: StreamSource, isPortait: Bool) -> StreamSourceViewRenderer {
let orientationKey = isPortait ? "Portrait" : "Landscape"
let storageKey = "\(source.id)_\(orientationKey)"
if let renderer = rendererDictionary[storageKey] {
return renderer
} else {
let renderer = StreamSourceViewRenderer(source)
rendererDictionary[source.id] = renderer
rendererDictionary[storageKey] = renderer
return renderer
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/DolbyIORTSUIKit/Private/Views/GridView/GridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct GridView: View {

VideoRendererView(
viewModel: viewModel,
viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource),
viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: maxAllowedSubVideoWidth,
maxHeight: maxAllowedSubVideoHeight,
contentMode: .aspectFit
Expand All @@ -96,7 +96,7 @@ struct GridView: View {
ForEach(viewModel.allVideoViewModels, id: \.streamSource.id) { viewModel in
VideoRendererView(
viewModel: viewModel,
viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource),
viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: .infinity,
maxHeight: availableHeight / CGFloat(rowsCount),
contentMode: .aspectFit
Expand Down
6 changes: 3 additions & 3 deletions Sources/DolbyIORTSUIKit/Private/Views/ListView/ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct ListView: View {
let viewModel = viewModel.primaryVideoViewModel
return VideoRendererView(
viewModel: viewModel,
viewRenderer: mainViewRendererProvider.renderer(for: viewModel.streamSource),
viewRenderer: mainViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: maxAllowedMainVideoSize.width,
maxHeight: maxAllowedMainVideoSize.height,
contentMode: .aspectFit
Expand All @@ -227,7 +227,7 @@ struct ListView: View {

VideoRendererView(
viewModel: viewModel,
viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource),
viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: maxAllowedSubVideoWidth,
maxHeight: maxAllowedSubVideoHeight,
contentMode: .aspectFit
Expand Down Expand Up @@ -257,7 +257,7 @@ struct ListView: View {
ForEach(viewModel.secondaryVideoViewModels, id: \.streamSource.id) { viewModel in
VideoRendererView(
viewModel: viewModel,
viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource),
viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: .infinity,
maxHeight: availableHeight,
contentMode: .aspectFit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct SingleStreamView: View {
@State private var selectedVideoStreamSourceId: UUID
@State private var isShowingSettingsScreen: Bool = false
@State private var isShowingStatsInfoScreen: Bool = false
@State private var deviceOrientation: UIDeviceOrientation = UIDeviceOrientation.portrait

@StateObject private var userInteractionViewModel: UserInteractionViewModel = .init()
@StateObject private var viewRendererProvider: ViewRendererProvider = .init()

Expand Down Expand Up @@ -100,7 +102,7 @@ struct SingleStreamView: View {
let maxAllowedVideoHeight = proxy.size.height
VideoRendererView(
viewModel: videoRendererViewModel,
viewRenderer: viewRendererProvider.renderer(for: videoRendererViewModel.streamSource),
viewRenderer: viewRendererProvider.renderer(for: videoRendererViewModel.streamSource, isPortait: deviceOrientation.isPortrait),
maxWidth: maxAllowedVideoWidth,
maxHeight: maxAllowedVideoHeight,
contentMode: .aspectFit
Expand Down Expand Up @@ -149,6 +151,11 @@ struct SingleStreamView: View {
}
.navigationBarHidden(isShowingDetailPresentation)
}
.onRotate { newOrientation in
if !newOrientation.isFlat && newOrientation.isValidInterfaceOrientation {
deviceOrientation = newOrientation
}
}
}

private func statisticsView() -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public struct StreamingScreen: View {
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden(true)
}
.onAppear {
UIApplication.shared.isIdleTimerDisabled = true
}
.onDisappear {
UIApplication.shared.isIdleTimerDisabled = false
}
}
}

Expand Down

0 comments on commit 4b6bc69

Please sign in to comment.