Skip to content

Commit

Permalink
Check audio codec
Browse files Browse the repository at this point in the history
  • Loading branch information
j0sh committed Sep 6, 2024
1 parent 2721326 commit 6016b9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
7 changes: 4 additions & 3 deletions server/mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ func (s *LivepeerServer) HandlePush(w http.ResponseWriter, r *http.Request) {
cxn.mu.Lock()
if cxn.mediaFormat == (ffmpeg.MediaFormatInfo{}) {
cxn.mediaFormat = mediaFormat
} else if !videoCompatible(cxn.mediaFormat, mediaFormat) {
} else if !mediaCompatible(cxn.mediaFormat, mediaFormat) {
cxn.mediaFormat = mediaFormat
segPar.ForceSessionReinit = true
}
Expand Down Expand Up @@ -1650,8 +1650,9 @@ func getRemoteAddr(r *http.Request) string {
return strings.Split(addr, ":")[0]
}

func videoCompatible(a, b ffmpeg.MediaFormatInfo) bool {
return a.Vcodec == b.Vcodec &&
func mediaCompatible(a, b ffmpeg.MediaFormatInfo) bool {
return a.Acodec == b.Acodec &&
a.Vcodec == b.Vcodec &&
a.PixFormat == b.PixFormat &&
a.Width == b.Width &&
a.Height == b.Height
Expand Down
59 changes: 37 additions & 22 deletions server/mediaserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1494,16 +1494,17 @@ func TestJsonProfileToVideoProfiles(t *testing.T) {
assert.Equal("unable to parse the H264 encoder profile: unknown VideoProfile profile name", err.Error())
}

func TestVideoCompatible(t *testing.T) {
func TestMediaCompatible(t *testing.T) {
empty := ffmpeg.MediaFormatInfo{}
normal := ffmpeg.MediaFormatInfo{
Acodec: "aac",
Vcodec: "h264",
PixFormat: ffmpeg.PixelFormat{RawValue: ffmpeg.PixelFormatNV12},
Format: "mpegts",
Width: 100,
Height: 200,
DurSecs: 5,
Acodec: "aac",
Vcodec: "h264",
PixFormat: ffmpeg.PixelFormat{RawValue: ffmpeg.PixelFormatNV12},
Format: "mpegts",
Width: 100,
Height: 200,
AudioBitrate: 300,
DurSecs: 5,
}
tests := []struct {
name string
Expand All @@ -1519,19 +1520,21 @@ func TestVideoCompatible(t *testing.T) {
match: true,
a: normal,
b: ffmpeg.MediaFormatInfo{
Acodec: "opus",
Format: "mp4",
DurSecs: 10,
Vcodec: normal.Vcodec,
PixFormat: normal.PixFormat,
Width: normal.Width,
Height: normal.Height,
Format: "mp4",
DurSecs: 10,
AudioBitrate: 400,
Acodec: normal.Acodec,
Vcodec: normal.Vcodec,
PixFormat: normal.PixFormat,
Width: normal.Width,
Height: normal.Height,
},
}, {
name: "w",
a: normal,
b: ffmpeg.MediaFormatInfo{
Width: normal.Width + 1,
Acodec: normal.Acodec,
Vcodec: normal.Vcodec,
PixFormat: normal.PixFormat,
Height: normal.Height,
Expand All @@ -1540,36 +1543,48 @@ func TestVideoCompatible(t *testing.T) {
name: "h",
a: normal,
b: ffmpeg.MediaFormatInfo{
Width: normal.Width,
Height: normal.Height + 1,
Acodec: normal.Acodec,
Vcodec: normal.Vcodec,
PixFormat: normal.PixFormat,
Height: normal.Height + 1,
Width: normal.Width,
},
}, {
name: "pixfmt",
a: normal,
b: ffmpeg.MediaFormatInfo{
Width: normal.Width,
Acodec: normal.Acodec,
Vcodec: normal.Vcodec,
PixFormat: ffmpeg.PixelFormat{RawValue: ffmpeg.PixelFormatYUV420P},
Height: normal.Height,
},
}, {
name: "codec",
name: "video codec",
a: normal,
b: ffmpeg.MediaFormatInfo{
Width: normal.Width,
Vcodec: "flv",
Acodec: normal.Acodec,
Format: normal.Format,
DurSecs: normal.DurSecs,
Vcodec: "flv",
PixFormat: normal.PixFormat,
Width: normal.Width,
Height: normal.Height,
},
}, {
name: "audio codec",
a: normal,
b: ffmpeg.MediaFormatInfo{
Acodec: "opus",
Vcodec: normal.Vcodec,
Format: normal.Format,
PixFormat: normal.PixFormat,
Width: normal.Width,
Height: normal.Height,
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.match, videoCompatible(tt.a, tt.b))
assert.Equal(t, tt.match, mediaCompatible(tt.a, tt.b))
})
}
}
Expand Down

0 comments on commit 6016b9b

Please sign in to comment.