[MM][M47] Fix segment fault with GetUserMedia
authorws29.jung <ws29.jung@samsung.com>
Wed, 18 Nov 2015 01:20:24 +0000 (10:20 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
With Camera capture, new function(OnIncomingCapturedYuvData) is introduced
on M47 and replacing |OnIncomingCapturedVideoFrame| to new function resolve
the segmentation fault problem with GetUserMedia.
Also, using new function does not require allocate buffer on efl(client) side,
so allocating and deallocating functions are removed.

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=14494

Reviewed by: sm.venugopal, sns.park

Change-Id: I86a8ebdd67a177c27feb5193f2c5c45b43ec1041
Signed-off-by: ws29.jung <ws29.jung@samsung.com>
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.cc
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.h

index 9de2489c3efeaf2f4d6087c61b4c49c4ff7b8201..bb5a73970f7f3dc7ce4ea059e1c3250297525f9e 100644 (file)
@@ -205,7 +205,6 @@ void VideoCaptureDeviceTizen::StopAndDeAllocate() {
       base::Bind(&VideoCaptureDeviceTizen::OnStopAndDeAllocate,
                  base::Unretained(this)));
   worker_.Stop();
-  DeAllocateVideoBuffers();
 }
 
 camera_device_e VideoCaptureDeviceTizen::DeviceNameToCameraId(
@@ -232,6 +231,7 @@ std::string VideoCaptureDeviceTizen::GetCameraErrorMessage(int err_code) {
 
 void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
                                                void* data) {
+  CHECK(frame->format == CAMERA_PIXEL_FORMAT_I420);
   VideoCaptureDeviceTizen* self = static_cast<VideoCaptureDeviceTizen*>(data);
   camera_attr_fps_e current_fps =
       static_cast<camera_attr_fps_e>(kTypicalFramerate);
@@ -246,42 +246,22 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
   gfx::Size target_resolution(frame->width, frame->height);
   int target_rotation = (orientation +
       GetCameraOrientation(self->device_name_.id().c_str())) % DEGREE_360;
-  if ((target_rotation / DEGREE_90) & 0x1) {
-    target_resolution.SetSize(frame->height, frame->width);
-    DVLOG(3) << " rotation from:" << orientation
-             << " to: " << target_rotation;
-  }
 
-  uint8* yplane = reinterpret_cast<uint8*>(self->buffer_->data());
-  uint8* uplane = yplane + frame->data.triple_plane.y_size;
-  uint8* vplane = uplane + frame->data.triple_plane.u_size;
   int src_stride_y = frame->width;
   int src_stride_uv = (src_stride_y + 1) / 2;
-  int tgt_stride_y = target_resolution.width();
-  int tgt_stride_uv = (tgt_stride_y + 1) / 2;
-
-  if (0 != libyuv::I420Rotate(
-        frame->data.triple_plane.y, src_stride_y,
-        frame->data.triple_plane.u, src_stride_uv,
-        frame->data.triple_plane.v, src_stride_uv,
-        yplane, tgt_stride_y,
-        uplane, tgt_stride_uv,
-        vplane, tgt_stride_uv,
-        frame->width, frame->height,
-        static_cast<libyuv::RotationMode>(target_rotation))) {
-    LOG(ERROR) << " Error when rotating the video frame";
-  }
   WEBRTC_DEBUG_DUMPFRAME(frame, yplane);
 
-  gfx::Rect rect(target_resolution.width(), target_resolution.height());
-
-  scoped_refptr<VideoFrame> videoframe =
-      VideoFrame::CreateFrame(media::PIXEL_FORMAT_I420, target_resolution,
-                              rect, target_resolution, base::TimeDelta());
-
-  self->client_->OnIncomingCapturedVideoFrame(self->buffer_.Pass(),
-                                              videoframe,
-                                              base::TimeTicks::Now());
+  media::VideoCaptureFormat videocaptureformat;
+  videocaptureformat.frame_size = gfx::Size(frame->width, frame->height);
+  videocaptureformat.frame_rate = static_cast<int>(current_fps);
+  videocaptureformat.pixel_format = media::PIXEL_FORMAT_I420;
+
+  self->client_->OnIncomingCapturedYuvData(
+      reinterpret_cast<uint8*>(frame->data.triple_plane.y),
+      reinterpret_cast<uint8*>(frame->data.triple_plane.u),
+      reinterpret_cast<uint8*>(frame->data.triple_plane.v),
+      src_stride_y, src_stride_uv, src_stride_uv,
+      videocaptureformat, target_rotation, base::TimeTicks::Now());
 }
 
 void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
@@ -367,13 +347,6 @@ void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
       return;
     }
   }
-
-  if (!AllocateVideoBuffers(width, height)) {
-    LOG(ERROR) << "Allocate buffer failed";
-    SetErrorState("Camera internal Error");
-    return;
-  }
-
   state_ = kCapturing;
 
   if (CAMERA_ERROR_NONE != camera_start_preview(camera_)) {
@@ -387,23 +360,11 @@ void VideoCaptureDeviceTizen::OnStopAndDeAllocate() {
 
   camera_stop_preview(camera_);
   camera_destroy(camera_);
-  DeAllocateVideoBuffers();
 
   state_ = kIdle;
   client_.reset();
 }
 
-bool VideoCaptureDeviceTizen::AllocateVideoBuffers(int width, int height) {
-  buffer_ = client_->ReserveOutputBuffer(gfx::Size(width, height),
-                                         media::PIXEL_FORMAT_I420,
-                                         media::PIXEL_STORAGE_GPUMEMORYBUFFER);
-  return (buffer_.get() != NULL);
-}
-
-void VideoCaptureDeviceTizen::DeAllocateVideoBuffers() {
-  /* Nothing to do */
-}
-
 void VideoCaptureDeviceTizen::SetErrorState(const std::string& reason) {
   LOG(ERROR) << "Camera Error: " << reason;
   DCHECK(!worker_.IsRunning() ||
index 3f7390bf667b3bcc86db70529d7fa43cd5e7424e..9461d2211cf3a52345b02accc74d2e0f7787372a 100644 (file)
@@ -51,8 +51,6 @@ class VideoCaptureDeviceTizen : public VideoCaptureDevice {
                           scoped_ptr<Client> client);
   void OnStopAndDeAllocate();
 
-  bool AllocateVideoBuffers(int width, int height);
-  void DeAllocateVideoBuffers();
   void SetErrorState(const std::string& reason);
 
   InternalState state_;