| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ | 5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ |
| 6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ | 6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
| 17 #include "media/base/demuxer_stream.h" | 17 #include "media/base/demuxer_stream.h" |
| 18 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
| 19 #include "media/base/pipeline_status.h" | 19 #include "media/base/pipeline_status.h" |
| 20 #include "media/base/video_decoder.h" | 20 #include "media/base/video_decoder.h" |
| 21 #include "media/filters/video_decoder_selector.h" | |
| 22 | 21 |
| 23 namespace base { | 22 namespace base { |
| 24 class MessageLoopProxy; | 23 class MessageLoopProxy; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace media { | 26 namespace media { |
| 28 | 27 |
| 29 class DecryptingDemuxerStream; | 28 class DecryptingDemuxerStream; |
| 30 class VideoDecoderSelector; | 29 class VideoDecoderSelector; |
| 31 | 30 |
| 32 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded | 31 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded |
| 33 // VideoFrames to its client (e.g. VideoRendererBase). | 32 // VideoFrames to its client (e.g. VideoRendererBase). |
| 34 class MEDIA_EXPORT VideoFrameStream : public DemuxerStream { | 33 class MEDIA_EXPORT VideoFrameStream : public DemuxerStream { |
| 35 public: | 34 public: |
| 36 // Indicates completion of VideoFrameStream initialization. | 35 // Indicates completion of VideoFrameStream initialization. |
| 37 typedef base::Callback<void(bool success, bool has_alpha)> InitCB; | 36 typedef base::Callback<void(bool success, bool has_alpha)> InitCB; |
| 38 | 37 |
| 39 VideoFrameStream(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 38 VideoFrameStream(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 40 ScopedVector<VideoDecoder> decoders, | 39 ScopedVector<VideoDecoder> decoders, |
| 41 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 40 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
| 41 virtual ~VideoFrameStream(); |
| 42 | 42 |
| 43 // Initializes the VideoFrameStream and returns the initialization result | 43 // Initializes the VideoFrameStream and returns the initialization result |
| 44 // through |init_cb|. Note that |init_cb| is always called asynchronously. | 44 // through |init_cb|. Note that |init_cb| is always called asynchronously. |
| 45 void Initialize(const scoped_refptr<DemuxerStream>& stream, | 45 void Initialize(DemuxerStream* stream, |
| 46 const StatisticsCB& statistics_cb, | 46 const StatisticsCB& statistics_cb, |
| 47 const InitCB& init_cb); | 47 const InitCB& init_cb); |
| 48 | 48 |
| 49 // Reads a decoded VideoFrame and returns it via the |read_cb|. Note that | 49 // Reads a decoded VideoFrame and returns it via the |read_cb|. Note that |
| 50 // |read_cb| is always called asynchronously. This method should only be | 50 // |read_cb| is always called asynchronously. This method should only be |
| 51 // called after initialization has succeeded and must not be called during | 51 // called after initialization has succeeded and must not be called during |
| 52 // any pending Reset() and/or Stop(). | 52 // any pending Reset() and/or Stop(). |
| 53 void ReadFrame(const VideoDecoder::ReadCB& read_cb); | 53 void ReadFrame(const VideoDecoder::ReadCB& read_cb); |
| 54 | 54 |
| 55 // Resets the decoder, flushes all decoded frames and/or internal buffers, | 55 // Resets the decoder, flushes all decoded frames and/or internal buffers, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 // a VideoFrame. | 70 // a VideoFrame. |
| 71 bool HasOutputFrameAvailable() const; | 71 bool HasOutputFrameAvailable() const; |
| 72 | 72 |
| 73 // DemuxerStream implementation. | 73 // DemuxerStream implementation. |
| 74 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 74 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 75 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; | 75 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
| 76 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; | 76 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
| 77 virtual Type type() OVERRIDE; | 77 virtual Type type() OVERRIDE; |
| 78 virtual void EnableBitstreamConverter() OVERRIDE; | 78 virtual void EnableBitstreamConverter() OVERRIDE; |
| 79 | 79 |
| 80 protected: | |
| 81 virtual ~VideoFrameStream(); | |
| 82 | |
| 83 private: | 80 private: |
| 84 enum State { | 81 enum State { |
| 85 UNINITIALIZED, | 82 UNINITIALIZED, |
| 86 NORMAL, | 83 NORMAL, |
| 87 STOPPED | 84 STOPPED |
| 88 }; | 85 }; |
| 89 | 86 |
| 90 // Called when |decoder_selector| selected the |selected_decoder|. | 87 // Called when |decoder_selector| selected the |selected_decoder|. |
| 91 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream | 88 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream |
| 92 // is created to help decrypt the encrypted stream. | 89 // is created to help decrypt the encrypted stream. |
| 93 void OnDecoderSelected( | 90 void OnDecoderSelected( |
| 94 scoped_ptr<VideoDecoderSelector> decoder_selector, | |
| 95 scoped_ptr<VideoDecoder> selected_decoder, | 91 scoped_ptr<VideoDecoder> selected_decoder, |
| 96 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream); | 92 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); |
| 97 | 93 |
| 98 // Callback for VideoDecoder::Read(). | 94 // Callback for VideoDecoder::Read(). |
| 99 void OnFrameRead(const VideoDecoder::Status status, | 95 void OnFrameRead(const VideoDecoder::Status status, |
| 100 const scoped_refptr<VideoFrame>& frame); | 96 const scoped_refptr<VideoFrame>& frame); |
| 101 | 97 |
| 102 void ResetDecoder(); | 98 void ResetDecoder(); |
| 103 void OnDecoderReset(); | 99 void OnDecoderReset(); |
| 104 | 100 |
| 105 void StopDecoder(); | 101 void StopDecoder(); |
| 106 void OnDecoderStopped(); | 102 void OnDecoderStopped(); |
| 107 | 103 |
| 108 scoped_refptr<base::MessageLoopProxy> message_loop_; | 104 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 109 base::WeakPtrFactory<VideoFrameStream> weak_factory_; | 105 base::WeakPtrFactory<VideoFrameStream> weak_factory_; |
| 110 base::WeakPtr<VideoFrameStream> weak_this_; | 106 base::WeakPtr<VideoFrameStream> weak_this_; |
| 111 | 107 |
| 112 State state_; | 108 State state_; |
| 113 | 109 |
| 114 InitCB init_cb_; | 110 InitCB init_cb_; |
| 115 VideoDecoder::ReadCB read_cb_; | 111 VideoDecoder::ReadCB read_cb_; |
| 116 base::Closure reset_cb_; | 112 base::Closure reset_cb_; |
| 117 base::Closure stop_cb_; | 113 base::Closure stop_cb_; |
| 118 | 114 |
| 119 // TODO(scherkus): Replace these with a VideoDecoderSelector instance after | 115 DemuxerStream* stream_; |
| 120 // DemuxerStream is no longer refcounted. | |
| 121 ScopedVector<VideoDecoder> decoders_; | |
| 122 SetDecryptorReadyCB set_decryptor_ready_cb_; | |
| 123 | 116 |
| 124 scoped_refptr<DemuxerStream> stream_; | 117 scoped_ptr<VideoDecoderSelector> decoder_selector_; |
| 125 | 118 |
| 126 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). | 119 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). |
| 127 scoped_ptr<VideoDecoder> decoder_; | 120 scoped_ptr<VideoDecoder> decoder_; |
| 128 scoped_refptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | 121 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; |
| 129 | 122 |
| 130 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream); | 123 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream); |
| 131 }; | 124 }; |
| 132 | 125 |
| 133 } // namespace media | 126 } // namespace media |
| 134 | 127 |
| 135 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ | 128 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ |
| OLD | NEW |