From: Yuxuan Shui <yshui@codeweavers.com> An H264 stream can contain aspect ratio information in its extradata, and that information is only made available after we have called avformat_find_stream_info. Doing so makes the aspect ratio information available from media sources, but only when winedmo is used. So the test case is updated to test winedmo specifically. --- dlls/winedmo/unix_demuxer.c | 38 +++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/dlls/winedmo/unix_demuxer.c b/dlls/winedmo/unix_demuxer.c index 4c6bc15579b..de7c8e76611 100644 --- a/dlls/winedmo/unix_demuxer.c +++ b/dlls/winedmo/unix_demuxer.c @@ -138,6 +138,7 @@ NTSTATUS demuxer_create( void *arg ) { struct demuxer_create_params *params = arg; const char *ext = params->url ? strrchr( params->url, '.' ) : ""; + BOOL needs_find_stream_info = FALSE; const AVInputFormat *format; struct demuxer *demuxer; int i, ret; @@ -155,16 +156,36 @@ NTSTATUS demuxer_create( void *arg ) } format = demuxer->ctx->iformat; + /* Determine if we need a call to avformat_find_stream_info. Some stream information is only + * available after calling it. */ if ((params->duration = get_context_duration( demuxer->ctx )) == AV_NOPTS_VALUE || strstr( format->name, "mp3" )) + needs_find_stream_info = TRUE; + + for (i = 0; i < demuxer->ctx->nb_streams && !needs_find_stream_info; i++) { - if ((ret = avformat_find_stream_info( demuxer->ctx, NULL )) < 0) - { - ERR( "Failed to find stream info, error %s.\n", debugstr_averr(ret) ); - goto failed; - } - params->duration = get_context_duration( demuxer->ctx ); + /* For H264 streams, sample aspect ratio is sometimes found in its sequence parameter set, + * which requires avformat_find_stream_info. */ + AVStream *stream = demuxer->ctx->streams[i]; + AVCodecParameters *par = stream->codecpar; + + if (par->codec_id != AV_CODEC_ID_H264) continue; + + /* If sample aspect ratio is available somewhere, skip find stream info. */ + if (stream->sample_aspect_ratio.den && stream->sample_aspect_ratio.num) continue; + if (par->sample_aspect_ratio.den && par->sample_aspect_ratio.num) continue; + + needs_find_stream_info = TRUE; } + + if (needs_find_stream_info && (ret = avformat_find_stream_info( demuxer->ctx, NULL )) < 0) + { + ERR( "Failed to find stream info, error %s.\n", debugstr_averr( ret ) ); + goto failed; + } + + if (params->duration == AV_NOPTS_VALUE) params->duration = get_context_duration( demuxer->ctx ); + if (!(demuxer->streams = calloc( demuxer->ctx->nb_streams, sizeof(*demuxer->streams) ))) goto failed; if (demuxer_create_streams( demuxer )) goto failed; @@ -367,11 +388,12 @@ NTSTATUS demuxer_stream_type( void *arg ) struct demuxer *demuxer = get_demuxer( params->demuxer ); AVStream *stream = demuxer->ctx->streams[params->stream]; AVCodecParameters *par = demuxer->streams[params->stream].filter->par_out; + AVRational sar = stream->sample_aspect_ratio; TRACE( "demuxer %p, stream %u, stream %p, index %u\n", demuxer, params->stream, stream, stream->index ); - return media_type_from_codec_params( par, &stream->sample_aspect_ratio, - &stream->avg_frame_rate, 0, ¶ms->media_type ); + if (!sar.den || !sar.num) sar = stream->codecpar->sample_aspect_ratio; + return media_type_from_codec_params( par, &sar, &stream->avg_frame_rate, 0, ¶ms->media_type ); } #endif /* HAVE_FFMPEG */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10468