mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Move to new Track API
See v2.0.0 Release Notes[0] for all changes Resolves #405 [0] https://github.com/pions/webrtc/wiki/v2.0.0-Release-Notes#media-api
This commit is contained in:
@@ -23,7 +23,7 @@ func init() {
|
||||
// Pipeline is a wrapper for a GStreamer Pipeline
|
||||
type Pipeline struct {
|
||||
Pipeline *C.GstElement
|
||||
in chan<- media.Sample
|
||||
track *webrtc.Track
|
||||
// stop acts as a signal that this pipeline is stopped
|
||||
// any pending sends to Pipeline.in should be cancelled
|
||||
stop chan interface{}
|
||||
@@ -35,7 +35,7 @@ var pipelines = make(map[int]*Pipeline)
|
||||
var pipelinesLock sync.Mutex
|
||||
|
||||
// CreatePipeline creates a GStreamer Pipeline
|
||||
func CreatePipeline(codecName string, in chan<- media.Sample, pipelineSrc string) *Pipeline {
|
||||
func CreatePipeline(codecName string, track *webrtc.Track, pipelineSrc string) *Pipeline {
|
||||
pipelineStr := "appsink name=appsink"
|
||||
switch codecName {
|
||||
case webrtc.VP8:
|
||||
@@ -60,7 +60,7 @@ func CreatePipeline(codecName string, in chan<- media.Sample, pipelineSrc string
|
||||
|
||||
pipeline := &Pipeline{
|
||||
Pipeline: C.gstreamer_send_create_pipeline(pipelineStrUnsafe),
|
||||
in: in,
|
||||
track: track,
|
||||
id: len(pipelines),
|
||||
codecName: codecName,
|
||||
}
|
||||
@@ -105,9 +105,8 @@ func goHandlePipelineBuffer(buffer unsafe.Pointer, bufferLen C.int, duration C.i
|
||||
}
|
||||
// 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.
|
||||
select {
|
||||
case pipeline.in <- media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}:
|
||||
case <-pipeline.stop:
|
||||
if err := pipeline.track.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))
|
||||
|
Reference in New Issue
Block a user