summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-01 22:25:25 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-01 22:25:25 +0000
commitd8fedf9ca7071735da290dca4d58440d05594694 (patch)
tree4b182b22e2973f01e7209c82973793c005d67eed /media
parenta76af4a70e85380fb855e9babc0ab700d9a3a10d (diff)
downloadchromium_src-d8fedf9ca7071735da290dca4d58440d05594694.zip
chromium_src-d8fedf9ca7071735da290dca4d58440d05594694.tar.gz
chromium_src-d8fedf9ca7071735da290dca4d58440d05594694.tar.bz2
Using bitstream filters if OpenMAX is enabled
Use FFmpeg bitstream filters if OpenMAX is enabled. The following filters are used: 1. h264_mp4toannexb 2. mpeg4video_es 3. vc1_asftorcv 4. vc1_asftoannexg TEST=run player_x11 with --enable-openmax and the above formats work Review URL: http://codereview.chromium.org/661059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40306 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/ffmpeg_demuxer.cc60
-rw-r--r--media/filters/ffmpeg_demuxer.h9
-rw-r--r--media/tools/omx_test/file_reader_util.cc6
3 files changed, 51 insertions, 24 deletions
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index 8c3a0a1..2e020ba 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -116,6 +116,12 @@ base::TimeDelta FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) {
return timestamp;
}
+ // Convert if the packet if there is bitstream filter.
+ if (bitstream_converter_.get() &&
+ !bitstream_converter_->ConvertPacket(packet)) {
+ LOG(ERROR) << "Format converstion failed.";
+ }
+
// Enqueue the callback and attempt to satisfy a read immediately.
scoped_refptr<Buffer> buffer =
new AVPacketBuffer(packet, timestamp, duration);
@@ -197,6 +203,11 @@ void FFmpegDemuxerStream::FulfillPendingRead() {
read_callback->Run(buffer);
}
+void FFmpegDemuxerStream::SetBitstreamConverter(
+ BitstreamConverter* converter) {
+ bitstream_converter_.reset(converter);
+}
+
// static
base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp(
const AVRational& time_base, int64 timestamp) {
@@ -402,11 +413,38 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
// Create demuxer streams for all supported streams.
base::TimeDelta max_duration;
for (size_t i = 0; i < format_context_->nb_streams; ++i) {
- CodecType codec_type = format_context_->streams[i]->codec->codec_type;
+ AVCodecContext* codec_context = format_context_->streams[i]->codec;
+ CodecType codec_type = codec_context->codec_type;
if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) {
AVStream* stream = format_context_->streams[i];
FFmpegDemuxerStream* demuxer_stream
= new FFmpegDemuxerStream(this, stream);
+
+ // Initialize the bitstream if OpenMAX is enabled.
+ // TODO(hclam): Should be enabled by the decoder.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableOpenMax)) {
+ // TODO(ajwong): Unittest this branch of the if statement.
+ // TODO(hclam): In addition to codec we should also check the container.
+ const char* filter_name = NULL;
+ if (stream->codec->codec_id == CODEC_ID_H264) {
+ filter_name = "h264_mp4toannexb";
+ } else if (stream->codec->codec_id == CODEC_ID_MPEG4) {
+ filter_name = "mpeg4video_es";
+ } else if (stream->codec->codec_id == CODEC_ID_WMV3) {
+ filter_name = "vc1_asftorcv";
+ } else if (stream->codec->codec_id == CODEC_ID_VC1) {
+ filter_name = "vc1_asftoannexg";
+ }
+
+ if (filter_name) {
+ BitstreamConverter* bitstream_converter =
+ new FFmpegBitstreamConverter(filter_name, codec_context);
+ CHECK(bitstream_converter->Initialize());
+ demuxer_stream->SetBitstreamConverter(bitstream_converter);
+ }
+ }
+
DCHECK(demuxer_stream);
streams_.push_back(demuxer_stream);
packet_streams_.push_back(demuxer_stream);
@@ -492,26 +530,6 @@ void FFmpegDemuxer::DemuxTask() {
DCHECK_LT(packet->stream_index, static_cast<int>(packet_streams_.size()));
FFmpegDemuxerStream* demuxer_stream = packet_streams_[packet->stream_index];
if (demuxer_stream) {
- using switches::kEnableOpenMax;
- AVCodecContext* stream_context =
- format_context_->streams[packet->stream_index]->codec;
- if (stream_context->codec_id == CODEC_ID_H264 &&
- CommandLine::ForCurrentProcess()->HasSwitch(kEnableOpenMax)) {
- // TODO(ajwong): Unittest this branch of the if statement.
- // Also, move this code into the FFmpegDemuxerStream, so that the decoder
- // can enable a filter in the stream as needed.
- if (!bitstream_converter_.get()) {
- bitstream_converter_.reset(
- new FFmpegBitstreamConverter("h264_mp4toannexb", stream_context));
- CHECK(bitstream_converter_->Initialize());
- }
-
- if (!bitstream_converter_->ConvertPacket(packet.get())) {
- LOG(ERROR) << "Packet dropped: Format converstion failed.";
- packet.reset();
- }
- }
-
// Queue the packet with the appropriate stream. The stream takes
// ownership of the AVPacket.
if (packet.get()) {
diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h
index 899af84..bb55565 100644
--- a/media/filters/ffmpeg_demuxer.h
+++ b/media/filters/ffmpeg_demuxer.h
@@ -80,6 +80,9 @@ class FFmpegDemuxerStream : public DemuxerStream, public AVStreamProvider {
// AVStreamProvider implementation.
virtual AVStream* GetAVStream() { return stream_; }
+ // Bitstream converter to convert input packet.
+ void SetBitstreamConverter(BitstreamConverter* converter);
+
protected:
virtual void* QueryInterface(const char* interface_id);
@@ -110,6 +113,9 @@ class FFmpegDemuxerStream : public DemuxerStream, public AVStreamProvider {
typedef std::deque<Callback1<Buffer*>::Type*> ReadQueue;
ReadQueue read_queue_;
+ // Used to translate bitstream formats.
+ scoped_ptr<BitstreamConverter> bitstream_converter_;
+
DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
};
@@ -194,9 +200,6 @@ class FFmpegDemuxer : public Demuxer,
// Latest timestamp read on the demuxer thread.
base::TimeDelta current_timestamp_;
- // Used to translate bitstream formats. Lazily allocated.
- scoped_ptr<BitstreamConverter> bitstream_converter_;
-
// Two vector of streams:
// - |streams_| is indexed for the Demuxer interface GetStream(), which only
// contains supported streams and no NULL entries.
diff --git a/media/tools/omx_test/file_reader_util.cc b/media/tools/omx_test/file_reader_util.cc
index 700ffc0..4414cd7 100644
--- a/media/tools/omx_test/file_reader_util.cc
+++ b/media/tools/omx_test/file_reader_util.cc
@@ -156,6 +156,12 @@ bool FFmpegFileReader::Initialize() {
} else if (codec_context_->codec_id == CODEC_ID_MPEG4) {
converter_.reset(new media::FFmpegBitstreamConverter(
"mpeg4video_es", codec_context_));
+ } else if (codec_context_->codec_id == CODEC_ID_WMV3) {
+ converter_.reset(new media::FFmpegBitstreamConverter(
+ "vc1_asftorcv", codec_context_));
+ } else if (codec_context_->codec_id == CODEC_ID_VC1) {
+ converter_.reset(new media::FFmpegBitstreamConverter(
+ "vc1_asftoannexg", codec_context_));
}
if (converter_.get() && !converter_->Initialize()) {