wave521test.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #include <stdio.h>
  6. #include <signal.h>
  7. #include <OMX_Core.h>
  8. #include <OMX_Component.h>
  9. #include <OMX_Video.h>
  10. #define OMX_INIT_STRUCTURE(a) \
  11. memset(&(a), 0, sizeof(a)); \
  12. (a).nSize = sizeof(a); \
  13. (a).nVersion.nVersion = 1; \
  14. (a).nVersion.s.nVersionMajor = 1; \
  15. (a).nVersion.s.nVersionMinor = 1; \
  16. (a).nVersion.s.nRevision = 1; \
  17. (a).nVersion.s.nStep = 1
  18. static OMX_ERRORTYPE event_handler(
  19. OMX_HANDLETYPE hComponent,
  20. OMX_PTR pAppData,
  21. OMX_EVENTTYPE eEvent,
  22. OMX_U32 nData1,
  23. OMX_U32 nData2,
  24. OMX_PTR pEventData)
  25. {
  26. return OMX_ErrorNone;
  27. }
  28. static OMX_ERRORTYPE fill_output_buffer_done_handler(
  29. OMX_HANDLETYPE hComponent,
  30. OMX_PTR pAppData,
  31. OMX_BUFFERHEADERTYPE *pBuffer)
  32. {
  33. return OMX_ErrorNone;
  34. }
  35. static void block_until_state_changed(OMX_HANDLETYPE hComponent, OMX_STATETYPE wanted_eState)
  36. {
  37. OMX_STATETYPE eState;
  38. while (eState != wanted_eState)
  39. {
  40. OMX_GetState(hComponent, &eState);
  41. if (eState != wanted_eState)
  42. {
  43. printf("state = %d\r\n", eState);
  44. usleep(1000 * 1000);
  45. }
  46. }
  47. }
  48. static int g_is_run = 0;
  49. static void signal_handle(int sig)
  50. {
  51. printf("[%s,%d]: receive sig=%d \n", __FUNCTION__, __LINE__, sig);
  52. if (g_is_run) {
  53. OMX_Deinit();
  54. g_is_run = 0;
  55. }
  56. }
  57. //TODO: callback, parameter, buffer
  58. int main(void)
  59. {
  60. printf("=============================\r\n");
  61. OMX_HANDLETYPE hComponentEncoder;
  62. OMX_HANDLETYPE hComponentFeeder;
  63. OMX_HANDLETYPE hComponentReader;
  64. OMX_CALLBACKTYPE callbacks;
  65. int ret = OMX_ErrorNone;
  66. signal(SIGINT, signal_handle);
  67. ret = OMX_Init();
  68. if (ret != OMX_ErrorNone) {
  69. printf("[%s,%d]: run OMX_Init failed. ret is %d \n", __FUNCTION__, __LINE__, ret);
  70. return 1;
  71. }
  72. g_is_run = 1;
  73. callbacks.EventHandler = event_handler;
  74. callbacks.FillBufferDone = fill_output_buffer_done_handler;
  75. OMX_GetHandle(&hComponentEncoder, "sf.enc.encoder", NULL, &callbacks);
  76. OMX_GetHandle(&hComponentFeeder, "sf.enc.feeder", NULL, &callbacks);
  77. OMX_GetHandle(&hComponentReader, "sf.enc.reader", NULL, &callbacks);
  78. if (hComponentEncoder == NULL || hComponentFeeder == NULL || hComponentReader == NULL)
  79. {
  80. printf("could not get handle\r\n");
  81. return 0;
  82. }
  83. OMX_SetParameter(hComponentFeeder, OMX_IndexConfigCommonInputCrop, "./yuv/mix_1920x1080_8b_9frm.yuv");
  84. OMX_SetParameter(hComponentReader, OMX_IndexConfigCommonOutputCrop, "./output/inter_8b_11.cfg.265");
  85. OMX_SetParameter(hComponentEncoder, OMX_IndexParamOtherPortFormat, "./cfg/hevc_fhd_inter_8b_11.cfg");
  86. OMX_SetParameter(hComponentFeeder, OMX_IndexParamOtherPortFormat, "./cfg/hevc_fhd_inter_8b_11.cfg");
  87. OMX_SetParameter(hComponentReader, OMX_IndexParamOtherPortFormat, "./cfg/hevc_fhd_inter_8b_11.cfg");
  88. OMX_SendCommand(hComponentEncoder, OMX_CommandStateSet, OMX_StateIdle, NULL);
  89. OMX_SendCommand(hComponentFeeder, OMX_CommandStateSet, OMX_StateIdle, NULL);
  90. OMX_SendCommand(hComponentReader, OMX_CommandStateSet, OMX_StateIdle, NULL);
  91. OMX_SetupTunnel(hComponentFeeder, 0, hComponentEncoder, 0);
  92. OMX_SetupTunnel(hComponentEncoder, 0, hComponentReader, 0);
  93. OMX_SendCommand(hComponentFeeder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
  94. OMX_SendCommand(hComponentEncoder, OMX_CommandStateSet, OMX_StateExecuting, NULL);
  95. OMX_SendCommand(hComponentReader, OMX_CommandStateSet, OMX_StateExecuting, NULL);
  96. block_until_state_changed(hComponentFeeder, OMX_StateIdle);
  97. block_until_state_changed(hComponentEncoder, OMX_StateIdle);
  98. block_until_state_changed(hComponentReader, OMX_StateIdle);
  99. OMX_FreeHandle(hComponentFeeder);
  100. OMX_FreeHandle(hComponentEncoder);
  101. OMX_FreeHandle(hComponentReader);
  102. OMX_Deinit();
  103. return 0;
  104. }