summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2016-04-13 17:58:40 -0300
committerJames Almer <jamrial@gmail.com>2016-04-13 20:58:04 -0300
commit868bce48f6d85c29d1b8c17686b42ea5601865ce (patch)
treec2b50b8e7374f40386e3615aa14f3eb4761f9360
parent2ea5ab6fc6b1b453791eb3c62e7205a66d339299 (diff)
downloadffmpeg-868bce48f6d85c29d1b8c17686b42ea5601865ce.tar.gz
avformat/framehash: add sidedata checksum
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavformat/hashenc.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index 4aa4fcf3ab..86f93813fe 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -22,6 +22,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/hash.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
@@ -189,13 +190,38 @@ static int framehash_write_header(struct AVFormatContext *s)
static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
struct HashContext *c = s->priv_data;
- char buf[256];
+ char buf[AV_HASH_MAX_SIZE*2+128];
+ int len;
av_hash_init(c->hash);
av_hash_update(c->hash, pkt->data, pkt->size);
- snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, ",
+ snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, ",
pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
- hash_finish(s, buf);
+ len = strlen(buf);
+ av_hash_final_hex(c->hash, buf + len, sizeof(buf) - len);
+ avio_write(s->pb, buf, strlen(buf));
+
+ if (c->format_version > 1 && pkt->side_data_elems) {
+ int i, j;
+ avio_printf(s->pb, ", S=%d", pkt->side_data_elems);
+ for (i = 0; i < pkt->side_data_elems; i++) {
+ av_hash_init(c->hash);
+ if (HAVE_BIGENDIAN && pkt->side_data[i].type == AV_PKT_DATA_PALETTE) {
+ for (j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) {
+ uint32_t data = AV_RL32(pkt->side_data[i].data + j);
+ av_hash_update(c->hash, (uint8_t *)&data, sizeof(uint32_t));
+ }
+ } else
+ av_hash_update(c->hash, pkt->side_data[i].data, pkt->side_data[i].size);
+ snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), ", %8d, ", pkt->side_data[i].size);
+ len = strlen(buf);
+ av_hash_final_hex(c->hash, buf + len, sizeof(buf) - len);
+ avio_write(s->pb, buf, strlen(buf));
+ }
+ }
+
+ avio_printf(s->pb, "\n");
+ avio_flush(s->pb);
return 0;
}