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

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

Issue 1132683004: MJPEG acceleration for video capture, browser part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mjpeg-2-gpu
Patch Set: Created 5 years, 6 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 <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread.h"
16 #include "content/common/content_export.h"
17 #include "media/video/capture/video_capture_device.h"
Pawel Osciak 2015/06/22 08:51:23 Would it be enough to declare media::VideoCaptureD
kcwu 2015/06/23 13:58:25 AFAIK, there is no way to forward declare an inner
18 #include "media/video/jpeg_decode_accelerator.h"
19
20 namespace media {
21 class VideoFrame;
22 }
23
24 namespace content {
25 class GpuChannelHost;
26
27 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes
28 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading
29 // issues.
30 //
31 // All public methods except JpegDecodeAccelerator::Client ones should be called
32 // on the same thread.
Pawel Osciak 2015/06/22 08:51:23 Should we mention explicitly that Client methods s
kcwu 2015/06/23 13:58:25 Done.
33 class CONTENT_EXPORT GpuJpegDecoder
Pawel Osciak 2015/06/22 08:51:23 Since this is a Capture-specific class, I'd prefer
kcwu 2015/06/22 09:18:48 I was thinking it's an adapter in the other direct
kcwu 2015/06/23 13:58:25 wucheng has flaky network and we chatted off-line.
34 : public media::JpegDecodeAccelerator::Client,
35 public base::NonThreadSafe,
36 public base::SupportsWeakPtr<GpuJpegDecoder> {
37 public:
38 typedef base::Callback<void(
39 scoped_ptr<media::VideoCaptureDevice::Client::Buffer>,
40 const scoped_refptr<media::VideoFrame>&,
41 const base::TimeTicks&)> DecodeDoneCB;
42 typedef base::Callback<void(const std::string&)> ErrorCB;
43
44 // Returns true if JPEG hardware decoding is supported on this device.
45 static bool Supported();
46
47 // |decode_done_cb| is called when decode succeed.
48 // |error_cb| is called when error.
49 // Both |decode_done_cb| and |error_cb| are called on the IO thread and never
50 // after GpuJpegDecoder is destroyed.
51 GpuJpegDecoder(const DecodeDoneCB& decode_done_cb, const ErrorCB& error_cb);
52 ~GpuJpegDecoder();
53
54 // Creates and intializes decoder asynchronously.
55 void Initialize();
56
57 // Returns true if Initialize is done and it's okay to call
58 // DecodeCapturedData.
59 bool ReadyToDecode() { return decoder_; }
Pawel Osciak 2015/06/22 08:51:23 Should this DCHECK(CalledOnValidThread()) ?
kcwu 2015/06/23 13:58:25 Done.
60
61 // Decodes a JPEG picture.
62 void DecodeCapturedData(
63 const uint8* data,
Pawel Osciak 2015/06/22 08:51:23 s/uint8/uint8_t/ ?
kcwu 2015/06/23 13:58:25 Done.
64 size_t in_buffer_size,
65 const media::VideoCaptureFormat& frame_format,
66 const base::TimeTicks& timestamp,
67 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer);
68
69 // JpegDecodeAccelerator::Client implementation.
70 // These will be called on IO thread.
71 virtual void VideoFrameReady(int32_t buffer_id) override;
72 virtual void NotifyError(int32_t buffer_id,
73 media::JpegDecodeAccelerator::Error error) override;
74
75 private:
76 // Initialization helper, to establish GPU channel
Pawel Osciak 2015/06/22 08:51:23 Nit: dot at the end of sentences please.
kcwu 2015/06/23 13:58:24 Done.
77 static void EstablishGpuChannelOnUIThread(
78 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
79 base::WeakPtr<GpuJpegDecoder> weak_this);
80
81 static void GpuChannelEstablishedOnUIThread(
82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
83 base::WeakPtr<GpuJpegDecoder> weak_this);
84
85 void InitializeDone(scoped_refptr<GpuChannelHost> gpu_channel_host);
86
87 // Returns true if the decoding of last frame is not finished yet.
88 bool IsDecoding_Locked();
89
90 scoped_refptr<GpuChannelHost> gpu_channel_host_;
91
92 // The underlying JPEG decode accelerator.
93 scoped_ptr<media::JpegDecodeAccelerator> decoder_;
94
95 // The callback to run when decode succeeds.
96 const DecodeDoneCB decode_done_cb_;
97
98 // Guards |decode_done_closure_| and |error_cb_|.
99 base::Lock lock_;
Pawel Osciak 2015/06/22 08:51:23 Should we just trampoline NotifyError() and VideoF
kcwu 2015/06/22 09:18:48 They cannot be on the device thread. The device th
100
101 // The callback to run when an error occurs.
102 const ErrorCB error_cb_;
103
104 // The closure of |decode_done_cb_| with bound parameters.
105 base::Closure decode_done_closure_;
106
107 // Next id for |in_buffer_|.
108 int32 next_bitstream_buffer_id_;
109
110 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this.
111 scoped_ptr<base::SharedMemory> in_shared_memory_;
112
113 // JPEG stream buffer as input to JpegDecodeAccelerator.
114 media::BitstreamBuffer in_buffer_;
Pawel Osciak 2015/06/22 08:51:23 Should we say this is the in_buffer_ currently bei
kcwu 2015/06/23 13:58:25 Done. (applied to in_buffer_id_)
115
116 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder);
117 };
118
119 } // namespace content
120
121 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/gpu_jpeg_decoder.cc » ('j') | content/browser/renderer_host/gpu_jpeg_decoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698