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. |
| 24 static const char kMp4InitDataType[] = "video/mp4"; |
| 25 |
23 MP4StreamParser::MP4StreamParser(bool has_sbr) | 26 MP4StreamParser::MP4StreamParser(bool has_sbr) |
24 : state_(kWaitingForInit), | 27 : state_(kWaitingForInit), |
25 moof_head_(0), | 28 moof_head_(0), |
26 mdat_tail_(0), | 29 mdat_tail_(0), |
27 has_audio_(false), | 30 has_audio_(false), |
28 has_video_(false), | 31 has_video_(false), |
29 audio_track_id_(0), | 32 audio_track_id_(0), |
30 video_track_id_(0), | 33 video_track_id_(0), |
31 has_sbr_(has_sbr) { | 34 has_sbr_(has_sbr) { |
32 } | 35 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 for (size_t i = 0; i < headers.size(); i++) | 283 for (size_t i = 0; i < headers.size(); i++) |
281 total_size += headers[i].raw_box.size(); | 284 total_size += headers[i].raw_box.size(); |
282 | 285 |
283 scoped_array<uint8> init_data(new uint8[total_size]); | 286 scoped_array<uint8> init_data(new uint8[total_size]); |
284 size_t pos = 0; | 287 size_t pos = 0; |
285 for (size_t i = 0; i < headers.size(); i++) { | 288 for (size_t i = 0; i < headers.size(); i++) { |
286 memcpy(&init_data.get()[pos], &headers[i].raw_box[0], | 289 memcpy(&init_data.get()[pos], &headers[i].raw_box[0], |
287 headers[i].raw_box.size()); | 290 headers[i].raw_box.size()); |
288 pos += headers[i].raw_box.size(); | 291 pos += headers[i].raw_box.size(); |
289 } | 292 } |
290 return need_key_cb_.Run(init_data.Pass(), total_size); | 293 return need_key_cb_.Run(kMp4InitDataType, init_data.Pass(), total_size); |
291 } | 294 } |
292 | 295 |
293 bool MP4StreamParser::PrepareAVCBuffer( | 296 bool MP4StreamParser::PrepareAVCBuffer( |
294 const AVCDecoderConfigurationRecord& avc_config, | 297 const AVCDecoderConfigurationRecord& avc_config, |
295 std::vector<uint8>* frame_buf, | 298 std::vector<uint8>* frame_buf, |
296 std::vector<SubsampleEntry>* subsamples) const { | 299 std::vector<SubsampleEntry>* subsamples) const { |
297 // Convert the AVC NALU length fields to Annex B headers, as expected by | 300 // Convert the AVC NALU length fields to Annex B headers, as expected by |
298 // decoding libraries. Since this may enlarge the size of the buffer, we also | 301 // decoding libraries. Since this may enlarge the size of the buffer, we also |
299 // update the clear byte count for each subsample if encryption is used to | 302 // update the clear byte count for each subsample if encryption is used to |
300 // account for the difference in size between the length prefix and Annex B | 303 // account for the difference in size between the length prefix and Annex B |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 return !err; | 499 return !err; |
497 } | 500 } |
498 | 501 |
499 void MP4StreamParser::ChangeState(State new_state) { | 502 void MP4StreamParser::ChangeState(State new_state) { |
500 DVLOG(2) << "Changing state: " << new_state; | 503 DVLOG(2) << "Changing state: " << new_state; |
501 state_ = new_state; | 504 state_ = new_state; |
502 } | 505 } |
503 | 506 |
504 } // namespace mp4 | 507 } // namespace mp4 |
505 } // namespace media | 508 } // namespace media |
OLD | NEW |