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

Side by Side Diff: media/filters/decrypting_demuxer_stream.cc

Issue 2543623003: media: Allow config change between clear and encrypted streams (Closed)
Patch Set: media: Allow config change between clear and encrypted streams Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "media/filters/decrypting_demuxer_stream.h" 5 #include "media/filters/decrypting_demuxer_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "media/base/bind_to_current_loop.h" 13 #include "media/base/bind_to_current_loop.h"
14 #include "media/base/decoder_buffer.h" 14 #include "media/base/decoder_buffer.h"
15 #include "media/base/media_log.h" 15 #include "media/base/media_log.h"
16 #include "media/base/media_util.h" 16 #include "media/base/media_util.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 static bool IsStreamValidAndEncrypted(DemuxerStream* stream) { 20 static bool IsStreamValid(DemuxerStream* stream) {
21 return ((stream->type() == DemuxerStream::AUDIO && 21 return ((stream->type() == DemuxerStream::AUDIO &&
22 stream->audio_decoder_config().IsValidConfig() && 22 stream->audio_decoder_config().IsValidConfig()) ||
23 stream->audio_decoder_config().is_encrypted()) ||
24 (stream->type() == DemuxerStream::VIDEO && 23 (stream->type() == DemuxerStream::VIDEO &&
25 stream->video_decoder_config().IsValidConfig() && 24 stream->video_decoder_config().IsValidConfig()));
26 stream->video_decoder_config().is_encrypted()));
27 } 25 }
28 26
29 DecryptingDemuxerStream::DecryptingDemuxerStream( 27 DecryptingDemuxerStream::DecryptingDemuxerStream(
30 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
31 const scoped_refptr<MediaLog>& media_log, 29 const scoped_refptr<MediaLog>& media_log,
32 const base::Closure& waiting_for_decryption_key_cb) 30 const base::Closure& waiting_for_decryption_key_cb)
33 : task_runner_(task_runner), 31 : task_runner_(task_runner),
34 media_log_(media_log), 32 media_log_(media_log),
35 state_(kUninitialized), 33 state_(kUninitialized),
36 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), 34 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb),
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return; 225 return;
228 } 226 }
229 227
230 if (buffer->end_of_stream()) { 228 if (buffer->end_of_stream()) {
231 DVLOG(2) << "DoDecryptBuffer() - EOS buffer."; 229 DVLOG(2) << "DoDecryptBuffer() - EOS buffer.";
232 state_ = kIdle; 230 state_ = kIdle;
233 base::ResetAndReturn(&read_cb_).Run(status, buffer); 231 base::ResetAndReturn(&read_cb_).Run(status, buffer);
234 return; 232 return;
235 } 233 }
236 234
237 DCHECK(buffer->decrypt_config()); 235 if (!buffer->decrypt_config()) {
ddorwin 2016/12/05 23:53:04 Why is this different from the block at 242? I wou
xhwang 2016/12/16 20:12:28 I agree this is a bit odd. In the block at 242, we
236 DVLOG(2) << "DoDecryptBuffer() - clear buffer in clear stream.";
237 state_ = kIdle;
238 base::ResetAndReturn(&read_cb_).Run(kOk, buffer);
ddorwin 2016/12/05 23:53:04 Should we report |status| instead like 231?
xhwang 2016/12/16 20:12:28 |status| must be kOk here. Added a DCHECK and fixe
239 return;
240 }
241
238 if (!buffer->decrypt_config()->is_encrypted()) { 242 if (!buffer->decrypt_config()->is_encrypted()) {
239 DVLOG(2) << "DoDecryptBuffer() - clear buffer."; 243 DVLOG(2) << "DoDecryptBuffer() - clear buffer in encrypted stream.";
240 scoped_refptr<DecoderBuffer> decrypted = DecoderBuffer::CopyFrom( 244 scoped_refptr<DecoderBuffer> decrypted = DecoderBuffer::CopyFrom(
241 buffer->data(), buffer->data_size()); 245 buffer->data(), buffer->data_size());
242 decrypted->set_timestamp(buffer->timestamp()); 246 decrypted->set_timestamp(buffer->timestamp());
243 decrypted->set_duration(buffer->duration()); 247 decrypted->set_duration(buffer->duration());
244 if (buffer->is_key_frame()) 248 if (buffer->is_key_frame())
245 decrypted->set_is_key_frame(true); 249 decrypted->set_is_key_frame(true);
246 250
247 state_ = kIdle; 251 state_ = kIdle;
248 base::ResetAndReturn(&read_cb_).Run(kOk, decrypted); 252 base::ResetAndReturn(&read_cb_).Run(kOk, decrypted);
249 return; 253 return;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 359
356 Decryptor::StreamType DecryptingDemuxerStream::GetDecryptorStreamType() const { 360 Decryptor::StreamType DecryptingDemuxerStream::GetDecryptorStreamType() const {
357 if (demuxer_stream_->type() == AUDIO) 361 if (demuxer_stream_->type() == AUDIO)
358 return Decryptor::kAudio; 362 return Decryptor::kAudio;
359 363
360 DCHECK_EQ(demuxer_stream_->type(), VIDEO); 364 DCHECK_EQ(demuxer_stream_->type(), VIDEO);
361 return Decryptor::kVideo; 365 return Decryptor::kVideo;
362 } 366 }
363 367
364 void DecryptingDemuxerStream::InitializeDecoderConfig() { 368 void DecryptingDemuxerStream::InitializeDecoderConfig() {
365 // The decoder selector or upstream demuxer make sure the stream is valid and 369 // The decoder selector or upstream demuxer make sure the stream is valid.
366 // potentially encrypted. 370 DCHECK(IsStreamValid(demuxer_stream_));
367 DCHECK(IsStreamValidAndEncrypted(demuxer_stream_));
368 371
369 switch (demuxer_stream_->type()) { 372 switch (demuxer_stream_->type()) {
370 case AUDIO: { 373 case AUDIO: {
371 AudioDecoderConfig input_audio_config = 374 AudioDecoderConfig input_audio_config =
372 demuxer_stream_->audio_decoder_config(); 375 demuxer_stream_->audio_decoder_config();
373 audio_config_.Initialize( 376 audio_config_.Initialize(
374 input_audio_config.codec(), input_audio_config.sample_format(), 377 input_audio_config.codec(), input_audio_config.sample_format(),
375 input_audio_config.channel_layout(), 378 input_audio_config.channel_layout(),
376 input_audio_config.samples_per_second(), 379 input_audio_config.samples_per_second(),
377 input_audio_config.extra_data(), Unencrypted(), 380 input_audio_config.extra_data(), Unencrypted(),
(...skipping 13 matching lines...) Expand all
391 break; 394 break;
392 } 395 }
393 396
394 default: 397 default:
395 NOTREACHED(); 398 NOTREACHED();
396 return; 399 return;
397 } 400 }
398 } 401 }
399 402
400 } // namespace media 403 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698