Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
|
scherkus (not reviewing)
2013/02/22 23:18:01
this include should go inside ffmpeg_common.h
vignesh
2013/02/25 21:51:42
Done.
| |
| 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 Loading... | |
| 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 | |
|
scherkus (not reviewing)
2013/02/22 23:18:01
remove extra blank line
vignesh
2013/02/25 21:51:42
Done.
| |
| 78 uint8_t* side_data; | |
| 79 int side_data_size = 0; | |
| 80 AVPacket* pkt; | |
| 81 | |
| 73 DCHECK(message_loop_->BelongsToCurrentThread()); | 82 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 74 | 83 |
| 75 if (stopped_ || end_of_stream_) { | 84 if (stopped_ || end_of_stream_) { |
| 76 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; | 85 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; |
| 77 return; | 86 return; |
| 78 } | 87 } |
| 79 | 88 |
| 80 // Convert the packet if there is a bitstream filter. | 89 // Convert the packet if there is a bitstream filter. |
| 81 if (packet->data && bitstream_converter_enabled_ && | 90 if (packet->data && bitstream_converter_enabled_ && |
| 82 !bitstream_converter_->ConvertPacket(packet.get())) { | 91 !bitstream_converter_->ConvertPacket(packet.get())) { |
| 83 LOG(ERROR) << "Format conversion failed."; | 92 LOG(ERROR) << "Format conversion failed."; |
| 84 } | 93 } |
| 85 | 94 |
| 95 // Get the alpha data if any | |
|
scherkus (not reviewing)
2013/02/22 23:18:01
nit: I'm sure side data is used for more than just
vignesh
2013/02/25 21:51:42
Done.
| |
| 96 pkt = packet.get(); | |
| 97 av_packet_split_side_data(pkt); | |
| 98 side_data = av_packet_get_side_data(pkt, | |
| 99 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, | |
| 100 &side_data_size); | |
| 101 | |
| 86 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will | 102 // 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 | 103 // reference inner memory of FFmpeg. As such we should transfer the packet |
| 88 // into memory we control. | 104 // into memory we control. |
| 89 scoped_refptr<DecoderBuffer> buffer; | 105 scoped_refptr<DecoderBuffer> buffer; |
| 90 buffer = DecoderBuffer::CopyFrom(packet->data, packet->size); | 106 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size); |
| 107 if (side_data_size) { | |
| 108 buffer->SetSideData(side_data, side_data_size); | |
| 109 } | |
| 91 buffer->SetTimestamp(ConvertStreamTimestamp( | 110 buffer->SetTimestamp(ConvertStreamTimestamp( |
| 92 stream_->time_base, packet->pts)); | 111 stream_->time_base, packet->pts)); |
| 93 buffer->SetDuration(ConvertStreamTimestamp( | 112 buffer->SetDuration(ConvertStreamTimestamp( |
| 94 stream_->time_base, packet->duration)); | 113 stream_->time_base, packet->duration)); |
| 95 if (buffer->GetTimestamp() != kNoTimestamp() && | 114 if (buffer->GetTimestamp() != kNoTimestamp() && |
| 96 last_packet_timestamp_ != kNoTimestamp() && | 115 last_packet_timestamp_ != kNoTimestamp() && |
| 97 last_packet_timestamp_ < buffer->GetTimestamp()) { | 116 last_packet_timestamp_ < buffer->GetTimestamp()) { |
| 98 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); | 117 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); |
| 99 demuxer_->NotifyBufferingChanged(); | 118 demuxer_->NotifyBufferingChanged(); |
| 100 } | 119 } |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 } | 697 } |
| 679 for (size_t i = 0; i < buffered.size(); ++i) | 698 for (size_t i = 0; i < buffered.size(); ++i) |
| 680 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 699 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
| 681 } | 700 } |
| 682 | 701 |
| 683 void FFmpegDemuxer::OnDataSourceError() { | 702 void FFmpegDemuxer::OnDataSourceError() { |
| 684 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 703 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
| 685 } | 704 } |
| 686 | 705 |
| 687 } // namespace media | 706 } // namespace media |
| OLD | NEW |