Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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_VIDEO_FRAME_STREAM_H_ | |
| 6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "media/base/decryptor.h" | |
| 15 #include "media/base/media_export.h" | |
| 16 #include "media/base/pipeline_status.h" | |
| 17 #include "media/base/video_decoder.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class MessageLoopProxy; | |
| 21 } | |
| 22 | |
| 23 namespace media { | |
| 24 | |
| 25 class DecryptingDemuxerStream; | |
| 26 class DemuxerStream; | |
| 27 class VideoDecoderSelector; | |
| 28 | |
| 29 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded | |
| 30 // VideoFrames to its client (e.g. VideoRendererBase). | |
| 31 class MEDIA_EXPORT VideoFrameStream { | |
| 32 public: | |
| 33 typedef std::list<scoped_refptr<VideoDecoder> > VideoDecoderList; | |
| 34 | |
| 35 // Indicates completion of VideoFrameStream initialization. | |
| 36 typedef base::Callback<void(bool success, bool has_alpha)> InitCB; | |
| 37 | |
| 38 VideoFrameStream(const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
| 39 const SetDecryptorReadyCB& set_decryptor_ready_cb); | |
| 40 | |
| 41 ~VideoFrameStream(); | |
| 42 | |
| 43 // Initializes the VideoFrameStream and returns the initialization result | |
| 44 // through |init_cb|. Note that |init_cb| is always called asynchronously. | |
| 45 void Initialize(const scoped_refptr<DemuxerStream>& stream, | |
| 46 const VideoDecoderList& decoders, | |
| 47 const StatisticsCB& statistics_cb, | |
| 48 const InitCB& init_cb); | |
| 49 | |
| 50 // Reads a decoded VideoFrame and returns it via the |read_cb|. Note that | |
| 51 // |read_cb| is always called asynchronously. This method should only be | |
| 52 // called after initialization has succeeded and must not be called during | |
| 53 // any pending Reset() and/or Stop(). | |
| 54 void ReadFrame(const VideoDecoder::ReadCB& read_cb); | |
|
xhwang
2013/03/21 01:10:17
I didn't use Read() on purpose because in the next
| |
| 55 | |
| 56 // Resets the decoder, flushes all decoded frames and/or internal buffers, | |
| 57 // fires any existing pending read callback and calls |closure| on completion. | |
| 58 // Note that |closure| is always called asynchronously. This method should | |
| 59 // only be called after initialization has succeeded and must not be called | |
| 60 // during any pending Reset() and/or Stop(). | |
| 61 void Reset(const base::Closure& closure); | |
| 62 | |
| 63 // Stops the decoder, fires any existing pending read callback or reset | |
| 64 // callback and calls |closure| on completion. Note that |closure| is always | |
| 65 // called asynchronously. The VideoFrameStream cannot be used anymore after | |
| 66 // it is stopped. This method can be called at any time but not during another | |
| 67 // pending Stop(). | |
| 68 void Stop(const base::Closure& closure); | |
| 69 | |
| 70 private: | |
| 71 enum State { | |
| 72 UNINITIALIZED, | |
| 73 NORMAL, | |
| 74 STOPPED | |
| 75 }; | |
| 76 | |
| 77 // Called when |decoder_selector_| selected the |selected_decoder|. | |
| 78 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream | |
| 79 // is created to help decrypt the encrypted stream. | |
| 80 // Note: |decoder_selector| is passed here to keep the VideoDecoderSelector | |
| 81 // alive until OnDecoderSelected() finishes. | |
| 82 void OnDecoderSelected( | |
| 83 scoped_ptr<VideoDecoderSelector> decoder_selector, | |
| 84 const scoped_refptr<VideoDecoder>& selected_decoder, | |
| 85 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream); | |
| 86 | |
| 87 // Callback for VideoDecoder::Read(). | |
| 88 void OnFrameRead(const VideoDecoder::Status status, | |
| 89 const scoped_refptr<VideoFrame>& frame); | |
| 90 | |
| 91 void ResetDecoder(); | |
| 92 // Callback for VideoDecoder::Reset(). | |
| 93 void OnDecoderReset(); | |
| 94 | |
| 95 void StopDecoder(); | |
| 96 // Callback for VideoDecoder::Stop(). | |
| 97 void OnDecoderStopped(); | |
| 98 | |
| 99 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
| 100 base::WeakPtrFactory<VideoFrameStream> weak_factory_; | |
| 101 base::WeakPtr<VideoFrameStream> weak_this_; | |
| 102 | |
| 103 State state_; | |
| 104 | |
| 105 InitCB init_cb_; | |
| 106 VideoDecoder::ReadCB read_cb_; | |
| 107 base::Closure reset_cb_; | |
| 108 base::Closure stop_cb_; | |
| 109 | |
| 110 SetDecryptorReadyCB set_decryptor_ready_cb_; | |
| 111 | |
| 112 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). | |
| 113 scoped_refptr<VideoDecoder> decoder_; | |
| 114 scoped_refptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream); | |
| 117 }; | |
| 118 | |
| 119 } // namespace media | |
| 120 | |
| 121 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ | |
| OLD | NEW |