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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // Calculate the duration. | 63 // Calculate the duration. |
64 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); | 64 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); |
65 | 65 |
66 if (stream_->codec->codec_id == CODEC_ID_H264) { | 66 if (stream_->codec->codec_id == CODEC_ID_H264) { |
67 bitstream_converter_.reset( | 67 bitstream_converter_.reset( |
68 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 68 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { | 72 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { |
73 uint8_t* side_data; | |
Tom Finegan
2013/02/25 22:56:06
uint8
vignesh
2013/02/25 23:33:14
Done.
| |
74 int side_data_size = 0; | |
75 AVPacket* pkt; | |
76 | |
73 DCHECK(message_loop_->BelongsToCurrentThread()); | 77 DCHECK(message_loop_->BelongsToCurrentThread()); |
74 | 78 |
75 if (stopped_ || end_of_stream_) { | 79 if (stopped_ || end_of_stream_) { |
76 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; | 80 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; |
77 return; | 81 return; |
78 } | 82 } |
79 | 83 |
80 // Convert the packet if there is a bitstream filter. | 84 // Convert the packet if there is a bitstream filter. |
81 if (packet->data && bitstream_converter_enabled_ && | 85 if (packet->data && bitstream_converter_enabled_ && |
82 !bitstream_converter_->ConvertPacket(packet.get())) { | 86 !bitstream_converter_->ConvertPacket(packet.get())) { |
83 LOG(ERROR) << "Format conversion failed."; | 87 LOG(ERROR) << "Format conversion failed."; |
84 } | 88 } |
85 | 89 |
90 // Get side data if any. For now, the only type of side_data is VP8 Alpha. We | |
91 // keep this generic so that other side_data types in the future can be | |
92 // handled the same way as well. | |
93 pkt = packet.get(); | |
94 av_packet_split_side_data(pkt); | |
95 side_data = av_packet_get_side_data(pkt, | |
96 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, | |
97 &side_data_size); | |
98 | |
86 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will | 99 // 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 | 100 // reference inner memory of FFmpeg. As such we should transfer the packet |
88 // into memory we control. | 101 // into memory we control. |
89 scoped_refptr<DecoderBuffer> buffer; | 102 scoped_refptr<DecoderBuffer> buffer; |
90 buffer = DecoderBuffer::CopyFrom(packet->data, packet->size); | 103 if (side_data_size) { |
Tom Finegan
2013/02/25 22:56:06
side_data_size > 0 ?
vignesh
2013/02/25 23:33:14
Done.
| |
104 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size, side_data, | |
105 side_data_size); | |
Tom Finegan
2013/02/25 22:56:06
It would be nice if side_data and side_data_size w
vignesh
2013/02/25 23:33:14
Done.
| |
106 } else { | |
107 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size); | |
108 } | |
91 buffer->SetTimestamp(ConvertStreamTimestamp( | 109 buffer->SetTimestamp(ConvertStreamTimestamp( |
92 stream_->time_base, packet->pts)); | 110 stream_->time_base, packet->pts)); |
93 buffer->SetDuration(ConvertStreamTimestamp( | 111 buffer->SetDuration(ConvertStreamTimestamp( |
94 stream_->time_base, packet->duration)); | 112 stream_->time_base, packet->duration)); |
95 if (buffer->GetTimestamp() != kNoTimestamp() && | 113 if (buffer->GetTimestamp() != kNoTimestamp() && |
96 last_packet_timestamp_ != kNoTimestamp() && | 114 last_packet_timestamp_ != kNoTimestamp() && |
97 last_packet_timestamp_ < buffer->GetTimestamp()) { | 115 last_packet_timestamp_ < buffer->GetTimestamp()) { |
98 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); | 116 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); |
99 demuxer_->NotifyBufferingChanged(); | 117 demuxer_->NotifyBufferingChanged(); |
100 } | 118 } |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 } | 696 } |
679 for (size_t i = 0; i < buffered.size(); ++i) | 697 for (size_t i = 0; i < buffered.size(); ++i) |
680 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 698 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
681 } | 699 } |
682 | 700 |
683 void FFmpegDemuxer::OnDataSourceError() { | 701 void FFmpegDemuxer::OnDataSourceError() { |
684 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 702 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
685 } | 703 } |
686 | 704 |
687 } // namespace media | 705 } // namespace media |
OLD | NEW |