| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/formats/mp2t/es_parser_mpeg1audio.h" | 5 #include "media/formats/mp2t/es_parser_mpeg1audio.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 Mpeg1AudioFrame mpeg1audio_frame; | 53 Mpeg1AudioFrame mpeg1audio_frame; |
| 54 while (LookForMpeg1AudioFrame(&mpeg1audio_frame)) { | 54 while (LookForMpeg1AudioFrame(&mpeg1audio_frame)) { |
| 55 // Update the audio configuration if needed. | 55 // Update the audio configuration if needed. |
| 56 DCHECK_GE(mpeg1audio_frame.size, MPEG1AudioStreamParser::kHeaderSize); | 56 DCHECK_GE(mpeg1audio_frame.size, MPEG1AudioStreamParser::kHeaderSize); |
| 57 if (!UpdateAudioConfiguration(mpeg1audio_frame.data)) | 57 if (!UpdateAudioConfiguration(mpeg1audio_frame.data)) |
| 58 return false; | 58 return false; |
| 59 | 59 |
| 60 // Get the PTS & the duration of this access unit. | 60 // Get the PTS & the duration of this access unit. |
| 61 TimingDesc current_timing_desc = | 61 TimingDesc current_timing_desc = |
| 62 GetTimingDescriptor(mpeg1audio_frame.queue_offset); | 62 GetTimingDescriptor(mpeg1audio_frame.queue_offset); |
| 63 if (current_timing_desc.pts != kNoTimestamp()) | 63 if (current_timing_desc.pts != kNoTimestamp) |
| 64 audio_timestamp_helper_->SetBaseTimestamp(current_timing_desc.pts); | 64 audio_timestamp_helper_->SetBaseTimestamp(current_timing_desc.pts); |
| 65 | 65 |
| 66 if (audio_timestamp_helper_->base_timestamp() == kNoTimestamp()) { | 66 if (audio_timestamp_helper_->base_timestamp() == kNoTimestamp) { |
| 67 DVLOG(1) << "Skipping audio frame with unknown timestamp"; | 67 DVLOG(1) << "Skipping audio frame with unknown timestamp"; |
| 68 SkipMpeg1AudioFrame(mpeg1audio_frame); | 68 SkipMpeg1AudioFrame(mpeg1audio_frame); |
| 69 continue; | 69 continue; |
| 70 } | 70 } |
| 71 base::TimeDelta current_pts = audio_timestamp_helper_->GetTimestamp(); | 71 base::TimeDelta current_pts = audio_timestamp_helper_->GetTimestamp(); |
| 72 base::TimeDelta frame_duration = | 72 base::TimeDelta frame_duration = |
| 73 audio_timestamp_helper_->GetFrameDuration( | 73 audio_timestamp_helper_->GetFrameDuration( |
| 74 mpeg1audio_frame.sample_count); | 74 mpeg1audio_frame.sample_count); |
| 75 | 75 |
| 76 // Emit an audio frame. | 76 // Emit an audio frame. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // field for Mpeg1 audio. If yes, we should generate this field. | 172 // field for Mpeg1 audio. If yes, we should generate this field. |
| 173 AudioDecoderConfig audio_decoder_config( | 173 AudioDecoderConfig audio_decoder_config( |
| 174 kCodecMP3, kSampleFormatS16, header.channel_layout, header.sample_rate, | 174 kCodecMP3, kSampleFormatS16, header.channel_layout, header.sample_rate, |
| 175 EmptyExtraData(), Unencrypted()); | 175 EmptyExtraData(), Unencrypted()); |
| 176 | 176 |
| 177 if (!audio_decoder_config.Matches(last_audio_decoder_config_)) { | 177 if (!audio_decoder_config.Matches(last_audio_decoder_config_)) { |
| 178 DVLOG(1) << "Sampling frequency: " << header.sample_rate; | 178 DVLOG(1) << "Sampling frequency: " << header.sample_rate; |
| 179 DVLOG(1) << "Channel layout: " << header.channel_layout; | 179 DVLOG(1) << "Channel layout: " << header.channel_layout; |
| 180 // Reset the timestamp helper to use a new time scale. | 180 // Reset the timestamp helper to use a new time scale. |
| 181 if (audio_timestamp_helper_ && | 181 if (audio_timestamp_helper_ && |
| 182 audio_timestamp_helper_->base_timestamp() != kNoTimestamp()) { | 182 audio_timestamp_helper_->base_timestamp() != kNoTimestamp) { |
| 183 base::TimeDelta base_timestamp = audio_timestamp_helper_->GetTimestamp(); | 183 base::TimeDelta base_timestamp = audio_timestamp_helper_->GetTimestamp(); |
| 184 audio_timestamp_helper_.reset( | 184 audio_timestamp_helper_.reset( |
| 185 new AudioTimestampHelper(header.sample_rate)); | 185 new AudioTimestampHelper(header.sample_rate)); |
| 186 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp); | 186 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp); |
| 187 } else { | 187 } else { |
| 188 audio_timestamp_helper_.reset( | 188 audio_timestamp_helper_.reset( |
| 189 new AudioTimestampHelper(header.sample_rate)); | 189 new AudioTimestampHelper(header.sample_rate)); |
| 190 } | 190 } |
| 191 // Audio config notification. | 191 // Audio config notification. |
| 192 last_audio_decoder_config_ = audio_decoder_config; | 192 last_audio_decoder_config_ = audio_decoder_config; |
| 193 new_audio_config_cb_.Run(audio_decoder_config); | 193 new_audio_config_cb_.Run(audio_decoder_config); |
| 194 } | 194 } |
| 195 | 195 |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void EsParserMpeg1Audio::SkipMpeg1AudioFrame( | 199 void EsParserMpeg1Audio::SkipMpeg1AudioFrame( |
| 200 const Mpeg1AudioFrame& mpeg1audio_frame) { | 200 const Mpeg1AudioFrame& mpeg1audio_frame) { |
| 201 DCHECK_EQ(mpeg1audio_frame.queue_offset, es_queue_->head()); | 201 DCHECK_EQ(mpeg1audio_frame.queue_offset, es_queue_->head()); |
| 202 es_queue_->Pop(mpeg1audio_frame.size); | 202 es_queue_->Pop(mpeg1audio_frame.size); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace mp2t | 205 } // namespace mp2t |
| 206 } // namespace media | 206 } // namespace media |
| OLD | NEW |