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

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

Issue 1442933002: media: Pass SetCdmReadyCB in {Audio|Video}Decoder::Initialize(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile errors Created 5 years, 1 month 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_audio_decoder.h" 5 #include "media/filters/decrypting_audio_decoder.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 16 matching lines...) Expand all
27 // Out of sync of 100ms would be pretty noticeable and we should keep any 27 // Out of sync of 100ms would be pretty noticeable and we should keep any
28 // drift below that. 28 // drift below that.
29 const int64 kOutOfSyncThresholdInMilliseconds = 100; 29 const int64 kOutOfSyncThresholdInMilliseconds = 100;
30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) > 30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) >
31 kOutOfSyncThresholdInMilliseconds; 31 kOutOfSyncThresholdInMilliseconds;
32 } 32 }
33 33
34 DecryptingAudioDecoder::DecryptingAudioDecoder( 34 DecryptingAudioDecoder::DecryptingAudioDecoder(
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
36 const scoped_refptr<MediaLog>& media_log, 36 const scoped_refptr<MediaLog>& media_log,
37 const SetCdmReadyCB& set_cdm_ready_cb,
38 const base::Closure& waiting_for_decryption_key_cb) 37 const base::Closure& waiting_for_decryption_key_cb)
39 : task_runner_(task_runner), 38 : task_runner_(task_runner),
40 media_log_(media_log), 39 media_log_(media_log),
41 state_(kUninitialized), 40 state_(kUninitialized),
42 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), 41 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb),
43 set_cdm_ready_cb_(set_cdm_ready_cb),
44 decryptor_(NULL), 42 decryptor_(NULL),
45 key_added_while_decode_pending_(false), 43 key_added_while_decode_pending_(false),
46 weak_factory_(this) {} 44 weak_factory_(this) {}
47 45
48 std::string DecryptingAudioDecoder::GetDisplayName() const { 46 std::string DecryptingAudioDecoder::GetDisplayName() const {
49 return "DecryptingAudioDecoder"; 47 return "DecryptingAudioDecoder";
50 } 48 }
51 49
52 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, 50 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config,
51 const SetCdmReadyCB& set_cdm_ready_cb,
53 const InitCB& init_cb, 52 const InitCB& init_cb,
54 const OutputCB& output_cb) { 53 const OutputCB& output_cb) {
55 DVLOG(2) << "Initialize()"; 54 DVLOG(2) << "Initialize()";
56 DCHECK(task_runner_->BelongsToCurrentThread()); 55 DCHECK(task_runner_->BelongsToCurrentThread());
57 DCHECK(decode_cb_.is_null()); 56 DCHECK(decode_cb_.is_null());
58 DCHECK(reset_cb_.is_null()); 57 DCHECK(reset_cb_.is_null());
59 58
60 weak_this_ = weak_factory_.GetWeakPtr(); 59 weak_this_ = weak_factory_.GetWeakPtr();
61 init_cb_ = BindToCurrentLoop(init_cb); 60 init_cb_ = BindToCurrentLoop(init_cb);
62 output_cb_ = BindToCurrentLoop(output_cb); 61 output_cb_ = BindToCurrentLoop(output_cb);
63 62
64 if (!config.IsValidConfig()) { 63 if (!config.IsValidConfig()) {
65 DLOG(ERROR) << "Invalid audio stream config."; 64 DLOG(ERROR) << "Invalid audio stream config.";
66 base::ResetAndReturn(&init_cb_).Run(false); 65 base::ResetAndReturn(&init_cb_).Run(false);
67 return; 66 return;
68 } 67 }
69 68
70 // DecryptingAudioDecoder only accepts potentially encrypted stream. 69 // DecryptingAudioDecoder only accepts potentially encrypted stream.
71 if (!config.is_encrypted()) { 70 if (!config.is_encrypted()) {
72 base::ResetAndReturn(&init_cb_).Run(false); 71 base::ResetAndReturn(&init_cb_).Run(false);
73 return; 72 return;
74 } 73 }
75 74
76 config_ = config; 75 config_ = config;
77 76
78 if (state_ == kUninitialized) { 77 if (state_ == kUninitialized) {
78 DCHECK(!set_cdm_ready_cb.is_null());
79 state_ = kDecryptorRequested; 79 state_ = kDecryptorRequested;
80 set_cdm_ready_cb_ = set_cdm_ready_cb;
80 set_cdm_ready_cb_.Run(BindToCurrentLoop( 81 set_cdm_ready_cb_.Run(BindToCurrentLoop(
81 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_))); 82 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_)));
82 return; 83 return;
83 } 84 }
84 85
85 // Reinitialization (i.e. upon a config change) 86 // Reinitialization (i.e. upon a config change)
86 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 87 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
87 InitializeDecoder(); 88 InitializeDecoder();
88 } 89 }
89 90
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 366 }
366 367
367 frame->set_timestamp(current_time); 368 frame->set_timestamp(current_time);
368 timestamp_helper_->AddFrames(frame->frame_count()); 369 timestamp_helper_->AddFrames(frame->frame_count());
369 370
370 output_cb_.Run(frame); 371 output_cb_.Run(frame);
371 } 372 }
372 } 373 }
373 374
374 } // namespace media 375 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder.h ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698