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