2014-07-14 21:35:57 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/formats/wvm/wvm_media_parser.h>
|
2014-10-01 19:35:23 +00:00
|
|
|
|
2014-07-14 21:35:57 +00:00
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-10-09 23:21:41 +00:00
|
|
|
#include <absl/base/internal/endian.h>
|
2023-08-31 23:59:46 +00:00
|
|
|
#include <absl/strings/str_format.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/aes_decryptor.h>
|
|
|
|
#include <packager/media/base/audio_stream_info.h>
|
|
|
|
#include <packager/media/base/key_source.h>
|
|
|
|
#include <packager/media/base/media_sample.h>
|
|
|
|
#include <packager/media/codecs/aac_audio_specific_config.h>
|
|
|
|
#include <packager/media/codecs/avc_decoder_configuration_record.h>
|
|
|
|
#include <packager/media/codecs/es_descriptor.h>
|
|
|
|
#include <packager/media/formats/mp2t/adts_header.h>
|
2014-07-14 21:35:57 +00:00
|
|
|
|
|
|
|
#define HAS_HEADER_EXTENSION(x) ((x != 0xBC) && (x != 0xBE) && (x != 0xBF) \
|
|
|
|
&& (x != 0xF0) && (x != 0xF2) && (x != 0xF8) \
|
|
|
|
&& (x != 0xFF))
|
|
|
|
|
|
|
|
namespace {
|
2015-10-08 18:20:53 +00:00
|
|
|
const uint32_t kMpeg2ClockRate = 90000;
|
|
|
|
const uint32_t kPesOptPts = 0x80;
|
|
|
|
const uint32_t kPesOptDts = 0x40;
|
|
|
|
const uint32_t kPesOptAlign = 0x04;
|
|
|
|
const uint32_t kPsmStreamId = 0xBC;
|
|
|
|
const uint32_t kPaddingStreamId = 0xBE;
|
|
|
|
const uint32_t kIndexMagic = 0x49444d69;
|
|
|
|
const uint32_t kIndexStreamId = 0xBF; // private_stream_2
|
|
|
|
const uint32_t kIndexVersion4HeaderSize = 12;
|
|
|
|
const uint32_t kEcmStreamId = 0xF0;
|
|
|
|
const uint32_t kV2MetadataStreamId = 0xF1; // EMM_stream
|
|
|
|
const uint32_t kScramblingBitsMask = 0x30;
|
|
|
|
const uint32_t kStartCode1 = 0x00;
|
|
|
|
const uint32_t kStartCode2 = 0x00;
|
|
|
|
const uint32_t kStartCode3 = 0x01;
|
|
|
|
const uint32_t kStartCode4Pack = 0xBA;
|
|
|
|
const uint32_t kStartCode4System = 0xBB;
|
|
|
|
const uint32_t kStartCode4ProgramEnd = 0xB9;
|
|
|
|
const uint32_t kPesStreamIdVideoMask = 0xF0;
|
|
|
|
const uint32_t kPesStreamIdVideo = 0xE0;
|
|
|
|
const uint32_t kPesStreamIdAudioMask = 0xE0;
|
|
|
|
const uint32_t kPesStreamIdAudio = 0xC0;
|
|
|
|
const uint32_t kVersion4 = 4;
|
|
|
|
const uint8_t kAacSampleSizeBits = 16;
|
|
|
|
// Applies to all video streams.
|
2015-10-16 20:10:42 +00:00
|
|
|
const uint8_t kNaluLengthSize = 4; // unit is bytes.
|
2015-10-08 18:20:53 +00:00
|
|
|
// Placeholder sampling frequency for all audio streams, which
|
|
|
|
// will be overwritten after filter parsing.
|
|
|
|
const uint32_t kDefaultSamplingFrequency = 100;
|
|
|
|
const uint16_t kEcmSizeBytes = 80;
|
|
|
|
const uint32_t kInitializationVectorSizeBytes = 16;
|
|
|
|
// ECM fields for processing.
|
|
|
|
const uint32_t kEcmContentKeySizeBytes = 16;
|
|
|
|
const uint32_t kEcmDCPFlagsSizeBytes = 3;
|
|
|
|
const uint32_t kEcmCCIFlagsSizeBytes = 1;
|
|
|
|
const uint32_t kEcmFlagsSizeBytes =
|
|
|
|
kEcmCCIFlagsSizeBytes + kEcmDCPFlagsSizeBytes;
|
|
|
|
const uint32_t kEcmPaddingSizeBytes = 12;
|
|
|
|
const uint32_t kAssetKeySizeBytes = 16;
|
|
|
|
// Default audio and video PES stream IDs.
|
|
|
|
const uint8_t kDefaultAudioStreamId = kPesStreamIdAudio;
|
|
|
|
const uint8_t kDefaultVideoStreamId = kPesStreamIdVideo;
|
2014-09-30 16:58:43 +00:00
|
|
|
|
2015-10-08 18:20:53 +00:00
|
|
|
enum Type {
|
|
|
|
Type_void = 0,
|
|
|
|
Type_uint8 = 1,
|
|
|
|
Type_int8 = 2,
|
|
|
|
Type_uint16 = 3,
|
|
|
|
Type_int16 = 4,
|
|
|
|
Type_uint32 = 5,
|
|
|
|
Type_int32 = 6,
|
|
|
|
Type_uint64 = 7,
|
|
|
|
Type_int64 = 8,
|
|
|
|
Type_string = 9,
|
|
|
|
Type_BinaryData = 10
|
|
|
|
};
|
2015-10-16 20:10:42 +00:00
|
|
|
} // namespace
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-07-14 21:35:57 +00:00
|
|
|
namespace media {
|
|
|
|
namespace wvm {
|
|
|
|
|
2014-11-25 21:42:16 +00:00
|
|
|
WvmMediaParser::WvmMediaParser()
|
|
|
|
: is_initialized_(false),
|
|
|
|
parse_state_(StartCode1),
|
|
|
|
skip_bytes_(0),
|
|
|
|
metadata_is_complete_(false),
|
|
|
|
current_program_id_(0),
|
|
|
|
pes_stream_id_(0),
|
|
|
|
prev_pes_stream_id_(0),
|
|
|
|
pes_packet_bytes_(0),
|
|
|
|
pes_flags_1_(0),
|
|
|
|
pes_flags_2_(0),
|
|
|
|
prev_pes_flags_1_(0),
|
|
|
|
pes_header_data_bytes_(0),
|
|
|
|
timestamp_(0),
|
|
|
|
pts_(0),
|
|
|
|
dts_(0),
|
|
|
|
index_program_id_(0),
|
|
|
|
media_sample_(NULL),
|
|
|
|
crypto_unit_start_pos_(0),
|
|
|
|
stream_id_count_(0),
|
2017-03-23 18:34:20 +00:00
|
|
|
decryption_key_source_(NULL) {}
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2014-09-16 19:55:49 +00:00
|
|
|
WvmMediaParser::~WvmMediaParser() {}
|
|
|
|
|
2014-07-14 21:35:57 +00:00
|
|
|
void WvmMediaParser::Init(const InitCB& init_cb,
|
2020-07-01 22:43:44 +00:00
|
|
|
const NewMediaSampleCB& new_media_sample_cb,
|
|
|
|
const NewTextSampleCB& new_text_sample_cb,
|
2014-07-14 21:35:57 +00:00
|
|
|
KeySource* decryption_key_source) {
|
|
|
|
DCHECK(!is_initialized_);
|
2023-08-31 23:59:46 +00:00
|
|
|
DCHECK(init_cb != nullptr);
|
|
|
|
DCHECK(new_media_sample_cb != nullptr);
|
2014-10-09 19:56:51 +00:00
|
|
|
decryption_key_source_ = decryption_key_source;
|
2014-07-14 21:35:57 +00:00
|
|
|
init_cb_ = init_cb;
|
2020-07-01 22:43:44 +00:00
|
|
|
new_sample_cb_ = new_media_sample_cb;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
bool WvmMediaParser::Parse(const uint8_t* buf, int size) {
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t num_bytes = 0;
|
|
|
|
size_t prev_size = 0;
|
2015-10-16 20:10:42 +00:00
|
|
|
const uint8_t* read_ptr = buf;
|
|
|
|
const uint8_t* end = read_ptr + size;
|
2014-07-14 21:35:57 +00:00
|
|
|
|
|
|
|
while (read_ptr < end) {
|
2015-10-16 20:10:42 +00:00
|
|
|
switch (parse_state_) {
|
2014-07-14 21:35:57 +00:00
|
|
|
case StartCode1:
|
|
|
|
if (*read_ptr == kStartCode1) {
|
|
|
|
parse_state_ = StartCode2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StartCode2:
|
|
|
|
if (*read_ptr == kStartCode2) {
|
|
|
|
parse_state_ = StartCode3;
|
|
|
|
} else {
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StartCode3:
|
|
|
|
if (*read_ptr == kStartCode3) {
|
|
|
|
parse_state_ = StartCode4;
|
|
|
|
} else {
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StartCode4:
|
|
|
|
switch (*read_ptr) {
|
|
|
|
case kStartCode4Pack:
|
|
|
|
parse_state_ = PackHeader1;
|
|
|
|
break;
|
|
|
|
case kStartCode4System:
|
|
|
|
parse_state_ = SystemHeader1;
|
|
|
|
break;
|
|
|
|
case kStartCode4ProgramEnd:
|
|
|
|
parse_state_ = ProgramEnd;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
parse_state_ = PesStreamId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PackHeader1:
|
|
|
|
parse_state_ = PackHeader2;
|
|
|
|
break;
|
|
|
|
case PackHeader2:
|
|
|
|
parse_state_ = PackHeader3;
|
|
|
|
break;
|
|
|
|
case PackHeader3:
|
|
|
|
parse_state_ = PackHeader4;
|
|
|
|
break;
|
|
|
|
case PackHeader4:
|
|
|
|
parse_state_ = PackHeader5;
|
|
|
|
break;
|
|
|
|
case PackHeader5:
|
|
|
|
parse_state_ = PackHeader6;
|
|
|
|
break;
|
|
|
|
case PackHeader6:
|
|
|
|
parse_state_ = PackHeader7;
|
|
|
|
break;
|
|
|
|
case PackHeader7:
|
|
|
|
parse_state_ = PackHeader8;
|
|
|
|
break;
|
|
|
|
case PackHeader8:
|
|
|
|
parse_state_ = PackHeader9;
|
|
|
|
break;
|
|
|
|
case PackHeader9:
|
|
|
|
parse_state_ = PackHeader10;
|
|
|
|
break;
|
|
|
|
case PackHeader10:
|
|
|
|
skip_bytes_ = *read_ptr & 0x07;
|
|
|
|
parse_state_ = PackHeaderStuffingSkip;
|
|
|
|
break;
|
|
|
|
case SystemHeader1:
|
|
|
|
skip_bytes_ = *read_ptr;
|
|
|
|
skip_bytes_ <<= 8;
|
|
|
|
parse_state_ = SystemHeader2;
|
|
|
|
break;
|
|
|
|
case SystemHeader2:
|
|
|
|
skip_bytes_ |= *read_ptr;
|
|
|
|
parse_state_ = SystemHeaderSkip;
|
|
|
|
break;
|
|
|
|
case PackHeaderStuffingSkip:
|
2017-01-06 22:57:48 +00:00
|
|
|
if (end >= skip_bytes_ + read_ptr) {
|
2014-07-14 21:35:57 +00:00
|
|
|
read_ptr += skip_bytes_;
|
|
|
|
skip_bytes_ = 0;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
} else {
|
|
|
|
skip_bytes_ -= (end - read_ptr);
|
|
|
|
read_ptr = end;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case SystemHeaderSkip:
|
2017-01-06 22:57:48 +00:00
|
|
|
if (end >= skip_bytes_ + read_ptr) {
|
2014-07-14 21:35:57 +00:00
|
|
|
read_ptr += skip_bytes_;
|
|
|
|
skip_bytes_ = 0;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
} else {
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t remaining_size = end - read_ptr;
|
2014-07-14 21:35:57 +00:00
|
|
|
skip_bytes_ -= remaining_size;
|
|
|
|
read_ptr = end;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case PesStreamId:
|
|
|
|
pes_stream_id_ = *read_ptr;
|
|
|
|
if (!metadata_is_complete_ &&
|
|
|
|
(pes_stream_id_ != kPsmStreamId) &&
|
|
|
|
(pes_stream_id_ != kIndexStreamId) &&
|
|
|
|
(pes_stream_id_ != kEcmStreamId) &&
|
|
|
|
(pes_stream_id_ != kV2MetadataStreamId) &&
|
|
|
|
(pes_stream_id_ != kPaddingStreamId)) {
|
|
|
|
metadata_is_complete_ = true;
|
|
|
|
}
|
|
|
|
parse_state_ = PesPacketLength1;
|
|
|
|
break;
|
|
|
|
case PesPacketLength1:
|
|
|
|
pes_packet_bytes_ = *read_ptr;
|
|
|
|
pes_packet_bytes_ <<= 8;
|
|
|
|
parse_state_ = PesPacketLength2;
|
|
|
|
break;
|
|
|
|
case PesPacketLength2:
|
|
|
|
pes_packet_bytes_ |= *read_ptr;
|
|
|
|
if (HAS_HEADER_EXTENSION(pes_stream_id_)) {
|
|
|
|
parse_state_ = PesExtension1;
|
|
|
|
} else {
|
2017-03-23 18:34:20 +00:00
|
|
|
prev_pes_flags_1_ = pes_flags_1_;
|
2014-07-14 21:35:57 +00:00
|
|
|
pes_flags_1_ = pes_flags_2_ = 0;
|
|
|
|
pes_header_data_bytes_ = 0;
|
|
|
|
parse_state_ = PesPayload;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PesExtension1:
|
2014-09-30 16:58:43 +00:00
|
|
|
prev_pes_flags_1_ = pes_flags_1_;
|
2014-07-14 21:35:57 +00:00
|
|
|
pes_flags_1_ = *read_ptr;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = PesExtension2;
|
|
|
|
break;
|
|
|
|
case PesExtension2:
|
|
|
|
pes_flags_2_ = *read_ptr;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = PesExtension3;
|
|
|
|
break;
|
|
|
|
case PesExtension3:
|
|
|
|
pes_header_data_bytes_ = *read_ptr;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
if (pes_flags_2_ & kPesOptPts) {
|
|
|
|
parse_state_ = Pts1;
|
|
|
|
} else {
|
|
|
|
parse_state_ = PesHeaderData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pts1:
|
|
|
|
timestamp_ = (*read_ptr & 0x0E);
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Pts2;
|
|
|
|
break;
|
|
|
|
case Pts2:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Pts3;
|
|
|
|
break;
|
|
|
|
case Pts3:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr >> 1;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Pts4;
|
|
|
|
break;
|
|
|
|
case Pts4:
|
|
|
|
timestamp_ <<= 8;
|
|
|
|
timestamp_ |= *read_ptr;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Pts5;
|
|
|
|
break;
|
|
|
|
case Pts5:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr >> 1;
|
|
|
|
pts_ = timestamp_;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
if (pes_flags_2_ & kPesOptDts) {
|
|
|
|
parse_state_ = Dts1;
|
|
|
|
} else {
|
|
|
|
dts_ = pts_;
|
|
|
|
parse_state_ = PesHeaderData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Dts1:
|
|
|
|
timestamp_ = (*read_ptr & 0x0E);
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Dts2;
|
|
|
|
break;
|
|
|
|
case Dts2:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Dts3;
|
|
|
|
break;
|
|
|
|
case Dts3:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr >> 1;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Dts4;
|
|
|
|
break;
|
|
|
|
case Dts4:
|
|
|
|
timestamp_ <<= 8;
|
|
|
|
timestamp_ |= *read_ptr;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = Dts5;
|
|
|
|
break;
|
|
|
|
case Dts5:
|
|
|
|
timestamp_ <<= 7;
|
|
|
|
timestamp_ |= *read_ptr >> 1;
|
|
|
|
dts_ = timestamp_;
|
|
|
|
--pes_header_data_bytes_;
|
|
|
|
--pes_packet_bytes_;
|
|
|
|
parse_state_ = PesHeaderData;
|
|
|
|
break;
|
|
|
|
case PesHeaderData:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_header_data_bytes_) {
|
|
|
|
num_bytes = pes_header_data_bytes_;
|
|
|
|
parse_state_ = PesPayload;
|
|
|
|
}
|
|
|
|
pes_header_data_bytes_ -= num_bytes;
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case PesPayload:
|
|
|
|
switch (pes_stream_id_) {
|
|
|
|
case kPsmStreamId:
|
|
|
|
psm_data_.clear();
|
|
|
|
parse_state_ = PsmPayload;
|
|
|
|
continue;
|
|
|
|
case kPaddingStreamId:
|
|
|
|
parse_state_ = Padding;
|
|
|
|
continue;
|
|
|
|
case kEcmStreamId:
|
|
|
|
ecm_.clear();
|
|
|
|
parse_state_ = EcmPayload;
|
|
|
|
continue;
|
|
|
|
case kIndexStreamId:
|
|
|
|
parse_state_ = IndexPayload;
|
|
|
|
continue;
|
|
|
|
default:
|
2015-01-12 21:17:10 +00:00
|
|
|
if (!DemuxNextPes(false)) {
|
2014-07-14 21:35:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
parse_state_ = EsPayload;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case PsmPayload:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_packet_bytes_) {
|
|
|
|
num_bytes = pes_packet_bytes_;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
if (num_bytes > 0) {
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
prev_size = psm_data_.size();
|
|
|
|
psm_data_.resize(prev_size + num_bytes);
|
|
|
|
memcpy(&psm_data_[prev_size], read_ptr, num_bytes);
|
|
|
|
}
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case EcmPayload:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_packet_bytes_) {
|
|
|
|
num_bytes = pes_packet_bytes_;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
if (num_bytes > 0) {
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
prev_size = ecm_.size();
|
|
|
|
ecm_.resize(prev_size + num_bytes);
|
|
|
|
memcpy(&ecm_[prev_size], read_ptr, num_bytes);
|
|
|
|
}
|
|
|
|
if ((pes_packet_bytes_ == 0) && !ecm_.empty()) {
|
2014-09-30 16:58:43 +00:00
|
|
|
if (!ProcessEcm()) {
|
2014-07-14 21:35:57 +00:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case IndexPayload:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_packet_bytes_) {
|
|
|
|
num_bytes = pes_packet_bytes_;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
if (num_bytes > 0) {
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
prev_size = index_data_.size();
|
|
|
|
index_data_.resize(prev_size + num_bytes);
|
|
|
|
memcpy(&index_data_[prev_size], read_ptr, num_bytes);
|
|
|
|
}
|
|
|
|
if (pes_packet_bytes_ == 0 && !index_data_.empty()) {
|
|
|
|
if (!metadata_is_complete_) {
|
|
|
|
if (!ParseIndexEntry()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case EsPayload:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_packet_bytes_) {
|
|
|
|
num_bytes = pes_packet_bytes_;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
if (pes_stream_id_ != kV2MetadataStreamId) {
|
|
|
|
sample_data_.resize(sample_data_.size() + num_bytes);
|
|
|
|
memcpy(&sample_data_[sample_data_.size() - num_bytes], read_ptr,
|
|
|
|
num_bytes);
|
|
|
|
}
|
|
|
|
prev_pes_stream_id_ = pes_stream_id_;
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case Padding:
|
|
|
|
num_bytes = end - read_ptr;
|
|
|
|
if (num_bytes >= pes_packet_bytes_) {
|
|
|
|
num_bytes = pes_packet_bytes_;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
}
|
|
|
|
pes_packet_bytes_ -= num_bytes;
|
|
|
|
read_ptr += num_bytes;
|
|
|
|
continue;
|
|
|
|
case ProgramEnd:
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
metadata_is_complete_ = true;
|
2015-01-12 21:17:10 +00:00
|
|
|
if (!DemuxNextPes(true)) {
|
2014-07-14 21:35:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-21 18:30:29 +00:00
|
|
|
if (!Flush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
// Reset.
|
|
|
|
dts_ = pts_ = 0;
|
|
|
|
parse_state_ = StartCode1;
|
|
|
|
prev_media_sample_data_.Reset();
|
|
|
|
current_program_id_++;
|
2014-09-30 16:58:43 +00:00
|
|
|
ecm_.clear();
|
|
|
|
index_data_.clear();
|
|
|
|
psm_data_.clear();
|
2014-07-14 21:35:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++read_ptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
bool WvmMediaParser::EmitLastSample(
|
|
|
|
uint32_t stream_id,
|
|
|
|
const std::shared_ptr<MediaSample>& new_sample) {
|
2023-08-31 23:59:46 +00:00
|
|
|
std::string key = absl::StrFormat("%u:%u", current_program_id_, stream_id);
|
2014-09-30 21:52:21 +00:00
|
|
|
std::map<std::string, uint32_t>::iterator it =
|
2014-07-14 21:35:57 +00:00
|
|
|
program_demux_stream_map_.find(key);
|
2014-10-15 21:56:12 +00:00
|
|
|
if (it == program_demux_stream_map_.end())
|
2014-07-14 21:35:57 +00:00
|
|
|
return false;
|
2014-10-15 21:56:12 +00:00
|
|
|
return EmitSample(stream_id, (*it).second, new_sample, true);
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 21:56:12 +00:00
|
|
|
bool WvmMediaParser::EmitPendingSamples() {
|
2014-07-14 21:35:57 +00:00
|
|
|
// Emit queued samples which were built when not initialized.
|
|
|
|
while (!media_sample_queue_.empty()) {
|
|
|
|
DemuxStreamIdMediaSample& demux_stream_media_sample =
|
|
|
|
media_sample_queue_.front();
|
2014-10-15 21:56:12 +00:00
|
|
|
if (!EmitSample(demux_stream_media_sample.parsed_audio_or_video_stream_id,
|
|
|
|
demux_stream_media_sample.demux_stream_id,
|
|
|
|
demux_stream_media_sample.media_sample,
|
|
|
|
false)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
media_sample_queue_.pop_front();
|
|
|
|
}
|
2014-10-15 21:56:12 +00:00
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 18:30:29 +00:00
|
|
|
bool WvmMediaParser::Flush() {
|
2014-07-14 21:35:57 +00:00
|
|
|
// Flush the last audio and video sample for current program.
|
|
|
|
// Reset the streamID when successfully emitted.
|
|
|
|
if (prev_media_sample_data_.audio_sample != NULL) {
|
|
|
|
if (!EmitLastSample(prev_pes_stream_id_,
|
|
|
|
prev_media_sample_data_.audio_sample)) {
|
|
|
|
LOG(ERROR) << "Did not emit last sample for audio stream with ID = "
|
|
|
|
<< prev_pes_stream_id_;
|
2016-01-21 18:30:29 +00:00
|
|
|
return false;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prev_media_sample_data_.video_sample != NULL) {
|
|
|
|
if (!EmitLastSample(prev_pes_stream_id_,
|
|
|
|
prev_media_sample_data_.video_sample)) {
|
|
|
|
LOG(ERROR) << "Did not emit last sample for video stream with ID = "
|
|
|
|
<< prev_pes_stream_id_;
|
2016-01-21 18:30:29 +00:00
|
|
|
return false;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-21 18:30:29 +00:00
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WvmMediaParser::ParseIndexEntry() {
|
|
|
|
// Do not parse index entry at the beginning of any track *after* the first
|
|
|
|
// track.
|
|
|
|
if (current_program_id_ > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t index_size = 0;
|
2014-07-14 21:35:57 +00:00
|
|
|
if (index_data_.size() < kIndexVersion4HeaderSize) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-29 21:23:12 +00:00
|
|
|
const uint8_t* read_ptr = index_data_.data();
|
2023-08-31 23:59:46 +00:00
|
|
|
if (absl::big_endian::Load32(read_ptr) != kIndexMagic) {
|
2014-07-14 21:35:57 +00:00
|
|
|
index_data_.clear();
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-09 22:09:09 +00:00
|
|
|
read_ptr += 4;
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2023-08-31 23:59:46 +00:00
|
|
|
uint32_t version = absl::big_endian::Load32(read_ptr);
|
2015-10-09 22:09:09 +00:00
|
|
|
read_ptr += 4;
|
2014-07-14 21:35:57 +00:00
|
|
|
if (version == kVersion4) {
|
2023-08-31 23:59:46 +00:00
|
|
|
index_size = kIndexVersion4HeaderSize + absl::big_endian::Load32(read_ptr);
|
2014-07-14 21:35:57 +00:00
|
|
|
if (index_data_.size() < index_size) {
|
2014-12-03 23:33:16 +00:00
|
|
|
// We do not yet have the full index. Keep accumulating index data.
|
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
2015-10-09 22:09:09 +00:00
|
|
|
read_ptr += sizeof(uint32_t);
|
2014-07-14 21:35:57 +00:00
|
|
|
|
|
|
|
// Index metadata
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t index_metadata_max_size = index_size - kIndexVersion4HeaderSize;
|
|
|
|
if (index_metadata_max_size < sizeof(uint8_t)) {
|
2014-07-14 21:35:57 +00:00
|
|
|
index_data_.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
int64_t track_duration = 0;
|
2017-05-15 16:22:06 +00:00
|
|
|
uint32_t trick_play_factor = 0;
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t sampling_frequency = kDefaultSamplingFrequency;
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t time_scale = kMpeg2ClockRate;
|
2014-09-30 21:52:21 +00:00
|
|
|
uint16_t video_width = 0;
|
|
|
|
uint16_t video_height = 0;
|
2015-06-17 22:42:56 +00:00
|
|
|
uint32_t pixel_width = 0;
|
|
|
|
uint32_t pixel_height = 0;
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t nalu_length_size = kNaluLengthSize;
|
|
|
|
uint8_t num_channels = 0;
|
2014-07-14 21:35:57 +00:00
|
|
|
int audio_pes_stream_id = 0;
|
|
|
|
int video_pes_stream_id = 0;
|
|
|
|
bool has_video = false;
|
|
|
|
bool has_audio = false;
|
2015-10-09 22:09:09 +00:00
|
|
|
std::vector<uint8_t> audio_codec_config;
|
|
|
|
std::vector<uint8_t> video_codec_config;
|
|
|
|
uint8_t num_index_entries = *read_ptr;
|
|
|
|
++read_ptr;
|
2014-07-14 21:35:57 +00:00
|
|
|
--index_metadata_max_size;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint8_t idx = 0; idx < num_index_entries; ++idx) {
|
|
|
|
if (index_metadata_max_size < (2 * sizeof(uint8_t)) + sizeof(uint32_t)) {
|
2014-07-14 21:35:57 +00:00
|
|
|
return false;
|
2015-06-17 22:42:56 +00:00
|
|
|
}
|
2015-10-09 22:09:09 +00:00
|
|
|
uint8_t tag = *read_ptr;
|
|
|
|
++read_ptr;
|
|
|
|
uint8_t type = *read_ptr;
|
|
|
|
++read_ptr;
|
2023-08-31 23:59:46 +00:00
|
|
|
uint32_t length = absl::big_endian::Load32(read_ptr);
|
2015-10-09 22:09:09 +00:00
|
|
|
read_ptr += sizeof(uint32_t);
|
2015-06-17 22:42:56 +00:00
|
|
|
index_metadata_max_size -= (2 * sizeof(uint8_t)) + sizeof(uint32_t);
|
|
|
|
if (index_metadata_max_size < length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int64_t value = 0;
|
|
|
|
Tag tagtype = Unset;
|
2015-10-09 22:09:09 +00:00
|
|
|
std::vector<uint8_t> binary_data;
|
2015-06-17 22:42:56 +00:00
|
|
|
switch (Type(type)) {
|
|
|
|
case Type_uint8:
|
|
|
|
if (length == sizeof(uint8_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_int8:
|
|
|
|
if (length == sizeof(int8_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_uint16:
|
|
|
|
if (length == sizeof(uint16_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_int16:
|
|
|
|
if (length == sizeof(int16_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_uint32:
|
|
|
|
if (length == sizeof(uint32_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_int32:
|
|
|
|
if (length == sizeof(int32_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_uint64:
|
|
|
|
if (length == sizeof(uint64_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_int64:
|
|
|
|
if (length == sizeof(int64_t)) {
|
2015-10-09 22:09:09 +00:00
|
|
|
tagtype = GetTag(tag, length, read_ptr, &value);
|
2015-06-17 22:42:56 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Type_string:
|
|
|
|
case Type_BinaryData:
|
2015-10-09 22:09:09 +00:00
|
|
|
binary_data.assign(read_ptr, read_ptr + length);
|
2015-06-17 22:42:56 +00:00
|
|
|
tagtype = Tag(tag);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-10-08 18:20:53 +00:00
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2015-06-17 22:42:56 +00:00
|
|
|
switch (tagtype) {
|
|
|
|
case TrackDuration:
|
|
|
|
track_duration = value;
|
|
|
|
break;
|
2017-05-15 16:22:06 +00:00
|
|
|
case TrackTrickPlayFactor:
|
|
|
|
trick_play_factor = value;
|
2015-06-17 22:42:56 +00:00
|
|
|
break;
|
|
|
|
case VideoStreamId:
|
|
|
|
video_pes_stream_id = value;
|
|
|
|
break;
|
|
|
|
case AudioStreamId:
|
|
|
|
audio_pes_stream_id = value;
|
|
|
|
break;
|
|
|
|
case VideoWidth:
|
|
|
|
video_width = (uint16_t)value;
|
|
|
|
break;
|
|
|
|
case VideoHeight:
|
|
|
|
video_height = (uint16_t)value;
|
|
|
|
break;
|
|
|
|
case AudioNumChannels:
|
|
|
|
num_channels = (uint8_t)value;
|
|
|
|
break;
|
|
|
|
case VideoType:
|
|
|
|
has_video = true;
|
|
|
|
break;
|
|
|
|
case AudioType:
|
|
|
|
has_audio = true;
|
|
|
|
break;
|
|
|
|
case VideoPixelWidth:
|
|
|
|
pixel_width = static_cast<uint32_t>(value);
|
|
|
|
break;
|
|
|
|
case VideoPixelHeight:
|
|
|
|
pixel_height = static_cast<uint32_t>(value);
|
|
|
|
break;
|
2015-10-09 22:09:09 +00:00
|
|
|
case Audio_EsDescriptor: {
|
2016-05-25 18:03:17 +00:00
|
|
|
ESDescriptor descriptor;
|
2015-10-09 22:09:09 +00:00
|
|
|
if (!descriptor.Parse(binary_data)) {
|
|
|
|
LOG(ERROR) <<
|
|
|
|
"Could not extract AudioSpecificConfig from ES_Descriptor";
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-04 23:49:57 +00:00
|
|
|
audio_codec_config = descriptor.decoder_config_descriptor()
|
|
|
|
.decoder_specific_info_descriptor()
|
|
|
|
.data();
|
2015-10-09 22:09:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Audio_EC3SpecificData:
|
|
|
|
case Audio_DtsSpecificData:
|
|
|
|
case Audio_AC3SpecificData:
|
|
|
|
LOG(ERROR) << "Audio type not supported.";
|
|
|
|
return false;
|
2016-05-25 17:33:53 +00:00
|
|
|
case Video_AVCDecoderConfigurationRecord:
|
2015-10-09 22:09:09 +00:00
|
|
|
video_codec_config = binary_data;
|
|
|
|
break;
|
2015-06-17 22:42:56 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2015-10-09 22:09:09 +00:00
|
|
|
read_ptr += length;
|
2015-06-17 22:42:56 +00:00
|
|
|
index_metadata_max_size -= length;
|
|
|
|
}
|
|
|
|
// End Index metadata
|
2016-01-29 21:23:12 +00:00
|
|
|
index_size = read_ptr - index_data_.data();
|
2014-07-14 21:35:57 +00:00
|
|
|
|
2015-06-17 22:42:56 +00:00
|
|
|
if (has_video) {
|
2017-01-24 00:55:02 +00:00
|
|
|
stream_infos_.emplace_back(new VideoStreamInfo(
|
2017-03-23 18:34:20 +00:00
|
|
|
stream_id_count_, time_scale, track_duration, kCodecH264,
|
|
|
|
byte_to_unit_stream_converter_.stream_format(), std::string(),
|
|
|
|
video_codec_config.data(), video_codec_config.size(), video_width,
|
2019-09-23 06:24:33 +00:00
|
|
|
video_height, pixel_width, pixel_height,
|
|
|
|
0 /* transfer_characteristics */, trick_play_factor, nalu_length_size,
|
|
|
|
std::string(), decryption_key_source_ ? false : true));
|
2023-08-31 23:59:46 +00:00
|
|
|
program_demux_stream_map_[absl::StrFormat(
|
|
|
|
"%u:%u", index_program_id_,
|
|
|
|
video_pes_stream_id ? video_pes_stream_id : kDefaultVideoStreamId)] =
|
2015-06-17 22:42:56 +00:00
|
|
|
stream_id_count_++;
|
|
|
|
}
|
|
|
|
if (has_audio) {
|
2016-07-27 00:51:08 +00:00
|
|
|
const Codec audio_codec = kCodecAAC;
|
2016-01-04 18:57:05 +00:00
|
|
|
// TODO(beil): Pass in max and average bitrate in wvm container.
|
2017-01-24 00:55:02 +00:00
|
|
|
stream_infos_.emplace_back(new AudioStreamInfo(
|
2015-06-17 22:42:56 +00:00
|
|
|
stream_id_count_, time_scale, track_duration, audio_codec,
|
2016-07-27 00:51:08 +00:00
|
|
|
std::string(), audio_codec_config.data(), audio_codec_config.size(),
|
|
|
|
kAacSampleSizeBits, num_channels, sampling_frequency,
|
|
|
|
0 /* seek preroll */, 0 /* codec delay */, 0 /* max bitrate */,
|
2017-03-11 02:49:55 +00:00
|
|
|
0 /* avg bitrate */, std::string(),
|
|
|
|
decryption_key_source_ ? false : true));
|
2023-08-31 23:59:46 +00:00
|
|
|
program_demux_stream_map_[absl::StrFormat(
|
|
|
|
"%u:%u", index_program_id_,
|
|
|
|
audio_pes_stream_id ? audio_pes_stream_id : kDefaultAudioStreamId)] =
|
2015-06-17 22:42:56 +00:00
|
|
|
stream_id_count_++;
|
|
|
|
}
|
2014-12-03 23:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index_program_id_++;
|
|
|
|
index_data_.clear();
|
2014-07-14 21:35:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:17:10 +00:00
|
|
|
bool WvmMediaParser::DemuxNextPes(bool is_program_end) {
|
|
|
|
bool output_encrypted_sample = false;
|
2014-11-25 21:42:16 +00:00
|
|
|
if (!sample_data_.empty() && (prev_pes_flags_1_ & kScramblingBitsMask)) {
|
|
|
|
// Decrypt crypto unit.
|
|
|
|
if (!content_decryptor_) {
|
2015-01-12 21:17:10 +00:00
|
|
|
output_encrypted_sample = true;
|
|
|
|
} else {
|
2023-08-31 23:59:46 +00:00
|
|
|
size_t output_size = content_decryptor_->RequiredOutputSize(
|
|
|
|
sample_data_.size() - crypto_unit_start_pos_);
|
2016-04-06 00:19:16 +00:00
|
|
|
content_decryptor_->Crypt(&sample_data_[crypto_unit_start_pos_],
|
|
|
|
sample_data_.size() - crypto_unit_start_pos_,
|
2023-08-31 23:59:46 +00:00
|
|
|
&sample_data_[crypto_unit_start_pos_],
|
|
|
|
&output_size);
|
2014-11-25 21:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
// Demux media sample if we are at program end or if we are not at a
|
|
|
|
// continuation PES.
|
2014-11-25 21:42:16 +00:00
|
|
|
if ((pes_flags_2_ & kPesOptPts) || is_program_end) {
|
2014-07-14 21:35:57 +00:00
|
|
|
if (!sample_data_.empty()) {
|
2015-01-12 21:17:10 +00:00
|
|
|
if (!Output(output_encrypted_sample)) {
|
2014-07-14 21:35:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-01-12 21:17:10 +00:00
|
|
|
StartMediaSampleDemux();
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
2014-11-25 21:42:16 +00:00
|
|
|
|
|
|
|
crypto_unit_start_pos_ = sample_data_.size();
|
2014-07-14 21:35:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:17:10 +00:00
|
|
|
void WvmMediaParser::StartMediaSampleDemux() {
|
2014-07-14 21:35:57 +00:00
|
|
|
bool is_key_frame = ((pes_flags_1_ & kPesOptAlign) != 0);
|
|
|
|
media_sample_ = MediaSample::CreateEmptyMediaSample();
|
|
|
|
media_sample_->set_dts(dts_);
|
|
|
|
media_sample_->set_pts(pts_);
|
|
|
|
media_sample_->set_is_key_frame(is_key_frame);
|
|
|
|
|
|
|
|
sample_data_.clear();
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:17:10 +00:00
|
|
|
bool WvmMediaParser::Output(bool output_encrypted_sample) {
|
|
|
|
if (output_encrypted_sample) {
|
2017-09-18 23:31:00 +00:00
|
|
|
media_sample_->SetData(sample_data_.data(), sample_data_.size());
|
2015-01-12 21:17:10 +00:00
|
|
|
media_sample_->set_is_encrypted(true);
|
|
|
|
} else {
|
|
|
|
if ((prev_pes_stream_id_ & kPesStreamIdVideoMask) == kPesStreamIdVideo) {
|
2015-10-09 22:09:09 +00:00
|
|
|
// Convert video stream to unit stream and get config.
|
2015-01-12 21:17:10 +00:00
|
|
|
std::vector<uint8_t> nal_unit_stream;
|
|
|
|
if (!byte_to_unit_stream_converter_.ConvertByteStreamToNalUnitStream(
|
2016-01-29 21:23:12 +00:00
|
|
|
sample_data_.data(), sample_data_.size(), &nal_unit_stream)) {
|
2015-01-12 21:17:10 +00:00
|
|
|
LOG(ERROR) << "Could not convert h.264 byte stream sample";
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-18 23:31:00 +00:00
|
|
|
media_sample_->SetData(nal_unit_stream.data(), nal_unit_stream.size());
|
2015-01-12 21:17:10 +00:00
|
|
|
if (!is_initialized_) {
|
|
|
|
// Set extra data for video stream from AVC Decoder Config Record.
|
|
|
|
// Also, set codec string from the AVC Decoder Config Record.
|
|
|
|
std::vector<uint8_t> decoder_config_record;
|
2016-04-01 17:00:49 +00:00
|
|
|
byte_to_unit_stream_converter_.GetDecoderConfigurationRecord(
|
2015-01-12 21:17:10 +00:00
|
|
|
&decoder_config_record);
|
|
|
|
for (uint32_t i = 0; i < stream_infos_.size(); i++) {
|
2016-05-25 17:33:53 +00:00
|
|
|
if (stream_infos_[i]->stream_type() == kStreamVideo &&
|
2015-10-09 22:09:09 +00:00
|
|
|
stream_infos_[i]->codec_string().empty()) {
|
|
|
|
const std::vector<uint8_t>* stream_config;
|
2016-06-27 19:30:32 +00:00
|
|
|
if (stream_infos_[i]->codec_config().empty()) {
|
2015-10-09 22:09:09 +00:00
|
|
|
// Decoder config record not available for stream. Use the one
|
|
|
|
// computed from the first video stream.
|
2016-06-27 19:30:32 +00:00
|
|
|
stream_infos_[i]->set_codec_config(decoder_config_record);
|
2015-10-09 22:09:09 +00:00
|
|
|
stream_config = &decoder_config_record;
|
|
|
|
} else {
|
|
|
|
// Use stream-specific config record.
|
2016-06-27 19:30:32 +00:00
|
|
|
stream_config = &stream_infos_[i]->codec_config();
|
2015-10-09 22:09:09 +00:00
|
|
|
}
|
|
|
|
DCHECK(stream_config);
|
2015-08-20 19:06:02 +00:00
|
|
|
|
|
|
|
VideoStreamInfo* video_stream_info =
|
|
|
|
reinterpret_cast<VideoStreamInfo*>(stream_infos_[i].get());
|
2016-05-25 17:33:53 +00:00
|
|
|
AVCDecoderConfigurationRecord avc_config;
|
2015-10-27 00:52:57 +00:00
|
|
|
if (!avc_config.Parse(*stream_config)) {
|
2015-10-14 16:46:14 +00:00
|
|
|
LOG(WARNING) << "Failed to parse AVCDecoderConfigurationRecord. "
|
2015-10-27 00:52:57 +00:00
|
|
|
"Using computed configuration record instead.";
|
2016-06-27 19:30:32 +00:00
|
|
|
video_stream_info->set_codec_config(decoder_config_record);
|
2015-10-27 00:52:57 +00:00
|
|
|
if (!avc_config.Parse(decoder_config_record)) {
|
2015-10-14 16:46:14 +00:00
|
|
|
LOG(ERROR) << "Failed to parse AVCDecoderConfigurationRecord.";
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-16 22:22:22 +00:00
|
|
|
}
|
2017-03-23 18:36:47 +00:00
|
|
|
const FourCC codec_fourcc =
|
|
|
|
byte_to_unit_stream_converter_.stream_format() ==
|
|
|
|
H26xStreamFormat::kNalUnitStreamWithParameterSetNalus
|
|
|
|
? FOURCC_avc3
|
|
|
|
: FOURCC_avc1;
|
|
|
|
video_stream_info->set_codec_string(
|
|
|
|
avc_config.GetCodecString(codec_fourcc));
|
2015-10-27 00:52:57 +00:00
|
|
|
|
|
|
|
if (avc_config.pixel_width() != video_stream_info->pixel_width() ||
|
|
|
|
avc_config.pixel_height() !=
|
|
|
|
video_stream_info->pixel_height()) {
|
2015-09-16 22:22:22 +00:00
|
|
|
LOG_IF(WARNING, video_stream_info->pixel_width() != 0 ||
|
|
|
|
video_stream_info->pixel_height() != 0)
|
|
|
|
<< "Pixel aspect ratio in WVM metadata ("
|
|
|
|
<< video_stream_info->pixel_width() << ","
|
|
|
|
<< video_stream_info->pixel_height()
|
|
|
|
<< ") does not match with SAR in "
|
|
|
|
"AVCDecoderConfigurationRecord ("
|
2015-10-27 00:52:57 +00:00
|
|
|
<< avc_config.pixel_width() << ","
|
|
|
|
<< avc_config.pixel_height()
|
2015-09-16 22:22:22 +00:00
|
|
|
<< "). Use AVCDecoderConfigurationRecord.";
|
2015-10-27 00:52:57 +00:00
|
|
|
video_stream_info->set_pixel_width(avc_config.pixel_width());
|
|
|
|
video_stream_info->set_pixel_height(avc_config.pixel_height());
|
2015-08-20 19:06:02 +00:00
|
|
|
}
|
2015-10-27 00:52:57 +00:00
|
|
|
if (avc_config.coded_width() != video_stream_info->width() ||
|
|
|
|
avc_config.coded_height() != video_stream_info->height()) {
|
2015-09-16 22:22:22 +00:00
|
|
|
LOG(WARNING) << "Resolution in WVM metadata ("
|
|
|
|
<< video_stream_info->width() << ","
|
|
|
|
<< video_stream_info->height()
|
|
|
|
<< ") does not match with resolution in "
|
|
|
|
"AVCDecoderConfigurationRecord ("
|
2015-10-27 00:52:57 +00:00
|
|
|
<< avc_config.coded_width() << ","
|
|
|
|
<< avc_config.coded_height()
|
2015-09-16 22:22:22 +00:00
|
|
|
<< "). Use AVCDecoderConfigurationRecord.";
|
2015-10-27 00:52:57 +00:00
|
|
|
video_stream_info->set_width(avc_config.coded_width());
|
|
|
|
video_stream_info->set_height(avc_config.coded_height());
|
2015-09-16 22:22:22 +00:00
|
|
|
}
|
2015-01-12 21:17:10 +00:00
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-12 21:17:10 +00:00
|
|
|
} else if ((prev_pes_stream_id_ & kPesStreamIdAudioMask) ==
|
|
|
|
kPesStreamIdAudio) {
|
2015-10-09 22:09:09 +00:00
|
|
|
// Set data on the audio stream.
|
2016-05-25 17:33:53 +00:00
|
|
|
mp2t::AdtsHeader adts_header;
|
2016-01-29 21:23:12 +00:00
|
|
|
const uint8_t* frame_ptr = sample_data_.data();
|
2017-10-23 05:27:27 +00:00
|
|
|
if (!adts_header.Parse(frame_ptr, sample_data_.size())) {
|
2015-01-12 21:17:10 +00:00
|
|
|
LOG(ERROR) << "Could not parse ADTS header";
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-23 05:27:27 +00:00
|
|
|
media_sample_->SetData(
|
|
|
|
frame_ptr + adts_header.GetHeaderSize(),
|
|
|
|
adts_header.GetFrameSize() - adts_header.GetHeaderSize());
|
2015-01-12 21:17:10 +00:00
|
|
|
if (!is_initialized_) {
|
|
|
|
for (uint32_t i = 0; i < stream_infos_.size(); i++) {
|
2016-05-25 17:33:53 +00:00
|
|
|
if (stream_infos_[i]->stream_type() == kStreamAudio &&
|
2015-10-09 22:09:09 +00:00
|
|
|
stream_infos_[i]->codec_string().empty()) {
|
2015-01-12 21:17:10 +00:00
|
|
|
AudioStreamInfo* audio_stream_info =
|
2015-10-09 22:09:09 +00:00
|
|
|
reinterpret_cast<AudioStreamInfo*>(stream_infos_[i].get());
|
2016-06-27 19:30:32 +00:00
|
|
|
if (audio_stream_info->codec_config().empty()) {
|
2015-10-09 22:09:09 +00:00
|
|
|
// Set AudioStreamInfo fields using information from the ADTS
|
|
|
|
// header.
|
|
|
|
audio_stream_info->set_sampling_frequency(
|
|
|
|
adts_header.GetSamplingFrequency());
|
|
|
|
std::vector<uint8_t> audio_specific_config;
|
2017-10-23 05:27:27 +00:00
|
|
|
adts_header.GetAudioSpecificConfig(&audio_specific_config);
|
2016-06-27 19:30:32 +00:00
|
|
|
audio_stream_info->set_codec_config(audio_specific_config);
|
2015-10-09 22:09:09 +00:00
|
|
|
audio_stream_info->set_codec_string(
|
|
|
|
AudioStreamInfo::GetCodecString(
|
|
|
|
kCodecAAC, adts_header.GetObjectType()));
|
|
|
|
} else {
|
|
|
|
// Set AudioStreamInfo fields using information from the
|
|
|
|
// AACAudioSpecificConfig record.
|
2016-05-25 18:03:17 +00:00
|
|
|
AACAudioSpecificConfig aac_config;
|
2016-06-27 19:30:32 +00:00
|
|
|
if (!aac_config.Parse(stream_infos_[i]->codec_config())) {
|
2015-10-09 22:09:09 +00:00
|
|
|
LOG(ERROR) << "Could not parse AACAudioSpecificconfig";
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-10 20:20:45 +00:00
|
|
|
audio_stream_info->set_sampling_frequency(
|
|
|
|
aac_config.GetSamplesPerSecond());
|
2015-10-09 22:09:09 +00:00
|
|
|
audio_stream_info->set_codec_string(
|
|
|
|
AudioStreamInfo::GetCodecString(
|
2017-04-10 20:20:45 +00:00
|
|
|
kCodecAAC, aac_config.GetAudioObjectType()));
|
2015-10-09 22:09:09 +00:00
|
|
|
}
|
2015-01-12 21:17:10 +00:00
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-09 19:56:51 +00:00
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
|
|
|
|
if (!is_initialized_) {
|
2015-10-09 22:09:09 +00:00
|
|
|
bool all_streams_have_config = true;
|
2016-06-27 19:30:32 +00:00
|
|
|
// Check if all collected stream infos have codec_config set.
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < stream_infos_.size(); i++) {
|
2015-10-09 22:09:09 +00:00
|
|
|
if (stream_infos_[i]->codec_string().empty()) {
|
|
|
|
all_streams_have_config = false;
|
2014-07-14 21:35:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 22:09:09 +00:00
|
|
|
if (all_streams_have_config) {
|
2023-08-31 23:59:46 +00:00
|
|
|
init_cb_(stream_infos_);
|
2014-07-14 21:35:57 +00:00
|
|
|
is_initialized_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_GT(media_sample_->data_size(), 0UL);
|
2023-08-31 23:59:46 +00:00
|
|
|
std::string key =
|
|
|
|
absl::StrFormat("%u:%u", current_program_id_, prev_pes_stream_id_);
|
2014-09-30 21:52:21 +00:00
|
|
|
std::map<std::string, uint32_t>::iterator it =
|
2014-07-14 21:35:57 +00:00
|
|
|
program_demux_stream_map_.find(key);
|
|
|
|
if (it == program_demux_stream_map_.end()) {
|
|
|
|
// TODO(ramjic): Log error message here and in other error cases through
|
|
|
|
// this method.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DemuxStreamIdMediaSample demux_stream_media_sample;
|
|
|
|
demux_stream_media_sample.parsed_audio_or_video_stream_id =
|
|
|
|
prev_pes_stream_id_;
|
|
|
|
demux_stream_media_sample.demux_stream_id = (*it).second;
|
|
|
|
demux_stream_media_sample.media_sample = media_sample_;
|
|
|
|
// Check if sample can be emitted.
|
|
|
|
if (!is_initialized_) {
|
|
|
|
media_sample_queue_.push_back(demux_stream_media_sample);
|
|
|
|
} else {
|
|
|
|
// flush the sample queue and emit all queued samples.
|
|
|
|
while (!media_sample_queue_.empty()) {
|
2014-10-15 21:56:12 +00:00
|
|
|
if (!EmitPendingSamples())
|
|
|
|
return false;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
// Emit current sample.
|
2014-10-15 21:56:12 +00:00
|
|
|
if (!EmitSample(prev_pes_stream_id_, (*it).second, media_sample_, false))
|
|
|
|
return false;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-15 21:56:12 +00:00
|
|
|
bool WvmMediaParser::EmitSample(uint32_t parsed_audio_or_video_stream_id,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t stream_id,
|
2017-01-24 00:55:02 +00:00
|
|
|
const std::shared_ptr<MediaSample>& new_sample,
|
2014-09-30 21:52:21 +00:00
|
|
|
bool isLastSample) {
|
2014-07-14 21:35:57 +00:00
|
|
|
DCHECK(new_sample);
|
|
|
|
if (isLastSample) {
|
2014-10-15 21:56:12 +00:00
|
|
|
if ((parsed_audio_or_video_stream_id & kPesStreamIdVideoMask) ==
|
|
|
|
kPesStreamIdVideo) {
|
2014-07-14 21:35:57 +00:00
|
|
|
new_sample->set_duration(prev_media_sample_data_.video_sample_duration);
|
2014-10-15 21:56:12 +00:00
|
|
|
} else if ((parsed_audio_or_video_stream_id & kPesStreamIdAudioMask) ==
|
|
|
|
kPesStreamIdAudio) {
|
2014-07-14 21:35:57 +00:00
|
|
|
new_sample->set_duration(prev_media_sample_data_.audio_sample_duration);
|
|
|
|
}
|
2023-08-31 23:59:46 +00:00
|
|
|
if (!new_sample_cb_(stream_id, new_sample)) {
|
2014-10-15 21:56:12 +00:00
|
|
|
LOG(ERROR) << "Failed to process the last sample.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cannot emit current sample. Compute duration first and then,
|
|
|
|
// emit previous sample.
|
2014-10-15 21:56:12 +00:00
|
|
|
if ((parsed_audio_or_video_stream_id & kPesStreamIdVideoMask) ==
|
|
|
|
kPesStreamIdVideo) {
|
2014-07-14 21:35:57 +00:00
|
|
|
if (prev_media_sample_data_.video_sample == NULL) {
|
|
|
|
prev_media_sample_data_.video_sample = new_sample;
|
|
|
|
prev_media_sample_data_.video_stream_id = stream_id;
|
2014-10-15 21:56:12 +00:00
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
prev_media_sample_data_.video_sample->set_duration(
|
|
|
|
new_sample->dts() - prev_media_sample_data_.video_sample->dts());
|
|
|
|
prev_media_sample_data_.video_sample_duration =
|
|
|
|
prev_media_sample_data_.video_sample->duration();
|
2023-08-31 23:59:46 +00:00
|
|
|
if (!new_sample_cb_(prev_media_sample_data_.video_stream_id,
|
|
|
|
prev_media_sample_data_.video_sample)) {
|
2014-10-15 21:56:12 +00:00
|
|
|
LOG(ERROR) << "Failed to process the video sample.";
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
prev_media_sample_data_.video_sample = new_sample;
|
|
|
|
prev_media_sample_data_.video_stream_id = stream_id;
|
2014-10-15 21:56:12 +00:00
|
|
|
} else if ((parsed_audio_or_video_stream_id & kPesStreamIdAudioMask) ==
|
|
|
|
kPesStreamIdAudio) {
|
2014-07-14 21:35:57 +00:00
|
|
|
if (prev_media_sample_data_.audio_sample == NULL) {
|
|
|
|
prev_media_sample_data_.audio_sample = new_sample;
|
|
|
|
prev_media_sample_data_.audio_stream_id = stream_id;
|
2014-10-15 21:56:12 +00:00
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
prev_media_sample_data_.audio_sample->set_duration(
|
|
|
|
new_sample->dts() - prev_media_sample_data_.audio_sample->dts());
|
|
|
|
prev_media_sample_data_.audio_sample_duration =
|
|
|
|
prev_media_sample_data_.audio_sample->duration();
|
2023-08-31 23:59:46 +00:00
|
|
|
if (!new_sample_cb_(prev_media_sample_data_.audio_stream_id,
|
|
|
|
prev_media_sample_data_.audio_sample)) {
|
2014-10-15 21:56:12 +00:00
|
|
|
LOG(ERROR) << "Failed to process the audio sample.";
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
prev_media_sample_data_.audio_sample = new_sample;
|
|
|
|
prev_media_sample_data_.audio_stream_id = stream_id;
|
|
|
|
}
|
2014-10-15 21:56:12 +00:00
|
|
|
return true;
|
2014-07-14 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 19:43:41 +00:00
|
|
|
bool WvmMediaParser::GetAssetKey(const uint8_t* asset_id,
|
2014-10-01 22:10:21 +00:00
|
|
|
EncryptionKey* encryption_key) {
|
2014-10-14 02:34:29 +00:00
|
|
|
DCHECK(decryption_key_source_);
|
2017-04-04 19:43:41 +00:00
|
|
|
Status status = decryption_key_source_->FetchKeys(
|
|
|
|
EmeInitDataType::WIDEVINE_CLASSIC,
|
|
|
|
std::vector<uint8_t>(asset_id, asset_id + sizeof(uint32_t)));
|
2014-09-30 16:58:43 +00:00
|
|
|
if (!status.ok()) {
|
2017-04-04 19:43:41 +00:00
|
|
|
LOG(ERROR) << "Fetch Key(s) failed for AssetID = "
|
2023-08-31 23:59:46 +00:00
|
|
|
<< absl::big_endian::Load32(asset_id) << ", error = " << status;
|
2014-09-30 16:58:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:54:12 +00:00
|
|
|
const char kHdStreamLabel[] = "HD";
|
|
|
|
status = decryption_key_source_->GetKey(kHdStreamLabel, encryption_key);
|
2014-09-30 16:58:43 +00:00
|
|
|
if (!status.ok()) {
|
2017-04-04 19:43:41 +00:00
|
|
|
LOG(ERROR) << "Fetch Key(s) failed for AssetID = "
|
2023-08-31 23:59:46 +00:00
|
|
|
<< absl::big_endian::Load32(asset_id) << ", error = " << status;
|
2014-09-30 16:58:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WvmMediaParser::ProcessEcm() {
|
2014-10-14 02:34:29 +00:00
|
|
|
// An error will be returned later if the samples need to be decrypted.
|
|
|
|
if (!decryption_key_source_)
|
|
|
|
return true;
|
|
|
|
|
2014-09-30 16:58:43 +00:00
|
|
|
if (current_program_id_ > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ecm_.size() != kEcmSizeBytes) {
|
|
|
|
LOG(ERROR) << "Unexpected ECM size = " << ecm_.size()
|
|
|
|
<< ", expected size = " << kEcmSizeBytes;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const uint8_t* ecm_data = ecm_.data();
|
|
|
|
DCHECK(ecm_data);
|
|
|
|
ecm_data += sizeof(uint32_t); // old version field - skip.
|
|
|
|
ecm_data += sizeof(uint32_t); // clear lead - skip.
|
|
|
|
ecm_data += sizeof(uint32_t); // system id(includes ECM version) - skip.
|
|
|
|
EncryptionKey encryption_key;
|
2017-04-04 19:43:41 +00:00
|
|
|
if (!GetAssetKey(ecm_data, &encryption_key)) {
|
2014-09-30 16:58:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-16 16:18:30 +00:00
|
|
|
if (encryption_key.key.size() < kAssetKeySizeBytes) {
|
|
|
|
LOG(ERROR) << "Asset Key size of " << encryption_key.key.size()
|
2023-08-31 23:59:46 +00:00
|
|
|
<< " for AssetID = " << absl::big_endian::Load32(ecm_data)
|
2014-10-16 16:18:30 +00:00
|
|
|
<< " is less than minimum asset key size.";
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-04 19:43:41 +00:00
|
|
|
ecm_data += sizeof(uint32_t); // asset_id.
|
2014-10-16 16:18:30 +00:00
|
|
|
// Legacy WVM content may have asset keys > 16 bytes.
|
|
|
|
// Use only the first 16 bytes of the asset key to get
|
|
|
|
// the content key.
|
|
|
|
std::vector<uint8_t> asset_key(
|
|
|
|
encryption_key.key.begin(),
|
|
|
|
encryption_key.key.begin() + kAssetKeySizeBytes);
|
2016-04-22 20:41:45 +00:00
|
|
|
// WVM format always uses all zero IV.
|
|
|
|
std::vector<uint8_t> zero_iv(kInitializationVectorSizeBytes, 0);
|
2016-04-13 17:52:41 +00:00
|
|
|
AesCbcDecryptor asset_decryptor(kCtsPadding, AesCryptor::kUseConstantIv);
|
2016-04-22 20:41:45 +00:00
|
|
|
if (!asset_decryptor.InitializeWithIv(asset_key, zero_iv)) {
|
2014-10-14 02:34:29 +00:00
|
|
|
LOG(ERROR) << "Failed to initialize asset_decryptor.";
|
2014-09-30 16:58:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-14 02:34:29 +00:00
|
|
|
const size_t content_key_buffer_size =
|
|
|
|
kEcmFlagsSizeBytes + kEcmContentKeySizeBytes +
|
|
|
|
kEcmPaddingSizeBytes; // flags + contentKey + padding.
|
2023-08-31 23:59:46 +00:00
|
|
|
|
|
|
|
size_t output_size =
|
|
|
|
asset_decryptor.RequiredOutputSize(content_key_buffer_size);
|
|
|
|
std::vector<uint8_t> content_key_buffer(output_size);
|
2016-04-06 00:19:16 +00:00
|
|
|
CHECK(asset_decryptor.Crypt(ecm_data, content_key_buffer_size,
|
2023-08-31 23:59:46 +00:00
|
|
|
content_key_buffer.data(), &output_size));
|
2014-10-14 02:34:29 +00:00
|
|
|
|
2014-09-30 16:58:43 +00:00
|
|
|
std::vector<uint8_t> decrypted_content_key_vec(
|
|
|
|
content_key_buffer.begin() + 4,
|
|
|
|
content_key_buffer.begin() + 20);
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<AesCbcDecryptor> content_decryptor(
|
2016-04-13 17:52:41 +00:00
|
|
|
new AesCbcDecryptor(kCtsPadding, AesCryptor::kUseConstantIv));
|
2016-04-22 20:41:45 +00:00
|
|
|
if (!content_decryptor->InitializeWithIv(decrypted_content_key_vec,
|
|
|
|
zero_iv)) {
|
2014-10-14 02:34:29 +00:00
|
|
|
LOG(ERROR) << "Failed to initialize content decryptor.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
content_decryptor_ = std::move(content_decryptor);
|
2014-10-14 02:34:29 +00:00
|
|
|
return true;
|
2014-09-30 16:58:43 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 19:55:49 +00:00
|
|
|
DemuxStreamIdMediaSample::DemuxStreamIdMediaSample() :
|
2014-09-30 16:58:43 +00:00
|
|
|
demux_stream_id(0),
|
|
|
|
parsed_audio_or_video_stream_id(0) {}
|
2014-09-16 19:55:49 +00:00
|
|
|
|
|
|
|
DemuxStreamIdMediaSample::~DemuxStreamIdMediaSample() {}
|
|
|
|
|
|
|
|
PrevSampleData::PrevSampleData() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrevSampleData::~PrevSampleData() {}
|
|
|
|
|
|
|
|
void PrevSampleData::Reset() {
|
2014-09-30 16:58:43 +00:00
|
|
|
audio_sample = NULL;
|
|
|
|
video_sample = NULL;
|
|
|
|
audio_stream_id = 0;
|
|
|
|
video_stream_id = 0;
|
|
|
|
audio_sample_duration = 0;
|
|
|
|
video_sample_duration = 0;
|
2014-09-16 19:55:49 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 21:35:57 +00:00
|
|
|
} // namespace wvm
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|