| 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()); |
| 182 reset_cb_ = closure; | 183 reset_cb_ = closure; |
| 183 | 184 |
| 184 // Defer the reset if a read is pending. | 185 // Defer the reset if a read is pending. |
| 185 if (!read_cb_.is_null()) | 186 if (!read_cb_.is_null()) |
| 186 return; | 187 return; |
| 187 | 188 |
| 188 DoReset(); | 189 DoReset(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void FFmpegVideoDecoder::DoReset() { | 192 void FFmpegVideoDecoder::DoReset() { |
| 192 DCHECK(read_cb_.is_null()); | 193 DCHECK(read_cb_.is_null()); |
| 193 | 194 |
| 194 avcodec_flush_buffers(codec_context_); | 195 avcodec_flush_buffers(codec_context_); |
| 195 state_ = kNormal; | 196 state_ = kNormal; |
| 196 reset_cb_.Run(); | 197 reset_cb_.Run(); |
| 197 reset_cb_.Reset(); | 198 reset_cb_.Reset(); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { | 201 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { |
| 201 if (!message_loop_->BelongsToCurrentThread()) { | 202 if (!message_loop_->BelongsToCurrentThread()) { |
| 202 message_loop_->PostTask(FROM_HERE, base::Bind( | 203 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 203 &FFmpegVideoDecoder::Stop, this, closure)); | 204 &FFmpegVideoDecoder::Stop, this, closure)); |
| 204 return; | 205 return; |
| 205 } | 206 } |
| 206 | 207 |
| 208 DCHECK(stop_cb_.is_null()); |
| 209 stop_cb_ = closure; |
| 210 |
| 207 if (decryptor_) | 211 if (decryptor_) |
| 208 decryptor_->Stop(); | 212 decryptor_->Stop(); |
| 209 | 213 |
| 210 stop_cb_ = closure; | |
| 211 | |
| 212 // Defer stopping if a read is pending. | 214 // Defer stopping if a read is pending. |
| 213 if (!read_cb_.is_null()) | 215 if (!read_cb_.is_null()) |
| 214 return; | 216 return; |
| 215 | 217 |
| 216 DoStop(); | 218 DoStop(); |
| 217 } | 219 } |
| 218 | 220 |
| 219 void FFmpegVideoDecoder::DoStop() { | 221 void FFmpegVideoDecoder::DoStop() { |
| 220 ReleaseFFmpegResources(); | 222 ReleaseFFmpegResources(); |
| 221 state_ = kUninitialized; | 223 state_ = kUninitialized; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return false; | 525 return false; |
| 524 | 526 |
| 525 if (avcodec_open2(codec_context_, codec, NULL) < 0) | 527 if (avcodec_open2(codec_context_, codec, NULL) < 0) |
| 526 return false; | 528 return false; |
| 527 | 529 |
| 528 av_frame_ = avcodec_alloc_frame(); | 530 av_frame_ = avcodec_alloc_frame(); |
| 529 return true; | 531 return true; |
| 530 } | 532 } |
| 531 | 533 |
| 532 } // namespace media | 534 } // namespace media |
| OLD | NEW |