OLD | NEW |
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/mp4/mp4_stream_parser.h" | 5 #include "media/formats/mp4/mp4_stream_parser.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 std::vector<uint8> init_data(total_size); | 380 std::vector<uint8> init_data(total_size); |
381 size_t pos = 0; | 381 size_t pos = 0; |
382 for (size_t i = 0; i < headers.size(); i++) { | 382 for (size_t i = 0; i < headers.size(); i++) { |
383 memcpy(&init_data[pos], &headers[i].raw_box[0], | 383 memcpy(&init_data[pos], &headers[i].raw_box[0], |
384 headers[i].raw_box.size()); | 384 headers[i].raw_box.size()); |
385 pos += headers[i].raw_box.size(); | 385 pos += headers[i].raw_box.size(); |
386 } | 386 } |
387 encrypted_media_init_data_cb_.Run(EmeInitDataType::CENC, init_data); | 387 encrypted_media_init_data_cb_.Run(EmeInitDataType::CENC, init_data); |
388 } | 388 } |
389 | 389 |
390 bool MP4StreamParser::PrepareAVCBuffer( | |
391 const AVCDecoderConfigurationRecord& avc_config, | |
392 std::vector<uint8>* frame_buf, | |
393 std::vector<SubsampleEntry>* subsamples) const { | |
394 // Convert the AVC NALU length fields to Annex B headers, as expected by | |
395 // decoding libraries. Since this may enlarge the size of the buffer, we also | |
396 // update the clear byte count for each subsample if encryption is used to | |
397 // account for the difference in size between the length prefix and Annex B | |
398 // start code. | |
399 RCHECK(AVC::ConvertFrameToAnnexB(avc_config.length_size, frame_buf, | |
400 subsamples)); | |
401 | |
402 if (runs_->is_keyframe()) { | |
403 // If this is a keyframe, we (re-)inject SPS and PPS headers at the start of | |
404 // a frame. If subsample info is present, we also update the clear byte | |
405 // count for that first subsample. | |
406 RCHECK(AVC::InsertParamSetsAnnexB(avc_config, frame_buf, subsamples)); | |
407 } | |
408 | |
409 DCHECK(AVC::IsValidAnnexB(*frame_buf, *subsamples)); | |
410 return true; | |
411 } | |
412 | |
413 bool MP4StreamParser::PrepareAACBuffer( | 390 bool MP4StreamParser::PrepareAACBuffer( |
414 const AAC& aac_config, std::vector<uint8>* frame_buf, | 391 const AAC& aac_config, std::vector<uint8>* frame_buf, |
415 std::vector<SubsampleEntry>* subsamples) const { | 392 std::vector<SubsampleEntry>* subsamples) const { |
416 // Append an ADTS header to every audio sample. | 393 // Append an ADTS header to every audio sample. |
417 RCHECK(aac_config.ConvertEsdsToADTS(frame_buf)); | 394 RCHECK(aac_config.ConvertEsdsToADTS(frame_buf)); |
418 | 395 |
419 // As above, adjust subsample information to account for the headers. AAC is | 396 // As above, adjust subsample information to account for the headers. AAC is |
420 // not required to use subsample encryption, so we may need to add an entry. | 397 // not required to use subsample encryption, so we may need to add an entry. |
421 if (subsamples->empty()) { | 398 if (subsamples->empty()) { |
422 subsamples->push_back(SubsampleEntry( | 399 subsamples->push_back(SubsampleEntry( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 decrypt_config = runs_->GetDecryptConfig(); | 470 decrypt_config = runs_->GetDecryptConfig(); |
494 if (!decrypt_config) { | 471 if (!decrypt_config) { |
495 *err = true; | 472 *err = true; |
496 return false; | 473 return false; |
497 } | 474 } |
498 subsamples = decrypt_config->subsamples(); | 475 subsamples = decrypt_config->subsamples(); |
499 } | 476 } |
500 | 477 |
501 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size()); | 478 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size()); |
502 if (video) { | 479 if (video) { |
503 if (!PrepareAVCBuffer(runs_->video_description().avcc, | 480 DCHECK(runs_->video_description().frame_bitstream_converter); |
504 &frame_buf, &subsamples)) { | 481 if (!runs_->video_description().frame_bitstream_converter->ConvertFrame( |
| 482 &frame_buf, runs_->is_keyframe(), &subsamples)) { |
505 MEDIA_LOG(ERROR, media_log_) << "Failed to prepare AVC sample for decode"; | 483 MEDIA_LOG(ERROR, media_log_) << "Failed to prepare AVC sample for decode"; |
506 *err = true; | 484 *err = true; |
507 return false; | 485 return false; |
508 } | 486 } |
509 } | 487 } |
510 | 488 |
511 if (audio) { | 489 if (audio) { |
512 if (ESDescriptor::IsAAC(runs_->audio_description().esds.object_type) && | 490 if (ESDescriptor::IsAAC(runs_->audio_description().esds.object_type) && |
513 !PrepareAACBuffer(runs_->audio_description().esds.aac, | 491 !PrepareAACBuffer(runs_->audio_description().esds.aac, |
514 &frame_buf, &subsamples)) { | 492 &frame_buf, &subsamples)) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 runs.AdvanceSample(); | 626 runs.AdvanceSample(); |
649 } | 627 } |
650 runs.AdvanceRun(); | 628 runs.AdvanceRun(); |
651 } | 629 } |
652 | 630 |
653 return true; | 631 return true; |
654 } | 632 } |
655 | 633 |
656 } // namespace mp4 | 634 } // namespace mp4 |
657 } // namespace media | 635 } // namespace media |
OLD | NEW |