Skip to content

Commit 68fa422

Browse files
committedJul 26, 2024
Fix PCM audio from Hikvision cameras
1 parent c5bc761 commit 68fa422

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
 

‎pkg/core/codec.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ func UnmarshalCodec(md *sdp.MediaDescription, payloadType string) *Codec {
157157
}
158158
}
159159

160-
if c.Name == "" {
160+
switch c.Name {
161+
case "PCM":
162+
// https://www.reddit.com/r/Hikvision/comments/17elxex/comment/k642g2r/
163+
// check pkg/rtsp/rtsp_test.go TestHikvisionPCM
164+
c.Name = CodecPCML
165+
case "":
161166
// https://en.wikipedia.org/wiki/RTP_payload_formats
162167
switch payloadType {
163168
case "0":

‎pkg/rtsp/rtsp_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rtsp
33
import (
44
"testing"
55

6+
"github.com/AlexxIT/go2rtc/pkg/core"
67
"github.com/stretchr/testify/assert"
78
)
89

@@ -159,3 +160,34 @@ a=control:trackID=2
159160
assert.Equal(t, "recvonly", medias[0].Direction)
160161
assert.Equal(t, "recvonly", medias[1].Direction)
161162
}
163+
164+
func TestHikvisionPCM(t *testing.T) {
165+
s := `v=0
166+
o=- 1721969533379665 1721969533379665 IN IP4 192.168.1.12
167+
s=Media Presentation
168+
e=NONE
169+
b=AS:5100
170+
t=0 0
171+
a=control:rtsp://192.168.1.12:554/Streaming/channels/101/
172+
m=video 0 RTP/AVP 96
173+
c=IN IP4 0.0.0.0
174+
b=AS:5000
175+
a=recvonly
176+
a=x-dimensions:3200,1800
177+
a=control:rtsp://192.168.1.12:554/Streaming/channels/101/trackID=1
178+
a=rtpmap:96 H264/90000
179+
a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z2QAM6wVFKAyAOP5f/AAEAAWyAAAH0AAB1MAIA==,aO48sA==
180+
m=audio 0 RTP/AVP 11
181+
c=IN IP4 0.0.0.0
182+
b=AS:50
183+
a=recvonly
184+
a=control:rtsp://192.168.1.12:554/Streaming/channels/101/trackID=2
185+
a=rtpmap:11 PCM/48000
186+
a=Media_header:MEDIAINFO=494D4B4801030000040000010170011080BB0000007D000000000000000000000000000000000000;
187+
a=appversion:1.0
188+
`
189+
medias, err := UnmarshalSDP([]byte(s))
190+
assert.Nil(t, err)
191+
assert.Len(t, medias, 2)
192+
assert.Equal(t, core.CodecPCML, medias[1].Codecs[0].Name)
193+
}

0 commit comments

Comments
 (0)