Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: media/filters/ffmpeg_demuxer.cc

Issue 12157002: Adding YUVA support for enabling Alpha Playback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving VP8 Alpha Playback behind its own flag Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_demuxer.h" 5 #include "media/filters/ffmpeg_demuxer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/task_runner_util.h" 18 #include "base/task_runner_util.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "media/base/audio_decoder_config.h" 20 #include "media/base/audio_decoder_config.h"
21 #include "media/base/bind_to_loop.h" 21 #include "media/base/bind_to_loop.h"
22 #include "media/base/decoder_buffer.h" 22 #include "media/base/decoder_buffer.h"
23 #include "media/base/limits.h" 23 #include "media/base/limits.h"
24 #include "media/base/media_switches.h" 24 #include "media/base/media_switches.h"
25 #include "media/base/video_decoder_config.h" 25 #include "media/base/video_decoder_config.h"
26 #include "media/ffmpeg/ffmpeg_common.h" 26 #include "media/ffmpeg/ffmpeg_common.h"
27 #include "media/filters/ffmpeg_glue.h" 27 #include "media/filters/ffmpeg_glue.h"
28 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" 28 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h"
29 29
30 extern "C" {
31 #include "third_party/ffmpeg/libavcodec/avcodec.h"
32 }
33
30 namespace media { 34 namespace media {
31 35
32 // 36 //
33 // FFmpegDemuxerStream 37 // FFmpegDemuxerStream
34 // 38 //
35 FFmpegDemuxerStream::FFmpegDemuxerStream( 39 FFmpegDemuxerStream::FFmpegDemuxerStream(
36 FFmpegDemuxer* demuxer, 40 FFmpegDemuxer* demuxer,
37 AVStream* stream) 41 AVStream* stream)
38 : demuxer_(demuxer), 42 : demuxer_(demuxer),
39 message_loop_(base::MessageLoopProxy::current()), 43 message_loop_(base::MessageLoopProxy::current()),
(...skipping 23 matching lines...) Expand all
63 // Calculate the duration. 67 // Calculate the duration.
64 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); 68 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration);
65 69
66 if (stream_->codec->codec_id == CODEC_ID_H264) { 70 if (stream_->codec->codec_id == CODEC_ID_H264) {
67 bitstream_converter_.reset( 71 bitstream_converter_.reset(
68 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); 72 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec));
69 } 73 }
70 } 74 }
71 75
72 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { 76 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
77
78 uint8_t *side_data;
fgalligan1 2013/02/12 01:20:58 nit: asterisk adjacent to type.
vigneshv 2013/02/14 19:06:14 Done.
79 int side_data_size = 0;
80 //int i;
fgalligan1 2013/02/12 01:20:58 remove
vigneshv 2013/02/14 19:06:14 Done.
81 AVPacket *pkt;
fgalligan1 2013/02/12 01:20:58 nit: asterisk adjacent to type.
vigneshv 2013/02/14 19:06:14 Done.
82
73 DCHECK(message_loop_->BelongsToCurrentThread()); 83 DCHECK(message_loop_->BelongsToCurrentThread());
74 84
75 if (stopped_ || end_of_stream_) { 85 if (stopped_ || end_of_stream_) {
76 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; 86 NOTREACHED() << "Attempted to enqueue packet on a stopped stream";
77 return; 87 return;
78 } 88 }
79 89
80 // Convert the packet if there is a bitstream filter. 90 // Convert the packet if there is a bitstream filter.
81 if (packet->data && bitstream_converter_enabled_ && 91 if (packet->data && bitstream_converter_enabled_ &&
82 !bitstream_converter_->ConvertPacket(packet.get())) { 92 !bitstream_converter_->ConvertPacket(packet.get())) {
83 LOG(ERROR) << "Format conversion failed."; 93 LOG(ERROR) << "Format conversion failed.";
84 } 94 }
85 95
96 // Get the alpha data if any
97 pkt = packet.get();
98 av_packet_split_side_data(pkt);
99 side_data = av_packet_get_side_data(pkt,
100 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
101 &side_data_size);
102
86 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will 103 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will
87 // reference inner memory of FFmpeg. As such we should transfer the packet 104 // reference inner memory of FFmpeg. As such we should transfer the packet
88 // into memory we control. 105 // into memory we control.
89 scoped_refptr<DecoderBuffer> buffer; 106 scoped_refptr<DecoderBuffer> buffer;
90 buffer = DecoderBuffer::CopyFrom(packet->data, packet->size); 107 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size);
108 if (side_data_size) {
109 buffer->SetSideData(side_data, side_data_size);
110 }
91 buffer->SetTimestamp(ConvertStreamTimestamp( 111 buffer->SetTimestamp(ConvertStreamTimestamp(
92 stream_->time_base, packet->pts)); 112 stream_->time_base, packet->pts));
93 buffer->SetDuration(ConvertStreamTimestamp( 113 buffer->SetDuration(ConvertStreamTimestamp(
94 stream_->time_base, packet->duration)); 114 stream_->time_base, packet->duration));
95 if (buffer->GetTimestamp() != kNoTimestamp() && 115 if (buffer->GetTimestamp() != kNoTimestamp() &&
96 last_packet_timestamp_ != kNoTimestamp() && 116 last_packet_timestamp_ != kNoTimestamp() &&
97 last_packet_timestamp_ < buffer->GetTimestamp()) { 117 last_packet_timestamp_ < buffer->GetTimestamp()) {
98 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); 118 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp());
99 demuxer_->NotifyBufferingChanged(); 119 demuxer_->NotifyBufferingChanged();
100 } 120 }
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 } 698 }
679 for (size_t i = 0; i < buffered.size(); ++i) 699 for (size_t i = 0; i < buffered.size(); ++i)
680 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); 700 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i));
681 } 701 }
682 702
683 void FFmpegDemuxer::OnDataSourceError() { 703 void FFmpegDemuxer::OnDataSourceError() {
684 host_->OnDemuxerError(PIPELINE_ERROR_READ); 704 host_->OnDemuxerError(PIPELINE_ERROR_READ);
685 } 705 }
686 706
687 } // namespace media 707 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698