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

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

Issue 2837613004: media: Support better decoder switching (Closed)
Patch Set: Created 3 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
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 using CreateDecodersCB = base::RepeatingCallback<ScopedVector<Decoder>()>;
sandersd (OOO until July 31) 2017/04/24 20:55:14 Is now perhaps a good time to replace this ScopedV
xhwang 2017/04/25 00:43:30 Agreed, and this is the tracking bug: https://bugs
44
42 // Indicates completion of Decoder selection. 45 // Indicates completion of Decoder selection.
43 // - First parameter: The initialized Decoder. If it's set to NULL, then 46 // - First parameter: The initialized Decoder. If it's set to NULL, then
44 // Decoder initialization failed. 47 // Decoder initialization failed.
45 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not 48 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not
46 // NULL, then a DecryptingDemuxerStream is created and initialized to do 49 // NULL, then a DecryptingDemuxerStream is created and initialized to do
47 // decryption for the initialized Decoder. 50 // decryption for the initialized Decoder.
48 // Note: The caller owns selected Decoder and DecryptingDemuxerStream. 51 // Note: The caller owns selected Decoder and DecryptingDemuxerStream.
49 // The caller should call DecryptingDemuxerStream::Reset() before 52 // The caller should call DecryptingDemuxerStream::Reset() before
50 // calling Decoder::Reset() to release any pending decryption or read. 53 // calling Decoder::Reset() to release any pending decryption or read.
51 typedef base::Callback<void(std::unique_ptr<Decoder>, 54 using SelectDecoderCB =
52 std::unique_ptr<DecryptingDemuxerStream>)> 55 base::Callback<void(std::unique_ptr<Decoder>,
53 SelectDecoderCB; 56 std::unique_ptr<DecryptingDemuxerStream>)>;
54 57
55 // |decoders| contains the Decoders to use when initializing.
56 DecoderSelector( 58 DecoderSelector(
57 const scoped_refptr<base::SingleThreadTaskRunner>& message_loop, 59 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
58 ScopedVector<Decoder> decoders, 60 const CreateDecodersCB& create_decoders_cb,
59 const scoped_refptr<MediaLog>& media_log); 61 const scoped_refptr<MediaLog>& media_log);
60 62
61 // Aborts pending Decoder selection and fires |select_decoder_cb| with 63 // Aborts pending Decoder selection and fires |select_decoder_cb| with
62 // NULL and NULL immediately if it's pending. 64 // NULL and NULL immediately if it's pending.
63 ~DecoderSelector(); 65 ~DecoderSelector();
64 66
65 // Initializes and selects the first Decoder that can decode the |stream|. 67 // Initializes and selects the first Decoder that can decode the |stream|.
66 // The selected Decoder (and DecryptingDemuxerStream) is returned via 68 // The selected Decoder (and DecryptingDemuxerStream) is returned via
67 // the |select_decoder_cb|. 69 // the |select_decoder_cb|.
68 // Notes: 70 // Notes:
69 // 1. This must not be called again before |select_decoder_cb| is run. 71 // 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 72 // 2. Decoders that fail to initialize will be deleted. Future calls will
71 // select from the decoders following the decoder that was last returned. 73 // select from the decoders following the decoder that was last returned.
72 // 3. |cdm_context| is optional. If |cdm_context| is 74 // 3. |cdm_context| is optional. If |cdm_context| is
73 // null, no CDM will be available to perform decryption. 75 // null, no CDM will be available to perform decryption.
74 void SelectDecoder(StreamTraits* traits, 76 void SelectDecoder(StreamTraits* traits,
75 DemuxerStream* stream, 77 DemuxerStream* stream,
76 CdmContext* cdm_context, 78 CdmContext* cdm_context,
79 const std::string& blacklisted_decoder,
77 const SelectDecoderCB& select_decoder_cb, 80 const SelectDecoderCB& select_decoder_cb,
78 const typename Decoder::OutputCB& output_cb, 81 const typename Decoder::OutputCB& output_cb,
79 const base::Closure& waiting_for_decryption_key_cb); 82 const base::Closure& waiting_for_decryption_key_cb);
80 83
81 private: 84 private:
82 #if !defined(OS_ANDROID) 85 #if !defined(OS_ANDROID)
83 void InitializeDecryptingDecoder(); 86 void InitializeDecryptingDecoder();
84 void DecryptingDecoderInitDone(bool success); 87 void DecryptingDecoderInitDone(bool success);
85 #endif 88 #endif
86 void InitializeDecryptingDemuxerStream(); 89 void InitializeDecryptingDemuxerStream();
87 void DecryptingDemuxerStreamInitDone(PipelineStatus status); 90 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
88 void InitializeDecoder(); 91 void InitializeDecoder();
89 void DecoderInitDone(bool success); 92 void DecoderInitDone(bool success);
90 void ReturnNullDecoder(); 93 void ReturnNullDecoder();
91 94
92 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 95 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
93 ScopedVector<Decoder> decoders_; 96 CreateDecodersCB create_decoders_cb_;
94 scoped_refptr<MediaLog> media_log_; 97 scoped_refptr<MediaLog> media_log_;
95 98
96 StreamTraits* traits_; 99 StreamTraits* traits_;
97 100
98 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when 101 // Could be the |stream| passed in SelectDecoder, or |decrypted_stream_| when
99 // a DecryptingDemuxerStream is selected. 102 // a DecryptingDemuxerStream is selected.
100 DemuxerStream* input_stream_; 103 DemuxerStream* input_stream_;
101 104
102 CdmContext* cdm_context_; 105 CdmContext* cdm_context_;
106 std::string blacklisted_decoder_;
103 SelectDecoderCB select_decoder_cb_; 107 SelectDecoderCB select_decoder_cb_;
104 typename Decoder::OutputCB output_cb_; 108 typename Decoder::OutputCB output_cb_;
105 base::Closure waiting_for_decryption_key_cb_; 109 base::Closure waiting_for_decryption_key_cb_;
106 110
111 ScopedVector<Decoder> decoders_;
112
107 std::unique_ptr<Decoder> decoder_; 113 std::unique_ptr<Decoder> decoder_;
108 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_; 114 std::unique_ptr<DecryptingDemuxerStream> decrypted_stream_;
109 115
110 // Config of the |input_stream| used to initialize decoders. 116 // Config of the |input_stream| used to initialize decoders.
111 DecoderConfig config_; 117 DecoderConfig config_;
112 118
113 // NOTE: Weak pointers must be invalidated before all other member variables. 119 // NOTE: Weak pointers must be invalidated before all other member variables.
114 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_; 120 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
115 121
116 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector); 122 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
117 }; 123 };
118 124
119 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector; 125 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
120 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector; 126 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
121 127
122 } // namespace media 128 } // namespace media
123 129
124 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_ 130 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698