Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mmalomx_roles.c 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "mmalomx.h"
  26. #include "mmalomx_roles.h"
  27. #include "mmalomx_registry.h"
  28. #include "mmalomx_logging.h"
  29. static const struct {
  30. const char *name;
  31. MMALOMX_ROLE_T role;
  32. } mmalomx_roles[] =
  33. {
  34. {"video_decoder.h263", MMALOMX_ROLE_VIDEO_DECODER_H263},
  35. {"video_decoder.mpeg4", MMALOMX_ROLE_VIDEO_DECODER_MPEG4},
  36. {"video_decoder.avc", MMALOMX_ROLE_VIDEO_DECODER_AVC},
  37. {"video_decoder.mpeg2", MMALOMX_ROLE_VIDEO_DECODER_MPEG2},
  38. {"video_decoder.wmv", MMALOMX_ROLE_VIDEO_DECODER_WMV},
  39. {"video_decoder.vpx", MMALOMX_ROLE_VIDEO_DECODER_VPX},
  40. {"video_encoder.h263", MMALOMX_ROLE_VIDEO_ENCODER_H263},
  41. {"video_encoder.mpeg4", MMALOMX_ROLE_VIDEO_ENCODER_MPEG4},
  42. {"video_encoder.avc", MMALOMX_ROLE_VIDEO_ENCODER_AVC},
  43. {"audio_decoder.aac", MMALOMX_ROLE_AUDIO_DECODER_AAC},
  44. {"audio_decoder.mp1", MMALOMX_ROLE_AUDIO_DECODER_MPGA_L1},
  45. {"audio_decoder.mp2", MMALOMX_ROLE_AUDIO_DECODER_MPGA_L2},
  46. {"audio_decoder.mp3", MMALOMX_ROLE_AUDIO_DECODER_MPGA_L3},
  47. {"audio_decoder.ddp", MMALOMX_ROLE_AUDIO_DECODER_DDP},
  48. {"AIV.play.101", MMALOMX_ROLE_AIV_PLAY_101},
  49. {"play.avcddp", MMALOMX_ROLE_AIV_PLAY_AVCDDP},
  50. {0, 0}
  51. };
  52. const char *mmalomx_role_to_name(MMALOMX_ROLE_T role)
  53. {
  54. unsigned int i;
  55. for (i = 0; mmalomx_roles[i].name; i++)
  56. if (mmalomx_roles[i].role == role)
  57. break;
  58. return mmalomx_roles[i].name;
  59. }
  60. MMALOMX_ROLE_T mmalomx_role_from_name(const char *name)
  61. {
  62. unsigned int i;
  63. for (i = 0; mmalomx_roles[i].name; i++)
  64. if (!strcmp(mmalomx_roles[i].name, name))
  65. break;
  66. return mmalomx_roles[i].role;
  67. }
  68. static void mmalomx_format_encoding_from_role(MMALOMX_ROLE_T role,
  69. MMAL_FOURCC_T *encoding, MMAL_ES_TYPE_T *es_type, unsigned int *port)
  70. {
  71. switch (role)
  72. {
  73. case MMALOMX_ROLE_VIDEO_DECODER_MPEG4:
  74. case MMALOMX_ROLE_VIDEO_ENCODER_MPEG4:
  75. *encoding = MMAL_ENCODING_MP4V;
  76. *es_type = MMAL_ES_TYPE_VIDEO;
  77. break;
  78. case MMALOMX_ROLE_VIDEO_DECODER_AVC:
  79. case MMALOMX_ROLE_VIDEO_ENCODER_AVC:
  80. *encoding = MMAL_ENCODING_H264;
  81. *es_type = MMAL_ES_TYPE_VIDEO;
  82. break;
  83. case MMALOMX_ROLE_VIDEO_DECODER_MPEG2:
  84. *encoding = MMAL_ENCODING_MP2V;
  85. *es_type = MMAL_ES_TYPE_VIDEO;
  86. break;
  87. case MMALOMX_ROLE_VIDEO_DECODER_WMV:
  88. *encoding = MMAL_ENCODING_WMV3;
  89. *es_type = MMAL_ES_TYPE_VIDEO;
  90. break;
  91. case MMALOMX_ROLE_VIDEO_DECODER_VPX:
  92. *encoding = MMAL_ENCODING_VP8;
  93. *es_type = MMAL_ES_TYPE_VIDEO;
  94. break;
  95. case MMALOMX_ROLE_VIDEO_DECODER_H263:
  96. case MMALOMX_ROLE_VIDEO_ENCODER_H263:
  97. *encoding = MMAL_ENCODING_H263;
  98. *es_type = MMAL_ES_TYPE_VIDEO;
  99. break;
  100. case MMALOMX_ROLE_AUDIO_DECODER_AAC:
  101. *encoding = MMAL_ENCODING_MP4A;
  102. *es_type = MMAL_ES_TYPE_AUDIO;
  103. break;
  104. case MMALOMX_ROLE_AUDIO_DECODER_MPGA_L1:
  105. case MMALOMX_ROLE_AUDIO_DECODER_MPGA_L2:
  106. case MMALOMX_ROLE_AUDIO_DECODER_MPGA_L3:
  107. *encoding = MMAL_ENCODING_MPGA;
  108. *es_type = MMAL_ES_TYPE_AUDIO;
  109. break;
  110. case MMALOMX_ROLE_AUDIO_DECODER_DDP:
  111. *encoding = MMAL_ENCODING_AC3;
  112. *es_type = MMAL_ES_TYPE_AUDIO;
  113. break;
  114. default:
  115. *encoding = MMAL_ENCODING_UNKNOWN;
  116. *es_type = MMAL_ES_TYPE_UNKNOWN;
  117. break;
  118. }
  119. switch (role)
  120. {
  121. case MMALOMX_ROLE_VIDEO_ENCODER_H263:
  122. case MMALOMX_ROLE_VIDEO_ENCODER_MPEG4:
  123. case MMALOMX_ROLE_VIDEO_ENCODER_AVC:
  124. *port = 1;
  125. break;
  126. default:
  127. *port = 0;
  128. break;
  129. }
  130. }
  131. OMX_ERRORTYPE mmalomx_role_set(MMALOMX_COMPONENT_T *component, const char *name)
  132. {
  133. const MMALOMX_ROLE_T role = mmalomx_role_from_name(name);
  134. MMAL_FOURCC_T encoding = MMAL_ENCODING_UNKNOWN;
  135. MMAL_ES_TYPE_T es_type = MMAL_ES_TYPE_UNKNOWN;
  136. unsigned int port;
  137. MMAL_ES_FORMAT_T *format;
  138. if (!role || !mmalomx_registry_component_supports_role(component->registry_id, role))
  139. return OMX_ErrorUnsupportedSetting;
  140. component->role = role;
  141. mmalomx_format_encoding_from_role(role, &encoding, &es_type, &port);
  142. if (encoding == MMAL_ENCODING_UNKNOWN)
  143. return OMX_ErrorNone;
  144. format = component->ports[port].mmal->format;
  145. format->type = es_type;
  146. format->encoding = encoding;
  147. format->bitrate = 64000;
  148. switch (es_type)
  149. {
  150. case MMAL_ES_TYPE_VIDEO:
  151. format->es->video.width = 176;
  152. format->es->video.height = 144;
  153. format->es->video.frame_rate.num = 15;
  154. format->es->video.frame_rate.den = 1;
  155. break;
  156. default:
  157. break;
  158. }
  159. switch (role)
  160. {
  161. case MMALOMX_ROLE_VIDEO_DECODER_H263:
  162. case MMALOMX_ROLE_VIDEO_ENCODER_H263:
  163. component->ports[port].format_param.h263.eProfile = OMX_VIDEO_H263ProfileBaseline;
  164. component->ports[port].format_param.h263.eLevel = OMX_VIDEO_H263Level10;
  165. component->ports[port].format_param.h263.bPLUSPTYPEAllowed = OMX_FALSE;
  166. component->ports[port].format_param.h263.bForceRoundingTypeToZero = OMX_TRUE;
  167. break;
  168. case MMALOMX_ROLE_VIDEO_DECODER_MPEG4:
  169. case MMALOMX_ROLE_VIDEO_ENCODER_MPEG4:
  170. component->ports[port].format_param.mpeg4.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
  171. component->ports[port].format_param.mpeg4.eLevel = OMX_VIDEO_MPEG4Level1;
  172. break;
  173. case MMALOMX_ROLE_VIDEO_DECODER_AVC:
  174. case MMALOMX_ROLE_VIDEO_ENCODER_AVC:
  175. component->ports[port].format_param.avc.eProfile = OMX_VIDEO_AVCProfileBaseline;
  176. component->ports[port].format_param.avc.eLevel = OMX_VIDEO_AVCLevel1;
  177. break;
  178. case MMALOMX_ROLE_VIDEO_DECODER_WMV:
  179. component->ports[port].format_param.wmv.eFormat = OMX_VIDEO_WMVFormat9;
  180. break;
  181. default:
  182. break;
  183. }
  184. if (mmal_port_format_commit(component->ports[port].mmal) != MMAL_SUCCESS)
  185. LOG_ERROR("failed to commit format to %s for role %s",
  186. component->ports[port].mmal->name, name);
  187. return OMX_ErrorNone;
  188. }