summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 19:26:27 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 19:26:27 +0000
commit11309735fce8bf91f70643e955c6153b79f40095 (patch)
tree6a87158dbb3995246322c135de4112336ff38e45 /media
parentbfd71998f58c08dafbdb58ebf59e56b1c7845fc3 (diff)
downloadchromium_src-11309735fce8bf91f70643e955c6153b79f40095.zip
chromium_src-11309735fce8bf91f70643e955c6153b79f40095.tar.gz
chromium_src-11309735fce8bf91f70643e955c6153b79f40095.tar.bz2
New FFmpeg public API headers to match our source tarball in deps.
Review URL: http://codereview.chromium.org/113748 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16771 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/media_posix.cc200
-rw-r--r--media/bench/bench.cc8
-rw-r--r--media/filters/ffmpeg_audio_decoder.cc11
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc8
-rw-r--r--media/filters/ffmpeg_video_decoder.cc13
5 files changed, 137 insertions, 103 deletions
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc
index 57e1b77..cd6bbe3 100644
--- a/media/base/media_posix.cc
+++ b/media/base/media_posix.cc
@@ -13,28 +13,56 @@
#include "base/path_service.h"
#include "media/filters/ffmpeg_common.h"
-// We create stub references to dynamically loaded functions in ffmpeg
+// We create stub references to dynamically loaded functions in FFmpeg
// for ease of linking.
//
// TODO(ajwong): We need to find a more maintainable way to have this work.
-// Also, this code should really be in the ffmpeg wrapper, and not here
+// Also, this code should really be in the FFmpeg wrapper, and not here
// in the media level. The concept of "weak symbols" looks like it might
// be promising, but I don't quite understand it yet.
+//
+// TODO(scherkus): I am *this close* to writing the world's coolest macro to
+// make modifying this file easier.
extern "C" {
-int (*av_get_bits_per_sample_format_ptr)(enum SampleFormat sample_fmt);
+// libavcodec functions.
+void (*av_free_packet_ptr)(AVPacket* pkt) = NULL;
+void av_free_packet(AVPacket* pkt) {
+ av_free_packet_ptr(pkt);
+}
+
+int (*av_get_bits_per_sample_format_ptr)(enum SampleFormat sample_fmt) = NULL;
int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
return av_get_bits_per_sample_format_ptr(sample_fmt);
}
-int (*av_new_packet_ptr)(AVPacket* pkt, int size);
+void (*av_init_packet_ptr)(AVPacket* pkt) = NULL;
+void av_init_packet(AVPacket* pkt) {
+ av_init_packet_ptr(pkt);
+}
+
+int (*av_new_packet_ptr)(AVPacket* pkt, int size) = NULL;
int av_new_packet(AVPacket* pkt, int size) {
return av_new_packet_ptr(pkt, size);
}
-void (*avcodec_init_ptr)(void) = NULL;
-void avcodec_init(void) {
- avcodec_init_ptr();
+AVFrame* (*avcodec_alloc_frame_ptr)(void) = NULL;
+AVFrame* avcodec_alloc_frame(void) {
+ return avcodec_alloc_frame_ptr();
+}
+
+int (*avcodec_decode_audio3_ptr)(AVCodecContext* avctx, int16_t* samples,
+ int* frame_size_ptr, AVPacket* avpkt) = NULL;
+int avcodec_decode_audio3(AVCodecContext* avctx, int16_t* samples,
+ int* frame_size_ptr, AVPacket* avpkt) {
+ return avcodec_decode_audio3_ptr(avctx, samples, frame_size_ptr, avpkt);
+}
+
+int (*avcodec_decode_video2_ptr)(AVCodecContext* avctx, AVFrame* picture,
+ int* got_picture_ptr, AVPacket* avpkt) = NULL;
+int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture,
+ int* got_picture_ptr, AVPacket* avpkt) {
+ return avcodec_decode_video2_ptr(avctx, picture, got_picture_ptr, avpkt);
}
AVCodec* (*avcodec_find_decoder_ptr)(enum CodecID id) = NULL;
@@ -42,9 +70,9 @@ AVCodec* avcodec_find_decoder(enum CodecID id) {
return avcodec_find_decoder_ptr(id);
}
-int (*avcodec_thread_init_ptr)(AVCodecContext* s, int thread_count) = NULL;
-int avcodec_thread_init(AVCodecContext* s, int thread_count) {
- return avcodec_thread_init_ptr(s, thread_count);
+void (*avcodec_init_ptr)(void) = NULL;
+void avcodec_init(void) {
+ avcodec_init_ptr();
}
int (*avcodec_open_ptr)(AVCodecContext* avctx, AVCodec* codec) = NULL;
@@ -52,37 +80,16 @@ int avcodec_open(AVCodecContext* avctx, AVCodec* codec) {
return avcodec_open_ptr(avctx, codec);
}
-AVFrame* (*avcodec_alloc_frame_ptr)(void) = NULL;
-AVFrame* avcodec_alloc_frame(void) {
- return avcodec_alloc_frame_ptr();
-}
-
-int (*avcodec_decode_audio2_ptr)(AVCodecContext* avctx, int16_t* samples,
- int* frame_size_ptr, const uint8_t* buf,
- int buf_size) = NULL;
-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,
- buf_size);
-}
-
-
-int (*avcodec_decode_video_ptr)(AVCodecContext* avctx, AVFrame* picture,
- int* got_picture_ptr, const uint8_t* buf,
- int buf_size) = NULL;
-int avcodec_decode_video(AVCodecContext* avctx, AVFrame* picture,
- int* got_picture_ptr, const uint8_t* buf,
- int buf_size) {
- return avcodec_decode_video_ptr(avctx, picture, got_picture_ptr, buf,
- buf_size);
+int (*avcodec_thread_init_ptr)(AVCodecContext* s, int thread_count) = NULL;
+int avcodec_thread_init(AVCodecContext* s, int thread_count) {
+ return avcodec_thread_init_ptr(s, thread_count);
}
-void (*av_register_all_ptr)(void);
-void av_register_all(void) {
- av_register_all_ptr();
+// libavformat functions.
+int (*av_find_stream_info_ptr)(AVFormatContext* ic) = NULL;
+int av_find_stream_info(AVFormatContext* ic) {
+ return av_find_stream_info_ptr(ic);
}
int (*av_open_input_file_ptr)(AVFormatContext** ic_ptr, const char* filename,
@@ -94,21 +101,14 @@ int av_open_input_file(AVFormatContext** ic_ptr, const char* filename,
return av_open_input_file_ptr(ic_ptr, filename, fmt, buf_size, ap);
}
-int (*av_find_stream_info_ptr)(AVFormatContext* ic) = NULL;
-int av_find_stream_info(AVFormatContext* ic) {
- return av_find_stream_info_ptr(ic);
-}
-
int (*av_read_frame_ptr)(AVFormatContext* s, AVPacket* pkt) = NULL;
int av_read_frame(AVFormatContext* s, AVPacket* pkt) {
return av_read_frame_ptr(s, pkt);
}
-int (*av_seek_frame_ptr)(AVFormatContext* s, int stream_index,
- int64_t timestamp, int flags) = NULL;
-int av_seek_frame(AVFormatContext* s, int stream_index,
- int64_t timestamp, int flags) {
- return av_seek_frame_ptr(s, stream_index, timestamp, flags);
+void (*av_register_all_ptr)(void) = NULL;
+void av_register_all(void) {
+ av_register_all_ptr();
}
int (*av_register_protocol_ptr)(URLProtocol* protocol) = NULL;
@@ -116,17 +116,25 @@ int av_register_protocol(URLProtocol* protocol) {
return av_register_protocol_ptr(protocol);
}
-
-void* (*av_malloc_ptr)(unsigned int size) = NULL;
-void* av_malloc(unsigned int size) {
- return av_malloc_ptr(size);
+int (*av_seek_frame_ptr)(AVFormatContext* s, int stream_index,
+ int64_t timestamp, int flags) = NULL;
+int av_seek_frame(AVFormatContext* s, int stream_index,
+ int64_t timestamp, int flags) {
+ return av_seek_frame_ptr(s, stream_index, timestamp, flags);
}
+
+// libavutil functions.
void (*av_free_ptr)(void* ptr) = NULL;
void av_free(void* ptr) {
return av_free_ptr(ptr);
}
+void* (*av_malloc_ptr)(unsigned int size) = NULL;
+void* av_malloc(unsigned int size) {
+ return av_malloc_ptr(size);
+}
+
int64_t (*av_rescale_q_ptr)(int64_t a, AVRational bq, AVRational cq) = NULL;
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) {
return av_rescale_q_ptr(a, bq, cq);
@@ -196,87 +204,97 @@ 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.
+
+ // libavcodec functions.
+ av_free_packet_ptr =
+ reinterpret_cast<void (*)(AVPacket*)>(
+ dlsym(libs[FILE_LIBAVCODEC], "av_free_packet"));
av_get_bits_per_sample_format_ptr =
reinterpret_cast<int (*)(enum SampleFormat)>(
dlsym(libs[FILE_LIBAVCODEC], "av_get_bits_per_sample_format"));
+ av_init_packet_ptr =
+ reinterpret_cast<void (*)(AVPacket*)>(
+ dlsym(libs[FILE_LIBAVCODEC], "av_init_packet"));
av_new_packet_ptr =
reinterpret_cast<int (*)(AVPacket*, int)>(
dlsym(libs[FILE_LIBAVCODEC], "av_new_packet"));
- avcodec_init_ptr =
- reinterpret_cast<void(*)(void)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_init"));
+ avcodec_alloc_frame_ptr =
+ reinterpret_cast<AVFrame* (*)(void)>(
+ dlsym(libs[FILE_LIBAVCODEC], "avcodec_alloc_frame"));
+ avcodec_decode_audio3_ptr =
+ reinterpret_cast<int (*)(AVCodecContext*, int16_t*, int*, AVPacket*)>(
+ dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_audio3"));
+ avcodec_decode_video2_ptr =
+ reinterpret_cast<int (*)(AVCodecContext*, AVFrame*, int*, AVPacket*)>(
+ dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_video2"));
avcodec_find_decoder_ptr =
reinterpret_cast<AVCodec* (*)(enum CodecID)>(
dlsym(libs[FILE_LIBAVCODEC], "avcodec_find_decoder"));
- avcodec_thread_init_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, int)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_thread_init"));
+ avcodec_init_ptr =
+ reinterpret_cast<void (*)(void)>(
+ dlsym(libs[FILE_LIBAVCODEC], "avcodec_init"));
avcodec_open_ptr =
reinterpret_cast<int (*)(AVCodecContext*, AVCodec*)>(
dlsym(libs[FILE_LIBAVCODEC], "avcodec_open"));
- avcodec_alloc_frame_ptr =
- reinterpret_cast<AVFrame* (*)(void)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_alloc_frame"));
- avcodec_decode_audio2_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, int16_t*, int*,
- const uint8_t*, int)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_audio2"));
- avcodec_decode_video_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, AVFrame*, int*,
- const uint8_t*, int)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_video"));
+ avcodec_thread_init_ptr =
+ reinterpret_cast<int (*)(AVCodecContext*, int)>(
+ dlsym(libs[FILE_LIBAVCODEC], "avcodec_thread_init"));
- av_register_all_ptr =
- reinterpret_cast<void(*)(void)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_register_all"));
+ // libavformat functions.
+ av_find_stream_info_ptr =
+ reinterpret_cast<int (*)(AVFormatContext*)>(
+ dlsym(libs[FILE_LIBAVFORMAT], "av_find_stream_info"));
av_open_input_file_ptr =
reinterpret_cast<int (*)(AVFormatContext**, const char*,
AVInputFormat*, int,
AVFormatParameters*)>(
dlsym(libs[FILE_LIBAVFORMAT], "av_open_input_file"));
- av_find_stream_info_ptr =
- reinterpret_cast<int (*)(AVFormatContext*)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_find_stream_info"));
av_read_frame_ptr =
reinterpret_cast<int (*)(AVFormatContext*, AVPacket*)>(
dlsym(libs[FILE_LIBAVFORMAT], "av_read_frame"));
- av_seek_frame_ptr =
- reinterpret_cast<int (*)(AVFormatContext*, int, int64_t, int)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_seek_frame"));
+ av_register_all_ptr =
+ reinterpret_cast<void (*)(void)>(
+ dlsym(libs[FILE_LIBAVFORMAT], "av_register_all"));
av_register_protocol_ptr =
reinterpret_cast<int (*)(URLProtocol*)>(
dlsym(libs[FILE_LIBAVFORMAT], "av_register_protocol"));
+ av_seek_frame_ptr =
+ reinterpret_cast<int (*)(AVFormatContext*, int, int64_t, int)>(
+ dlsym(libs[FILE_LIBAVFORMAT], "av_seek_frame"));
- av_malloc_ptr =
- reinterpret_cast<void* (*)(unsigned int)>(
- dlsym(libs[FILE_LIBAVUTIL], "av_malloc"));
+ // libavutil functions.
av_free_ptr =
reinterpret_cast<void (*)(void*)>(
dlsym(libs[FILE_LIBAVUTIL], "av_free"));
+ av_malloc_ptr =
+ reinterpret_cast<void* (*)(unsigned int)>(
+ dlsym(libs[FILE_LIBAVUTIL], "av_malloc"));
av_rescale_q_ptr =
reinterpret_cast<int64_t (*)(int64_t, AVRational, AVRational)>(
dlsym(libs[FILE_LIBAVUTIL], "av_rescale_q"));
// Check that all the symbols were loaded correctly before returning true.
- if (av_get_bits_per_sample_format_ptr &&
+ if (av_free_packet_ptr &&
+ av_get_bits_per_sample_format_ptr &&
+ av_init_packet_ptr &&
av_new_packet_ptr &&
- avcodec_init_ptr &&
+ avcodec_alloc_frame_ptr &&
+ avcodec_decode_audio3_ptr &&
+ avcodec_decode_video2_ptr &&
avcodec_find_decoder_ptr &&
- avcodec_thread_init_ptr &&
+ avcodec_init_ptr &&
avcodec_open_ptr &&
- avcodec_alloc_frame_ptr &&
- avcodec_decode_audio2_ptr &&
- avcodec_decode_video_ptr &&
+ avcodec_thread_init_ptr &&
- av_register_all_ptr &&
- av_open_input_file_ptr &&
av_find_stream_info_ptr &&
+ av_open_input_file_ptr &&
av_read_frame_ptr &&
- av_seek_frame_ptr &&
+ av_register_all_ptr &&
av_register_protocol_ptr &&
+ av_seek_frame_ptr &&
- av_malloc_ptr &&
av_free_ptr &&
+ av_malloc_ptr &&
av_rescale_q_ptr) {
return true;
}
diff --git a/media/bench/bench.cc b/media/bench/bench.cc
index 42deacf..147b91a 100644
--- a/media/bench/bench.cc
+++ b/media/bench/bench.cc
@@ -189,12 +189,12 @@ int main(int argc, const char** argv) {
base::TimeTicks decode_start = base::TimeTicks::HighResNow();
if (target_codec == CODEC_TYPE_AUDIO) {
int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- result = avcodec_decode_audio2(codec_context, samples, &size_out,
- packet.data, packet.size);
+ result = avcodec_decode_audio3(codec_context, samples, &size_out,
+ &packet);
} else if (target_codec == CODEC_TYPE_VIDEO) {
int got_picture = 0;
- result = avcodec_decode_video(codec_context, frame, &got_picture,
- packet.data, packet.size);
+ result = avcodec_decode_video2(codec_context, frame, &got_picture,
+ &packet);
} else {
NOTREACHED();
}
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index e44880a..808904c7 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -74,13 +74,18 @@ void FFmpegAudioDecoder::OnStop() {
}
void FFmpegAudioDecoder::OnDecode(Buffer* input) {
+ // Due to FFmpeg API changes we no longer have const read-only pointers.
+ AVPacket packet;
+ av_init_packet(&packet);
+ packet.data = const_cast<uint8*>(input->GetData());
+ packet.size = input->GetDataSize();
+
int16_t* output_buffer = reinterpret_cast<int16_t*>(output_buffer_.get());
int output_buffer_size = kOutputBufferSize;
- int result = avcodec_decode_audio2(codec_context_,
+ int result = avcodec_decode_audio3(codec_context_,
output_buffer,
&output_buffer_size,
- input->GetData(),
- input->GetDataSize());
+ &packet);
// TODO(ajwong): Consider if kOutputBufferSize should just be an int instead
// of a size_t.
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index 6b4f06d..157f2ae 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -143,6 +143,14 @@ int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) {
return a * num / den;
}
+void av_free_packet(AVPacket* packet) {
+ if (packet->destruct) {
+ packet->destruct(packet);
+ packet->data = NULL;
+ packet->size = 0;
+ }
+}
+
void DestructPacket(AVPacket* packet) {
delete [] packet->data;
--g_outstanding_packets_av_new_frame;
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index 6d5505a4..b80d215 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -81,17 +81,20 @@ void FFmpegVideoDecoder::OnDecode(Buffer* buffer) {
times.duration = buffer->GetDuration();
time_queue_.push(times);
- // Cast everything to FFmpeg types.
- const uint8_t* data_in = buffer->GetData();
- const size_t size_in = buffer->GetDataSize();
+ // Create a packet for input data.
+ // Due to FFmpeg API changes we no longer have const read-only pointers.
+ AVPacket packet;
+ av_init_packet(&packet);
+ packet.data = const_cast<uint8*>(buffer->GetData());
+ packet.size = buffer->GetDataSize();
// We don't allocate AVFrame on the stack since different versions of FFmpeg
// may change the size of AVFrame, causing stack corruption. The solution is
// to let FFmpeg allocate the structure via avcodec_alloc_frame().
int decoded = 0;
scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> yuv_frame(avcodec_alloc_frame());
- int result = avcodec_decode_video(codec_context_, yuv_frame.get(), &decoded,
- data_in, size_in);
+ int result = avcodec_decode_video2(codec_context_, yuv_frame.get(), &decoded,
+ &packet);
// Log the problem if we can't decode a video frame.
if (result < 0) {