You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.5KB

  1. /*
  2. * Copyright (c) 2009 Aurelien Jacobs <aurel@gnuage.org>
  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. #if LIBAVFORMAT_VERSION_MAJOR < 53
  21. #include <strings.h>
  22. #include "metadata.h"
  23. #include "libavutil/avstring.h"
  24. #define SIZE_OFFSET(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x)
  25. static const struct {
  26. const char name[16];
  27. int size;
  28. int offset;
  29. } compat_tab[] = {
  30. { "title", SIZE_OFFSET(title) },
  31. { "author", SIZE_OFFSET(author) },
  32. { "copyright", SIZE_OFFSET(copyright) },
  33. { "comment", SIZE_OFFSET(comment) },
  34. { "album", SIZE_OFFSET(album) },
  35. { "year", SIZE_OFFSET(year) },
  36. { "track", SIZE_OFFSET(track) },
  37. { "genre", SIZE_OFFSET(genre) },
  38. { "artist", SIZE_OFFSET(author) },
  39. { "creator", SIZE_OFFSET(author) },
  40. { "written_by", SIZE_OFFSET(author) },
  41. { "lead_performer", SIZE_OFFSET(author) },
  42. { "description", SIZE_OFFSET(comment) },
  43. { "albumtitle", SIZE_OFFSET(album) },
  44. { "date_written", SIZE_OFFSET(year) },
  45. { "date_released", SIZE_OFFSET(year) },
  46. { "tracknumber", SIZE_OFFSET(track) },
  47. { "part_number", SIZE_OFFSET(track) },
  48. };
  49. void ff_metadata_demux_compat(AVFormatContext *ctx)
  50. {
  51. AVMetadata *m;
  52. int i, j;
  53. if ((m = ctx->metadata))
  54. for (j=0; j<m->count; j++)
  55. for (i=0; i<FF_ARRAY_ELEMS(compat_tab); i++)
  56. if (!strcasecmp(m->elems[j].key, compat_tab[i].name)) {
  57. int *ptr = (int *)((char *)ctx+compat_tab[i].offset);
  58. if (*ptr) continue;
  59. if (compat_tab[i].size > sizeof(int))
  60. av_strlcpy((char *)ptr, m->elems[j].value, compat_tab[i].size);
  61. else
  62. *ptr = atoi(m->elems[j].value);
  63. }
  64. for (i=0; i<ctx->nb_chapters; i++)
  65. if ((m = ctx->chapters[i]->metadata))
  66. for (j=0; j<m->count; j++)
  67. if (!strcasecmp(m->elems[j].key, "title")) {
  68. av_free(ctx->chapters[i]->title);
  69. ctx->chapters[i]->title = av_strdup(m->elems[j].value);
  70. }
  71. for (i=0; i<ctx->nb_programs; i++)
  72. if ((m = ctx->programs[i]->metadata))
  73. for (j=0; j<m->count; j++) {
  74. if (!strcasecmp(m->elems[j].key, "name")) {
  75. av_free(ctx->programs[i]->name);
  76. ctx->programs[i]->name = av_strdup(m->elems[j].value);
  77. }
  78. if (!strcasecmp(m->elems[j].key, "provider_name")) {
  79. av_free(ctx->programs[i]->provider_name);
  80. ctx->programs[i]->provider_name = av_strdup(m->elems[j].value);
  81. }
  82. }
  83. for (i=0; i<ctx->nb_streams; i++)
  84. if ((m = ctx->streams[i]->metadata))
  85. for (j=0; j<m->count; j++) {
  86. if (!strcasecmp(m->elems[j].key, "language"))
  87. av_strlcpy(ctx->streams[i]->language, m->elems[j].value, 4);
  88. if (!strcasecmp(m->elems[j].key, "filename")) {
  89. av_free(ctx->streams[i]->filename);
  90. ctx->streams[i]->filename= av_strdup(m->elems[j].value);
  91. }
  92. }
  93. }
  94. #define FILL_METADATA(s, key, value) { \
  95. if (value && *value && \
  96. !av_metadata_get(s->metadata, #key, NULL, AV_METADATA_IGNORE_CASE)) \
  97. av_metadata_set(&s->metadata, (const AVMetadataTag){#key, value}); \
  98. }
  99. #define FILL_METADATA_STR(s, key) FILL_METADATA(s, key, s->key)
  100. #define FILL_METADATA_INT(s, key) { \
  101. char number[10]; \
  102. snprintf(number, sizeof(number), "%d", s->key); \
  103. if(s->key) FILL_METADATA(s, key, number) }
  104. void ff_metadata_mux_compat(AVFormatContext *ctx)
  105. {
  106. int i;
  107. FILL_METADATA_STR(ctx, title);
  108. FILL_METADATA_STR(ctx, author);
  109. FILL_METADATA_STR(ctx, copyright);
  110. FILL_METADATA_STR(ctx, comment);
  111. FILL_METADATA_STR(ctx, album);
  112. FILL_METADATA_INT(ctx, year);
  113. FILL_METADATA_INT(ctx, track);
  114. FILL_METADATA_STR(ctx, genre);
  115. for (i=0; i<ctx->nb_chapters; i++)
  116. FILL_METADATA_STR(ctx->chapters[i], title);
  117. for (i=0; i<ctx->nb_programs; i++) {
  118. FILL_METADATA_STR(ctx->programs[i], name);
  119. FILL_METADATA_STR(ctx->programs[i], provider_name);
  120. }
  121. for (i=0; i<ctx->nb_streams; i++) {
  122. FILL_METADATA_STR(ctx->streams[i], language);
  123. FILL_METADATA_STR(ctx->streams[i], filename);
  124. }
  125. }
  126. #endif /* LIBAVFORMAT_VERSION_MAJOR < 53 */