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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 DCHECK_EQ(kUninitialized, state_); | 210 DCHECK_EQ(kUninitialized, state_); |
211 DCHECK(!codec_context_); | 211 DCHECK(!codec_context_); |
212 DCHECK(!av_frame_); | 212 DCHECK(!av_frame_); |
213 } | 213 } |
214 | 214 |
215 void FFmpegVideoDecoder::ReadFromDemuxerStream() { | 215 void FFmpegVideoDecoder::ReadFromDemuxerStream() { |
216 DCHECK_NE(state_, kUninitialized); | 216 DCHECK_NE(state_, kUninitialized); |
217 DCHECK_NE(state_, kDecodeFinished); | 217 DCHECK_NE(state_, kDecodeFinished); |
218 DCHECK(!read_cb_.is_null()); | 218 DCHECK(!read_cb_.is_null()); |
219 | 219 |
220 demuxer_stream_->Read(base::Bind( | 220 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::BufferReady, this)); |
221 &FFmpegVideoDecoder::BufferReady, this)); | |
222 } | 221 } |
223 | 222 |
224 void FFmpegVideoDecoder::BufferReady( | 223 void FFmpegVideoDecoder::BufferReady( |
225 DemuxerStream::Status status, | 224 DemuxerStream::Status status, |
226 const scoped_refptr<DecoderBuffer>& buffer) { | 225 const scoped_refptr<DecoderBuffer>& buffer) { |
227 DCHECK(message_loop_->BelongsToCurrentThread()); | 226 DCHECK(message_loop_->BelongsToCurrentThread()); |
228 DCHECK_NE(state_, kDecodeFinished); | 227 DCHECK_NE(state_, kDecodeFinished); |
229 DCHECK_EQ(status != DemuxerStream::kOk, !buffer) << status; | 228 DCHECK_EQ(status != DemuxerStream::kOk, !buffer) << status; |
230 | 229 |
231 if (state_ == kUninitialized) | 230 if (state_ == kUninitialized) |
232 return; | 231 return; |
233 | 232 |
234 DCHECK(!read_cb_.is_null()); | 233 DCHECK(!read_cb_.is_null()); |
235 | 234 |
| 235 if (status == DemuxerStream::kConfigChanged) { |
| 236 if (!ConfigureDecoder()) { |
| 237 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
| 238 state_ = kDecodeFinished; |
| 239 if (!reset_cb_.is_null()) |
| 240 base::ResetAndReturn(&reset_cb_).Run(); |
| 241 return; |
| 242 } |
| 243 |
| 244 if (reset_cb_.is_null()) { |
| 245 ReadFromDemuxerStream(); |
| 246 return; |
| 247 } |
| 248 } |
| 249 |
236 if (!reset_cb_.is_null()) { | 250 if (!reset_cb_.is_null()) { |
237 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 251 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
238 DoReset(); | 252 DoReset(); |
239 return; | 253 return; |
240 } | 254 } |
241 | 255 |
242 if (status == DemuxerStream::kAborted) { | 256 if (status == DemuxerStream::kAborted) { |
243 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 257 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
244 return; | 258 return; |
245 } | 259 } |
246 | 260 |
247 if (status == DemuxerStream::kConfigChanged) { | |
248 if (!ConfigureDecoder()) { | |
249 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | |
250 return; | |
251 } | |
252 | |
253 ReadFromDemuxerStream(); | |
254 return; | |
255 } | |
256 | |
257 DCHECK_EQ(status, DemuxerStream::kOk); | 261 DCHECK_EQ(status, DemuxerStream::kOk); |
258 DecodeBuffer(buffer); | 262 DecodeBuffer(buffer); |
259 } | 263 } |
260 | 264 |
261 void FFmpegVideoDecoder::DecodeBuffer( | 265 void FFmpegVideoDecoder::DecodeBuffer( |
262 const scoped_refptr<DecoderBuffer>& buffer) { | 266 const scoped_refptr<DecoderBuffer>& buffer) { |
263 DCHECK(message_loop_->BelongsToCurrentThread()); | 267 DCHECK(message_loop_->BelongsToCurrentThread()); |
264 DCHECK_NE(state_, kUninitialized); | 268 DCHECK_NE(state_, kUninitialized); |
265 DCHECK_NE(state_, kDecodeFinished); | 269 DCHECK_NE(state_, kDecodeFinished); |
266 DCHECK(reset_cb_.is_null()); | 270 DCHECK(reset_cb_.is_null()); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { | 446 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
443 ReleaseFFmpegResources(); | 447 ReleaseFFmpegResources(); |
444 return false; | 448 return false; |
445 } | 449 } |
446 | 450 |
447 av_frame_ = avcodec_alloc_frame(); | 451 av_frame_ = avcodec_alloc_frame(); |
448 return true; | 452 return true; |
449 } | 453 } |
450 | 454 |
451 } // namespace media | 455 } // namespace media |
OLD | NEW |