OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/synchronization/waitable_event.h" | |
15 #include "base/threading/thread.h" | |
16 #include "content/common/content_export.h" | |
17 #include "media/video/capture/video_capture_device.h" | |
18 #include "media/video/jpeg_decode_accelerator.h" | |
19 | |
20 namespace base { | |
21 class MessageLoopProxy; | |
22 } | |
23 | |
24 namespace media { | |
25 class VideoFrame; | |
26 } | |
27 | |
28 namespace content { | |
29 | |
30 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes | |
31 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading | |
32 // issues. | |
33 // | |
34 // All public methods, if not specified, are called on the same thread. | |
wuchengli
2015/05/13 15:04:06
s/are/should/.
All public methods except JpegDeco
kcwu
2015/05/25 18:20:34
Done.
| |
35 class CONTENT_EXPORT GpuJpegDecoder | |
36 : public media::JpegDecodeAccelerator::Client, | |
37 public base::NonThreadSafe { | |
38 public: | |
39 typedef base::Callback<void( | |
40 scoped_ptr<media::VideoCaptureDevice::Client::Buffer>, | |
41 const scoped_refptr<media::VideoFrame>&, | |
42 const base::TimeTicks&)> DecodeDoneCB; | |
43 typedef base::Callback<void(const std::string&)> ErrorCB; | |
44 | |
45 // Returns true if JPEG hardware decoding is supported on this device. | |
46 static bool Supported(); | |
47 | |
48 // |decode_done_cb| is called when decode succeed. | |
49 // |error_cb| is called when error. | |
50 GpuJpegDecoder(const DecodeDoneCB& decode_done_cb, const ErrorCB& error_cb); | |
51 ~GpuJpegDecoder(); | |
52 | |
53 // Creates and intializes decoder in GPU side. Returns falses if failed. | |
54 bool Initialize(); | |
55 | |
56 // Decodes a JPEG picture. | |
57 void DecodeCapturedData( | |
58 const uint8* data, | |
59 size_t in_buffer_size, | |
60 const media::VideoCaptureFormat& frame_format, | |
61 const base::TimeTicks& timestamp, | |
62 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | |
63 | |
64 // JpegDecodeAccelerator::Client implementation. | |
65 // These will be called on jpeg thread. | |
66 virtual void VideoFrameReady(int32_t buffer_id) override; | |
67 virtual void NotifyError(int32_t buffer_id, | |
68 media::JpegDecodeAccelerator::Error error) override; | |
69 | |
70 private: | |
71 // Returns true if the decoding of last frame is not finished yet. | |
72 bool IsDecoding(); | |
73 | |
74 void CreateDecoderOnJpegThread(); | |
wuchengli
2015/05/13 15:04:05
s/CreateDecoderOnJpegThread/InitializeOnJpegThread
kcwu
2015/05/25 18:20:35
Done.
| |
75 void DecodeCapturedDataOnJpegThread( | |
76 const uint8* data, | |
77 size_t in_buffer_size, | |
78 const media::VideoCaptureFormat& frame_format, | |
79 const base::TimeTicks& timestamp, | |
80 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | |
81 | |
82 base::Thread jpeg_thread_; | |
83 scoped_refptr<base::MessageLoopProxy> jpeg_thread_proxy_; | |
84 base::WaitableEvent create_event_; | |
85 base::WaitableEvent decode_event_; | |
wuchengli
2015/05/13 15:04:06
|create_event_| is only used once. Let's combine t
kcwu
2015/05/25 18:20:34
Done.
| |
86 | |
87 // The underlying JPEG decode accelerator. | |
88 scoped_ptr<media::JpegDecodeAccelerator> decoder_; | |
89 | |
90 // The callback when decode succeed. | |
wuchengli
2015/05/13 15:04:05
s/succeed/succeeds/. s/callback/callback to run/
kcwu
2015/05/25 18:20:35
Done.
| |
91 DecodeDoneCB decode_done_cb_; | |
92 | |
93 // The callback when error. | |
wuchengli
2015/05/13 15:04:05
s/callback/callback to run/. s/error/an error occu
kcwu
2015/05/25 18:20:35
Done.
| |
94 ErrorCB error_cb_; | |
95 | |
96 // The closure of |decode_done_cb_| with bound parameters. | |
97 base::Closure decode_done_closure_; | |
98 | |
99 // Next id for |in_buffer_|. | |
100 int32 next_bitstream_buffer_id_; | |
101 | |
102 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this. | |
103 scoped_ptr<base::SharedMemory> in_shared_memory_; | |
104 | |
105 // JPEG stream buffer as input to JpegDecodeAccelerator. | |
106 media::BitstreamBuffer in_buffer_; | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder); | |
109 }; | |
110 | |
111 } // namespace content | |
112 | |
113 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
OLD | NEW |