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

Side by Side Diff: media/filters/gpu_video_decoder.h

Issue 8686010: <video> decode in hardware! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 MEDIA_FILTERS_GPU_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_GPU_VIDEO_DECODER_H_
7
8 #include <deque>
9 #include <list>
10 #include <map>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/filters.h"
14 #include "media/base/pipeline_status.h"
15 #include "media/base/pts_stream.h"
16 #include "media/video/video_decode_accelerator.h"
17 #include "ui/gfx/size.h"
18
19 class MessageLoop;
20 namespace base {
21 class SharedMemory;
22 }
23
24 namespace media {
25
26 // GPU-accelerated video decoder implementation. Relies on
27 // AcceleratedVideoDecoderMsg_Decode and friends.
28 // All methods internally trampoline to the message_loop passed to the ctor.
29 class MEDIA_EXPORT GpuVideoDecoder
30 : public VideoDecoder,
31 public VideoDecodeAccelerator::Client {
32 public:
33 // Helper interface for specifying factories needed to instantiate a
34 // GpuVideoDecoder.
35 class Factories {
36 public:
37 virtual ~Factories();
38 // Caller owns returned pointer.
39 virtual VideoDecodeAccelerator* CreateVideoDecodeAccelerator(
40 VideoDecodeAccelerator::Profile, VideoDecodeAccelerator::Client*) = 0;
41 // Allocate & delete native textures. Return true on success.
42 virtual bool CreateTextures(int32 count, const gfx::Size& size,
43 std::vector<uint32>* texture_ids) = 0;
44 virtual bool DeleteTexture(uint32 texture_id) = 0;
45 // Allocate & return a shared memory segment. Caller is responsible for
46 // Close()ing the returned pointer.
47 virtual base::SharedMemory* CreateSharedMemory(size_t size) = 0;
48 };
49
50 // Takes ownership of |factories| but not |message_loop|.
51 explicit GpuVideoDecoder(MessageLoop* message_loop,
52 Factories* factories);
53 virtual ~GpuVideoDecoder();
54
55 // Filter implementation.
56 virtual void Stop(const base::Closure& callback) OVERRIDE;
57 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb) OVERRIDE;
58 virtual void Pause(const base::Closure& callback) OVERRIDE;
59 virtual void Flush(const base::Closure& callback) OVERRIDE;
60
61 // VideoDecoder implementation.
62 virtual void Initialize(DemuxerStream* demuxer_stream,
63 const PipelineStatusCB& callback,
64 const StatisticsCallback& stats_callback) OVERRIDE;
65 virtual void Read(const ReadCB& callback) OVERRIDE;
66 virtual const gfx::Size& natural_size() OVERRIDE;
67
68 // VideoDecodeAccelerator::Client implementation.
69 virtual void NotifyInitializeDone();
70 virtual void ProvidePictureBuffers(uint32 count, const gfx::Size& size);
71 virtual void DismissPictureBuffer(int32 id);
72 virtual void PictureReady(const media::Picture& picture);
73 virtual void NotifyEndOfStream();
74 virtual void NotifyEndOfBitstreamBuffer(int32 id);
75 virtual void NotifyFlushDone();
76 virtual void NotifyResetDone();
77 virtual void NotifyError(media::VideoDecodeAccelerator::Error error);
78
79 private:
80 // If no demuxer read is in flight and no bitstream buffers are in the
81 // decoder, kick some off demuxing/decoding.
82 void EnsureDemuxOrDecode();
83
84 // Callback to pass to demuxer_stream_->Read() for receiving encoded bits.
85 void RequestBufferDecode(const scoped_refptr<Buffer>& buffer);
86
87 // Deliver a frame to the client. Because VideoDecoder::Read() promises not
88 // to run its callback before returning, we need an out-of-line helper here.
89 void DeliverFrame(const scoped_refptr<VideoFrame>& frame);
90 void DeliverFrameOutOfLine(const scoped_refptr<VideoFrame>& frame);
91
92 // Indicate the picturebuffer can be reused by the decoder.
93 void ReusePictureBuffer(int64 picture_buffer_id);
94
95 // A shared memory segment and its allocated size.
96 typedef std::pair<base::SharedMemory*, size_t> SHMBuffer;
97
98 // Request a shared-memory segment of at least |min_size| bytes. Will
99 // allocate as necessary. Caller does not own returned pointer.
100 SHMBuffer* GetSHM(size_t min_size);
101 // Return a shared-memory segment to the available pool.
102 void PutSHM(SHMBuffer* shm_buffer);
103
104 PtsStream pts_stream_;
105 StatisticsCallback statistics_callback_;
106
107 // TODO(scherkus): I think this should be calculated by VideoRenderers based
108 // on information provided by VideoDecoders (i.e., aspect ratio).
109 gfx::Size natural_size_;
110
111 // Pointer to the demuxer stream that will feed us compressed buffers.
112 scoped_refptr<DemuxerStream> demuxer_stream_;
113
114 // MessageLoop on which to do fire callbacks and to which trampoline calls to
115 // this class if they arrive on other loops.
116 MessageLoop* message_loop_;
117
118 scoped_ptr<Factories> factories_;
119 // Populated during Initialize() (on success) and unchanged thereafter.
120 scoped_refptr<VideoDecodeAccelerator> vda_;
121
122 // Callbacks that are !is_null() only during their respective operation being
123 // asynchronously executed.
124 ReadCB pending_read_cb_;
125 base::Closure pending_flush_cb_;
126
127 // Status of the decoder.
128 bool flush_in_progress_;
129
130 // Is a demuxer read in flight?
131 bool demuxer_read_in_progress_;
132
133 // Shared-memory buffer pool. Since allocating SHM segments requires a
134 // round-trip to the browser process, we keep allocation out of the
135 // steady-state of the decoder.
136 std::vector<SHMBuffer*> available_shm_segments_;
137
138 // Book-keeping variables.
139 typedef std::pair<SHMBuffer*, scoped_refptr<Buffer> > BufferPair;
140 std::map<int32, BufferPair> bitstream_buffers_in_decoder_;
141 std::map<int32, PictureBuffer> picture_buffers_in_decoder_;
142 // picture_buffer_id and the frame wrapping the corresponding Picture, for
143 // frames that have been decoded but haven't been requested by a Read() yet.
144 std::list<scoped_refptr<VideoFrame> > ready_video_frames_;
145 int64 next_picture_buffer_id_;
146 int64 next_bitstream_buffer_id_;
147
148
149 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder);
150 };
151
152 } // namespace media
153
154 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698