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

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: add flag --enable-accelerated-mjpeg-decode 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/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 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.
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 IO 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_Locked();
71
72 void GpuChannelEstablished();
73
74 scoped_refptr<GpuChannelHost> gpu_channel_host_;
75
76 // Event to notify that |gpu_channel_host_| is established.
77 base::WaitableEvent gpu_channel_event_;
78
79 // The underlying JPEG decode accelerator.
80 scoped_ptr<media::JpegDecodeAccelerator> decoder_;
81
82 // The callback to run when decode succeeds.
83 const DecodeDoneCB decode_done_cb_;
84
85 // Guards |decode_done_closure_| and |error_cb_|.
86 base::Lock lock_;
87
88 // The callback to run when an error occurs.
89 const ErrorCB error_cb_;
90
91 // The closure of |decode_done_cb_| with bound parameters.
92 base::Closure decode_done_closure_;
93
94 // Next id for |in_buffer_|.
95 int32 next_bitstream_buffer_id_;
96
97 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this.
98 scoped_ptr<base::SharedMemory> in_shared_memory_;
99
100 // JPEG stream buffer as input to JpegDecodeAccelerator.
101 media::BitstreamBuffer in_buffer_;
102
103 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder);
104 };
105
106 } // namespace content
107
108 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698