| Index: media/formats/mp2t/es_parser_adts.cc
|
| diff --git a/media/formats/mp2t/es_parser_adts.cc b/media/formats/mp2t/es_parser_adts.cc
|
| index 78579db72756c12a402cd3e3a38a2d994b7eeca6..931a3fee50fea8e811116f3b6693f2bd9cd0d056 100644
|
| --- a/media/formats/mp2t/es_parser_adts.cc
|
| +++ b/media/formats/mp2t/es_parser_adts.cc
|
| @@ -12,6 +12,7 @@
|
| #include "media/base/audio_timestamp_helper.h"
|
| #include "media/base/bit_reader.h"
|
| #include "media/base/channel_layout.h"
|
| +#include "media/base/decrypt_config.h"
|
| #include "media/base/encryption_scheme.h"
|
| #include "media/base/stream_parser_buffer.h"
|
| #include "media/base/timestamp_constants.h"
|
| @@ -27,6 +28,11 @@ static int ExtractAdtsFrameSize(const uint8* adts_header) {
|
| ((static_cast<int>(adts_header[3]) & 0x3) << 11));
|
| }
|
|
|
| +static int AdtsHeaderSize(const uint8* adts_header) {
|
| + // protection absent bit: set to 1 if there is no CRC and 0 if there is CRC
|
| + return (adts_header[1] & 0x1) ? kADTSHeaderSizeNoCrc : kADTSHeaderSizeWithCrc;
|
| +}
|
| +
|
| static size_t ExtractAdtsFrequencyIndex(const uint8* adts_header) {
|
| return ((adts_header[2] >> 2) & 0xf);
|
| }
|
| @@ -52,6 +58,7 @@ struct EsParserAdts::AdtsFrame {
|
|
|
| // Frame size;
|
| int size;
|
| + int header_size;
|
|
|
| // Frame offset in the ES queue.
|
| int64 queue_offset;
|
| @@ -76,6 +83,7 @@ bool EsParserAdts::LookForAdtsFrame(AdtsFrame* adts_frame) {
|
| // Too short to be an ADTS frame.
|
| continue;
|
| }
|
| + int header_size = AdtsHeaderSize(cur_buf);
|
|
|
| int remaining_size = es_size - offset;
|
| if (remaining_size < frame_size) {
|
| @@ -95,6 +103,7 @@ bool EsParserAdts::LookForAdtsFrame(AdtsFrame* adts_frame) {
|
| es_queue_->Peek(&adts_frame->data, &es_size);
|
| adts_frame->queue_offset = es_queue_->head();
|
| adts_frame->size = frame_size;
|
| + adts_frame->header_size = header_size;
|
| DVLOG(LOG_LEVEL_ES)
|
| << "ADTS syncword @ pos=" << adts_frame->queue_offset
|
| << " frame_size=" << adts_frame->size;
|
| @@ -113,18 +122,61 @@ void EsParserAdts::SkipAdtsFrame(const AdtsFrame& adts_frame) {
|
| es_queue_->Pop(adts_frame.size);
|
| }
|
|
|
| -EsParserAdts::EsParserAdts(
|
| - const NewAudioConfigCB& new_audio_config_cb,
|
| - const EmitBufferCB& emit_buffer_cb,
|
| - bool sbr_in_mimetype)
|
| - : new_audio_config_cb_(new_audio_config_cb),
|
| - emit_buffer_cb_(emit_buffer_cb),
|
| - sbr_in_mimetype_(sbr_in_mimetype) {
|
| +EsParserAdts::EsParserAdts(const NewAudioConfigCB& new_audio_config_cb,
|
| + const EmitBufferCB& emit_buffer_cb,
|
| + bool sbr_in_mimetype)
|
| + : new_audio_config_cb_(new_audio_config_cb),
|
| + emit_buffer_cb_(emit_buffer_cb),
|
| +#ifdef ENABLE_HLS_SAMPLE_AES
|
| + get_decrypt_config_cb_(GetDecryptConfigCB()),
|
| + use_hls_sample_aes_(false),
|
| +#endif
|
| + sbr_in_mimetype_(sbr_in_mimetype) {
|
| }
|
|
|
| +#ifdef ENABLE_HLS_SAMPLE_AES
|
| +EsParserAdts::EsParserAdts(const NewAudioConfigCB& new_audio_config_cb,
|
| + const EmitBufferCB& emit_buffer_cb,
|
| + const GetDecryptConfigCB get_decrypt_config_cb,
|
| + bool use_hls_sample_aes,
|
| + bool sbr_in_mimetype)
|
| + : new_audio_config_cb_(new_audio_config_cb),
|
| + emit_buffer_cb_(emit_buffer_cb),
|
| + get_decrypt_config_cb_(get_decrypt_config_cb),
|
| + use_hls_sample_aes_(use_hls_sample_aes),
|
| + sbr_in_mimetype_(sbr_in_mimetype) {}
|
| +#endif
|
| +
|
| EsParserAdts::~EsParserAdts() {
|
| }
|
|
|
| +#ifdef ENABLE_HLS_SAMPLE_AES
|
| +void EsParserAdts::CalculateSubsamplesForAdtsFrame(
|
| + const AdtsFrame& adts_frame,
|
| + std::vector<SubsampleEntry>* subsamples) {
|
| + DCHECK(subsamples);
|
| + subsamples->clear();
|
| + int data_size = adts_frame.size - adts_frame.header_size;
|
| + int residue = data_size % 16;
|
| + int clear_bytes = adts_frame.header_size;
|
| + int encrypted_bytes = 0;
|
| + if (data_size <= 16) {
|
| + clear_bytes += data_size;
|
| + residue = 0;
|
| + } else {
|
| + clear_bytes += 16;
|
| + encrypted_bytes = adts_frame.size - clear_bytes - residue;
|
| + }
|
| + SubsampleEntry subsample(clear_bytes, encrypted_bytes);
|
| + subsamples->push_back(subsample);
|
| + if (residue) {
|
| + subsample.clear_bytes = residue;
|
| + subsample.cypher_bytes = 0;
|
| + subsamples->push_back(subsample);
|
| + }
|
| +}
|
| +#endif
|
| +
|
| bool EsParserAdts::ParseFromEsQueue() {
|
| // Look for every ADTS frame in the ES buffer.
|
| AdtsFrame adts_frame;
|
| @@ -164,6 +216,16 @@ bool EsParserAdts::ParseFromEsQueue() {
|
| stream_parser_buffer->SetDecodeTimestamp(
|
| DecodeTimestamp::FromPresentationTime(current_pts));
|
| stream_parser_buffer->set_duration(frame_duration);
|
| +#ifdef ENABLE_HLS_SAMPLE_AES
|
| + if (use_hls_sample_aes_) {
|
| + const DecryptConfig& base_decrypt_config = get_decrypt_config_cb_.Run();
|
| + std::vector<SubsampleEntry> subsamples;
|
| + CalculateSubsamplesForAdtsFrame(adts_frame, &subsamples);
|
| + scoped_ptr<DecryptConfig> decrypt_config(new DecryptConfig(
|
| + base_decrypt_config.key_id(), base_decrypt_config.iv(), subsamples));
|
| + stream_parser_buffer->set_decrypt_config(decrypt_config.Pass());
|
| + }
|
| +#endif
|
| emit_buffer_cb_.Run(stream_parser_buffer);
|
|
|
| // Update the PTS of the next frame.
|
| @@ -227,7 +289,11 @@ bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) {
|
| extra_data.push_back(static_cast<uint8>(extra_data_int & 0xff));
|
|
|
| EncryptionScheme scheme(false);
|
| -
|
| +#ifdef ENABLE_HLS_SAMPLE_AES
|
| + if (use_hls_sample_aes_) {
|
| + scheme = EncryptionScheme(kCipherModeAesCbc);
|
| + }
|
| +#endif
|
| AudioDecoderConfig audio_decoder_config(
|
| kCodecAAC, kSampleFormatS16,
|
| kADTSChannelLayoutTable[channel_configuration],
|
|
|