[WebRTC][Camera] Start camera preview after decoder initialization finished 62/320462/7
authorMichal Jurkiewicz <m.jurkiewicz@samsung.com>
Wed, 13 Nov 2024 14:03:20 +0000 (15:03 +0100)
committerBot Blink <blinkbot@samsung.com>
Fri, 15 Nov 2024 12:50:06 +0000 (12:50 +0000)
[Problem]
First few camera preview frames are dropped for remote camera,
resulting in camera preview stop-start sequence due to non-keyframe
being provided as first frame for decoding after initialization.

[Cause]
It is possible that camera preview frames will
be returned during decoder initialization. In such case, they will
be dropped.

[Solution]
Start camera preview after decoder initialization is completed
to prevent dropping preview frames.

Bug: https://jira-eu.sec.samsung.net/browse/VDWASM-1921
Change-Id: I4c58148391bb8e443d5bc9187f548143144c562f
Signed-off-by: Michal Jurkiewicz <m.jurkiewicz@samsung.com>
media/capture/video/tizen/video_capture_device_tizen_tv.cc

index b349fce669a383988eefe6b38854c6f484123886..e39c55cc3fbcb221082899c9cba9f6f9aa0ee5a8 100644 (file)
@@ -293,11 +293,13 @@ void VideoCaptureDeviceTizenTv::Impl::AllocateAndStart(
   client_ = std::move(client);
 
   CAMERA_CHECK_AND_RETURN(ConfigureCamera());
-  CAMERA_CHECK_AND_RETURN(StartCameraPreview());
 
-  TIZEN_MEDIA_LOG(INFO) << "Camera started";
-
-  if (IsEncodedCameraFormat(camera_format_) && !PrepareVideoDecoder()) {
+  if (!IsEncodedCameraFormat(camera_format_)) {
+    // For non-encoded formats, start camera preview immediately.
+    // For encoded formats, start camera preview after decoder completes
+    // initialization.
+    CAMERA_CHECK_AND_RETURN(StartCameraPreview());
+  } else if (!PrepareVideoDecoder()) {
     client_->OnError(VideoCaptureError::kV4L2VidiocStreamonFailed, FROM_HERE,
                      "Wrong video codec, cannot initialize decoder");
     return;
@@ -402,6 +404,8 @@ DeviceCaptureError VideoCaptureDeviceTizenTv::Impl::ConfigureCamera() {
             "Cannot set preview cb"};
   }
 
+  TIZEN_MEDIA_LOG(INFO) << "Camera configured";
+
   return {VideoCaptureError::kNone, ""};
 }
 
@@ -411,6 +415,8 @@ DeviceCaptureError VideoCaptureDeviceTizenTv::Impl::StartCameraPreview() {
             "Cannot start preview"};
   }
 
+  TIZEN_MEDIA_LOG(INFO) << "Camera started";
+
   return {VideoCaptureError::kNone, ""};
 }
 
@@ -694,10 +700,13 @@ void VideoCaptureDeviceTizenTv::Impl::OnDecoderInitialized(bool success) {
   if (success) {
     TIZEN_MEDIA_LOG(INFO) << "Decoder initialized successfully";
     decoder_state_ = DecoderState::kInitialized;
+    CAMERA_CHECK_AND_RETURN(StartCameraPreview());
   } else {
     TIZEN_MEDIA_LOG(ERROR) << "Decoder error during initialization";
     decoder_state_ = DecoderState::kError;
     decoder_ = nullptr;
+    client_->OnError(VideoCaptureError::kV4L2VidiocStreamonFailed, FROM_HERE,
+                     "Decoder initialization failed");
   }
 }
 
@@ -726,9 +735,7 @@ void VideoCaptureDeviceTizenTv::Impl::UpdateCameraState() {
 
   const bool was_suspended = last_state_ == suspend_resume::State::SUSPENDED;
   const bool is_suspended = new_state == suspend_resume::State::SUSPENDED;
-  if (was_suspended && !is_suspended) {
-    CAMERA_CHECK_AND_RETURN(StartCameraPreview());
-  } else if (!was_suspended && is_suspended) {
+  if (!was_suspended && is_suspended) {
     CAMERA_CHECK_AND_RETURN(StopCameraPreview());
     decoder_state_ = DecoderState::kIdle;
     decoder_.reset();
@@ -736,6 +743,12 @@ void VideoCaptureDeviceTizenTv::Impl::UpdateCameraState() {
   last_state_ = new_state;
 
   if (!IsEncodedCameraFormat(camera_format_)) {
+    if (was_suspended && !is_suspended) {
+      // For non-encoded formats, start camera preview immediately.
+      // For encoded formats, start camera preview after decoder completes
+      // initialization.
+      CAMERA_CHECK_AND_RETURN(StartCameraPreview());
+    }
     return;
   }