[FFmpeg-devel] [PATCH] avformat/avformat: Avoid including codec.h, frame.h

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Sep 6 12:36:19 EEST 2023


Andreas Rheinhardt:
> AVCodec is only ever used as an incomplete type (i.e. via a pointer
> to an AVCodec) in avformat.h and it is not really part of the core
> of avformat.h or libavformat; almost none of our internal users
> make use of it (and none make use of hwcontext.h, which is implicitly
> included). So switch to use struct AVCodec, but continue to include
> codec.h for external users for compatibility.
> 
> Also, do the same for AVFrame and frame.h, which is implicitly included
> by codec.h (via lavu/hwcontext.h).
> 
> Also, remove an unnecessary inclusion of <time.h>.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>  libavdevice/alsa_enc.c           |  1 +
>  libavdevice/opengl_enc.c         |  1 +
>  libavdevice/pulse_audio_enc.c    |  1 +
>  libavdevice/xv.c                 |  1 +
>  libavformat/asfdec_o.c           |  2 ++
>  libavformat/avformat.c           |  2 ++
>  libavformat/avformat.h           | 29 ++++++++++++++++-------------
>  libavformat/dashdec.c            |  1 +
>  libavformat/dashenc.c            |  1 +
>  libavformat/dhav.c               |  2 ++
>  libavformat/ftp.c                |  1 +
>  libavformat/hlsenc.c             |  1 +
>  libavformat/hlsplaylist.c        |  1 +
>  libavformat/http.c               |  1 +
>  libavformat/img2enc.c            |  2 ++
>  libavformat/internal.h           |  4 ++--
>  libavformat/mlvdec.c             |  2 ++
>  libavformat/mux.c                |  2 ++
>  libavformat/mux.h                |  2 +-
>  libavformat/mxfdec.c             |  1 +
>  libavformat/uncodedframecrcenc.c |  1 +
>  libavformat/wavenc.c             |  1 +
>  libavformat/webmdashenc.c        |  1 +
>  libavformat/wtvdec.c             |  1 +
>  libavformat/yuv4mpegenc.c        |  1 +
>  25 files changed, 47 insertions(+), 16 deletions(-)
> 
> diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c
> index 62a20c7ba4..4c7805065e 100644
> --- a/libavdevice/alsa_enc.c
> +++ b/libavdevice/alsa_enc.c
> @@ -39,6 +39,7 @@
>  
>  #include <alsa/asoundlib.h>
>  
> +#include "libavutil/frame.h"
>  #include "libavutil/internal.h"
>  #include "libavutil/time.h"
>  
> diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
> index 1b0cf5aa8f..80feda7072 100644
> --- a/libavdevice/opengl_enc.c
> +++ b/libavdevice/opengl_enc.c
> @@ -49,6 +49,7 @@
>  #endif
>  
>  #include "libavutil/common.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/log.h"
>  #include "libavutil/opt.h"
> diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
> index 3d8323233f..9e594c6424 100644
> --- a/libavdevice/pulse_audio_enc.c
> +++ b/libavdevice/pulse_audio_enc.c
> @@ -26,6 +26,7 @@
>  #include "libavformat/mux.h"
>  #include "libavformat/version.h"
>  #include "libavutil/channel_layout.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/time.h"
> diff --git a/libavdevice/xv.c b/libavdevice/xv.c
> index 441f854121..b3d79d57a8 100644
> --- a/libavdevice/xv.c
> +++ b/libavdevice/xv.c
> @@ -32,6 +32,7 @@
>  #include <X11/extensions/Xvlib.h>
>  #include <sys/shm.h>
>  
> +#include "libavutil/frame.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/imgutils.h"
> diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
> index 2b407c016f..10942ecfa0 100644
> --- a/libavformat/asfdec_o.c
> +++ b/libavformat/asfdec_o.c
> @@ -19,6 +19,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> +#include <time.h>
> +
>  #include "libavutil/attributes.h"
>  #include "libavutil/common.h"
>  #include "libavutil/dict.h"
> diff --git a/libavformat/avformat.c b/libavformat/avformat.c
> index 356b4de931..7ff0cf3429 100644
> --- a/libavformat/avformat.c
> +++ b/libavformat/avformat.c
> @@ -23,12 +23,14 @@
>  #include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/channel_layout.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/mem.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/pixfmt.h"
>  #include "libavutil/samplefmt.h"
>  #include "libavcodec/avcodec.h"
> +#include "libavcodec/codec.h"
>  #include "libavcodec/bsf.h"
>  #include "libavcodec/codec_desc.h"
>  #include "libavcodec/packet_internal.h"
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 1916aa2dc5..10ee3c87c6 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -307,10 +307,8 @@
>   * @}
>   */
>  
> -#include <time.h>
>  #include <stdio.h>  /* FILE */
>  
> -#include "libavcodec/codec.h"
>  #include "libavcodec/codec_par.h"
>  #include "libavcodec/defs.h"
>  #include "libavcodec/packet.h"
> @@ -325,10 +323,13 @@
>   * to avoid unnecessary rebuilds. When included externally, keep including
>   * the full version information. */
>  #include "libavformat/version.h"
> +
> +#include "libavutil/frame.h"
> +#include "libavcodec/codec.h"
>  #endif
>  
>  struct AVFormatContext;
> -
> +struct AVFrame;
>  struct AVDeviceInfoList;
>  
>  /**
> @@ -1569,7 +1570,7 @@ typedef struct AVFormatContext {
>       * the same codec_id.
>       * Demuxing: Set by user
>       */
> -    const AVCodec *video_codec;
> +    const struct AVCodec *video_codec;
>  
>      /**
>       * Forced audio codec.
> @@ -1577,7 +1578,7 @@ typedef struct AVFormatContext {
>       * the same codec_id.
>       * Demuxing: Set by user
>       */
> -    const AVCodec *audio_codec;
> +    const struct AVCodec *audio_codec;
>  
>      /**
>       * Forced subtitle codec.
> @@ -1585,7 +1586,7 @@ typedef struct AVFormatContext {
>       * the same codec_id.
>       * Demuxing: Set by user
>       */
> -    const AVCodec *subtitle_codec;
> +    const struct AVCodec *subtitle_codec;
>  
>      /**
>       * Forced data codec.
> @@ -1593,7 +1594,7 @@ typedef struct AVFormatContext {
>       * the same codec_id.
>       * Demuxing: Set by user
>       */
> -    const AVCodec *data_codec;
> +    const struct AVCodec *data_codec;
>  
>      /**
>       * Number of bytes to be written as padding in a metadata header.
> @@ -1842,7 +1843,7 @@ const AVClass *av_stream_get_class(void);
>   *
>   * @return newly created stream or NULL on error.
>   */
> -AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
> +AVStream *avformat_new_stream(AVFormatContext *s, const struct AVCodec *c);
>  
>  /**
>   * Wrap an existing array as stream side data.
> @@ -2076,7 +2077,7 @@ int av_find_best_stream(AVFormatContext *ic,
>                          enum AVMediaType type,
>                          int wanted_stream_nb,
>                          int related_stream,
> -                        const AVCodec **decoder_ret,
> +                        const struct AVCodec **decoder_ret,
>                          int flags);
>  
>  /**
> @@ -2352,7 +2353,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
>   * See av_interleaved_write_uncoded_frame() for details.
>   */
>  int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
> -                           AVFrame *frame);
> +                           struct AVFrame *frame);
>  
>  /**
>   * Write an uncoded frame to an output media file.
> @@ -2371,7 +2372,7 @@ int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
>   * @return  >=0 for success, a negative code on error
>   */
>  int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index,
> -                                       AVFrame *frame);
> +                                       struct AVFrame *frame);
>  
>  /**
>   * Test whether a muxer supports uncoded frame.
> @@ -2759,7 +2760,8 @@ const struct AVCodecTag *avformat_get_mov_audio_tags(void);
>   * @param frame the frame with the aspect ratio to be determined
>   * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea
>   */
> -AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
> +AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream,
> +                                        struct AVFrame *frame);
>  
>  /**
>   * Guess the frame rate, based on both the container and codec information.
> @@ -2769,7 +2771,8 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
>   * @param frame the frame for which the frame rate should be determined, may be NULL
>   * @return the guessed (valid) frame rate, 0/1 if no idea
>   */
> -AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame);
> +AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream,
> +                               struct AVFrame *frame);
>  
>  /**
>   * Check if the stream st contained in s is matched by the stream specifier
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 29d4680c68..f4af625814 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -20,6 +20,7 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  #include <libxml/parser.h>
> +#include <time.h>
>  #include "libavutil/bprint.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/time.h"
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 17fe5f430c..69ceae2cbf 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -22,6 +22,7 @@
>  
>  #include "config.h"
>  #include "config_components.h"
> +#include <time.h>
>  #if HAVE_UNISTD_H
>  #include <unistd.h>
>  #endif
> diff --git a/libavformat/dhav.c b/libavformat/dhav.c
> index 4e720f2a26..2ec4857f29 100644
> --- a/libavformat/dhav.c
> +++ b/libavformat/dhav.c
> @@ -20,6 +20,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> +#include <time.h>
> +
>  #include "libavutil/parseutils.h"
>  #include "avio_internal.h"
>  #include "avformat.h"
> diff --git a/libavformat/ftp.c b/libavformat/ftp.c
> index 883668b37b..f9b069a59e 100644
> --- a/libavformat/ftp.c
> +++ b/libavformat/ftp.c
> @@ -19,6 +19,7 @@
>   */
>  
>  #include <string.h>
> +#include <time.h>
>  
>  #include "libavutil/avstring.h"
>  #include "libavutil/internal.h"
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 27d97f5f72..004bd25359 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -23,6 +23,7 @@
>  #include "config.h"
>  #include "config_components.h"
>  #include <stdint.h>
> +#include <time.h>
>  #if HAVE_UNISTD_H
>  #include <unistd.h>
>  #endif
> diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c
> index 0e1dcc087f..2bf05f3c7c 100644
> --- a/libavformat/hlsplaylist.c
> +++ b/libavformat/hlsplaylist.c
> @@ -22,6 +22,7 @@
>  
>  #include "config.h"
>  #include <stdint.h>
> +#include <time.h>
>  
>  #include "libavutil/time_internal.h"
>  
> diff --git a/libavformat/http.c b/libavformat/http.c
> index fd931c2d8e..c0fe7c36d9 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -22,6 +22,7 @@
>  #include "config.h"
>  #include "config_components.h"
>  
> +#include <time.h>
>  #if CONFIG_ZLIB
>  #include <zlib.h>
>  #endif /* CONFIG_ZLIB */
> diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
> index 9b8ec06cea..526a11e5ee 100644
> --- a/libavformat/img2enc.c
> +++ b/libavformat/img2enc.c
> @@ -20,6 +20,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> +#include <time.h>
> +
>  #include "config_components.h"
>  
>  #include "libavutil/intreadwrite.h"
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 53e70ccb53..051e8e2893 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -566,8 +566,8 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
>  
>  enum AVCodecID ff_guess_image2_codec(const char *filename);
>  
> -const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
> -                               enum AVCodecID codec_id);
> +const struct AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
> +                                      enum AVCodecID codec_id);
>  
>  /**
>   * Set the time base and wrapping info for a given stream. This will be used
> diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c
> index db3b77bb9b..b706898cb3 100644
> --- a/libavformat/mlvdec.c
> +++ b/libavformat/mlvdec.c
> @@ -24,6 +24,8 @@
>   * Magic Lantern Video (MLV) demuxer
>   */
>  
> +#include <time.h>
> +
>  #include "libavutil/imgutils.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/rational.h"
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index 415bd3948f..fff8094341 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -24,12 +24,14 @@
>  #include "mux.h"
>  #include "version.h"
>  #include "libavcodec/bsf.h"
> +#include "libavcodec/codec_desc.h"
>  #include "libavcodec/internal.h"
>  #include "libavcodec/packet_internal.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/dict.h"
>  #include "libavutil/timestamp.h"
>  #include "libavutil/avassert.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/internal.h"
>  #include "libavutil/mathematics.h"
>  
> diff --git a/libavformat/mux.h b/libavformat/mux.h
> index c2de45400c..9de5c2852a 100644
> --- a/libavformat/mux.h
> +++ b/libavformat/mux.h
> @@ -96,7 +96,7 @@ typedef struct FFOutputFormat {
>       * by setting the pointer to NULL.
>       */
>      int (*write_uncoded_frame)(AVFormatContext *, int stream_index,
> -                               AVFrame **frame, unsigned flags);
> +                               struct AVFrame **frame, unsigned flags);
>      /**
>       * Returns device list with it properties.
>       * @see avdevice_list_devices() for more details.
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 34230ece98..110b69b7c1 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -45,6 +45,7 @@
>   */
>  
>  #include <inttypes.h>
> +#include <time.h>
>  
>  #include "libavutil/aes.h"
>  #include "libavutil/avstring.h"
> diff --git a/libavformat/uncodedframecrcenc.c b/libavformat/uncodedframecrcenc.c
> index 4c37ef6e5b..529b2f36cb 100644
> --- a/libavformat/uncodedframecrcenc.c
> +++ b/libavformat/uncodedframecrcenc.c
> @@ -21,6 +21,7 @@
>  #include "libavutil/adler32.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/bprint.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/imgutils.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavformat/mux.h"
> diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
> index c12c090934..82acb9ef0f 100644
> --- a/libavformat/wavenc.c
> +++ b/libavformat/wavenc.c
> @@ -32,6 +32,7 @@
>  
>  #include <stdint.h>
>  #include <string.h>
> +#include <time.h>
>  
>  #include "libavutil/avstring.h"
>  #include "libavutil/dict.h"
> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
> index 0d6c4a2072..31ea3c6e8c 100644
> --- a/libavformat/webmdashenc.c
> +++ b/libavformat/webmdashenc.c
> @@ -29,6 +29,7 @@
>  #include <float.h>
>  #include <stdint.h>
>  #include <string.h>
> +#include <time.h>
>  
>  #include "avformat.h"
>  #include "matroska.h"
> diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
> index 98128b7201..b29ea7a923 100644
> --- a/libavformat/wtvdec.c
> +++ b/libavformat/wtvdec.c
> @@ -26,6 +26,7 @@
>   */
>  
>  #include <inttypes.h>
> +#include <time.h>
>  
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/intreadwrite.h"
> diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
> index 968ba2fa13..1d641eb9e4 100644
> --- a/libavformat/yuv4mpegenc.c
> +++ b/libavformat/yuv4mpegenc.c
> @@ -19,6 +19,7 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> +#include "libavutil/frame.h"
>  #include "libavutil/pixdesc.h"
>  #include "avformat.h"
>  #include "internal.h"

Will apply this patchset tomorrow unless there are objections.

- Andreas



More information about the ffmpeg-devel mailing list