Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "media/capture/video/video_capture_device.h" | 17 #include "media/capture/video/video_capture_device.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class VideoCaptureBufferPool; | 20 class ProducerVideoCaptureBufferPool; |
| 21 class VideoCaptureController; | 21 class VideoFrameReceiver; |
| 22 class VideoCaptureGpuJpegDecoder; | 22 class VideoCaptureJpegDecoderFactory; |
| 23 class VideoCaptureJpegDecoder; | |
| 23 | 24 |
| 24 // Receives events from the VideoCaptureDevice and posts them to a |controller_| | 25 // Receives events from the VideoCaptureDevice and posts them to a |receiver_| |
| 25 // on the IO thread. An instance of this class may safely outlive its target | 26 // on the IO thread. An instance of this class may safely outlive its target |
| 26 // VideoCaptureController. This is a shallow class meant to convert incoming | 27 // VideoFrameReceiver. This is a shallow class meant to convert incoming |
| 27 // frames and holds no significant state. | 28 // frames and holds no significant state. |
| 28 // | 29 // |
| 29 // Methods of this class may be called from any thread, and in practice will | 30 // Methods of this class may be called from any thread, and in practice will |
| 30 // often be called on some auxiliary thread depending on the platform and the | 31 // often be called on some auxiliary thread depending on the platform and the |
| 31 // device type; including, for example, the DirectShow thread on Windows, the | 32 // device type; including, for example, the DirectShow thread on Windows, the |
| 32 // v4l2_thread on Linux, and the UI thread for tab capture. | 33 // v4l2_thread on Linux, and the UI thread for tab capture. |
| 33 // | 34 // |
| 34 // It has an internal ref counted TextureWrapHelper class used to wrap incoming | 35 // It has an internal ref counted TextureWrapHelper class used to wrap incoming |
| 35 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and | 36 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and |
| 36 // manages the necessary entities to interact with the GPU process, notably an | 37 // manages the necessary entities to interact with the GPU process, notably an |
| 37 // offscreen Context to avoid janking the UI thread. | 38 // offscreen Context to avoid janking the UI thread. |
| 38 class CONTENT_EXPORT VideoCaptureDeviceClient | 39 class CONTENT_EXPORT VideoCaptureDeviceClient |
| 39 : public media::VideoCaptureDevice::Client, | 40 : public media::VideoCaptureDevice::Client, |
| 40 public base::SupportsWeakPtr<VideoCaptureDeviceClient> { | 41 public base::SupportsWeakPtr<VideoCaptureDeviceClient> { |
| 41 public: | 42 public: |
| 42 VideoCaptureDeviceClient( | 43 VideoCaptureDeviceClient( |
| 43 const base::WeakPtr<VideoCaptureController>& controller, | 44 std::unique_ptr<VideoFrameReceiver> receiver, |
| 44 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); | 45 const scoped_refptr<ProducerVideoCaptureBufferPool>& buffer_pool, |
| 46 std::unique_ptr<VideoCaptureJpegDecoderFactory> jpeg_decoder_factory, | |
| 47 const base::Closure& check_thread_closure); | |
| 45 ~VideoCaptureDeviceClient() override; | 48 ~VideoCaptureDeviceClient() override; |
| 46 | 49 |
| 47 // VideoCaptureDevice::Client implementation. | 50 // VideoCaptureDevice::Client implementation. |
| 48 void OnIncomingCapturedData(const uint8_t* data, | 51 void OnIncomingCapturedData(const uint8_t* data, |
| 49 int length, | 52 int length, |
| 50 const media::VideoCaptureFormat& frame_format, | 53 const media::VideoCaptureFormat& frame_format, |
| 51 int rotation, | 54 int rotation, |
| 52 base::TimeTicks reference_time, | 55 base::TimeTicks reference_time, |
| 53 base::TimeDelta timestamp) override; | 56 base::TimeDelta timestamp) override; |
| 54 std::unique_ptr<Buffer> ReserveOutputBuffer( | 57 std::unique_ptr<Buffer> ReserveOutputBuffer( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 84 // GpuMemoryBuffers in R_8 format representing I420 planes are reserved. The | 87 // GpuMemoryBuffers in R_8 format representing I420 planes are reserved. The |
| 85 // output buffers stay reserved and mapped for use until the Buffer objects | 88 // output buffers stay reserved and mapped for use until the Buffer objects |
| 86 // are destroyed or returned. | 89 // are destroyed or returned. |
| 87 std::unique_ptr<Buffer> ReserveI420OutputBuffer( | 90 std::unique_ptr<Buffer> ReserveI420OutputBuffer( |
| 88 const gfx::Size& dimensions, | 91 const gfx::Size& dimensions, |
| 89 media::VideoPixelStorage storage, | 92 media::VideoPixelStorage storage, |
| 90 uint8_t** y_plane_data, | 93 uint8_t** y_plane_data, |
| 91 uint8_t** u_plane_data, | 94 uint8_t** u_plane_data, |
| 92 uint8_t** v_plane_data); | 95 uint8_t** v_plane_data); |
| 93 | 96 |
| 94 // The controller to which we post events. | 97 // The receiver to which we post events. |
| 95 const base::WeakPtr<VideoCaptureController> controller_; | 98 std::unique_ptr<VideoFrameReceiver> receiver_; |
|
emircan
2016/09/08 19:57:56
const
chfremer
2016/09/09 00:55:38
Done.
| |
| 96 | 99 |
| 97 // Hardware JPEG decoder. | 100 const std::unique_ptr<VideoCaptureJpegDecoderFactory> jpeg_decoder_factory_; |
| 98 std::unique_ptr<VideoCaptureGpuJpegDecoder> external_jpeg_decoder_; | 101 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_; |
| 99 | 102 |
| 100 // Whether |external_jpeg_decoder_| has been initialized. | 103 // Whether |external_jpeg_decoder_| has been initialized. |
| 101 bool external_jpeg_decoder_initialized_; | 104 bool external_jpeg_decoder_initialized_; |
| 102 | 105 |
| 103 // The pool of shared-memory buffers used for capturing. | 106 // The pool of shared-memory buffers used for capturing. |
| 104 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 107 const scoped_refptr<ProducerVideoCaptureBufferPool> buffer_pool_; |
| 105 | 108 |
| 106 #if DCHECK_IS_ON() | 109 #if DCHECK_IS_ON() |
| 107 // Counter used to track the number of times consecutive capture buffers are | 110 // Counter used to track the number of times consecutive capture buffers are |
| 108 // dropped. | 111 // dropped. |
| 109 int dropped_frame_counter_ = 0; | 112 int dropped_frame_counter_ = 0; |
| 110 | 113 |
| 111 static const int kMaxDroppedFrames = 150; | 114 static const int kMaxDroppedFrames = 150; |
| 112 #endif // DCHECK_IS_ON() | 115 #endif // DCHECK_IS_ON() |
| 113 | 116 |
| 114 // Indication to the Client to copy-transform the incoming data into | 117 // Indication to the Client to copy-transform the incoming data into |
| 115 // GpuMemoryBuffers. | 118 // GpuMemoryBuffers. |
| 116 const bool use_gpu_memory_buffers_; | 119 const bool use_gpu_memory_buffers_; |
| 117 | 120 |
| 118 media::VideoPixelFormat last_captured_pixel_format_; | 121 media::VideoPixelFormat last_captured_pixel_format_; |
| 119 | 122 |
| 120 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); | 123 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 | 126 |
| 124 } // namespace content | 127 } // namespace content |
| 125 | 128 |
| 126 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 129 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| OLD | NEW |