Browse code

lavf: rename meta{dec,enc}.c -> ffmeta{dec,enc}.c

Originally committed as revision 26113 to svn://svn.ffmpeg.org/ffmpeg/trunk

Anton Khirnov authored on 2010/12/28 18:03:33
Showing 5 changed files
... ...
@@ -71,8 +71,8 @@ OBJS-$(CONFIG_EAC3_DEMUXER)              += ac3dec.o rawdec.o
71 71
 OBJS-$(CONFIG_EAC3_MUXER)                += rawenc.o
72 72
 OBJS-$(CONFIG_FFM_DEMUXER)               += ffmdec.o
73 73
 OBJS-$(CONFIG_FFM_MUXER)                 += ffmenc.o
74
-OBJS-$(CONFIG_FFMETADATA_DEMUXER)        += metadec.o
75
-OBJS-$(CONFIG_FFMETADATA_MUXER)          += metaenc.o
74
+OBJS-$(CONFIG_FFMETADATA_DEMUXER)        += ffmetadec.o
75
+OBJS-$(CONFIG_FFMETADATA_MUXER)          += ffmetaenc.o
76 76
 OBJS-$(CONFIG_FILMSTRIP_DEMUXER)         += filmstripdec.o
77 77
 OBJS-$(CONFIG_FILMSTRIP_MUXER)           += filmstripenc.o
78 78
 OBJS-$(CONFIG_FLAC_DEMUXER)              += flacdec.o rawdec.o \
79 79
new file mode 100644
... ...
@@ -0,0 +1,172 @@
0
+/*
1
+ * Metadata demuxer
2
+ * Copyright (c) 2010 Anton Khirnov
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
+
21
+#include "avformat.h"
22
+#include "meta.h"
23
+
24
+static int probe(AVProbeData *p)
25
+{
26
+    if(!memcmp(p->buf, ID_STRING, strlen(ID_STRING)))
27
+        return AVPROBE_SCORE_MAX;
28
+    return 0;
29
+}
30
+
31
+static void get_line(ByteIOContext *s, uint8_t *buf, int size)
32
+{
33
+    do {
34
+        uint8_t c;
35
+        int i = 0;
36
+
37
+        while ((c = get_byte(s))) {
38
+            if (c == '\\') {
39
+                if (i < size - 1)
40
+                    buf[i++] = c;
41
+                c = get_byte(s);
42
+            } else if (c == '\n')
43
+                break;
44
+
45
+            if (i < size - 1)
46
+                buf[i++] = c;
47
+        }
48
+        buf[i] = 0;
49
+    } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0));
50
+}
51
+
52
+static AVChapter *read_chapter(AVFormatContext *s)
53
+{
54
+    uint8_t line[256];
55
+    int64_t start, end;
56
+    AVRational tb = {1, 1e9};
57
+
58
+    get_line(s->pb, line, sizeof(line));
59
+
60
+    if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den))
61
+        get_line(s->pb, line, sizeof(line));
62
+    if (!sscanf(line, "START=%lld", &start)) {
63
+        av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line);
64
+        start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ?
65
+                 s->chapters[s->nb_chapters - 1]->end : 0;
66
+    } else
67
+        get_line(s->pb, line, sizeof(line));
68
+
69
+    if (!sscanf(line, "END=%lld", &end)) {
70
+        av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line);
71
+        end = AV_NOPTS_VALUE;
72
+    }
73
+
74
+    return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL);
75
+}
76
+
77
+static uint8_t *unescape(uint8_t *buf, int size)
78
+{
79
+    uint8_t *ret = av_malloc(size + 1);
80
+    uint8_t *p1  = ret, *p2 = buf;
81
+
82
+    if (!ret)
83
+        return NULL;
84
+
85
+    while (p2 < buf + size) {
86
+        if (*p2 == '\\')
87
+            p2++;
88
+        *p1++ = *p2++;
89
+    }
90
+    *p1 = 0;
91
+    return ret;
92
+}
93
+
94
+static int read_tag(uint8_t *line, AVMetadata **m)
95
+{
96
+    uint8_t *key, *value, *p = line;
97
+
98
+    /* find first not escaped '=' */
99
+    while (1) {
100
+        if (*p == '=')
101
+            break;
102
+        else if (*p == '\\')
103
+            p++;
104
+
105
+        if (*p++)
106
+            continue;
107
+
108
+        return 0;
109
+    }
110
+
111
+    if (!(key = unescape(line, p - line)))
112
+        return AVERROR(ENOMEM);
113
+    if (!(value = unescape(p + 1, strlen(p + 1)))) {
114
+        av_free(key);
115
+        return AVERROR(ENOMEM);
116
+    }
117
+
118
+    av_metadata_set2(m, key, value, AV_METADATA_DONT_STRDUP_KEY | AV_METADATA_DONT_STRDUP_VAL);
119
+    return 0;
120
+}
121
+
122
+static int read_header(AVFormatContext *s, AVFormatParameters *ap)
123
+{
124
+    AVMetadata **m = &s->metadata;
125
+    uint8_t line[1024];
126
+
127
+    while(!url_feof(s->pb)) {
128
+        get_line(s->pb, line, sizeof(line));
129
+
130
+        if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) {
131
+            AVStream *st = av_new_stream(s, 0);
132
+
133
+            if (!st)
134
+                return -1;
135
+
136
+            st->codec->codec_type = AVMEDIA_TYPE_DATA;
137
+            st->codec->codec_id   = CODEC_ID_FFMETADATA;
138
+
139
+            m = &st->metadata;
140
+        } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) {
141
+            AVChapter *ch = read_chapter(s);
142
+
143
+            if (!ch)
144
+                return -1;
145
+
146
+            m = &ch->metadata;
147
+        } else
148
+            read_tag(line, m);
149
+    }
150
+
151
+    s->start_time = 0;
152
+    if (s->nb_chapters)
153
+        s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end,
154
+                                   s->chapters[s->nb_chapters - 1]->time_base,
155
+                                   AV_TIME_BASE_Q);
156
+
157
+    return 0;
158
+}
159
+
160
+static int read_packet(AVFormatContext *s, AVPacket *pkt)
161
+{
162
+    return AVERROR_EOF;
163
+}
164
+
165
+AVInputFormat ffmetadata_demuxer = {
166
+    .name        = "ffmetadata",
167
+    .long_name   = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"),
168
+    .read_probe  = probe,
169
+    .read_header = read_header,
170
+    .read_packet = read_packet,
171
+};
0 172
new file mode 100644
... ...
@@ -0,0 +1,100 @@
0
+/*
1
+ * Metadata muxer
2
+ * Copyright (c) 2010 Anton Khirnov
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
+
21
+#include "avformat.h"
22
+#include "meta.h"
23
+
24
+
25
+static void write_escape_str(ByteIOContext *s, const uint8_t *str)
26
+{
27
+    const uint8_t *p = str;
28
+
29
+    while (*p) {
30
+        if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n')
31
+            put_byte(s, '\\');
32
+        put_byte(s, *p);
33
+        p++;
34
+    }
35
+}
36
+
37
+static void write_tags(ByteIOContext *s, AVMetadata *m)
38
+{
39
+    AVMetadataTag *t = NULL;
40
+    while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) {
41
+        write_escape_str(s, t->key);
42
+        put_byte(s, '=');
43
+        write_escape_str(s, t->value);
44
+        put_byte(s, '\n');
45
+    }
46
+}
47
+
48
+static int write_header(AVFormatContext *s)
49
+{
50
+    put_tag(s->pb, ID_STRING);
51
+    put_byte(s->pb, '1');          // version
52
+    put_byte(s->pb, '\n');
53
+    put_flush_packet(s->pb);
54
+    return 0;
55
+}
56
+
57
+static int write_trailer(AVFormatContext *s)
58
+{
59
+    int i;
60
+
61
+    write_tags(s->pb, s->metadata);
62
+
63
+    for (i = 0; i < s->nb_streams; i++) {
64
+        put_tag(s->pb, ID_STREAM);
65
+        put_byte(s->pb, '\n');
66
+        write_tags(s->pb, s->streams[i]->metadata);
67
+    }
68
+
69
+    for (i = 0; i < s->nb_chapters; i++) {
70
+        AVChapter *ch = s->chapters[i];
71
+        put_tag(s->pb, ID_CHAPTER);
72
+        put_byte(s->pb, '\n');
73
+        url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den);
74
+        url_fprintf(s->pb, "START=%lld\n", ch->start);
75
+        url_fprintf(s->pb, "END=%lld\n",   ch->end);
76
+        write_tags(s->pb, ch->metadata);
77
+    }
78
+
79
+    put_flush_packet(s->pb);
80
+
81
+    return 0;
82
+}
83
+
84
+static int write_packet(AVFormatContext *s, AVPacket *pkt)
85
+{
86
+    return 0;
87
+}
88
+
89
+AVOutputFormat ffmetadata_muxer = {
90
+    .name          = "ffmetadata",
91
+    .long_name     = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"),
92
+    .extensions    = "ffmeta",
93
+    .video_codec   = CODEC_ID_NONE,
94
+    .audio_codec   = CODEC_ID_NONE,
95
+    .write_header  = write_header,
96
+    .write_packet  = write_packet,
97
+    .write_trailer = write_trailer,
98
+    .flags         = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS,
99
+};
0 100
deleted file mode 100644
... ...
@@ -1,172 +0,0 @@
1
-/*
2
- * Metadata demuxer
3
- * Copyright (c) 2010 Anton Khirnov
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 "meta.h"
24
-
25
-static int probe(AVProbeData *p)
26
-{
27
-    if(!memcmp(p->buf, ID_STRING, strlen(ID_STRING)))
28
-        return AVPROBE_SCORE_MAX;
29
-    return 0;
30
-}
31
-
32
-static void get_line(ByteIOContext *s, uint8_t *buf, int size)
33
-{
34
-    do {
35
-        uint8_t c;
36
-        int i = 0;
37
-
38
-        while ((c = get_byte(s))) {
39
-            if (c == '\\') {
40
-                if (i < size - 1)
41
-                    buf[i++] = c;
42
-                c = get_byte(s);
43
-            } else if (c == '\n')
44
-                break;
45
-
46
-            if (i < size - 1)
47
-                buf[i++] = c;
48
-        }
49
-        buf[i] = 0;
50
-    } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0));
51
-}
52
-
53
-static AVChapter *read_chapter(AVFormatContext *s)
54
-{
55
-    uint8_t line[256];
56
-    int64_t start, end;
57
-    AVRational tb = {1, 1e9};
58
-
59
-    get_line(s->pb, line, sizeof(line));
60
-
61
-    if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den))
62
-        get_line(s->pb, line, sizeof(line));
63
-    if (!sscanf(line, "START=%lld", &start)) {
64
-        av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line);
65
-        start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ?
66
-                 s->chapters[s->nb_chapters - 1]->end : 0;
67
-    } else
68
-        get_line(s->pb, line, sizeof(line));
69
-
70
-    if (!sscanf(line, "END=%lld", &end)) {
71
-        av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line);
72
-        end = AV_NOPTS_VALUE;
73
-    }
74
-
75
-    return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL);
76
-}
77
-
78
-static uint8_t *unescape(uint8_t *buf, int size)
79
-{
80
-    uint8_t *ret = av_malloc(size + 1);
81
-    uint8_t *p1  = ret, *p2 = buf;
82
-
83
-    if (!ret)
84
-        return NULL;
85
-
86
-    while (p2 < buf + size) {
87
-        if (*p2 == '\\')
88
-            p2++;
89
-        *p1++ = *p2++;
90
-    }
91
-    *p1 = 0;
92
-    return ret;
93
-}
94
-
95
-static int read_tag(uint8_t *line, AVMetadata **m)
96
-{
97
-    uint8_t *key, *value, *p = line;
98
-
99
-    /* find first not escaped '=' */
100
-    while (1) {
101
-        if (*p == '=')
102
-            break;
103
-        else if (*p == '\\')
104
-            p++;
105
-
106
-        if (*p++)
107
-            continue;
108
-
109
-        return 0;
110
-    }
111
-
112
-    if (!(key = unescape(line, p - line)))
113
-        return AVERROR(ENOMEM);
114
-    if (!(value = unescape(p + 1, strlen(p + 1)))) {
115
-        av_free(key);
116
-        return AVERROR(ENOMEM);
117
-    }
118
-
119
-    av_metadata_set2(m, key, value, AV_METADATA_DONT_STRDUP_KEY | AV_METADATA_DONT_STRDUP_VAL);
120
-    return 0;
121
-}
122
-
123
-static int read_header(AVFormatContext *s, AVFormatParameters *ap)
124
-{
125
-    AVMetadata **m = &s->metadata;
126
-    uint8_t line[1024];
127
-
128
-    while(!url_feof(s->pb)) {
129
-        get_line(s->pb, line, sizeof(line));
130
-
131
-        if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) {
132
-            AVStream *st = av_new_stream(s, 0);
133
-
134
-            if (!st)
135
-                return -1;
136
-
137
-            st->codec->codec_type = AVMEDIA_TYPE_DATA;
138
-            st->codec->codec_id   = CODEC_ID_FFMETADATA;
139
-
140
-            m = &st->metadata;
141
-        } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) {
142
-            AVChapter *ch = read_chapter(s);
143
-
144
-            if (!ch)
145
-                return -1;
146
-
147
-            m = &ch->metadata;
148
-        } else
149
-            read_tag(line, m);
150
-    }
151
-
152
-    s->start_time = 0;
153
-    if (s->nb_chapters)
154
-        s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end,
155
-                                   s->chapters[s->nb_chapters - 1]->time_base,
156
-                                   AV_TIME_BASE_Q);
157
-
158
-    return 0;
159
-}
160
-
161
-static int read_packet(AVFormatContext *s, AVPacket *pkt)
162
-{
163
-    return AVERROR_EOF;
164
-}
165
-
166
-AVInputFormat ffmetadata_demuxer = {
167
-    .name        = "ffmetadata",
168
-    .long_name   = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"),
169
-    .read_probe  = probe,
170
-    .read_header = read_header,
171
-    .read_packet = read_packet,
172
-};
173 1
deleted file mode 100644
... ...
@@ -1,100 +0,0 @@
1
-/*
2
- * Metadata muxer
3
- * Copyright (c) 2010 Anton Khirnov
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 "meta.h"
24
-
25
-
26
-static void write_escape_str(ByteIOContext *s, const uint8_t *str)
27
-{
28
-    const uint8_t *p = str;
29
-
30
-    while (*p) {
31
-        if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n')
32
-            put_byte(s, '\\');
33
-        put_byte(s, *p);
34
-        p++;
35
-    }
36
-}
37
-
38
-static void write_tags(ByteIOContext *s, AVMetadata *m)
39
-{
40
-    AVMetadataTag *t = NULL;
41
-    while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) {
42
-        write_escape_str(s, t->key);
43
-        put_byte(s, '=');
44
-        write_escape_str(s, t->value);
45
-        put_byte(s, '\n');
46
-    }
47
-}
48
-
49
-static int write_header(AVFormatContext *s)
50
-{
51
-    put_tag(s->pb, ID_STRING);
52
-    put_byte(s->pb, '1');          // version
53
-    put_byte(s->pb, '\n');
54
-    put_flush_packet(s->pb);
55
-    return 0;
56
-}
57
-
58
-static int write_trailer(AVFormatContext *s)
59
-{
60
-    int i;
61
-
62
-    write_tags(s->pb, s->metadata);
63
-
64
-    for (i = 0; i < s->nb_streams; i++) {
65
-        put_tag(s->pb, ID_STREAM);
66
-        put_byte(s->pb, '\n');
67
-        write_tags(s->pb, s->streams[i]->metadata);
68
-    }
69
-
70
-    for (i = 0; i < s->nb_chapters; i++) {
71
-        AVChapter *ch = s->chapters[i];
72
-        put_tag(s->pb, ID_CHAPTER);
73
-        put_byte(s->pb, '\n');
74
-        url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den);
75
-        url_fprintf(s->pb, "START=%lld\n", ch->start);
76
-        url_fprintf(s->pb, "END=%lld\n",   ch->end);
77
-        write_tags(s->pb, ch->metadata);
78
-    }
79
-
80
-    put_flush_packet(s->pb);
81
-
82
-    return 0;
83
-}
84
-
85
-static int write_packet(AVFormatContext *s, AVPacket *pkt)
86
-{
87
-    return 0;
88
-}
89
-
90
-AVOutputFormat ffmetadata_muxer = {
91
-    .name          = "ffmetadata",
92
-    .long_name     = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"),
93
-    .extensions    = "ffmeta",
94
-    .video_codec   = CODEC_ID_NONE,
95
-    .audio_codec   = CODEC_ID_NONE,
96
-    .write_header  = write_header,
97
-    .write_packet  = write_packet,
98
-    .write_trailer = write_trailer,
99
-    .flags         = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS,
100
-};