| 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 TextureWrapHelper class used to wrap incoming | |
| 29 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and | |
| 30 // manages the necessary entities to interact with the GPU process, notably an | |
| 31 // offscreen Context to avoid janking the UI thread. | |
| 32 class CONTENT_EXPORT VideoCaptureDeviceClient | 27 class CONTENT_EXPORT VideoCaptureDeviceClient |
| 33 : public media::VideoCaptureDevice::Client { | 28 : public media::VideoCaptureDevice::Client { |
| 34 public: | 29 public: |
| 35 VideoCaptureDeviceClient( | 30 VideoCaptureDeviceClient( |
| 36 const base::WeakPtr<VideoCaptureController>& controller, | 31 const base::WeakPtr<VideoCaptureController>& controller, |
| 37 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, | 32 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner); | |
| 39 ~VideoCaptureDeviceClient() override; | 33 ~VideoCaptureDeviceClient() override; |
| 40 | 34 |
| 41 // VideoCaptureDevice::Client implementation. | 35 // VideoCaptureDevice::Client implementation. |
| 42 void OnIncomingCapturedData(const uint8* data, | 36 void OnIncomingCapturedData(const uint8* data, |
| 43 int length, | 37 int length, |
| 44 const media::VideoCaptureFormat& frame_format, | 38 const media::VideoCaptureFormat& frame_format, |
| 45 int rotation, | 39 int rotation, |
| 46 const base::TimeTicks& timestamp) override; | 40 const base::TimeTicks& timestamp) override; |
| 47 void OnIncomingCapturedYuvData(const uint8* y_data, | 41 void OnIncomingCapturedYuvData(const uint8* y_data, |
| 48 const uint8* u_data, | 42 const uint8* u_data, |
| 49 const uint8* v_data, | 43 const uint8* v_data, |
| 50 size_t y_stride, | 44 size_t y_stride, |
| 51 size_t u_stride, | 45 size_t u_stride, |
| 52 size_t v_stride, | 46 size_t v_stride, |
| 53 const media::VideoCaptureFormat& frame_format, | 47 const media::VideoCaptureFormat& frame_format, |
| 54 int clockwise_rotation, | 48 int clockwise_rotation, |
| 55 const base::TimeTicks& timestamp) override; | 49 const base::TimeTicks& timestamp) override; |
| 56 scoped_ptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format, | 50 scoped_refptr<Buffer> ReserveOutputBuffer( |
| 57 const gfx::Size& dimensions) override; | 51 media::VideoPixelFormat format, |
| 58 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, | 52 const gfx::Size& dimensions) override; |
| 59 const media::VideoCaptureFormat& frame_format, | |
| 60 const base::TimeTicks& timestamp) override; | |
| 61 void OnIncomingCapturedVideoFrame( | 53 void OnIncomingCapturedVideoFrame( |
| 62 scoped_ptr<Buffer> buffer, | 54 const scoped_refptr<Buffer>& buffer, |
| 63 const scoped_refptr<media::VideoFrame>& frame, | 55 const scoped_refptr<media::VideoFrame>& frame, |
| 64 const base::TimeTicks& timestamp) override; | 56 const base::TimeTicks& timestamp) override; |
| 65 void OnError(const std::string& reason) override; | 57 void OnError(const std::string& reason) override; |
| 66 void OnLog(const std::string& message) override; | 58 void OnLog(const std::string& message) override; |
| 67 | 59 |
| 68 private: | 60 private: |
| 69 // The controller to which we post events. | 61 // The controller to which we post events. |
| 70 const base::WeakPtr<VideoCaptureController> controller_; | 62 const base::WeakPtr<VideoCaptureController> controller_; |
| 71 | 63 |
| 72 // The pool of shared-memory buffers used for capturing. | 64 // The pool of shared-memory buffers used for capturing. |
| 73 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 65 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 74 | 66 |
| 75 // Internal delegate for GpuMemoryBuffer-into-VideoFrame wrapping. | |
| 76 class TextureWrapHelper; | |
| 77 scoped_refptr<TextureWrapHelper> texture_wrap_helper_; | |
| 78 // Reference to Capture Thread task runner, where |texture_wrap_helper_| | |
| 79 // lives. | |
| 80 const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | |
| 81 | |
| 82 media::VideoPixelFormat last_captured_pixel_format_; | 67 media::VideoPixelFormat last_captured_pixel_format_; |
| 83 | 68 |
| 84 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); | 69 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); |
| 85 }; | 70 }; |
| 86 | 71 |
| 87 | 72 |
| 88 } // namespace content | 73 } // namespace content |
| 89 | 74 |
| 90 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 75 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| OLD | NEW |