From e99a6f3142e68e4933f0f8fb25707b0babc162cd Mon Sep 17 00:00:00 2001 From: Robert Rosengren Date: Wed, 24 Feb 2021 13:46:04 +0100 Subject: [PATCH] audio: Use GST_BUFFER_PTS instead of deprecated GST_BUFFER_TIMESTAMP GST_BUFFER_PTS already used in audio code base (e.g. gstaudiodecoder), so migrate completely from deprecated GST_BUFFER_TIMESTAMP for better readability, as gstcompat.h defines GST_BUFFER_TIMESTAMP directly to PTS anyway. Part-of: --- gst-libs/gst/audio/audio.c | 10 +++--- gst-libs/gst/audio/gstaudiobasesink.c | 2 +- gst-libs/gst/audio/gstaudiobasesrc.c | 4 +-- gst-libs/gst/audio/gstaudiocdsrc.c | 2 +- gst-libs/gst/audio/gstaudiodecoder.c | 51 +++++++++++++-------------- gst-libs/gst/audio/gstaudioencoder.c | 24 ++++++------- 6 files changed, 46 insertions(+), 47 deletions(-) diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c index 075b8db969..c4aac4dc05 100644 --- a/gst-libs/gst/audio/audio.c +++ b/gst-libs/gst/audio/audio.c @@ -91,7 +91,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, const GstSegment * segment, segment->format == GST_FORMAT_DEFAULT, buffer); g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL); - if (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) + if (!GST_BUFFER_PTS_IS_VALID (buffer)) /* No timestamp - assume the buffer is completely in the segment */ return buffer; @@ -109,7 +109,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, const GstSegment * segment, if (!size) return buffer; - timestamp = GST_BUFFER_TIMESTAMP (buffer); + timestamp = GST_BUFFER_PTS (buffer); GST_DEBUG ("timestamp %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); if (GST_BUFFER_DURATION_IS_VALID (buffer)) { duration = GST_BUFFER_DURATION (buffer); @@ -214,9 +214,9 @@ gst_audio_buffer_clip (GstBuffer * buffer, const GstSegment * segment, if (trim == 0 && size == osize) { ret = buffer; - if (GST_BUFFER_TIMESTAMP (ret) != timestamp) { + if (GST_BUFFER_PTS (ret) != timestamp) { ret = gst_buffer_make_writable (ret); - GST_BUFFER_TIMESTAMP (ret) = timestamp; + GST_BUFFER_PTS (ret) = timestamp; } if (GST_BUFFER_DURATION (ret) != duration) { ret = gst_buffer_make_writable (ret); @@ -229,7 +229,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, const GstSegment * segment, GST_DEBUG ("timestamp %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); if (ret) { - GST_BUFFER_TIMESTAMP (ret) = timestamp; + GST_BUFFER_PTS (ret) = timestamp; if (change_duration) GST_BUFFER_DURATION (ret) = duration; diff --git a/gst-libs/gst/audio/gstaudiobasesink.c b/gst-libs/gst/audio/gstaudiobasesink.c index 7ce15cdc7d..359b1b0110 100644 --- a/gst-libs/gst/audio/gstaudiobasesink.c +++ b/gst-libs/gst/audio/gstaudiobasesink.c @@ -1864,7 +1864,7 @@ gst_audio_base_sink_render (GstBaseSink * bsink, GstBuffer * buf) samples = size / bpf; - time = GST_BUFFER_TIMESTAMP (buf); + time = GST_BUFFER_PTS (buf); /* Last ditch attempt to ensure that we only play silence if * we are in trickmode no-audio mode (or if a buffer is marked as a GAP) diff --git a/gst-libs/gst/audio/gstaudiobasesrc.c b/gst-libs/gst/audio/gstaudiobasesrc.c index b30a357644..3df095ec96 100644 --- a/gst-libs/gst/audio/gstaudiobasesrc.c +++ b/gst-libs/gst/audio/gstaudiobasesrc.c @@ -1027,7 +1027,7 @@ gst_audio_base_src_create (GstBaseSrc * bsrc, guint64 offset, guint length, no_sync: GST_OBJECT_UNLOCK (src); - GST_BUFFER_TIMESTAMP (buf) = timestamp; + GST_BUFFER_PTS (buf) = timestamp; GST_BUFFER_DURATION (buf) = duration; GST_BUFFER_OFFSET (buf) = sample; GST_BUFFER_OFFSET_END (buf) = sample + samples; @@ -1035,7 +1035,7 @@ no_sync: *outbuf = buf; GST_LOG_OBJECT (src, "Pushed buffer timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); + GST_TIME_ARGS (GST_BUFFER_PTS (buf))); return GST_FLOW_OK; diff --git a/gst-libs/gst/audio/gstaudiocdsrc.c b/gst-libs/gst/audio/gstaudiocdsrc.c index 81421d327b..d295f39d81 100644 --- a/gst-libs/gst/audio/gstaudiocdsrc.c +++ b/gst-libs/gst/audio/gstaudiocdsrc.c @@ -1764,7 +1764,7 @@ gst_audio_cd_src_create (GstPushSrc * pushsrc, GstBuffer ** buffer) GST_SECOND, 44100); } - GST_BUFFER_TIMESTAMP (buf) = position; + GST_BUFFER_PTS (buf) = position; GST_BUFFER_DURATION (buf) = duration; GST_LOG_OBJECT (src, "pushing sector %d with timestamp %" GST_TIME_FORMAT, diff --git a/gst-libs/gst/audio/gstaudiodecoder.c b/gst-libs/gst/audio/gstaudiodecoder.c index 6742948e31..00f28a9b8d 100644 --- a/gst-libs/gst/audio/gstaudiodecoder.c +++ b/gst-libs/gst/audio/gstaudiodecoder.c @@ -978,12 +978,12 @@ gst_audio_decoder_push_forward (GstAudioDecoder * dec, GstBuffer * buf) } ctx->had_output_data = TRUE; - ts = GST_BUFFER_TIMESTAMP (buf); + ts = GST_BUFFER_PTS (buf); GST_LOG_OBJECT (dec, "clipping buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); /* clip buffer */ @@ -1012,11 +1012,11 @@ gst_audio_decoder_push_forward (GstAudioDecoder * dec, GstBuffer * buf) } /* track where we are */ - if (G_LIKELY (GST_BUFFER_TIMESTAMP_IS_VALID (buf))) { + if (G_LIKELY (GST_BUFFER_PTS_IS_VALID (buf))) { /* duration should always be valid for raw audio */ g_assert (GST_BUFFER_DURATION_IS_VALID (buf)); dec->output_segment.position = - GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf); + GST_BUFFER_PTS (buf) + GST_BUFFER_DURATION (buf); } if (klass->pre_push) { @@ -1034,7 +1034,7 @@ gst_audio_decoder_push_forward (GstAudioDecoder * dec, GstBuffer * buf) GST_LOG_OBJECT (dec, "pushing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); ret = gst_pad_push (dec->srcpad, buf); @@ -1061,7 +1061,7 @@ gst_audio_decoder_output (GstAudioDecoder * dec, GstBuffer * buf) GST_LOG_OBJECT (dec, "output buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); } @@ -1079,9 +1079,9 @@ again: /* forcibly send current */ assemble = TRUE; GST_LOG_OBJECT (dec, "forcing fragment flush"); - } else if (av && (!GST_BUFFER_TIMESTAMP_IS_VALID (buf) || + } else if (av && (!GST_BUFFER_PTS_IS_VALID (buf) || !GST_CLOCK_TIME_IS_VALID (priv->out_ts) || - ((diff = GST_CLOCK_DIFF (GST_BUFFER_TIMESTAMP (buf), + ((diff = GST_CLOCK_DIFF (GST_BUFFER_PTS (buf), priv->out_ts + priv->out_dur)) > tol) || diff < -tol)) { assemble = TRUE; GST_LOG_OBJECT (dec, "buffer %d ms apart from current fragment", @@ -1090,7 +1090,7 @@ again: /* add or start collecting */ if (!av) { GST_LOG_OBJECT (dec, "starting new fragment"); - priv->out_ts = GST_BUFFER_TIMESTAMP (buf); + priv->out_ts = GST_BUFFER_PTS (buf); } else { GST_LOG_OBJECT (dec, "adding to fragment"); } @@ -1105,7 +1105,7 @@ again: GST_LOG_OBJECT (dec, "assembling fragment"); inbuf = buf; buf = gst_adapter_take_buffer (priv->adapter_out, av); - GST_BUFFER_TIMESTAMP (buf) = priv->out_ts; + GST_BUFFER_PTS (buf) = priv->out_ts; GST_BUFFER_DURATION (buf) = priv->out_dur; priv->out_ts = GST_CLOCK_TIME_NONE; priv->out_dur = 0; @@ -1420,7 +1420,7 @@ gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec, } if (G_LIKELY (priv->frames.length)) - ts = GST_BUFFER_TIMESTAMP (priv->frames.head->data); + ts = GST_BUFFER_PTS (priv->frames.head->data); else ts = GST_CLOCK_TIME_NONE; @@ -1499,14 +1499,14 @@ gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec, buf = gst_buffer_make_writable (buf); if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (priv->base_ts))) { - GST_BUFFER_TIMESTAMP (buf) = + GST_BUFFER_PTS (buf) = priv->base_ts + GST_FRAMES_TO_CLOCK_TIME (priv->samples, ctx->info.rate); GST_BUFFER_DURATION (buf) = priv->base_ts + GST_FRAMES_TO_CLOCK_TIME (priv->samples + samples, ctx->info.rate) - - GST_BUFFER_TIMESTAMP (buf); + GST_BUFFER_PTS (buf); } else { - GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; + GST_BUFFER_PTS (buf) = GST_CLOCK_TIME_NONE; GST_BUFFER_DURATION (buf) = GST_FRAMES_TO_CLOCK_TIME (samples, ctx->info.rate); } @@ -1624,7 +1624,7 @@ gst_audio_decoder_handle_frame (GstAudioDecoder * dec, /* keep around for admin */ GST_LOG_OBJECT (dec, "tracking frame size %" G_GSIZE_FORMAT ", ts %" GST_TIME_FORMAT, size, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); + GST_TIME_ARGS (GST_BUFFER_PTS (buffer))); g_queue_push_tail (&dec->priv->frames, buffer); dec->priv->ctx.delay = dec->priv->frames.length; GST_OBJECT_LOCK (dec); @@ -1718,7 +1718,7 @@ gst_audio_decoder_push_buffers (GstAudioDecoder * dec, gboolean force) } buffer = gst_adapter_take_buffer (priv->adapter, len); buffer = gst_buffer_make_writable (buffer); - GST_BUFFER_TIMESTAMP (buffer) = ts; + GST_BUFFER_PTS (buffer) = ts; flush += len; priv->force = FALSE; } else { @@ -1952,7 +1952,7 @@ gst_audio_decoder_flush_decode (GstAudioDecoder * dec) GstBuffer *buf = GST_BUFFER_CAST (walk->data); GST_DEBUG_OBJECT (dec, "decoding buffer %p, ts %" GST_TIME_FORMAT, - buf, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); + buf, GST_TIME_ARGS (GST_BUFFER_PTS (buf))); next = g_list_next (walk); /* decode buffer, resulting data prepended to output queue */ @@ -1993,13 +1993,13 @@ gst_audio_decoder_flush_decode (GstAudioDecoder * dec) timestamp = 0; } - if (!GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { + if (!GST_BUFFER_PTS_IS_VALID (buf)) { GST_LOG_OBJECT (dec, "applying reverse interpolated ts %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); - GST_BUFFER_TIMESTAMP (buf) = timestamp; + GST_BUFFER_PTS (buf) = timestamp; } else { /* track otherwise */ - timestamp = GST_BUFFER_TIMESTAMP (buf); + timestamp = GST_BUFFER_PTS (buf); GST_LOG_OBJECT (dec, "tracking ts %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); } @@ -2007,7 +2007,7 @@ gst_audio_decoder_flush_decode (GstAudioDecoder * dec) if (G_LIKELY (res == GST_FLOW_OK)) { GST_DEBUG_OBJECT (dec, "pushing buffer %p of size %" G_GSIZE_FORMAT ", " "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf, - gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); /* should be already, but let's be sure */ buf = gst_buffer_make_writable (buf); @@ -2050,7 +2050,7 @@ gst_audio_decoder_chain_reverse (GstAudioDecoder * dec, GstBuffer * buf) if (G_LIKELY (buf)) { GST_DEBUG_OBJECT (dec, "gathering buffer %p of size %" G_GSIZE_FORMAT ", " "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf, - gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); /* add buffer to gather queue */ @@ -2071,7 +2071,7 @@ gst_audio_decoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GST_LOG_OBJECT (dec, "received buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buffer), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), + GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); GST_AUDIO_DECODER_STREAM_LOCK (dec); @@ -2096,8 +2096,7 @@ gst_audio_decoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) /* buffer may claim DISCONT loudly, if it can't tell us where we are now, * we'll stick to where we were ... * Particularly useful/needed for upstream BYTE based */ - if (dec->input_segment.rate > 0.0 - && !GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) { + if (dec->input_segment.rate > 0.0 && !GST_BUFFER_PTS_IS_VALID (buffer)) { GST_DEBUG_OBJECT (dec, "... but restoring previous ts tracking"); dec->priv->base_ts = ts; dec->priv->samples = samples; @@ -2293,7 +2292,7 @@ gst_audio_decoder_handle_gap (GstAudioDecoder * dec, GstEvent * event) /* hand subclass empty frame with duration that needs covering */ buf = gst_buffer_new (); - GST_BUFFER_TIMESTAMP (buf) = timestamp; + GST_BUFFER_PTS (buf) = timestamp; GST_BUFFER_DURATION (buf) = duration; /* best effort, not much error handling */ gst_audio_decoder_handle_frame (dec, klass, buf); diff --git a/gst-libs/gst/audio/gstaudioencoder.c b/gst-libs/gst/audio/gstaudioencoder.c index 2a5192cd22..4a14d0c482 100644 --- a/gst-libs/gst/audio/gstaudioencoder.c +++ b/gst-libs/gst/audio/gstaudioencoder.c @@ -937,16 +937,16 @@ gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf, /* FIXME ? lookahead could lead to weird ts and duration ? * (particularly if not in perfect mode) */ /* mind sample rounding and produce perfect output */ - GST_BUFFER_TIMESTAMP (buf) = priv->base_ts + + GST_BUFFER_PTS (buf) = priv->base_ts + gst_util_uint64_scale (priv->samples - ctx->lookahead, GST_SECOND, ctx->info.rate); - GST_BUFFER_DTS (buf) = GST_BUFFER_TIMESTAMP (buf); + GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf); GST_DEBUG_OBJECT (enc, "out samples %d", samples); if (G_LIKELY (samples > 0)) { priv->samples += samples; GST_BUFFER_DURATION (buf) = priv->base_ts + gst_util_uint64_scale (priv->samples - ctx->lookahead, GST_SECOND, - ctx->info.rate) - GST_BUFFER_TIMESTAMP (buf); + ctx->info.rate) - GST_BUFFER_PTS (buf); priv->last_duration = GST_BUFFER_DURATION (buf); } else { /* duration forecast in case of handling remainder; @@ -1008,7 +1008,7 @@ gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf, GST_LOG_OBJECT (enc, "pushing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, size, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), + GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); ret = gst_pad_push (enc->srcpad, buf); @@ -1236,7 +1236,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GST_LOG_OBJECT (enc, "received buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, size, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), + GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); /* input should be whole number of sample frames */ @@ -1282,11 +1282,11 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GST_LOG_OBJECT (enc, "buffer after segment clipping has size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, size, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), + GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); if (!GST_CLOCK_TIME_IS_VALID (priv->base_ts)) { - priv->base_ts = GST_BUFFER_TIMESTAMP (buffer); + priv->base_ts = GST_BUFFER_PTS (buffer); GST_DEBUG_OBJECT (enc, "new base ts %" GST_TIME_FORMAT, GST_TIME_ARGS (priv->base_ts)); gst_audio_encoder_set_base_gp (enc); @@ -1298,7 +1298,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GstClockTimeDiff diff = 0; GstClockTime next_ts = 0; - if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) && + if (GST_BUFFER_PTS_IS_VALID (buffer) && GST_CLOCK_TIME_IS_VALID (priv->base_ts)) { guint64 samples; @@ -1310,7 +1310,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) " samples past base_ts %" GST_TIME_FORMAT ", expected ts %" GST_TIME_FORMAT, samples, GST_TIME_ARGS (priv->base_ts), GST_TIME_ARGS (next_ts)); - diff = GST_CLOCK_DIFF (next_ts, GST_BUFFER_TIMESTAMP (buffer)); + diff = GST_CLOCK_DIFF (next_ts, GST_BUFFER_PTS (buffer)); GST_LOG_OBJECT (enc, "ts diff %d ms", (gint) (diff / GST_MSECOND)); /* if within tolerance, * discard buffer ts and carry on producing perfect stream, @@ -1339,7 +1339,7 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) buffer = gst_buffer_make_writable (buffer); gst_buffer_resize (buffer, diff_bytes, size - diff_bytes); - GST_BUFFER_TIMESTAMP (buffer) += diff; + GST_BUFFER_PTS (buffer) += diff; /* care even less about duration after this */ } else { /* drain stuff prior to resync */ @@ -1352,13 +1352,13 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) gst_util_uint64_scale (gst_adapter_available (priv->adapter), GST_SECOND, ctx->info.rate * ctx->info.bpf); - if (G_UNLIKELY (shift > GST_BUFFER_TIMESTAMP (buffer))) { + if (G_UNLIKELY (shift > GST_BUFFER_PTS (buffer))) { /* ERROR */ goto wrong_time; } /* arrange for newly added samples to come out with the ts * of the incoming buffer that adds these */ - priv->base_ts = GST_BUFFER_TIMESTAMP (buffer) - shift; + priv->base_ts = GST_BUFFER_PTS (buffer) - shift; priv->samples = 0; gst_audio_encoder_set_base_gp (enc); priv->discont |= discont;