Commit 0f5240f1 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

WIP support planar in gstaudioencoder

parent 857228a7
......@@ -1181,9 +1181,10 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GstAudioEncoder *enc;
GstAudioEncoderPrivate *priv;
GstAudioEncoderContext *ctx;
GstAudioMeta *meta;
GstFlowReturn ret = GST_FLOW_OK;
gboolean discont;
gsize size;
gsize size, samples;
enc = GST_AUDIO_ENCODER (parent);
......@@ -1208,6 +1209,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
if (!ctx->info.bpf)
goto not_negotiated;
meta = gst_buffer_get_audio_meta (buffer);
size = gst_buffer_get_size (buffer);
GST_LOG_OBJECT (enc,
......@@ -1216,9 +1218,17 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
/* input shoud be whole number of sample frames */
if (size % ctx->info.bpf)
goto wrong_buffer;
if (!meta || meta->layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
/* input should be whole number of sample frames */
if (size % ctx->info.bpf)
goto wrong_buffer;
samples = size / ctx->info.bpf;
} else {
samples = meta->samples;
/* can't have more samples than what the buffer fits */
if (samples > size / ctx->info.bpf)
goto wrong_samples;
}
#ifndef GST_DISABLE_GST_DEBUG
{
......@@ -1226,8 +1236,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GstClockTimeDiff diff;
/* verify buffer duration */
duration = gst_util_uint64_scale (size, GST_SECOND,
ctx->info.rate * ctx->info.bpf);
duration = gst_util_uint64_scale (samples, GST_SECOND, ctx->info.rate);
diff = GST_CLOCK_DIFF (duration, GST_BUFFER_DURATION (buffer));
if (GST_BUFFER_DURATION (buffer) != GST_CLOCK_TIME_NONE &&
(diff > GST_SECOND / ctx->info.rate / 2 ||
......@@ -1254,7 +1263,9 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
goto done;
}
meta = gst_buffer_get_audio_meta (buffer);
size = gst_buffer_get_size (buffer);
samples = meta ? meta->samples : size / ctx->info.bpf;
GST_LOG_OBJECT (enc,
"buffer after segment clipping has size %" G_GSIZE_FORMAT " with ts %"
......@@ -1302,19 +1313,18 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
/* do some fancy tweaking in hard resync case */
if (discont && enc->priv->hard_resync) {
if (diff < 0) {
guint64 diff_bytes;
guint64 diff_samples;
GST_WARNING_OBJECT (enc, "Buffer is older than expected ts %"
GST_TIME_FORMAT ". Clipping buffer", GST_TIME_ARGS (next_ts));
diff_bytes =
GST_CLOCK_TIME_TO_FRAMES (-diff, ctx->info.rate) * ctx->info.bpf;
if (diff_bytes >= size) {
diff_samples = GST_CLOCK_TIME_TO_FRAMES (-diff, ctx->info.rate);
if (diff_samples >= samples) {
gst_buffer_unref (buffer);
goto done;
}
buffer = gst_buffer_make_writable (buffer);
gst_buffer_resize (buffer, diff_bytes, size - diff_bytes);
buffer = gst_audio_buffer_truncate (buffer, ctx->info.bpf, diff_samples,
samples - diff_samples);
GST_BUFFER_TIMESTAMP (buffer) += diff;
/* care even less about duration after this */
......@@ -1364,6 +1374,16 @@ not_negotiated:
ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
wrong_samples:
{
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),
("GstAudioMeta samples (%" G_GSIZE_FORMAT ") are more than what "
"the buffer fits: %" G_GSIZE_FORMAT, meta->samples,
size / ctx->info.bpf));
gst_buffer_unref (buffer);
ret = GST_FLOW_ERROR;
goto done;
}
wrong_buffer:
{
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),
......
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