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

Side by Side Diff: media/formats/mp2t/es_parser_adts.cc

Issue 497203004: Mpeg2 TS parser: Es parsing using an ES byte queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing es_parser.cc Created 6 years, 3 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 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_adts.h" 5 #include "media/formats/mp2t/es_parser_adts.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 DCHECK_EQ(adts_frame.queue_offset, es_queue_->head()); 111 DCHECK_EQ(adts_frame.queue_offset, es_queue_->head());
112 es_queue_->Pop(adts_frame.size); 112 es_queue_->Pop(adts_frame.size);
113 } 113 }
114 114
115 EsParserAdts::EsParserAdts( 115 EsParserAdts::EsParserAdts(
116 const NewAudioConfigCB& new_audio_config_cb, 116 const NewAudioConfigCB& new_audio_config_cb,
117 const EmitBufferCB& emit_buffer_cb, 117 const EmitBufferCB& emit_buffer_cb,
118 bool sbr_in_mimetype) 118 bool sbr_in_mimetype)
119 : new_audio_config_cb_(new_audio_config_cb), 119 : new_audio_config_cb_(new_audio_config_cb),
120 emit_buffer_cb_(emit_buffer_cb), 120 emit_buffer_cb_(emit_buffer_cb),
121 sbr_in_mimetype_(sbr_in_mimetype), 121 sbr_in_mimetype_(sbr_in_mimetype) {
122 es_queue_(new media::OffsetByteQueue()) {
123 } 122 }
124 123
125 EsParserAdts::~EsParserAdts() { 124 EsParserAdts::~EsParserAdts() {
126 } 125 }
127 126
128 bool EsParserAdts::Parse(const uint8* buf, int size, 127 bool EsParserAdts::ParseFromEsQueue() {
129 base::TimeDelta pts,
130 DecodeTimestamp dts) {
131 // The incoming PTS applies to the access unit that comes just after
132 // the beginning of |buf|.
133 if (pts != kNoTimestamp())
134 pts_list_.push_back(EsPts(es_queue_->tail(), pts));
135
136 // Copy the input data to the ES buffer.
137 es_queue_->Push(buf, size);
138
139 // Look for every ADTS frame in the ES buffer. 128 // Look for every ADTS frame in the ES buffer.
140 AdtsFrame adts_frame; 129 AdtsFrame adts_frame;
141 while (LookForAdtsFrame(&adts_frame)) { 130 while (LookForAdtsFrame(&adts_frame)) {
142 // Update the audio configuration if needed. 131 // Update the audio configuration if needed.
143 DCHECK_GE(adts_frame.size, kADTSHeaderMinSize); 132 DCHECK_GE(adts_frame.size, kADTSHeaderMinSize);
144 if (!UpdateAudioConfiguration(adts_frame.data)) 133 if (!UpdateAudioConfiguration(adts_frame.data))
145 return false; 134 return false;
146 135
147 // Get the PTS & the duration of this access unit. 136 // Get the PTS & the duration of this access unit.
148 while (!pts_list_.empty() && 137 TimingDesc current_timing_desc =
149 pts_list_.front().first <= adts_frame.queue_offset) { 138 GetTimingDescriptor(adts_frame.queue_offset);
150 audio_timestamp_helper_->SetBaseTimestamp(pts_list_.front().second); 139 if (current_timing_desc.pts != kNoTimestamp())
151 pts_list_.pop_front(); 140 audio_timestamp_helper_->SetBaseTimestamp(current_timing_desc.pts);
152 }
153 141
154 if (audio_timestamp_helper_->base_timestamp() == kNoTimestamp()) { 142 if (audio_timestamp_helper_->base_timestamp() == kNoTimestamp()) {
155 DVLOG(1) << "Audio frame with unknown timestamp"; 143 DVLOG(1) << "Audio frame with unknown timestamp";
156 return false; 144 return false;
157 } 145 }
158 base::TimeDelta current_pts = audio_timestamp_helper_->GetTimestamp(); 146 base::TimeDelta current_pts = audio_timestamp_helper_->GetTimestamp();
159 base::TimeDelta frame_duration = 147 base::TimeDelta frame_duration =
160 audio_timestamp_helper_->GetFrameDuration(kSamplesPerAACFrame); 148 audio_timestamp_helper_->GetFrameDuration(kSamplesPerAACFrame);
161 149
162 // Emit an audio frame. 150 // Emit an audio frame.
(...skipping 18 matching lines...) Expand all
181 SkipAdtsFrame(adts_frame); 169 SkipAdtsFrame(adts_frame);
182 } 170 }
183 171
184 return true; 172 return true;
185 } 173 }
186 174
187 void EsParserAdts::Flush() { 175 void EsParserAdts::Flush() {
188 } 176 }
189 177
190 void EsParserAdts::Reset() { 178 void EsParserAdts::Reset() {
191 es_queue_.reset(new media::OffsetByteQueue()); 179 EsParser::Reset();
wolenetz 2014/08/26 23:01:44 This seems fragile to require overriding method to
damienv1 2014/08/27 16:23:43 Done.
192 pts_list_.clear();
193 last_audio_decoder_config_ = AudioDecoderConfig(); 180 last_audio_decoder_config_ = AudioDecoderConfig();
194 } 181 }
195 182
196 bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) { 183 bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) {
197 size_t frequency_index = ExtractAdtsFrequencyIndex(adts_header); 184 size_t frequency_index = ExtractAdtsFrequencyIndex(adts_header);
198 if (frequency_index >= kADTSFrequencyTableSize) { 185 if (frequency_index >= kADTSFrequencyTableSize) {
199 // Frequency index 13 & 14 are reserved 186 // Frequency index 13 & 14 are reserved
200 // while 15 means that the frequency is explicitly written 187 // while 15 means that the frequency is explicitly written
201 // (not supported). 188 // (not supported).
202 return false; 189 return false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // Audio config notification. 250 // Audio config notification.
264 last_audio_decoder_config_ = audio_decoder_config; 251 last_audio_decoder_config_ = audio_decoder_config;
265 new_audio_config_cb_.Run(audio_decoder_config); 252 new_audio_config_cb_.Run(audio_decoder_config);
266 } 253 }
267 254
268 return true; 255 return true;
269 } 256 }
270 257
271 } // namespace mp2t 258 } // namespace mp2t
272 } // namespace media 259 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698