metadata.c 3.3 KB

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