Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: media/filters/ffmpeg_video_decoder.cc

Issue 10248002: Report VideoDecoder status through ReadCB instead of through FilterHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename VideoDecoder::Status to VideoDecoder::DecoderStatus since Status has been polluted by Xlib.h. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/filters.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
11 #include "media/base/demuxer_stream.h" 12 #include "media/base/demuxer_stream.h"
12 #include "media/base/filter_host.h"
13 #include "media/base/limits.h" 13 #include "media/base/limits.h"
14 #include "media/base/media_switches.h" 14 #include "media/base/media_switches.h"
15 #include "media/base/pipeline.h" 15 #include "media/base/pipeline.h"
16 #include "media/base/video_decoder_config.h" 16 #include "media/base/video_decoder_config.h"
17 #include "media/base/video_frame.h" 17 #include "media/base/video_frame.h"
18 #include "media/base/video_util.h" 18 #include "media/base/video_util.h"
19 #include "media/ffmpeg/ffmpeg_common.h" 19 #include "media/ffmpeg/ffmpeg_common.h"
20 20
21 namespace media { 21 namespace media {
22 22
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 DCHECK(!read_cb.is_null()); 205 DCHECK(!read_cb.is_null());
206 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 206 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
207 207
208 // This can happen during shutdown after Stop() has been called. 208 // This can happen during shutdown after Stop() has been called.
209 if (state_ == kUninitialized) { 209 if (state_ == kUninitialized) {
210 return; 210 return;
211 } 211 }
212 212
213 // Return empty frames if decoding has finished. 213 // Return empty frames if decoding has finished.
214 if (state_ == kDecodeFinished) { 214 if (state_ == kDecodeFinished) {
215 read_cb.Run(VideoFrame::CreateEmptyFrame()); 215 read_cb.Run(kOk, VideoFrame::CreateEmptyFrame());
216 return; 216 return;
217 } 217 }
218 218
219 read_cb_ = read_cb; 219 read_cb_ = read_cb;
220 ReadFromDemuxerStream(); 220 ReadFromDemuxerStream();
221 } 221 }
222 222
223 223
224 void FFmpegVideoDecoder::ReadFromDemuxerStream() { 224 void FFmpegVideoDecoder::ReadFromDemuxerStream() {
225 DCHECK_NE(state_, kUninitialized); 225 DCHECK_NE(state_, kUninitialized);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Transition to kFlushCodec on the first end of stream buffer. 281 // Transition to kFlushCodec on the first end of stream buffer.
282 if (state_ == kNormal && buffer->IsEndOfStream()) { 282 if (state_ == kNormal && buffer->IsEndOfStream()) {
283 state_ = kFlushCodec; 283 state_ = kFlushCodec;
284 } 284 }
285 285
286 scoped_refptr<Buffer> unencrypted_buffer = buffer; 286 scoped_refptr<Buffer> unencrypted_buffer = buffer;
287 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { 287 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) {
288 unencrypted_buffer = decryptor_.Decrypt(buffer); 288 unencrypted_buffer = decryptor_.Decrypt(buffer);
289 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) { 289 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) {
290 state_ = kDecodeFinished; 290 state_ = kDecodeFinished;
291 DeliverFrame(VideoFrame::CreateEmptyFrame()); 291 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL);
292 host()->SetError(PIPELINE_ERROR_DECRYPT);
293 return; 292 return;
294 } 293 }
295 } 294 }
296 295
297 scoped_refptr<VideoFrame> video_frame; 296 scoped_refptr<VideoFrame> video_frame;
298 if (!Decode(unencrypted_buffer, &video_frame)) { 297 if (!Decode(unencrypted_buffer, &video_frame)) {
299 state_ = kDecodeFinished; 298 state_ = kDecodeFinished;
300 DeliverFrame(VideoFrame::CreateEmptyFrame()); 299 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL);
301 host()->SetError(PIPELINE_ERROR_DECODE);
302 return; 300 return;
303 } 301 }
304 302
305 // Any successful decode counts! 303 // Any successful decode counts!
306 if (buffer->GetDataSize()) { 304 if (buffer->GetDataSize()) {
307 PipelineStatistics statistics; 305 PipelineStatistics statistics;
308 statistics.video_bytes_decoded = buffer->GetDataSize(); 306 statistics.video_bytes_decoded = buffer->GetDataSize();
309 statistics_cb_.Run(statistics); 307 statistics_cb_.Run(statistics);
310 } 308 }
311 309
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 CopyYPlane(av_frame_->data[0], av_frame_->linesize[0], y_rows, *video_frame); 414 CopyYPlane(av_frame_->data[0], av_frame_->linesize[0], y_rows, *video_frame);
417 CopyUPlane(av_frame_->data[1], av_frame_->linesize[1], uv_rows, *video_frame); 415 CopyUPlane(av_frame_->data[1], av_frame_->linesize[1], uv_rows, *video_frame);
418 CopyVPlane(av_frame_->data[2], av_frame_->linesize[2], uv_rows, *video_frame); 416 CopyVPlane(av_frame_->data[2], av_frame_->linesize[2], uv_rows, *video_frame);
419 417
420 return true; 418 return true;
421 } 419 }
422 420
423 void FFmpegVideoDecoder::DeliverFrame( 421 void FFmpegVideoDecoder::DeliverFrame(
424 const scoped_refptr<VideoFrame>& video_frame) { 422 const scoped_refptr<VideoFrame>& video_frame) {
425 // Reset the callback before running to protect against reentrancy. 423 // Reset the callback before running to protect against reentrancy.
426 ReadCB read_cb = read_cb_; 424 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame);
427 read_cb_.Reset();
428 read_cb.Run(video_frame);
429 } 425 }
430 426
431 void FFmpegVideoDecoder::ReleaseFFmpegResources() { 427 void FFmpegVideoDecoder::ReleaseFFmpegResources() {
432 if (codec_context_) { 428 if (codec_context_) {
433 av_free(codec_context_->extradata); 429 av_free(codec_context_->extradata);
434 avcodec_close(codec_context_); 430 avcodec_close(codec_context_);
435 av_free(codec_context_); 431 av_free(codec_context_);
436 codec_context_ = NULL; 432 codec_context_ = NULL;
437 } 433 }
438 if (av_frame_) { 434 if (av_frame_) {
439 av_free(av_frame_); 435 av_free(av_frame_);
440 av_frame_ = NULL; 436 av_frame_ = NULL;
441 } 437 }
442 } 438 }
443 439
444 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { 440 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() {
445 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); 441 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt);
446 size_t width = codec_context_->width; 442 size_t width = codec_context_->width;
447 size_t height = codec_context_->height; 443 size_t height = codec_context_->height;
448 444
449 return VideoFrame::CreateFrame(format, width, height, 445 return VideoFrame::CreateFrame(format, width, height,
450 kNoTimestamp(), kNoTimestamp()); 446 kNoTimestamp(), kNoTimestamp());
451 } 447 }
452 448
453 } // namespace media 449 } // namespace media
OLDNEW
« no previous file with comments | « media/base/filters.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698