faac->cache = NULL;
faac->cache_time = GST_CLOCK_TIME_NONE;
faac->cache_duration = 0;
+ faac->next_ts = GST_CLOCK_TIME_NONE;
faac->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
gst_pad_set_chain_function (faac->sinkpad,
ret = TRUE;
/* flush first */
+ GST_DEBUG ("Pushing out remaining buffers because of EOS");
while (ret) {
if (gst_pad_alloc_buffer_and_set_caps (faac->srcpad,
GST_BUFFER_OFFSET_NONE, faac->bytes,
GST_PAD_CAPS (faac->srcpad), &outbuf) == GST_FLOW_OK) {
gint ret_size;
+ GST_DEBUG ("next_ts %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (faac->next_ts));
+
if ((ret_size = faacEncEncode (faac->handle, NULL, 0,
GST_BUFFER_DATA (outbuf), faac->bytes)) > 0) {
GST_BUFFER_SIZE (outbuf) = ret_size;
- GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
- GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
+ GST_BUFFER_TIMESTAMP (outbuf) = faac->next_ts;
+ /* faac seems to always consume a fixed number of input samples,
+ * therefore extrapolate the duration from that value and the incoming
+ * bitrate */
+ GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale (faac->samples,
+ GST_SECOND, faac->channels * faac->samplerate);
+ if (GST_CLOCK_TIME_IS_VALID (faac->next_ts))
+ faac->next_ts += GST_BUFFER_DURATION (outbuf);
gst_pad_push (faac->srcpad, outbuf);
} else {
gst_buffer_unref (outbuf);
goto nego_failed;
}
+ GST_DEBUG ("Got buffer time:%" GST_TIME_FORMAT " duration:%" GST_TIME_FORMAT,
+ GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)),
+ GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)));
+
size = GST_BUFFER_SIZE (inbuf);
in_size = size;
if (faac->cache)
GST_BUFFER_DURATION (outbuf) += faac->cache_duration;
faac->cache_duration = 0;
}
+ /* Store the value of the next expected timestamp to output
+ * This is required in order to output the trailing encoded packets
+ * at EOS with proper timestamps and duration. */
+ faac->next_ts =
+ GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf);
+ GST_DEBUG ("Pushing out buffer time:%" GST_TIME_FORMAT " duration:%"
+ GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
+ GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)));
result = gst_pad_push (faac->srcpad, outbuf);
} else {
/* FIXME: what I'm doing here isn't fully correct, but there
faac->cache_duration = 0;
faac->samplerate = -1;
faac->channels = -1;
+ faac->next_ts = GST_CLOCK_TIME_NONE;
GST_OBJECT_UNLOCK (faac);
break;
}