vorbiscomment.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * VorbisComment writer
  3. * Copyright (c) 2009 James Darnley
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "metadata.h"
  23. #include "vorbiscomment.h"
  24. #include "libavcodec/bytestream.h"
  25. #include "libavutil/dict.h"
  26. /**
  27. * VorbisComment metadata conversion mapping.
  28. * from Ogg Vorbis I format specification: comment field and header specification
  29. * http://xiph.org/vorbis/doc/v-comment.html
  30. */
  31. const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
  32. { "ALBUMARTIST", "album_artist"},
  33. { "TRACKNUMBER", "track" },
  34. { "DISCNUMBER", "disc" },
  35. { 0 }
  36. };
  37. int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
  38. unsigned *count)
  39. {
  40. int len = 8;
  41. len += strlen(vendor_string);
  42. *count = 0;
  43. if (m) {
  44. AVDictionaryEntry *tag = NULL;
  45. while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
  46. len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
  47. (*count)++;
  48. }
  49. }
  50. return len;
  51. }
  52. int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
  53. const char *vendor_string, const unsigned count)
  54. {
  55. bytestream_put_le32(p, strlen(vendor_string));
  56. bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
  57. if (*m) {
  58. AVDictionaryEntry *tag = NULL;
  59. bytestream_put_le32(p, count);
  60. while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
  61. unsigned int len1 = strlen(tag->key);
  62. unsigned int len2 = strlen(tag->value);
  63. bytestream_put_le32(p, len1+1+len2);
  64. bytestream_put_buffer(p, tag->key, len1);
  65. bytestream_put_byte(p, '=');
  66. bytestream_put_buffer(p, tag->value, len2);
  67. }
  68. } else
  69. bytestream_put_le32(p, 0);
  70. return 0;
  71. }