Skip to content

mod_av: avformat.c lines 458-459 reference private field within AVOutputFormat #2202

@Korynkai

Description

@Korynkai

The following code is apparently referencing a private field within the AVOutputFormat structure of libavformat, which is described as "[not] part of the public API", "may not be used outside of libavformat" and "can be changed and removed at will":

if (s->oformat->priv_data_size > 0) {

s->priv_data = av_mallocz(s->oformat->priv_data_size);

As described here:
https://github.com/FFmpeg/FFmpeg/blob/566aa38d98f5f492995127e82ab9a516f59bf952/libavformat/avformat.h#L540

typedef struct AVOutputFormat {

...continued...

    /*****************************************************************
     * No fields below this line are part of the public API. They
     * may not be used outside of libavformat and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */
    /**
     * size of private data so that it can be allocated in the wrapper
     */
    int priv_data_size;

...continued...

} AVOutputFormat;

mod_av, as-is, causes the following error when building against FFmpeg 6.0, as this field has apparently been removed from FFmpeg 6.0:

avformat.c: In function 'mod_avformat_alloc_output_context2':
avformat.c:458:23: error: 'const struct AVOutputFormat' has no member named 'priv_data_size'
  458 |         if (s->oformat->priv_data_size > 0) {
      |                       ^~
avformat.c:459:53: error: 'const struct AVOutputFormat' has no member named 'priv_data_size'
  459 |                 s->priv_data = av_mallocz(s->oformat->priv_data_size);
      |                                                     ^~
make[4]: *** [Makefile:1026: libavmod_la-avformat.lo] Error 1

With the following patch, everything seems to build correctly:

diff -Naur freeswitch-1.10.10.pristine/src/mod/applications/mod_av/avformat.c freeswitch-1.10.10/src/mod/applications/mod_av/avformat.c
--- freeswitch-1.10.10.pristine/src/mod/applications/mod_av/avformat.c  2023-08-14 17:45:02.529331160 +0000
+++ freeswitch-1.10.10/src/mod/applications/mod_av/avformat.c   2023-08-14 23:52:55.012169884 +0000
@@ -455,8 +455,10 @@
        }
 
        s->oformat = oformat;
+#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_N)
        if (s->oformat->priv_data_size > 0) {
                s->priv_data = av_mallocz(s->oformat->priv_data_size);
+
                if (!s->priv_data) {
                        goto nomem;
                }
@@ -468,6 +470,7 @@
        } else {
                s->priv_data = NULL;
        }
+#endif
 
        if (filename) {
 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,7,100))
diff -Naur freeswitch-1.10.10.pristine/src/mod/applications/mod_av/mod_av.h freeswitch-1.10.10/src/mod/applications/mod_av/mod_av.h
--- freeswitch-1.10.10.pristine/src/mod/applications/mod_av/mod_av.h    2023-08-14 17:45:02.529331160 +0000
+++ freeswitch-1.10.10/src/mod/applications/mod_av/mod_av.h     2023-08-14 19:40:21.271938704 +0000
@@ -42,6 +42,7 @@
 
 #define LIBAVCODEC_V 59
 #define LIBAVFORMAT_V 59
+#define LIBAVFORMAT_N 60
 #define LIBAVUTIL_V 57
 
 struct mod_av_globals {

What is the purpose of referencing the priv_data_size field within the AVOutputFormat structure, and can this be averted? Can this specific conditional block be safely removed by package maintainers such as myself, as in the above patch, or will it cause some form of runtime issues or undefined behavior? I have attempted to examine this code and have not quite determined the purpose it serves.. It seems as if it is allocating the number of bytes its value indicates to the priv_data field of the allocated AVFormatContext object and then the priv_data pointer is assigned to the priv_class object within the AVOutputFormat structure, then av_opt_set_defaults() is called on the priv_data pointer if the priv_class object exists...

Can someone help me determine the purpose of this and assist in developing a patch and/or pull request that would fix this?

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions