Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg: Support FFmpeg 5.0 #2434

Merged
merged 1 commit into from Feb 4, 2022
Merged

FFmpeg: Support FFmpeg 5.0 #2434

merged 1 commit into from Feb 4, 2022

Conversation

rtandy
Copy link
Contributor

@rtandy rtandy commented Feb 2, 2022

Hello,

Debian's FFmpeg maintainers reported that mgba fails to compile using the newly released FFmpeg 5.0.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1004768

I have compiled, run mgba-cinema, and briefly tested video and GIF encoding with these changes on Debian unstable, with both FFmpeg 4.4 and 5.0.

I'm not sure about all the const additions. The FFmpeg 5.0 APIs return const pointers, but there are places with both versions where the pointers are passed to functions taking void *, which of course causes a new warning. I don't really know what's less bad here; at least const makes sure mGBA itself is sane?

Copy link
Member

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consts should be fine if they don't throw warnings in older versions. Can you check on older FFmpegs, e.g. the one in bionic or xenial? Also, what functions are passed these as void*?

src/feature/ffmpeg/ffmpeg-encoder.c Show resolved Hide resolved
src/feature/ffmpeg/ffmpeg-decoder.c Outdated Show resolved Hide resolved
@rtandy
Copy link
Contributor Author

rtandy commented Feb 3, 2022

Thank you for the speedy review!

The consts should be fine if they don't throw warnings in older versions. Can you check on older FFmpegs, e.g. the one in bionic or xenial?

Same set of warnings on Debian bullseye (FFmpeg 4.3), Ubuntu bionic (FFmpeg 3.4), and xenial (FFmpeg 2.8):

/home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c: In function ‘FFmpegEncoderSetVideo’:
/home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c:219:30: warning: passing argument 1 of ‘av_opt_find’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  if (vbr < 0 && !av_opt_find(&codec->priv_class, "crf", NULL, 0, 0)) {
                              ^
In file included from /home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c:28:0:
/usr/include/x86_64-linux-gnu/libavutil/opt.h:650:17: note: expected ‘void *’ but argument is of type ‘const AVClass * const* {aka const struct AVClass * const*}’
 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
                 ^
/home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c: In function ‘FFmpegEncoderOpen’:
/home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c:280:52: warning: passing argument 2 of ‘avformat_alloc_output_context2’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  avformat_alloc_output_context2(&encoder->context, oformat, 0, outfile);
                                                    ^
In file included from /home/ryan/mgba/src/feature/ffmpeg/ffmpeg-common.h:15:0,
                 from /home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.h:15,
                 from /home/ryan/mgba/src/feature/ffmpeg/ffmpeg-encoder.c:6:
/usr/include/x86_64-linux-gnu/libavformat/avformat.h:2013:5: note: expected ‘AVOutputFormat * {aka struct AVOutputFormat *}’ but argument is of type ‘const AVOutputFormat * {aka const struct AVOutputFormat *}’
 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
     ^

Also, what functions are passed these as void*?

Looks like just av_opt_find, actually.

@endrift
Copy link
Member

endrift commented Feb 3, 2022

Add an explicit cast to (void*) for the cases where needed. It looks like (frustratingly) libavutil casts them back to const inside that function, even though it's not declared as const void*. That should squelch that warning.

@rtandy
Copy link
Contributor Author

rtandy commented Feb 4, 2022

Add an explicit cast to (void*) for the cases where needed.

Done.

Also added a cast to remove the const on the second argument to avformat_alloc_output_context2, which silences the other warning I pasted above (ffmpeg-encoder.c:280). Fingers crossed that's what you would have wanted.

Now compiling without warnings on 5.0 and 4.4, will go back and verify the older ones as well. Verified.

@endrift endrift merged commit cdc7535 into mgba-emu:master Feb 4, 2022
@rtandy
Copy link
Contributor Author

rtandy commented Feb 4, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants