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() const = 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 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes |
| 69 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading |
| 70 // issues. |
| 71 // |
| 72 // All public methods except JpegDecodeAccelerator::Client ones should be called |
| 73 // on the same thread. JpegDecodeAccelerator::Client methods should be called on |
| 74 // the IO thread. |
| 75 class CONTENT_EXPORT VideoCaptureGpuJpegDecoder |
| 76 : public VideoCaptureJpegDecoder, |
| 77 public media::JpegDecodeAccelerator::Client, |
| 78 public base::NonThreadSafe, |
| 79 public base::SupportsWeakPtr<VideoCaptureGpuJpegDecoder> { |
| 80 public: |
60 // |decode_done_cb| is called on the IO thread when decode succeed. This can | 81 // |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 | 82 // be on any thread. |decode_done_cb| is never called after |
62 // VideoCaptureGpuJpegDecoder is destroyed. | 83 // VideoCaptureGpuJpegDecoder is destroyed. |
63 explicit VideoCaptureGpuJpegDecoder(const DecodeDoneCB& decode_done_cb); | 84 explicit VideoCaptureGpuJpegDecoder(const DecodeDoneCB& decode_done_cb); |
64 ~VideoCaptureGpuJpegDecoder() override; | 85 ~VideoCaptureGpuJpegDecoder() override; |
65 | 86 |
66 // Creates and intializes decoder asynchronously. | 87 // Implementation of VideoCaptureJpegDecoder: |
67 void Initialize(); | 88 void Initialize() override; |
68 | 89 STATUS GetStatus() const override; |
69 // Returns initialization status. | |
70 STATUS GetStatus() const; | |
71 | |
72 // Decodes a JPEG picture. | |
73 void DecodeCapturedData( | 90 void DecodeCapturedData( |
74 const uint8_t* data, | 91 const uint8_t* data, |
75 size_t in_buffer_size, | 92 size_t in_buffer_size, |
76 const media::VideoCaptureFormat& frame_format, | 93 const media::VideoCaptureFormat& frame_format, |
77 base::TimeTicks reference_time, | 94 base::TimeTicks reference_time, |
78 base::TimeDelta timestamp, | 95 base::TimeDelta timestamp, |
79 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | 96 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer) |
| 97 override; |
80 | 98 |
81 // JpegDecodeAccelerator::Client implementation. | 99 // JpegDecodeAccelerator::Client implementation. |
82 // These will be called on IO thread. | 100 // These will be called on IO thread. |
83 void VideoFrameReady(int32_t buffer_id) override; | 101 void VideoFrameReady(int32_t buffer_id) override; |
84 void NotifyError(int32_t buffer_id, | 102 void NotifyError(int32_t buffer_id, |
85 media::JpegDecodeAccelerator::Error error) override; | 103 media::JpegDecodeAccelerator::Error error) override; |
86 | 104 |
87 private: | 105 private: |
88 // Initialization helper, to establish GPU channel. | 106 // Initialization helper, to establish GPU channel. |
89 static void EstablishGpuChannelOnUIThread( | 107 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_; | 147 std::unique_ptr<base::SharedMemory> in_shared_memory_; |
130 | 148 |
131 STATUS decoder_status_; | 149 STATUS decoder_status_; |
132 | 150 |
133 DISALLOW_COPY_AND_ASSIGN(VideoCaptureGpuJpegDecoder); | 151 DISALLOW_COPY_AND_ASSIGN(VideoCaptureGpuJpegDecoder); |
134 }; | 152 }; |
135 | 153 |
136 } // namespace content | 154 } // namespace content |
137 | 155 |
138 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ | 156 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_GPU_JPEG_DECODER_H_ |
OLD | NEW |