Guest User

Untitled

a guest
Jul 25th, 2019
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if defined(__linux__) && defined(__arm__)
  2.  
  3. #include "OPENMAX_H264_DECODER.h"
  4.  
  5. void Initialize_OPENMAX_H264_DECODER(OPENMAX_H264_DECODER* decoder) {
  6. decoder->port_settings_changed = 0;
  7. decoder->first_packet = 1;
  8. decoder->Buffer = NULL;
  9. memset(decoder->List, 0, sizeof(decoder->List));
  10. memset(decoder->Tunnel, 0, sizeof(decoder->Tunnel));
  11. memset(&decoder->Format, 0, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
  12.  
  13. bcm_host_init();
  14.  
  15. //why is this zero? who knows...
  16. decoder->Display = vc_dispmanx_display_open(0);
  17.  
  18. if (vc_dispmanx_display_get_info(decoder->Display, &decoder->Info)) {
  19. return;
  20. }
  21.  
  22. decoder->Width = decoder->Info.width;
  23. decoder->Height = decoder->Info.height;
  24.  
  25. if((decoder->Client = ilclient_init()) == NULL) {
  26. return;
  27. }
  28. if (OMX_Init() != OMX_ErrorNone) {
  29. ilclient_destroy(decoder->Client);
  30. return;
  31. }
  32. if (
  33. ilclient_create_component(decoder->Client, &decoder->Video_Decode,
  34. "video_decode", ILCLIENT_CREATE_FLAGS_T(ILCLIENT_DISABLE_ALL_PORTS |
  35. ILCLIENT_ENABLE_INPUT_BUFFERS)) != 0) {
  36. return;
  37. }
  38. decoder->List[0] = decoder->Video_Decode;
  39.  
  40. if (ilclient_create_component(
  41. decoder->Client, &decoder->Video_Render, "video_render",
  42. ILCLIENT_DISABLE_ALL_PORTS) != 0) {
  43. return;
  44. }
  45. decoder->List[1] = decoder->Video_Render;
  46.  
  47. set_tunnel(
  48. decoder->Tunnel, decoder->Video_Decode, 131, decoder->Video_Render, 90);
  49.  
  50. ilclient_change_component_state(decoder->Video_Decode, OMX_StateIdle);
  51.  
  52. decoder->Format.nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE);
  53. decoder->Format.nVersion.nVersion = OMX_VERSION;
  54. decoder->Format.nPortIndex = 130;
  55. decoder->Format.eCompressionFormat = OMX_VIDEO_CodingAVC;
  56.  
  57. if (
  58. OMX_SetParameter(ILC_GET_HANDLE(decoder->Video_Decode),
  59. OMX_IndexParamVideoPortFormat, &decoder->Format) == OMX_ErrorNone &&
  60. ilclient_enable_port_buffers(decoder->Video_Decode, 130, NULL, NULL, NULL)
  61. == 0) {
  62. ilclient_change_component_state(
  63. decoder->Video_Decode, OMX_StateExecuting);
  64. }
  65. }
  66.  
  67. void Render_H264_Frame(OPENMAX_H264_DECODER* decoder, char* buffer, int size) {
  68. int process_size = 0;
  69. while (process_size < size) {
  70. decoder->Buffer = ilclient_get_input_buffer(
  71. decoder->Video_Decode, 130, 1);
  72.  
  73. if (decoder->Buffer != NULL) {
  74. // feed data and wait until we get port settings changed
  75. unsigned char *dest = decoder->Buffer->pBuffer;
  76.  
  77. copy(
  78. buffer + process_size, buffer + process_size +
  79. (((size - process_size) > decoder->Buffer->nAllocLen) ?
  80. decoder->Buffer->nAllocLen : (size - process_size)), dest);
  81.  
  82. if (decoder->port_settings_changed == 0) {
  83. if (ilclient_remove_event(decoder->Video_Decode,
  84. OMX_EventPortSettingsChanged, 131, 0, 0, 1) == 0) {
  85. decoder->port_settings_changed = 1;
  86.  
  87. if(ilclient_setup_tunnel(decoder->Tunnel, 0, 0) != 0) {
  88. return;
  89. }
  90.  
  91. ilclient_change_component_state(
  92. decoder->Video_Render, OMX_StateExecuting);
  93. }
  94. }
  95.  
  96. decoder->Buffer->nFilledLen = (
  97. ((size - process_size) > decoder->Buffer->nAllocLen) ?
  98. decoder->Buffer->nAllocLen : (size - process_size));
  99.  
  100. process_size += (
  101. ((size - process_size) > decoder->Buffer->nAllocLen) ?
  102. decoder->Buffer->nAllocLen : (size - process_size));
  103.  
  104. decoder->Buffer->nOffset = 0;
  105. if(decoder->first_packet) {
  106. decoder->Buffer->nFlags = OMX_BUFFERFLAG_STARTTIME;
  107. decoder->first_packet = 0;
  108. } else {
  109. decoder->Buffer->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN;
  110. }
  111.  
  112. if (
  113. OMX_EmptyThisBuffer(ILC_GET_HANDLE(decoder->Video_Decode),
  114. decoder->Buffer) != OMX_ErrorNone) {
  115. return;
  116. }
  117. }
  118. }
  119. }
  120.  
  121. void Delete_OPENMAX_H264_DECODER(OPENMAX_H264_DECODER* decoder) {
  122. if (decoder->Buffer != NULL) {
  123. decoder->Buffer->nFilledLen = 0;
  124. decoder->Buffer->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN |
  125. OMX_BUFFERFLAG_EOS;
  126.  
  127. if (
  128. OMX_EmptyThisBuffer(ILC_GET_HANDLE(decoder->Video_Decode),
  129. decoder->Buffer) != OMX_ErrorNone) { }
  130.  
  131. ilclient_wait_for_event(
  132. decoder->Video_Render, OMX_EventBufferFlag, 90, 0, OMX_BUFFERFLAG_EOS,
  133. 0, ILCLIENT_BUFFER_FLAG_EOS, -1);
  134.  
  135. ilclient_flush_tunnels(decoder->Tunnel, 0);
  136. }
  137. if (!vc_dispmanx_display_close(decoder->Display)) {}
  138.  
  139. ilclient_disable_tunnel(decoder->Tunnel);
  140. ilclient_disable_port_buffers(decoder->Video_Decode, 130, NULL, NULL, NULL);
  141. ilclient_teardown_tunnels(decoder->Tunnel);
  142.  
  143. ilclient_state_transition(decoder->List, OMX_StateIdle);
  144. ilclient_state_transition(decoder->List, OMX_StateLoaded);
  145.  
  146. ilclient_cleanup_components(decoder->List);
  147.  
  148. OMX_Deinit();
  149.  
  150. ilclient_destroy(decoder->Client);
  151. }
  152.  
  153. #endif
RAW Paste Data