OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
ddorwin
2012/12/13 05:08:25
Update CL description.
xhwang
2012/12/13 11:24:36
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/filters/audio_decoder_selector.h" | |
ddorwin
2012/12/13 05:08:25
Does this really belong in filters/? I know we hav
xhwang
2012/12/13 11:24:36
Well, it's affliated with AudioRendererImpl, which
| |
6 | |
7 #include "base/bind.h" | |
8 #include "base/callback_helpers.h" | |
9 #include "base/logging.h" | |
10 #include "base/message_loop_proxy.h" | |
11 #include "media/base/audio_decoder_config.h" | |
12 #include "media/base/bind_to_loop.h" | |
13 #include "media/base/demuxer_stream.h" | |
14 #include "media/base/pipeline.h" | |
15 #include "media/filters/decrypting_audio_decoder.h" | |
16 #include "media/filters/decrypting_demuxer_stream.h" | |
17 | |
18 namespace media { | |
19 | |
20 AudioDecoderSelector::AudioDecoderSelector( | |
21 const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
22 const AudioDecoderList& clear_decoders, | |
23 const SetDecryptorReadyCB& set_decryptor_ready_cb) | |
24 : message_loop_(message_loop), | |
25 clear_decoders_(clear_decoders), | |
26 set_decryptor_ready_cb_(set_decryptor_ready_cb), | |
27 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | |
28 weak_this_(weak_ptr_factory_.GetWeakPtr()) { | |
29 } | |
30 | |
31 AudioDecoderSelector::~AudioDecoderSelector() {} | |
32 | |
33 void AudioDecoderSelector::SelectAudioDecoder( | |
34 const scoped_refptr<DemuxerStream>& stream, | |
35 const StatisticsCB& statistics_cb, | |
36 const SelectDecoderCB& select_decoder_cb) { | |
37 DCHECK(message_loop_->BelongsToCurrentThread()); | |
38 DVLOG(2) << "SelectAudioDecoder()"; | |
ddorwin
2012/12/13 05:08:25
I always log above checks, though it probably does
xhwang
2012/12/13 11:24:36
Done.
| |
39 DCHECK(stream); | |
40 | |
41 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); | |
ddorwin
2012/12/13 05:08:25
Maybe explain why.
xhwang
2012/12/13 11:24:36
Done.
| |
42 | |
43 const AudioDecoderConfig& config = stream->audio_decoder_config(); | |
44 if (!config.IsValidConfig()) { | |
45 DLOG(ERROR) << "Invalid audio stream config."; | |
46 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
47 return; | |
48 } | |
49 | |
50 input_stream_ = stream; | |
51 statistics_cb_ = statistics_cb; | |
52 | |
53 if (!config.is_encrypted()) { | |
54 if (clear_decoders_.empty()) { | |
55 DLOG(ERROR) << "No audio decoder can be used to decode the input stream."; | |
56 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
57 return; | |
58 } | |
59 | |
60 InitializeNextClearDecoder(); | |
61 return; | |
62 } | |
63 | |
64 // This could happen if Encrypted Media Extension (EME) is not enabled. | |
65 if (set_decryptor_ready_cb_.is_null()) { | |
66 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
67 return; | |
68 } | |
69 | |
70 audio_decoder_ = new DecryptingAudioDecoder( | |
71 message_loop_, set_decryptor_ready_cb_); | |
ddorwin
2012/12/13 05:08:25
better indentation. Can you fit with one above?
xhwang
2012/12/13 11:24:36
Done.
| |
72 | |
73 audio_decoder_->Initialize( | |
74 input_stream_, | |
75 BindToCurrentLoop(base::Bind( | |
76 &AudioDecoderSelector::DecryptingAudioDecoderInitDone, weak_this_)), | |
77 statistics_cb_); | |
78 } | |
79 | |
80 void AudioDecoderSelector::DecryptingAudioDecoderInitDone( | |
81 PipelineStatus status) { | |
82 DCHECK(message_loop_->BelongsToCurrentThread()); | |
83 | |
84 if (status == PIPELINE_OK) { | |
85 clear_decoders_.clear(); | |
86 base::ResetAndReturn(&select_decoder_cb_).Run(audio_decoder_, NULL); | |
87 return; | |
88 } | |
89 | |
90 audio_decoder_ = NULL; | |
91 | |
92 if (clear_decoders_.empty()) { | |
93 DLOG(ERROR) << "No audio decoder can be used to decode the input stream."; | |
94 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
95 return; | |
96 } | |
97 | |
98 decrypted_stream_ = new DecryptingDemuxerStream( | |
99 message_loop_, set_decryptor_ready_cb_); | |
100 | |
101 decrypted_stream_->Initialize( | |
102 input_stream_, | |
103 BindToCurrentLoop(base::Bind( | |
104 &AudioDecoderSelector::DecryptingDemuxerStreamInitDone, weak_this_))); | |
105 } | |
106 | |
107 void AudioDecoderSelector::DecryptingDemuxerStreamInitDone( | |
108 PipelineStatus status) { | |
109 DCHECK(message_loop_->BelongsToCurrentThread()); | |
110 | |
111 if (status != PIPELINE_OK) { | |
112 decrypted_stream_ = NULL; | |
113 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
114 return; | |
115 } | |
116 | |
117 DCHECK(!decrypted_stream_->audio_decoder_config().is_encrypted()); | |
118 input_stream_ = decrypted_stream_; | |
119 InitializeNextClearDecoder(); | |
120 } | |
121 | |
122 void AudioDecoderSelector::InitializeNextClearDecoder() { | |
123 DCHECK(message_loop_->BelongsToCurrentThread()); | |
124 DCHECK(!clear_decoders_.empty()); | |
125 | |
126 audio_decoder_ = clear_decoders_.front(); | |
127 clear_decoders_.pop_front(); | |
128 DCHECK(audio_decoder_); | |
129 audio_decoder_->Initialize( | |
130 input_stream_, | |
131 BindToCurrentLoop(base::Bind( | |
132 &AudioDecoderSelector::ClearDecoderInitDone, weak_this_)), | |
133 statistics_cb_); | |
134 } | |
135 | |
136 void AudioDecoderSelector::ClearDecoderInitDone(PipelineStatus status) { | |
137 DCHECK(message_loop_->BelongsToCurrentThread()); | |
138 | |
139 if (status != PIPELINE_OK) { | |
140 if (!clear_decoders_.empty()) | |
141 InitializeNextClearDecoder(); | |
142 else | |
143 base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); | |
144 return; | |
145 } | |
146 | |
147 clear_decoders_.clear(); | |
148 base::ResetAndReturn(&select_decoder_cb_).Run(audio_decoder_, | |
149 decrypted_stream_); | |
150 } | |
151 | |
152 } // namespace media | |
OLD | NEW |