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

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

Issue 2837613004: media: Support better decoder switching (Closed)
Patch Set: update GetDisplayName() comments 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 decoder one by one as needed,
watk 2017/05/04 21:35:33 s/decoder/decoders/
xhwang 2017/05/04 23:53:13 Done.
44 // instead of creating a list of decoders at once.
watk 2017/05/04 21:35:33 s/at once/all at once/
xhwang 2017/05/04 23:53:13 Done.
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. Decoders that fail to initialize will be deleted. Future calls will
71 // select from the decoders following the decoder that was last returned. 75 // select from the decoders following the decoder that was last returned.
watk 2017/05/04 21:35:33 Needs updating? And document blacklisted_decoder?
xhwang 2017/05/04 23:53:13 Good catch. Done.
72 // 3. |cdm_context| is optional. If |cdm_context| is 76 // 3. |cdm_context| is optional. If |cdm_context| is
73 // null, no CDM will be available to perform decryption. 77 // null, no CDM will be available to perform decryption.
74 void SelectDecoder(StreamTraits* traits, 78 void SelectDecoder(StreamTraits* traits,
75 DemuxerStream* stream, 79 DemuxerStream* stream,
76 CdmContext* cdm_context, 80 CdmContext* cdm_context,
81 const std::string& blacklisted_decoder,
77 const SelectDecoderCB& select_decoder_cb, 82 const SelectDecoderCB& select_decoder_cb,
78 const typename Decoder::OutputCB& output_cb, 83 const typename Decoder::OutputCB& output_cb,
79 const base::Closure& waiting_for_decryption_key_cb); 84 const base::Closure& waiting_for_decryption_key_cb);
80 85
81 private: 86 private:
82 #if !defined(OS_ANDROID) 87 #if !defined(OS_ANDROID)
83 void InitializeDecryptingDecoder(); 88 void InitializeDecryptingDecoder();
84 void DecryptingDecoderInitDone(bool success); 89 void DecryptingDecoderInitDone(bool success);
85 #endif 90 #endif
86 void InitializeDecryptingDemuxerStream(); 91 void InitializeDecryptingDemuxerStream();
87 void DecryptingDemuxerStreamInitDone(PipelineStatus status); 92 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
88 void InitializeDecoder(); 93 void InitializeDecoder();
89 void DecoderInitDone(bool success); 94 void DecoderInitDone(bool success);
90 void ReturnNullDecoder(); 95 void ReturnNullDecoder();
91 96
92 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
93 ScopedVector<Decoder> decoders_; 98 CreateDecodersCB create_decoders_cb_;
94 MediaLog* media_log_; 99 MediaLog* media_log_;
95 100
96 StreamTraits* traits_; 101 StreamTraits* traits_;
97 102
98 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when 103 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when
99 // a DecryptingDemuxerStream is selected. 104 // a DecryptingDemuxerStream is selected.
100 DemuxerStream* input_stream_; 105 DemuxerStream* input_stream_;
101 106
102 CdmContext* cdm_context_; 107 CdmContext* cdm_context_;
108 std::string blacklisted_decoder_;
103 SelectDecoderCB select_decoder_cb_; 109 SelectDecoderCB select_decoder_cb_;
104 typename Decoder::OutputCB output_cb_; 110 typename Decoder::OutputCB output_cb_;
105 base::Closure waiting_for_decryption_key_cb_; 111 base::Closure waiting_for_decryption_key_cb_;
106 112
113 ScopedVector<Decoder> decoders_;
114
107 std::unique_ptr<Decoder> decoder_; 115 std::unique_ptr<Decoder> decoder_;
108 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_; 116 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_;
109 117
110 // Config of the |input_stream| used to initialize decoders. 118 // Config of the |input_stream| used to initialize decoders.
111 DecoderConfig config_; 119 DecoderConfig config_;
112 120
113 // NOTE: Weak pointers must be invalidated before all other member variables. 121 // NOTE: Weak pointers must be invalidated before all other member variables.
114 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_; 122 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
115 123
116 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector); 124 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
117 }; 125 };
118 126
119 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector; 127 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
120 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector; 128 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
121 129
122 } // namespace media 130 } // namespace media
123 131
124 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_ 132 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698