LCOV - code coverage report
Current view: top level - libavformat - vorbiscomment.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 26 96.2 %
Date: 2017-12-18 13:19:42 Functions: 2 2 100.0 %

          Line data    Source code
       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             : 
      22             : #include "avformat.h"
      23             : #include "metadata.h"
      24             : #include "vorbiscomment.h"
      25             : #include "libavcodec/bytestream.h"
      26             : #include "libavutil/dict.h"
      27             : 
      28             : /**
      29             :  * VorbisComment metadata conversion mapping.
      30             :  * from Ogg Vorbis I format specification: comment field and header specification
      31             :  * http://xiph.org/vorbis/doc/v-comment.html
      32             :  */
      33             : const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
      34             :     { "ALBUMARTIST", "album_artist"},
      35             :     { "TRACKNUMBER", "track"  },
      36             :     { "DISCNUMBER",  "disc"   },
      37             :     { "DESCRIPTION", "comment" },
      38             :     { 0 }
      39             : };
      40             : 
      41          18 : int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string)
      42             : {
      43          18 :     int64_t len = 8;
      44          18 :     len += strlen(vendor_string);
      45          18 :     if (m) {
      46          16 :         AVDictionaryEntry *tag = NULL;
      47          56 :         while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
      48          24 :             len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
      49             :         }
      50             :     }
      51          18 :     return len;
      52             : }
      53             : 
      54          18 : int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
      55             :                            const char *vendor_string)
      56             : {
      57          18 :     bytestream_put_le32(p, strlen(vendor_string));
      58          18 :     bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
      59          18 :     if (*m) {
      60          16 :         int count = av_dict_count(*m);
      61          16 :         AVDictionaryEntry *tag = NULL;
      62          16 :         bytestream_put_le32(p, count);
      63          56 :         while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
      64          24 :             int64_t len1 = strlen(tag->key);
      65          24 :             int64_t len2 = strlen(tag->value);
      66          24 :             if (len1+1+len2 > UINT32_MAX)
      67           0 :                 return AVERROR(EINVAL);
      68          24 :             bytestream_put_le32(p, len1+1+len2);
      69          24 :             bytestream_put_buffer(p, tag->key, len1);
      70          24 :             bytestream_put_byte(p, '=');
      71          24 :             bytestream_put_buffer(p, tag->value, len2);
      72             :         }
      73             :     } else
      74           2 :         bytestream_put_le32(p, 0);
      75          18 :     return 0;
      76             : }

Generated by: LCOV version 1.13