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_GPU_JPEG_DECODER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 namespace gpu { | 24 namespace gpu { |
| 25 class GpuChannelHost; | 25 class GpuChannelHost; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace media { | 28 namespace media { |
| 29 class VideoFrame; | 29 class VideoFrame; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes | 34 class CONTENT_EXPORT VideoCaptureJpegDecoder { |
| 35 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading | |
| 36 // issues. | |
| 37 // | |
| 38 // All public methods except JpegDecodeAccelerator::Client ones should be called | |
| 39 // on the same thread. JpegDecodeAccelerator::Client methods should be called on | |
| 40 // the IO thread. | |
| 41 class CONTENT_EXPORT VideoCaptureGpuJpegDecoder | |
| 42 : public media::JpegDecodeAccelerator::Client, | |
| 43 public base::NonThreadSafe, | |
| 44 public base::SupportsWeakPtr<VideoCaptureGpuJpegDecoder> { | |
| 45 public: | 35 public: |
| 46 // Enumeration of decoder status. The enumeration is published for clients to | 36 // Enumeration of decoder status. The enumeration is published for clients to |
| 47 // decide the behavior according to STATUS. | 37 // decide the behavior according to STATUS. |
| 48 enum STATUS { | 38 enum STATUS { |
| 49 INIT_PENDING, // Default value while waiting initialization finished. | 39 INIT_PENDING, // Default value while waiting initialization finished. |
| 50 INIT_PASSED, // Initialization succeed. | 40 INIT_PASSED, // Initialization succeed. |
| 51 FAILED, // JPEG decode is not supported, initialization failed, or | 41 FAILED, // JPEG decode is not supported, initialization failed, or |
| 52 // decode error. | 42 // decode error. |
| 53 }; | 43 }; |
| 54 | 44 |
| 55 typedef base::Callback<void( | 45 using DecodeDoneCB = base::Callback<void( |
| 56 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>, | 46 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>, |
| 57 const scoped_refptr<media::VideoFrame>&)> | 47 const scoped_refptr<media::VideoFrame>&)>; |
| 58 DecodeDoneCB; | |
| 59 | 48 |
| 49 virtual ~VideoCaptureJpegDecoder() {} | |
| 50 | |
| 51 // Creates and intializes decoder asynchronously. | |
| 52 virtual void Initialize() = 0; | |
| 53 | |
| 54 // Returns initialization status. | |
| 55 virtual STATUS GetStatus() = 0; | |
| 56 | |
| 57 // Decodes a JPEG picture. | |
| 58 virtual void DecodeCapturedData( | |
| 59 const uint8_t* data, | |
| 60 size_t in_buffer_size, | |
| 61 const media::VideoCaptureFormat& frame_format, | |
| 62 base::TimeTicks reference_time, | |
| 63 base::TimeDelta timestamp, | |
| 64 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | |
| 65 out_buffer) = 0; | |
| 66 }; | |
| 67 | |
| 68 class CONTENT_EXPORT VideoCaptureJpegDecoderFactory { | |
| 69 public: | |
| 70 virtual ~VideoCaptureJpegDecoderFactory() {} | |
| 71 virtual std::unique_ptr<VideoCaptureJpegDecoder> CreateJpegDecoder() = 0; | |
| 72 }; | |
| 73 | |
| 74 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes | |
| 75 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading | |
| 76 // issues. | |
| 77 // | |
| 78 // All public methods except JpegDecodeAccelerator::Client ones should be called | |
| 79 // on the same thread. JpegDecodeAccelerator::Client methods should be called on | |
| 80 // the IO thread. | |
| 81 class CONTENT_EXPORT VideoCaptureGpuJpegDecoder | |
|
mcasas
2016/09/09 22:28:02
Following my recommendation before, this class
sho
chfremer
2016/09/12 18:31:22
Despite this being done a lot in the Chromium code
| |
| 82 : public VideoCaptureJpegDecoder, | |
| 83 public media::JpegDecodeAccelerator::Client, | |
| 84 public base::NonThreadSafe, | |
| 85 public base::SupportsWeakPtr<VideoCaptureGpuJpegDecoder> { | |
| 86 public: | |
|
mcasas
2016/09/09 22:28:02
Also, if we're creating abstract base classes and
chfremer
2016/09/12 18:31:22
Agreed.
As stated in the CL description: "Interfa
| |
| 60 // |decode_done_cb| is called on the IO thread when decode succeed. This can | 87 // |decode_done_cb| is called on the IO thread when decode succeed. This can |
| 61 // be on any thread. |decode_done_cb| is never called after | 88 // be on any thread. |decode_done_cb| is never called after |
| 62 // VideoCaptureGpuJpegDecoder is destroyed. | 89 // VideoCaptureGpuJpegDecoder is destroyed. |
| 63 explicit VideoCaptureGpuJpegDecoder(const DecodeDoneCB& decode_done_cb); | 90 explicit VideoCaptureGpuJpegDecoder(const DecodeDoneCB& decode_done_cb); |
| 64 ~VideoCaptureGpuJpegDecoder() override; | 91 ~VideoCaptureGpuJpegDecoder() override; |
| 65 | 92 |
| 66 // Creates and intializes decoder asynchronously. | 93 // Implementation of VideoCaptureJpegDecoder: |
| 67 void Initialize(); | 94 void Initialize() override; |
| 68 | 95 STATUS GetStatus() override; |
| 69 // Returns initialization status. | |
| 70 STATUS GetStatus() const; | |
| 71 | |
| 72 // Decodes a JPEG picture. | |
| 73 void DecodeCapturedData( | 96 void DecodeCapturedData( |
| 74 const uint8_t* data, | 97 const uint8_t* data, |
| 75 size_t in_buffer_size, | 98 size_t in_buffer_size, |
| 76 const media::VideoCaptureFormat& frame_format, | 99 const media::VideoCaptureFormat& frame_format, |
| 77 base::TimeTicks reference_time, | 100 base::TimeTicks reference_time, |
| 78 base::TimeDelta timestamp, | 101 base::TimeDelta timestamp, |
| 79 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | 102 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer) |
| 103 override; | |
| 80 | 104 |
| 81 // JpegDecodeAccelerator::Client implementation. | 105 // JpegDecodeAccelerator::Client implementation. |
| 82 // These will be called on IO thread. | 106 // These will be called on IO thread. |
| 83 void VideoFrameReady(int32_t buffer_id) override; | 107 void VideoFrameReady(int32_t buffer_id) override; |
| 84 void NotifyError(int32_t buffer_id, | 108 void NotifyError(int32_t buffer_id, |
| 85 media::JpegDecodeAccelerator::Error error) override; | 109 media::JpegDecodeAccelerator::Error error) override; |
| 86 | 110 |
| 87 private: | 111 private: |
| 88 // Initialization helper, to establish GPU channel. | 112 // Initialization helper, to establish GPU channel. |
| 89 static void EstablishGpuChannelOnUIThread( | 113 static void EstablishGpuChannelOnUIThread( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 std::unique_ptr<base::SharedMemory> in_shared_memory_; | 153 std::unique_ptr<base::SharedMemory> in_shared_memory_; |
| 130 | 154 |
| 131 STATUS decoder_status_; | 155 STATUS decoder_status_; |
| 132 | 156 |
| 133 DISALLOW_COPY_AND_ASSIGN(VideoCaptureGpuJpegDecoder); | 157 DISALLOW_COPY_AND_ASSIGN(VideoCaptureGpuJpegDecoder); |
| 134 }; | 158 }; |
| 135 | 159 |
| 136 } // namespace content | 160 } // namespace content |
| 137 | 161 |
| 138 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ | 162 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ |
| OLD | NEW |