Commit bd3408a8 authored by Marijn Suijten's avatar Marijn Suijten 🦀
Browse files

Replace adapter with in-line sink pull

parent 7aaeab64
......@@ -39,33 +39,11 @@ static void app_sink_eos(GstAppSink *appsink, gpointer userdata) {
pa_log_debug("Sink got EOS");
}
/* Called from the GStreamer streaming thread */
static GstFlowReturn app_sink_new_sample(GstAppSink *appsink, gpointer userdata) {
struct gst_info *info = (struct gst_info *) userdata;
GstSample *sample = NULL;
GstBuffer *buf;
// pa_log_debug("%s thread %p", __func__, pa_thread_mq_get());
sample = gst_app_sink_pull_sample(GST_APP_SINK(info->app_sink));
if (!sample)
return GST_FLOW_OK;
buf = gst_sample_get_buffer(sample);
gst_buffer_ref(buf);
gst_adapter_push(info->sink_adapter, buf);
gst_sample_unref(sample);
return GST_FLOW_OK;
}
static void gst_deinit_common(struct gst_info *info) {
if (!info)
return;
if (info->app_sink)
gst_object_unref(info->app_sink);
if (info->sink_adapter)
g_object_unref(info->sink_adapter);
if (info->pipeline)
gst_object_unref(info->pipeline);
}
......@@ -84,7 +62,6 @@ bool gst_init_common(struct gst_info *info) {
g_object_set(appsink, "sync", FALSE, "async", FALSE, "enable-last-sample", FALSE, NULL);
callbacks.eos = app_sink_eos;
callbacks.new_sample = app_sink_new_sample;
gst_app_sink_set_callbacks(GST_APP_SINK(appsink), &callbacks, info, NULL);
adapter = gst_adapter_new();
......@@ -94,7 +71,6 @@ bool gst_init_common(struct gst_info *info) {
pa_assert(pipeline);
info->app_sink = appsink;
info->sink_adapter = adapter;
info->pipeline = pipeline;
return true;
......@@ -215,11 +191,12 @@ common_fail:
size_t gst_transcode_buffer(void *codec_info, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed) {
struct gst_info *info = (struct gst_info *) codec_info;
gsize available, transcoded;
gsize transcoded;
GstBuffer *in_buf;
GstFlowReturn ret;
size_t written = 0;
GstPad *in_pad;
GstSample *sample;
// pa_log_debug("%s thread %p", __func__, pa_thread_mq_get());
......@@ -242,13 +219,22 @@ size_t gst_transcode_buffer(void *codec_info, const uint8_t *input_buffer, size_
goto fail;
}
available = gst_adapter_available(info->sink_adapter);
// TODO: This might block! Can use try_pull_sample!
// sample = gst_app_sink_pull_sample(GST_APP_SINK(info->enc_sink));
sample = gst_app_sink_try_pull_sample(GST_APP_SINK(info->app_sink), 0);
if (sample) {
in_buf = gst_sample_get_buffer(sample);
if (available) {
transcoded = PA_MIN(available, output_size);
transcoded = gst_buffer_get_size(in_buf);
pa_assert(transcoded <= output_size);
gst_adapter_copy(info->sink_adapter, output_buffer, 0, transcoded);
gst_adapter_flush(info->sink_adapter, transcoded);
// transcoded = PA_MIN(gst_buffer_get_size(in_buf), output_size);
GstMapInfo map_info;
pa_assert_se(gst_buffer_map(in_buf, &map_info, GST_MAP_READ));
memcpy(output_buffer, map_info.data, output_size);
gst_buffer_unmap(in_buf, &map_info);
written += transcoded;
} else
......@@ -272,8 +258,5 @@ void gst_codec_deinit(void *codec_info) {
gst_object_unref(info->pipeline);
}
if (info->sink_adapter)
g_object_unref(info->sink_adapter);
pa_xfree(info);
}
......@@ -45,7 +45,6 @@ struct gst_info {
GstElement *app_sink;
GstElement *pipeline;
GstAdapter *sink_adapter;
uint16_t seq_num;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment