Skip to content

Commit 79a8161

Browse files
committed
revert HEVC config box which would be parsed inside Gecko later.
1 parent 4d6ca2d commit 79a8161

File tree

3 files changed

+19
-160
lines changed

3 files changed

+19
-160
lines changed

mp4parse/src/lib.rs

Lines changed: 11 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ pub enum VideoCodecSpecific {
11611161
AV1Config(AV1ConfigBox),
11621162
ESDSConfig(TryVec<u8>),
11631163
H263Config(TryVec<u8>),
1164-
HEVCConfig(HEVCConfigBox),
1164+
HEVCConfig(TryVec<u8>),
11651165
}
11661166

11671167
#[derive(Debug)]
@@ -1234,44 +1234,6 @@ impl AV1ConfigBox {
12341234
}
12351235
}
12361236

1237-
// Spec 8.3.2.1.2 HEVCDecoderConfigurationRecord
1238-
#[derive(Debug)]
1239-
pub struct NALUnit {
1240-
pub nal_unit_length: u16,
1241-
pub nal_unit_content: TryVec<u8>,
1242-
}
1243-
1244-
#[derive(Debug)]
1245-
pub struct HEVCArrayInfo {
1246-
pub array_completeness: u8,
1247-
pub nal_unit_type: u8,
1248-
pub num_nalus: u16,
1249-
pub nal_units: TryVec<NALUnit>,
1250-
}
1251-
1252-
#[derive(Debug)]
1253-
pub struct HEVCConfigBox {
1254-
pub configuration_version: u8,
1255-
pub general_profile_space: u8,
1256-
pub general_tier_flag: u8,
1257-
pub general_profile_idc: u8,
1258-
pub general_profile_compatibility_flags: u32,
1259-
pub general_constraint_indicator_flags: u64,
1260-
pub general_level_idc: u8,
1261-
pub min_spatial_segmentation_idc: u16,
1262-
pub parallelism_type: u8,
1263-
pub chroma_format_idc: u8,
1264-
pub bit_depth_luma_minus8: u8,
1265-
pub bit_depth_chroma_minus8: u8,
1266-
pub avg_frame_rate: u16,
1267-
pub constant_frame_rate: u8,
1268-
pub num_temporal_layers: u8,
1269-
pub temporal_id_nested: u8,
1270-
pub length_size_minus_one: u8,
1271-
pub num_of_arrays: u8,
1272-
pub array_infos: TryVec<HEVCArrayInfo>,
1273-
}
1274-
12751237
#[derive(Debug)]
12761238
pub struct FLACMetadataBlock {
12771239
pub block_type: u8,
@@ -4967,102 +4929,6 @@ fn read_av1c<T: Read>(src: &mut BMFFBox<T>) -> Result<AV1ConfigBox> {
49674929
})
49684930
}
49694931

4970-
fn read_hvcc<T: Read>(src: &mut BMFFBox<T>) -> Result<HEVCConfigBox> {
4971-
let configuration_version = src.read_u8()?;
4972-
let (general_profile_space, general_tier_flag, general_profile_idc) = {
4973-
let byte = src.read_u8()?;
4974-
((byte >> 6) & 0x03, (byte >> 5) & 0x01, byte & 0x1F)
4975-
};
4976-
let general_profile_compatibility_flags = src.read_u32::<byteorder::BigEndian>()?;
4977-
let general_constraint_indicator_flags = {
4978-
let flag_high = src.read_u32::<byteorder::BigEndian>()?;
4979-
let flag_low: u16 = src.read_u16::<byteorder::BigEndian>()?;
4980-
(flag_high as u64) << 16 | flag_low as u64
4981-
};
4982-
let general_level_idc = src.read_u8()?;
4983-
let (min_spatial_segmentation_idc, parallelism_type, chroma_format_idc) = {
4984-
let byte = src.read_u32::<byteorder::BigEndian>()?;
4985-
(
4986-
((byte >> 16) & 0x0FFF) as u16,
4987-
((byte >> 8) & 0x03) as u8,
4988-
(byte & 0x03) as u8,
4989-
)
4990-
};
4991-
let (bit_depth_luma_minus8, bit_depth_chroma_minus8) = {
4992-
let byte = src.read_u16::<byteorder::BigEndian>()?;
4993-
(((byte >> 8) & 0x07) as u8, (byte & 0x07) as u8)
4994-
};
4995-
let avg_frame_rate = src.read_u16::<byteorder::BigEndian>()?;
4996-
let (constant_frame_rate, num_temporal_layers, temporal_id_nested, length_size_minus_one) = {
4997-
let byte = src.read_u8()?;
4998-
(
4999-
(byte >> 6) & 0x03,
5000-
(byte >> 3) & 0x07,
5001-
(byte >> 2) & 0x01,
5002-
byte & 0x03,
5003-
)
5004-
};
5005-
let num_of_arrays = src.read_u8()?;
5006-
let mut array_infos = TryVec::new();
5007-
for _i in 0..num_of_arrays {
5008-
let array_info = read_hevc_arry_info(src)?;
5009-
array_infos.push(array_info)?;
5010-
}
5011-
Ok(HEVCConfigBox {
5012-
configuration_version,
5013-
general_profile_space,
5014-
general_tier_flag,
5015-
general_profile_idc,
5016-
general_profile_compatibility_flags,
5017-
general_constraint_indicator_flags,
5018-
general_level_idc,
5019-
min_spatial_segmentation_idc,
5020-
parallelism_type,
5021-
chroma_format_idc,
5022-
bit_depth_luma_minus8,
5023-
bit_depth_chroma_minus8,
5024-
avg_frame_rate,
5025-
constant_frame_rate,
5026-
num_temporal_layers,
5027-
temporal_id_nested,
5028-
length_size_minus_one,
5029-
num_of_arrays,
5030-
array_infos,
5031-
})
5032-
}
5033-
5034-
fn read_hevc_arry_info<T: Read>(src: &mut BMFFBox<T>) -> Result<HEVCArrayInfo> {
5035-
let (array_completeness, nal_unit_type) = {
5036-
let byte = src.read_u8()?;
5037-
((byte >> 7) & 0x01, byte & 0x3F)
5038-
};
5039-
let num_nalus = src.read_u16::<byteorder::BigEndian>()?;
5040-
let mut nal_units = TryVec::new();
5041-
for _i in 0..num_nalus {
5042-
let nal = read_nal_unit(src)?;
5043-
nal_units.push(nal)?;
5044-
}
5045-
Ok(HEVCArrayInfo {
5046-
array_completeness,
5047-
nal_unit_type,
5048-
num_nalus,
5049-
nal_units,
5050-
})
5051-
}
5052-
5053-
fn read_nal_unit<T: Read>(src: &mut BMFFBox<T>) -> Result<NALUnit> {
5054-
let nal_unit_length = src.read_u16::<byteorder::BigEndian>()?;
5055-
let mut nal_unit_content = TryVec::new();
5056-
for _i in 0..nal_unit_length {
5057-
let byte = src.read_u8()?;
5058-
nal_unit_content.push(byte)?;
5059-
}
5060-
Ok(NALUnit {
5061-
nal_unit_length,
5062-
nal_unit_content,
5063-
})
5064-
}
5065-
50664932
fn read_flac_metadata<T: Read>(src: &mut BMFFBox<T>) -> Result<FLACMetadataBlock> {
50674933
let temp = src.read_u8()?;
50684934
let block_type = temp & 0x7f;
@@ -5705,10 +5571,18 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
57055571
protection_info.push(sinf)?;
57065572
}
57075573
BoxType::HEVCConfigurationBox => {
5708-
if name != BoxType::HEV1SampleEntry && name != BoxType::HVC1SampleEntry {
5574+
if (name != BoxType::HEV1SampleEntry && name != BoxType::HVC1SampleEntry)
5575+
|| codec_specific.is_some()
5576+
{
57095577
return Status::StsdBadVideoSampleEntry.into();
57105578
}
5711-
let hvcc = read_hvcc(&mut b)?;
5579+
let hvcc_size = b
5580+
.head
5581+
.size
5582+
.checked_sub(b.head.offset)
5583+
.expect("offset invalid");
5584+
let hvcc = read_buf(&mut b.content, hvcc_size)?;
5585+
debug!("{:?} (hvcc)", hvcc);
57125586
codec_specific = Some(VideoCodecSpecific::HEVCConfig(hvcc));
57135587
}
57145588
_ => {

mp4parse/tests/public.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ fn public_api() {
289289
mp4::VideoCodecSpecific::H263Config(ref _h263) => {
290290
"H263"
291291
}
292-
mp4::VideoCodecSpecific::HEVCConfig(ref _hevc) => {
292+
mp4::VideoCodecSpecific::HEVCConfig(ref hevc) => {
293+
assert!(!hevc.is_empty());
293294
"HEVC"
294295
}
295296
},
@@ -1458,27 +1459,8 @@ fn public_video_hevc() {
14581459
assert_eq!(v.codec_type, mp4::CodecType::HEVC);
14591460
assert_eq!(v.width, 640);
14601461
assert_eq!(v.height, 480);
1461-
match &v.codec_specific {
1462-
mp4::VideoCodecSpecific::HEVCConfig(config) => {
1463-
assert_eq!(config.configuration_version, 1);
1464-
assert_eq!(config.general_profile_space, 0);
1465-
assert_eq!(config.general_tier_flag, 0);
1466-
assert_eq!(config.general_profile_idc, 1);
1467-
assert_eq!(config.general_profile_compatibility_flags, 1610612736);
1468-
assert_eq!(config.general_constraint_indicator_flags, 158329674399744);
1469-
assert_eq!(config.general_level_idc, 90);
1470-
assert_eq!(config.min_spatial_segmentation_idc, 0);
1471-
assert_eq!(config.parallelism_type, 0);
1472-
assert_eq!(config.chroma_format_idc, 1);
1473-
assert_eq!(config.bit_depth_luma_minus8, 0);
1474-
assert_eq!(config.bit_depth_chroma_minus8, 0);
1475-
assert_eq!(config.avg_frame_rate, 0);
1476-
assert_eq!(config.constant_frame_rate, 0);
1477-
assert_eq!(config.num_temporal_layers, 1);
1478-
assert_eq!(config.temporal_id_nested, 1);
1479-
assert_eq!(config.length_size_minus_one, 3);
1480-
assert_eq!(config.num_of_arrays, 4);
1481-
}
1462+
let _codec_specific = match &v.codec_specific {
1463+
mp4::VideoCodecSpecific::HEVCConfig(_) => true,
14821464
_ => {
14831465
panic!("expected a HEVCConfig",);
14841466
}
@@ -1495,6 +1477,7 @@ fn public_audio_amrnb() {
14951477

14961478
let mut c = Cursor::new(&buf);
14971479
let context = mp4::read_mp4(&mut c).expect("read_mp4 failed");
1480+
14981481
for track in context.tracks {
14991482
let stsd = track.stsd.expect("expected an stsd");
15001483
let a = match stsd.descriptions.first().expect("expected a SampleEntry") {

mp4parse_capi/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,9 @@ fn mp4parse_get_track_video_info_safe(
980980
VideoCodecSpecific::AV1Config(ref config) => {
981981
sample_info.extra_data.set_data(&config.raw_config);
982982
}
983-
VideoCodecSpecific::AVCConfig(ref data) | VideoCodecSpecific::ESDSConfig(ref data) => {
983+
VideoCodecSpecific::AVCConfig(ref data)
984+
| VideoCodecSpecific::ESDSConfig(ref data)
985+
| VideoCodecSpecific::HEVCConfig(ref data) => {
984986
sample_info.extra_data.set_data(data);
985987
}
986988
_ => {}

0 commit comments

Comments
 (0)