Kaynağa Gözat

omx-il: upgrade omx unit test

1.open test case output file with wb+
2.video_dec_test add scale down option
3.video_enc_test add frame rate option
4.video_enc_test add gop option
5.flesh out help message

Signed-off-by: Som Qin <som.qin@starfivetech.com>
Som Qin 1 yıl önce
ebeveyn
işleme
3ee2881e94

+ 32 - 7
soft_3rdpart/omx-il/tests/dec_test.c

@@ -39,6 +39,8 @@ typedef struct DecodeTestContext
     char sOutputFilePath[64];
     char sInputFilePath[64];
     char sOutputFormat[64];
+    OMX_U32 ScaleWidth;
+    OMX_U32 ScaleHeight;
     OMX_BUFFERHEADERTYPE *pInputBufferArray[64];
     OMX_BUFFERHEADERTYPE *pOutputBufferArray[64];
     AVFormatContext *avContext;
@@ -95,7 +97,14 @@ static OMX_ERRORTYPE event_handler(
 
 static void help()
 {
-    printf("./omx_dec_test -i <input file> -o <output file> \r\n");
+    printf("video_dec_test - omx video hardware decode unit test case\r\n\r\n");
+    printf("Usage:\r\n\r\n");
+    printf("./video_dec_test -i <input file>      input file\r\n");
+    printf("                 -o <output file>     output file\r\n");
+    printf("                 -f <format>          i420/nv12/nv21\r\n");
+    printf("                 --scaleW=<width>     (optional) scale width down. ceil8(width/8) <= scaledW <= width\r\n");
+    printf("                 --scaleH=<heitht>    (optional) scale height down, ceil8(height/8) <= scaledH <= height\r\n\r\n");
+    printf("./video_dec_test --help: show this message\r\n");
 }
 
 static OMX_ERRORTYPE fill_output_buffer_done_handler(
@@ -177,6 +186,8 @@ static OMX_S32 FillInputBuffer(DecodeTestContext *decodeTestContext, OMX_BUFFERH
     }
     pInputBuffer->nFlags = 0x10;
     pInputBuffer->nFilledLen = avpacket.size;
+    if(!pInputBuffer->pBuffer || !avpacket.data)
+        return 0;
     memcpy(pInputBuffer->pBuffer, avpacket.data, avpacket.size);
     return avpacket.size;
 }
@@ -185,6 +196,7 @@ int main(int argc, char **argv)
 {
     printf("=============================\r\n");
     OMX_S32 error;
+    FILE *fb;
     decodeTestContext = malloc(sizeof(DecodeTestContext));
     memset(decodeTestContext, 0, sizeof(DecodeTestContext));
 
@@ -200,9 +212,12 @@ int main(int argc, char **argv)
         {"output", required_argument, NULL, 'o'},
         {"input", required_argument, NULL, 'i'},
         {"format", required_argument, NULL, 'f'},
+        {"scaleW", required_argument, NULL, 'w'},
+        {"scaleH", required_argument, NULL, 'h'},
+        {"help", no_argument, NULL, '0'},
         {NULL, no_argument, NULL, 0},
     };
-    char *shortOpt = "i:o:f:";
+    char *shortOpt = "i:o:f:w:h:";
     OMX_U32 c;
     OMX_S32 l;
 
@@ -236,7 +251,15 @@ int main(int argc, char **argv)
             printf("format: %s\r\n", optarg);
             memcpy(decodeTestContext->sOutputFormat, optarg, strlen(optarg));
             break;
+        case 'w':
+            printf("ScaleWidth: %s\r\n", optarg);
+            decodeTestContext->ScaleWidth = atoi(optarg);
+            break;
         case 'h':
+            printf("ScaleHeight: %s\r\n", optarg);
+            decodeTestContext->ScaleHeight = atoi(optarg);
+            break;
+        case '0':
         default:
             help();
             return -1;
@@ -327,8 +350,10 @@ int main(int argc, char **argv)
     OMX_INIT_STRUCTURE(pOutputPortDefinition);
     pOutputPortDefinition.nPortIndex = 1;
     OMX_GetParameter(decodeTestContext->hComponentDecoder, OMX_IndexParamPortDefinition, &pOutputPortDefinition);
-    pOutputPortDefinition.format.video.nFrameWidth = codecParameters->width;
-    pOutputPortDefinition.format.video.nFrameHeight = codecParameters->height;
+    pOutputPortDefinition.format.video.nFrameWidth
+                = decodeTestContext->ScaleWidth? decodeTestContext->ScaleWidth:codecParameters->width;
+    pOutputPortDefinition.format.video.nFrameHeight
+                = decodeTestContext->ScaleHeight? decodeTestContext->ScaleHeight:codecParameters->height;
     if (strstr(decodeTestContext->sOutputFormat, "nv12") != NULL)
     {
         pOutputPortDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
@@ -372,6 +397,8 @@ int main(int argc, char **argv)
         OMX_EmptyThisBuffer(hComponentDecoder, pBuffer);
     }
 
+    fb = fopen(decodeTestContext->sOutputFilePath, "wb+");
+
     OMX_SendCommand(hComponentDecoder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
 
     /*wait until decode finished*/
@@ -395,10 +422,7 @@ int main(int argc, char **argv)
         case 1:
         {
             OMX_BUFFERHEADERTYPE *pBuffer = data.pBuffer;
-            OMX_STRING sFilePath = decodeTestContext->sOutputFilePath;
-            FILE *fb = fopen(sFilePath, "ab+");
             fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
-            fclose(fb);
             if ((pBuffer->nFlags) & (OMX_BUFFERFLAG_EOS == OMX_BUFFERFLAG_EOS))
             {
                 goto end;
@@ -418,6 +442,7 @@ int main(int argc, char **argv)
 
 end:
     /*free resource*/
+    fclose(fb);
     OMX_FreeHandle(hComponentDecoder);
     OMX_Deinit();
 }

+ 45 - 9
soft_3rdpart/omx-il/tests/enc_test.c

@@ -45,6 +45,8 @@ typedef struct EncodeTestContext
     char sOutputFormat[64];
     OMX_U32 nFrameBufferSize;
     OMX_U32 nBitrate;
+    OMX_U32 nFrameRate;
+    OMX_U32 nNumPFrame;
     OMX_BUFFERHEADERTYPE *pInputBufferArray[64];
     OMX_BUFFERHEADERTYPE *pOutputBufferArray[64];
     int msgid;
@@ -100,8 +102,18 @@ static OMX_ERRORTYPE event_handler(
 
 static void help()
 {
-    printf("./video_enc_test -i <input file> -o <output file> -w <width> -h <height> "
-           "-c <yuv/nv12/nv21> -s <h264/h265> -b <bitrate>\r\n");
+    printf("video_enc_test - omx video hardware encode unit test case\r\n\r\n");
+    printf("Usage:\r\n\r\n");
+    printf("./video_enc_test -i <input file>       input file \r\n");
+    printf("                 -o <output file>      output file \r\n");
+    printf("                 -w <width>            input width \r\n");
+    printf("                 -h <height>           input hight \r\n");
+    printf("                 -s <Srcformat>        stream format h264/h265 \r\n");
+    printf("                 -c <cformat>          color format i420/nv12/nv21 \r\n");
+    printf("                 -b <bitrate>          (optional) set bit rate \r\n");
+    printf("                 -v <frame rate>       (optional) set frame rate \r\n");
+    printf("                 -g <num>              (optional) Number of P frames between each I frame for h264 only \r\n\r\n");
+    printf("./video_enc_test --help: show this message\r\n");
 }
 
 static OMX_ERRORTYPE fill_output_buffer_done_handler(
@@ -195,6 +207,7 @@ static OMX_S32 FillInputBuffer(EncodeTestContext *encodeTestContext, OMX_BUFFERH
 
 int main(int argc, char **argv)
 {
+    FILE *fb;
     printf("=============================\r\n");
     encodeTestContext = malloc(sizeof(EncodeTestContext));
     memset(encodeTestContext, 0, sizeof(EncodeTestContext));
@@ -210,14 +223,17 @@ int main(int argc, char **argv)
     struct option longOpt[] = {
         {"output", required_argument, NULL, 'o'},
         {"input", required_argument, NULL, 'f'},
-        {"color format", required_argument, NULL, 'c'},
-        {"stream format", required_argument, NULL, 's'},
-        {"bit rate", optional_argument, NULL, 'b'},
+        {"colorformat", required_argument, NULL, 'c'},
+        {"streamformat", required_argument, NULL, 's'},
+        {"bitrate", required_argument, NULL, 'b'},
+        {"framerate", required_argument, NULL, 'v'},
         {"width", required_argument, NULL, 'w'},
         {"height", required_argument, NULL, 'h'},
+        {"gop", required_argument, NULL, 'g'},
+        {"help", no_argument, NULL, 0},
         {NULL, no_argument, NULL, 0},
     };
-    char *shortOpt = "i:o:f:s:w:h:b:c:";
+    char *shortOpt = "i:o:f:s:w:h:b:v:c:g:";
     OMX_U32 c;
     OMX_S32 l;
 
@@ -269,6 +285,15 @@ int main(int argc, char **argv)
             printf("bit rate: %s\r\n", optarg);
             encodeTestContext->nBitrate = atoi(optarg);
             break;
+        case 'v':
+            printf("frame rate: %s\r\n", optarg);
+            encodeTestContext->nFrameRate = atoi(optarg);
+            break;
+        case 'g':
+            printf("P frames: %s\r\n", optarg);
+            encodeTestContext->nNumPFrame = atoi(optarg);
+            break;
+        case 0:
         default:
             help();
             return 0;
@@ -340,6 +365,9 @@ int main(int argc, char **argv)
         printf("unsupported color format: %s\r\n", encodeTestContext->sInputFormat);
         goto end;
     }
+    if(encodeTestContext->nFrameRate){
+        pInputPortDefinition.format.video.xFramerate = encodeTestContext->nFrameRate;
+    }
     OMX_SetParameter(hComponentEncoder, OMX_IndexParamPortDefinition, &pInputPortDefinition);
     OMX_GetParameter(hComponentEncoder, OMX_IndexParamPortDefinition, &pInputPortDefinition);
 
@@ -352,6 +380,15 @@ int main(int argc, char **argv)
     pOutputPortDefinition.format.video.nBitrate = encodeTestContext->nBitrate;
     OMX_SetParameter(hComponentEncoder, OMX_IndexParamPortDefinition, &pOutputPortDefinition);
 
+    if(encodeTestContext->nNumPFrame){
+        OMX_VIDEO_PARAM_AVCTYPE avcType;
+        OMX_INIT_STRUCTURE(avcType);
+        avcType.nPortIndex = 1;
+        OMX_GetParameter(hComponentEncoder, OMX_IndexParamVideoAvc, &avcType);
+        avcType.nPFrames = encodeTestContext->nNumPFrame;
+        OMX_SetParameter(hComponentEncoder, OMX_IndexParamVideoAvc, &avcType);
+    }
+
     /*Alloc input buffer*/
     OMX_U32 nInputBufferSize = pInputPortDefinition.nBufferSize;
     OMX_U32 nInputBufferCount = pInputPortDefinition.nBufferCountActual;
@@ -367,6 +404,7 @@ int main(int argc, char **argv)
         FillInputBuffer(encodeTestContext, pBuffer);
         OMX_EmptyThisBuffer(hComponentEncoder, pBuffer);
     }
+    fb = fopen(encodeTestContext->sOutputFilePath, "wb+");
 
     OMX_SendCommand(hComponentEncoder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
 
@@ -391,10 +429,7 @@ int main(int argc, char **argv)
         case 1:
         {
             OMX_BUFFERHEADERTYPE *pBuffer = data.pBuffer;
-            OMX_STRING sFilePath = encodeTestContext->sOutputFilePath;
-            FILE *fb = fopen(sFilePath, "ab+");
             fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
-            fclose(fb);
             if ((pBuffer->nFlags) & (OMX_BUFFERFLAG_EOS == OMX_BUFFERFLAG_EOS))
             {
                 goto end;
@@ -414,6 +449,7 @@ int main(int argc, char **argv)
 
 end:
     /*free resource*/
+    fclose(fb);
     fclose(encodeTestContext->pInputFile);
     OMX_FreeHandle(hComponentEncoder);
     OMX_Deinit();

+ 23 - 6
soft_3rdpart/omx-il/tests/mjpeg_dec_test.c

@@ -105,7 +105,17 @@ static OMX_ERRORTYPE event_handler(
 
 static void help()
 {
-    printf("./omx_mjpeg_dec_test -i <input file> -o <output file> \r\n");
+    printf("omx_mjpeg_dec_test - omx mjpg hardware decode unit test case\r\n\r\n");
+    printf("Usage:\r\n\r\n");
+    printf("./omx_mjpeg_dec_test -i <input file>               input file \r\n");
+    printf("                     -o <output file>              output file\r\n");
+    printf("                     -f <format>                   nv12/nv21/i420/i422/nv16/nv61/yuyv/yvyu/uyvy/vyuy/i444/yuv444packed \r\n");
+    printf("                     --roi=<x>,<y>,<w>,<h>         (optional) roi coord and width/height(from left top)\r\n");
+    printf("                     --mirror=<0/1/2/3>            (optional) mirror 0(none), 1(V), 2(H), 3(VH)\r\n");
+    printf("                     --scaleH=<0/1/2/3>            (optional) Horizontal downscale: 0(none), 1(1/2), 2(1/4), 3(1/8)\r\n");
+    printf("                     --scaleV=<0/1/2/3>            (optional) Vertical downscale  : 0(none), 1(1/2), 2(1/4), 3(1/8)\r\n");
+    printf("                     --rotation=<0/90/180/270>     (optional) rotation 0, 90, 180, 270\r\n\r\n");
+    printf("./omx_mjpeg_dec_test --help: show this message\r\n");
 }
 
 static OMX_ERRORTYPE fill_output_buffer_done_handler(
@@ -197,6 +207,7 @@ int main(int argc, char **argv)
 {
     printf("=============================\r\n");
     OMX_S32 error;
+    FILE *fb;
     decodeTestContext = malloc(sizeof(DecodeTestContext));
     memset(decodeTestContext, 0, sizeof(DecodeTestContext));
 
@@ -217,9 +228,10 @@ int main(int argc, char **argv)
         {"mirror", required_argument, NULL, 'm'},
         {"scaleH", required_argument, NULL, 'H'},
         {"scaleV", required_argument, NULL, 'V'},
+        {"help", no_argument, NULL, 0},
         {NULL, no_argument, NULL, 0},
     };
-    char *shortOpt = "i:o:f:c:r:m:";
+    char *shortOpt = "i:o:f:c:r:m:H:V:";
     OMX_U32 c;
     OMX_S32 l;
     OMX_STRING val;
@@ -255,6 +267,7 @@ int main(int argc, char **argv)
             memcpy(decodeTestContext->sOutputFormat, optarg, strlen(optarg));
             break;
         case 'c':
+            printf("ROI: %s\r\n", optarg);
             val = strtok(optarg, ",");
             if (val == NULL) {
                 printf("Invalid ROI option: %s\n", optarg);
@@ -289,18 +302,22 @@ int main(int argc, char **argv)
             }
             break;
         case 'r':
+            printf("rotation: %s\r\n", optarg);
             decodeTestContext->Rotation = atoi(optarg);
             break;
         case 'm':
+            printf("mirror: %s\r\n", optarg);
             decodeTestContext->Mirror = atoi(optarg);
             break;
         case 'H':
+            printf("scaleH: %s\r\n", optarg);
             decodeTestContext->ScaleFactorH = atoi(optarg);
             break;
         case 'V':
+            printf("scaleV: %s\r\n", optarg);
             decodeTestContext->ScaleFactorV = atoi(optarg);
             break;
-        case 'h':
+        case 0:
         default:
             help();
             return -1;
@@ -518,6 +535,8 @@ int main(int argc, char **argv)
         OMX_EmptyThisBuffer(hComponentDecoder, pBuffer);
     }
 
+    fb = fopen(decodeTestContext->sOutputFilePath, "wb+");
+
     OMX_SendCommand(hComponentDecoder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
 
     /*wait until decode finished*/
@@ -541,13 +560,10 @@ int main(int argc, char **argv)
         case 1:
         {
             OMX_BUFFERHEADERTYPE *pBuffer = data.pBuffer;
-            OMX_STRING sFilePath = decodeTestContext->sOutputFilePath;
             printf("write %lu buffers to file\r\n", pBuffer->nFilledLen);
-            FILE *fb = fopen(sFilePath, "ab+");
             size_t size = fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
             int error = ferror(fb);
             printf("write error = %d\r\n", error);
-            fclose(fb);
             printf("write %lu buffers finish\r\n", size);
             if ((pBuffer->nFlags) & (OMX_BUFFERFLAG_EOS == OMX_BUFFERFLAG_EOS))
             {
@@ -568,6 +584,7 @@ int main(int argc, char **argv)
 
 end:
     /*free resource*/
+    fclose(fb);
     OMX_FreeHandle(hComponentDecoder);
     OMX_Deinit();
 }