metadata.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #if FF_API_OLD_METADATA2
  25. AVDictionaryEntry *
  26. av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
  27. {
  28. return av_dict_get(m, key, prev, flags);
  29. }
  30. int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags)
  31. {
  32. return av_dict_set(pm, key, value, flags);
  33. }
  34. void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv,
  35. const AVMetadataConv *s_conv)
  36. {
  37. return;
  38. }
  39. void av_metadata_free(AVDictionary **pm)
  40. {
  41. av_dict_free(pm);
  42. }
  43. void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags)
  44. {
  45. av_dict_copy(dst, src, flags);
  46. }
  47. #endif
  48. void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
  49. const AVMetadataConv *s_conv)
  50. {
  51. /* TODO: use binary search to look up the two conversion tables
  52. if the tables are getting big enough that it would matter speed wise */
  53. const AVMetadataConv *sc, *dc;
  54. AVDictionaryEntry *mtag = NULL;
  55. AVDictionary *dst = NULL;
  56. const char *key;
  57. if (d_conv == s_conv)
  58. return;
  59. while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
  60. key = mtag->key;
  61. if (s_conv)
  62. for (sc=s_conv; sc->native; sc++)
  63. if (!av_strcasecmp(key, sc->native)) {
  64. key = sc->generic;
  65. break;
  66. }
  67. if (d_conv)
  68. for (dc=d_conv; dc->native; dc++)
  69. if (!av_strcasecmp(key, dc->generic)) {
  70. key = dc->native;
  71. break;
  72. }
  73. av_dict_set(&dst, key, mtag->value, 0);
  74. }
  75. av_dict_free(pm);
  76. *pm = dst;
  77. }
  78. void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
  79. const AVMetadataConv *s_conv)
  80. {
  81. int i;
  82. ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
  83. for (i=0; i<ctx->nb_streams ; i++)
  84. ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
  85. for (i=0; i<ctx->nb_chapters; i++)
  86. ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
  87. for (i=0; i<ctx->nb_programs; i++)
  88. ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
  89. }