summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 23:06:45 +0000
committerdalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 23:06:45 +0000
commit7a032766439f88961cf02aa8b06e31c865c30692 (patch)
treea8aba2889c7644e184728b287ceb95eb165e0250 /media
parentdc6ea7623f8289de35907a940e1e980b65f16aae (diff)
downloadchromium_src-7a032766439f88961cf02aa8b06e31c865c30692.zip
chromium_src-7a032766439f88961cf02aa8b06e31c865c30692.tar.gz
chromium_src-7a032766439f88961cf02aa8b06e31c865c30692.tar.bz2
Fix media code to work with new ffmpeg.
Once ffmpeg git, svn are updated to new ffmpeg, will update DEPS in this CL. Which when committed, should seal the deal for the ffmpeg roll. API Changes: avutil: SampleFormat->AVSampleFormat avutil: av_get_bits_per_sample_fmt -> av_get_bytes_per_sample avcodec: avcodec_open -> avcodec_open2(..., NULL) avcodec: avcodec_decode_video2(... AVPacket ...) -> const AVPacket. avformat: av_open_input_file -> avformat_open_input avformat: av_register_protocol2 -> ffurl_register_protocol avformat: av_close_input_file -> avformat_close_input(&...) avformat: av_find_stream_info -> avformat_find_stream_info(..., NULL) URLContext now has a url_open2 method as well, for now I've set this to NULL. Also fixes: - ffmpeg_unittests change threading to mirror ffmpeg_video_decoder. There's an issue where threading causes the last frames of a no-audio video to be clipped. It existed before this ffmpeg roll, but because threading was disabled by default in ffmpeg, we never noticed it. - ffmpeg_demuxer_tests: GetBitrate_UnsetInContainer_NoFileSize now passes. - New ffmpeg_unittests passes: sync0_ogv/FFmpegTest.Seek_Video/0, where GetParam() = "sync0.ogv" sync1_ogv/FFmpegTest.Seek_Video/0, where GetParam() = "sync1.ogv" sync2_ogv/FFmpegTest.Seek_Video/0, where GetParam() = "sync2.ogv" FFmpeg fixups here, https://chromiumcodereview.appspot.com/9325049/ New git repo here: http://git.chromium.org/gitweb/?p=chromium/third_party/ffmpeg.git;a=summary Merge+Patches diff: https://chromiumcodereview.appspot.com/9317107 BUG=110776 TEST=unittests, layouttests, etc. Trybots. Review URL: https://chromiumcodereview.appspot.com/9317096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123123 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/audio_decoder_config.h3
-rw-r--r--media/base/media_posix.cc6
-rw-r--r--media/base/media_win.cc6
-rw-r--r--media/ffmpeg/ffmpeg_common.cc38
-rw-r--r--media/ffmpeg/ffmpeg_common.h1
-rw-r--r--media/ffmpeg/ffmpeg_regression_tests.cc49
-rw-r--r--media/ffmpeg/ffmpeg_unittest.cc34
-rw-r--r--media/ffmpeg/file_protocol.cc3
-rw-r--r--media/filters/audio_file_reader.cc16
-rw-r--r--media/filters/ffmpeg_audio_decoder.cc2
-rw-r--r--media/filters/ffmpeg_demuxer.cc4
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc8
-rw-r--r--media/filters/ffmpeg_glue.cc6
-rw-r--r--media/filters/ffmpeg_glue.h34
-rw-r--r--media/filters/ffmpeg_glue_unittest.cc4
-rw-r--r--media/filters/ffmpeg_video_decoder.cc4
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc2
-rw-r--r--media/test/ffmpeg_tests/ffmpeg_tests.cc15
-rw-r--r--media/tools/media_bench/media_bench.cc17
-rw-r--r--media/webm/webm_stream_parser.cc6
20 files changed, 143 insertions, 115 deletions
diff --git a/media/base/audio_decoder_config.h b/media/base/audio_decoder_config.h
index 90f51c1..6e58c5b 100644
--- a/media/base/audio_decoder_config.h
+++ b/media/base/audio_decoder_config.h
@@ -35,6 +35,9 @@ enum AudioCodec {
kAudioCodecMax = kCodecPCM_MULAW // Must equal the last "real" codec above.
};
+// TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
+// |bits_per_channel|, we should switch over since bits are generally confusing
+// to work with.
class MEDIA_EXPORT AudioDecoderConfig {
public:
// Constructs an uninitialized object. Clients should call Initialize() with
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc
index 7be3255..52ad34f 100644
--- a/media/base/media_posix.cc
+++ b/media/base/media_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -55,9 +55,9 @@ static std::string GetDSOName(tp_ffmpeg::StubModules stub_key) {
// TODO(ajwong): Remove this once mac is migrated. Either that, or have GYP
// set a constant that we can switch implementations based off of.
switch (stub_key) {
- case tp_ffmpeg::kModuleAvcodec53:
+ case tp_ffmpeg::kModuleAvcodec54:
return FILE_PATH_LITERAL(DSO_NAME("avcodec", AVCODEC_VERSION));
- case tp_ffmpeg::kModuleAvformat53:
+ case tp_ffmpeg::kModuleAvformat54:
return FILE_PATH_LITERAL(DSO_NAME("avformat", AVFORMAT_VERSION));
case tp_ffmpeg::kModuleAvutil51:
return FILE_PATH_LITERAL(DSO_NAME("avutil", AVUTIL_VERSION));
diff --git a/media/base/media_win.cc b/media/base/media_win.cc
index 9462c02..e8c0368 100644
--- a/media/base/media_win.cc
+++ b/media/base/media_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,9 +25,9 @@ static FilePath::CharType* GetDLLName(FFmpegDLLKeys dll_key) {
// TODO(ajwong): Do we want to lock to a specific ffmpeg version?
switch (dll_key) {
case FILE_LIBAVCODEC:
- return FILE_PATH_LITERAL("avcodec-53.dll");
+ return FILE_PATH_LITERAL("avcodec-54.dll");
case FILE_LIBAVFORMAT:
- return FILE_PATH_LITERAL("avformat-53.dll");
+ return FILE_PATH_LITERAL("avformat-54.dll");
case FILE_LIBAVUTIL:
return FILE_PATH_LITERAL("avutil-51.dll");
default:
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc
index 4fc7f4e..978aff0 100644
--- a/media/ffmpeg/ffmpeg_common.cc
+++ b/media/ffmpeg/ffmpeg_common.cc
@@ -178,14 +178,14 @@ void AVCodecContextToAudioDecoderConfig(
DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO);
AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id);
- int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt);
+ int bytes_per_channel = av_get_bytes_per_sample(codec_context->sample_fmt);
ChannelLayout channel_layout =
ChannelLayoutToChromeChannelLayout(codec_context->channel_layout,
codec_context->channels);
int samples_per_second = codec_context->sample_rate;
config->Initialize(codec,
- bits_per_channel,
+ bytes_per_channel << 3,
channel_layout,
samples_per_second,
codec_context->extradata,
@@ -289,35 +289,35 @@ void VideoDecoderConfigToAVCodecContext(
ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout,
int channels) {
switch (layout) {
- case CH_LAYOUT_MONO:
+ case AV_CH_LAYOUT_MONO:
return CHANNEL_LAYOUT_MONO;
- case CH_LAYOUT_STEREO:
+ case AV_CH_LAYOUT_STEREO:
return CHANNEL_LAYOUT_STEREO;
- case CH_LAYOUT_2_1:
+ case AV_CH_LAYOUT_2_1:
return CHANNEL_LAYOUT_2_1;
- case CH_LAYOUT_SURROUND:
+ case AV_CH_LAYOUT_SURROUND:
return CHANNEL_LAYOUT_SURROUND;
- case CH_LAYOUT_4POINT0:
+ case AV_CH_LAYOUT_4POINT0:
return CHANNEL_LAYOUT_4POINT0;
- case CH_LAYOUT_2_2:
+ case AV_CH_LAYOUT_2_2:
return CHANNEL_LAYOUT_2_2;
- case CH_LAYOUT_QUAD:
+ case AV_CH_LAYOUT_QUAD:
return CHANNEL_LAYOUT_QUAD;
- case CH_LAYOUT_5POINT0:
+ case AV_CH_LAYOUT_5POINT0:
return CHANNEL_LAYOUT_5POINT0;
- case CH_LAYOUT_5POINT1:
+ case AV_CH_LAYOUT_5POINT1:
return CHANNEL_LAYOUT_5POINT1;
- case CH_LAYOUT_5POINT0_BACK:
+ case AV_CH_LAYOUT_5POINT0_BACK:
return CHANNEL_LAYOUT_5POINT0_BACK;
- case CH_LAYOUT_5POINT1_BACK:
+ case AV_CH_LAYOUT_5POINT1_BACK:
return CHANNEL_LAYOUT_5POINT1_BACK;
- case CH_LAYOUT_7POINT0:
+ case AV_CH_LAYOUT_7POINT0:
return CHANNEL_LAYOUT_7POINT0;
- case CH_LAYOUT_7POINT1:
+ case AV_CH_LAYOUT_7POINT1:
return CHANNEL_LAYOUT_7POINT1;
- case CH_LAYOUT_7POINT1_WIDE:
+ case AV_CH_LAYOUT_7POINT1_WIDE:
return CHANNEL_LAYOUT_7POINT1_WIDE;
- case CH_LAYOUT_STEREO_DOWNMIX:
+ case AV_CH_LAYOUT_STEREO_DOWNMIX:
return CHANNEL_LAYOUT_STEREO_DOWNMIX;
default:
// FFmpeg channel_layout is 0 for .wav and .mp3. We know mono and stereo
@@ -376,7 +376,7 @@ void DestroyAVFormatContext(AVFormatContext* format_context) {
// 1. AVStream is alive.
// 2. AVCodecContext in AVStream is alive.
// 3. AVCodec in AVCodecContext is alive.
- // Notice that closing a codec context without prior avcodec_open() will
+ // Notice that closing a codec context without prior avcodec_open2() will
// result in a crash in FFmpeg.
if (stream && stream->codec && stream->codec->codec) {
stream->discard = AVDISCARD_ALL;
@@ -386,7 +386,7 @@ void DestroyAVFormatContext(AVFormatContext* format_context) {
}
// Then finally cleanup the format context.
- av_close_input_file(format_context);
+ avformat_close_input(&format_context);
}
} // namespace media
diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h
index 6ebd5fa..22ddb7c 100644
--- a/media/ffmpeg/ffmpeg_common.h
+++ b/media/ffmpeg/ffmpeg_common.h
@@ -22,6 +22,7 @@ MSVC_PUSH_DISABLE_WARNING(4244);
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
+#include <libavformat/url.h>
#include <libavutil/avutil.h>
#include <libavutil/mathematics.h>
#include <libavutil/log.h>
diff --git a/media/ffmpeg/ffmpeg_regression_tests.cc b/media/ffmpeg/ffmpeg_regression_tests.cc
index 8df6c10..9b7d2dd 100644
--- a/media/ffmpeg/ffmpeg_regression_tests.cc
+++ b/media/ffmpeg/ffmpeg_regression_tests.cc
@@ -1,6 +1,18 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+//
+// Regression tests for FFmpeg. Security test files can be found in the
+// internal media test data directory:
+//
+// svn://svn.chromium.org/chrome-internal/trunk/data/media/security/
+//
+// Simply symlink or copy the security directory into media/test/data folder and
+// build the ffmpeg_regression_tests target to run these tests.
+//
+// Many of the files here do not cause issues outside of tooling, so you'll need
+// to run this test under ASAN, TSAN, and Valgrind to ensure that all issues are
+// caught.
#include "media/filters/pipeline_integration_test_base.h"
@@ -36,8 +48,6 @@ class FFmpegRegressionTest
// Test cases from issues.
FFMPEG_TEST_CASE(Cr93620, "security/93620.ogg", PIPELINE_OK, PIPELINE_OK);
-FFMPEG_TEST_CASE(Cr99652, "security/99652.webm", PIPELINE_OK,
- PIPELINE_ERROR_DECODE);
FFMPEG_TEST_CASE(Cr100492, "security/100492.webm", DECODER_ERROR_NOT_SUPPORTED,
DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(Cr100543, "security/100543.webm", PIPELINE_OK, PIPELINE_OK);
@@ -72,19 +82,12 @@ FFMPEG_TEST_CASE(MP4_9, "security/smclockmp4aac_1_0.mp4",
DEMUXER_ERROR_COULD_NOT_OPEN, DEMUXER_ERROR_COULD_NOT_OPEN);
// General OGV test cases.
-FFMPEG_TEST_CASE(OGV_0, "security/big_dims.ogv", PIPELINE_ERROR_DECODE,
- PIPELINE_ERROR_DECODE);
FFMPEG_TEST_CASE(OGV_1, "security/out.163.ogv", DECODER_ERROR_NOT_SUPPORTED,
DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(OGV_2, "security/out.391.ogv", DECODER_ERROR_NOT_SUPPORTED,
DECODER_ERROR_NOT_SUPPORTED);
-FFMPEG_TEST_CASE(OGV_3, "security/smclock_1_0.ogv", PIPELINE_OK, PIPELINE_OK);
-FFMPEG_TEST_CASE(OGV_4, "security/smclock.ogv.1.0.ogv", PIPELINE_OK,
- PIPELINE_OK);
FFMPEG_TEST_CASE(OGV_5, "security/smclocktheora_1_0.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
-FFMPEG_TEST_CASE(OGV_6, "security/smclocktheora_1_10000.ogv",
- PIPELINE_ERROR_DECODE, PIPELINE_ERROR_DECODE);
FFMPEG_TEST_CASE(OGV_7, "security/smclocktheora_1_102.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(OGV_8, "security/smclocktheora_1_104.ogv",
@@ -97,14 +100,16 @@ FFMPEG_TEST_CASE(OGV_11, "security/smclocktheora_1_20.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(OGV_12, "security/smclocktheora_1_723.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
-FFMPEG_TEST_CASE(OGV_13, "security/smclocktheora_1_790.ogv", PIPELINE_OK,
- PIPELINE_OK);
FFMPEG_TEST_CASE(OGV_14, "security/smclocktheora_2_10405.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
+FFMPEG_TEST_CASE(OGV_15, "security/smclocktheora_2_10619.ogv",
+ DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(OGV_16, "security/smclocktheora_2_1075.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
FFMPEG_TEST_CASE(OGV_17, "security/vorbis.482086.ogv",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
+FFMPEG_TEST_CASE(OGV_18, "security/wav.711.ogv", DECODER_ERROR_NOT_SUPPORTED,
+ DECODER_ERROR_NOT_SUPPORTED);
// General WebM test cases.
FFMPEG_TEST_CASE(WEBM_1, "security/no-bug.webm", PIPELINE_OK, PIPELINE_OK);
@@ -115,15 +120,25 @@ FFMPEG_TEST_CASE(WEBM_3, "security/out.webm.139771.2965",
FFMPEG_TEST_CASE(WEBM_4, "security/out.webm.68798.1929",
DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
-// Flaky, maybe larger issues.
-FFMPEG_TEST_CASE(Cr100464, "security/100464.webm", PIPELINE_OK,
+// Flaky, maybe larger issues. All eventually fail in the browser.
+FFMPEG_TEST_CASE(FLAKY_Cr99652, "security/99652.webm", PIPELINE_OK,
+ PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_Cr100464, "security/100464.webm", PIPELINE_OK,
+ PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_Cr111342, "security/111342.ogm", PIPELINE_OK,
PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_OGV_0, "security/big_dims.ogv", PIPELINE_OK,
+ PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_OGV_3, "security/smclock_1_0.ogv", PIPELINE_ERROR_DECODE,
+ PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_OGV_4, "security/smclock.ogv.1.0.ogv",
+ PIPELINE_OK, PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_OGV_6, "security/smclocktheora_1_10000.ogv",
+ PIPELINE_OK, PIPELINE_ERROR_DECODE);
+FFMPEG_TEST_CASE(FLAKY_OGV_13, "security/smclocktheora_1_790.ogv",
+ PIPELINE_ERROR_DECODE, PIPELINE_ERROR_DECODE);
// Current crashers.
-// FFMPEG_TEST_CASE(Cr111342, "security/111342.ogm", PIPELINE_OK, PIPELINE_OK);
-// FFMPEG_TEST_CASE(OGV_15, "security/smclocktheora_2_10619.ogv",
-// DECODER_ERROR_NOT_SUPPORTED, DECODER_ERROR_NOT_SUPPORTED);
-// FFMPEG_TEST_CASE(OGV_18, "security/wav.711.ogv", PIPELINE_OK, PIPELINE_OK);
// FFMPEG_TEST_CASE(Cr112976, "security/112976.ogg", PIPELINE_OK, PIPELINE_OK);
// Clock failures. http://crbug.com/113037
diff --git a/media/ffmpeg/ffmpeg_unittest.cc b/media/ffmpeg/ffmpeg_unittest.cc
index 9e377aa..121f0a6 100644
--- a/media/ffmpeg/ffmpeg_unittest.cc
+++ b/media/ffmpeg/ffmpeg_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -46,6 +46,9 @@ int main(int argc, char** argv) {
namespace media {
+// Mirror setting in ffmpeg_video_decoder.
+static const int kDecodeThreads = 2;
+
class AVPacketQueue {
public:
AVPacketQueue() {
@@ -87,6 +90,8 @@ class AVPacketQueue {
DISALLOW_COPY_AND_ASSIGN(AVPacketQueue);
};
+// TODO(dalecurtis): We should really just use PipelineIntegrationTests instead
+// of a one-off step decoder so we're exercising the real pipeline.
class FFmpegTest : public testing::TestWithParam<const char*> {
protected:
FFmpegTest()
@@ -133,18 +138,18 @@ class FFmpegTest : public testing::TestWithParam<const char*> {
std::string ascii_path = path.value();
#endif
- EXPECT_EQ(0, av_open_input_file(&av_format_context_,
- ascii_path.c_str(),
- NULL, 0, NULL))
+ EXPECT_EQ(0, avformat_open_input(&av_format_context_,
+ ascii_path.c_str(),
+ NULL, NULL))
<< "Could not open " << path.value();
- EXPECT_LE(0, av_find_stream_info(av_format_context_))
+ EXPECT_LE(0, avformat_find_stream_info(av_format_context_, NULL))
<< "Could not find stream information for " << path.value();
// Determine duration by picking max stream duration.
for (unsigned int i = 0; i < av_format_context_->nb_streams; ++i) {
AVStream* av_stream = av_format_context_->streams[i];
- int64 duration = ConvertFromTimeBase(av_stream->time_base,
- av_stream->duration).InMicroseconds();
+ int64 duration = ConvertFromTimeBase(
+ av_stream->time_base, av_stream->duration).InMicroseconds();
duration_ = std::max(duration_, duration);
}
@@ -152,12 +157,12 @@ class FFmpegTest : public testing::TestWithParam<const char*> {
AVRational av_time_base = {1, AV_TIME_BASE};
int64 duration =
ConvertFromTimeBase(av_time_base,
- av_format_context_->duration).InMicroseconds();
+ av_format_context_->duration).InMicroseconds();
duration_ = std::max(duration_, duration);
}
void CloseFile() {
- av_close_input_file(av_format_context_);
+ avformat_close_input(&av_format_context_);
}
void OpenCodecs() {
@@ -169,7 +174,13 @@ class FFmpegTest : public testing::TestWithParam<const char*> {
EXPECT_TRUE(av_codec)
<< "Could not find AVCodec with CodecID "
<< av_codec_context->codec_id;
- EXPECT_EQ(0, avcodec_open(av_codec_context, av_codec))
+
+ av_codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
+ av_codec_context->err_recognition = AV_EF_CAREFUL;
+ av_codec_context->thread_count = (
+ av_codec_context->codec_id == CODEC_ID_THEORA ? 1 : kDecodeThreads);
+
+ EXPECT_EQ(0, avcodec_open2(av_codec_context, av_codec, NULL))
<< "Could not open AVCodecContext with CodecID "
<< av_codec_context->codec_id;
@@ -271,7 +282,7 @@ class FFmpegTest : public testing::TestWithParam<const char*> {
if (result > 0) {
// TODO(scherkus): move this to ffmpeg_common.h and dedup.
int64 denominator = av_audio_context()->channels *
- av_get_bits_per_sample_fmt(av_audio_context()->sample_fmt) / 8 *
+ av_get_bytes_per_sample(av_audio_context()->sample_fmt) *
av_audio_context()->sample_rate;
double microseconds = size_out /
(denominator /
@@ -402,7 +413,6 @@ class FFmpegTest : public testing::TestWithParam<const char*> {
EXPECT_TRUE(InitializeMediaLibrary(path))
<< "Could not initialize media library.";
- avcodec_init();
av_log_set_level(AV_LOG_FATAL);
av_register_all();
av_register_protocol2(&kFFmpegFileProtocol, sizeof(kFFmpegFileProtocol));
diff --git a/media/ffmpeg/file_protocol.cc b/media/ffmpeg/file_protocol.cc
index 26ba8ce..49b9f1c 100644
--- a/media/ffmpeg/file_protocol.cc
+++ b/media/ffmpeg/file_protocol.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -78,6 +78,7 @@ MSVC_POP_WARNING()
URLProtocol kFFmpegFileProtocol = {
"file",
&OpenContext,
+ NULL, // url_open2
&ReadContext,
&WriteContext,
&SeekContext,
diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc
index bf26aff..138d89e 100644
--- a/media/filters/audio_file_reader.cc
+++ b/media/filters/audio_file_reader.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -51,15 +51,15 @@ bool AudioFileReader::Open() {
DCHECK(!format_context_);
AVFormatContext* context = NULL;
- int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL);
+ int result = avformat_open_input(&context, key.c_str(), NULL, NULL);
- // Remove our data reader from protocol list since av_open_input_file() setup
+ // Remove our data reader from protocol list since avformat_open_input() setup
// the AVFormatContext with the data reader.
FFmpegGlue::GetInstance()->RemoveProtocol(protocol_);
if (result) {
DLOG(WARNING)
- << "AudioFileReader::Open() : error in av_open_input_file() -"
+ << "AudioFileReader::Open() : error in avformat_open_input() -"
<< " result: " << result;
return false;
}
@@ -81,10 +81,10 @@ bool AudioFileReader::Open() {
if (!codec_context_)
return false;
- av_find_stream_info(format_context_);
+ avformat_find_stream_info(format_context_, NULL);
codec_ = avcodec_find_decoder(codec_context_->codec_id);
if (codec_) {
- if ((result = avcodec_open(codec_context_, codec_)) < 0) {
+ if ((result = avcodec_open2(codec_context_, codec_, NULL)) < 0) {
DLOG(WARNING) << "AudioFileReader::Open() : could not open codec -"
<< " result: " << result;
return false;
@@ -112,7 +112,7 @@ void AudioFileReader::Close() {
codec_ = NULL;
if (format_context_) {
- av_close_input_file(format_context_);
+ avformat_close_input(&format_context_);
format_context_ = NULL;
}
}
@@ -157,7 +157,7 @@ bool AudioFileReader::Read(const std::vector<float*>& audio_data,
// Determine the number of sample-frames we just decoded.
size_t bytes_per_sample =
- av_get_bits_per_sample_fmt(codec_context_->sample_fmt) >> 3;
+ av_get_bytes_per_sample(codec_context_->sample_fmt);
size_t frames_read = out_size / (channels * bytes_per_sample);
// Truncate, if necessary, if the destination isn't big enough.
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index b794cd9..acb0d75 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -127,7 +127,7 @@ void FFmpegAudioDecoder::DoInitialize(
AudioDecoderConfigToAVCodecContext(config, codec_context_);
AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
- if (!codec || avcodec_open(codec_context_, codec) < 0) {
+ if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) {
DLOG(ERROR) << "Could not initialize audio decoder: "
<< codec_context_->codec_id;
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index 0cb2ea4..5dc5ce7 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -465,7 +465,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
// Open FFmpeg AVFormatContext.
DCHECK(!format_context_);
AVFormatContext* context = NULL;
- int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL);
+ int result = avformat_open_input(&context, key.c_str(), NULL, NULL);
// Remove ourself from protocol list.
FFmpegGlue::GetInstance()->RemoveProtocol(this);
@@ -479,7 +479,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
format_context_ = context;
// Fully initialize AVFormatContext by parsing the stream a little.
- result = av_find_stream_info(format_context_);
+ result = avformat_find_stream_info(format_context_, NULL);
if (result < 0) {
callback.Run(DEMUXER_ERROR_COULD_NOT_PARSE);
return;
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index 45838f6..d15d8ec 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -144,7 +144,7 @@ class FFmpegDemuxerTest : public testing::Test {
};
TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
- // Simulate av_open_input_file() failing.
+ // Simulate avformat_open_input() failing.
EXPECT_CALL(host_, SetCurrentReadPosition(_));
demuxer_->Initialize(CreateDataSource("ten_byte_file"),
NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
@@ -153,7 +153,7 @@ TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
}
// TODO(acolwell): Uncomment this test when we discover a file that passes
-// av_open_input_file(), but has av_find_stream_info() fail.
+// avformat_open_input(), but has avformat_find_stream_info() fail.
//
//TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
// demuxer_->Initialize(
@@ -639,7 +639,7 @@ TEST_F(FFmpegDemuxerTest, GetBitrate_SetInContainer_NoFileSize) {
}
TEST_F(FFmpegDemuxerTest, GetBitrate_UnsetInContainer_NoFileSize) {
- EXPECT_FALSE(VideoHasValidBitrate("bear-320x240.webm", true));
+ EXPECT_TRUE(VideoHasValidBitrate("bear-320x240.webm", true));
}
TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) {
diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc
index bd55901..5177462 100644
--- a/media/filters/ffmpeg_glue.cc
+++ b/media/filters/ffmpeg_glue.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,7 +23,7 @@ static int OpenContext(URLContext* h, const char* filename, int flags) {
return AVERROR(EIO);
h->priv_data = protocol;
- h->flags = URL_RDONLY;
+ h->flags = AVIO_FLAG_READ;
h->is_streamed = protocol->IsStreaming();
return 0;
}
@@ -118,6 +118,7 @@ static const char kProtocol[] = "http";
static URLProtocol kFFmpegURLProtocol = {
kProtocol,
&OpenContext,
+ NULL, // url_open2
&ReadContext,
&WriteContext,
&SeekContext,
@@ -129,7 +130,6 @@ FFmpegGlue::FFmpegGlue() {
av_log_set_level(AV_LOG_QUIET);
// Register our protocol glue code with FFmpeg.
- avcodec_init();
av_register_protocol2(&kFFmpegURLProtocol, sizeof(kFFmpegURLProtocol));
av_lockmgr_register(&LockManagerOperation);
diff --git a/media/filters/ffmpeg_glue.h b/media/filters/ffmpeg_glue.h
index 257915e..4e122a6 100644
--- a/media/filters/ffmpeg_glue.h
+++ b/media/filters/ffmpeg_glue.h
@@ -1,27 +1,27 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// FFmpegGlue is an adapter for FFmpeg's URLProtocol interface that allows us to
-// use a DataSource implementation with FFmpeg. For convenience we use FFmpeg's
-// av_open_input_file function, which analyzes the filename given to it and
+// use a DataSource implementation with FFmpeg. For convenience we use FFmpeg's
+// avformat_open_input() function, which analyzes the filename given to it and
// automatically initializes the appropriate URLProtocol.
//
-// Since the DataSource is already open by time we call av_open_input_file, we
-// need a way for av_open_input_file to find the correct DataSource instance.
-// The solution is to maintain a map of "filenames" to DataSource instances,
-// where filenames are actually just a unique identifier. For simplicity,
-// FFmpegGlue is registered as an HTTP handler and generates filenames based on
-// the memory address of the DataSource, i.e., http://0xc0bf4870. Since there
-// may be multiple FFmpegDemuxers active at one time, FFmpegGlue is a
-// thread-safe singleton.
+// Since the DataSource is already open by time we call avformat_open_input(),
+// we need a way for avformat_open_input() to find the correct DataSource
+// instance. The solution is to maintain a map of "filenames" to DataSource
+// instances, where filenames are actually just a unique identifier. For
+// simplicity, FFmpegGlue is registered as an HTTP handler and generates
+// filenames based on the memory address of the DataSource, i.e.,
+// http://0xc0bf4870. Since there may be multiple FFmpegDemuxers active at one
+// time, FFmpegGlue is a thread-safe singleton.
//
// Usage: FFmpegDemuxer adds the DataSource to FFmpegGlue's map and is given a
-// filename to pass to av_open_input_file. FFmpegDemuxer calls
-// av_open_input_file with the filename, which results in FFmpegGlue returning
-// the DataSource as a URLProtocol instance to FFmpeg. Since FFmpegGlue is only
-// needed for opening files, when av_open_input_file returns FFmpegDemuxer
-// removes the DataSource from FFmpegGlue's map.
+// filename to pass to avformat_open_input(). FFmpegDemuxer calls
+// avformat_open_input() with the filename, which results in FFmpegGlue
+// returning the DataSource as a URLProtocol instance to FFmpeg. Since
+// FFmpegGlue is only needed for opening files, when avformat_open_input()
+// returns FFmpegDemuxer removes the DataSource from FFmpegGlue's map.
#ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_
#define MEDIA_FILTERS_FFMPEG_GLUE_H_
@@ -90,7 +90,7 @@ class MEDIA_EXPORT FFmpegGlue {
virtual ~FFmpegGlue();
// Returns the unique key for this data source, which can be passed to
- // av_open_input_file as the filename.
+ // avformat_open_input() as the filename.
std::string GetProtocolKey(FFmpegURLProtocol* protocol);
// Mutual exclusion while adding/removing items from the map.
diff --git a/media/filters/ffmpeg_glue_unittest.cc b/media/filters/ffmpeg_glue_unittest.cc
index 94258e9..8fded22 100644
--- a/media/filters/ffmpeg_glue_unittest.cc
+++ b/media/filters/ffmpeg_glue_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -154,7 +154,7 @@ TEST_F(FFmpegGlueTest, OpenClose) {
// Test opening a URLContext with our protocol.
EXPECT_EQ(0, protocol_->url_open(&context, key.c_str(), 0));
- EXPECT_EQ(URL_RDONLY, context.flags);
+ EXPECT_EQ(AVIO_FLAG_READ, context.flags);
EXPECT_EQ(protocol.get(), context.priv_data);
EXPECT_TRUE(context.is_streamed);
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index 7ca0d1d..61932ff 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -101,7 +101,7 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream,
// Enable motion vector search (potentially slow), strong deblocking filter
// for damaged macroblocks, and set our error detection sensitivity.
codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
- codec_context_->error_recognition = FF_ER_CAREFUL;
+ codec_context_->err_recognition = AV_EF_CAREFUL;
codec_context_->thread_count = GetThreadCount(codec_context_->codec_id);
AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
@@ -110,7 +110,7 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream,
return;
}
- if (avcodec_open(codec_context_, codec) < 0) {
+ if (avcodec_open2(codec_context_, codec, NULL) < 0) {
callback.Run(PIPELINE_ERROR_DECODE);
return;
}
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 83a754e..939e689 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -238,7 +238,7 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) {
}
TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) {
- // Specify Theora w/o extra data so that avcodec_open() fails.
+ // Specify Theora w/o extra data so that avcodec_open2() fails.
VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN,
kVideoFormat,
kCodedSize, kVisibleRect,
diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc
index 90cf45e..73b69f4 100644
--- a/media/test/ffmpeg_tests/ffmpeg_tests.cc
+++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc
@@ -114,12 +114,11 @@ int main(int argc, const char** argv) {
#endif
// Register FFmpeg and attempt to open file.
- avcodec_init();
av_log_set_level(verbose_level);
av_register_all();
av_register_protocol2(&kFFmpegFileProtocol, sizeof(kFFmpegFileProtocol));
AVFormatContext* format_context = NULL;
- // av_open_input_file wants a char*, which can't work with wide paths.
+ // avformat_open_input() wants a char*, which can't work with wide paths.
// So we assume ASCII on Windows. On other platforms we can pass the
// path bytes through verbatim.
#if defined(OS_WIN)
@@ -127,8 +126,8 @@ int main(int argc, const char** argv) {
#else
const std::string& string_path = in_path.value();
#endif
- int result = av_open_input_file(&format_context, string_path.c_str(),
- NULL, 0, NULL);
+ int result = avformat_open_input(&format_context, string_path.c_str(),
+ NULL, NULL);
if (result < 0) {
switch (result) {
case AVERROR(EINVAL):
@@ -155,7 +154,7 @@ int main(int argc, const char** argv) {
}
// Parse a little bit of the stream to fill out the format context.
- if (av_find_stream_info(format_context) < 0) {
+ if (avformat_find_stream_info(format_context, NULL) < 0) {
std::cerr << "Error: Could not find stream info for "
<< in_path.value() << std::endl;
return 1;
@@ -230,7 +229,7 @@ int main(int argc, const char** argv) {
}
codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
- codec_context->error_recognition = FF_ER_CAREFUL;
+ codec_context->err_recognition = AV_EF_CAREFUL;
// Initialize threaded decode.
if (target_codec == AVMEDIA_TYPE_VIDEO && video_threads > 0) {
@@ -238,7 +237,7 @@ int main(int argc, const char** argv) {
}
// Initialize our codec.
- if (avcodec_open(codec_context, codec) < 0) {
+ if (avcodec_open2(codec_context, codec, NULL) < 0) {
std::cerr << "Error: Could not open codec "
<< codec_context->codec->name << " for "
<< in_path.value() << std::endl;
@@ -421,7 +420,7 @@ int main(int argc, const char** argv) {
if (codec_context)
avcodec_close(codec_context);
if (format_context)
- av_close_input_file(format_context);
+ avformat_close_input(&format_context);
// Calculate the sum of times. Note that some of these may be zero.
double sum = 0;
diff --git a/media/tools/media_bench/media_bench.cc b/media/tools/media_bench/media_bench.cc
index fc732bf..532aa7d 100644
--- a/media/tools/media_bench/media_bench.cc
+++ b/media/tools/media_bench/media_bench.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -228,12 +228,11 @@ int main(int argc, const char** argv) {
#endif
// Register FFmpeg and attempt to open file.
- avcodec_init();
av_log_set_level(verbose_level);
av_register_all();
av_register_protocol2(&kFFmpegFileProtocol, sizeof(kFFmpegFileProtocol));
AVFormatContext* format_context = NULL;
- // av_open_input_file wants a char*, which can't work with wide paths.
+ // avformat_open_input() wants a char*, which can't work with wide paths.
// So we assume ASCII on Windows. On other platforms we can pass the
// path bytes through verbatim.
#if defined(OS_WIN)
@@ -241,8 +240,8 @@ int main(int argc, const char** argv) {
#else
const std::string& string_path = in_path.value();
#endif
- int result = av_open_input_file(&format_context, string_path.c_str(),
- NULL, 0, NULL);
+ int result = avformat_open_input(&format_context, string_path.c_str(),
+ NULL, NULL);
if (result < 0) {
switch (result) {
case AVERROR(EINVAL):
@@ -279,7 +278,7 @@ int main(int argc, const char** argv) {
}
// Parse a little bit of the stream to fill out the format context.
- if (av_find_stream_info(format_context) < 0) {
+ if (avformat_find_stream_info(format_context, NULL) < 0) {
std::cerr << "Error: Could not find stream info for "
<< in_path.value() << std::endl;
return 1;
@@ -341,7 +340,7 @@ int main(int argc, const char** argv) {
}
if (error_correction) {
codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
- codec_context->error_recognition = FF_ER_CAREFUL;
+ codec_context->err_recognition = AV_EF_CAREFUL;
}
// Initialize threaded decode.
@@ -350,7 +349,7 @@ int main(int argc, const char** argv) {
}
// Initialize our codec.
- if (avcodec_open(codec_context, codec) < 0) {
+ if (avcodec_open2(codec_context, codec, NULL) < 0) {
std::cerr << "Error: Could not open codec "
<< (codec_context->codec ? codec_context->codec->name : "(NULL)")
<< " for " << in_path.value() << std::endl;
@@ -533,7 +532,7 @@ int main(int argc, const char** argv) {
if (codec_context)
avcodec_close(codec_context);
if (format_context)
- av_close_input_file(format_context);
+ avformat_close_input(&format_context);
// Calculate the sum of times. Note that some of these may be zero.
double sum = 0;
diff --git a/media/webm/webm_stream_parser.cc b/media/webm/webm_stream_parser.cc
index f1d6001..d49ed7c 100644
--- a/media/webm/webm_stream_parser.cc
+++ b/media/webm/webm_stream_parser.cc
@@ -46,7 +46,7 @@ class FFmpegConfigHelper {
scoped_ptr<FFmpegURLProtocol> url_protocol_;
// FFmpeg format context for this demuxer. It is created by
- // av_open_input_file() during demuxer initialization and cleaned up with
+ // avformat_open_input() during demuxer initialization and cleaned up with
// DestroyAVFormatContext() in the destructor.
AVFormatContext* format_context_;
@@ -139,7 +139,7 @@ AVFormatContext* FFmpegConfigHelper::CreateFormatContext(const uint8* data,
// Open FFmpeg AVFormatContext.
AVFormatContext* context = NULL;
- int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL);
+ int result = avformat_open_input(&context, key.c_str(), NULL, NULL);
if (result < 0)
return NULL;
@@ -148,7 +148,7 @@ AVFormatContext* FFmpegConfigHelper::CreateFormatContext(const uint8* data,
}
bool FFmpegConfigHelper::SetupStreamConfigs() {
- int result = av_find_stream_info(format_context_);
+ int result = avformat_find_stream_info(format_context_, NULL);
if (result < 0)
return false;