dholroyd / h264-reader

Rust reader for H264 bitsream syntax
Apache License 2.0
72 stars 25 forks source link

Maybe wrong constants in PicScalingMatrix #45

Closed sshiroi closed 1 year ago

sshiroi commented 1 year ago

When i try to use the code similar to this i get following error. On all streams i tried it on. https://github.com/dholroyd/h264-reader/blob/945b404818bd12e8a2f61d2332a86e84deba2333/benches/bench.rs#L71-L105

[..] on an `Err` value: ScalingMatrix(ReaderError(ReaderErrorFor("delta_scale", Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })))', [...]

Which i think is caused by wrong constants here.

https://github.com/dholroyd/h264-reader/blob/945b404818bd12e8a2f61d2332a86e84deba2333/src/nal/pps.rs#L158-L162

Specification i have says:

for( i = 0; i < 6 +
( ( chroma_format_idc != 3 ) ? 2 : 6 ) * transform_8x8_mode_flag;
i++ ) {

Error goes away with these values.

dholroyd commented 1 year ago

Could you provide a PPS that we can use in a test? I think that in my limited testing, I must have only looked at steams with pic_scaling_matrix_present_flag=0.

sshiroi commented 1 year ago

I think these values are what you asked for.

    #[test]
    fn test_oooo() {
        let sps = vec![100, 0, 41, 172, 27, 26, 80, 30, 0, 137, 249, 112, 17, 0, 0, 3, 233, 0, 0, 187, 128, 226, 96, 0, 4, 195, 122, 0, 0, 114, 112, 232, 196, 184, 196, 192, 0, 9, 134, 244, 0, 0, 228, 225, 209, 137, 112, 248, 225, 133, 44];
        let pps = vec![234, 141, 206, 80, 148, 141, 24, 178, 90, 85, 40, 74, 70, 140, 89, 45, 42, 80, 201, 26, 49, 100, 180, 170, 133, 72, 210, 117, 213, 37, 29, 35, 73, 210, 122, 35, 116, 147, 122, 73, 190, 149, 218, 173, 213, 61, 122, 107, 84, 34, 154, 78, 147, 214, 234, 159, 164, 238, 170, 253, 110, 191, 245, 247];

        let sps = super::sps::SeqParameterSet::from_bits(rbsp::BitReader::new(&sps[..])).expect("unexpected test data");
        let mut ctx = Context::default();
        ctx.put_seq_param_set(sps);
        match PicParameterSet::from_bits(&ctx, rbsp::BitReader::new(&pps[..])) {
            Err(e) => panic!("failed: {:?}", e),
            Ok(pps) => {
                println!("pps: {:#?}", pps);
            }
        }
    }
dholroyd commented 1 year ago

Many thanks for hunting down this bug and providing the test case!