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/base/video_util.h" | 14 #include "media/base/video_util.h" |
15 #include "media/mp4/box_definitions.h" | 15 #include "media/mp4/box_definitions.h" |
16 #include "media/mp4/box_reader.h" | 16 #include "media/mp4/box_reader.h" |
17 #include "media/mp4/es_descriptor.h" | 17 #include "media/mp4/es_descriptor.h" |
18 #include "media/mp4/rcheck.h" | 18 #include "media/mp4/rcheck.h" |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 namespace mp4 { | 21 namespace mp4 { |
22 | 22 |
23 // TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. | 23 // TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. |
24 static const char kMp4InitDataType[] = "video/mp4"; | 24 static const char kMp4InitDataType[] = "video/mp4"; |
25 | 25 |
26 MP4StreamParser::MP4StreamParser(bool has_sbr) | 26 MP4StreamParser::MP4StreamParser(const std::set<int>& audio_object_types, |
| 27 bool has_sbr) |
27 : state_(kWaitingForInit), | 28 : state_(kWaitingForInit), |
28 moof_head_(0), | 29 moof_head_(0), |
29 mdat_tail_(0), | 30 mdat_tail_(0), |
30 has_audio_(false), | 31 has_audio_(false), |
31 has_video_(false), | 32 has_video_(false), |
32 audio_track_id_(0), | 33 audio_track_id_(0), |
33 video_track_id_(0), | 34 video_track_id_(0), |
| 35 audio_object_types_(audio_object_types), |
34 has_sbr_(has_sbr), | 36 has_sbr_(has_sbr), |
35 is_audio_track_encrypted_(false), | 37 is_audio_track_encrypted_(false), |
36 is_video_track_encrypted_(false) { | 38 is_video_track_encrypted_(false) { |
37 } | 39 } |
38 | 40 |
39 MP4StreamParser::~MP4StreamParser() {} | 41 MP4StreamParser::~MP4StreamParser() {} |
40 | 42 |
41 void MP4StreamParser::Init(const InitCB& init_cb, | 43 void MP4StreamParser::Init(const InitCB& init_cb, |
42 const NewConfigCB& config_cb, | 44 const NewConfigCB& config_cb, |
43 const NewBuffersCB& audio_cb, | 45 const NewBuffersCB& audio_cb, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; | 197 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; |
196 const AAC& aac = entry.esds.aac; | 198 const AAC& aac = entry.esds.aac; |
197 | 199 |
198 if (!(entry.format == FOURCC_MP4A || | 200 if (!(entry.format == FOURCC_MP4A || |
199 (entry.format == FOURCC_ENCA && | 201 (entry.format == FOURCC_ENCA && |
200 entry.sinf.format.format == FOURCC_MP4A))) { | 202 entry.sinf.format.format == FOURCC_MP4A))) { |
201 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" | 203 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" |
202 << std::hex << entry.format << " in stsd box."; | 204 << std::hex << entry.format << " in stsd box."; |
203 return false; | 205 return false; |
204 } | 206 } |
205 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3. | 207 |
206 if (entry.esds.object_type != kISO_14496_3) { | 208 int audio_type = entry.esds.object_type; |
207 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex | 209 DVLOG(1) << "audio_type " << std::hex << audio_type; |
208 << static_cast<int>(entry.esds.object_type) | 210 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { |
209 << " in esds."; | 211 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type |
| 212 << " does not match what is specified in the" |
| 213 << " mimetype."; |
210 return false; | 214 return false; |
211 } | 215 } |
212 | 216 |
| 217 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or |
| 218 // supported MPEG2 AAC varients. |
| 219 if (audio_type != kISO_14496_3 && audio_type != kISO_13818_7_AAC_LC) { |
| 220 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex |
| 221 << audio_type << " in esds."; |
| 222 return false; |
| 223 } |
| 224 |
213 SampleFormat sample_format; | 225 SampleFormat sample_format; |
214 if (entry.samplesize == 8) { | 226 if (entry.samplesize == 8) { |
215 sample_format = kSampleFormatU8; | 227 sample_format = kSampleFormatU8; |
216 } else if (entry.samplesize == 16) { | 228 } else if (entry.samplesize == 16) { |
217 sample_format = kSampleFormatS16; | 229 sample_format = kSampleFormatS16; |
218 } else if (entry.samplesize == 32) { | 230 } else if (entry.samplesize == 32) { |
219 sample_format = kSampleFormatS32; | 231 sample_format = kSampleFormatS32; |
220 } else { | 232 } else { |
221 LOG(ERROR) << "Unsupported sample size."; | 233 LOG(ERROR) << "Unsupported sample size."; |
222 return false; | 234 return false; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return !err; | 545 return !err; |
534 } | 546 } |
535 | 547 |
536 void MP4StreamParser::ChangeState(State new_state) { | 548 void MP4StreamParser::ChangeState(State new_state) { |
537 DVLOG(2) << "Changing state: " << new_state; | 549 DVLOG(2) << "Changing state: " << new_state; |
538 state_ = new_state; | 550 state_ = new_state; |
539 } | 551 } |
540 | 552 |
541 } // namespace mp4 | 553 } // namespace mp4 |
542 } // namespace media | 554 } // namespace media |
OLD | NEW |