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/single_thread_task_runner.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 media { | |
21 class VideoFrame; | |
22 } | |
23 | |
24 namespace content { | |
25 | |
26 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes | |
27 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading | |
28 // issues. | |
29 // | |
30 // All public methods except JpegDecodeAccelerator::Client ones should be called | |
31 // on the same thread. They are trampolined to an internal JPEG thread. | |
32 // JpegDecodeAccelerator::Client methods also run on the JPEG thread. | |
33 class CONTENT_EXPORT GpuJpegDecoder | |
34 : public media::JpegDecodeAccelerator::Client, | |
35 public base::NonThreadSafe { | |
36 public: | |
37 typedef base::Callback<void( | |
38 scoped_ptr<media::VideoCaptureDevice::Client::Buffer>, | |
39 const scoped_refptr<media::VideoFrame>&, | |
40 const base::TimeTicks&)> DecodeDoneCB; | |
41 typedef base::Callback<void(const std::string&)> ErrorCB; | |
42 | |
43 // Returns true if JPEG hardware decoding is supported on this device. | |
44 static bool Supported(); | |
45 | |
46 // |decode_done_cb| is called when decode succeed. | |
47 // |error_cb| is called when error. | |
48 GpuJpegDecoder(const DecodeDoneCB& decode_done_cb, const ErrorCB& error_cb); | |
49 ~GpuJpegDecoder(); | |
50 | |
51 // Creates and intializes decoder in GPU side. Returns falses if failed. | |
52 bool Initialize(); | |
53 | |
54 // Decodes a JPEG picture. | |
55 void DecodeCapturedData( | |
56 const uint8* data, | |
57 size_t in_buffer_size, | |
58 const media::VideoCaptureFormat& frame_format, | |
59 const base::TimeTicks& timestamp, | |
60 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | |
61 | |
62 // JpegDecodeAccelerator::Client implementation. | |
63 // These will be called on jpeg thread. | |
64 virtual void VideoFrameReady(int32_t buffer_id) override; | |
65 virtual void NotifyError(int32_t buffer_id, | |
66 media::JpegDecodeAccelerator::Error error) override; | |
67 | |
68 private: | |
69 // Returns true if the decoding of last frame is not finished yet. | |
70 bool IsDecoding(); | |
71 | |
72 void InitializeOnJpegThread(); | |
73 void DecodeCapturedDataOnJpegThread( | |
74 const uint8* data, | |
75 size_t in_buffer_size, | |
76 const media::VideoCaptureFormat& frame_format, | |
77 const base::TimeTicks& timestamp, | |
78 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer); | |
79 | |
80 base::Thread jpeg_thread_; | |
81 scoped_refptr<base::SingleThreadTaskRunner> jpeg_task_runner_; | |
82 // Event to notify that the task posted to JPEG thread is done. | |
83 base::WaitableEvent jpeg_event_; | |
84 | |
85 // The underlying JPEG decode accelerator. | |
86 scoped_ptr<media::JpegDecodeAccelerator> decoder_; | |
87 | |
88 // The callback to run when decode succeeds. | |
89 DecodeDoneCB decode_done_cb_; | |
mcasas
2015/05/27 18:08:43
const
kcwu
2015/06/02 15:09:56
Done.
| |
90 | |
91 // The callback to run when an error occurs. | |
92 ErrorCB error_cb_; | |
mcasas
2015/05/27 18:08:43
const
kcwu
2015/06/02 15:09:56
Done.
| |
93 | |
94 // The closure of |decode_done_cb_| with bound parameters. | |
95 base::Closure decode_done_closure_; | |
96 | |
97 // Next id for |in_buffer_|. | |
98 int32 next_bitstream_buffer_id_; | |
99 | |
100 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this. | |
101 scoped_ptr<base::SharedMemory> in_shared_memory_; | |
102 | |
103 // JPEG stream buffer as input to JpegDecodeAccelerator. | |
104 media::BitstreamBuffer in_buffer_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder); | |
107 }; | |
108 | |
109 } // namespace content | |
110 | |
111 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
OLD | NEW |