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

Side by Side Diff: media/formats/mpeg/mpeg_audio_stream_parser_base.cc

Issue 2378443002: Fix MSE ADTS parsing on Android. (Closed)
Patch Set: Address comments. Created 4 years, 2 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
« no previous file with comments | « media/formats/mpeg/mpeg_audio_stream_parser_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mpeg/mpeg_audio_stream_parser_base.h" 5 #include "media/formats/mpeg/mpeg_audio_stream_parser_base.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 int MPEGAudioStreamParserBase::ParseFrame(const uint8_t* data, 172 int MPEGAudioStreamParserBase::ParseFrame(const uint8_t* data,
173 int size, 173 int size,
174 BufferQueue* buffers) { 174 BufferQueue* buffers) {
175 DVLOG(2) << __FUNCTION__ << "(" << size << ")"; 175 DVLOG(2) << __FUNCTION__ << "(" << size << ")";
176 176
177 int sample_rate; 177 int sample_rate;
178 ChannelLayout channel_layout; 178 ChannelLayout channel_layout;
179 int frame_size; 179 int frame_size;
180 int sample_count; 180 int sample_count;
181 bool metadata_frame = false; 181 bool metadata_frame = false;
182 int bytes_read = ParseFrameHeader(data, 182 std::vector<uint8_t> extra_data;
183 size, 183 int bytes_read =
184 &frame_size, 184 ParseFrameHeader(data, size, &frame_size, &sample_rate, &channel_layout,
185 &sample_rate, 185 &sample_count, &metadata_frame, &extra_data);
186 &channel_layout,
187 &sample_count,
188 &metadata_frame);
189 186
190 if (bytes_read <= 0) 187 if (bytes_read <= 0)
191 return bytes_read; 188 return bytes_read;
192 189
193 // Make sure data contains the entire frame. 190 // Make sure data contains the entire frame.
194 if (size < frame_size) 191 if (size < frame_size)
195 return 0; 192 return 0;
196 193
197 DVLOG(2) << " sample_rate " << sample_rate 194 DVLOG(2) << " sample_rate " << sample_rate << " channel_layout "
198 << " channel_layout " << channel_layout 195 << channel_layout << " frame_size " << frame_size << " sample_count "
199 << " frame_size " << frame_size 196 << sample_count;
200 << " sample_count " << sample_count;
201 197
202 if (config_.IsValidConfig() && 198 if (config_.IsValidConfig() && (config_.samples_per_second() != sample_rate ||
203 (config_.samples_per_second() != sample_rate || 199 config_.channel_layout() != channel_layout)) {
204 config_.channel_layout() != channel_layout)) {
205 // Clear config data so that a config change is initiated. 200 // Clear config data so that a config change is initiated.
206 config_ = AudioDecoderConfig(); 201 config_ = AudioDecoderConfig();
207 202
208 // Send all buffers associated with the previous config. 203 // Send all buffers associated with the previous config.
209 if (!buffers->empty() && !SendBuffers(buffers, true)) 204 if (!buffers->empty() && !SendBuffers(buffers, true))
210 return -1; 205 return -1;
211 } 206 }
212 207
213 if (!config_.IsValidConfig()) { 208 if (!config_.IsValidConfig()) {
214 config_.Initialize(audio_codec_, kSampleFormatF32, channel_layout, 209 config_.Initialize(audio_codec_, kSampleFormatF32, channel_layout,
215 sample_rate, std::vector<uint8_t>(), Unencrypted(), 210 sample_rate, extra_data, Unencrypted(),
216 base::TimeDelta(), codec_delay_); 211 base::TimeDelta(), codec_delay_);
217 212
218 base::TimeDelta base_timestamp; 213 base::TimeDelta base_timestamp;
219 if (timestamp_helper_) 214 if (timestamp_helper_)
220 base_timestamp = timestamp_helper_->GetTimestamp(); 215 base_timestamp = timestamp_helper_->GetTimestamp();
221 216
222 timestamp_helper_.reset(new AudioTimestampHelper(sample_rate)); 217 timestamp_helper_.reset(new AudioTimestampHelper(sample_rate));
223 timestamp_helper_->SetBaseTimestamp(base_timestamp); 218 timestamp_helper_->SetBaseTimestamp(base_timestamp);
224 219
225 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); 220 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 289
295 if (size < 10) 290 if (size < 10)
296 return 0; 291 return 0;
297 292
298 BitReader reader(data, size); 293 BitReader reader(data, size);
299 int32_t id; 294 int32_t id;
300 int version; 295 int version;
301 uint8_t flags; 296 uint8_t flags;
302 int32_t id3_size; 297 int32_t id3_size;
303 298
304 if (!reader.ReadBits(24, &id) || 299 if (!reader.ReadBits(24, &id) || !reader.ReadBits(16, &version) ||
305 !reader.ReadBits(16, &version) || 300 !reader.ReadBits(8, &flags) || !ParseSyncSafeInt(&reader, &id3_size)) {
306 !reader.ReadBits(8, &flags) ||
307 !ParseSyncSafeInt(&reader, &id3_size)) {
308 return -1; 301 return -1;
309 } 302 }
310 303
311 int32_t actual_tag_size = 10 + id3_size; 304 int32_t actual_tag_size = 10 + id3_size;
312 305
313 // Increment size if 'Footer present' flag is set. 306 // Increment size if 'Footer present' flag is set.
314 if (flags & 0x10) 307 if (flags & 0x10)
315 actual_tag_size += 10; 308 actual_tag_size += 10;
316 309
317 // Make sure we have the entire tag. 310 // Make sure we have the entire tag.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (!candidate_start_code) 349 if (!candidate_start_code)
357 return 0; 350 return 0;
358 351
359 bool parse_header_failed = false; 352 bool parse_header_failed = false;
360 const uint8_t* sync = candidate_start_code; 353 const uint8_t* sync = candidate_start_code;
361 // Try to find 3 valid frames in a row. 3 was selected to decrease 354 // Try to find 3 valid frames in a row. 3 was selected to decrease
362 // the probability of false positives. 355 // the probability of false positives.
363 for (int i = 0; i < 3; ++i) { 356 for (int i = 0; i < 3; ++i) {
364 int sync_size = end - sync; 357 int sync_size = end - sync;
365 int frame_size; 358 int frame_size;
366 int sync_bytes = ParseFrameHeader( 359 int sync_bytes = ParseFrameHeader(sync, sync_size, &frame_size, nullptr,
367 sync, sync_size, &frame_size, NULL, NULL, NULL, NULL); 360 nullptr, nullptr, nullptr, nullptr);
368 361
369 if (sync_bytes == 0) 362 if (sync_bytes == 0)
370 return 0; 363 return 0;
371 364
372 if (sync_bytes > 0) { 365 if (sync_bytes > 0) {
373 DCHECK_LT(sync_bytes, sync_size); 366 DCHECK_LT(sync_bytes, sync_size);
374 367
375 // Skip over this frame so we can check the next one. 368 // Skip over this frame so we can check the next one.
376 sync += frame_size; 369 sync += frame_size;
377 370
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (end_of_segment) { 410 if (end_of_segment) {
418 in_media_segment_ = false; 411 in_media_segment_ = false;
419 end_of_segment_cb_.Run(); 412 end_of_segment_cb_.Run();
420 } 413 }
421 414
422 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); 415 timestamp_helper_->SetBaseTimestamp(base::TimeDelta());
423 return true; 416 return true;
424 } 417 }
425 418
426 } // namespace media 419 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/mpeg/mpeg_audio_stream_parser_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698