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

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

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (hide change of base/containers/scoped_ptr_hash_map.h in https://codereview.chromium.org/1099383002… 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_DECODER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_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 // There are two threads involved in this class. Ctor, dtor, Initialize(), and
26 // DecodeCapturedData() are running on one thread (i.e., device thread for
27 // Linux). The decoding responses (JpegDecodeAccelerator::Client functions) run
28 // on IO thread.
29 class CONTENT_EXPORT GpuJpegDecoder
30 : public media::JpegDecodeAccelerator::Client {
31 public:
32 // Return true if JPEG hardware decoding is supported on this device.
mcasas 2015/04/28 00:04:50 s/Return/Returns/ (Comments are descriptive rather
kcwu 2015/04/30 19:25:43 Done.
33 static bool Supported();
34
35 // |device_client| is where we request VideoCaptureDevice::Client::Buffer as
36 // output buffer from and send decoded result to.
37 GpuJpegDecoder(media::VideoCaptureDevice::Client* device_client);
38 ~GpuJpegDecoder();
39
40 // Create and intialize decoder in GPU side. Return false if failed.
41 bool Initialize();
42
43 // Return true if in failed state.
44 bool IsFailed();
45
46 // Decode a JPEG picture. If this class is in failed state,
47 // DecodeCapturedData() will ignore all decoding requests.
48 void DecodeCapturedData(const uint8* data,
49 int length,
50 const media::VideoCaptureFormat& frame_format,
51 int rotation,
52 const base::TimeTicks& timestamp);
53
54 // JpegDecodeAccelerator::Client implementation.
55 // These will be called on IO thread.
56 virtual void VideoFrameReady(int32_t buffer_id) override;
mcasas 2015/04/28 00:04:50 Suggest s/VideoFrameReady/VideoFrameReadyOnIOThrea
kcwu 2015/04/30 19:25:43 These names are inheritance from JpegDecodeAcceler
57 virtual void NotifyError(int32_t buffer_id,
58 media::JpegDecodeAccelerator::Error error) override;
59
60 private:
61 // Fail state indicates to use software decode. See comment in
62 // FallbackToSoftwareDecode for detail.
63 enum FailState { NOT_FAIL, FAILING, FAILED };
64
65 // For keeping parameters of DecodeCapturedData. In case we need to pass them
66 // to software decoder if hardware decoding failed.
67 struct CapturedData {
68 // If accessed inside DecodeCapturedData(), |data| is owned by capturer
69 // (i.e., v4l2 driver on linux). Otherwise, |data| is backed by
70 // |in_shared_memory_|.
71 uint8* data;
72 int length;
73 media::VideoCaptureFormat frame_format;
74 int rotation;
75 base::TimeTicks timestamp;
76 };
77
78 bool IsDecoding();
79 // Check |bitstream_buffer_id| from GPU process is expected.
80 bool IsExpectedDecodeResponse(int32 bitstream_buffer_id);
81 // Current frame decoding is done. Allow DecodeCapturedData() to accept next
82 // frame.
83 void DecodeDone();
84 // Fallback current frame to software decode. Set flag to reject future
85 // upcoming frames.
86 void FallbackToSoftwareDecode();
87
88 // The "customer" of GpuJpegDecoder.
89 media::VideoCaptureDevice::Client* device_client_;
90 // The main working thread.
91 const scoped_refptr<base::MessageLoopProxy> main_task_runner_;
mcasas 2015/04/28 00:04:50 Hmm |main| can have another meaning in the Browser
kcwu 2015/04/30 19:25:43 Done.
92 // The underlying JPEG decode accelerator.
93 scoped_ptr<media::JpegDecodeAccelerator> decoder_;
94
95 // Below fields are protected by |lock_|.
96 base::Lock lock_;
97
98 FailState fail_state_;
99
100 // Keep the captured data from camera. If hardware decode failed, pass this
101 // to software decoder as fallback.
102 CapturedData captured_data_;
103
104 // Next id for |in_buffer_|.
105 int32 next_bitstream_buffer_id_;
106
107 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this.
108 scoped_ptr<base::SharedMemory> in_shared_memory_;
109 // JPEG stream buffer as input to JpegDecodeAccelerator.
110 media::BitstreamBuffer in_buffer_;
111
112 // Buffer to hold decoded output of JPEG decoder.
113 // |out_frame_| is backed by this.
114 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> out_buffer_;
115 // VideoFrame to receive decoded output of JpegDecodeAccelerator.
116 scoped_refptr<media::VideoFrame> out_frame_;
117
118 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder);
119 };
120
121 } // namespace content
122
123 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698