Skip to content

Commit

Permalink
gstreamer-src/Pipeline accepts multiple tracks
Browse files Browse the repository at this point in the history
This allows us to demonstrate multi-track easier, without having to
worry about encoding multiple times

Relates to #54
  • Loading branch information
Sean-Der committed Mar 13, 2019
1 parent 08a93d8 commit dcef86c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/gstreamer-send-offer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func main() {
}

// Start pushing buffers on these tracks
gst.CreatePipeline(webrtc.Opus, opusTrack, *audioSrc).Start()
gst.CreatePipeline(webrtc.VP8, vp8Track, *videoSrc).Start()
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, *audioSrc).Start()
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, *videoSrc).Start()

// Block forever
select {}
Expand Down
4 changes: 2 additions & 2 deletions examples/gstreamer-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func main() {
fmt.Println(signal.Encode(answer))

// Start pushing buffers on these tracks
gst.CreatePipeline(webrtc.Opus, opusTrack, *audioSrc).Start()
gst.CreatePipeline(webrtc.VP8, vp8Track, *videoSrc).Start()
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, *audioSrc).Start()
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, *videoSrc).Start()

// Block forever
select {}
Expand Down
14 changes: 7 additions & 7 deletions examples/internal/gstreamer-src/gst.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
// Pipeline is a wrapper for a GStreamer Pipeline
type Pipeline struct {
Pipeline *C.GstElement
track *webrtc.Track
tracks []*webrtc.Track
// stop acts as a signal that this pipeline is stopped
// any pending sends to Pipeline.in should be cancelled
stop chan interface{}
Expand All @@ -35,7 +35,7 @@ var pipelines = make(map[int]*Pipeline)
var pipelinesLock sync.Mutex

// CreatePipeline creates a GStreamer Pipeline
func CreatePipeline(codecName string, track *webrtc.Track, pipelineSrc string) *Pipeline {
func CreatePipeline(codecName string, tracks []*webrtc.Track, pipelineSrc string) *Pipeline {
pipelineStr := "appsink name=appsink"
switch codecName {
case webrtc.VP8:
Expand All @@ -60,7 +60,7 @@ func CreatePipeline(codecName string, track *webrtc.Track, pipelineSrc string) *

pipeline := &Pipeline{
Pipeline: C.gstreamer_send_create_pipeline(pipelineStrUnsafe),
track: track,
tracks: tracks,
id: len(pipelines),
codecName: codecName,
}
Expand Down Expand Up @@ -103,10 +103,10 @@ func goHandlePipelineBuffer(buffer unsafe.Pointer, bufferLen C.int, duration C.i
} else {
samples = uint32(videoClockRate * (float32(duration) / 1000000000))
}
// We need to be able to cancel this function even f pipeline.in isn't being serviced
// When pipeline.stop is closed the sending of data will be cancelled.
if err := pipeline.track.WriteSample(media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}); err != nil {
panic(err)
for _, t := range pipeline.tracks {
if err := t.WriteSample(media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}); err != nil {
panic(err)
}
}
} else {
fmt.Printf("discarding buffer, no pipeline with id %d", int(pipelineID))
Expand Down
4 changes: 2 additions & 2 deletions examples/janus-gateway/video-room/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func main() {
}

// Start pushing buffers on these tracks
gst.CreatePipeline(webrtc.Opus, opusTrack, "audiotestsrc").Start()
gst.CreatePipeline(webrtc.VP8, vp8Track, "videotestsrc").Start()
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, "audiotestsrc").Start()
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, "videotestsrc").Start()
}

select {}
Expand Down

0 comments on commit dcef86c

Please sign in to comment.