[FFmpeg-devel] [PATCH 3/5] avformat: Add adler protocol
Michael Niedermayer
michaelni at gmx.at
Wed May 8 17:00:10 CEST 2013
This is based on md5proto but using adler32 instead
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/Makefile | 1 +
libavformat/adlerproto.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++
libavformat/allformats.c | 1 +
3 files changed, 90 insertions(+)
create mode 100644 libavformat/adlerproto.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3679708..770d98c 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -412,6 +412,7 @@ OBJS-$(CONFIG_LIBQUVI_DEMUXER) += libquvi.o
OBJS-$(CONFIG_LIBRTMP) += librtmp.o
# protocols I/O
+OBJS-$(CONFIG_ADLER_PROTOCOL) += adlerproto.o
OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += hlsproto.o
OBJS-$(CONFIG_BLURAY_PROTOCOL) += bluray.o
OBJS-$(CONFIG_CACHE_PROTOCOL) += cache.o
diff --git a/libavformat/adlerproto.c b/libavformat/adlerproto.c
new file mode 100644
index 0000000..891b6eb
--- /dev/null
+++ b/libavformat/adlerproto.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2010 Mans Rullgard
+ * Copyright (c) 2013 Michael Niedermayer
+ *
+ * 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 <stdio.h>
+#include "libavutil/avstring.h"
+#include "libavutil/adler32.h"
+#include "libavutil/mem.h"
+#include "libavutil/error.h"
+#include "avformat.h"
+#include "avio.h"
+#include "url.h"
+
+struct AdlerContext {
+ uint32_t checksum;
+};
+
+static int adler_open(URLContext *h, const char *filename, int flags)
+{
+ struct AdlerContext *c = h->priv_data;
+
+ if (!(flags & AVIO_FLAG_WRITE))
+ return AVERROR(EINVAL);
+
+ c->checksum = 1;
+
+ return 0;
+}
+
+static int adler_write(URLContext *h, const unsigned char *buf, int size)
+{
+ struct AdlerContext *c = h->priv_data;
+ c->checksum = av_adler32_update(c->checksum, buf, size);
+ return size;
+}
+
+static int adler_close(URLContext *h)
+{
+ struct AdlerContext *c = h->priv_data;
+ const char *filename = h->filename;
+ uint8_t buf[64];
+ URLContext *out;
+ int err = 0;
+
+ snprintf(buf, 15, "%08x\n", c->checksum);
+
+ av_strstart(filename, "adler:", &filename);
+
+ if (*filename) {
+ err = ffurl_open(&out, filename, AVIO_FLAG_WRITE,
+ &h->interrupt_callback, NULL);
+ if (err)
+ return err;
+ err = ffurl_write(out, buf, 9);
+ ffurl_close(out);
+ } else {
+ if (fwrite(buf, 1, 9, stdout) < 9)
+ err = AVERROR(errno);
+ }
+
+ return err;
+}
+
+
+URLProtocol ff_adler_protocol = {
+ .name = "adler",
+ .url_open = adler_open,
+ .url_write = adler_write,
+ .url_close = adler_close,
+ .priv_data_size = sizeof(struct AdlerContext),
+};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index bca2c40..7ee8096 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -302,6 +302,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX(YUV4MPEGPIPE, yuv4mpegpipe);
/* protocols */
+ REGISTER_PROTOCOL(ADLER, adler);
REGISTER_PROTOCOL(BLURAY, bluray);
REGISTER_PROTOCOL(CACHE, cache);
REGISTER_PROTOCOL(CONCAT, concat);
--
1.7.9.5
More information about the ffmpeg-devel
mailing list