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

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

Issue 2837613004: media: Support better decoder switching (Closed)
Patch Set: Mock*Decoder name Created 3 years, 7 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
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_SELECTOR_H_ 5 #ifndef MEDIA_FILTERS_DECODER_SELECTOR_H_
6 #define MEDIA_FILTERS_DECODER_SELECTOR_H_ 6 #define MEDIA_FILTERS_DECODER_SELECTOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 21 matching lines...) Expand all
32 // encrypted, a DecryptingDemuxerStream may also be created. 32 // encrypted, a DecryptingDemuxerStream may also be created.
33 // The template parameter |StreamType| is the type of stream we will be 33 // The template parameter |StreamType| is the type of stream we will be
34 // selecting a decoder for. 34 // selecting a decoder for.
35 template<DemuxerStream::Type StreamType> 35 template<DemuxerStream::Type StreamType>
36 class MEDIA_EXPORT DecoderSelector { 36 class MEDIA_EXPORT DecoderSelector {
37 public: 37 public:
38 typedef DecoderStreamTraits<StreamType> StreamTraits; 38 typedef DecoderStreamTraits<StreamType> StreamTraits;
39 typedef typename StreamTraits::DecoderType Decoder; 39 typedef typename StreamTraits::DecoderType Decoder;
40 typedef typename StreamTraits::DecoderConfigType DecoderConfig; 40 typedef typename StreamTraits::DecoderConfigType DecoderConfig;
41 41
42 // Callback to create a list of decoders to select from.
43 // TODO(xhwang): Use a DecoderFactory to create decoders one by one as needed,
44 // instead of creating a list of decoders all at once.
45 using CreateDecodersCB = base::RepeatingCallback<ScopedVector<Decoder>()>;
46
42 // Indicates completion of Decoder selection. 47 // Indicates completion of Decoder selection.
43 // - First parameter: The initialized Decoder. If it's set to NULL, then 48 // - First parameter: The initialized Decoder. If it's set to NULL, then
44 // Decoder initialization failed. 49 // Decoder initialization failed.
45 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not 50 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not
46 // NULL, then a DecryptingDemuxerStream is created and initialized to do 51 // NULL, then a DecryptingDemuxerStream is created and initialized to do
47 // decryption for the initialized Decoder. 52 // decryption for the initialized Decoder.
48 // Note: The caller owns selected Decoder and DecryptingDemuxerStream. 53 // Note: The caller owns selected Decoder and DecryptingDemuxerStream.
49 // The caller should call DecryptingDemuxerStream::Reset() before 54 // The caller should call DecryptingDemuxerStream::Reset() before
50 // calling Decoder::Reset() to release any pending decryption or read. 55 // calling Decoder::Reset() to release any pending decryption or read.
51 typedef base::Callback<void(std::unique_ptr<Decoder>, 56 using SelectDecoderCB =
52 std::unique_ptr<DecryptingDemuxerStream>)> 57 base::Callback<void(std::unique_ptr<Decoder>,
53 SelectDecoderCB; 58 std::unique_ptr<DecryptingDemuxerStream>)>;
54 59
55 // |decoders| contains the Decoders to use when initializing.
56 DecoderSelector( 60 DecoderSelector(
57 const scoped_refptr<base::SingleThreadTaskRunner>& message_loop, 61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
58 ScopedVector<Decoder> decoders, 62 CreateDecodersCB create_decoders_cb,
59 MediaLog* media_log); 63 MediaLog* media_log);
60 64
61 // Aborts pending Decoder selection and fires |select_decoder_cb| with 65 // Aborts pending Decoder selection and fires |select_decoder_cb| with
62 // NULL and NULL immediately if it's pending. 66 // null and null immediately if it's pending.
63 ~DecoderSelector(); 67 ~DecoderSelector();
64 68
65 // Initializes and selects the first Decoder that can decode the |stream|. 69 // Initializes and selects the first Decoder that can decode the |stream|.
66 // The selected Decoder (and DecryptingDemuxerStream) is returned via 70 // The selected Decoder (and DecryptingDemuxerStream) is returned via
67 // the |select_decoder_cb|. 71 // the |select_decoder_cb|.
68 // Notes: 72 // Notes:
69 // 1. This must not be called again before |select_decoder_cb| is run. 73 // 1. This must not be called again before |select_decoder_cb| is run.
70 // 2. Decoders that fail to initialize will be deleted. Future calls will 74 // 2. |create_decoders_cb| will be called to create a list of candidate
71 // select from the decoders following the decoder that was last returned. 75 // decoders to select from.
72 // 3. |cdm_context| is optional. If |cdm_context| is 76 // 3. The |blacklisted_decoder| will be skipped in the decoder selection
73 // null, no CDM will be available to perform decryption. 77 // process, unless DecryptingDemuxerStream is chosen. This is because
78 // DecryptingDemuxerStream updates the |config_|, and the blacklist should
79 // only be applied to the original |stream| config.
80 // 4. All decoders that are not selected will be deleted upon returning
81 // |select_decoder_cb|.
82 // 5. |cdm_context| is optional. If |cdm_context| is null, no CDM will be
83 // available to perform decryption.
74 void SelectDecoder(StreamTraits* traits, 84 void SelectDecoder(StreamTraits* traits,
75 DemuxerStream* stream, 85 DemuxerStream* stream,
76 CdmContext* cdm_context, 86 CdmContext* cdm_context,
87 const std::string& blacklisted_decoder,
77 const SelectDecoderCB& select_decoder_cb, 88 const SelectDecoderCB& select_decoder_cb,
78 const typename Decoder::OutputCB& output_cb, 89 const typename Decoder::OutputCB& output_cb,
79 const base::Closure& waiting_for_decryption_key_cb); 90 const base::Closure& waiting_for_decryption_key_cb);
80 91
81 private: 92 private:
82 #if !defined(OS_ANDROID) 93 #if !defined(OS_ANDROID)
83 void InitializeDecryptingDecoder(); 94 void InitializeDecryptingDecoder();
84 void DecryptingDecoderInitDone(bool success); 95 void DecryptingDecoderInitDone(bool success);
85 #endif 96 #endif
86 void InitializeDecryptingDemuxerStream(); 97 void InitializeDecryptingDemuxerStream();
87 void DecryptingDemuxerStreamInitDone(PipelineStatus status); 98 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
88 void InitializeDecoder(); 99 void InitializeDecoder();
89 void DecoderInitDone(bool success); 100 void DecoderInitDone(bool success);
90 void ReturnNullDecoder(); 101 void ReturnNullDecoder();
91 102
92 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 103 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
93 ScopedVector<Decoder> decoders_; 104 CreateDecodersCB create_decoders_cb_;
94 MediaLog* media_log_; 105 MediaLog* media_log_;
95 106
96 StreamTraits* traits_; 107 StreamTraits* traits_;
97 108
98 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when 109 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when
99 // a DecryptingDemuxerStream is selected. 110 // a DecryptingDemuxerStream is selected.
100 DemuxerStream* input_stream_; 111 DemuxerStream* input_stream_;
101 112
102 CdmContext* cdm_context_; 113 CdmContext* cdm_context_;
114 std::string blacklisted_decoder_;
103 SelectDecoderCB select_decoder_cb_; 115 SelectDecoderCB select_decoder_cb_;
104 typename Decoder::OutputCB output_cb_; 116 typename Decoder::OutputCB output_cb_;
105 base::Closure waiting_for_decryption_key_cb_; 117 base::Closure waiting_for_decryption_key_cb_;
106 118
119 ScopedVector<Decoder> decoders_;
120
107 std::unique_ptr<Decoder> decoder_; 121 std::unique_ptr<Decoder> decoder_;
108 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_; 122 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_;
109 123
110 // Config of the |input_stream| used to initialize decoders. 124 // Config of the |input_stream| used to initialize decoders.
111 DecoderConfig config_; 125 DecoderConfig config_;
112 126
113 // NOTE: Weak pointers must be invalidated before all other member variables. 127 // NOTE: Weak pointers must be invalidated before all other member variables.
114 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_; 128 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
115 129
116 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector); 130 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
117 }; 131 };
118 132
119 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector; 133 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
120 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector; 134 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
121 135
122 } // namespace media 136 } // namespace media
123 137
124 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_ 138 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698