vorbiscomment.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /**
  26. * VorbisComment metadata conversion mapping.
  27. * from Ogg Vorbis I format specification: comment field and header specification
  28. * http://xiph.org/vorbis/doc/v-comment.html
  29. */
  30. const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
  31. { "ALBUMARTIST", "album_artist"},
  32. { "TRACKNUMBER", "track" },
  33. { 0 }
  34. };
  35. int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string,
  36. unsigned *count)
  37. {
  38. int len = 8;
  39. len += strlen(vendor_string);
  40. *count = 0;
  41. if (m) {
  42. AVMetadataTag *tag = NULL;
  43. while ( (tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX) ) ) {
  44. len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
  45. (*count)++;
  46. }
  47. }
  48. return len;
  49. }
  50. int ff_vorbiscomment_write(uint8_t **p, AVMetadata *m,
  51. const char *vendor_string, const unsigned count)
  52. {
  53. bytestream_put_le32(p, strlen(vendor_string));
  54. bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
  55. if (m) {
  56. AVMetadataTag *tag = NULL;
  57. bytestream_put_le32(p, count);
  58. while ( (tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX) ) ) {
  59. unsigned int len1 = strlen(tag->key);
  60. unsigned int len2 = strlen(tag->value);
  61. bytestream_put_le32(p, len1+1+len2);
  62. bytestream_put_buffer(p, tag->key, len1);
  63. bytestream_put_byte(p, '=');
  64. bytestream_put_buffer(p, tag->value, len2);
  65. }
  66. } else
  67. bytestream_put_le32(p, 0);
  68. return 0;
  69. }