OLD | NEW |
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_video_decoder.h" | 5 #include "media/filters/decrypting_video_decoder.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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "media/base/bind_to_loop.h" | 13 #include "media/base/bind_to_loop.h" |
14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
15 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
16 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
17 #include "media/base/pipeline.h" | 17 #include "media/base/pipeline.h" |
18 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
19 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 DecryptingVideoDecoder::DecryptingVideoDecoder( | 23 DecryptingVideoDecoder::DecryptingVideoDecoder( |
24 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 24 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
25 const RequestDecryptorNotificationCB& request_decryptor_notification_cb) | 25 const SetDecryptorReadyCB& set_decryptor_ready_cb) |
26 : message_loop_(message_loop), | 26 : message_loop_(message_loop), |
27 state_(kUninitialized), | 27 state_(kUninitialized), |
28 request_decryptor_notification_cb_(request_decryptor_notification_cb), | 28 set_decryptor_ready_cb_(set_decryptor_ready_cb), |
29 decryptor_(NULL), | 29 decryptor_(NULL), |
30 key_added_while_decode_pending_(false), | 30 key_added_while_decode_pending_(false), |
31 trace_id_(0) { | 31 trace_id_(0) { |
32 } | 32 } |
33 | 33 |
34 void DecryptingVideoDecoder::Initialize( | 34 void DecryptingVideoDecoder::Initialize( |
35 const scoped_refptr<DemuxerStream>& stream, | 35 const scoped_refptr<DemuxerStream>& stream, |
36 const PipelineStatusCB& status_cb, | 36 const PipelineStatusCB& status_cb, |
37 const StatisticsCB& statistics_cb) { | 37 const StatisticsCB& statistics_cb) { |
38 DVLOG(2) << "Initialize()"; | 38 DVLOG(2) << "Initialize()"; |
(...skipping 14 matching lines...) Expand all Loading... |
53 if (!config.is_encrypted()) { | 53 if (!config.is_encrypted()) { |
54 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 54 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
55 return; | 55 return; |
56 } | 56 } |
57 | 57 |
58 DCHECK(!demuxer_stream_); | 58 DCHECK(!demuxer_stream_); |
59 demuxer_stream_ = stream; | 59 demuxer_stream_ = stream; |
60 statistics_cb_ = statistics_cb; | 60 statistics_cb_ = statistics_cb; |
61 | 61 |
62 state_ = kDecryptorRequested; | 62 state_ = kDecryptorRequested; |
63 request_decryptor_notification_cb_.Run(BindToCurrentLoop(base::Bind( | 63 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( |
64 &DecryptingVideoDecoder::SetDecryptor, this))); | 64 &DecryptingVideoDecoder::SetDecryptor, this))); |
65 } | 65 } |
66 | 66 |
67 void DecryptingVideoDecoder::Read(const ReadCB& read_cb) { | 67 void DecryptingVideoDecoder::Read(const ReadCB& read_cb) { |
68 DVLOG(3) << "Read()"; | 68 DVLOG(3) << "Read()"; |
69 DCHECK(message_loop_->BelongsToCurrentThread()); | 69 DCHECK(message_loop_->BelongsToCurrentThread()); |
70 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; | 70 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; |
71 DCHECK(!read_cb.is_null()); | 71 DCHECK(!read_cb.is_null()); |
72 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 72 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
73 read_cb_ = BindToCurrentLoop(read_cb); | 73 read_cb_ = BindToCurrentLoop(read_cb); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 // At this point the render thread is likely paused (in WebMediaPlayerImpl's | 123 // At this point the render thread is likely paused (in WebMediaPlayerImpl's |
124 // Destroy()), so running |closure| can't wait for anything that requires the | 124 // Destroy()), so running |closure| can't wait for anything that requires the |
125 // render thread to be processing messages to complete (such as PPAPI | 125 // render thread to be processing messages to complete (such as PPAPI |
126 // callbacks). | 126 // callbacks). |
127 if (decryptor_) { | 127 if (decryptor_) { |
128 decryptor_->RegisterKeyAddedCB(Decryptor::kVideo, Decryptor::KeyAddedCB()); | 128 decryptor_->RegisterKeyAddedCB(Decryptor::kVideo, Decryptor::KeyAddedCB()); |
129 decryptor_->DeinitializeDecoder(Decryptor::kVideo); | 129 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
130 decryptor_ = NULL; | 130 decryptor_ = NULL; |
131 } | 131 } |
132 if (!request_decryptor_notification_cb_.is_null()) { | 132 if (!set_decryptor_ready_cb_.is_null()) |
133 base::ResetAndReturn(&request_decryptor_notification_cb_).Run( | 133 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); |
134 DecryptorNotificationCB()); | |
135 } | |
136 pending_buffer_to_decode_ = NULL; | 134 pending_buffer_to_decode_ = NULL; |
137 if (!init_cb_.is_null()) | 135 if (!init_cb_.is_null()) |
138 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 136 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
139 if (!read_cb_.is_null()) | 137 if (!read_cb_.is_null()) |
140 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 138 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
141 if (!reset_cb_.is_null()) | 139 if (!reset_cb_.is_null()) |
142 base::ResetAndReturn(&reset_cb_).Run(); | 140 base::ResetAndReturn(&reset_cb_).Run(); |
143 state_ = kStopped; | 141 state_ = kStopped; |
144 BindToCurrentLoop(closure).Run(); | 142 BindToCurrentLoop(closure).Run(); |
145 } | 143 } |
146 | 144 |
147 DecryptingVideoDecoder::~DecryptingVideoDecoder() { | 145 DecryptingVideoDecoder::~DecryptingVideoDecoder() { |
148 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; | 146 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; |
149 } | 147 } |
150 | 148 |
151 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) { | 149 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) { |
152 DVLOG(2) << "SetDecryptor()"; | 150 DVLOG(2) << "SetDecryptor()"; |
153 DCHECK(message_loop_->BelongsToCurrentThread()); | 151 DCHECK(message_loop_->BelongsToCurrentThread()); |
154 | 152 |
155 if (state_ == kStopped) | 153 if (state_ == kStopped) |
156 return; | 154 return; |
157 | 155 |
158 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 156 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
159 DCHECK(!init_cb_.is_null()); | 157 DCHECK(!init_cb_.is_null()); |
160 DCHECK(!request_decryptor_notification_cb_.is_null()); | 158 DCHECK(!set_decryptor_ready_cb_.is_null()); |
161 request_decryptor_notification_cb_.Reset(); | 159 set_decryptor_ready_cb_.Reset(); |
162 | 160 |
163 decryptor_ = decryptor; | 161 decryptor_ = decryptor; |
164 | 162 |
165 scoped_ptr<VideoDecoderConfig> scoped_config(new VideoDecoderConfig()); | 163 scoped_ptr<VideoDecoderConfig> scoped_config(new VideoDecoderConfig()); |
166 scoped_config->CopyFrom(demuxer_stream_->video_decoder_config()); | 164 scoped_config->CopyFrom(demuxer_stream_->video_decoder_config()); |
167 | 165 |
168 state_ = kPendingDecoderInit; | 166 state_ = kPendingDecoderInit; |
169 decryptor_->InitializeVideoDecoder( | 167 decryptor_->InitializeVideoDecoder( |
170 scoped_config.Pass(), BindToCurrentLoop(base::Bind( | 168 scoped_config.Pass(), BindToCurrentLoop(base::Bind( |
171 &DecryptingVideoDecoder::FinishInitialization, this))); | 169 &DecryptingVideoDecoder::FinishInitialization, this))); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 356 } |
359 | 357 |
360 void DecryptingVideoDecoder::DoReset() { | 358 void DecryptingVideoDecoder::DoReset() { |
361 DCHECK(init_cb_.is_null()); | 359 DCHECK(init_cb_.is_null()); |
362 DCHECK(read_cb_.is_null()); | 360 DCHECK(read_cb_.is_null()); |
363 state_ = kIdle; | 361 state_ = kIdle; |
364 base::ResetAndReturn(&reset_cb_).Run(); | 362 base::ResetAndReturn(&reset_cb_).Run(); |
365 } | 363 } |
366 | 364 |
367 } // namespace media | 365 } // namespace media |
OLD | NEW |