| 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 |
| 210 if (state_ == kUninitialized) { | 213 if (state_ == kUninitialized) { |
| 211 closure.Run(); | 214 closure.Run(); |
| 212 return; | 215 return; |
| 213 } | 216 } |
| 214 | 217 |
| 218 stop_cb_ = closure; |
| 219 |
| 215 if (decryptor_) | 220 if (decryptor_) |
| 216 decryptor_->CancelDecrypt(); | 221 decryptor_->CancelDecrypt(); |
| 217 | 222 |
| 218 stop_cb_ = closure; | |
| 219 | |
| 220 // Defer stopping if a read is pending. | 223 // Defer stopping if a read is pending. |
| 221 if (!read_cb_.is_null()) | 224 if (!read_cb_.is_null()) |
| 222 return; | 225 return; |
| 223 | 226 |
| 224 DoStop(); | 227 DoStop(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 void FFmpegVideoDecoder::DoStop() { | 230 void FFmpegVideoDecoder::DoStop() { |
| 228 ReleaseFFmpegResources(); | 231 ReleaseFFmpegResources(); |
| 229 state_ = kUninitialized; | 232 state_ = kUninitialized; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { | 541 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
| 539 ReleaseFFmpegResources(); | 542 ReleaseFFmpegResources(); |
| 540 return false; | 543 return false; |
| 541 } | 544 } |
| 542 | 545 |
| 543 av_frame_ = avcodec_alloc_frame(); | 546 av_frame_ = avcodec_alloc_frame(); |
| 544 return true; | 547 return true; |
| 545 } | 548 } |
| 546 | 549 |
| 547 } // namespace media | 550 } // namespace media |
| OLD | NEW |