Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_DECODER_STREAM_H_ | 5 #ifndef MEDIA_FILTERS_DECODER_STREAM_H_ |
| 6 #define MEDIA_FILTERS_DECODER_STREAM_H_ | 6 #define MEDIA_FILTERS_DECODER_STREAM_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 typedef base::Closure ConfigChangeObserverCB; | 115 typedef base::Closure ConfigChangeObserverCB; |
| 116 void set_config_change_observer( | 116 void set_config_change_observer( |
| 117 const ConfigChangeObserverCB& config_change_observer) { | 117 const ConfigChangeObserverCB& config_change_observer) { |
| 118 config_change_observer_cb_ = config_change_observer; | 118 config_change_observer_cb_ = config_change_observer; |
| 119 } | 119 } |
| 120 | 120 |
| 121 const Decoder* get_previous_decoder_for_testing() const { | 121 const Decoder* get_previous_decoder_for_testing() const { |
| 122 return previous_decoder_.get(); | 122 return previous_decoder_.get(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 int get_pending_buffers_size_for_testing() const { | |
| 126 return pending_buffers_.size(); | |
| 127 } | |
| 128 | |
| 129 int get_fallback_buffers_size_for_testing() const { | |
| 130 return fallback_buffers_.size(); | |
| 131 } | |
| 132 | |
| 125 private: | 133 private: |
| 126 enum State { | 134 enum State { |
| 127 STATE_UNINITIALIZED, | 135 STATE_UNINITIALIZED, |
| 128 STATE_INITIALIZING, | 136 STATE_INITIALIZING, |
| 129 STATE_NORMAL, // Includes idle, pending decoder decode/reset. | 137 STATE_NORMAL, // Includes idle, pending decoder decode/reset. |
| 130 STATE_FLUSHING_DECODER, | 138 STATE_FLUSHING_DECODER, |
| 131 STATE_PENDING_DEMUXER_READ, | 139 STATE_PENDING_DEMUXER_READ, |
| 132 STATE_REINITIALIZING_DECODER, | 140 STATE_REINITIALIZING_DECODER, |
| 133 STATE_END_OF_STREAM, // End of stream reached; returns EOS on all reads. | 141 STATE_END_OF_STREAM, // End of stream reached; returns EOS on all reads. |
| 134 STATE_ERROR | 142 STATE_ERROR, |
| 143 // TODO(tguilbert): support config changes during decoder fallback, see | |
| 144 // crbug.com/603713 | |
| 145 STATE_CONFIG_CHANGE_RECEIVED_WHILE_REINITIALIZING_DECODER | |
| 135 }; | 146 }; |
| 136 | 147 |
| 137 void SelectDecoder(CdmContext* cdm_context); | 148 void SelectDecoder(CdmContext* cdm_context); |
| 138 | 149 |
| 139 // Called when |decoder_selector| selected the |selected_decoder|. | 150 // Called when |decoder_selector| selected the |selected_decoder|. |
| 140 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream | 151 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream |
| 141 // is created to help decrypt the encrypted stream. | 152 // is created to help decrypt the encrypted stream. |
| 142 void OnDecoderSelected( | 153 void OnDecoderSelected( |
| 143 scoped_ptr<Decoder> selected_decoder, | 154 scoped_ptr<Decoder> selected_decoder, |
| 144 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); | 155 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); |
| 145 | 156 |
| 146 // Satisfy pending |read_cb_| with |status| and |output|. | 157 // Satisfy pending |read_cb_| with |status| and |output|. |
| 147 void SatisfyRead(Status status, | 158 void SatisfyRead(Status status, |
| 148 const scoped_refptr<Output>& output); | 159 const scoped_refptr<Output>& output); |
| 149 | 160 |
| 150 // Decodes |buffer| and returns the result via OnDecodeOutputReady(). | 161 // Decodes |buffer| and returns the result via OnDecodeOutputReady(). |
| 162 // Saves |buffer| into |pending_buffers_| if appropriate. | |
| 151 void Decode(const scoped_refptr<DecoderBuffer>& buffer); | 163 void Decode(const scoped_refptr<DecoderBuffer>& buffer); |
| 152 | 164 |
| 165 // Performs the heavy lifting of the decode call. | |
| 166 void DecodeInternal(const scoped_refptr<DecoderBuffer>& buffer); | |
| 167 | |
| 153 // Flushes the decoder with an EOS buffer to retrieve internally buffered | 168 // Flushes the decoder with an EOS buffer to retrieve internally buffered |
| 154 // decoder output. | 169 // decoder output. |
| 155 void FlushDecoder(); | 170 void FlushDecoder(); |
| 156 | 171 |
| 157 // Callback for Decoder::Decode(). | 172 // Callback for Decoder::Decode(). |
| 158 void OnDecodeDone(int buffer_size, bool end_of_stream, DecodeStatus status); | 173 void OnDecodeDone(int buffer_size, bool end_of_stream, DecodeStatus status); |
| 159 | 174 |
| 160 // Output callback passed to Decoder::Initialize(). | 175 // Output callback passed to Decoder::Initialize(). |
| 161 void OnDecodeOutputReady(const scoped_refptr<Output>& output); | 176 void OnDecodeOutputReady(const scoped_refptr<Output>& output); |
| 162 | 177 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // Decoded buffers that haven't been read yet. Used when the decoder supports | 233 // Decoded buffers that haven't been read yet. Used when the decoder supports |
| 219 // parallel decoding. | 234 // parallel decoding. |
| 220 std::list<scoped_refptr<Output> > ready_outputs_; | 235 std::list<scoped_refptr<Output> > ready_outputs_; |
| 221 | 236 |
| 222 // Number of outstanding decode requests sent to the |decoder_|. | 237 // Number of outstanding decode requests sent to the |decoder_|. |
| 223 int pending_decode_requests_; | 238 int pending_decode_requests_; |
| 224 | 239 |
| 225 // Tracks the duration of incoming packets over time. | 240 // Tracks the duration of incoming packets over time. |
| 226 MovingAverage duration_tracker_; | 241 MovingAverage duration_tracker_; |
| 227 | 242 |
| 243 // Stores buffers that might be reused if the decoder fails right after | |
| 244 // Initialize(). | |
| 245 std::deque<scoped_refptr<DecoderBuffer>> pending_buffers_; | |
| 246 | |
| 247 // Stores buffers that are garanteed to be fed to the decoder before fetching | |
|
DaleCurtis
2016/04/15 01:19:17
guaranteed
tguilbert
2016/04/15 20:45:52
Done.
| |
| 248 // more from the demuxer stream. Populated by |pending_buffers_| on decoder | |
|
DaleCurtis
2016/04/15 01:19:17
"Populated by ..." seems like it should be followe
tguilbert
2016/04/15 20:45:52
Done.
| |
| 249 // fallback. | |
| 250 std::deque<scoped_refptr<DecoderBuffer>> fallback_buffers_; | |
| 251 | |
| 228 // NOTE: Weak pointers must be invalidated before all other member variables. | 252 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 229 base::WeakPtrFactory<DecoderStream<StreamType> > weak_factory_; | 253 base::WeakPtrFactory<DecoderStream<StreamType>> weak_factory_; |
| 254 base::WeakPtrFactory<DecoderStream<StreamType>> decode_weak_factory_; | |
|
DaleCurtis
2016/04/15 01:19:17
This should have a comment about exactly what this
tguilbert
2016/04/15 20:45:52
Done.
| |
| 230 }; | 255 }; |
| 231 | 256 |
| 232 template <> | 257 template <> |
| 233 bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const; | 258 bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const; |
| 234 | 259 |
| 235 template <> | 260 template <> |
| 236 int DecoderStream<DemuxerStream::AUDIO>::GetMaxDecodeRequests() const; | 261 int DecoderStream<DemuxerStream::AUDIO>::GetMaxDecodeRequests() const; |
| 237 | 262 |
| 238 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream; | 263 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream; |
| 239 typedef DecoderStream<DemuxerStream::AUDIO> AudioBufferStream; | 264 typedef DecoderStream<DemuxerStream::AUDIO> AudioBufferStream; |
| 240 | 265 |
| 241 } // namespace media | 266 } // namespace media |
| 242 | 267 |
| 243 #endif // MEDIA_FILTERS_DECODER_STREAM_H_ | 268 #endif // MEDIA_FILTERS_DECODER_STREAM_H_ |
| OLD | NEW |