Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h265: fix DTS extraction of streams with short_term_ref_pic_set_sps_flag=1 #95

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions pkg/codecs/h265/dts_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"fmt"
"math"
"time"

"github.com/bluenviron/mediacommon/pkg/bits"
Expand Down Expand Up @@ -78,14 +79,31 @@
return 0, err
}

if shortTermRefPicSetSpsFlag {
return 0, fmt.Errorf("short_term_ref_pic_set_sps_flag = true is not supported")
}
var rps *SPS_ShortTermRefPicSet

var rps SPS_ShortTermRefPicSet
err = rps.unmarshal(buf, &pos, uint32(len(sps.ShortTermRefPicSets)), uint32(len(sps.ShortTermRefPicSets)), nil)
if err != nil {
return 0, err
if !shortTermRefPicSetSpsFlag {
rps = &SPS_ShortTermRefPicSet{}
err = rps.unmarshal(buf, &pos, uint32(len(sps.ShortTermRefPicSets)), uint32(len(sps.ShortTermRefPicSets)), nil)
if err != nil {
return 0, err
}
} else {
if len(sps.ShortTermRefPicSets) == 0 {
return 0, fmt.Errorf("invalid short_term_ref_pic_set_idx")
}

b := int(math.Ceil(math.Log2(float64(len(sps.ShortTermRefPicSets)))))
tmp, err := bits.ReadBits(buf, &pos, b)
if err != nil {
return 0, err
}

Check warning on line 99 in pkg/codecs/h265/dts_extractor.go

View check run for this annotation

Codecov / codecov/patch

pkg/codecs/h265/dts_extractor.go#L98-L99

Added lines #L98 - L99 were not covered by tests
shortTermRefPicSetIdx := int(tmp)

if len(sps.ShortTermRefPicSets) <= shortTermRefPicSetIdx {
return 0, fmt.Errorf("invalid short_term_ref_pic_set_idx")
}

Check warning on line 104 in pkg/codecs/h265/dts_extractor.go

View check run for this annotation

Codecov / codecov/patch

pkg/codecs/h265/dts_extractor.go#L103-L104

Added lines #L103 - L104 were not covered by tests

rps = sps.ShortTermRefPicSets[shortTermRefPicSetIdx]
}

var v uint32
Expand Down
55 changes: 55 additions & 0 deletions pkg/codecs/h265/dts_extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,61 @@ func TestDTSExtractor(t *testing.T) {
},
},
},
{
"short_term_ref_pic_set_sps_flag",
[]sequenceSample{
{
[][]byte{
{ // VPS
0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x01, 0x40,
0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x03,
0x00, 0x00, 0x03, 0x00, 0x99, 0xa5, 0x02, 0x40,
},
{ // SPS
0x42, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0x03,
0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x99, 0xa0, 0x03, 0xc0, 0x80, 0x10, 0xe5,
0x8d, 0xa5, 0x92, 0x42, 0x36, 0x22, 0xec, 0xb8,
0x80, 0x40, 0x00, 0x00, 0x03, 0x00, 0x40, 0x00,
0x00, 0x05, 0x0f, 0xe2, 0xc4, 0xa0,
},
{ // PPS
0x44, 0x01, 0xc0, 0xe0, 0x98, 0x93, 0x03, 0x05,
0x14, 0x90,
},
{ // IDR
0x26, 0x01, 0xaf, 0x3e, 0x3d, 0x3a, 0xca, 0xc0,
0xf2, 0x2f, 0xc3, 0x0f, 0x86, 0x9f, 0xed, 0xfc,
0x67, 0x2f, 0x62, 0x69,
},
},
1113436 * time.Nanosecond,
-48886564 * time.Nanosecond,
},
{
[][]byte{
{ // TRAIL_R
0x02, 0x02, 0xd0, 0x00, 0x0c, 0xc6, 0x27, 0xfe,
0x6e, 0x6d, 0xe8, 0x10, 0xd5, 0xce, 0x61, 0x1b,
0x66, 0xf6, 0x21, 0x59,
},
},
68113436 * time.Nanosecond,
18113436 * time.Nanosecond,
},
{
[][]byte{
{ // TRAIL_R
0x02, 0x02, 0xd0, 0x00, 0x14, 0xc6, 0x7c, 0xfe,
0x83, 0x29, 0x34, 0xba, 0xce, 0xaa, 0x8b, 0x76,
0xb0, 0x95, 0x67, 0xb2,
},
},
101113436 * time.Nanosecond,
51113436 * time.Nanosecond,
},
},
},
} {
t.Run(ca.name, func(t *testing.T) {
ex := NewDTSExtractor()
Expand Down
Loading