!3316 新增解码的MD5值比对代码优化

Merge pull request !3316 from 梅梦婷/master
This commit is contained in:
openharmony_ci 2024-09-10 12:24:54 +00:00 committed by Gitee
commit 1dc63c0a8a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 232 additions and 47 deletions

View File

@ -0,0 +1,74 @@
{
"1104x622.h264": {
"nv12": "20,da,42,fd,b1,ee,94,5c,cb,31,e0,28,57,4a,0e,fb,21,cd,7f,31,67,a0,a1,ea,ba,2f,3e,5b,bc,9f,2c,ae,34,ca,84,b8,34,60,28,93,20,ce,a0,38,e8,65,69,4c,4e,d9,3d,d6,ee,e6,75,6f,1f,e5,31,c4,71,d0,e6,18,",
"nv21": "66,5d,34,35,25,81,3c,2e,fc,4d,ee,c6,9f,8c,94,1d,db,19,35,dc,d0,86,74,5e,4e,ae,8d,4d,dc,19,37,63,7c,8b,9d,d1,68,91,de,43,52,88,ba,ba,fb,88,ad,ee,ca,16,85,c0,b9,07,0f,03,fd,9f,6b,df,fd,c2,5f,75,"
},
"1104x622.h265": {
"nv12": "94,52,8d,28,8a,77,ce,f8,9e,9e,90,4b,48,a2,46,65,a7,6f,2f,c5,ed,d2,29,d7,71,13,81,7b,d9,2d,3c,d1,2d,db,2e,8f,d3,ce,1d,eb,6e,cc,69,b3,a9,f3,21,b9,da,c1,9a,85,d5,79,9c,0f,3e,9f,e8,d0,b1,bd,a6,70,",
"nv21": "73,1a,5e,47,72,c6,ca,aa,81,18,f2,6f,aa,c9,72,d2,d9,c9,f6,4c,bc,f6,c7,19,45,7d,5c,d4,bd,33,f8,7f,ed,d8,2b,86,28,ba,56,d3,48,49,d8,80,29,6e,bf,74,8c,52,a4,d1,59,7a,00,76,eb,a7,ad,e6,e1,3e,67,8c,"
},
"1280_720_30_10Mb.h264": {
"nv12": "03,20,64,97,44,28,73,86,de,ad,69,3d,f8,32,73,41,f4,df,27,df,a7,a2,c4,e1,be,44,68,a7,99,71,5a,2d,cf,e2,93,a4,85,51,ed,f4,1c,d3,7d,cd,be,fc,0c,19,c3,5e,f2,c8,c9,82,27,82,a3,61,eb,34,26,22,71,d1,",
"nv21": "be,9f,a5,cc,39,77,d0,8a,d2,38,4e,c3,f8,c7,fa,e7,28,d3,a3,9d,b4,08,e3,7f,ca,73,bc,98,48,ce,50,03,6b,f1,11,03,46,cf,9d,57,9f,d4,b8,15,3d,38,7d,17,31,3c,b3,6f,4a,85,09,7b,79,6c,7b,5c,ad,36,a6,e0,"
},
"1920_1080_10_30Mb.h264": {
"nv12": "d6,7b,ec,20,f7,f1,c9,c2,ad,0c,b3,9c,15,c2,2c,ce,4d,43,30,fe,80,e3,e8,12,6d,0a,0f,ae,81,d5,34,50,a1,fd,02,9c,36,f1,5e,18,02,4c,42,2e,f3,d5,49,85,d6,e8,b5,69,c4,79,f6,50,41,cb,af,a6,86,6a,e1,87,",
"nv21": "ec,4d,f5,ea,4e,d7,0d,b8,98,df,62,64,05,f4,03,5c,e8,23,be,89,d5,ac,c6,68,e9,4e,dc,6b,39,7b,ba,35,e9,cf,81,a5,d6,75,93,e3,7f,69,5c,43,10,79,c8,2d,67,70,66,69,fb,81,f1,bd,67,08,fb,0c,4c,41,99,0e,"
},
"1920_1080_20M_30.h265": {
"nv12": "05,58,c2,7e,93,bd,78,59,6a,4e,c0,6c,0b,2b,55,ed,7e,dd,cb,54,b7,d6,88,ff,11,0c,cb,7e,32,0f,b1,1b,f8,ec,e0,52,96,a2,e7,b8,75,ea,b0,c1,95,e6,b0,96,6e,c1,8f,04,d2,a7,d3,23,2d,a1,f4,72,8e,54,d2,1a,",
"nv21": "b3,d3,6e,5b,2b,9b,7e,e4,ba,74,3e,8d,79,2c,d6,c0,f4,73,31,1e,ca,c5,b3,de,28,26,f3,5d,13,d7,c6,35,e9,95,e8,b9,ef,82,01,b1,d0,2c,71,5a,e4,4d,ff,bc,2e,03,6e,3b,87,d2,ec,3c,c1,69,67,f2,b1,ea,3b,6e,"
},
"1920x1080.h264": {
"nv12": "9e,1c,4a,6c,99,aa,d0,48,26,f4,ce,e8,ae,a6,02,20,82,24,f0,17,1e,87,cb,f8,be,df,f1,a0,76,a0,f6,98,a8,71,56,c9,47,56,77,c3,42,ad,70,9b,7c,27,37,f4,06,6e,2a,4d,30,c4,37,56,c7,6c,50,11,10,84,cd,50,",
"nv21": "72,76,11,87,49,0c,c7,e9,a4,28,85,fa,7b,ba,ca,c9,00,da,38,da,4c,d8,7f,b2,35,ef,44,4d,20,6e,cb,f3,21,e1,5c,fd,fd,54,f9,81,50,e9,6d,fd,e9,f6,b9,9d,80,0f,c1,25,db,5a,ca,48,31,20,d0,0b,1b,ff,61,f6,"
},
"1920x1080.h265": {
"nv12": "e6,c9,85,cb,a1,9f,f7,8d,ac,89,44,87,04,91,66,14,b0,69,51,df,5e,49,74,8d,be,5a,20,a5,1c,e7,16,d1,08,29,50,30,c9,51,de,0f,46,13,0c,b9,69,7f,4b,70,e1,87,f9,48,66,26,b8,ca,a4,32,4e,25,63,a2,16,be,",
"nv21": "dc,96,7f,73,54,8f,66,52,3c,0a,c6,37,b0,f4,b9,d2,1d,2b,6f,7b,77,0c,f6,f8,a8,86,dc,dc,a0,05,1c,b6,d1,bc,ab,ca,85,c1,aa,7f,ad,3a,45,07,d4,22,95,fa,ad,86,d6,d0,65,a4,0f,42,6a,e5,15,30,94,03,48,f0,"
},
"3840x2160.h264": {
"nv12": "00,de,5b,80,55,3f,92,94,67,45,b5,9d,6c,4b,06,18,75,3f,31,08,76,b7,6b,73,e0,b3,28,f4,c6,00,0c,ca,e1,cd,36,c5,2d,6a,69,f1,8e,6e,54,98,c6,69,3e,5c,d1,4f,35,90,7e,c8,8e,12,1e,fa,87,0b,ba,16,d3,fe,",
"nv21": "b1,ef,e1,9e,e1,b5,a0,a3,12,1c,95,bf,81,21,ff,9b,e0,93,3e,ff,ee,fc,df,fe,2d,95,42,34,92,8e,08,6c,62,f0,0f,b3,a0,7f,99,4b,b7,27,2b,36,24,e3,29,b0,7d,ab,b5,b8,8b,73,55,1e,0f,d0,a2,60,83,88,da,3f,"
},
"3840x2160.h265": {
"nv12": "89,cf,84,13,d5,0e,c6,e9,0a,bb,39,d2,a1,2c,ee,8e,ae,64,30,1b,85,f4,f0,11,e4,0c,fb,3a,69,28,1a,73,a2,ed,25,b6,4d,67,09,27,02,85,5a,c7,93,38,88,e0,fd,36,2d,2e,a8,ce,f9,e7,7e,a5,d1,fa,a1,d0,4e,b7,",
"nv21": "15,ef,ac,7b,98,15,37,d2,af,db,61,28,90,1d,ba,1b,2c,ae,d1,11,67,0e,45,ba,6b,9a,34,e4,23,82,f3,ba,7b,88,1d,7c,33,89,84,e7,c9,c1,e9,97,1f,8b,88,b1,a2,60,89,e8,83,7d,2e,64,30,b9,8c,30,ff,42,46,c1,"
},
"hdr10.h265": {
"nv12": "e2,e6,91,9b,63,c2,ed,69,59,e4,a9,51,f0,5a,91,1c,dd,d5,6e,24,9d,de,3f,84,46,6c,d5,af,42,f0,49,f3,b4,42,e2,93,92,7d,27,60,d9,0b,6e,1a,a3,a3,e4,2e,08,f0,ba,67,a1,e1,bb,e7,a6,0e,e8,eb,8e,08,fb,b4,",
"nv21": "c9,a7,af,66,aa,bd,33,93,28,55,ab,42,da,49,31,02,f5,2d,2e,78,0b,c5,35,c6,bc,c8,f7,4b,1c,67,fe,3c,a5,d8,a8,1d,6c,3c,9a,2f,af,92,e6,f0,02,48,08,7a,65,46,54,d0,a2,5e,b1,f9,7f,66,1f,c7,77,ad,2f,88,"
},
"hlg.h265": {
"nv12": "59,22,ef,a2,5c,4d,56,5b,0d,79,ca,83,51,c6,59,c1,7a,60,a5,0e,65,0f,53,d0,14,69,ce,f3,8e,96,b8,e5,bc,d3,41,09,13,cc,55,9b,69,d7,f8,95,dd,8d,f9,1d,45,6b,f1,20,ec,8f,27,9e,93,0e,87,87,3f,ab,e5,ac,",
"nv21": "30,bc,d0,80,2d,ad,53,26,ef,5c,86,30,24,66,8c,dd,d3,16,1a,87,5d,b7,eb,3b,ca,72,71,f2,e7,d5,23,61,4d,30,0e,0c,50,73,c6,cc,b4,0a,fa,2b,ee,ed,f4,ad,f6,83,3a,2e,91,3c,fa,6f,3e,fa,b4,c3,cd,2f,78,f9,"
},
"hlg_vivid_4k.h265": {
"nv12": "ab,6a,31,e4,6d,1f,d3,d0,9e,f3,17,5d,ba,45,75,dc,21,cd,19,f6,63,dd,2a,89,8a,82,74,00,cd,45,b4,c8,05,c3,d7,5f,55,25,5e,3f,95,60,f6,25,60,d1,c4,f5,56,42,43,de,00,a7,cd,09,7a,0f,7a,38,38,ca,02,50,",
"nv21": "be,d2,68,5e,e3,f2,bd,70,6c,c7,78,ea,16,20,63,d2,f1,e0,0d,10,24,84,e3,e8,3d,ef,01,51,18,e5,b5,ee,54,ff,19,6d,8e,86,ca,50,e0,73,4d,b6,4e,77,93,aa,48,84,6a,b1,53,7c,a9,37,63,0b,e7,e3,1f,54,75,ce,"
},
"hlg_vivid_1080p.h265": {
"nv12": "8b,d2,23,00,6e,98,62,88,b0,4f,d2,41,fc,a9,ab,bb,26,bd,69,8e,31,45,3e,4d,8a,99,ad,ff,ce,0f,27,39,8d,f0,52,d7,87,c5,12,14,39,5f,5c,6d,08,97,50,0a,d1,af,77,3a,26,e1,f3,87,d3,9e,ab,81,65,5d,bf,7d,",
"nv21": "2a,d6,82,68,58,ab,41,fd,8e,f8,27,d9,0c,67,f6,60,d8,dc,4c,f1,f6,72,7f,e7,7a,bf,d0,94,b6,84,80,17,e6,a1,aa,f4,57,43,dc,9b,8b,71,db,c5,95,f5,aa,f9,4c,54,61,4b,4b,a1,31,00,60,6e,24,60,a9,a2,2a,22,"
},
"hlgHdrVivid_4k.h265": {
"nv12": "38,eb,55,a8,9d,65,3c,ad,33,9b,c4,58,a9,a9,25,f3,cc,0f,f4,6a,73,0f,75,dd,91,4e,ff,71,f0,4b,c9,b4,73,8b,7b,fa,1c,f2,9b,99,c3,31,45,3f,42,15,fd,57,ee,a8,88,0f,4a,bd,a6,07,90,43,b0,80,4f,e2,ed,0e,",
"nv21": "78,d4,96,31,b8,8c,73,ab,73,7b,a6,d6,9f,9e,6a,c4,48,ee,8c,9e,49,9c,5f,c3,5d,2a,e6,de,e6,ca,b5,5a,42,8d,bb,17,53,cb,f3,e2,8d,f5,5f,85,df,e7,6b,b4,7c,7c,f3,83,b5,d2,60,86,e1,37,48,0e,d1,44,8b,1f,"
},
"hlgHdrVivid_1080p.h265": {
"nv12": "df,46,ad,4d,a0,0c,c4,f3,3c,40,30,71,6f,cd,72,ca,d7,07,a3,ca,73,4d,97,26,ad,90,61,db,e2,f4,ee,c0,9b,d7,2f,3a,af,a8,ea,fc,eb,cc,58,60,15,90,1c,37,8e,1e,5b,cc,bf,74,22,3c,e7,c7,19,38,b1,37,a5,f7,",
"nv21": "8f,7f,8a,80,45,a4,ca,f2,87,6b,42,4b,db,98,7c,40,b0,07,dd,53,a8,e4,c1,ff,01,85,f2,25,2b,b0,28,62,9f,71,2f,d6,06,4e,7d,e2,d7,12,b5,38,fc,d8,b1,9b,3a,d8,22,97,83,fa,df,42,b4,51,54,0d,e5,cf,3f,6b,"
},
"pq_vivid.h265": {
"nv12": "ba,54,41,18,0a,3e,df,3b,f1,d0,18,e0,02,dd,49,82,09,77,62,73,23,03,3c,42,c2,b5,ab,62,dc,da,db,04,84,c5,0d,1c,24,d1,71,84,2d,05,82,fe,e1,01,5d,6c,f1,82,27,81,51,c6,54,38,f1,95,6c,6e,87,ae,ae,32,",
"nv21": "86,7f,f7,44,a6,17,ca,f9,28,0f,d4,d8,93,9e,36,53,cc,dd,c4,ea,8a,28,04,c6,66,62,8f,3e,ed,fd,5e,27,11,b9,5c,fb,18,94,38,aa,d7,19,88,63,2f,05,eb,77,50,01,84,fe,73,34,d7,dd,0a,99,e7,91,86,0c,e2,ed,"
},
"pqHdrVivid_4k.h265": {
"nv12": "96,5a,8f,84,ca,70,14,ea,ea,99,76,29,b4,c6,0a,49,a9,cf,4d,95,1b,e3,94,70,09,64,ad,34,73,40,8b,3f,72,4e,70,a2,29,15,b0,ba,c2,88,f2,93,f6,ef,0f,c5,43,b3,f9,0f,68,22,98,fa,9a,ce,8a,aa,33,2d,ca,b0,",
"nv21": "8d,35,e3,e0,a1,65,99,9f,ad,e4,f8,3f,70,1d,da,08,30,74,9d,8c,b4,b6,76,d9,66,b4,d9,2c,7d,5f,12,2f,b9,ec,d7,d8,0f,25,8f,6b,c0,11,be,71,06,f1,24,c7,17,e5,d3,b2,cb,10,5a,02,f8,e3,80,d8,61,66,5a,71,"
},
"resolutionChange.h264": {
"nv12": "96,1c,15,c9,ea,6d,80,a9,11,a6,e3,69,75,e5,c4,07,d0,0d,e0,eb,92,71,59,44,f0,e0,b8,73,06,31,85,da,49,fe,47,3e,60,54,55,e3,71,48,8f,a2,d4,6a,e8,fa,35,f4,10,38,5a,73,79,cc,9c,77,97,73,bd,2d,89,8d,",
"nv21": "12,24,7f,a4,4b,c9,1d,0f,f4,3e,54,ab,a3,35,ff,17,93,1a,89,d3,fc,48,69,2e,2a,0b,88,21,ed,83,18,69,d8,d2,59,e3,ea,c8,23,83,b9,70,6c,c8,78,84,8a,7a,f9,6a,bd,1d,16,84,5d,d6,a8,05,d7,7a,d1,12,3a,d0,"
}
}

View File

@ -24,6 +24,7 @@ hwdecoder_moduletest_native_include_dirs = [
"$MEDIA_ROOT_DIR/interfaces/inner_api/native",
"$MEDIA_ROOT_DIR/interfaces/kits/c",
"$MEDIA_ROOT_DIR/../../../third_party/openssl/ohos_lite/include",
"$MEDIA_ROOT_DIR/../../../third_party/json/include",
]
hwdecoder_moduletest_cflags = [

View File

@ -63,6 +63,7 @@ public:
bool TRANSFER_FLAG = false;
bool NV21_FLAG = false;
bool PREPARE_FLAG = true;
bool IS_FIRST_FRAME = true;
uint32_t DEFAULT_WIDTH = 1920;
uint32_t DEFAULT_HEIGHT = 1080;
uint32_t originalWidth = 0;
@ -88,11 +89,10 @@ public:
uint32_t expectCropBottom = 0;
uint32_t expectCropLeft = 0;
uint32_t expectCropRight = 0;
const char *fileSourcesha256[64] = {"27", "6D", "A2", "D4", "18", "21", "A5", "CD", "50", "F6", "DD", "CA", "46",
"32", "C3", "FE", "58", "FC", "BC", "51", "FD", "70", "C7", "D4", "E7", "4D",
"5C", "76", "E7", "71", "8A", "B3", "C0", "51", "84", "0A", "FA", "AF", "FA",
"DC", "7B", "C5", "26", "D1", "9A", "CA", "00", "DE", "FC", "C8", "4E", "34",
"C5", "9A", "43", "59", "85", "DC", "AC", "97", "A3", "FB", "23", "51"};
int32_t stride_ = 0;
int32_t sliceHeight_ = 0;
int32_t picWidth_ = 0;
int32_t picHeight_ = 0;
int32_t Start();
int32_t Stop();
@ -119,10 +119,11 @@ public:
int32_t PushData(uint32_t index, OH_AVBuffer *buffer);
int32_t CheckAndReturnBufferSize(OH_AVBuffer *buffer);
uint32_t SendData(uint32_t bufferSize, uint32_t index, OH_AVBuffer *buffer);
void ProcessOutputData(OH_AVBuffer *buffer, uint32_t index, int32_t size);
void ProcessOutputData(OH_AVBuffer *buffer, uint32_t index);
int32_t CheckAttrFlag(OH_AVCodecBufferAttr attr);
void OutputFunc();
void GetStride();
void InputFuncTest();
void InFuncTest();
void OutputFuncTest();
void ReleaseSignal();
void CreateSurface();
@ -132,7 +133,8 @@ public:
void StopOutloop();
bool IsRender();
void RenderOutAtTime(uint32_t index);
bool MdCompare(unsigned char *buffer, int len, const char *source[]);
bool MdCompare(uint8_t source[]);
std::vector<uint8_t> LoadHashFile();
VDecAPI11Signal *signal_;
uint32_t errCount = 0;
uint32_t outCount = 0;

View File

@ -15,12 +15,18 @@
#include <arpa/inet.h>
#include <sys/time.h>
#include <utility>
#include <vector>
#include <string>
#include <sstream>
#include "openssl/crypto.h"
#include "openssl/sha.h"
#include "videodec_api11_sample.h"
#include "nlohmann/json.hpp"
using namespace OHOS;
using namespace OHOS::Media;
using namespace std;
using namespace nlohmann;
namespace {
constexpr int64_t NANOS_IN_SECOND = 1000000000L;
constexpr int64_t MICRO_IN_SECOND = 1000000L;
@ -43,8 +49,9 @@ constexpr int32_t CROP_INFO[RES_CHANGE_TIME][CROP_INFO_SIZE] = {{621, 1103},
constexpr int32_t CROP_BOTTOM = 0;
constexpr int32_t CROP_RIGHT = 1;
constexpr int32_t DEFAULT_ANGLE = 90;
SHA512_CTX g_c;
unsigned char g_md[SHA512_DIGEST_LENGTH];
uint8_t g_md[SHA512_DIGEST_LENGTH];
VDecAPI11Sample *dec_sample = nullptr;
void clearIntqueue(std::queue<uint32_t> &q)
@ -104,20 +111,28 @@ void VdecAPI11FormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userDa
{
int32_t currentWidth = 0;
int32_t currentHeight = 0;
int32_t stride = 0;
int32_t sliceHeight = 0;
int32_t picWidth = 0;
int32_t picHeight = 0;
OH_AVFormat_GetIntValue(format, OH_MD_KEY_WIDTH, &currentWidth);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_HEIGHT, &currentHeight);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &stride);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &sliceHeight);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_PIC_WIDTH, &picWidth);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_PIC_HEIGHT, &picHeight);
dec_sample->DEFAULT_WIDTH = currentWidth;
dec_sample->DEFAULT_HEIGHT = currentHeight;
dec_sample->stride_ = stride;
dec_sample->sliceHeight_ = sliceHeight;
dec_sample->picWidth_ = picWidth;
dec_sample->picHeight_ = picHeight;
if (dec_sample->isResChangeStream) {
static int32_t resCount = 0;
int32_t cropBottom = 0;
int32_t cropRight = 0;
int32_t stride = 0;
int32_t sliceHeight = 0;
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_CROP_BOTTOM, &cropBottom);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_CROP_RIGHT, &cropRight);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &stride);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &sliceHeight);
if (cropBottom != CROP_INFO[resCount][CROP_BOTTOM] || cropRight != CROP_INFO[resCount][CROP_RIGHT]) {
dec_sample->errCount++;
}
@ -199,12 +214,60 @@ void VDecAPI11Sample::Flush_buffer()
outLock.unlock();
}
bool VDecAPI11Sample::MdCompare(unsigned char buffer[], int len, const char *source[])
std::vector<uint8_t> VDecAPI11Sample::LoadHashFile()
{
bool result = true;
for (int i = 0; i < len; i++) {
std::ifstream f("/data/test/media/hash_val.json", ios::in);
std::vector<uint8_t> ret;
if (f) {
json data = json::parse(f);
filesystem::path filePath = INP_DIR;
std::string pixFmt = defualtPixelFormat == AV_PIXEL_FORMAT_NV12 ? "nv12" : "nv21";
std::string fileName = filePath.filename();
std::string hashValue = data[fileName.c_str()][pixFmt];
std::stringstream ss(hashValue);
std::string item;
while (getline(ss, item, ',')) {
if (!item.empty()) {
ret.push_back(stol(item, nullptr, SIXTEEN));
}
}
}
return result;
return ret;
}
static void DumpHashValue(std::vector<uint8_t> &srcHashVal, uint8_t outputHashVal[])
{
printf("-----------output hash value-----------\n");
for (int i = 1; i < SHA512_DIGEST_LENGTH + 1; i++) {
printf("%02x,", outputHashVal[i - 1]);
if (i % SIXTEEN == 0) {
printf("\n");
}
}
printf("-----------standard hash value-----------\n");
for (int i = 1; i < SHA512_DIGEST_LENGTH + 1; i++) {
printf("%02x,", srcHashVal[i - 1]);
if (i % SIXTEEN == 0) {
printf("\n");
}
}
}
bool VDecAPI11Sample::MdCompare(uint8_t source[])
{
std::vector<uint8_t> srcHashVal = LoadHashFile();
DumpHashValue(srcHashVal, source);
if (srcHashVal.size() != SHA512_DIGEST_LENGTH) {
cout << "get hash value failed, size " << srcHashVal.size() << endl;
return false;
}
for (int32_t i = 0; i < SHA512_DIGEST_LENGTH; i++) {
if (source[i] != srcHashVal[i]) {
cout << "decoded hash value mismatch" << endl;
return false;
}
}
return true;
}
int64_t VDecAPI11Sample::GetSystemTimeUs()
@ -235,7 +298,7 @@ int32_t VDecAPI11Sample::ConfigureVideoDecoder()
originalHeight = DEFAULT_HEIGHT;
(void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
(void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
(void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
(void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, defualtPixelFormat);
(void)OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
if (useHDRSource) {
(void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PROFILE, DEFAULT_PROFILE);
@ -500,6 +563,24 @@ void VDecAPI11Sample::WaitForEOS()
}
}
void VDecAPI11Sample::InFuncTest()
{
if (REPEAT_START_FLUSH_BEFORE_EOS > 0) {
REPEAT_START_FLUSH_BEFORE_EOS--;
OH_VideoDecoder_Flush(vdec_);
Flush_buffer();
OH_VideoDecoder_Start(vdec_);
}
if (REPEAT_START_STOP_BEFORE_EOS > 0) {
REPEAT_START_STOP_BEFORE_EOS--;
OH_VideoDecoder_Stop(vdec_);
Flush_buffer();
inFile_->clear();
inFile_->seekg(0, ios::beg);
OH_VideoDecoder_Start(vdec_);
}
}
void VDecAPI11Sample::InputFuncTest()
{
bool flag = true;
@ -508,18 +589,7 @@ void VDecAPI11Sample::InputFuncTest()
flag = false;
break;
}
if (REPEAT_START_FLUSH_BEFORE_EOS > 0) {
REPEAT_START_FLUSH_BEFORE_EOS--;
OH_VideoDecoder_Flush(vdec_);
Flush_buffer();
OH_VideoDecoder_Start(vdec_);
}
if (REPEAT_START_STOP_BEFORE_EOS > 0) {
REPEAT_START_STOP_BEFORE_EOS--;
OH_VideoDecoder_Stop(vdec_);
Flush_buffer();
OH_VideoDecoder_Start(vdec_);
}
InFuncTest();
uint32_t index;
unique_lock<mutex> lock(signal_->inMutex_);
signal_->inCond_.wait(lock, [this]() {
@ -708,8 +778,13 @@ void VDecAPI11Sample::AutoSwitchSurface()
OH_AVFormat_Destroy(format);
}
}
int32_t VDecAPI11Sample::CheckAttrFlag(OH_AVCodecBufferAttr attr)
{
if (IS_FIRST_FRAME) {
GetStride();
IS_FIRST_FRAME = false;
}
if (needCheckOutputDesc) {
CheckOutputDescription();
needCheckOutputDesc = false;
@ -719,7 +794,11 @@ int32_t VDecAPI11Sample::CheckAttrFlag(OH_AVCodecBufferAttr attr)
AutoSwitchSurface();
SHA512_Final(g_md, &g_c);
OPENSSL_cleanse(&g_c, sizeof(g_c));
MdCompare(g_md, SHA512_DIGEST_LENGTH, fileSourcesha256);
if (!SF_OUTPUT) {
if (!MdCompare(g_md)) {
errCount++;
}
}
return -1;
}
if (attr.flags == AVCODEC_BUFFER_FLAGS_CODEC_DATA) {
@ -729,6 +808,31 @@ int32_t VDecAPI11Sample::CheckAttrFlag(OH_AVCodecBufferAttr attr)
outFrameCount = outFrameCount + 1;
return 0;
}
void VDecAPI11Sample::GetStride()
{
OH_AVFormat *format = OH_VideoDecoder_GetOutputDescription(vdec_);
int32_t currentWidth = 0;
int32_t currentHeight = 0;
int32_t stride = 0;
int32_t sliceHeight = 0;
int32_t picWidth = 0;
int32_t picHeight = 0;
OH_AVFormat_GetIntValue(format, OH_MD_KEY_WIDTH, &currentWidth);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_HEIGHT, &currentHeight);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &stride);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &sliceHeight);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_PIC_WIDTH, &picWidth);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_PIC_HEIGHT, &picHeight);
dec_sample->DEFAULT_WIDTH = currentWidth;
dec_sample->DEFAULT_HEIGHT = currentHeight;
dec_sample->stride_ = stride;
dec_sample->sliceHeight_ = sliceHeight;
dec_sample->picWidth_ = picWidth;
dec_sample->picHeight_ = picHeight;
OH_AVFormat_Destroy(format);
}
void VDecAPI11Sample::OutputFuncTest()
{
FILE *outFile = nullptr;
@ -765,7 +869,7 @@ void VDecAPI11Sample::OutputFuncTest()
flag = false;
break;
}
ProcessOutputData(buffer, index, attr.size);
ProcessOutputData(buffer, index);
if (outFile != nullptr) {
fwrite(OH_AVBuffer_GetAddr(buffer), 1, attr.size, outFile);
}
@ -780,24 +884,28 @@ void VDecAPI11Sample::OutputFuncTest()
}
}
void VDecAPI11Sample::ProcessOutputData(OH_AVBuffer *buffer, uint32_t index, int32_t size)
void VDecAPI11Sample::ProcessOutputData(OH_AVBuffer *buffer, uint32_t index)
{
if (!SF_OUTPUT) {
if (size >= DEFAULT_WIDTH * DEFAULT_HEIGHT * THREE >> 1) {
uint8_t *cropBuffer = new uint8_t[size];
if (memcpy_s(cropBuffer, size, OH_AVBuffer_GetAddr(buffer),
DEFAULT_WIDTH * DEFAULT_HEIGHT) != EOK) {
cout << "Fatal: memory copy failed Y" << endl;
}
// copy UV
uint32_t uvSize = size - DEFAULT_WIDTH * DEFAULT_HEIGHT;
if (memcpy_s(cropBuffer + DEFAULT_WIDTH * DEFAULT_HEIGHT, uvSize,
OH_AVBuffer_GetAddr(buffer) + DEFAULT_WIDTH * DEFAULT_HEIGHT, uvSize) != EOK) {
cout << "Fatal: memory copy failed UV" << endl;
}
SHA512_Update(&g_c, cropBuffer, size);
delete[] cropBuffer;
uint8_t *bufferAddr = OH_AVBuffer_GetAddr(buffer);
uint32_t cropSize = (picWidth_ * picHeight_ * THREE) >> 1;
uint8_t *cropBuffer = new uint8_t[cropSize];
uint8_t *copyPos = cropBuffer;
//copy y
for (int32_t i = 0; i < picHeight_; i++) {
memcpy_s(copyPos, picWidth_, bufferAddr, picWidth_);
bufferAddr += stride_;
copyPos += picWidth_;
}
bufferAddr += (sliceHeight_ - picHeight_) * stride_;
//copy uv
for (int32_t i = 0; i < picHeight_ >> 1; i++) {
memcpy_s(copyPos, picWidth_, bufferAddr, picWidth_);
bufferAddr += stride_;
copyPos += picWidth_;
}
SHA512_Update(&g_c, cropBuffer, cropSize);
delete[] cropBuffer;
if (OH_VideoDecoder_FreeOutputBuffer(vdec_, index) != AV_ERR_OK) {
cout << "Fatal: ReleaseOutputBuffer fail" << endl;
errCount = errCount + 1;