[FFmpeg-devel] [PATCH] doc/examples/muxing: make compatible with C++

Clément Bœsch u at pkh.me
Thu Mar 13 23:10:40 CET 2014


On Thu, Mar 13, 2014 at 06:03:49PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  doc/examples/muxing.c |   12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
> index ad8e027..4e1d72b 100644
> --- a/doc/examples/muxing.c
> +++ b/doc/examples/muxing.c
> @@ -29,6 +29,11 @@
>   * @example muxing.c
>   */
>  
> +#ifdef __cplusplus
> +    extern "C" {
> +#endif

> +#define __STDC_FORMAT_MACROS
> +#define __STDC_CONSTANT_MACROS

I'd move those under the if so people not doing c++ aren't copying this.

>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <string.h>
> @@ -40,6 +45,9 @@
>  #include <libavformat/avformat.h>
>  #include <libswscale/swscale.h>
>  #include <libswresample/swresample.h>
> +#ifdef __cplusplus
> +    }   // extern "C"
> +#endif
>  
>  static int audio_is_eof, video_is_eof;
>  
> @@ -63,8 +71,8 @@ static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt)
>  static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
>  {
>      /* rescale output packet timestamp values from codec to stream timebase */
> -    pkt->pts = av_rescale_q_rnd(pkt->pts, *time_base, st->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
> -    pkt->dts = av_rescale_q_rnd(pkt->dts, *time_base, st->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
> +    pkt->pts = av_rescale_q_rnd(pkt->pts, *time_base, st->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
> +    pkt->dts = av_rescale_q_rnd(pkt->dts, *time_base, st->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));

wow...

>      pkt->duration = av_rescale_q(pkt->duration, *time_base, st->time_base);
>      pkt->stream_index = st->index;

I don't think supporting examples compilation with g++ is worth the
effort. Actually, I believe it's harmful because people doing C will start
copying naive/broken/c++ patterns (are you going to cast malloc() return
values too?).

I'd better have a warning + link to the FAQ about this stuff in
doc/examples/README than cluttering the already complex examples we have
with that stuff.

And/or maybe a longer explanation for all the problems to expect while
building with g++ (_STDC things, av_ts* like macros, random casts, ...)

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140313/90445ae4/attachment.asc>


More information about the ffmpeg-devel mailing list