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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 reset_cb_.Reset(); | 200 reset_cb_.Reset(); |
201 } | 201 } |
202 | 202 |
203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { | 203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { |
204 if (!message_loop_->BelongsToCurrentThread()) { | 204 if (!message_loop_->BelongsToCurrentThread()) { |
205 message_loop_->PostTask(FROM_HERE, base::Bind( | 205 message_loop_->PostTask(FROM_HERE, base::Bind( |
206 &FFmpegVideoDecoder::Stop, this, closure)); | 206 &FFmpegVideoDecoder::Stop, this, closure)); |
207 return; | 207 return; |
208 } | 208 } |
209 | 209 |
| 210 if (state_ == kUninitialized) { |
| 211 closure.Run(); |
| 212 return; |
| 213 } |
| 214 |
210 if (decryptor_) | 215 if (decryptor_) |
211 decryptor_->CancelDecrypt(); | 216 decryptor_->CancelDecrypt(); |
212 | 217 |
213 stop_cb_ = closure; | 218 stop_cb_ = closure; |
214 | 219 |
215 // Defer stopping if a read is pending. | 220 // Defer stopping if a read is pending. |
216 if (!read_cb_.is_null()) | 221 if (!read_cb_.is_null()) |
217 return; | 222 return; |
218 | 223 |
219 DoStop(); | 224 DoStop(); |
220 } | 225 } |
221 | 226 |
222 void FFmpegVideoDecoder::DoStop() { | 227 void FFmpegVideoDecoder::DoStop() { |
223 ReleaseFFmpegResources(); | 228 ReleaseFFmpegResources(); |
224 state_ = kUninitialized; | 229 state_ = kUninitialized; |
225 base::ResetAndReturn(&stop_cb_).Run(); | 230 base::ResetAndReturn(&stop_cb_).Run(); |
226 } | 231 } |
227 | 232 |
228 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | 233 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
229 ReleaseFFmpegResources(); | 234 DCHECK_EQ(kUninitialized, state_); |
230 } | 235 } |
231 | 236 |
232 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { | 237 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { |
233 DCHECK(message_loop_->BelongsToCurrentThread()); | 238 DCHECK(message_loop_->BelongsToCurrentThread()); |
234 DCHECK(!read_cb.is_null()); | 239 DCHECK(!read_cb.is_null()); |
235 CHECK_NE(state_, kUninitialized); | 240 CHECK_NE(state_, kUninitialized); |
236 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 241 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
237 | 242 |
238 // Return empty frames if decoding has finished. | 243 // Return empty frames if decoding has finished. |
239 if (state_ == kDecodeFinished) { | 244 if (state_ == kDecodeFinished) { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 return false; | 537 return false; |
533 | 538 |
534 if (avcodec_open2(codec_context_, codec, NULL) < 0) | 539 if (avcodec_open2(codec_context_, codec, NULL) < 0) |
535 return false; | 540 return false; |
536 | 541 |
537 av_frame_ = avcodec_alloc_frame(); | 542 av_frame_ = avcodec_alloc_frame(); |
538 return true; | 543 return true; |
539 } | 544 } |
540 | 545 |
541 } // namespace media | 546 } // namespace media |
OLD | NEW |