Chromium Code Reviews| OLD | NEW |
|---|---|
| (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. | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
space out methods
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 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, | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
not explicit
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 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() OVERRIDE; | |
| 70 virtual void ProvidePictureBuffers(uint32 count, | |
| 71 const gfx::Size& size) OVERRIDE; | |
| 72 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | |
| 73 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | |
| 74 virtual void NotifyEndOfStream() OVERRIDE; | |
| 75 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | |
| 76 virtual void NotifyFlushDone() OVERRIDE; | |
| 77 virtual void NotifyResetDone() OVERRIDE; | |
| 78 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | |
| 79 | |
| 80 private: | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
add 1 space
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 81 // If no demuxer read is in flight and no bitstream buffers are in the | |
| 82 // decoder, kick some off demuxing/decoding. | |
| 83 void EnsureDemuxOrDecode(); | |
| 84 | |
| 85 // Callback to pass to demuxer_stream_->Read() for receiving encoded bits. | |
| 86 void RequestBufferDecode(const scoped_refptr<Buffer>& buffer); | |
| 87 | |
| 88 // Deliver a frame to the client. Because VideoDecoder::Read() promises not | |
| 89 // to run its callback before returning, we need an out-of-line helper here. | |
| 90 void DeliverFrame(const scoped_refptr<VideoFrame>& frame); | |
| 91 void DeliverFrameOutOfLine(const scoped_refptr<VideoFrame>& frame); | |
| 92 | |
| 93 // Indicate the picturebuffer can be reused by the decoder. | |
| 94 void ReusePictureBuffer(int64 picture_buffer_id); | |
| 95 | |
| 96 // A shared memory segment and its allocated size. | |
| 97 typedef std::pair<base::SharedMemory*, size_t> SHMBuffer; | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
struct SHMBuffer {
base::SharedMemory* shm;
si
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Meh. I honestly don't think the replacement is mu
| |
| 98 | |
| 99 // Request a shared-memory segment of at least |min_size| bytes. Will | |
| 100 // allocate as necessary. Caller does not own returned pointer. | |
| 101 SHMBuffer* GetSHM(size_t min_size); | |
| 102 // Return a shared-memory segment to the available pool. | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
nit: blank lines before // comments
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 103 void PutSHM(SHMBuffer* shm_buffer); | |
| 104 | |
| 105 PtsStream pts_stream_; | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
I'd like to get rid of this class -- did you find
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Not really, although the way I use it is pretty mu
| |
| 106 StatisticsCallback statistics_callback_; | |
| 107 | |
| 108 // TODO(scherkus): I think this should be calculated by VideoRenderers based | |
| 109 // on information provided by VideoDecoders (i.e., aspect ratio). | |
| 110 gfx::Size natural_size_; | |
| 111 | |
| 112 // Pointer to the demuxer stream that will feed us compressed buffers. | |
| 113 scoped_refptr<DemuxerStream> demuxer_stream_; | |
| 114 | |
| 115 // MessageLoop on which to do fire callbacks and to which trampoline calls to | |
| 116 // this class if they arrive on other loops. | |
| 117 MessageLoop* message_loop_; | |
| 118 | |
| 119 scoped_ptr<Factories> factories_; | |
| 120 // Populated during Initialize() (on success) and unchanged thereafter. | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
nit: blank lines before // comments
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 121 scoped_refptr<VideoDecodeAccelerator> vda_; | |
| 122 | |
| 123 // Callbacks that are !is_null() only during their respective operation being | |
| 124 // asynchronously executed. | |
| 125 ReadCB pending_read_cb_; | |
| 126 base::Closure pending_flush_cb_; | |
| 127 | |
| 128 // Status of the decoder. | |
| 129 bool flush_in_progress_; | |
| 130 | |
| 131 // Is a demuxer read in flight? | |
| 132 bool demuxer_read_in_progress_; | |
| 133 | |
| 134 // Shared-memory buffer pool. Since allocating SHM segments requires a | |
| 135 // round-trip to the browser process, we keep allocation out of the | |
| 136 // steady-state of the decoder. | |
| 137 std::vector<SHMBuffer*> available_shm_segments_; | |
| 138 | |
| 139 // Book-keeping variables. | |
| 140 typedef std::pair<SHMBuffer*, scoped_refptr<Buffer> > BufferPair; | |
| 141 std::map<int32, BufferPair> bitstream_buffers_in_decoder_; | |
| 142 std::map<int32, PictureBuffer> picture_buffers_in_decoder_; | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
sanity check: do we need maps or if the count is l
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
picture_buffers_in_decoder_ is always going to hav
| |
| 143 // picture_buffer_id and the frame wrapping the corresponding Picture, for | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
nit: blank lines before // comments
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 144 // frames that have been decoded but haven't been requested by a Read() yet. | |
| 145 std::list<scoped_refptr<VideoFrame> > ready_video_frames_; | |
| 146 int64 next_picture_buffer_id_; | |
| 147 int64 next_bitstream_buffer_id_; | |
| 148 | |
| 149 | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
remove extra line
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
| 150 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); | |
| 151 }; | |
| 152 | |
| 153 } // namespace media | |
| 154 | |
| 155 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | |
| OLD | NEW |