Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
decodeoutput: add built in md5 support
Browse files Browse the repository at this point in the history
the built in md5sum is slow than libbsd, so we will detect libbsd firstly
  • Loading branch information
xuguangxin authored and uartie committed May 9, 2018
1 parent 06f0e45 commit ebcb87e
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 34 deletions.
18 changes: 6 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ fi
AM_CONDITIONAL(ENABLE_AVFORMAT,
[test "x$enable_avformat" = "xyes"])

AC_ARG_ENABLE(md5,
[AC_HELP_STRING([--enable-md5], [enable generate md5 by per frame@<:@default=yes@:>@])],
[], [enable_md5="yes"])

dnl encoder getmv
AC_ARG_ENABLE(getmv,
[AC_HELP_STRING([--enable-getmv],
Expand Down Expand Up @@ -247,17 +243,15 @@ if test "$enable_avformat" = "yes"; then
PKG_CHECK_MODULES(LIBAVFORMAT, [libavformat libavcodec libavutil])
fi

#check openssl
if test "$enable_md5" = "yes"; then
PKG_CHECK_MODULES([LIBBSD], [libbsd],
[AC_DEFINE([__ENABLE_MD5__], [1],
[Defined to 1 if MD5 API and --enable-md5[default] are enabled])],
[])

PKG_CHECK_MODULES([LIBBSD], [libbsd], [have_bsd="yes"], [have_bsd="no"])
AM_CONDITIONAL([HAVE_LIBBSD], [test "x$have_bsd" = xyes])
if test "$have_bsd" = "yes"; then
AC_DEFINE(HAVE_LIBBSD, 1, [Define if libbsd is available])
fi

PKG_CHECK_MODULES([LIBYAMI], [libyami >= 0.5.2])

AM_CONDITIONAL(ENABLE_MD5, test "x$enable_md5" = "xyes")
PKG_CHECK_MODULES([LIBYAMI], [libyami >= 0.5.2])

# Checks for library functions.
AC_FUNC_MALLOC
Expand Down
4 changes: 2 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if ENABLE_EGL
YAMI_DECODE_LIBS += $(LIBEGL_LIBS) $(LIBGLES2_LIBS)
endif

if ENABLE_MD5
if HAVE_LIBBSD
YAMI_DECODE_LIBS += $(LIBBSD_LIBS)
endif

Expand Down Expand Up @@ -95,7 +95,7 @@ YAMI_VPP_CFLAGS = \

yamidecode_LDADD = $(YAMI_VPP_LIBS)
yamidecode_LDFLAGS = $(YAMI_VPP_LDFLAGS)
yamidecode_SOURCES = decode.cpp decodehelp.cpp $(DECODE_INPUT_SOURCES) decodeoutput.cpp vppinputoutput.cpp vppinputdecode.cpp vppoutputencode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp vppinputdecodecapi.cpp
yamidecode_SOURCES = decode.cpp decodehelp.cpp $(DECODE_INPUT_SOURCES) decodeoutput.cpp vppinputoutput.cpp vppinputdecode.cpp vppoutputencode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp vppinputdecodecapi.cpp md5.c
if ENABLE_EGL
yamidecode_SOURCES += ../egl/egl_util.c ./egl/gles2_help.c
endif
Expand Down
28 changes: 8 additions & 20 deletions tests/decodeoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@
#include "common/log.h"
#include "common/VaapiUtils.h"

#if __ENABLE_MD5__
// including bsd/md5.h produces a warning with __bounded__ attribute,
// libyami-utils chooses to ignore this particular warning by pushing the
// current environment, ignoring attributes and then poping to restore the
// environment.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#include <bsd/md5.h>
#pragma GCC diagnostic pop
#endif
extern "C" {
#include "md5.h"
}

#ifdef __ENABLE_X11__
#include <X11/Xlib.h>
Expand Down Expand Up @@ -333,7 +326,6 @@ bool DecodeOutputDump::output(const SharedPtr<VideoFrame>& frame)
return m_output->output(dest);
}

#if __ENABLE_MD5__
class DecodeOutputMD5 : public DecodeOutputFile {
public:
DecodeOutputMD5(const char* outputFile, const char* inputFile, uint32_t fourcc)
Expand Down Expand Up @@ -384,7 +376,7 @@ bool DecodeOutputMD5::setVideoSize(uint32_t width, uint32_t height)
//ERROR("fail to open input file: %s", name.c_str());
return false;
}
MD5Init(&m_fileMD5);
MD5_Init(&m_fileMD5);
return true;
}
return DecodeOutputFile::setVideoSize(width, height);
Expand All @@ -395,7 +387,7 @@ std::string DecodeOutputMD5::writeToFile(MD5_CTX& t_ctx)
char temp[4];
uint8_t result[16] = { 0 };
std::string strMD5;
MD5Final(result, &t_ctx);
MD5_Final(result, &t_ctx);
for(uint32_t i = 0; i < 16; i++) {
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%02x", (uint32_t)result[i]);
Expand Down Expand Up @@ -427,17 +419,15 @@ bool DecodeOutputMD5::output(const SharedPtr<VideoFrame>& frame)
return false;

MD5_CTX frameMD5;
MD5Init(&frameMD5);
MD5Update(&frameMD5, &m_data[0], m_data.size());
MD5_Init(&frameMD5);
MD5_Update(&frameMD5, &m_data[0], m_data.size());
writeToFile(frameMD5);

MD5Update(&m_fileMD5, &m_data[0], m_data.size());
MD5_Update(&m_fileMD5, &m_data[0], m_data.size());

return true;
}

#endif //__ENABLE_MD5__

#ifdef __ENABLE_X11__
class DecodeOutputX11 : public DecodeOutput
{
Expand Down Expand Up @@ -915,11 +905,9 @@ DecodeOutput* DecodeOutput::create(int renderMode, uint32_t fourcc, const char*
{
DecodeOutput* output;
switch (renderMode) {
#ifdef __ENABLE_MD5__
case -2:
output = new DecodeOutputMD5(outputFile, inputFile, fourcc);
break;
#endif //__ENABLE_MD5__
case -1:
output = new DecodeOutputNull();
break;
Expand Down

0 comments on commit ebcb87e

Please sign in to comment.