| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "media/video/capture/video_capture_device.h" | 12 #include "media/video/capture/video_capture_device.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 class VideoCaptureBufferPool; | 15 class VideoCaptureBufferPool; |
| 16 class VideoCaptureController; | 16 class VideoCaptureController; |
| 17 | 17 |
| 18 // Receives events from the VideoCaptureDevice and posts them to a |controller_| | 18 // Receives events from the VideoCaptureDevice and posts them to a |controller_| |
| 19 // on the IO thread. An instance of this class may safely outlive its target | 19 // on the IO thread. An instance of this class may safely outlive its target |
| 20 // VideoCaptureController. This is a shallow class meant to convert incoming | 20 // VideoCaptureController. This is a shallow class meant to convert incoming |
| 21 // frames and holds no significant state. | 21 // frames and holds no significant state. |
| 22 // | 22 // |
| 23 // Methods of this class may be called from any thread, and in practice will | 23 // Methods of this class may be called from any thread, and in practice will |
| 24 // often be called on some auxiliary thread depending on the platform and the | 24 // often be called on some auxiliary thread depending on the platform and the |
| 25 // device type; including, for example, the DirectShow thread on Windows, the | 25 // device type; including, for example, the DirectShow thread on Windows, the |
| 26 // v4l2_thread on Linux, and the UI thread for tab capture. | 26 // v4l2_thread on Linux, and the UI thread for tab capture. |
| 27 // |
| 28 // It has an internal ref counted TextureWrapperDelegate class used to wrap |
| 29 // incoming GpuMemoryBuffers into Texture backed Videoframes. This class creates |
| 30 // and manages the necessary interactions with the GPU process, notably an |
| 31 // offscreen Context to avoid janking the UI thread. This delegate is also |
| 32 // needed since the frame producer owns VideoCaptureDeviceClient, but this needs |
| 33 // to launch PostTask()s to the delegate. |
| 27 class CONTENT_EXPORT VideoCaptureDeviceClient | 34 class CONTENT_EXPORT VideoCaptureDeviceClient |
| 28 : public media::VideoCaptureDevice::Client { | 35 : public media::VideoCaptureDevice::Client { |
| 29 public: | 36 public: |
| 30 VideoCaptureDeviceClient( | 37 VideoCaptureDeviceClient( |
| 31 const base::WeakPtr<VideoCaptureController>& controller, | 38 const base::WeakPtr<VideoCaptureController>& controller, |
| 32 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); | 39 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, |
| 40 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner, |
| 41 const media::VideoCaptureFormat& capture_format); |
| 33 ~VideoCaptureDeviceClient() override; | 42 ~VideoCaptureDeviceClient() override; |
| 34 | 43 |
| 35 // VideoCaptureDevice::Client implementation. | 44 // VideoCaptureDevice::Client implementation. |
| 36 void OnIncomingCapturedData(const uint8* data, | 45 void OnIncomingCapturedData(const uint8* data, |
| 37 int length, | 46 int length, |
| 38 const media::VideoCaptureFormat& frame_format, | 47 const media::VideoCaptureFormat& frame_format, |
| 39 int rotation, | 48 int rotation, |
| 40 const base::TimeTicks& timestamp) override; | 49 const base::TimeTicks& timestamp) override; |
| 41 void OnIncomingCapturedYuvData(const uint8* y_data, | 50 void OnIncomingCapturedYuvData(const uint8* y_data, |
| 42 const uint8* u_data, | 51 const uint8* u_data, |
| 43 const uint8* v_data, | 52 const uint8* v_data, |
| 44 size_t y_stride, | 53 size_t y_stride, |
| 45 size_t u_stride, | 54 size_t u_stride, |
| 46 size_t v_stride, | 55 size_t v_stride, |
| 47 const media::VideoCaptureFormat& frame_format, | 56 const media::VideoCaptureFormat& frame_format, |
| 48 int clockwise_rotation, | 57 int clockwise_rotation, |
| 49 const base::TimeTicks& timestamp) override; | 58 const base::TimeTicks& timestamp) override; |
| 50 scoped_refptr<Buffer> ReserveOutputBuffer( | 59 scoped_refptr<Buffer> ReserveOutputBuffer( |
| 51 media::VideoPixelFormat format, | 60 media::VideoPixelFormat format, |
| 52 const gfx::Size& dimensions) override; | 61 const gfx::Size& dimensions) override; |
| 62 void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, |
| 63 const media::VideoCaptureFormat& frame_format, |
| 64 const base::TimeTicks& timestamp) override; |
| 53 void OnIncomingCapturedVideoFrame( | 65 void OnIncomingCapturedVideoFrame( |
| 54 const scoped_refptr<Buffer>& buffer, | 66 const scoped_refptr<Buffer>& buffer, |
| 55 const scoped_refptr<media::VideoFrame>& frame, | 67 const scoped_refptr<media::VideoFrame>& frame, |
| 56 const base::TimeTicks& timestamp) override; | 68 const base::TimeTicks& timestamp) override; |
| 57 void OnError(const std::string& reason) override; | 69 void OnError(const std::string& reason) override; |
| 58 void OnLog(const std::string& message) override; | 70 void OnLog(const std::string& message) override; |
| 59 | 71 |
| 60 private: | 72 private: |
| 61 // The controller to which we post events. | 73 // The controller to which we post events. |
| 62 const base::WeakPtr<VideoCaptureController> controller_; | 74 const base::WeakPtr<VideoCaptureController> controller_; |
| 63 | 75 |
| 64 // The pool of shared-memory buffers used for capturing. | 76 // The pool of shared-memory buffers used for capturing. |
| 65 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 77 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 66 | 78 |
| 79 // Internal delegate for GpuMemoryBuffer-into-VideoFrame wrapping. Created if |
| 80 // |capture_format| on constructor specifies PIXEL_FORMAT_GPUMEMORYBUFFER. |
| 81 class TextureWrapperDelegate; |
| 82 scoped_refptr<TextureWrapperDelegate> wrapper_delegate_; |
| 83 // Reference to Capture Thread task runner, where |wrapper_delegate_| lives. |
| 84 const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
| 85 |
| 67 media::VideoPixelFormat last_captured_pixel_format_; | 86 media::VideoPixelFormat last_captured_pixel_format_; |
| 68 | 87 |
| 69 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); | 88 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); |
| 70 }; | 89 }; |
| 71 | 90 |
| 72 | 91 |
| 73 } // namespace content | 92 } // namespace content |
| 74 | 93 |
| 75 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 94 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| OLD | NEW |