Why doesn’t the message GST_MESSAGE_DURATION_CHANGED
arrive with this code?
Other messages like GST_MESSAGE_STATE_CHANGED
arrive.
// gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0 gstreamer-audio-1.0`
#include <gst/gst.h>
int quit = 0;
static void test_cb(GstBus *bus, GstMessage *msg, gpointer data) {
g_print("Message: %i\n", msg);
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_DURATION_CHANGED:
g_print("Duration changed\n");
break;
case GST_MESSAGE_STATE_CHANGED:
g_print("State changed\n");
break;
case GST_MESSAGE_EOS:
g_print("Finish\n");
quit = 1;
break;
}
}
int main(int argc, char *argv[]) {
gst_init(&argc, &argv);
GstElement *pipeline = gst_parse_launch("filesrc location=/home/tux/Schreibtisch/sound/test.wav ! decodebin ! audioconvert ! autoaudiosink", NULL);
GstBus *bus = gst_element_get_bus(pipeline);
gst_bus_add_signal_watch(bus);
g_signal_connect(bus, "message", G_CALLBACK(test_cb), NULL);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
while (!quit) {
g_main_context_iteration(0, 0);
}
}
Not sure, but as you’re playing a single file with a fixed duration, I wouldn’t expect that message to be issued.
I might be wrong, someone better skilled may correct my assumption.
Not sure, but as you’re playing a single file with a fixed duration, I wouldn’t expect that message to be issued.[/quote]
It seems that Duration does not appear for every file type.
It does not appear for WAV, but it does appear for FLAC and MP3.
wav:
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-start
Message: latency
Message: tag
Message: state-changed
Message: state-changed
Message: state-changed
Message: async-done
Message: latency
Message: new-clock
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Flac:
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: duration-changed
Message: state-changed
Message: state-changed
Message: latency
Message: state-changed
Message: stream-start
Message: latency
Message: tag
Message: state-changed
Message: state-changed
Message: state-changed
Message: async-done
Message: latency
Message: new-clock
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
Message: tag
MP3:
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: stream-status
Message: state-changed
Message: state-changed
Message: state-changed
Message: stream-start
Message: latency
Message: tag
Message: tag
Message: state-changed
Message: state-changed
Message: state-changed
Message: async-done
Message: latency
Message: new-clock
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: state-changed
Message: tag
Message: tag
Message: duration-changed
Addendum: OGG doesn’t work either.
Is there a way I can get the duration for WAV and OGG?
Ok, got it. Someone more skilled may provide more accurate advice for this case… In the meantime, do you see differences from gst-discoverer-1.0 for the various cases ?
tpm
August 31, 2024, 2:22pm
5
If you’re just interested in the duration, you would usually just do a duration query it when you get an ASYNC_DONE
message on the bus (which is when the pipeline is prerolled, at which point the demuxer/parsers will have produced some data and will have processed headers and metadata).
The DURATION_CHANGED
message on the bus is something elements can post to indicate to the application that something has changed and it should re-query the duration.
With most container formats, the duration is determined and known initially once the headers have been processed.
The main case where you get a DURATION_CHANGED
message is with audio files that are elementary streams without a container, such as e.g. MP3, where in case of VBR encoding the parser will update the duration estimate over time, as the estimated average bitrate changes the more frames it processes, which means the duration estimate in time will change too (but depends on what other metadata exists, e.g. there could be xing metadata or such to provide good info from the start).
Long story short: don’t expect a DURATION_CHANGED
message from the start, just query the duration yourself and then query again when you get a message that says that it changed.
1 Like