Skip to content

Commit

Permalink
fix support for LPCM tracks with no explicit channel count
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Dec 12, 2022
1 parent 2a5b3e3 commit 107d7b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
18 changes: 12 additions & 6 deletions track_lpcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func newTrackLPCMFromMediaDescription(
bitDepth = 24
}

tmp := strings.SplitN(clock, "/", 32)
if len(tmp) != 2 {
tmp := strings.SplitN(clock, "/", 2)
if len(tmp) < 1 {
return nil, fmt.Errorf("invalid clock (%v)", clock)
}

Expand All @@ -49,16 +49,22 @@ func newTrackLPCMFromMediaDescription(
return nil, err
}

channelCount, err := strconv.ParseInt(tmp[1], 10, 64)
if err != nil {
return nil, err
var channelCount int
if len(tmp) >= 2 {
tmp, err := strconv.ParseInt(tmp[1], 10, 64)
if err != nil {
return nil, err
}
channelCount = int(tmp)
} else {
channelCount = 1
}

return &TrackLPCM{
PayloadType: payloadType,
BitDepth: bitDepth,
SampleRate: int(sampleRate),
ChannelCount: int(channelCount),
ChannelCount: channelCount,
trackBase: trackBase{
control: control,
},
Expand Down
22 changes: 22 additions & 0 deletions track_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
ChannelCount: 2,
},
},
{
"lpcm 16 with no explicit channel",
&psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"97"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "97 L16/16000",
},
},
},
&TrackLPCM{
PayloadType: 97,
BitDepth: 16,
SampleRate: 16000,
ChannelCount: 1,
},
},
{
"lpcm 24",
&psdp.MediaDescription{
Expand Down

0 comments on commit 107d7b6

Please sign in to comment.