From 645439c3c3ce39114e4f46a9198cd8b9a11c3e66 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 28 Dec 2010 09:03:33 +0000 Subject: lavf: rename meta{dec,enc}.c -> ffmeta{dec,enc}.c Originally committed as revision 26113 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/Makefile | 4 +- libavformat/ffmetadec.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/ffmetaenc.c | 100 ++++++++++++++++++++++++++++ libavformat/metadec.c | 172 ------------------------------------------------ libavformat/metaenc.c | 100 ---------------------------- 5 files changed, 274 insertions(+), 274 deletions(-) create mode 100644 libavformat/ffmetadec.c create mode 100644 libavformat/ffmetaenc.c delete mode 100644 libavformat/metadec.c delete mode 100644 libavformat/metaenc.c (limited to 'libavformat') diff --git a/libavformat/Makefile b/libavformat/Makefile index 4b031f4..013f6be 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -71,8 +71,8 @@ OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_EAC3_MUXER) += rawenc.o OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o -OBJS-$(CONFIG_FFMETADATA_DEMUXER) += metadec.o -OBJS-$(CONFIG_FFMETADATA_MUXER) += metaenc.o +OBJS-$(CONFIG_FFMETADATA_DEMUXER) += ffmetadec.o +OBJS-$(CONFIG_FFMETADATA_MUXER) += ffmetaenc.o OBJS-$(CONFIG_FILMSTRIP_DEMUXER) += filmstripdec.o OBJS-$(CONFIG_FILMSTRIP_MUXER) += filmstripenc.o OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o rawdec.o \ diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c new file mode 100644 index 0000000..0269ac5 --- /dev/null +++ b/libavformat/ffmetadec.c @@ -0,0 +1,172 @@ +/* + * Metadata demuxer + * Copyright (c) 2010 Anton Khirnov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "meta.h" + +static int probe(AVProbeData *p) +{ + if(!memcmp(p->buf, ID_STRING, strlen(ID_STRING))) + return AVPROBE_SCORE_MAX; + return 0; +} + +static void get_line(ByteIOContext *s, uint8_t *buf, int size) +{ + do { + uint8_t c; + int i = 0; + + while ((c = get_byte(s))) { + if (c == '\\') { + if (i < size - 1) + buf[i++] = c; + c = get_byte(s); + } else if (c == '\n') + break; + + if (i < size - 1) + buf[i++] = c; + } + buf[i] = 0; + } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0)); +} + +static AVChapter *read_chapter(AVFormatContext *s) +{ + uint8_t line[256]; + int64_t start, end; + AVRational tb = {1, 1e9}; + + get_line(s->pb, line, sizeof(line)); + + if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den)) + get_line(s->pb, line, sizeof(line)); + if (!sscanf(line, "START=%lld", &start)) { + av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line); + start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ? + s->chapters[s->nb_chapters - 1]->end : 0; + } else + get_line(s->pb, line, sizeof(line)); + + if (!sscanf(line, "END=%lld", &end)) { + av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line); + end = AV_NOPTS_VALUE; + } + + return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL); +} + +static uint8_t *unescape(uint8_t *buf, int size) +{ + uint8_t *ret = av_malloc(size + 1); + uint8_t *p1 = ret, *p2 = buf; + + if (!ret) + return NULL; + + while (p2 < buf + size) { + if (*p2 == '\\') + p2++; + *p1++ = *p2++; + } + *p1 = 0; + return ret; +} + +static int read_tag(uint8_t *line, AVMetadata **m) +{ + uint8_t *key, *value, *p = line; + + /* find first not escaped '=' */ + while (1) { + if (*p == '=') + break; + else if (*p == '\\') + p++; + + if (*p++) + continue; + + return 0; + } + + if (!(key = unescape(line, p - line))) + return AVERROR(ENOMEM); + if (!(value = unescape(p + 1, strlen(p + 1)))) { + av_free(key); + return AVERROR(ENOMEM); + } + + av_metadata_set2(m, key, value, AV_METADATA_DONT_STRDUP_KEY | AV_METADATA_DONT_STRDUP_VAL); + return 0; +} + +static int read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + AVMetadata **m = &s->metadata; + uint8_t line[1024]; + + while(!url_feof(s->pb)) { + get_line(s->pb, line, sizeof(line)); + + if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { + AVStream *st = av_new_stream(s, 0); + + if (!st) + return -1; + + st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codec->codec_id = CODEC_ID_FFMETADATA; + + m = &st->metadata; + } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { + AVChapter *ch = read_chapter(s); + + if (!ch) + return -1; + + m = &ch->metadata; + } else + read_tag(line, m); + } + + s->start_time = 0; + if (s->nb_chapters) + s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end, + s->chapters[s->nb_chapters - 1]->time_base, + AV_TIME_BASE_Q); + + return 0; +} + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + return AVERROR_EOF; +} + +AVInputFormat ffmetadata_demuxer = { + .name = "ffmetadata", + .long_name = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"), + .read_probe = probe, + .read_header = read_header, + .read_packet = read_packet, +}; diff --git a/libavformat/ffmetaenc.c b/libavformat/ffmetaenc.c new file mode 100644 index 0000000..65ab363 --- /dev/null +++ b/libavformat/ffmetaenc.c @@ -0,0 +1,100 @@ +/* + * Metadata muxer + * Copyright (c) 2010 Anton Khirnov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "meta.h" + + +static void write_escape_str(ByteIOContext *s, const uint8_t *str) +{ + const uint8_t *p = str; + + while (*p) { + if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n') + put_byte(s, '\\'); + put_byte(s, *p); + p++; + } +} + +static void write_tags(ByteIOContext *s, AVMetadata *m) +{ + AVMetadataTag *t = NULL; + while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) { + write_escape_str(s, t->key); + put_byte(s, '='); + write_escape_str(s, t->value); + put_byte(s, '\n'); + } +} + +static int write_header(AVFormatContext *s) +{ + put_tag(s->pb, ID_STRING); + put_byte(s->pb, '1'); // version + put_byte(s->pb, '\n'); + put_flush_packet(s->pb); + return 0; +} + +static int write_trailer(AVFormatContext *s) +{ + int i; + + write_tags(s->pb, s->metadata); + + for (i = 0; i < s->nb_streams; i++) { + put_tag(s->pb, ID_STREAM); + put_byte(s->pb, '\n'); + write_tags(s->pb, s->streams[i]->metadata); + } + + for (i = 0; i < s->nb_chapters; i++) { + AVChapter *ch = s->chapters[i]; + put_tag(s->pb, ID_CHAPTER); + put_byte(s->pb, '\n'); + url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); + url_fprintf(s->pb, "START=%lld\n", ch->start); + url_fprintf(s->pb, "END=%lld\n", ch->end); + write_tags(s->pb, ch->metadata); + } + + put_flush_packet(s->pb); + + return 0; +} + +static int write_packet(AVFormatContext *s, AVPacket *pkt) +{ + return 0; +} + +AVOutputFormat ffmetadata_muxer = { + .name = "ffmetadata", + .long_name = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"), + .extensions = "ffmeta", + .video_codec = CODEC_ID_NONE, + .audio_codec = CODEC_ID_NONE, + .write_header = write_header, + .write_packet = write_packet, + .write_trailer = write_trailer, + .flags = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS, +}; diff --git a/libavformat/metadec.c b/libavformat/metadec.c deleted file mode 100644 index 0269ac5..0000000 --- a/libavformat/metadec.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Metadata demuxer - * Copyright (c) 2010 Anton Khirnov - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avformat.h" -#include "meta.h" - -static int probe(AVProbeData *p) -{ - if(!memcmp(p->buf, ID_STRING, strlen(ID_STRING))) - return AVPROBE_SCORE_MAX; - return 0; -} - -static void get_line(ByteIOContext *s, uint8_t *buf, int size) -{ - do { - uint8_t c; - int i = 0; - - while ((c = get_byte(s))) { - if (c == '\\') { - if (i < size - 1) - buf[i++] = c; - c = get_byte(s); - } else if (c == '\n') - break; - - if (i < size - 1) - buf[i++] = c; - } - buf[i] = 0; - } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0)); -} - -static AVChapter *read_chapter(AVFormatContext *s) -{ - uint8_t line[256]; - int64_t start, end; - AVRational tb = {1, 1e9}; - - get_line(s->pb, line, sizeof(line)); - - if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den)) - get_line(s->pb, line, sizeof(line)); - if (!sscanf(line, "START=%lld", &start)) { - av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line); - start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ? - s->chapters[s->nb_chapters - 1]->end : 0; - } else - get_line(s->pb, line, sizeof(line)); - - if (!sscanf(line, "END=%lld", &end)) { - av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line); - end = AV_NOPTS_VALUE; - } - - return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL); -} - -static uint8_t *unescape(uint8_t *buf, int size) -{ - uint8_t *ret = av_malloc(size + 1); - uint8_t *p1 = ret, *p2 = buf; - - if (!ret) - return NULL; - - while (p2 < buf + size) { - if (*p2 == '\\') - p2++; - *p1++ = *p2++; - } - *p1 = 0; - return ret; -} - -static int read_tag(uint8_t *line, AVMetadata **m) -{ - uint8_t *key, *value, *p = line; - - /* find first not escaped '=' */ - while (1) { - if (*p == '=') - break; - else if (*p == '\\') - p++; - - if (*p++) - continue; - - return 0; - } - - if (!(key = unescape(line, p - line))) - return AVERROR(ENOMEM); - if (!(value = unescape(p + 1, strlen(p + 1)))) { - av_free(key); - return AVERROR(ENOMEM); - } - - av_metadata_set2(m, key, value, AV_METADATA_DONT_STRDUP_KEY | AV_METADATA_DONT_STRDUP_VAL); - return 0; -} - -static int read_header(AVFormatContext *s, AVFormatParameters *ap) -{ - AVMetadata **m = &s->metadata; - uint8_t line[1024]; - - while(!url_feof(s->pb)) { - get_line(s->pb, line, sizeof(line)); - - if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { - AVStream *st = av_new_stream(s, 0); - - if (!st) - return -1; - - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = CODEC_ID_FFMETADATA; - - m = &st->metadata; - } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { - AVChapter *ch = read_chapter(s); - - if (!ch) - return -1; - - m = &ch->metadata; - } else - read_tag(line, m); - } - - s->start_time = 0; - if (s->nb_chapters) - s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end, - s->chapters[s->nb_chapters - 1]->time_base, - AV_TIME_BASE_Q); - - return 0; -} - -static int read_packet(AVFormatContext *s, AVPacket *pkt) -{ - return AVERROR_EOF; -} - -AVInputFormat ffmetadata_demuxer = { - .name = "ffmetadata", - .long_name = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"), - .read_probe = probe, - .read_header = read_header, - .read_packet = read_packet, -}; diff --git a/libavformat/metaenc.c b/libavformat/metaenc.c deleted file mode 100644 index 65ab363..0000000 --- a/libavformat/metaenc.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Metadata muxer - * Copyright (c) 2010 Anton Khirnov - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avformat.h" -#include "meta.h" - - -static void write_escape_str(ByteIOContext *s, const uint8_t *str) -{ - const uint8_t *p = str; - - while (*p) { - if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n') - put_byte(s, '\\'); - put_byte(s, *p); - p++; - } -} - -static void write_tags(ByteIOContext *s, AVMetadata *m) -{ - AVMetadataTag *t = NULL; - while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) { - write_escape_str(s, t->key); - put_byte(s, '='); - write_escape_str(s, t->value); - put_byte(s, '\n'); - } -} - -static int write_header(AVFormatContext *s) -{ - put_tag(s->pb, ID_STRING); - put_byte(s->pb, '1'); // version - put_byte(s->pb, '\n'); - put_flush_packet(s->pb); - return 0; -} - -static int write_trailer(AVFormatContext *s) -{ - int i; - - write_tags(s->pb, s->metadata); - - for (i = 0; i < s->nb_streams; i++) { - put_tag(s->pb, ID_STREAM); - put_byte(s->pb, '\n'); - write_tags(s->pb, s->streams[i]->metadata); - } - - for (i = 0; i < s->nb_chapters; i++) { - AVChapter *ch = s->chapters[i]; - put_tag(s->pb, ID_CHAPTER); - put_byte(s->pb, '\n'); - url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); - url_fprintf(s->pb, "START=%lld\n", ch->start); - url_fprintf(s->pb, "END=%lld\n", ch->end); - write_tags(s->pb, ch->metadata); - } - - put_flush_packet(s->pb); - - return 0; -} - -static int write_packet(AVFormatContext *s, AVPacket *pkt) -{ - return 0; -} - -AVOutputFormat ffmetadata_muxer = { - .name = "ffmetadata", - .long_name = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"), - .extensions = "ffmeta", - .video_codec = CODEC_ID_NONE, - .audio_codec = CODEC_ID_NONE, - .write_header = write_header, - .write_packet = write_packet, - .write_trailer = write_trailer, - .flags = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS, -}; -- cgit v1.1