mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 23:26:58 +08:00
Rewrite gstreamer-src/Pipeline for multi-track
This allows us to demonstrate multi-track easier, without having to worry about encoding multiple times Relates to #54
This commit is contained in:
@@ -85,8 +85,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start pushing buffers on these tracks
|
// Start pushing buffers on these tracks
|
||||||
gst.CreatePipeline(webrtc.Opus, opusTrack, *audioSrc).Start()
|
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, *audioSrc).Start()
|
||||||
gst.CreatePipeline(webrtc.VP8, vp8Track, *videoSrc).Start()
|
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, *videoSrc).Start()
|
||||||
|
|
||||||
// Block forever
|
// Block forever
|
||||||
select {}
|
select {}
|
||||||
|
@@ -85,8 +85,8 @@ func main() {
|
|||||||
fmt.Println(signal.Encode(answer))
|
fmt.Println(signal.Encode(answer))
|
||||||
|
|
||||||
// Start pushing buffers on these tracks
|
// Start pushing buffers on these tracks
|
||||||
gst.CreatePipeline(webrtc.Opus, opusTrack, *audioSrc).Start()
|
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, *audioSrc).Start()
|
||||||
gst.CreatePipeline(webrtc.VP8, vp8Track, *videoSrc).Start()
|
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, *videoSrc).Start()
|
||||||
|
|
||||||
// Block forever
|
// Block forever
|
||||||
select {}
|
select {}
|
||||||
|
@@ -23,7 +23,7 @@ func init() {
|
|||||||
// Pipeline is a wrapper for a GStreamer Pipeline
|
// Pipeline is a wrapper for a GStreamer Pipeline
|
||||||
type Pipeline struct {
|
type Pipeline struct {
|
||||||
Pipeline *C.GstElement
|
Pipeline *C.GstElement
|
||||||
track *webrtc.Track
|
tracks []*webrtc.Track
|
||||||
id int
|
id int
|
||||||
codecName string
|
codecName string
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ var pipelines = make(map[int]*Pipeline)
|
|||||||
var pipelinesLock sync.Mutex
|
var pipelinesLock sync.Mutex
|
||||||
|
|
||||||
// CreatePipeline creates a GStreamer Pipeline
|
// 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"
|
pipelineStr := "appsink name=appsink"
|
||||||
switch codecName {
|
switch codecName {
|
||||||
case webrtc.VP8:
|
case webrtc.VP8:
|
||||||
@@ -57,7 +57,7 @@ func CreatePipeline(codecName string, track *webrtc.Track, pipelineSrc string) *
|
|||||||
|
|
||||||
pipeline := &Pipeline{
|
pipeline := &Pipeline{
|
||||||
Pipeline: C.gstreamer_send_create_pipeline(pipelineStrUnsafe),
|
Pipeline: C.gstreamer_send_create_pipeline(pipelineStrUnsafe),
|
||||||
track: track,
|
tracks: tracks,
|
||||||
id: len(pipelines),
|
id: len(pipelines),
|
||||||
codecName: codecName,
|
codecName: codecName,
|
||||||
}
|
}
|
||||||
@@ -94,9 +94,11 @@ func goHandlePipelineBuffer(buffer unsafe.Pointer, bufferLen C.int, duration C.i
|
|||||||
} else {
|
} else {
|
||||||
samples = uint32(videoClockRate * (float32(duration) / 1000000000))
|
samples = uint32(videoClockRate * (float32(duration) / 1000000000))
|
||||||
}
|
}
|
||||||
if err := pipeline.track.WriteSample(media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}); err != nil {
|
for _, t := range pipeline.tracks {
|
||||||
|
if err := t.WriteSample(media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("discarding buffer, no pipeline with id %d", int(pipelineID))
|
fmt.Printf("discarding buffer, no pipeline with id %d", int(pipelineID))
|
||||||
}
|
}
|
||||||
|
@@ -146,8 +146,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start pushing buffers on these tracks
|
// Start pushing buffers on these tracks
|
||||||
gst.CreatePipeline(webrtc.Opus, opusTrack, "audiotestsrc").Start()
|
gst.CreatePipeline(webrtc.Opus, []*webrtc.Track{opusTrack}, "audiotestsrc").Start()
|
||||||
gst.CreatePipeline(webrtc.VP8, vp8Track, "videotestsrc").Start()
|
gst.CreatePipeline(webrtc.VP8, []*webrtc.Track{vp8Track}, "videotestsrc").Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
|
Reference in New Issue
Block a user