summaryrefslogtreecommitdiff
path: root/libavformat/hashenc.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2016-04-14 20:49:35 -0300
committerJames Almer <jamrial@gmail.com>2016-04-14 20:59:08 -0300
commitbb505cd5057ce926e81048e19bb96dbdcb6ae2cf (patch)
tree8acaa53538cf3b5c7a4589eda34a0d1d708a59d5 /libavformat/hashenc.c
parent21acc4db5fa3f11997b2a27f03e87eac4d69e088 (diff)
downloadffmpeg-bb505cd5057ce926e81048e19bb96dbdcb6ae2cf.tar.gz
avformat/hashenc: simplify hash_write_trailer
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/hashenc.c')
-rw-r--r--libavformat/hashenc.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index ced2f66e65..01b00b5bb7 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -34,25 +34,6 @@ struct HashContext {
int format_version;
};
-static void hash_finish(struct AVFormatContext *s, char *buf)
-{
- struct HashContext *c = s->priv_data;
- uint8_t hash[AV_HASH_MAX_SIZE];
- int i, offset = strlen(buf);
- int len = av_hash_get_size(c->hash);
- av_assert0(len > 0 && len <= sizeof(hash));
- av_hash_final(c->hash, hash);
- for (i = 0; i < len; i++) {
- snprintf(buf + offset, 3, "%02"PRIx8, hash[i]);
- offset += 2;
- }
- buf[offset] = '\n';
- buf[offset+1] = 0;
-
- avio_write(s->pb, buf, strlen(buf));
- avio_flush(s->pb);
-}
-
#define OFFSET(x) offsetof(struct HashContext, x)
#define ENC AV_OPT_FLAG_ENCODING_PARAM
#if CONFIG_HASH_MUXER || CONFIG_FRAMEHASH_MUXER
@@ -92,11 +73,12 @@ static int hash_write_packet(struct AVFormatContext *s, AVPacket *pkt)
static int hash_write_trailer(struct AVFormatContext *s)
{
struct HashContext *c = s->priv_data;
- char buf[256];
- av_strlcpy(buf, av_hash_get_name(c->hash), sizeof(buf) - 200);
- av_strlcat(buf, "=", sizeof(buf) - 200);
+ char buf[AV_HASH_MAX_SIZE*2+128];
+ snprintf(buf, sizeof(buf) - 200, "%s=", av_hash_get_name(c->hash));
- hash_finish(s, buf);
+ av_hash_final_hex(c->hash, buf + strlen(buf), sizeof(buf) - strlen(buf));
+ av_strlcatf(buf, sizeof(buf), "\n");
+ avio_write(s->pb, buf, strlen(buf));
av_hash_freep(&c->hash);
return 0;