summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-29 00:25:27 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-29 00:25:27 +0000
commit20fab9ec3cc2f1387247339c6eab504873b3824f (patch)
treee38482897fe4cb876c409610a26b74d5dd8d3bc8
parent8de57342e6e4c50337c553f49f39a59ff1d825d3 (diff)
downloadchromium_src-20fab9ec3cc2f1387247339c6eab504873b3824f.zip
chromium_src-20fab9ec3cc2f1387247339c6eab504873b3824f.tar.gz
chromium_src-20fab9ec3cc2f1387247339c6eab504873b3824f.tar.bz2
Clean up FFmpeg media formats and switch to using av_get_bits_per_sample_format().
Before we were relying on codecs setting bits_per_raw_sample, which turns out isn't a valid assumption at all (i.e., vorbis). However, codecs always set the sample format so we can use the FFmpeg utility function av_get_bits_per_sample_format() to convert the SampleFormat enum to an integer number of bits. Review URL: http://codereview.chromium.org/99160 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14808 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/base/media_posix.cc10
-rw-r--r--media/filters/ffmpeg_audio_decoder.cc13
-rw-r--r--media/filters/ffmpeg_common.cc2
-rw-r--r--media/filters/ffmpeg_common.h3
-rw-r--r--media/filters/ffmpeg_demuxer.cc12
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc19
-rw-r--r--third_party/ffmpeg/avcodec-52.def2
7 files changed, 13 insertions, 48 deletions
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc
index 331a143..edbced0 100644
--- a/media/base/media_posix.cc
+++ b/media/base/media_posix.cc
@@ -22,6 +22,11 @@
// be promising, but I don't quite understand it yet.
extern "C" {
+int (*av_get_bits_per_sample_format_ptr)(enum SampleFormat sample_fmt);
+int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
+ return av_get_bits_per_sample_format(sample_fmt);
+}
+
void (*avcodec_init_ptr)(void) = NULL;
void avcodec_init(void) {
avcodec_init_ptr();
@@ -54,7 +59,7 @@ int avcodec_decode_audio2(AVCodecContext* avctx, int16_t* samples,
int* frame_size_ptr,
const uint8_t* buf, int buf_size) {
- return avcodec_decode_audio2_ptr(avctx, samples, frame_size_ptr, buf,
+ return avcodec_decode_audio2_ptr(avctx, samples, frame_size_ptr, buf,
buf_size);
}
@@ -164,6 +169,9 @@ bool InitializeMediaLibrary(const FilePath& module_dir) {
// TODO(ajwong): Extract this to somewhere saner, and hopefully
// autogenerate the bindings from the .def files. Having all this
// code here is incredibly ugly.
+ av_get_bits_per_sample_format_ptr =
+ reinterpret_cast<int (*)(enum SampleFormat)>(
+ dlsym(libs[FILE_LIBAVCODEC], "av_get_bits_per_sample_format"));
avcodec_init_ptr =
reinterpret_cast<void(*)(void)>(
dlsym(libs[FILE_LIBAVCODEC], "avcodec_init"));
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index 914a8ed8..019bc15 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -23,16 +23,9 @@ FFmpegAudioDecoder::~FFmpegAudioDecoder() {
// static
bool FFmpegAudioDecoder::IsMediaFormatSupported(const MediaFormat& format) {
- int channels, sample_bits, sample_rate;
std::string mime_type;
- if (format.GetAsInteger(MediaFormat::kChannels, &channels) &&
- format.GetAsInteger(MediaFormat::kSampleBits, &sample_bits) &&
- format.GetAsInteger(MediaFormat::kSampleRate, &sample_rate) &&
- format.GetAsString(MediaFormat::kMimeType, &mime_type) &&
- mime_type::kFFmpegAudio == mime_type) {
- return true;
- }
- return false;
+ return format.GetAsString(MediaFormat::kMimeType, &mime_type) &&
+ mime_type::kFFmpegAudio == mime_type;
}
bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
@@ -50,7 +43,7 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels);
media_format_.SetAsInteger(MediaFormat::kSampleBits,
- codec_context_->bits_per_coded_sample);
+ av_get_bits_per_sample_format(codec_context_->sample_fmt));
media_format_.SetAsInteger(MediaFormat::kSampleRate,
codec_context_->sample_rate);
media_format_.SetAsString(MediaFormat::kMimeType,
diff --git a/media/filters/ffmpeg_common.cc b/media/filters/ffmpeg_common.cc
index 875d968..88dab9f 100644
--- a/media/filters/ffmpeg_common.cc
+++ b/media/filters/ffmpeg_common.cc
@@ -6,8 +6,6 @@
namespace media {
-const char kFFmpegCodecID[] = "FFmpegCodecID";
-
namespace mime_type {
const char kFFmpegAudio[] = "audio/x-ffmpeg";
diff --git a/media/filters/ffmpeg_common.h b/media/filters/ffmpeg_common.h
index d82dfef..8f1cc59 100644
--- a/media/filters/ffmpeg_common.h
+++ b/media/filters/ffmpeg_common.h
@@ -31,9 +31,6 @@ class ScopedPtrAVFree {
}
};
-// MediaFormat key identifying the CodecID.
-extern const char kFFmpegCodecID[];
-
// FFmpeg MIME types.
namespace mime_type {
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index e6c08954..077314e 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -60,27 +60,15 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
case CODEC_TYPE_AUDIO:
media_format_.SetAsString(MediaFormat::kMimeType,
mime_type::kFFmpegAudio);
- media_format_.SetAsInteger(MediaFormat::kChannels,
- stream->codec->channels);
- media_format_.SetAsInteger(MediaFormat::kSampleRate,
- stream->codec->sample_rate);
- media_format_.SetAsInteger(MediaFormat::kSampleBits,
- stream->codec->bits_per_raw_sample);
break;
case CODEC_TYPE_VIDEO:
media_format_.SetAsString(MediaFormat::kMimeType,
mime_type::kFFmpegVideo);
- media_format_.SetAsInteger(MediaFormat::kHeight,
- stream->codec->height);
- media_format_.SetAsInteger(MediaFormat::kWidth,
- stream->codec->width);
break;
default:
NOTREACHED();
break;
}
- int codec_id = static_cast<int>(stream->codec->codec_id);
- media_format_.SetAsInteger(kFFmpegCodecID, codec_id);
// Calculate the time base and duration in microseconds.
int64 time_base_us = static_cast<int64>(av_q2d(stream->time_base) *
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index e0fa404..e82ca10 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -364,19 +364,9 @@ TEST(FFmpegDemuxerTest, DISABLED_InitializeStreams) {
scoped_refptr<FFmpegDemuxerStream> ffmpeg_demuxer_stream;
ASSERT_TRUE(stream);
std::string mime_type;
- int result;
EXPECT_TRUE(
stream->media_format().GetAsString(MediaFormat::kMimeType, &mime_type));
EXPECT_STREQ(mime_type::kFFmpegVideo, mime_type.c_str());
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(kFFmpegCodecID, &result));
- EXPECT_EQ(CODEC_ID_THEORA, static_cast<CodecID>(result));
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(MediaFormat::kHeight, &result));
- EXPECT_EQ(g_video_codec.height, result);
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(MediaFormat::kWidth, &result));
- EXPECT_EQ(g_video_codec.width, result);
EXPECT_TRUE(stream->QueryInterface(&ffmpeg_demuxer_stream));
EXPECT_TRUE(ffmpeg_demuxer_stream);
EXPECT_EQ(&g_streams[1], ffmpeg_demuxer_stream->av_stream());
@@ -388,15 +378,6 @@ TEST(FFmpegDemuxerTest, DISABLED_InitializeStreams) {
EXPECT_TRUE(
stream->media_format().GetAsString(MediaFormat::kMimeType, &mime_type));
EXPECT_STREQ(mime_type::kFFmpegAudio, mime_type.c_str());
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(kFFmpegCodecID, &result));
- EXPECT_EQ(CODEC_ID_VORBIS, static_cast<CodecID>(result));
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(MediaFormat::kChannels, &result));
- EXPECT_EQ(g_audio_codec.channels, result);
- EXPECT_TRUE(
- stream->media_format().GetAsInteger(MediaFormat::kSampleRate, &result));
- EXPECT_EQ(g_audio_codec.sample_rate, result);
EXPECT_TRUE(stream->QueryInterface(&ffmpeg_demuxer_stream));
EXPECT_TRUE(ffmpeg_demuxer_stream);
EXPECT_EQ(&g_streams[2], ffmpeg_demuxer_stream->av_stream());
diff --git a/third_party/ffmpeg/avcodec-52.def b/third_party/ffmpeg/avcodec-52.def
index 7a377304..e567dc9 100644
--- a/third_party/ffmpeg/avcodec-52.def
+++ b/third_party/ffmpeg/avcodec-52.def
@@ -1,6 +1,6 @@
LIBRARY avcodec-52
EXPORTS
- av_bitstream_filter_init
+ av_get_bits_per_sample_format
avcodec_alloc_context
avcodec_alloc_frame
avcodec_decode_audio2