diff --git a/pkg/pipeline/builder/segment.go b/pkg/pipeline/builder/segment.go index db1e3997..8370a7a8 100644 --- a/pkg/pipeline/builder/segment.go +++ b/pkg/pipeline/builder/segment.go @@ -36,9 +36,17 @@ func BuildSegmentBin(pipeline *gstreamer.Pipeline, p *config.PipelineConfig) (*g b := pipeline.NewBin("segment") o := p.GetSegmentConfig() - h264parse, err := gst.NewElement("h264parse") - if err != nil { - return nil, err + var h264parse *gst.Element + var err error + if p.VideoEnabled { + h264parse, err = gst.NewElement("h264parse") + if err != nil { + return nil, err + } + + if err = b.AddElements(h264parse); err != nil { + return nil, errors.ErrGstPipelineError(err) + } } sink, err := gst.NewElement("splitmuxsink") @@ -91,15 +99,18 @@ func BuildSegmentBin(pipeline *gstreamer.Pipeline, p *config.PipelineConfig) (*g return nil, errors.ErrGstPipelineError(err) } - if err = b.AddElements(h264parse, sink); err != nil { + if err = b.AddElements(sink); err != nil { return nil, errors.ErrGstPipelineError(err) } b.SetGetSrcPad(func(name string) *gst.Pad { if name == "audio" { return sink.GetRequestPad("audio_%u") - } else { + } else if h264parse != nil { return h264parse.GetStaticPad("sink") + } else { + // Should never happen + return nil } }) diff --git a/test/room_composite.go b/test/room_composite.go index 00e6ed2c..35e6b937 100644 --- a/test/room_composite.go +++ b/test/room_composite.go @@ -193,52 +193,63 @@ func (r *Runner) testRoomCompositeSegments(t *testing.T) { } r.runRoomTest(t, "RoomComposite/Segments", types.MimeTypeOpus, types.MimeTypeVP8, func(t *testing.T) { - test := &testCase{ - options: &livekit.EncodingOptions{ - AudioCodec: livekit.AudioCodec_AAC, - VideoCodec: livekit.VideoCodec_H264_BASELINE, - Width: 1920, - Height: 1080, - VideoBitrate: 4500, + for _, test := range []*testCase{ + &testCase{ + options: &livekit.EncodingOptions{ + AudioCodec: livekit.AudioCodec_AAC, + VideoCodec: livekit.VideoCodec_H264_BASELINE, + Width: 1920, + Height: 1080, + VideoBitrate: 4500, + }, + filename: "r_{room_name}_{time}", + playlist: "r_{room_name}_{time}.m3u8", + filenameSuffix: livekit.SegmentedFileSuffix_TIMESTAMP, + expectVideoTranscoding: true, }, - filename: "r_{room_name}_{time}", - playlist: "r_{room_name}_{time}.m3u8", - filenameSuffix: livekit.SegmentedFileSuffix_TIMESTAMP, - expectVideoTranscoding: true, - } + &testCase{ + options: &livekit.EncodingOptions{ + AudioCodec: livekit.AudioCodec_AAC, + }, + filename: "r_{room_name}_audio_{time}", + playlist: "r_{room_name}_audio_{time}.m3u8", + filenameSuffix: livekit.SegmentedFileSuffix_TIMESTAMP, + audioOnly: true, + }, + } { + segmentOutput := &livekit.SegmentedFileOutput{ + FilenamePrefix: r.getFilePath(test.filename), + PlaylistName: test.playlist, + FilenameSuffix: test.filenameSuffix, + } + if test.filenameSuffix == livekit.SegmentedFileSuffix_INDEX && r.GCPUpload != nil { + segmentOutput.FilenamePrefix = test.filename + segmentOutput.Output = &livekit.SegmentedFileOutput_Gcp{ + Gcp: r.GCPUpload, + } + } - segmentOutput := &livekit.SegmentedFileOutput{ - FilenamePrefix: r.getFilePath(test.filename), - PlaylistName: test.playlist, - FilenameSuffix: test.filenameSuffix, - } - if test.filenameSuffix == livekit.SegmentedFileSuffix_INDEX && r.GCPUpload != nil { - segmentOutput.FilenamePrefix = test.filename - segmentOutput.Output = &livekit.SegmentedFileOutput_Gcp{ - Gcp: r.GCPUpload, + room := &livekit.RoomCompositeEgressRequest{ + RoomName: r.RoomName, + Layout: "grid-dark", + AudioOnly: test.audioOnly, + SegmentOutputs: []*livekit.SegmentedFileOutput{segmentOutput}, + } + if test.options != nil { + room.Options = &livekit.RoomCompositeEgressRequest_Advanced{ + Advanced: test.options, + } } - } - room := &livekit.RoomCompositeEgressRequest{ - RoomName: r.RoomName, - Layout: "grid-dark", - AudioOnly: test.audioOnly, - SegmentOutputs: []*livekit.SegmentedFileOutput{segmentOutput}, - } - if test.options != nil { - room.Options = &livekit.RoomCompositeEgressRequest_Advanced{ - Advanced: test.options, + req := &rpc.StartEgressRequest{ + EgressId: utils.NewGuid(utils.EgressPrefix), + Request: &rpc.StartEgressRequest_RoomComposite{ + RoomComposite: room, + }, } - } - req := &rpc.StartEgressRequest{ - EgressId: utils.NewGuid(utils.EgressPrefix), - Request: &rpc.StartEgressRequest_RoomComposite{ - RoomComposite: room, - }, + r.runSegmentsTest(t, req, test) } - - r.runSegmentsTest(t, req, test) }) } diff --git a/test/segments.go b/test/segments.go index 2ec0b024..754c8271 100644 --- a/test/segments.go +++ b/test/segments.go @@ -48,7 +48,9 @@ func (r *Runner) runSegmentsTest(t *testing.T, req *rpc.StartEgressRequest, test p, err := config.GetValidatedPipelineConfig(r.ServiceConfig, req) require.NoError(t, err) - require.Equal(t, test.expectVideoTranscoding, p.VideoTranscoding) + if !test.audioOnly { + require.Equal(t, test.expectVideoTranscoding, p.VideoTranscoding) + } r.verifySegments(t, p, test.filenameSuffix, res) } diff --git a/test/track_composite.go b/test/track_composite.go index 09e945f9..8843bbbe 100644 --- a/test/track_composite.go +++ b/test/track_composite.go @@ -166,6 +166,13 @@ func (r *Runner) testTrackCompositeSegments(t *testing.T) { filename: "tcs_{room_name}_h264_{time}", playlist: "tcs_{room_name}_h264_{time}.m3u8", }, + { + name: "Audio Only", + audioCodec: types.MimeTypeOpus, + filename: "tcs_{room_name}_audio_{time}", + playlist: "tcs_{room_name}_audio_{time}.m3u8", + audioOnly: true, + }, } { r.runTrackTest(t, test.name, test.audioCodec, test.videoCodec, func(t *testing.T, audioTrackID, videoTrackID string) {