list_devices.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #include "device.h"
  2. #include <assert.h>
  3. #include <linux/limits.h>
  4. #include <linux/media.h>
  5. #include <stdio.h>
  6. const char *
  7. entity_type_str(uint32_t type)
  8. {
  9. switch (type) {
  10. case MEDIA_ENT_F_UNKNOWN:
  11. return "UNKNOWN";
  12. case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
  13. return "V4L2_SUBDEV_UNKNOWN";
  14. case MEDIA_ENT_F_IO_V4L:
  15. return "IO_V4L";
  16. case MEDIA_ENT_F_IO_VBI:
  17. return "IO_VBI";
  18. case MEDIA_ENT_F_IO_SWRADIO:
  19. return "IO_SWRADIO";
  20. case MEDIA_ENT_F_IO_DTV:
  21. return "IO_DTV";
  22. case MEDIA_ENT_F_DTV_DEMOD:
  23. return "DTV_DEMOD";
  24. case MEDIA_ENT_F_TS_DEMUX:
  25. return "TS_DEMUX";
  26. case MEDIA_ENT_F_DTV_CA:
  27. return "DTV_CA";
  28. case MEDIA_ENT_F_DTV_NET_DECAP:
  29. return "DTV_NET_DECAP";
  30. case MEDIA_ENT_F_CAM_SENSOR:
  31. return "CAM_SENSOR";
  32. case MEDIA_ENT_F_FLASH:
  33. return "FLASH";
  34. case MEDIA_ENT_F_LENS:
  35. return "LENS";
  36. case MEDIA_ENT_F_ATV_DECODER:
  37. return "ATV_DECODER";
  38. case MEDIA_ENT_F_TUNER:
  39. return "TUNER";
  40. case MEDIA_ENT_F_IF_VID_DECODER:
  41. return "IF_VID_DECODER";
  42. case MEDIA_ENT_F_IF_AUD_DECODER:
  43. return "IF_AUD_DECODER";
  44. case MEDIA_ENT_F_AUDIO_CAPTURE:
  45. return "AUDIO_CAPTURE";
  46. case MEDIA_ENT_F_AUDIO_PLAYBACK:
  47. return "AUDIO_PLAYBACK";
  48. case MEDIA_ENT_F_AUDIO_MIXER:
  49. return "AUDIO_MIXER";
  50. case MEDIA_ENT_F_PROC_VIDEO_COMPOSER:
  51. return "PROC_VIDEO_COMPOSER";
  52. case MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER:
  53. return "PROC_VIDEO_PIXEL_FORMATTER";
  54. case MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV:
  55. return "PROC_VIDEO_PIXEL_ENC_CONV";
  56. case MEDIA_ENT_F_PROC_VIDEO_LUT:
  57. return "PROC_VIDEO_LUT";
  58. case MEDIA_ENT_F_PROC_VIDEO_SCALER:
  59. return "PROC_VIDEO_SCALER";
  60. case MEDIA_ENT_F_PROC_VIDEO_STATISTICS:
  61. return "PROC_VIDEO_STATISTICS";
  62. case MEDIA_ENT_F_PROC_VIDEO_ENCODER:
  63. return "PROC_VIDEO_ENCODER";
  64. case MEDIA_ENT_F_PROC_VIDEO_DECODER:
  65. return "PROC_VIDEO_DECODER";
  66. case MEDIA_ENT_F_PROC_VIDEO_ISP:
  67. return "PROC_VIDEO_ISP";
  68. case MEDIA_ENT_F_VID_MUX:
  69. return "VID_MUX";
  70. case MEDIA_ENT_F_VID_IF_BRIDGE:
  71. return "VID_IF_BRIDGE";
  72. default:
  73. return "invalid type";
  74. }
  75. }
  76. const char *
  77. intf_type_str(uint32_t type)
  78. {
  79. switch (type) {
  80. case MEDIA_INTF_T_DVB_FE:
  81. return "DVB_FE";
  82. case MEDIA_INTF_T_DVB_DEMUX:
  83. return "DVB_DEMUX";
  84. case MEDIA_INTF_T_DVB_DVR:
  85. return "DVB_DVR";
  86. case MEDIA_INTF_T_DVB_CA:
  87. return "DVB_CA";
  88. case MEDIA_INTF_T_DVB_NET:
  89. return "DVB_NET";
  90. case MEDIA_INTF_T_V4L_VIDEO:
  91. return "V4L_VIDEO";
  92. case MEDIA_INTF_T_V4L_VBI:
  93. return "V4L_VBI";
  94. case MEDIA_INTF_T_V4L_RADIO:
  95. return "V4L_RADIO";
  96. case MEDIA_INTF_T_V4L_SUBDEV:
  97. return "V4L_SUBDEV";
  98. case MEDIA_INTF_T_V4L_SWRADIO:
  99. return "V4L_SWRADIO";
  100. case MEDIA_INTF_T_V4L_TOUCH:
  101. return "V4L_TOUCH";
  102. case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
  103. return "ALSA_PCM_CAPTURE";
  104. case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
  105. return "ALSA_PCM_PLAYBACK";
  106. case MEDIA_INTF_T_ALSA_CONTROL:
  107. return "ALSA_CONTROL";
  108. case MEDIA_INTF_T_ALSA_COMPRESS:
  109. return "ALSA_COMPRESS";
  110. case MEDIA_INTF_T_ALSA_RAWMIDI:
  111. return "ALSA_RAWMIDI";
  112. case MEDIA_INTF_T_ALSA_HWDEP:
  113. return "ALSA_HWDEP";
  114. case MEDIA_INTF_T_ALSA_SEQUENCER:
  115. return "ALSA_SEQUENCER";
  116. case MEDIA_INTF_T_ALSA_TIMER:
  117. return "ALSA_TIMER";
  118. default:
  119. return "invalid type";
  120. }
  121. }
  122. int
  123. main(int argc, char *argv[])
  124. {
  125. MPDeviceList *list = mp_device_list_new();
  126. while (list) {
  127. MPDevice *device = mp_device_list_get(list);
  128. const struct media_device_info *info = mp_device_get_info(device);
  129. printf("%s (%s) %s\n", info->model, info->driver, info->serial);
  130. printf(" Path: %s\n", mp_device_list_get_path(list));
  131. printf(" Bus Info: %s\n", info->bus_info);
  132. printf(" Media Version: %d\n", info->media_version);
  133. printf(" HW Revision: %d\n", info->hw_revision);
  134. printf(" Driver Version: %d\n", info->driver_version);
  135. const struct media_v2_entity *entities =
  136. mp_device_get_entities(device);
  137. size_t num = mp_device_get_num_entities(device);
  138. printf(" Entities (%ld):\n", num);
  139. for (int i = 0; i < num; ++i) {
  140. printf(" %d %s (%s)\n",
  141. entities[i].id,
  142. entities[i].name,
  143. entity_type_str(entities[i].function));
  144. }
  145. const struct media_v2_interface *interfaces =
  146. mp_device_get_interfaces(device);
  147. num = mp_device_get_num_interfaces(device);
  148. printf(" Interfaces (%ld):\n", num);
  149. for (int i = 0; i < num; ++i) {
  150. // Unused
  151. assert(interfaces[i].flags == 0);
  152. char buf[PATH_MAX];
  153. buf[0] = '\0';
  154. mp_find_device_path(interfaces[i].devnode, buf, PATH_MAX);
  155. printf(" %d (%s) devnode %d:%d %s\n",
  156. interfaces[i].id,
  157. intf_type_str(interfaces[i].intf_type),
  158. interfaces[i].devnode.major,
  159. interfaces[i].devnode.minor,
  160. buf);
  161. }
  162. const struct media_v2_pad *pads = mp_device_get_pads(device);
  163. num = mp_device_get_num_pads(device);
  164. printf(" Pads (%ld):\n", num);
  165. for (int i = 0; i < num; ++i) {
  166. printf(" %d for device:%d (",
  167. pads[i].id,
  168. pads[i].entity_id);
  169. if (pads[i].flags & MEDIA_PAD_FL_SINK)
  170. printf("SINK ");
  171. if (pads[i].flags & MEDIA_PAD_FL_SOURCE)
  172. printf("SOURCE ");
  173. if (pads[i].flags & MEDIA_PAD_FL_MUST_CONNECT)
  174. printf("MUST_CONNECT ");
  175. printf(")\n");
  176. }
  177. const struct media_v2_link *links = mp_device_get_links(device);
  178. num = mp_device_get_num_links(device);
  179. printf(" Links (%ld):\n", num);
  180. for (int i = 0; i < num; ++i) {
  181. printf(" %d from:%d to:%d (",
  182. links[i].id,
  183. links[i].source_id,
  184. links[i].sink_id);
  185. if (links[i].flags & MEDIA_LNK_FL_ENABLED)
  186. printf("ENABLED ");
  187. if (links[i].flags & MEDIA_LNK_FL_IMMUTABLE)
  188. printf("IMMUTABLE ");
  189. if (links[i].flags & MEDIA_LNK_FL_DYNAMIC)
  190. printf("DYNAMIC ");
  191. uint32_t type = links[i].flags & MEDIA_LNK_FL_LINK_TYPE;
  192. if (type == MEDIA_LNK_FL_INTERFACE_LINK) {
  193. printf("INTERFACE)\n");
  194. } else {
  195. assert(type == MEDIA_LNK_FL_DATA_LINK);
  196. printf("DATA)\n");
  197. }
  198. }
  199. list = mp_device_list_next(list);
  200. }
  201. mp_device_list_free(list);
  202. }