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

Fix output bin for audio only segmented output #493

Merged
merged 2 commits into from
Sep 15, 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
21 changes: 16 additions & 5 deletions pkg/pipeline/builder/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
})

Expand Down
89 changes: 50 additions & 39 deletions test/room_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
4 changes: 3 additions & 1 deletion test/segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions test/track_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down