On Tue, Mar 28, 2017 at 12:47:39AM +0200, Alexander Strasser wrote: [...] > > +#define AV_FOURCC_MAX_STRING_SIZE 32 > > Should be fine, though I don't know how you came up with this max size in > particular. >
IIRC the actual maximum is 21 characters, I just took the closest superior power of two. Probably just like we did for AV_TS_MAX_STRING_SIZE. > > + > > +#define av_4cc2str(fourcc) > > av_fourcc_make_string((char[AV_FOURCC_MAX_STRING_SIZE]){0}, fourcc) > > Did your write it as 4cc2str to make the name shorter? > I guess fourcc2str is more readable and more consistent. > This is a shorthand, so yeah I wanted to keep it short. If you replace "4cc" with "fourcc", why not do that for the '2' as well? Writing "four" but keeping '2' was kind of weird to me :) > > + > > +/** > > + * Fill the provided buffer with a string containing a FourCC > > (four-character > > + * code) representation. > > + * > > + * @param buf a buffer with size in bytes of at least > > AV_FOURCC_MAX_STRING_SIZE > > + * @param fourcc the fourcc to represent > > + * @return the buffer in input > > + */ > > +char *av_fourcc_make_string(char *buf, uint32_t fourcc); > > + > > /** > > * @} > > * @} > > diff --git a/libavutil/utils.c b/libavutil/utils.c > > index 36e4dd5fdb..ba557b9252 100644 > > --- a/libavutil/utils.c > > +++ b/libavutil/utils.c > > @@ -121,6 +121,27 @@ unsigned av_int_list_length_for_size(unsigned elsize, > > return i; > > } > > > > +char *av_fourcc_make_string(char *buf, uint32_t fourcc) > > +{ > > + int i, len; > > + char *orig_buf = buf; > > + size_t buf_size = AV_FOURCC_MAX_STRING_SIZE; > > + > > +#define TAG_PRINT(x) \ > > + (((x) >= '0' && (x) <= '9') || \ > > + ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \ > > + ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_')) > > You could spare this macro, by using a temporary char for the character and > an int to indicate if it is printable in the loop below. Would probably be > 1 or 2 lines longer. > > You might want to at least rename TAG_PRINT to IS_PRINTABLE or > IS_PRINTABLE_FOURCC_CHAR or similar as TAG_PRINT is a rather confusing name. > > Also if the macro is only introduced for use this function, #undef could be > used, but I don't think we really do it anywhere else. > Yeah well I just took the existing code in libavcodec, so I didn't want to change it too much. But you're right on all your comments so I just adjusted the function. See patch attached. [...] Thanks -- Clément B.
From 067d474907ed6c3170f2d1d05e5f9931648ce9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <u...@pkh.me> Date: Mon, 27 Mar 2017 01:05:18 +0200 Subject: [PATCH 01/15] lavu: add av_fourcc_make_string() and av_4cc2str() --- doc/APIchanges | 4 ++++ libavutil/avutil.h | 14 ++++++++++++++ libavutil/utils.c | 23 +++++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 2274543024..ee062d7aeb 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-03-xx - xxxxxxx - lavu 55.52.100 - avutil.h + add av_fourcc_make_string() function and av_4cc2str() macro to replace + av_get_codec_tag_string() from lavc. + 2017-03-xx - xxxxxxx - lavf 57.68.100 - avformat.h Deprecate that demuxers export the stream rotation angle in AVStream.metadata (via an entry named "rotate"). Use av_stream_get_side_data() with diff --git a/libavutil/avutil.h b/libavutil/avutil.h index e9aaa03722..98100fdcc5 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -343,6 +343,20 @@ FILE *av_fopen_utf8(const char *path, const char *mode); */ AVRational av_get_time_base_q(void); +#define AV_FOURCC_MAX_STRING_SIZE 32 + +#define av_4cc2str(fourcc) av_fourcc_make_string((char[AV_FOURCC_MAX_STRING_SIZE]){0}, fourcc) + +/** + * Fill the provided buffer with a string containing a FourCC (four-character + * code) representation. + * + * @param buf a buffer with size in bytes of at least AV_FOURCC_MAX_STRING_SIZE + * @param fourcc the fourcc to represent + * @return the buffer in input + */ +char *av_fourcc_make_string(char *buf, uint32_t fourcc); + /** * @} * @} diff --git a/libavutil/utils.c b/libavutil/utils.c index 36e4dd5fdb..29f2746338 100644 --- a/libavutil/utils.c +++ b/libavutil/utils.c @@ -121,6 +121,29 @@ unsigned av_int_list_length_for_size(unsigned elsize, return i; } +char *av_fourcc_make_string(char *buf, uint32_t fourcc) +{ + int i; + char *orig_buf = buf; + size_t buf_size = AV_FOURCC_MAX_STRING_SIZE; + + for (i = 0; i < 4; i++) { + const char c = fourcc & 0xff; + const int print_chr = (c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c && strchr(". -_", c)); + const int len = snprintf(buf, buf_size, print_chr ? "%c" : "[%d]", c); + if (len < 0) + break; + buf += len; + buf_size = buf_size > len ? buf_size - len : 0; + fourcc >>= 8; + } + + return orig_buf; +} + AVRational av_get_time_base_q(void) { return (AVRational){1, AV_TIME_BASE}; diff --git a/libavutil/version.h b/libavutil/version.h index 3c86c26638..d6d78e7dc2 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 51 +#define LIBAVUTIL_VERSION_MINOR 52 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- 2.12.0
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel