From patchwork Tue Mar 28 08:19:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 3142 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.13.202.146 with SMTP id m140csp1461698ywd; Tue, 28 Mar 2017 01:19:58 -0700 (PDT) X-Received: by 10.223.154.11 with SMTP id z11mr23776625wrb.76.1490689198719; Tue, 28 Mar 2017 01:19:58 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 88si3816144wrm.267.2017.03.28.01.19.58; Tue, 28 Mar 2017 01:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C6C92689747; Tue, 28 Mar 2017 11:19:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from golem.pkh.me (LStLambert-657-1-117-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3A2E6891D5 for ; Tue, 28 Mar 2017 11:19:26 +0300 (EEST) Received: from golem.pkh.me (localhost.localdomain [127.0.0.1]) by golem.pkh.me (OpenSMTPD) with ESMTPSA id 54c39f56 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Tue, 28 Mar 2017 08:19:48 +0000 (UTC) Date: Tue, 28 Mar 2017 10:19:46 +0200 From: =?utf-8?B?Q2zDqW1lbnQgQsWTc2No?= To: FFmpeg development discussions and patches Message-ID: <20170328081946.GN3964@golem.pkh.me> Mail-Followup-To: FFmpeg development discussions and patches References: <20170327075203.7499-1-u@pkh.me> <20170327224739.GA5068@xklotz.local> MIME-Version: 1.0 In-Reply-To: <20170327224739.GA5068@xklotz.local> User-Agent: Mutt/1.8.0 (2017-02-23) Subject: Re: [FFmpeg-devel] [PATCH 01/10] lavu: add av_fourcc_make_string() and av_4cc2str() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 From 067d474907ed6c3170f2d1d05e5f9931648ce9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= 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