| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 // TODO(scherkus): this check should go in Pipeline prior to creating | 90 // TODO(scherkus): this check should go in Pipeline prior to creating |
| 91 // decoder objects. | 91 // decoder objects. |
| 92 if (!config.IsValidConfig()) { | 92 if (!config.IsValidConfig()) { |
| 93 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); | 93 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); |
| 94 status_cb.Run(PIPELINE_ERROR_DECODE); | 94 status_cb.Run(PIPELINE_ERROR_DECODE); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Initialize AVCodecContext structure. | 98 // Initialize AVCodecContext structure. |
| 99 codec_context_ = avcodec_alloc_context(); | 99 codec_context_ = avcodec_alloc_context3(NULL); |
| 100 VideoDecoderConfigToAVCodecContext(config, codec_context_); | 100 VideoDecoderConfigToAVCodecContext(config, codec_context_); |
| 101 | 101 |
| 102 // Enable motion vector search (potentially slow), strong deblocking filter | 102 // Enable motion vector search (potentially slow), strong deblocking filter |
| 103 // for damaged macroblocks, and set our error detection sensitivity. | 103 // for damaged macroblocks, and set our error detection sensitivity. |
| 104 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 104 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
| 105 codec_context_->err_recognition = AV_EF_CAREFUL; | 105 codec_context_->err_recognition = AV_EF_CAREFUL; |
| 106 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); | 106 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); |
| 107 | 107 |
| 108 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 108 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 109 if (!codec) { | 109 if (!codec) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // Create a packet for input data. | 316 // Create a packet for input data. |
| 317 // Due to FFmpeg API changes we no longer have const read-only pointers. | 317 // Due to FFmpeg API changes we no longer have const read-only pointers. |
| 318 AVPacket packet; | 318 AVPacket packet; |
| 319 av_init_packet(&packet); | 319 av_init_packet(&packet); |
| 320 packet.data = const_cast<uint8*>(buffer->GetData()); | 320 packet.data = const_cast<uint8*>(buffer->GetData()); |
| 321 packet.size = buffer->GetDataSize(); | 321 packet.size = buffer->GetDataSize(); |
| 322 | 322 |
| 323 // Let FFmpeg handle presentation timestamp reordering. | 323 // Let FFmpeg handle presentation timestamp reordering. |
| 324 codec_context_->reordered_opaque = buffer->GetTimestamp().InMicroseconds(); | 324 codec_context_->reordered_opaque = buffer->GetTimestamp().InMicroseconds(); |
| 325 | 325 |
| 326 // Reset frame to default values. |
| 327 avcodec_get_frame_defaults(av_frame_); |
| 328 |
| 326 // This is for codecs not using get_buffer to initialize | 329 // This is for codecs not using get_buffer to initialize |
| 327 // |av_frame_->reordered_opaque| | 330 // |av_frame_->reordered_opaque| |
| 328 av_frame_->reordered_opaque = codec_context_->reordered_opaque; | 331 av_frame_->reordered_opaque = codec_context_->reordered_opaque; |
| 329 | 332 |
| 330 int frame_decoded = 0; | 333 int frame_decoded = 0; |
| 331 int result = avcodec_decode_video2(codec_context_, | 334 int result = avcodec_decode_video2(codec_context_, |
| 332 av_frame_, | 335 av_frame_, |
| 333 &frame_decoded, | 336 &frame_decoded, |
| 334 &packet); | 337 &packet); |
| 335 // Log the problem if we can't decode a video frame and exit early. | 338 // Log the problem if we can't decode a video frame and exit early. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 428 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
| 426 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 429 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
| 427 size_t width = codec_context_->width; | 430 size_t width = codec_context_->width; |
| 428 size_t height = codec_context_->height; | 431 size_t height = codec_context_->height; |
| 429 | 432 |
| 430 return VideoFrame::CreateFrame(format, width, height, | 433 return VideoFrame::CreateFrame(format, width, height, |
| 431 kNoTimestamp(), kNoTimestamp()); | 434 kNoTimestamp(), kNoTimestamp()); |
| 432 } | 435 } |
| 433 | 436 |
| 434 } // namespace media | 437 } // namespace media |
| OLD | NEW |