From: Scott Theisen <scott.the.elm@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH] lavu: make av_get_media_type_string() never return NULL Date: Tue, 1 Feb 2022 21:42:32 -0500 Message-ID: <52297cd1-a76b-5224-8dcc-e275edc0b528@gmail.com> (raw) In-Reply-To: <5653ed95-8318-d383-d2bd-bf60535743a8@gmail.com> On 2/1/22 21:06, James Almer wrote: >> 32/44 uses do not check for null. > > But do they need to? Those modules have probably ensured media type is > one of the known and supported ones by the time they call this function. > > Why do you need this function to never return NULL, anyway? If you > know any of these calls where media type can be UNKNOWN, then it's > easier to just fix them by checking for NULL as per the doxy. The impetus was the desire to use this function in MythTV without invoking undefined behavior. Currently MythTV uses a modification to ffmpeg: https://github.com/MythTV/mythtv/blob/7fa02d4dc3ab0d3f2cbfcbc514047fe2736fe9cf/mythtv/external/FFmpeg/libavcodec/utils-mythtv.c#L228 (For reference, I just tested and a NULL/nullptr const char* becomes an empty QString, but this is not documented.) Also, another reason was to match behavior with avcodec_get_name() which never returns NULL, instead it returns "unknown_codec". On 2/1/22 21:13, Andreas Rheinhardt wrote: > That would need an announcement in doc/APIchanges; it can then be > changed at the next major version bump after two years have passed. So, would creating a new function instead and deprecating the old one be a better option? (e.g. av_get_media_type_name) > Who sets invalid media types? > (In case of fftools/*: If they don't set it themselves, they (and all > our users) should be able to rely on our libraries to not set invalid > values. The same goes for all demuxers (as they set this value > themselves). Checks are only necessary where the media type comes from > the user; this means muxers (where the check should be done generically) > and possibly avfiltergraph.c (I am pretty sure that the type has already > been checked earlier for filters).) I agree invalid media types are probably not set by anyone, but without checking for non-NULL it potentially invokes undefined behavior. Returning "unknown" for AVMEDIA_TYPE_UNKNOWN and returning a different value for the default case is, in my opinion clearer. "invalid_media_type" may be a better default string to match the behavior of avcodec_get_name(). Regards, Scott _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-02 2:42 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-01 22:30 Scott Theisen 2022-02-01 22:34 ` James Almer 2022-02-02 1:58 ` Scott Theisen 2022-02-02 2:06 ` James Almer 2022-02-02 2:42 ` Scott Theisen [this message] 2022-02-02 2:13 ` Andreas Rheinhardt 2022-02-23 7:52 ` Anton Khirnov 2022-02-28 21:06 ` Scott Theisen 2022-02-03 20:09 ` [FFmpeg-devel] [PATCH v2] create av_media_type_get_string() Scott Theisen 2022-02-03 20:09 ` [FFmpeg-devel] [PATCH 1/2] libavutil: " Scott Theisen 2022-02-03 20:09 ` [FFmpeg-devel] [PATCH 2/2] replace av_get_media_type_string() with av_media_type_get_string() Scott Theisen 2022-02-13 21:52 ` [FFmpeg-devel] [PATCH v3] create av_media_type_get_string() Scott Theisen 2022-02-13 21:52 ` [FFmpeg-devel] [PATCH v3 1/2] libavutil: " Scott Theisen 2022-02-13 21:52 ` [FFmpeg-devel] [PATCH v3 2/2] av_get_media_type_string(): replace with av_media_type_get_string() Scott Theisen 2022-05-15 19:55 ` [FFmpeg-devel] [Patch v4 0/2] create av_media_type_get_string() Scott Theisen 2022-05-15 19:55 ` [FFmpeg-devel] [PATCH v4 1/2] libavutil: " Scott Theisen 2022-05-15 19:55 ` [FFmpeg-devel] [PATCH v4 2/2] av_get_media_type_string(): replace with av_media_type_get_string() Scott Theisen 2022-06-01 19:22 ` [FFmpeg-devel] [PATCH] " Scott Theisen 2022-09-16 17:32 ` [FFmpeg-devel] [PATCH v2] " Scott Theisen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=52297cd1-a76b-5224-8dcc-e275edc0b528@gmail.com \ --to=scott.the.elm@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git