[FFmpeg-devel] [PATCH 2/2] avformat/framehash: add sidedata checksum
James Almer
jamrial at gmail.com
Wed Apr 13 06:54:26 CEST 2016
Signed-off-by: James Almer <jamrial at gmail.com>
---
Once these two patches go in I'll send one enabling version 2 output
by default.
libavformat/hashenc.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index e471789..016cff7 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"
@@ -196,13 +197,42 @@ 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;
+ snprintf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);
+ avio_write(s->pb, buf, strlen(buf));
+ 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) {
+ int j;
+ 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));
+ }
+ }
+ snprintf(buf, sizeof(buf), "\n");
+
+ avio_write(s->pb, buf, strlen(buf));
+ avio_flush(s->pb);
return 0;
}
--
2.8.0
More information about the ffmpeg-devel
mailing list