[FFmpeg-devel] [PATCH 2/3] lavf/hashenc: rename variables where appropriate
Moritz Barsnick
barsnick at gmx.net
Wed Mar 2 15:18:00 CET 2016
In preparation for duplication of muxers and functionality. Functions
which are applicable to md5 only - those which default to using the
MD5 hash algorithm - and will continue to do so keep their names.
What's more, the options array, which already carried "hash" in its
name instead of "md5", now gains an "md5" name, as it will continue
to exist in order to carry the same default option for the "legacy"
muxers.
Signed-off-by: Moritz Barsnick <barsnick at gmx.net>
---
libavformat/hashenc.c | 68 +++++++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index 8433be4..e4d308d 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -1,5 +1,5 @@
/*
- * MD5 encoder (for codec/format testing)
+ * Hash/MD5 encoder (for codec/format testing)
* Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
@@ -26,23 +26,23 @@
#include "avformat.h"
#include "internal.h"
-struct MD5Context {
+struct HashContext {
const AVClass *avclass;
struct AVHashContext *hash;
char *hash_name;
int format_version;
};
-static void md5_finish(struct AVFormatContext *s, char *buf)
+static void hash_finish(struct AVFormatContext *s, char *buf)
{
- struct MD5Context *c = s->priv_data;
- uint8_t md5[AV_HASH_MAX_SIZE];
+ 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(md5));
- av_hash_final(c->hash, md5);
+ 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, md5[i]);
+ snprintf(buf + offset, 3, "%02"PRIx8, hash[i]);
offset += 2;
}
buf[offset] = '\n';
@@ -52,9 +52,9 @@ static void md5_finish(struct AVFormatContext *s, char *buf)
avio_flush(s->pb);
}
-#define OFFSET(x) offsetof(struct MD5Context, x)
+#define OFFSET(x) offsetof(struct HashContext, x)
#define ENC AV_OPT_FLAG_ENCODING_PARAM
-static const AVOption hash_options[] = {
+static const AVOption md5_options[] = {
{ "hash", "set hash to use", OFFSET(hash_name), AV_OPT_TYPE_STRING, {.str = "md5"}, 0, 0, ENC },
{ "format_version", "file format version", OFFSET(format_version), AV_OPT_TYPE_INT, {.i64 = 1}, 1, 1, ENC },
{ NULL },
@@ -63,14 +63,14 @@ static const AVOption hash_options[] = {
static const AVClass md5enc_class = {
.class_name = "hash encoder class",
.item_name = av_default_item_name,
- .option = hash_options,
+ .option = md5_options,
.version = LIBAVUTIL_VERSION_INT,
};
#if CONFIG_MD5_MUXER
-static int write_header(struct AVFormatContext *s)
+static int hash_write_header(struct AVFormatContext *s)
{
- struct MD5Context *c = s->priv_data;
+ struct HashContext *c = s->priv_data;
int res = av_hash_alloc(&c->hash, c->hash_name);
if (res < 0)
return res;
@@ -78,21 +78,21 @@ static int write_header(struct AVFormatContext *s)
return 0;
}
-static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
+static int hash_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
- struct MD5Context *c = s->priv_data;
+ struct HashContext *c = s->priv_data;
av_hash_update(c->hash, pkt->data, pkt->size);
return 0;
}
-static int write_trailer(struct AVFormatContext *s)
+static int hash_write_trailer(struct AVFormatContext *s)
{
- struct MD5Context *c = s->priv_data;
+ 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);
- md5_finish(s, buf);
+ hash_finish(s, buf);
av_hash_freep(&c->hash);
return 0;
@@ -101,12 +101,12 @@ static int write_trailer(struct AVFormatContext *s)
AVOutputFormat ff_md5_muxer = {
.name = "md5",
.long_name = NULL_IF_CONFIG_SMALL("MD5 testing"),
- .priv_data_size = sizeof(struct MD5Context),
+ .priv_data_size = sizeof(struct HashContext),
.audio_codec = AV_CODEC_ID_PCM_S16LE,
.video_codec = AV_CODEC_ID_RAWVIDEO,
- .write_header = write_header,
- .write_packet = write_packet,
- .write_trailer = write_trailer,
+ .write_header = hash_write_header,
+ .write_packet = hash_write_packet,
+ .write_trailer = hash_write_trailer,
.flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
AVFMT_TS_NEGATIVE,
.priv_class = &md5enc_class,
@@ -114,9 +114,9 @@ AVOutputFormat ff_md5_muxer = {
#endif
#if CONFIG_FRAMEMD5_MUXER
-static int framemd5_write_header(struct AVFormatContext *s)
+static int framehash_write_header(struct AVFormatContext *s)
{
- struct MD5Context *c = s->priv_data;
+ struct HashContext *c = s->priv_data;
int res = av_hash_alloc(&c->hash, c->hash_name);
if (res < 0)
return res;
@@ -128,22 +128,22 @@ static int framemd5_write_header(struct AVFormatContext *s)
return 0;
}
-static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
- struct MD5Context *c = s->priv_data;
+ struct HashContext *c = s->priv_data;
char buf[256];
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, ",
pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
- md5_finish(s, buf);
+ hash_finish(s, buf);
return 0;
}
-static int framemd5_write_trailer(struct AVFormatContext *s)
+static int framehash_write_trailer(struct AVFormatContext *s)
{
- struct MD5Context *c = s->priv_data;
+ struct HashContext *c = s->priv_data;
av_hash_freep(&c->hash);
return 0;
}
@@ -151,19 +151,19 @@ static int framemd5_write_trailer(struct AVFormatContext *s)
static const AVClass framemd5_class = {
.class_name = "frame hash encoder class",
.item_name = av_default_item_name,
- .option = hash_options,
+ .option = md5_options,
.version = LIBAVUTIL_VERSION_INT,
};
AVOutputFormat ff_framemd5_muxer = {
.name = "framemd5",
.long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing"),
- .priv_data_size = sizeof(struct MD5Context),
+ .priv_data_size = sizeof(struct HashContext),
.audio_codec = AV_CODEC_ID_PCM_S16LE,
.video_codec = AV_CODEC_ID_RAWVIDEO,
- .write_header = framemd5_write_header,
- .write_packet = framemd5_write_packet,
- .write_trailer = framemd5_write_trailer,
+ .write_header = framehash_write_header,
+ .write_packet = framehash_write_packet,
+ .write_trailer = framehash_write_trailer,
.flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
AVFMT_TS_NEGATIVE,
.priv_class = &framemd5_class,
--
2.5.0
More information about the ffmpeg-devel
mailing list