Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: media/filters/decoder_stream.h

Issue 1879353003: Attempt decoder fallback if first decode fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new test for EOS flushing edge case Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/filters/decoder_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 guaranteed to be fed to the decoder before fetching
248 // more from the demuxer stream. All buffers in this queue first were in
249 // |pending_buffers_|.
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
255 // Used to invalidate pending decode requests and output callbacks when
256 // falling back to a new decoder (on first decode error).
257 base::WeakPtrFactory<DecoderStream<StreamType>> fallback_weak_factory_;
230 }; 258 };
231 259
232 template <> 260 template <>
233 bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const; 261 bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const;
234 262
235 template <> 263 template <>
236 int DecoderStream<DemuxerStream::AUDIO>::GetMaxDecodeRequests() const; 264 int DecoderStream<DemuxerStream::AUDIO>::GetMaxDecodeRequests() const;
237 265
238 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream; 266 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream;
239 typedef DecoderStream<DemuxerStream::AUDIO> AudioBufferStream; 267 typedef DecoderStream<DemuxerStream::AUDIO> AudioBufferStream;
240 268
241 } // namespace media 269 } // namespace media
242 270
243 #endif // MEDIA_FILTERS_DECODER_STREAM_H_ 271 #endif // MEDIA_FILTERS_DECODER_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | media/filters/decoder_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698