[M120 Migration][WebRTC] Get camera rotation from camera instance 82/309682/2
authorhongyanting <yanting.hong@samsung.com>
Mon, 15 Apr 2024 09:34:25 +0000 (17:34 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 16 Apr 2024 22:25:56 +0000 (22:25 +0000)
Patch from:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/292881/

CameraFW has supplied a new interface that could be used to
get camera rotation information in preview callback.
new interface name: camera_attr_get_preview_frame_rotation

refer to:
http://wiki.vd.sec.samsung.net/display/23POG/Camera+FW

Change-Id: I905c9e9a2bff2a834e69da379a80402345aa50dd
Signed-off-by: hongyanting <yanting.hong@samsung.com>
tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.cc
tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.h
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.cc

index 39fdd16..8ac630f 100644 (file)
@@ -41,6 +41,21 @@ constexpr int kMinIso = 50;
 constexpr int kMaxIso = 3200;
 constexpr int kStepIso = 50;
 
+int CameraRotaionToInt(camera_rotation_e rotation) {
+  switch (rotation) {
+    case CAMERA_ROTATION_NONE:
+      return 0;
+    case CAMERA_ROTATION_90:
+      return 90;
+    case CAMERA_ROTATION_180:
+      return 180;
+    case CAMERA_ROTATION_270:
+      return 270;
+  }
+  NOTREACHED();
+  return 0;
+}
+
 // Construct a device id using label or manufacturer (vendor and model) details.
 std::string MakeDeviceUniqueIdForUdevDevice(struct udev_device* device) {
   std::string uuid = device::UdevDeviceGetPropertyValue(device, kFsUUID);
@@ -639,6 +654,22 @@ int CameraHandle::GetOrientation() {
   return orientation;
 }
 
+int CameraHandle::GetCameraRotation() {
+  camera_rotation_e rotation = CAMERA_ROTATION_NONE;
+#if BUILDFLAG(IS_TIZEN_TV)
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
+  int err = CAMERA_ERROR_NONE;
+  if (CAMERA_ERROR_NONE != (err = camera_attr_get_preview_frame_rotation(
+                                camera_handle_, &rotation))) {
+    LOG(ERROR) << "Cannot get camera rotaion, Error:" << GetErrorString(err);
+    return 0;
+  }
+#endif
+#endif
+
+  return CameraRotaionToInt(rotation);
+}
+
 #if BUILDFLAG(IS_TIZEN_TV)
 void CameraHandle::CheckCurrentHandleChange(
     VideoCaptureDeviceDescriptors* device_descriptors) {
index e49d786..9dd0553 100644 (file)
@@ -112,6 +112,7 @@ class CameraHandle final {
   int GetMaxFrameRate(CameraCapability::Resolution) const;
   int GetDeviceCounts();
   int GetOrientation();
+  int GetCameraRotation();
 
 #if BUILDFLAG(IS_TIZEN_TV)
   using GetDevicesInfoCallback =
index 86ea118..b62a9a8 100644 (file)
@@ -136,6 +136,21 @@ const char* CameraPixelFormatToString(camera_pixel_format_e format) {
   return "UNKNOWN";
 }
 
+media::VideoRotation ToVideoRotaion(int rotation) {
+  switch (rotation) {
+    case 0:
+      return media::VIDEO_ROTATION_0;
+    case 90:
+      return media::VIDEO_ROTATION_90;
+    case 180:
+      return media::VIDEO_ROTATION_180;
+    case 270:
+      return media::VIDEO_ROTATION_270;
+  }
+  NOTREACHED();
+  return media::VIDEO_ROTATION_0;
+}
+
 }  // unnamed namespace
 
 namespace media {
@@ -591,6 +606,10 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
   if (self->first_ref_time_.is_null())
     self->first_ref_time_ = now;
 
+  media::VideoFrameMetadata metadata;
+  const auto rotation = self->GetCurrentRotation();
+  metadata.transformation = media::VideoTransformation(rotation);
+
   self->client_->OnIncomingCapturedBufferExt(
       std::move(self->buffer_), videocaptureformat, gfx::ColorSpace(), now,
       now - self->first_ref_time_, gfx::Rect(videocaptureformat.frame_size),
@@ -603,6 +622,7 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
       << "total:" << self->frame_total_
       << " frame_timestamp:" << frame->timestamp << " width:" << frame->width
       << " height:" << frame->height
+      << " rotation:" << media::VideoRotationToString(rotation)
       << " format: " << CameraPixelFormatToString(frame->format)
       << " size: " << frame_size.ToString();
 }
@@ -642,7 +662,22 @@ VideoCaptureDeviceTizen::GetCameraOrientation() {
 }
 
 VideoRotation VideoCaptureDeviceTizen::GetCurrentRotation() const noexcept {
-  NOTIMPLEMENTED();
+// NOTIMPLEMENTED();
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (camera_instance_) {
+    // Three purposes to add rotation into captured frame:
+    // 1. Tv web engine need to keep captured subjects head up. Set camera
+    // rotation into video frame meta data will help to render video layer
+    // in corret orientation.
+    // 2. This rotation value will sent to peer side to trigger the video
+    // rotate in peer device
+    // 3. This rotation will trigger the natrual size changing in
+    // WebMediaPlayerMS then trigger resize event to video element
+    int camera_rotation = camera_instance_->GetCameraRotation();
+    int counterclockwise_camera_rotation = (360 - camera_rotation) % 360;
+    return ToVideoRotaion(counterclockwise_camera_rotation);
+  }
+#endif
   return media::VIDEO_ROTATION_0;
 }