@@ -24,6 +24,7 @@ type Pipeline struct {
24
24
Pipeline * C.GstElement
25
25
in chan <- webrtc.RTCSample
26
26
id int
27
+ codec webrtc.TrackType
27
28
}
28
29
29
30
var pipelines = make (map [int ]* Pipeline )
@@ -53,6 +54,7 @@ func CreatePipeline(codec webrtc.TrackType, in chan<- webrtc.RTCSample) *Pipelin
53
54
Pipeline : C .gstreamer_send_create_pipeline (pipelineStrUnsafe ),
54
55
in : in ,
55
56
id : len (pipelines ),
57
+ codec : codec ,
56
58
}
57
59
58
60
pipelines [pipeline .id ] = pipeline
@@ -69,13 +71,24 @@ func (p *Pipeline) Stop() {
69
71
C .gstreamer_send_stop_pipeline (p .Pipeline )
70
72
}
71
73
74
+ const (
75
+ videoClockRate = 90000
76
+ audioClockRate = 48000
77
+ )
78
+
72
79
//export goHandlePipelineBuffer
73
- func goHandlePipelineBuffer (buffer unsafe.Pointer , bufferLen C.int , samples C.int , pipelineId C.int ) {
80
+ func goHandlePipelineBuffer (buffer unsafe.Pointer , bufferLen C.int , duration C.int , pipelineId C.int ) {
74
81
pipelinesLock .Lock ()
75
82
defer pipelinesLock .Unlock ()
76
83
77
84
if pipeline , ok := pipelines [int (pipelineId )]; ok {
78
- pipeline .in <- webrtc.RTCSample {C .GoBytes (buffer , bufferLen ), uint32 (samples )}
85
+ var samples uint32
86
+ if pipeline .codec == webrtc .Opus {
87
+ samples = uint32 (audioClockRate * (float32 (duration ) / 1000000000 ))
88
+ } else {
89
+ samples = uint32 (videoClockRate * (float32 (duration ) / 1000000000 ))
90
+ }
91
+ pipeline .in <- webrtc.RTCSample {C .GoBytes (buffer , bufferLen ), samples }
79
92
} else {
80
93
fmt .Printf ("discarding buffer, no pipeline with id %d" , int (pipelineId ))
81
94
}
0 commit comments