diff mbox series

[FFmpeg-devel,RFC,v2] avdevice: lock to minor version of avformat

Message ID 20211228150703.1228-1-dcnieho@gmail.com
State Superseded, archived
Headers show
Series [FFmpeg-devel,RFC,v2] avdevice: lock to minor version of avformat | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/makex86 warning New warnings during build
andriy/make_ppc success Make finished
andriy/make_fate_ppc fail Make fate failed
andriy/makeppc warning New warnings during build

Commit Message

Diederick C. Niehorster Dec. 28, 2021, 3:07 p.m. UTC
As per discussion on the list (
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
to resolve the the unholy ABI-relationship between libavdevice and
libavformat and allow easier working on the part of the avdevice API
that lives in avformat, lock avdevice to a specific major and minor
version of avformat.

Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
---
 libavdevice/avdevice.c | 10 ++++++++++
 libavdevice/version.h  | 10 ++++++++++
 libavformat/utils.c    |  5 +++++
 libavformat/version.h  | 11 +++++++++++
 libavutil/macros.h     |  3 +++
 5 files changed, 39 insertions(+)

Comments

Andreas Rheinhardt Jan. 3, 2022, 10:02 a.m. UTC | #1
Diederick Niehorster:
> As per discussion on the list (
> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
> especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
> to resolve the the unholy ABI-relationship between libavdevice and
> libavformat and allow easier working on the part of the avdevice API
> that lives in avformat, lock avdevice to a specific major and minor
> version of avformat.
> 
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---

1. If this patch intends to make it illegal to use libavdevice together
with libavformat with a different minor version than it was compiled
against, then the most basic requirement of this is to actually properly
document it and not add stuff that might cause linking failure if used
in a way that runs afoul of your undocumented new requirements.
2. Is avdevice_version_same_minor() supposed to cause linking failures
by virtue of its AV_MAKE_MAJOR_MINOR_FUNC_NAME generated symbol name? Or
is the user actually supposed to run this function explicitly?
Anyway, it is not clear from the documentation that this function calls
abort on failure.

>  libavdevice/avdevice.c | 10 ++++++++++
>  libavdevice/version.h  | 10 ++++++++++
>  libavformat/utils.c    |  5 +++++
>  libavformat/version.h  | 11 +++++++++++
>  libavutil/macros.h     |  3 +++
>  5 files changed, 39 insertions(+)
> 
> diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
> index 8f460c7564..0c9b702eda 100644
> --- a/libavdevice/avdevice.c
> +++ b/libavdevice/avdevice.c
> @@ -38,6 +38,16 @@ unsigned avdevice_version(void)
>      return LIBAVDEVICE_VERSION_INT;
>  }
>  
> +unsigned avdevice_version_same_minor()
> +{
> +    // check version of loaded lavf has same major and minor version as
> +    // this library was compiled against
> +    if ((avformat_version_same_minor()) & ~0xFF != (LIBAVFORMAT_VERSION_INT & ~0xFF))
> +        abort();
> +
> +    return avdevice_version();
> +}
> +
>  const char * avdevice_configuration(void)
>  {
>      return FFMPEG_CONFIGURATION;
> diff --git a/libavdevice/version.h b/libavdevice/version.h
> index 41f568d6b0..83d8c67511 100644
> --- a/libavdevice/version.h
> +++ b/libavdevice/version.h
> @@ -26,6 +26,7 @@
>   */
>  
>  #include "libavutil/version.h"
> +#include "libavutil/macros.h"
>  
>  #define LIBAVDEVICE_VERSION_MAJOR  59
>  #define LIBAVDEVICE_VERSION_MINOR   1
> @@ -48,4 +49,13 @@
>   */
>  #define FF_API_DEVICE_CAPABILITIES (LIBAVDEVICE_VERSION_MAJOR < 60)
>  
> +/**
> + * avdevice_version_same_minor() expands to a function with
> + * the same minor and major version it was compiled against
> + * encoded in it. Enables locking to the minor version of
> + * other libraries they were compiled against.
> + */
> +#define avdevice_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(device,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
> +unsigned avdevice_version_same_minor();
> +
>  #endif /* AVDEVICE_VERSION_H */
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 332ba534d2..607a777c3f 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -63,6 +63,11 @@ unsigned avformat_version(void)
>      return LIBAVFORMAT_VERSION_INT;
>  }
>  
> +unsigned avformat_version_same_minor()
> +{
> +    return avformat_version();
> +}
> +
>  const char *avformat_configuration(void)
>  {
>      return FFMPEG_CONFIGURATION;
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 379a68cc7c..661d074b12 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -28,6 +28,7 @@
>   */
>  
>  #include "libavutil/version.h"
> +#include "libavutil/macros.h"
>  
>  // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
>  // Also please add any ticket numbers that you believe might be affected here
> @@ -63,4 +64,14 @@
>  
>  
>  #define FF_API_R_FRAME_RATE            1
> +
> +/**
> + * avformat_version_same_minor() expands to a function with
> + * the same minor and major version it was compiled against
> + * encoded in it. Enables locking to the minor version of
> + * other libraries they were compiled against. 
> + */
> +#define avformat_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(format,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
> +unsigned avformat_version_same_minor();
> +
>  #endif /* AVFORMAT_VERSION_H */
> diff --git a/libavutil/macros.h b/libavutil/macros.h
> index 2a7567c3ea..dab530a8a0 100644
> --- a/libavutil/macros.h
> +++ b/libavutil/macros.h
> @@ -73,6 +73,9 @@
>   * @}
>   */
>  
> +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor) av ## name ## _version_ ## major ## _ ## minor
> +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME(name,major,minor) AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor)
> +
>  #define AV_PRAGMA(s) _Pragma(#s)
>  
>  #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
>
Diederick C. Niehorster Jan. 3, 2022, 11:03 a.m. UTC | #2
Hi Andreas,

Thanks for the comments!

On Mon, Jan 3, 2022 at 11:02 AM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> Diederick Niehorster:
> > As per discussion on the list (
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
> > especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
> > to resolve the the unholy ABI-relationship between libavdevice and
> > libavformat and allow easier working on the part of the avdevice API
> > that lives in avformat, lock avdevice to a specific major and minor
> > version of avformat.
> >
> > Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> > ---
>
> 1. If this patch intends to make it illegal to use libavdevice together
> with libavformat with a different minor version than it was compiled
> against, then the most basic requirement of this is to actually properly
> document it and not add stuff that might cause linking failure if used
> in a way that runs afoul of your undocumented new requirements.

Absolutely, documentation is required. Should that be in (amongst
local to the function in the header)?
I wanted to have the discussion first, or would docs be good to have
ready to help the discussion?

> 2. Is avdevice_version_same_minor() supposed to cause linking failures
> by virtue of its AV_MAKE_MAJOR_MINOR_FUNC_NAME generated symbol name? Or
> is the user actually supposed to run this function explicitly?
> Anyway, it is not clear from the documentation that this function calls
> abort on failure.

The implementation is as suggested by Nicolas as suggested here
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-August/284492.html (And
thanks for letting me know about preprocessor rescan, my v2 fixes most
except ppc, see https://patchwork.ffmpeg.org/check/49132/, and now i
know why :p).

The idea is that it causes linker failure. I've tested this indeed,
when trying to load incompatible avformat and avdevice dlls the
dynamic linker throws an error. So strictly the function doesn't have
to abort, nor does it have to be called at all, but it's nicely
documenting.

> >  libavdevice/avdevice.c | 10 ++++++++++
> >  libavdevice/version.h  | 10 ++++++++++
> >  libavformat/utils.c    |  5 +++++
> >  libavformat/version.h  | 11 +++++++++++
> >  libavutil/macros.h     |  3 +++
> >  5 files changed, 39 insertions(+)
> >
> > diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
> > index 8f460c7564..0c9b702eda 100644
> > --- a/libavdevice/avdevice.c
> > +++ b/libavdevice/avdevice.c
> > @@ -38,6 +38,16 @@ unsigned avdevice_version(void)
> >      return LIBAVDEVICE_VERSION_INT;
> >  }
> >
> > +unsigned avdevice_version_same_minor()
> > +{
> > +    // check version of loaded lavf has same major and minor version as
> > +    // this library was compiled against
> > +    if ((avformat_version_same_minor()) & ~0xFF != (LIBAVFORMAT_VERSION_INT & ~0xFF))
> > +        abort();
> > +
> > +    return avdevice_version();
> > +}
> > +
> >  const char * avdevice_configuration(void)
> >  {
> >      return FFMPEG_CONFIGURATION;
> > diff --git a/libavdevice/version.h b/libavdevice/version.h
> > index 41f568d6b0..83d8c67511 100644
> > --- a/libavdevice/version.h
> > +++ b/libavdevice/version.h
> > @@ -26,6 +26,7 @@
> >   */
> >
> >  #include "libavutil/version.h"
> > +#include "libavutil/macros.h"
> >
> >  #define LIBAVDEVICE_VERSION_MAJOR  59
> >  #define LIBAVDEVICE_VERSION_MINOR   1
> > @@ -48,4 +49,13 @@
> >   */
> >  #define FF_API_DEVICE_CAPABILITIES (LIBAVDEVICE_VERSION_MAJOR < 60)
> >
> > +/**
> > + * avdevice_version_same_minor() expands to a function with
> > + * the same minor and major version it was compiled against
> > + * encoded in it. Enables locking to the minor version of
> > + * other libraries they were compiled against.
> > + */
> > +#define avdevice_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(device,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
> > +unsigned avdevice_version_same_minor();
> > +
> >  #endif /* AVDEVICE_VERSION_H */
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index 332ba534d2..607a777c3f 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -63,6 +63,11 @@ unsigned avformat_version(void)
> >      return LIBAVFORMAT_VERSION_INT;
> >  }
> >
> > +unsigned avformat_version_same_minor()
> > +{
> > +    return avformat_version();
> > +}
> > +
> >  const char *avformat_configuration(void)
> >  {
> >      return FFMPEG_CONFIGURATION;
> > diff --git a/libavformat/version.h b/libavformat/version.h
> > index 379a68cc7c..661d074b12 100644
> > --- a/libavformat/version.h
> > +++ b/libavformat/version.h
> > @@ -28,6 +28,7 @@
> >   */
> >
> >  #include "libavutil/version.h"
> > +#include "libavutil/macros.h"
> >
> >  // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
> >  // Also please add any ticket numbers that you believe might be affected here
> > @@ -63,4 +64,14 @@
> >
> >
> >  #define FF_API_R_FRAME_RATE            1
> > +
> > +/**
> > + * avformat_version_same_minor() expands to a function with
> > + * the same minor and major version it was compiled against
> > + * encoded in it. Enables locking to the minor version of
> > + * other libraries they were compiled against.
> > + */
> > +#define avformat_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(format,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
> > +unsigned avformat_version_same_minor();
> > +
> >  #endif /* AVFORMAT_VERSION_H */
> > diff --git a/libavutil/macros.h b/libavutil/macros.h
> > index 2a7567c3ea..dab530a8a0 100644
> > --- a/libavutil/macros.h
> > +++ b/libavutil/macros.h
> > @@ -73,6 +73,9 @@
> >   * @}
> >   */
> >
> > +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor) av ## name ## _version_ ## major ## _ ## minor
> > +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME(name,major,minor) AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor)
> > +
> >  #define AV_PRAGMA(s) _Pragma(#s)
> >
> >  #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Diederick C. Niehorster March 3, 2022, 9:03 a.m. UTC | #3
Hi Andreas,

On Mon, Jan 3, 2022 at 12:03 PM Diederick C. Niehorster <dcnieho@gmail.com>
wrote:

> Hi Andreas,
>
> Thanks for the comments!
>
> On Mon, Jan 3, 2022 at 11:02 AM Andreas Rheinhardt
> <andreas.rheinhardt@outlook.com> wrote:
> >
> > Diederick Niehorster:
> > > As per discussion on the list (
> > > https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
> > > especially
> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
> > > to resolve the the unholy ABI-relationship between libavdevice and
> > > libavformat and allow easier working on the part of the avdevice API
> > > that lives in avformat, lock avdevice to a specific major and minor
> > > version of avformat.
> > >
> > > Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> > > ---
> >
> > 1. If this patch intends to make it illegal to use libavdevice together
> > with libavformat with a different minor version than it was compiled
> > against, then the most basic requirement of this is to actually properly
> > document it and not add stuff that might cause linking failure if used
> > in a way that runs afoul of your undocumented new requirements.
>
> Absolutely, documentation is required. Should that be in (amongst
> local to the function in the header)?
>

I want to prepare a next version to get this discussion going. Where should
i document that it is illegal to use libavdevice together with libavformat
with a different minor version?
The versioning documentation starting on line 47 in /libavutil/avutil.h?

All the best,
Dee
Andreas Rheinhardt March 3, 2022, 2:38 p.m. UTC | #4
Diederick C. Niehorster:
> Hi Andreas,
> 
> On Mon, Jan 3, 2022 at 12:03 PM Diederick C. Niehorster <dcnieho@gmail.com>
> wrote:
> 
>> Hi Andreas,
>>
>> Thanks for the comments!
>>
>> On Mon, Jan 3, 2022 at 11:02 AM Andreas Rheinhardt
>> <andreas.rheinhardt@outlook.com> wrote:
>>>
>>> Diederick Niehorster:
>>>> As per discussion on the list (
>>>> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
>>>> especially
>> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
>>>> to resolve the the unholy ABI-relationship between libavdevice and
>>>> libavformat and allow easier working on the part of the avdevice API
>>>> that lives in avformat, lock avdevice to a specific major and minor
>>>> version of avformat.
>>>>
>>>> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
>>>> ---
>>>
>>> 1. If this patch intends to make it illegal to use libavdevice together
>>> with libavformat with a different minor version than it was compiled
>>> against, then the most basic requirement of this is to actually properly
>>> document it and not add stuff that might cause linking failure if used
>>> in a way that runs afoul of your undocumented new requirements.
>>
>> Absolutely, documentation is required. Should that be in (amongst
>> local to the function in the header)?
>>
> 
> I want to prepare a next version to get this discussion going. Where should
> i document that it is illegal to use libavdevice together with libavformat
> with a different minor version?
> The versioning documentation starting on line 47 in /libavutil/avutil.h?
> 

That would be the best place for it if one wanted to to lock all the
library versions together; but you only want to do it for lavf<->lavd.
Then the proper place would be in some avdevice header (naturally
version.h, but who reads that header?) with references in avutil.h as
well as some avformat header (naturally version.h, but who reads that).

- Andreas
diff mbox series

Patch

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 8f460c7564..0c9b702eda 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -38,6 +38,16 @@  unsigned avdevice_version(void)
     return LIBAVDEVICE_VERSION_INT;
 }
 
+unsigned avdevice_version_same_minor()
+{
+    // check version of loaded lavf has same major and minor version as
+    // this library was compiled against
+    if ((avformat_version_same_minor()) & ~0xFF != (LIBAVFORMAT_VERSION_INT & ~0xFF))
+        abort();
+
+    return avdevice_version();
+}
+
 const char * avdevice_configuration(void)
 {
     return FFMPEG_CONFIGURATION;
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 41f568d6b0..83d8c67511 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -26,6 +26,7 @@ 
  */
 
 #include "libavutil/version.h"
+#include "libavutil/macros.h"
 
 #define LIBAVDEVICE_VERSION_MAJOR  59
 #define LIBAVDEVICE_VERSION_MINOR   1
@@ -48,4 +49,13 @@ 
  */
 #define FF_API_DEVICE_CAPABILITIES (LIBAVDEVICE_VERSION_MAJOR < 60)
 
+/**
+ * avdevice_version_same_minor() expands to a function with
+ * the same minor and major version it was compiled against
+ * encoded in it. Enables locking to the minor version of
+ * other libraries they were compiled against.
+ */
+#define avdevice_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(device,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
+unsigned avdevice_version_same_minor();
+
 #endif /* AVDEVICE_VERSION_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 332ba534d2..607a777c3f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -63,6 +63,11 @@  unsigned avformat_version(void)
     return LIBAVFORMAT_VERSION_INT;
 }
 
+unsigned avformat_version_same_minor()
+{
+    return avformat_version();
+}
+
 const char *avformat_configuration(void)
 {
     return FFMPEG_CONFIGURATION;
diff --git a/libavformat/version.h b/libavformat/version.h
index 379a68cc7c..661d074b12 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -28,6 +28,7 @@ 
  */
 
 #include "libavutil/version.h"
+#include "libavutil/macros.h"
 
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
@@ -63,4 +64,14 @@ 
 
 
 #define FF_API_R_FRAME_RATE            1
+
+/**
+ * avformat_version_same_minor() expands to a function with
+ * the same minor and major version it was compiled against
+ * encoded in it. Enables locking to the minor version of
+ * other libraries they were compiled against. 
+ */
+#define avformat_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(format,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
+unsigned avformat_version_same_minor();
+
 #endif /* AVFORMAT_VERSION_H */
diff --git a/libavutil/macros.h b/libavutil/macros.h
index 2a7567c3ea..dab530a8a0 100644
--- a/libavutil/macros.h
+++ b/libavutil/macros.h
@@ -73,6 +73,9 @@ 
  * @}
  */
 
+#define AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor) av ## name ## _version_ ## major ## _ ## minor
+#define AV_MAKE_MAJOR_MINOR_FUNC_NAME(name,major,minor) AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor)
+
 #define AV_PRAGMA(s) _Pragma(#s)
 
 #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))