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 "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 "base/synchronization/lock.h" | |
| 11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 12 #include "media/video/capture/video_capture_device.h" | 13 #include "media/video/capture/video_capture_device.h" |
| 14 #include "media/video/jpeg_decode_accelerator.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class WaitableEvent; | |
| 18 } // namespace base | |
| 13 | 19 |
| 14 namespace content { | 20 namespace content { |
| 15 class VideoCaptureBufferPool; | 21 class VideoCaptureBufferPool; |
| 16 class VideoCaptureController; | 22 class VideoCaptureController; |
| 17 | 23 |
| 24 struct CapturedData { | |
|
wuchengli
2015/04/14 09:41:44
Can this be moved to video_capture_device_client.c
kcwu
2015/04/14 20:02:35
Done.
| |
| 25 uint8* data; | |
| 26 int length; | |
| 27 media::VideoCaptureFormat frame_format; | |
| 28 int rotation; | |
| 29 base::TimeTicks timestamp; | |
| 30 }; | |
| 31 | |
| 32 // TODO(kcwu): convert to class | |
|
wuchengli
2015/04/14 09:41:44
Remove. Make it a class.
kcwu
2015/04/14 20:02:34
Done.
| |
| 33 struct JpegDecodeTask { | |
|
wuchengli
2015/04/14 09:41:44
s/JpegDecodeTask/JpegDecodeData/ is better. A task
kcwu
2015/04/14 20:02:35
Done.
| |
| 34 JpegDecodeTask(); | |
| 35 | |
| 36 base::Lock lock_; | |
| 37 | |
| 38 bool decoding; | |
| 39 | |
| 40 CapturedData captured_data; | |
| 41 | |
| 42 scoped_ptr<base::SharedMemory> in_shared_memory; | |
|
wuchengli
2015/04/14 09:41:44
Need variable comments for JpegDecodeTask and Capt
kcwu
2015/04/16 14:38:27
Done.
| |
| 43 // |in_buffer| is backed by |in_shared_memory|. | |
| 44 scoped_ptr<media::BitstreamBuffer> in_buffer; | |
| 45 | |
| 46 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> out_buffer; | |
| 47 // |out_frame| is backed by |out_buffer|. | |
| 48 scoped_refptr<media::VideoFrame> out_frame; | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(JpegDecodeTask); | |
| 52 }; | |
| 53 | |
| 18 // Receives events from the VideoCaptureDevice and posts them to a |controller_| | 54 // 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 | 55 // 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 | 56 // VideoCaptureController. This is a shallow class meant to convert incoming |
| 21 // frames and holds no significant state. | 57 // frames and holds no significant state. |
| 22 // | 58 // |
| 23 // Methods of this class may be called from any thread, and in practice will | 59 // Methods of this class may be called from any thread if not specified, and in |
| 24 // often be called on some auxiliary thread depending on the platform and the | 60 // practice will often be called on some auxiliary thread depending on the |
| 25 // device type; including, for example, the DirectShow thread on Windows, the | 61 // platform and the device type; including, for example, the DirectShow thread |
| 26 // v4l2_thread on Linux, and the UI thread for tab capture. | 62 // on Windows, the v4l2_thread on Linux, and the UI thread for tab capture. |
| 27 class CONTENT_EXPORT VideoCaptureDeviceClient | 63 class CONTENT_EXPORT VideoCaptureDeviceClient |
| 28 : public media::VideoCaptureDevice::Client { | 64 : public media::VideoCaptureDevice::Client, |
| 65 public media::JpegDecodeAccelerator::Client { | |
| 29 public: | 66 public: |
| 30 VideoCaptureDeviceClient( | 67 VideoCaptureDeviceClient( |
| 31 const base::WeakPtr<VideoCaptureController>& controller, | 68 const base::WeakPtr<VideoCaptureController>& controller, |
| 32 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); | 69 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); |
| 33 ~VideoCaptureDeviceClient() override; | 70 ~VideoCaptureDeviceClient() override; |
| 34 | 71 |
| 35 // VideoCaptureDevice::Client implementation. | 72 // VideoCaptureDevice::Client implementation. |
| 73 bool InitializeJpegDecoder() override; | |
| 36 void OnIncomingCapturedData( | 74 void OnIncomingCapturedData( |
| 37 const uint8* data, | 75 const uint8* data, |
| 38 int length, | 76 int length, |
| 39 const media::VideoCaptureFormat& frame_format, | 77 const media::VideoCaptureFormat& frame_format, |
| 40 int rotation, | 78 int rotation, |
| 41 const base::TimeTicks& timestamp) override; | 79 const base::TimeTicks& timestamp) override; |
| 42 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoFrame::Format format, | 80 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoFrame::Format format, |
| 43 const gfx::Size& size) override; | 81 const gfx::Size& size) override; |
| 44 void OnIncomingCapturedVideoFrame( | 82 void OnIncomingCapturedVideoFrame( |
| 45 const scoped_refptr<Buffer>& buffer, | 83 const scoped_refptr<Buffer>& buffer, |
| 46 const scoped_refptr<media::VideoFrame>& frame, | 84 const scoped_refptr<media::VideoFrame>& frame, |
| 47 const base::TimeTicks& timestamp) override; | 85 const base::TimeTicks& timestamp) override; |
| 48 void OnError(const std::string& reason) override; | 86 void OnError(const std::string& reason) override; |
| 49 void OnLog(const std::string& message) override; | 87 void OnLog(const std::string& message) override; |
| 50 | 88 |
| 89 // JpegDecodeAccelerator::Client implementation. | |
| 90 // These will be called in IO thread. | |
| 91 virtual void VideoFrameReady(int32_t buffer_id) override; | |
| 92 virtual void NotifyError(int32_t buffer_id, | |
| 93 media::JpegDecodeAccelerator::Error error) override; | |
| 94 | |
| 51 private: | 95 private: |
| 96 // TODO(kcwu): better name | |
| 97 void OnIncomingCapturedData2(const CapturedData& captured_data); | |
| 98 bool PrepareJpegDecode(const CapturedData& captured_data, | |
| 99 const scoped_refptr<Buffer> out_buffer); | |
| 100 | |
| 52 // The controller to which we post events. | 101 // The controller to which we post events. |
| 53 const base::WeakPtr<VideoCaptureController> controller_; | 102 const base::WeakPtr<VideoCaptureController> controller_; |
| 54 | 103 |
| 104 bool jpeg_failed_; | |
|
wuchengli
2015/04/14 09:41:44
Remove this. Let's not do fallback now. If a platf
kcwu
2015/04/16 14:38:27
Removed. But still do fallback. Some kind of fallb
| |
| 105 scoped_ptr<media::JpegDecodeAccelerator> jpeg_decoder_; | |
| 106 JpegDecodeTask jpeg_decode_task_; | |
|
wuchengli
2015/04/14 09:41:44
Put all jpeg variables together. Move these beside
kcwu
2015/04/14 20:02:34
Done.
| |
| 107 | |
| 55 // The pool of shared-memory buffers used for capturing. | 108 // The pool of shared-memory buffers used for capturing. |
| 56 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 109 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 57 | 110 |
| 58 media::VideoPixelFormat last_captured_pixel_format_; | 111 media::VideoPixelFormat last_captured_pixel_format_; |
| 59 | 112 |
| 113 int32 next_bitstream_buffer_id_; | |
|
wuchengli
2015/04/14 09:41:44
Better to have jpeg in the name. s/next_bitstream_
kcwu
2015/04/14 20:02:34
Done.
| |
| 114 | |
| 60 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); | 115 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); |
| 61 }; | 116 }; |
| 62 | 117 |
| 63 | 118 |
| 64 } // namespace content | 119 } // namespace content |
| 65 | 120 |
| 66 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 121 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| OLD | NEW |