mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
interaudio: Fix timestamp, latency and period handling
This commit is contained in:
parent
8c5a8c76f6
commit
04dbd095a1
2 changed files with 31 additions and 27 deletions
|
@ -47,6 +47,9 @@
|
||||||
#include "gstinteraudiosink.h"
|
#include "gstinteraudiosink.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define PERIOD 1600
|
||||||
|
#define N_PERIODS 10
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_inter_audio_sink_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_inter_audio_sink_debug_category);
|
||||||
#define GST_CAT_DEFAULT gst_inter_audio_sink_debug_category
|
#define GST_CAT_DEFAULT gst_inter_audio_sink_debug_category
|
||||||
|
|
||||||
|
@ -253,11 +256,11 @@ gst_inter_audio_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||||
|
|
||||||
g_mutex_lock (&interaudiosink->surface->mutex);
|
g_mutex_lock (&interaudiosink->surface->mutex);
|
||||||
n = gst_adapter_available (interaudiosink->surface->audio_adapter) / 4;
|
n = gst_adapter_available (interaudiosink->surface->audio_adapter) / 4;
|
||||||
#define SIZE 1600
|
while (n > PERIOD * N_PERIODS) {
|
||||||
if (n > SIZE * 3) {
|
GST_WARNING_OBJECT (interaudiosink, "flushing %d samples", PERIOD / 2);
|
||||||
GST_WARNING_OBJECT (interaudiosink, "flushing %d samples", SIZE / 2);
|
|
||||||
gst_adapter_flush (interaudiosink->surface->audio_adapter,
|
gst_adapter_flush (interaudiosink->surface->audio_adapter,
|
||||||
(SIZE / 2) * bpf);
|
(PERIOD / 2) * bpf);
|
||||||
|
n -= (PERIOD / 2);
|
||||||
}
|
}
|
||||||
gst_adapter_push (interaudiosink->surface->audio_adapter,
|
gst_adapter_push (interaudiosink->surface->audio_adapter,
|
||||||
gst_buffer_ref (buffer));
|
gst_buffer_ref (buffer));
|
||||||
|
|
|
@ -50,6 +50,9 @@
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_inter_audio_src_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_inter_audio_src_debug_category);
|
||||||
#define GST_CAT_DEFAULT gst_inter_audio_src_debug_category
|
#define GST_CAT_DEFAULT gst_inter_audio_src_debug_category
|
||||||
|
|
||||||
|
#define PERIOD 1600
|
||||||
|
#define N_PERIODS 10
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static void gst_inter_audio_src_set_property (GObject * object,
|
static void gst_inter_audio_src_set_property (GObject * object,
|
||||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
||||||
|
@ -281,8 +284,6 @@ gst_inter_audio_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SIZE 1600
|
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
||||||
GstBuffer ** buf)
|
GstBuffer ** buf)
|
||||||
|
@ -302,7 +303,7 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
||||||
if (!gst_audio_info_is_equal (&interaudiosrc->surface->audio_info,
|
if (!gst_audio_info_is_equal (&interaudiosrc->surface->audio_info,
|
||||||
&interaudiosrc->info)) {
|
&interaudiosrc->info)) {
|
||||||
caps = gst_audio_info_to_caps (&interaudiosrc->surface->audio_info);
|
caps = gst_audio_info_to_caps (&interaudiosrc->surface->audio_info);
|
||||||
interaudiosrc->timestamp_offset =
|
interaudiosrc->timestamp_offset +=
|
||||||
gst_util_uint64_scale_int (interaudiosrc->n_samples, GST_SECOND,
|
gst_util_uint64_scale_int (interaudiosrc->n_samples, GST_SECOND,
|
||||||
interaudiosrc->info.rate);
|
interaudiosrc->info.rate);
|
||||||
interaudiosrc->n_samples = 0;
|
interaudiosrc->n_samples = 0;
|
||||||
|
@ -311,16 +312,19 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
||||||
|
|
||||||
bpf = interaudiosrc->surface->audio_info.bpf;
|
bpf = interaudiosrc->surface->audio_info.bpf;
|
||||||
|
|
||||||
n = bpf >
|
if (bpf > 0)
|
||||||
0 ? gst_adapter_available (interaudiosrc->surface->audio_adapter) /
|
n = gst_adapter_available (interaudiosrc->surface->audio_adapter) / bpf;
|
||||||
bpf : 0;
|
else
|
||||||
if (n > SIZE * 3) {
|
n = 0;
|
||||||
GST_WARNING_OBJECT (interaudiosrc, "flushing %d samples", SIZE / 2);
|
|
||||||
gst_adapter_flush (interaudiosrc->surface->audio_adapter, (SIZE / 2) * bpf);
|
while (n > PERIOD * 10) {
|
||||||
n -= (SIZE / 2);
|
GST_WARNING_OBJECT (interaudiosrc, "flushing %d samples", PERIOD / 2);
|
||||||
|
gst_adapter_flush (interaudiosrc->surface->audio_adapter,
|
||||||
|
(PERIOD / 2) * bpf);
|
||||||
|
n -= (PERIOD / 2);
|
||||||
}
|
}
|
||||||
if (n > SIZE)
|
if (n > PERIOD)
|
||||||
n = SIZE;
|
n = PERIOD;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
buffer = gst_adapter_take_buffer (interaudiosrc->surface->audio_adapter,
|
buffer = gst_adapter_take_buffer (interaudiosrc->surface->audio_adapter,
|
||||||
n * bpf);
|
n * bpf);
|
||||||
|
@ -341,13 +345,13 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
||||||
}
|
}
|
||||||
|
|
||||||
bpf = interaudiosrc->info.bpf;
|
bpf = interaudiosrc->info.bpf;
|
||||||
if (n < SIZE) {
|
if (n < PERIOD) {
|
||||||
GstMapInfo map;
|
GstMapInfo map;
|
||||||
GstMemory *mem;
|
GstMemory *mem;
|
||||||
|
|
||||||
GST_WARNING_OBJECT (interaudiosrc, "creating %d samples of silence",
|
GST_WARNING_OBJECT (interaudiosrc, "creating %d samples of silence",
|
||||||
SIZE - n);
|
PERIOD - n);
|
||||||
mem = gst_allocator_alloc (NULL, (SIZE - n) * bpf, NULL);
|
mem = gst_allocator_alloc (NULL, (PERIOD - n) * bpf, NULL);
|
||||||
if (gst_memory_map (mem, &map, GST_MAP_WRITE)) {
|
if (gst_memory_map (mem, &map, GST_MAP_WRITE)) {
|
||||||
gst_audio_format_fill_silence (interaudiosrc->info.finfo, map.data,
|
gst_audio_format_fill_silence (interaudiosrc->info.finfo, map.data,
|
||||||
map.size);
|
map.size);
|
||||||
|
@ -356,20 +360,18 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
|
||||||
buffer = gst_buffer_make_writable (buffer);
|
buffer = gst_buffer_make_writable (buffer);
|
||||||
gst_buffer_prepend_memory (buffer, mem);
|
gst_buffer_prepend_memory (buffer, mem);
|
||||||
}
|
}
|
||||||
n = SIZE;
|
n = PERIOD;
|
||||||
|
|
||||||
GST_BUFFER_OFFSET (buffer) = interaudiosrc->n_samples;
|
GST_BUFFER_OFFSET (buffer) = interaudiosrc->n_samples;
|
||||||
GST_BUFFER_OFFSET_END (buffer) = interaudiosrc->n_samples + n;
|
GST_BUFFER_OFFSET_END (buffer) = interaudiosrc->n_samples + n;
|
||||||
GST_BUFFER_TIMESTAMP (buffer) =
|
GST_BUFFER_TIMESTAMP (buffer) = interaudiosrc->timestamp_offset +
|
||||||
gst_util_uint64_scale_int (interaudiosrc->n_samples, GST_SECOND,
|
gst_util_uint64_scale_int (interaudiosrc->n_samples, GST_SECOND,
|
||||||
interaudiosrc->info.rate);
|
interaudiosrc->info.rate);
|
||||||
GST_DEBUG_OBJECT (interaudiosrc, "create ts %" GST_TIME_FORMAT,
|
GST_DEBUG_OBJECT (interaudiosrc, "create ts %" GST_TIME_FORMAT,
|
||||||
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
||||||
GST_BUFFER_DURATION (buffer) =
|
GST_BUFFER_DURATION (buffer) = interaudiosrc->timestamp_offset +
|
||||||
gst_util_uint64_scale_int (interaudiosrc->n_samples + n, GST_SECOND,
|
gst_util_uint64_scale_int (interaudiosrc->n_samples + n, GST_SECOND,
|
||||||
interaudiosrc->info.rate) - GST_BUFFER_TIMESTAMP (buffer);
|
interaudiosrc->info.rate) - GST_BUFFER_TIMESTAMP (buffer);
|
||||||
GST_BUFFER_OFFSET (buffer) = interaudiosrc->n_samples;
|
|
||||||
GST_BUFFER_OFFSET_END (buffer) = -1;
|
|
||||||
GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DISCONT);
|
GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DISCONT);
|
||||||
if (interaudiosrc->n_samples == 0) {
|
if (interaudiosrc->n_samples == 0) {
|
||||||
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
||||||
|
@ -394,10 +396,9 @@ gst_inter_audio_src_query (GstBaseSrc * src, GstQuery * query)
|
||||||
GstClockTime min_latency, max_latency;
|
GstClockTime min_latency, max_latency;
|
||||||
|
|
||||||
if (interaudiosrc->info.rate > 0) {
|
if (interaudiosrc->info.rate > 0) {
|
||||||
/* FIXME: Where does the 30 come from? */
|
/* 1.5 just as a good measure */
|
||||||
|
|
||||||
min_latency =
|
min_latency =
|
||||||
30 * gst_util_uint64_scale_int (GST_SECOND, SIZE,
|
1.5 * N_PERIODS * gst_util_uint64_scale_int (GST_SECOND, PERIOD,
|
||||||
interaudiosrc->info.rate);
|
interaudiosrc->info.rate);
|
||||||
|
|
||||||
max_latency = min_latency;
|
max_latency = min_latency;
|
||||||
|
|
Loading…
Reference in a new issue