[FFmpeg-devel] [PATCH] avformat/avlanguage: deprecate av_convert_lang_to and make it internal

Aman Gupta ffmpeg at tmm1.net
Wed Nov 27 02:29:34 EET 2019


On Fri, May 13, 2016 at 2:29 PM James Almer <jamrial at gmail.com> wrote:

> The header was never installed and the function is only used in libavformat
>

I think av_convert_lang_to would be a useful public function. Do you mind
if I redefine it, and export the header this time?

libavformat returns iso639-2 codes in AVStream.metadata's "language" entry.
This can be problematic on some platforms like iOS where NSLocale can only
understand iso639-1 codes. ff_convert_lang_to is used for the same purpose
internally, so exposing it would make it easier for users to perform the
same conversion.

Aman


>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavformat/asfdec_f.c    |  2 +-
>  libavformat/asfdec_o.c    |  2 +-
>  libavformat/asfenc.c      |  2 +-
>  libavformat/avienc.c      |  2 +-
>  libavformat/avlanguage.c  | 11 +++++++++--
>  libavformat/avlanguage.h  |  7 +++++++
>  libavformat/matroskaenc.c |  2 +-
>  7 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
> index 2c81b13..b973eff 100644
> --- a/libavformat/asfdec_f.c
> +++ b/libavformat/asfdec_f.c
> @@ -912,7 +912,7 @@ static int asf_read_header(AVFormatContext *s)
>                  const char *rfc1766 =
> asf->stream_languages[asf->streams[i].stream_language_index];
>                  if (rfc1766 && strlen(rfc1766) > 1) {
>                      const char primary_tag[3] = { rfc1766[0], rfc1766[1],
> '\0' }; // ignore country code if any
> -                    const char *iso6392       =
> av_convert_lang_to(primary_tag,
> +                    const char *iso6392       =
> ff_convert_lang_to(primary_tag,
>
> AV_LANG_ISO639_2_BIBL);
>                      if (iso6392)
>                          av_dict_set(&st->metadata, "language", iso6392,
> 0);
> diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
> index 1c564a8..f8caf16 100644
> --- a/libavformat/asfdec_o.c
> +++ b/libavformat/asfdec_o.c
> @@ -829,7 +829,7 @@ static void set_language(AVFormatContext *s, const
> char *rfc1766, AVDictionary *
>      // language abbr should contain at least 2 chars
>      if (rfc1766 && strlen(rfc1766) > 1) {
>          const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; //
> ignore country code if any
> -        const char *iso6392       = av_convert_lang_to(primary_tag,
> +        const char *iso6392       = ff_convert_lang_to(primary_tag,
>
> AV_LANG_ISO639_2_BIBL);
>          if (iso6392)
>              if (av_dict_set(met, "language", iso6392, 0) < 0)
> diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
> index cfa4fad..93ab167 100644
> --- a/libavformat/asfenc.c
> +++ b/libavformat/asfenc.c
> @@ -431,7 +431,7 @@ static int asf_write_header1(AVFormatContext *s,
> int64_t file_size,
>
>          entry = av_dict_get(s->streams[n]->metadata, "language", NULL, 0);
>          if (entry) {
> -            const char *iso6391lang = av_convert_lang_to(entry->value,
> AV_LANG_ISO639_1);
> +            const char *iso6391lang = ff_convert_lang_to(entry->value,
> AV_LANG_ISO639_1);
>              if (iso6391lang) {
>                  int i;
>                  for (i = 0; i < asf->nb_languages; i++) {
> diff --git a/libavformat/avienc.c b/libavformat/avienc.c
> index c908c21..59ad2b2 100644
> --- a/libavformat/avienc.c
> +++ b/libavformat/avienc.c
> @@ -435,7 +435,7 @@ static int avi_write_header(AVFormatContext *s)
>              }
>              if (par->codec_id == AV_CODEC_ID_XSUB
>              && (t = av_dict_get(s->streams[i]->metadata, "language",
> NULL, 0))) {
> -                const char* langstr = av_convert_lang_to(t->value,
> AV_LANG_ISO639_1);
> +                const char* langstr = ff_convert_lang_to(t->value,
> AV_LANG_ISO639_1);
>                  t = NULL;
>                  if (langstr) {
>                      char* str = av_asprintf("Subtitle - %s-xx;02",
> langstr);
> diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
> index 39f2560..f5d2ddf 100644
> --- a/libavformat/avlanguage.c
> +++ b/libavformat/avlanguage.c
> @@ -733,7 +733,7 @@ static int lang_table_compare(const void *lhs, const
> void *rhs)
>      return strcmp(lhs, ((const LangEntry *)rhs)->str);
>  }
>
> -const char *av_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
> +const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
>  {
>      int i;
>      const LangEntry *entry = NULL;
> @@ -759,7 +759,14 @@ const char *av_convert_lang_to(const char *lang, enum
> AVLangCodespace target_cod
>              entry = lang_table + entry->next_equivalent;
>
>      if (target_codespace == AV_LANG_ISO639_2_TERM)
> -        return av_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
> +        return ff_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
>
>      return NULL;
>  }
> +
> +#if LIBAVFORMAT_VERSION_MAJOR < 58
> +const char *av_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
> +{
> +    return ff_convert_lang_to(lang, target_codespace);
> +}
> +#endif
> diff --git a/libavformat/avlanguage.h b/libavformat/avlanguage.h
> index 7fb8968..8b91b2a 100644
> --- a/libavformat/avlanguage.h
> +++ b/libavformat/avlanguage.h
> @@ -21,6 +21,9 @@
>  #ifndef AVFORMAT_AVLANGUAGE_H
>  #define AVFORMAT_AVLANGUAGE_H
>
> +#include "libavutil/attributes.h"
> +#include "libavformat/version.h"
> +
>  /**
>   * Known language codespaces
>   */
> @@ -34,6 +37,10 @@ enum AVLangCodespace {
>   * Convert a language code to a target codespace. The source codespace is
> guessed.
>   * @return NULL if the provided lang is null or invalid.
>   */
> +const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace);
> +#if LIBAVFORMAT_VERSION_MAJOR < 58
> +attribute_deprecated
>  const char *av_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace);
> +#endif
>
>  #endif /* AVFORMAT_AVLANGUAGE_H */
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 4cd9878..2bf9b30 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -1257,7 +1257,7 @@ static int mkv_write_simpletag(AVIOContext *pb,
> AVDictionaryEntry *t)
>          return AVERROR(ENOMEM);
>
>      if ((p = strrchr(p, '-')) &&
> -        (lang = av_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
> +        (lang = ff_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
>          *p = 0;
>
>      p = key;
> --
> 2.8.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list