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/base64.h" | 10 #include "base/base64.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 base::Time timeline_offset; | 43 base::Time timeline_offset; |
44 if (entry != NULL && entry->value != NULL && | 44 if (entry != NULL && entry->value != NULL && |
45 FFmpegUTCDateToTime(entry->value, &timeline_offset)) { | 45 FFmpegUTCDateToTime(entry->value, &timeline_offset)) { |
46 return timeline_offset; | 46 return timeline_offset; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 return base::Time(); | 50 return base::Time(); |
51 } | 51 } |
52 | 52 |
53 static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) { | |
54 return base::TimeDelta::FromMicroseconds( | |
55 frames * base::Time::kMicrosecondsPerSecond / sample_rate); | |
56 } | |
57 | |
53 // | 58 // |
54 // FFmpegDemuxerStream | 59 // FFmpegDemuxerStream |
55 // | 60 // |
56 FFmpegDemuxerStream::FFmpegDemuxerStream( | 61 FFmpegDemuxerStream::FFmpegDemuxerStream( |
57 FFmpegDemuxer* demuxer, | 62 FFmpegDemuxer* demuxer, |
58 AVStream* stream) | 63 AVStream* stream) |
59 : demuxer_(demuxer), | 64 : demuxer_(demuxer), |
60 task_runner_(base::MessageLoopProxy::current()), | 65 task_runner_(base::MessageLoopProxy::current()), |
61 stream_(stream), | 66 stream_(stream), |
62 type_(UNKNOWN), | 67 type_(UNKNOWN), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 if (side_data_size > 0) { | 187 if (side_data_size > 0) { |
183 buffer = DecoderBuffer::CopyFrom(packet.get()->data + data_offset, | 188 buffer = DecoderBuffer::CopyFrom(packet.get()->data + data_offset, |
184 packet.get()->size - data_offset, | 189 packet.get()->size - data_offset, |
185 side_data, side_data_size); | 190 side_data, side_data_size); |
186 } else { | 191 } else { |
187 buffer = DecoderBuffer::CopyFrom(packet.get()->data + data_offset, | 192 buffer = DecoderBuffer::CopyFrom(packet.get()->data + data_offset, |
188 packet.get()->size - data_offset); | 193 packet.get()->size - data_offset); |
189 } | 194 } |
190 | 195 |
191 int skip_samples_size = 0; | 196 int skip_samples_size = 0; |
192 uint8* skip_samples = av_packet_get_side_data(packet.get(), | 197 const uint32* skip_samples_ptr = |
193 AV_PKT_DATA_SKIP_SAMPLES, | 198 reinterpret_cast<const uint32*>(av_packet_get_side_data( |
194 &skip_samples_size); | 199 packet.get(), AV_PKT_DATA_SKIP_SAMPLES, &skip_samples_size)); |
195 const int kSkipSamplesValidSize = 10; | 200 const int kSkipSamplesValidSize = 10; |
196 const int kSkipSamplesOffset = 4; | 201 const int kSkipEndSamplesOffset = 4; |
DaleCurtis
2014/05/01 01:44:24
Note to self: This is wrong now, it should be in u
DaleCurtis
2014/05/01 19:21:27
Done.
| |
197 if (skip_samples_size >= kSkipSamplesValidSize) { | 202 if (skip_samples_size >= kSkipSamplesValidSize) { |
198 int discard_padding_samples = base::ByteSwapToLE32( | 203 // Because FFmpeg rolls codec delay and skip samples into one we can only |
199 *(reinterpret_cast<const uint32*>(skip_samples + | 204 // allow front discard padding on the first buffer. Otherwise the discard |
200 kSkipSamplesOffset))); | 205 // helper can't figure out which data to discard. See AudioDiscardHelper. |
201 // TODO(vigneshv): Change decoder buffer to use number of samples so that | 206 int discard_front_samples = base::ByteSwapToLE32(*skip_samples_ptr); |
202 // this conversion can be avoided. | 207 if (last_packet_timestamp_ != kNoTimestamp()) { |
203 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds( | 208 DLOG(ERROR) << "Skip samples are only allowed for the first packet."; |
204 discard_padding_samples * 1000000.0 / | 209 discard_front_samples = 0; |
205 audio_decoder_config().samples_per_second())); | 210 } |
211 | |
212 const int discard_end_samples = | |
213 base::ByteSwapToLE32(*(skip_samples_ptr + kSkipEndSamplesOffset)); | |
214 const int samples_per_second = | |
215 audio_decoder_config().samples_per_second(); | |
216 buffer->set_discard_padding(std::make_pair( | |
217 FramesToTimeDelta(discard_front_samples, samples_per_second), | |
218 FramesToTimeDelta(discard_end_samples, samples_per_second))); | |
206 } | 219 } |
207 | 220 |
208 if (decrypt_config) | 221 if (decrypt_config) |
209 buffer->set_decrypt_config(decrypt_config.Pass()); | 222 buffer->set_decrypt_config(decrypt_config.Pass()); |
210 } | 223 } |
211 | 224 |
212 buffer->set_timestamp(ConvertStreamTimestamp( | 225 buffer->set_timestamp(ConvertStreamTimestamp( |
213 stream_->time_base, packet->pts)); | 226 stream_->time_base, packet->pts)); |
214 buffer->set_duration(ConvertStreamTimestamp( | 227 buffer->set_duration(ConvertStreamTimestamp( |
215 stream_->time_base, packet->duration)); | 228 stream_->time_base, packet->duration)); |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 } | 1029 } |
1017 for (size_t i = 0; i < buffered.size(); ++i) | 1030 for (size_t i = 0; i < buffered.size(); ++i) |
1018 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 1031 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
1019 } | 1032 } |
1020 | 1033 |
1021 void FFmpegDemuxer::OnDataSourceError() { | 1034 void FFmpegDemuxer::OnDataSourceError() { |
1022 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 1035 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
1023 } | 1036 } |
1024 | 1037 |
1025 } // namespace media | 1038 } // namespace media |
OLD | NEW |