On 4/26/21 12:37 PM, Connor McAdams wrote:
Wait to query the pad duration until after caps are received, and poll gst_pad_query_duration a few times before giving up and trying to get duration by converting from byte-length. Fixes a bug in Fallout: New Vegas where the duration value is incorrect and causes the audio to loop.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com
dlls/winegstreamer/wg_parser.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/dlls/winegstreamer/wg_parser.c b/dlls/winegstreamer/wg_parser.c index 5529321490e..e07fb7510ac 100644 --- a/dlls/winegstreamer/wg_parser.c +++ b/dlls/winegstreamer/wg_parser.c @@ -1499,9 +1499,21 @@ static gboolean src_event_cb(GstPad *pad, GstObject *parent, GstEvent *event) static LONGLONG query_duration(GstPad *pad) { gint64 duration, byte_length;
unsigned int i;
if (gst_pad_query_duration(pad, GST_FORMAT_TIME, &duration)) return duration / 100;
/*
* Sometimes we query duration too early, try again a few times before
* giving up and trying to convert from byte length. If the duration can't
* be found after 50ms, we probably have a bigger issue.
*/
for (i = 0; i < 10; ++i)
{
g_usleep(5000);
We probably don't want to just sleep here, but instead try to wait for duration-changed. For elements that send it (e.g. mpegaudioparse) that should be more efficient than polling.
if (gst_pad_query_duration(pad, GST_FORMAT_TIME, &duration))
return duration / 100;
}
WARN("Failed to query time duration; trying to convert from byte length.\n");
@@ -1553,9 +1565,9 @@ static HRESULT CDECL wg_parser_connect(struct wg_parser *parser, uint64_t file_s { struct wg_parser_stream *stream = parser->streams[i];
stream->duration = query_duration(stream->their_src); while (!stream->has_caps && !parser->error) pthread_cond_wait(&parser->init_cond, &parser->mutex);
stream->duration = query_duration(stream->their_src); if (parser->error) { pthread_mutex_unlock(&parser->mutex);
This is a good idea, but it's also a separate change and deserves its own patch.