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_ACCELERATOR_ADAPTER_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_ACCELERATOR_ADAPTER_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "content/common/content_export.h" | |
11 #include "media/video/capture/video_capture_device.h" | |
12 #include "media/video/jpeg_decode_accelerator.h" | |
13 | |
14 namespace base { | |
15 class MessageLoopProxy; | |
16 } | |
17 | |
18 namespace content { | |
19 | |
20 // Adapter to GpuJpegDecodeAccelerator for VideoDeviceDevice::Client. It takes | |
mcasas
2015/04/16 23:55:14
s/VideoDeviceDevice/VideoCaptureDevice/
kcwu
2015/04/20 17:48:00
Done.
| |
21 // care GpuJpegDecodeAccelerator creation, shared memory, and thread issues. | |
mcasas
2015/04/16 23:55:14
"care of"
"threading issues"
kcwu
2015/04/20 17:48:00
Done.
| |
22 // If decoding failed, it will fallback to software decode for current frame | |
mcasas
2015/04/16 23:55:14
s/failed/fails/
kcwu
2015/04/20 17:48:00
Done.
| |
23 // and reject upcoming frames. | |
24 // | |
25 // This class is mainly accessed by device thread. The decoding responses | |
mcasas
2015/04/16 23:55:14
Please also mention that it's created and destroye
kcwu
2015/04/20 17:48:00
Done.
| |
26 // (JpegDecodeAccelerator::Client) are on IO thread. Since it only decodes a | |
27 // frame at a time, the access is almost mutual exclusive: device thread can | |
28 // only access members if IsDecoding() is false. IO thread can only access if | |
29 // IsDecoding() is true. | |
30 class CONTENT_EXPORT GpuJpegDecodeAcceleratorAdapter | |
31 : public media::JpegDecodeAccelerator::Client { | |
32 public: | |
33 // A lightweight check for caller to avoid IPC latency for known unsupported | |
34 // platform. Initialize() can do the real platform supporting check but it | |
35 // requires an IPC. | |
36 static bool Supported(); | |
37 | |
38 // |device_client| is where we request VideoCaptureDevice::Client::Buffer as | |
39 // output buffer from and send decoded result to. | |
40 GpuJpegDecodeAcceleratorAdapter( | |
41 media::VideoCaptureDevice::Client* device_client); | |
42 ~GpuJpegDecodeAcceleratorAdapter(); | |
43 | |
44 // Create and intialize decoder in GPU side. Return false if failed. | |
45 bool Initialize(); | |
46 // Return true if in failed state. If so, the caller, | |
47 // VideoCaptureDevice::Client, should do software decoding by itself. | |
48 bool IsFailed(); | |
49 | |
50 // Decode JPEG stream. Parameters are modeled after | |
51 // VideoCaptureDeviceClient::OnIncomingCapturedData. | |
52 void DecodeCapturedData(const uint8* data, | |
53 int length, | |
54 const media::VideoCaptureFormat& frame_format, | |
55 int rotation, | |
56 const base::TimeTicks& timestamp); | |
57 | |
58 // JpegDecodeAccelerator::Client implementation. | |
59 // These will be called in IO thread. | |
60 virtual void VideoFrameReady(int32_t buffer_id) override; | |
61 virtual void NotifyError(int32_t buffer_id, | |
62 media::JpegDecodeAccelerator::Error error) override; | |
63 | |
64 private: | |
65 // Fail state indicats to use software decode. See comment in | |
mcasas
2015/04/16 23:55:14
s/indicats/indicates/
kcwu
2015/04/20 17:48:00
Done.
| |
66 // FallbackToSoftwareDecode for detail. | |
67 enum FailState { NOT_FAIL, FAILING, FAILED }; | |
68 | |
69 // For keeping parameters of DecodeCapturedData. In case we need to pass them | |
70 // to software decoder if hardware decoding failed. | |
71 struct CapturedData { | |
72 uint8* data; | |
73 int length; | |
74 media::VideoCaptureFormat frame_format; | |
75 int rotation; | |
76 base::TimeTicks timestamp; | |
77 }; | |
78 | |
79 bool IsDecoding(); | |
80 // Check |bitstream_buffer_id| from GPU process is expected. | |
81 bool IsExpectedDecodeResponse(int32 bitstream_buffer_id); | |
82 // Current frame decoding is done. Allow DecodeCapturedData() to accept next | |
83 // frame. | |
84 void DecodeDone(); | |
85 // Fallback current frame to software decode. Set flag to reject future | |
86 // upcoming frames. | |
87 void FallbackToSoftwareDecode(); | |
mcasas
2015/04/16 23:55:14
I don't think this is really needed: If the curren
kcwu
2015/04/20 17:48:00
That means for certain device or (external) camera
mcasas
2015/04/28 00:04:49
IIUC, the drop-first-frame would be an error condi
kcwu
2015/05/08 14:42:40
Acknowledged.
| |
88 | |
89 // The "customer" of GpuJpegDecodeAcceleratorAdapter. | |
90 media::VideoCaptureDevice::Client* device_client_; | |
91 // The main working thread. Used for DCHECK current thread. | |
92 scoped_refptr<base::MessageLoopProxy> device_thread_; | |
93 // All decoding requests are sent to |decoder_|. | |
94 scoped_ptr<media::JpegDecodeAccelerator> decoder_; | |
95 | |
96 // Below fields are protected by |lock_|. | |
97 base::Lock lock_; | |
98 | |
99 FailState fail_state_; | |
100 | |
101 // Keep the captured data from camera. If hardware decode failed, pass this | |
102 // to software decoder as fallback. | |
103 CapturedData captured_data_; | |
mcasas
2015/04/16 23:55:14
See my comments above, I think we could get rid of
kcwu
2015/05/08 14:42:40
Done.
| |
104 | |
105 // Next id for |in_buffer_|. | |
106 int32 next_bitstream_buffer_id_; | |
107 | |
108 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this. | |
109 scoped_ptr<base::SharedMemory> in_shared_memory_; | |
110 // JPEG stream buffer as input to JpegDecodeAccelerator. | |
111 media::BitstreamBuffer in_buffer_; | |
112 | |
113 // Buffer to hold decoded output of JPEG decoder. | |
114 // |out_frame_| is backed by this. | |
115 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> out_buffer_; | |
116 // VideoFrame to receive decoded output of JpegDecodeAccelerator. | |
117 scoped_refptr<media::VideoFrame> out_frame_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecodeAcceleratorAdapter); | |
120 }; | |
121 | |
122 } // namespace content | |
123 | |
124 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_ACCELERATOR_ADAPTER_H_ | |
OLD | NEW |