Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Grunau <janne-vlc@jannau.net>2021-01-05 16:31:43 +0300
committerJean-Baptiste Kempf <jb@videolan.org>2021-02-08 12:31:54 +0300
commite61685253608c340920ca66619b2068c22280e10 (patch)
treeba3d90ccccedd3baa83c6792a7da250d748215b9 /tools/output
parent061ac9aee82da23ebba5321f0625cac8bcb615ff (diff)
tools: add optional xxh3 based muxer
The required 'xxhash.h' header can either be in system include directory or can be copied to 'tools/output'. The xxh3_128bits based muxer shows no significant slowdown compared to the null muxer. Decoding times Chimera-AV1-8bit-1920x1080-6736kbps.ivf with 4 frame and 4 tile threads on a core i7-8550U (disabled turbo boost): null: 72.5 s md5: 99.8 s xxh3: 73.8 s Decoding Chimera-AV1-10bit-1920x1080-6191kbps.ivf with 6 frame and 4 tile threads on a m1 mc mini: null: 27.8 s md5: 105.9 s xxh3: 28.3 s
Diffstat (limited to 'tools/output')
-rw-r--r--tools/output/output.c5
-rw-r--r--tools/output/xxhash.c142
2 files changed, 147 insertions, 0 deletions
diff --git a/tools/output/output.c b/tools/output/output.c
index 368d079..fe4e07e 100644
--- a/tools/output/output.c
+++ b/tools/output/output.c
@@ -26,6 +26,7 @@
*/
#include "config.h"
+#include "cli_config.h"
#include <errno.h>
#include <stdio.h>
@@ -44,11 +45,15 @@ struct MuxerContext {
extern const Muxer null_muxer;
extern const Muxer md5_muxer;
+extern const Muxer xxh3_muxer;
extern const Muxer yuv_muxer;
extern const Muxer y4m2_muxer;
static const Muxer *muxers[] = {
&null_muxer,
&md5_muxer,
+#if HAVE_XXHASH_H
+ &xxh3_muxer,
+#endif
&yuv_muxer,
&y4m2_muxer,
NULL
diff --git a/tools/output/xxhash.c b/tools/output/xxhash.c
new file mode 100644
index 0000000..7d38c09
--- /dev/null
+++ b/tools/output/xxhash.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2018-2021, VideoLAN and dav1d authors
+ * Copyright © 2018-2021, Two Orioles, LLC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define XXH_INLINE_ALL
+#include "xxhash.h"
+
+#include "output/muxer.h"
+
+typedef struct MuxerPriv {
+ XXH3_state_t* state;
+ FILE *f;
+} xxh3Context;
+
+static int xxh3_open(xxh3Context *const xxh3, const char *const file,
+ const Dav1dPictureParameters *const p,
+ const unsigned fps[2])
+{
+ xxh3->state = XXH3_createState();
+ if (!xxh3->state) return DAV1D_ERR(ENOMEM);
+ XXH_errorcode err = XXH3_128bits_reset(xxh3->state);
+ if (err != XXH_OK) {
+ XXH3_freeState(xxh3->state);
+ xxh3->state = NULL;
+ return DAV1D_ERR(ENOMEM);
+ }
+
+ if (!strcmp(file, "-")) {
+ xxh3->f = stdout;
+ } else if (!(xxh3->f = fopen(file, "wb"))) {
+ XXH3_freeState(xxh3->state);
+ xxh3->state = NULL;
+ fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int xxh3_write(xxh3Context *const xxh3, Dav1dPicture *const p) {
+ const int hbd = p->p.bpc > 8;
+ const int w = p->p.w, h = p->p.h;
+ uint8_t *yptr = p->data[0];
+
+ for (int y = 0; y < h; y++) {
+ XXH3_128bits_update(xxh3->state, yptr, w << hbd);
+ yptr += p->stride[0];
+ }
+
+ if (p->p.layout != DAV1D_PIXEL_LAYOUT_I400) {
+ const int ss_ver = p->p.layout == DAV1D_PIXEL_LAYOUT_I420;
+ const int ss_hor = p->p.layout != DAV1D_PIXEL_LAYOUT_I444;
+ const int cw = (w + ss_hor) >> ss_hor;
+ const int ch = (h + ss_ver) >> ss_ver;
+ for (int pl = 1; pl <= 2; pl++) {
+ uint8_t *uvptr = p->data[pl];
+
+ for (int y = 0; y < ch; y++) {
+ XXH3_128bits_update(xxh3->state, uvptr, cw << hbd);
+ uvptr += p->stride[1];
+ }
+ }
+ }
+
+ dav1d_picture_unref(p);
+
+ return 0;
+}
+
+static void xxh3_close(xxh3Context *const xxh3) {
+ XXH128_hash_t hash = XXH3_128bits_digest(xxh3->state);
+ XXH3_freeState(xxh3->state);
+ XXH128_canonical_t c;
+ XXH128_canonicalFromHash(&c, hash);
+
+ for (int i = 0; i < 16; i++)
+ fprintf(xxh3->f, "%2.2x", c.digest[i]);
+ fprintf(xxh3->f, "\n");
+
+ if (xxh3->f != stdout)
+ fclose(xxh3->f);
+}
+
+static int xxh3_verify(xxh3Context *const xxh3, const char * xxh3_str) {
+ XXH128_hash_t hash = XXH3_128bits_digest(xxh3->state);
+ XXH3_freeState(xxh3->state);
+
+ if (strlen(xxh3_str) < 32)
+ return -1;
+
+ XXH128_canonical_t c;
+ char t[3] = { 0 };
+ for (int i = 0; i < 16; i++) {
+ char *ignore;
+ memcpy(t, xxh3_str, 2);
+ xxh3_str += 2;
+ c.digest[i] = strtoul(t, &ignore, 16);
+ }
+ XXH128_hash_t verify = XXH128_hashFromCanonical(&c);
+
+ return !XXH128_isEqual(hash, verify);
+}
+
+const Muxer xxh3_muxer = {
+ .priv_data_size = sizeof(xxh3Context),
+ .name = "xxh3",
+ .extension = "xxh3",
+ .write_header = xxh3_open,
+ .write_picture = xxh3_write,
+ .write_trailer = xxh3_close,
+ .verify = xxh3_verify,
+};