metadata.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * copyright (c) 2009 Michael Niedermayer
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avformat.h"
  21. #include "metadata.h"
  22. #include "libavutil/dict.h"
  23. #include "libavutil/avstring.h"
  24. void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
  25. const AVMetadataConv *s_conv)
  26. {
  27. /* TODO: use binary search to look up the two conversion tables
  28. if the tables are getting big enough that it would matter speed wise */
  29. const AVMetadataConv *sc, *dc;
  30. AVDictionaryEntry *mtag = NULL;
  31. AVDictionary *dst = NULL;
  32. const char *key;
  33. if (d_conv == s_conv)
  34. return;
  35. while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
  36. key = mtag->key;
  37. if (s_conv)
  38. for (sc=s_conv; sc->native; sc++)
  39. if (!av_strcasecmp(key, sc->native)) {
  40. key = sc->generic;
  41. break;
  42. }
  43. if (d_conv)
  44. for (dc=d_conv; dc->native; dc++)
  45. if (!av_strcasecmp(key, dc->generic)) {
  46. key = dc->native;
  47. break;
  48. }
  49. av_dict_set(&dst, key, mtag->value, 0);
  50. }
  51. av_dict_free(pm);
  52. *pm = dst;
  53. }
  54. void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
  55. const AVMetadataConv *s_conv)
  56. {
  57. int i;
  58. ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
  59. for (i=0; i<ctx->nb_streams ; i++)
  60. ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
  61. for (i=0; i<ctx->nb_chapters; i++)
  62. ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
  63. for (i=0; i<ctx->nb_programs; i++)
  64. ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
  65. }