| 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/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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { | 156 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { |
| 156 RCHECK(!samp_descr.audio_entries.empty()); | 157 RCHECK(!samp_descr.audio_entries.empty()); |
| 157 const AudioSampleEntry& entry = samp_descr.audio_entries[0]; | 158 const AudioSampleEntry& entry = samp_descr.audio_entries[0]; |
| 158 | 159 |
| 159 // TODO(strobe): We accept all format values, pending clarification on | 160 // TODO(strobe): We accept all format values, pending clarification on |
| 160 // the formats used for encrypted media (http://crbug.com/132351). | 161 // the formats used for encrypted media (http://crbug.com/132351). |
| 161 // RCHECK(entry.format == FOURCC_MP4A || | 162 // RCHECK(entry.format == FOURCC_MP4A || |
| 162 // (entry.format == FOURCC_ENCA && | 163 // (entry.format == FOURCC_ENCA && |
| 163 // entry.sinf.format.format == FOURCC_MP4A)); | 164 // entry.sinf.format.format == FOURCC_MP4A)); |
| 164 | 165 |
| 165 const ChannelLayout layout = | 166 RCHECK(entry.esds.object_type == kISO_14496_3); |
| 166 AVC::ConvertAACChannelCountToChannelLayout(entry.channelcount); | 167 aac_ = entry.esds.aac; |
| 167 audio_config.Initialize(kCodecAAC, entry.samplesize, layout, | 168 audio_config.Initialize(kCodecAAC, entry.samplesize, |
| 168 entry.samplerate, NULL, 0, false); | 169 aac_.channel_layout(), aac_.frequency(), |
| 170 NULL, 0, false); |
| 171 |
| 169 has_audio_ = true; | 172 has_audio_ = true; |
| 170 audio_track_id_ = track->header.track_id; | 173 audio_track_id_ = track->header.track_id; |
| 171 } | 174 } |
| 172 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { | 175 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { |
| 173 RCHECK(!samp_descr.video_entries.empty()); | 176 RCHECK(!samp_descr.video_entries.empty()); |
| 174 const VideoSampleEntry& entry = samp_descr.video_entries[0]; | 177 const VideoSampleEntry& entry = samp_descr.video_entries[0]; |
| 175 | 178 |
| 176 // RCHECK(entry.format == FOURCC_AVC1 || | 179 // RCHECK(entry.format == FOURCC_AVC1 || |
| 177 // (entry.format == FOURCC_ENCV && | 180 // (entry.format == FOURCC_ENCV && |
| 178 // entry.sinf.format.format == FOURCC_AVC1)); | 181 // entry.sinf.format.format == FOURCC_AVC1)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 avc_config = &moov_->tracks[t].media.information. | 287 avc_config = &moov_->tracks[t].media.information. |
| 285 sample_table.description.video_entries[0].avcc; | 288 sample_table.description.video_entries[0].avcc; |
| 286 break; | 289 break; |
| 287 } | 290 } |
| 288 } | 291 } |
| 289 RCHECK(avc_config != NULL); | 292 RCHECK(avc_config != NULL); |
| 290 RCHECK(AVC::InsertParameterSets(*avc_config, &frame_buf)); | 293 RCHECK(AVC::InsertParameterSets(*avc_config, &frame_buf)); |
| 291 } | 294 } |
| 292 } | 295 } |
| 293 | 296 |
| 297 if (audio) { |
| 298 aac_.ConvertEsdsToADTS(&frame_buf); |
| 299 } |
| 300 |
| 294 scoped_refptr<StreamParserBuffer> stream_buf = | 301 scoped_refptr<StreamParserBuffer> stream_buf = |
| 295 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(), | 302 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(), |
| 296 runs_.is_keyframe()); | 303 runs_.is_keyframe()); |
| 297 | 304 |
| 298 stream_buf->SetDuration(runs_.duration()); | 305 stream_buf->SetDuration(runs_.duration()); |
| 299 stream_buf->SetTimestamp(runs_.cts()); | 306 stream_buf->SetTimestamp(runs_.cts()); |
| 300 stream_buf->SetDecodeTimestamp(runs_.dts()); | 307 stream_buf->SetDecodeTimestamp(runs_.dts()); |
| 301 | 308 |
| 302 DVLOG(3) << "Pushing frame: aud=" << audio | 309 DVLOG(3) << "Pushing frame: aud=" << audio |
| 303 << ", key=" << runs_.is_keyframe() | 310 << ", key=" << runs_.is_keyframe() |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return true; | 363 return true; |
| 357 } | 364 } |
| 358 | 365 |
| 359 void MP4StreamParser::ChangeState(State new_state) { | 366 void MP4StreamParser::ChangeState(State new_state) { |
| 360 DVLOG(2) << "Changing state: " << new_state; | 367 DVLOG(2) << "Changing state: " << new_state; |
| 361 state_ = new_state; | 368 state_ = new_state; |
| 362 } | 369 } |
| 363 | 370 |
| 364 } // namespace mp4 | 371 } // namespace mp4 |
| 365 } // namespace media | 372 } // namespace media |
| OLD | NEW |