Skip to content

Commit 366f9ec

Browse files
committed
Implement sample count generation in gstreamer-send
Audio+Video now works in gstreamer-send
1 parent a5cf170 commit 366f9ec

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

examples/gstreamer-receive/gst/gst.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ GstElement *gstreamer_recieve_create_pipeline(char *pipeline) {
4343
}
4444

4545
void gstreamer_recieve_start_pipeline(GstElement *pipeline) {
46-
GstBus *bus;
47-
guint bus_watch_id;
48-
49-
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
50-
bus_watch_id = gst_bus_add_watch(bus, gstreamer_recieve_bus_call, NULL);
46+
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
47+
gst_bus_add_watch(bus, gstreamer_recieve_bus_call, NULL);
5148
gst_object_unref(bus);
5249

5350
gst_element_set_state(pipeline, GST_STATE_PLAYING);

examples/gstreamer-send/gst/gst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ GstFlowReturn gstreamer_send_new_sample_handler(GstElement *object, gpointer use
5252
buffer = gst_sample_get_buffer(sample);
5353
if (buffer) {
5454
gst_buffer_extract_dup(buffer, 0, gst_buffer_get_size(buffer), &copy, &copy_size);
55-
goHandlePipelineBuffer(copy, copy_size, 0, s->pipelineId);
55+
goHandlePipelineBuffer(copy, copy_size, GST_BUFFER_DURATION(buffer), s->pipelineId);
5656
}
5757
gst_sample_unref (sample);
5858
}

examples/gstreamer-send/gst/gst.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Pipeline struct {
2424
Pipeline *C.GstElement
2525
in chan<- webrtc.RTCSample
2626
id int
27+
codec webrtc.TrackType
2728
}
2829

2930
var pipelines = make(map[int]*Pipeline)
@@ -53,6 +54,7 @@ func CreatePipeline(codec webrtc.TrackType, in chan<- webrtc.RTCSample) *Pipelin
5354
Pipeline: C.gstreamer_send_create_pipeline(pipelineStrUnsafe),
5455
in: in,
5556
id: len(pipelines),
57+
codec: codec,
5658
}
5759

5860
pipelines[pipeline.id] = pipeline
@@ -69,13 +71,24 @@ func (p *Pipeline) Stop() {
6971
C.gstreamer_send_stop_pipeline(p.Pipeline)
7072
}
7173

74+
const (
75+
videoClockRate = 90000
76+
audioClockRate = 48000
77+
)
78+
7279
//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) {
7481
pipelinesLock.Lock()
7582
defer pipelinesLock.Unlock()
7683

7784
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}
7992
} else {
8093
fmt.Printf("discarding buffer, no pipeline with id %d", int(pipelineId))
8194
}

0 commit comments

Comments
 (0)