| 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 #include "media/video/jpeg_decode_accelerator.h" |
| 14 |
| 15 namespace base { |
| 16 class WaitableEvent; |
| 17 } // namespace base |
| 13 | 18 |
| 14 namespace content { | 19 namespace content { |
| 15 class VideoCaptureBufferPool; | 20 class VideoCaptureBufferPool; |
| 16 class VideoCaptureController; | 21 class VideoCaptureController; |
| 17 | 22 |
| 23 struct CapturedData { |
| 24 const uint8* data; |
| 25 int length; |
| 26 media::VideoCaptureFormat frame_format; |
| 27 int rotation; |
| 28 base::TimeTicks timestamp; |
| 29 scoped_refptr<media::VideoFrame> frame; |
| 30 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; |
| 31 }; |
| 32 |
| 18 // Receives events from the VideoCaptureDevice and posts them to a |controller_| | 33 // 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 | 34 // 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 | 35 // VideoCaptureController. This is a shallow class meant to convert incoming |
| 21 // frames and holds no significant state. | 36 // frames and holds no significant state. |
| 22 // | 37 // |
| 23 // Methods of this class may be called from any thread, and in practice will | 38 // 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 | 39 // 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 | 40 // device type; including, for example, the DirectShow thread on Windows, the |
| 26 // v4l2_thread on Linux, and the UI thread for tab capture. | 41 // v4l2_thread on Linux, and the UI thread for tab capture. |
| 27 class CONTENT_EXPORT VideoCaptureDeviceClient | 42 class CONTENT_EXPORT VideoCaptureDeviceClient |
| 28 : public media::VideoCaptureDevice::Client { | 43 : public media::VideoCaptureDevice::Client, |
| 44 public media::JpegDecodeAccelerator::Client { |
| 29 public: | 45 public: |
| 30 VideoCaptureDeviceClient( | 46 VideoCaptureDeviceClient( |
| 31 const base::WeakPtr<VideoCaptureController>& controller, | 47 const base::WeakPtr<VideoCaptureController>& controller, |
| 32 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); | 48 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); |
| 33 ~VideoCaptureDeviceClient() override; | 49 ~VideoCaptureDeviceClient() override; |
| 34 | 50 |
| 35 // VideoCaptureDevice::Client implementation. | 51 // VideoCaptureDevice::Client implementation. |
| 52 bool InitializeJpegDecoder() override; |
| 36 void OnIncomingCapturedData( | 53 void OnIncomingCapturedData( |
| 37 const uint8* data, | 54 const uint8* data, |
| 38 int length, | 55 int length, |
| 39 const media::VideoCaptureFormat& frame_format, | 56 const media::VideoCaptureFormat& frame_format, |
| 40 int rotation, | 57 int rotation, |
| 41 const base::TimeTicks& timestamp) override; | 58 const base::TimeTicks& timestamp) override; |
| 42 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoFrame::Format format, | 59 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoFrame::Format format, |
| 43 const gfx::Size& size) override; | 60 const gfx::Size& size) override; |
| 44 void OnIncomingCapturedVideoFrame( | 61 void OnIncomingCapturedVideoFrame( |
| 45 const scoped_refptr<Buffer>& buffer, | 62 const scoped_refptr<Buffer>& buffer, |
| 46 const scoped_refptr<media::VideoFrame>& frame, | 63 const scoped_refptr<media::VideoFrame>& frame, |
| 47 const base::TimeTicks& timestamp) override; | 64 const base::TimeTicks& timestamp) override; |
| 48 void OnError(const std::string& reason) override; | 65 void OnError(const std::string& reason) override; |
| 49 void OnLog(const std::string& message) override; | 66 void OnLog(const std::string& message) override; |
| 50 | 67 |
| 68 // JpegDecodeAccelerator::Client implementation. |
| 69 virtual void VideoFrameReady(int32_t buffer_id) override; |
| 70 virtual void NotifyError(int32_t buffer_id, |
| 71 media::JpegDecodeAccelerator::Error error) override; |
| 72 |
| 51 private: | 73 private: |
| 74 // TODO(kcwu): better name |
| 75 void OnIncomingCapturedData2(const CapturedData& captured_data); |
| 76 void DecodeJpegOnIOThread(media::BitstreamBuffer in_buffer, |
| 77 scoped_refptr<media::VideoFrame> out_frame); |
| 78 |
| 52 // The controller to which we post events. | 79 // The controller to which we post events. |
| 53 const base::WeakPtr<VideoCaptureController> controller_; | 80 const base::WeakPtr<VideoCaptureController> controller_; |
| 54 | 81 |
| 82 scoped_ptr<media::JpegDecodeAccelerator> jpeg_decoder_; |
| 83 // TODO(kcwu): in IOThread |
| 84 std::map<int32_t, CapturedData> jpeg_decode_task_map_; |
| 85 base::WaitableEvent* jpeg_decode_event_; |
| 86 |
| 55 // The pool of shared-memory buffers used for capturing. | 87 // The pool of shared-memory buffers used for capturing. |
| 56 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 88 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 57 | 89 |
| 58 media::VideoPixelFormat last_captured_pixel_format_; | 90 media::VideoPixelFormat last_captured_pixel_format_; |
| 59 | 91 |
| 92 int32 next_bitstream_buffer_id_; |
| 93 |
| 60 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); | 94 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); |
| 61 }; | 95 }; |
| 62 | 96 |
| 63 | 97 |
| 64 } // namespace content | 98 } // namespace content |
| 65 | 99 |
| 66 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ | 100 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_ |
| OLD | NEW |