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

Side by Side Diff: media/mp4/mp4_stream_parser.cc

Issue 10780026: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove aac.h. Created 8 years, 5 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/mp4/es_descriptor_unittest.cc ('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 (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/mp4/mp4_stream_parser.h" 5 #include "media/mp4/mp4_stream_parser.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/stream_parser_buffer.h" 12 #include "media/base/stream_parser_buffer.h"
13 #include "media/base/video_decoder_config.h" 13 #include "media/base/video_decoder_config.h"
14 #include "media/mp4/box_definitions.h" 14 #include "media/mp4/box_definitions.h"
15 #include "media/mp4/box_reader.h" 15 #include "media/mp4/box_reader.h"
16 #include "media/mp4/es_descriptor.h"
16 #include "media/mp4/rcheck.h" 17 #include "media/mp4/rcheck.h"
17 18
18 namespace media { 19 namespace media {
19 namespace mp4 { 20 namespace mp4 {
20 21
21 MP4StreamParser::MP4StreamParser() 22 MP4StreamParser::MP4StreamParser()
22 : state_(kWaitingForInit), 23 : state_(kWaitingForInit),
23 moof_head_(0), 24 moof_head_(0),
24 mdat_tail_(0), 25 mdat_tail_(0),
25 has_audio_(false), 26 has_audio_(false),
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 desc_idx -= 1; // BMFF descriptor index is one-based 169 desc_idx -= 1; // BMFF descriptor index is one-based
169 170
170 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { 171 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) {
171 RCHECK(!samp_descr.audio_entries.empty()); 172 RCHECK(!samp_descr.audio_entries.empty());
172 173
173 // It is not uncommon to find otherwise-valid files with incorrect sample 174 // It is not uncommon to find otherwise-valid files with incorrect sample
174 // description indices, so we fail gracefully in that case. 175 // description indices, so we fail gracefully in that case.
175 if (static_cast<uint32>(desc_idx) >= samp_descr.audio_entries.size()) 176 if (static_cast<uint32>(desc_idx) >= samp_descr.audio_entries.size())
176 desc_idx = 0; 177 desc_idx = 0;
177 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; 178 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx];
179 const AAC& aac = entry.esds.aac;
178 180
179 // TODO(strobe): We accept all format values, pending clarification on 181 // TODO(strobe): We accept all format values, pending clarification on
180 // the formats used for encrypted media (http://crbug.com/132351). 182 // the formats used for encrypted media (http://crbug.com/132351).
181 // RCHECK(entry.format == FOURCC_MP4A || 183 // RCHECK(entry.format == FOURCC_MP4A ||
182 // (entry.format == FOURCC_ENCA && 184 // (entry.format == FOURCC_ENCA &&
183 // entry.sinf.format.format == FOURCC_MP4A)); 185 // entry.sinf.format.format == FOURCC_MP4A));
184 186
185 const ChannelLayout layout = 187 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3.
186 AVC::ConvertAACChannelCountToChannelLayout(entry.channelcount); 188 RCHECK(entry.esds.object_type == kISO_14496_3);
187 audio_config.Initialize(kCodecAAC, entry.samplesize, layout, 189 audio_config.Initialize(kCodecAAC, entry.samplesize,
188 entry.samplerate, NULL, 0, false); 190 aac.channel_layout(), aac.frequency(),
191 NULL, 0, false);
192
189 has_audio_ = true; 193 has_audio_ = true;
190 audio_track_id_ = track->header.track_id; 194 audio_track_id_ = track->header.track_id;
191 } 195 }
192 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { 196 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) {
193 RCHECK(!samp_descr.video_entries.empty()); 197 RCHECK(!samp_descr.video_entries.empty());
194 if (static_cast<uint32>(desc_idx) >= samp_descr.video_entries.size()) 198 if (static_cast<uint32>(desc_idx) >= samp_descr.video_entries.size())
195 desc_idx = 0; 199 desc_idx = 0;
196 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; 200 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx];
197 201
198 // RCHECK(entry.format == FOURCC_AVC1 || 202 // RCHECK(entry.format == FOURCC_AVC1 ||
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 288
285 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size()); 289 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size());
286 if (video) { 290 if (video) {
287 const AVCDecoderConfigurationRecord& avc_config = 291 const AVCDecoderConfigurationRecord& avc_config =
288 runs_->video_description().avcc; 292 runs_->video_description().avcc;
289 RCHECK(AVC::ConvertToAnnexB(avc_config.length_size, &frame_buf)); 293 RCHECK(AVC::ConvertToAnnexB(avc_config.length_size, &frame_buf));
290 if (runs_->is_keyframe()) 294 if (runs_->is_keyframe())
291 RCHECK(AVC::InsertParameterSets(avc_config, &frame_buf)); 295 RCHECK(AVC::InsertParameterSets(avc_config, &frame_buf));
292 } 296 }
293 297
298 if (audio) {
299 const AAC& aac = runs_->audio_description().esds.aac;
300 RCHECK(aac.ConvertEsdsToADTS(&frame_buf));
301 }
302
294 scoped_refptr<StreamParserBuffer> stream_buf = 303 scoped_refptr<StreamParserBuffer> stream_buf =
295 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(), 304 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(),
296 runs_->is_keyframe()); 305 runs_->is_keyframe());
297 306
298 stream_buf->SetDuration(runs_->duration()); 307 stream_buf->SetDuration(runs_->duration());
299 stream_buf->SetTimestamp(runs_->cts()); 308 stream_buf->SetTimestamp(runs_->cts());
300 stream_buf->SetDecodeTimestamp(runs_->dts()); 309 stream_buf->SetDecodeTimestamp(runs_->dts());
301 310
302 DVLOG(3) << "Pushing frame: aud=" << audio 311 DVLOG(3) << "Pushing frame: aud=" << audio
303 << ", key=" << runs_->is_keyframe() 312 << ", key=" << runs_->is_keyframe()
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return true; 365 return true;
357 } 366 }
358 367
359 void MP4StreamParser::ChangeState(State new_state) { 368 void MP4StreamParser::ChangeState(State new_state) {
360 DVLOG(2) << "Changing state: " << new_state; 369 DVLOG(2) << "Changing state: " << new_state;
361 state_ = new_state; 370 state_ = new_state;
362 } 371 }
363 372
364 } // namespace mp4 373 } // namespace mp4
365 } // namespace media 374 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/es_descriptor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698