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 MEDIA_EXPORT Factories { | |
|
scherkus (not reviewing)
2011/12/13 00:36:47
craziness
| |
| 36 public: | |
| 37 virtual ~Factories(); | |
| 38 | |
| 39 // Caller owns returned pointer. | |
| 40 virtual VideoDecodeAccelerator* CreateVideoDecodeAccelerator( | |
| 41 VideoDecodeAccelerator::Profile, VideoDecodeAccelerator::Client*) = 0; | |
| 42 | |
| 43 // Allocate & delete native textures. | |
| 44 virtual bool CreateTextures(int32 count, const gfx::Size& size, | |
| 45 std::vector<uint32>* texture_ids) = 0; | |
| 46 virtual bool DeleteTexture(uint32 texture_id) = 0; | |
| 47 | |
| 48 // Allocate & return a shared memory segment. Caller is responsible for | |
| 49 // Close()ing the returned pointer. | |
| 50 virtual base::SharedMemory* CreateSharedMemory(size_t size) = 0; | |
| 51 }; | |
| 52 | |
| 53 // Takes ownership of |factories| but not |message_loop|. | |
| 54 GpuVideoDecoder(MessageLoop* message_loop, Factories* factories); | |
| 55 virtual ~GpuVideoDecoder(); | |
| 56 | |
| 57 // Filter implementation. | |
| 58 virtual void Stop(const base::Closure& callback) OVERRIDE; | |
| 59 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb) OVERRIDE; | |
| 60 virtual void Pause(const base::Closure& callback) OVERRIDE; | |
| 61 virtual void Flush(const base::Closure& callback) OVERRIDE; | |
| 62 | |
| 63 // VideoDecoder implementation. | |
| 64 virtual void Initialize(DemuxerStream* demuxer_stream, | |
| 65 const PipelineStatusCB& callback, | |
| 66 const StatisticsCallback& stats_callback) OVERRIDE; | |
| 67 virtual void Read(const ReadCB& callback) OVERRIDE; | |
| 68 virtual const gfx::Size& natural_size() OVERRIDE; | |
| 69 | |
| 70 // VideoDecodeAccelerator::Client implementation. | |
| 71 virtual void NotifyInitializeDone() OVERRIDE; | |
| 72 virtual void ProvidePictureBuffers(uint32 count, | |
| 73 const gfx::Size& size) OVERRIDE; | |
| 74 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | |
| 75 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | |
| 76 virtual void NotifyEndOfStream() OVERRIDE; | |
| 77 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | |
| 78 virtual void NotifyFlushDone() OVERRIDE; | |
| 79 virtual void NotifyResetDone() OVERRIDE; | |
| 80 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | |
| 81 | |
| 82 private: | |
| 83 // If no demuxer read is in flight and no bitstream buffers are in the | |
| 84 // decoder, kick some off demuxing/decoding. | |
| 85 void EnsureDemuxOrDecode(); | |
| 86 | |
| 87 // Callback to pass to demuxer_stream_->Read() for receiving encoded bits. | |
| 88 void RequestBufferDecode(const scoped_refptr<Buffer>& buffer); | |
| 89 | |
| 90 // Deliver a frame to the client. Because VideoDecoder::Read() promises not | |
| 91 // to run its callback before returning, we need an out-of-line helper here. | |
| 92 void DeliverFrame(const scoped_refptr<VideoFrame>& frame); | |
| 93 void DeliverFrameOutOfLine(const scoped_refptr<VideoFrame>& frame); | |
| 94 | |
| 95 // Indicate the picturebuffer can be reused by the decoder. | |
| 96 void ReusePictureBuffer(int64 picture_buffer_id); | |
| 97 | |
| 98 // A shared memory segment and its allocated size. | |
| 99 struct SHMBuffer { | |
| 100 SHMBuffer(base::SharedMemory* m, size_t s); | |
| 101 ~SHMBuffer(); | |
| 102 base::SharedMemory* shm; | |
| 103 size_t size; | |
| 104 }; | |
| 105 | |
| 106 // Request a shared-memory segment of at least |min_size| bytes. Will | |
| 107 // allocate as necessary. Caller does not own returned pointer. | |
| 108 SHMBuffer* GetSHM(size_t min_size); | |
| 109 | |
| 110 // Return a shared-memory segment to the available pool. | |
| 111 void PutSHM(SHMBuffer* shm_buffer); | |
| 112 | |
| 113 PtsStream pts_stream_; | |
| 114 StatisticsCallback statistics_callback_; | |
| 115 | |
| 116 // TODO(scherkus): I think this should be calculated by VideoRenderers based | |
| 117 // on information provided by VideoDecoders (i.e., aspect ratio). | |
| 118 gfx::Size natural_size_; | |
| 119 | |
| 120 // Pointer to the demuxer stream that will feed us compressed buffers. | |
| 121 scoped_refptr<DemuxerStream> demuxer_stream_; | |
| 122 | |
| 123 // MessageLoop on which to do fire callbacks and to which trampoline calls to | |
| 124 // this class if they arrive on other loops. | |
| 125 MessageLoop* message_loop_; | |
| 126 | |
| 127 scoped_ptr<Factories> factories_; | |
| 128 | |
| 129 // Populated during Initialize() (on success) and unchanged thereafter. | |
| 130 scoped_refptr<VideoDecodeAccelerator> vda_; | |
| 131 | |
| 132 // Callbacks that are !is_null() only during their respective operation being | |
| 133 // asynchronously executed. | |
| 134 ReadCB pending_read_cb_; | |
| 135 base::Closure pending_flush_cb_; | |
| 136 | |
| 137 // Status of the decoder. | |
| 138 bool flush_in_progress_; | |
| 139 | |
| 140 // Is a demuxer read in flight? | |
| 141 bool demuxer_read_in_progress_; | |
| 142 | |
| 143 // Shared-memory buffer pool. Since allocating SHM segments requires a | |
| 144 // round-trip to the browser process, we keep allocation out of the | |
| 145 // steady-state of the decoder. | |
| 146 std::vector<SHMBuffer*> available_shm_segments_; | |
| 147 | |
| 148 // Book-keeping variables. | |
| 149 struct BufferPair { | |
| 150 BufferPair(SHMBuffer* s, const scoped_refptr<Buffer>& b); | |
| 151 ~BufferPair(); | |
| 152 SHMBuffer* shm_buffer; | |
| 153 scoped_refptr<Buffer> buffer; | |
| 154 }; | |
| 155 std::map<int32, BufferPair> bitstream_buffers_in_decoder_; | |
| 156 std::map<int32, PictureBuffer> picture_buffers_in_decoder_; | |
| 157 | |
| 158 // picture_buffer_id and the frame wrapping the corresponding Picture, for | |
| 159 // frames that have been decoded but haven't been requested by a Read() yet. | |
| 160 std::list<scoped_refptr<VideoFrame> > ready_video_frames_; | |
| 161 int64 next_picture_buffer_id_; | |
| 162 int64 next_bitstream_buffer_id_; | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); | |
| 165 }; | |
| 166 | |
| 167 } // namespace media | |
| 168 | |
| 169 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | |
| OLD | NEW |