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/ffmpeg_video_decoder.h" | 5 #include "media/filters/ffmpeg_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 &FFmpegVideoDecoder::DoRead, this, read_cb)); | 172 &FFmpegVideoDecoder::DoRead, this, read_cb)); |
173 } | 173 } |
174 | 174 |
175 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { | 175 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { |
176 if (!message_loop_->BelongsToCurrentThread()) { | 176 if (!message_loop_->BelongsToCurrentThread()) { |
177 message_loop_->PostTask(FROM_HERE, base::Bind( | 177 message_loop_->PostTask(FROM_HERE, base::Bind( |
178 &FFmpegVideoDecoder::Reset, this, closure)); | 178 &FFmpegVideoDecoder::Reset, this, closure)); |
179 return; | 179 return; |
180 } | 180 } |
181 | 181 |
| 182 DCHECK(reset_cb_.is_null()); |
| 183 reset_cb_ = closure; |
| 184 |
182 if (decryptor_) | 185 if (decryptor_) |
183 decryptor_->CancelDecrypt(); | 186 decryptor_->CancelDecrypt(); |
184 | 187 |
185 reset_cb_ = closure; | |
186 | |
187 // Defer the reset if a read is pending. | 188 // Defer the reset if a read is pending. |
188 if (!read_cb_.is_null()) | 189 if (!read_cb_.is_null()) |
189 return; | 190 return; |
190 | 191 |
191 DoReset(); | 192 DoReset(); |
192 } | 193 } |
193 | 194 |
194 void FFmpegVideoDecoder::DoReset() { | 195 void FFmpegVideoDecoder::DoReset() { |
195 DCHECK(read_cb_.is_null()); | 196 DCHECK(read_cb_.is_null()); |
196 | 197 |
197 avcodec_flush_buffers(codec_context_); | 198 avcodec_flush_buffers(codec_context_); |
198 state_ = kNormal; | 199 state_ = kNormal; |
199 reset_cb_.Run(); | 200 reset_cb_.Run(); |
200 reset_cb_.Reset(); | 201 reset_cb_.Reset(); |
201 } | 202 } |
202 | 203 |
203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { | 204 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { |
204 if (!message_loop_->BelongsToCurrentThread()) { | 205 if (!message_loop_->BelongsToCurrentThread()) { |
205 message_loop_->PostTask(FROM_HERE, base::Bind( | 206 message_loop_->PostTask(FROM_HERE, base::Bind( |
206 &FFmpegVideoDecoder::Stop, this, closure)); | 207 &FFmpegVideoDecoder::Stop, this, closure)); |
207 return; | 208 return; |
208 } | 209 } |
209 | 210 |
| 211 DCHECK(stop_cb_.is_null()); |
| 212 stop_cb_ = closure; |
| 213 |
210 if (decryptor_) | 214 if (decryptor_) |
211 decryptor_->CancelDecrypt(); | 215 decryptor_->CancelDecrypt(); |
212 | 216 |
213 stop_cb_ = closure; | |
214 | |
215 // Defer stopping if a read is pending. | 217 // Defer stopping if a read is pending. |
216 if (!read_cb_.is_null()) | 218 if (!read_cb_.is_null()) |
217 return; | 219 return; |
218 | 220 |
219 DoStop(); | 221 DoStop(); |
220 } | 222 } |
221 | 223 |
222 void FFmpegVideoDecoder::DoStop() { | 224 void FFmpegVideoDecoder::DoStop() { |
223 ReleaseFFmpegResources(); | 225 ReleaseFFmpegResources(); |
224 state_ = kUninitialized; | 226 state_ = kUninitialized; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 return false; | 534 return false; |
533 | 535 |
534 if (avcodec_open2(codec_context_, codec, NULL) < 0) | 536 if (avcodec_open2(codec_context_, codec, NULL) < 0) |
535 return false; | 537 return false; |
536 | 538 |
537 av_frame_ = avcodec_alloc_frame(); | 539 av_frame_ = avcodec_alloc_frame(); |
538 return true; | 540 return true; |
539 } | 541 } |
540 | 542 |
541 } // namespace media | 543 } // namespace media |
OLD | NEW |