Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: content/browser/renderer_host/gpu_jpeg_decode_accelerator_adapter.h

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_
wuchengli 2015/04/21 06:05:37 I think the name GpuJpegDecoder is better. It's mo
kcwu 2015/04/22 14:43:33 Done.
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 VideoCaptureDevice::Client. It takes
21 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading
22 // issues. If decoding fails, it will fallback to software decode for current
23 // frame and reject upcoming frames.
24 //
25 // This class is created, destroyed, and mainly accessed on device thread. The
wuchengli 2015/04/21 06:05:37 Device thread only applies for Linux. s/thread/thr
kcwu 2015/04/22 14:43:33 I rewrote the comment and removed the confusing se
26 // decoding responses (JpegDecodeAccelerator::Client) are on IO thread. Since
wuchengli 2015/04/21 06:05:37 s/Client/Client functions/. s/are on/are run on/
kcwu 2015/04/22 14:43:33 Done.
27 // it only decodes a frame at a time, the access is almost mutual exclusive:
wuchengli 2015/04/21 06:05:37 The access of what? almost? If it is "almost", it
kcwu 2015/04/22 14:43:33 I rewrote the comment and removed the confusing se
28 // device thread can only access members if IsDecoding() is false. IO thread
29 // can only access if 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
wuchengli 2015/04/21 06:05:37 Add "True if JPEG hardware decoding is supported o
kcwu 2015/04/22 14:43:34 Done.
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();
wuchengli 2015/04/21 06:05:37 add a blank line
kcwu 2015/04/22 14:43:34 Done.
46 // Return true if in failed state. If so, the caller,
47 // VideoCaptureDevice::Client, should do software decoding by itself.
wuchengli 2015/04/21 06:05:37 What the caller actually does shouldn't be here. Y
kcwu 2015/04/22 14:43:34 Remove that sentence and explain DecodeCaptureData
48 bool IsFailed();
49
50 // Decode JPEG stream. Parameters are modeled after
wuchengli 2015/04/21 06:05:37 s/JPEG stream/a JPEG picture/. stream sounds like
kcwu 2015/04/22 14:43:33 Done.
51 // VideoCaptureDeviceClient::OnIncomingCapturedData.
wuchengli 2015/04/21 06:05:37 Doesn't need to explain what this modeled from. Re
kcwu 2015/04/22 14:43:33 Done.
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.
wuchengli 2015/04/21 06:05:37 s/in/on/
kcwu 2015/04/22 14:43:33 Done.
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 indicates to use software decode. See comment in
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 // If accessed inside DecodeCapturedData(), |data| is owned by capturer
73 // (i.e., v4l2 driver on linux). Otherwise, |data| is backed by
74 // |in_shared_memory_|.
75 uint8* data;
76 int length;
77 media::VideoCaptureFormat frame_format;
78 int rotation;
79 base::TimeTicks timestamp;
80 };
81
82 bool IsDecoding();
83 // Check |bitstream_buffer_id| from GPU process is expected.
84 bool IsExpectedDecodeResponse(int32 bitstream_buffer_id);
85 // Current frame decoding is done. Allow DecodeCapturedData() to accept next
86 // frame.
87 void DecodeDone();
88 // Fallback current frame to software decode. Set flag to reject future
89 // upcoming frames.
90 void FallbackToSoftwareDecode();
wuchengli 2015/04/21 06:05:37 Fallback should be decided by the caller, not this
kcwu 2015/04/22 14:43:33 How about modify the name to NotifyClientDecodeFai
91
92 // The "customer" of GpuJpegDecodeAcceleratorAdapter.
93 media::VideoCaptureDevice::Client* device_client_;
94 // The main working thread. Used for DCHECK current thread.
95 scoped_refptr<base::MessageLoopProxy> device_thread_;
wuchengli 2015/04/21 06:05:37 Change the name. device thread only applies for Li
kcwu 2015/04/22 14:43:34 Done.
96 // All decoding requests are sent to |decoder_|.
wuchengli 2015/04/21 06:05:37 Add "The underlying JPEG decode accelerator."
kcwu 2015/04/22 14:43:34 Done.
97 scoped_ptr<media::JpegDecodeAccelerator> decoder_;
98
99 // Below fields are protected by |lock_|.
100 base::Lock lock_;
101
102 FailState fail_state_;
103
104 // Keep the captured data from camera. If hardware decode failed, pass this
105 // to software decoder as fallback.
106 CapturedData captured_data_;
107
108 // Next id for |in_buffer_|.
109 int32 next_bitstream_buffer_id_;
110
111 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this.
112 scoped_ptr<base::SharedMemory> in_shared_memory_;
113 // JPEG stream buffer as input to JpegDecodeAccelerator.
114 media::BitstreamBuffer in_buffer_;
115
116 // Buffer to hold decoded output of JPEG decoder.
117 // |out_frame_| is backed by this.
118 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> out_buffer_;
119 // VideoFrame to receive decoded output of JpegDecodeAccelerator.
120 scoped_refptr<media::VideoFrame> out_frame_;
121
122 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecodeAcceleratorAdapter);
123 };
124
125 } // namespace content
126
127 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_ACCELERATOR_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698