apetagenc.c
Go to the documentation of this file.
1 /*
2  * APE tag writer
3  * Copyright (c) 2012 Paul B Mahol
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 "libavutil/dict.h"
23 #include "avio_internal.h"
24 #include "avformat.h"
25 #include "apetag.h"
26 
27 static int string_is_ascii(const uint8_t *str)
28 {
29  while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
30  return !*str;
31 }
32 
34 {
35  int64_t tag_bytes;
37  AVIOContext *pb = s->pb;
38  int tags = 0, vlen;
39 
40  tag_bytes = avio_tell(s->pb);
41  while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
42  if (!string_is_ascii(t->key)) {
43  av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n");
44  continue;
45  }
46 
47  vlen = strlen(t->value);
48  avio_wl32(pb, vlen + 1);
49  avio_wl32(pb, 0); // flags
50  avio_put_str(pb, t->key);
51  avio_put_str(pb, t->value);
52  tags++;
53  }
54  tag_bytes = avio_tell(s->pb) - tag_bytes;
55 
56  if (!tags)
57  return;
58 
61  avio_wl32(pb, tag_bytes + APE_TAG_FOOTER_BYTES);
62  avio_wl32(pb, tags); // item count
63  avio_wl32(pb, 0); // global flags
64  ffio_fill(pb, 0, 8); // reserved
65 }
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
void ff_ape_write(AVFormatContext *s)
Write an APEv2 tag.
Definition: apetagenc.c:33
Format I/O context.
Definition: avformat.h:944
Public dictionary API.
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
uint8_t
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
AVDictionary * metadata
Definition: avformat.h:1092
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define APE_TAG_PREAMBLE
Definition: apetag.h:28
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:159
t
Definition: genspecsines3.m:6
#define APE_TAG_VERSION
Definition: apetag.h:29
#define APE_TAG_FOOTER_BYTES
Definition: apetag.h:30
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:307
NULL
Definition: eval.c:55
AVIOContext * pb
I/O context.
Definition: avformat.h:977
Main libavformat public API header.
static int string_is_ascii(const uint8_t *str)
Definition: apetagenc.c:27
char * key
Definition: dict.h:81
char * value
Definition: dict.h:82
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68