本文主要是介绍gst-device-monitor-1.0源码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、gst-device-monitor-1.0命令输出
C:\Users\herego\Desktop>gst-device-monitor-1.0Probing devices...Device found:name : Default Audio Capture Deviceclass : Audio/Sourcecaps : audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = {2EEF81BE-33FA-4800-9670-1CD474972C3F}device.default = truewasapi2.device.description = Default Audio Capture Devicewasapi2.device.loopback = falsegst-launch-1.0 wasapi2src device="\{2EEF81BE-33FA-4800-9670-1CD474972C3F\}" ! ...Device found:name : Microphone (High Definition Audio Device)class : Audio/Sourcecaps : audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = \\?\SWD#MMDEVAPI#{0.0.1.00000000}.{6e7103bc-22b1-4cf4-8264-3075c86f6b5b}#{2eef81be-33fa-4800-9670-1cd474972c3f}device.default = falsewasapi2.device.description = Microphone (High Definition Audio Device)wasapi2.device.loopback = falsegst-launch-1.0 wasapi2src device="\\\\\?\\SWD\#MMDEVAPI\#\{0.0.1.00000000\}.\{6e7103bc-22b1-4cf4-8264-3075c86f6b5b\}\#\{2eef81be-33fa-4800-9670-1cd474972c3f\}" ! ...Device found:name : Default Audio Render Deviceclass : Audio/Sourcecaps : audio/x-raw, format=F32LE, layout=interleaved, rate=48000, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = {E6327CAD-DCEC-4949-AE8A-991E976A79D2}device.default = truewasapi2.device.description = Default Audio Render Devicewasapi2.device.loopback = truegst-launch-1.0 wasapi2src device="\{E6327CAD-DCEC-4949-AE8A-991E976A79D2\}" loopback=true ! ...Device found:name : 扬声器 (High Definition Audio Device)class : Audio/Sourcecaps : audio/x-raw, format=F32LE, layout=interleaved, rate=48000, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = \\?\SWD#MMDEVAPI#{0.0.0.00000000}.{445b7304-df4b-4f1e-887b-a6bb85c91705}#{e6327cad-dcec-4949-ae8a-991e976a79d2}device.default = falsewasapi2.device.description = 扬声器 (High Definition Audio Device)wasapi2.device.loopback = truegst-launch-1.0 wasapi2src device="\\\\\?\\SWD\#MMDEVAPI\#\{0.0.0.00000000\}.\{445b7304-df4b-4f1e-887b-a6bb85c91705\}\#\{e6327cad-dcec-4949-ae8a-991e976a79d2\}" loopback=true ! ...Device foundname : Default Audio Render Deviceclass : Audio/Sinkcaps : audio/x-raw, format=F32LE, layout=interleaved, rate=48000, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = {E6327CAD-DCEC-4949-AE8A-991E976A79D2}device.default = truewasapi2.device.description = Default Audio Render Devicegst-launch-1.0 ... ! wasapi2sink device="\{E6327CAD-DCEC-4949-AE8A-991E976A79D2\}"Device found:name : 扬声器 (High Definition Audio Device)class : Audio/Sinkcaps : audio/x-raw, format=F32LE, layout=interleaved, rate=48000, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapi2device.id = \\?\SWD#MMDEVAPI#{0.0.0.00000000}.{445b7304-df4b-4f1e-887b-a6bb85c91705}#{e6327cad-dcec-4949-ae8a-991e976a79d2}device.default = falsewasapi2.device.description = 扬声器 (High Definition Audio Device)gst-launch-1.0 ... ! wasapi2sink device="\\\\\?\\SWD\#MMDEVAPI\#\{0.0.0.00000000\}.\{445b7304-df4b-4f1e-887b-a6bb85c91705\}\#\{e6327cad-dcec-4949-ae8a-991e976a79d2\}"Device found:name : V2412class : Source/Monitorcaps : video/x-raw(memory:D3D11Memory), format=BGRA, width=1920, height=1080, framerate=[ 0/1, 2147483647/1 ], pixel-aspect-ratio=1/1video/x-raw, format=BGRA, width=1920, height=1080, framerate=[ 0/1, 2147483647/1 ], pixel-aspect-ratio=1/1properties:device.api = d3d11device.name = \\.\DISPLAY1device.path = \\?\DISPLAY#HKC2411#4&25b7d37e&0&UID198171#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}device.primary = truedevice.type = hdmidevice.hmonitor = 124978447device.adapter.luid = 44725device.adapter.description = Intel(R) UHD Graphics 630desktop.coordinates.left = 0desktop.coordinates.top = 0desktop.coordinates.right = 1920desktop.coordinates.bottom = 1080display.coordinates.left = 0display.coordinates.top = 0display.coordinates.right = 1920display.coordinates.bottom = 1080gst-launch-1.0 d3d11screencapturesrc monitor-handle=124978447 ! ...Device found:name : 扬声器 (High Definition Audio Device)class : Audio/Sinkcaps : audio/x-raw, format=S16LE, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]audio/x-raw, format=U8, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]audio/x-ac3, framed=trueaudio/x-dts, framed=trueproperties:device.api = directsounddevice.guid = {445B7304-DF4B-4F1E-887B-A6BB85C91705}directsound.device.driver = {0.0.0.00000000}.{445b7304-df4b-4f1e-887b-a6bb85c91705}directsound.device.description = 扬声器 (High Definition Audio Device)gst-launch-1.0 ... ! directsoundsink device="\{445B7304-DF4B-4F1E-887B-A6BB85C91705\}"Device found:name : 主声音驱动程序class : Audio/Sinkcaps : audio/x-raw, format=S16LE, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]audio/x-raw, format=U8, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]audio/x-ac3, framed=trueaudio/x-dts, framed=trueproperties:device.api = directsounddevice.guid = (NULL)directsound.device.driver =directsound.device.description = 主声音驱动程序gst-launch-1.0 ... ! directsoundsinkDevice found:name : Microphone (High Definition Audio Device)class : Audio/Sourcecaps : audio/x-raw, format={ (string)S16LE, (string)S8 }, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]properties:device.api = directsounddevice.guid = {6E7103BC-22B1-4CF4-8264-3075C86F6B5B}directsound.device.driver = {0.0.1.00000000}.{6e7103bc-22b1-4cf4-8264-3075c86f6b5b}directsound.device.description = Microphone (High Definition Audio Device)gst-launch-1.0 directsoundsrc device="\{6E7103BC-22B1-4CF4-8264-3075C86F6B5B\}" ! ...Device found:name : 主声音捕获驱动程序class : Audio/Sourcecaps : audio/x-raw, format={ (string)S16LE, (string)S8 }, layout=interleaved, rate=[ 1, 2147483647 ], channels=[ 1, 2 ]properties:device.api = directsounddevice.guid = (NULL)directsound.device.driver =directsound.device.description = 主声音捕获驱动程序gst-launch-1.0 directsoundsrc ! ...Device found:name : Microphone (High Definition Audio Device)class : Audio/Sourcecaps : audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapidevice.strid = {0.0.1.00000000}.{6e7103bc-22b1-4cf4-8264-3075c86f6b5b}wasapi.device.description = Microphone (High Definition Audio Device)gst-launch-1.0 wasapisrc device="\{0.0.1.00000000\}.\{6e7103bc-22b1-4cf4-8264-3075c86f6b5b\}" ! ...Device found:name : 扬声器 (High Definition Audio Device)class : Audio/Sinkcaps : audio/x-raw, format=F32LE, layout=interleaved, rate=48000, channels=2, channel-mask=0x0000000000000003properties:device.api = wasapidevice.strid = {0.0.0.00000000}.{445b7304-df4b-4f1e-887b-a6bb85c91705}wasapi.device.description = 扬声器 (High Definition Audio Device)gst-launch-1.0 ... ! wasapisink device="\{0.0.0.00000000\}.\{445b7304-df4b-4f1e-887b-a6bb85c91705\}"
2、在gst-device-monitor.c文件中先实现main函数,创建GMainLoop事件循环和GstDeviceMonitor对象,并gst_device_monitor_start启动,最后通过 gst_bus_add_watch监听设备信息。
int main (int argc, char **argv)
{...app.loop = g_main_loop_new (NULL, FALSE);app.monitor = gst_device_monitor_new ();gst_device_monitor_set_show_all_devices (app.monitor, include_hidden);bus = gst_device_monitor_get_bus (app.monitor);app.bus_watch_id = gst_bus_add_watch (bus, bus_msg_handler, &app);gst_object_unref (bus);timer = g_timer_new ();if (!gst_device_monitor_start (app.monitor)) {g_printerr ("Failed to start device monitor!\n");return -1;}if (!follow) {/* Consume all the messages pending on the bus and exit */g_idle_add ((GSourceFunc) quit_loop, app.loop);} else {g_print ("Monitoring devices, waiting for devices to be removed or new devices to be added...\n");}g_main_loop_run (app.loop);gst_device_monitor_stop (app.monitor);gst_object_unref (app.monitor);g_source_remove (app.bus_watch_id);g_main_loop_unref (app.loop);g_timer_destroy (timer);
}
2、通过bus_msg_handler消息监听实现
static gboolean
bus_msg_handler (GstBus * bus, GstMessage * msg, gpointer user_data)
{GstDevice *device;switch (GST_MESSAGE_TYPE (msg)) {case GST_MESSAGE_DEVICE_ADDED:gst_message_parse_device_added (msg, &device);print_device (device, FALSE);gst_object_unref (device);break;case GST_MESSAGE_DEVICE_REMOVED:gst_message_parse_device_removed (msg, &device);device_removed (device);gst_object_unref (device);break;case GST_MESSAGE_DEVICE_CHANGED:gst_message_parse_device_changed (msg, &device, NULL);print_device (device, TRUE);gst_object_unref (device);break;default:g_print ("%s message\n", GST_MESSAGE_TYPE_NAME (msg));break;}return TRUE;
}
3、输出设备信息
static void
print_device (GstDevice * device, gboolean modified)
{gchar *device_class, *str, *name;GstCaps *caps;GstStructure *props;guint i, size = 0;caps = gst_device_get_caps (device);if (caps != NULL)size = gst_caps_get_size (caps);name = gst_device_get_display_name (device);device_class = gst_device_get_device_class (device);props = gst_device_get_properties (device);g_print ("\nDevice %s:\n\n", modified ? "modified" : "found"); //发现设备还是修改设备g_print ("\tname : %s\n", name); //设备名称g_print ("\tclass : %s\n", device_class); //设备类型//cap能力字段信息for (i = 0; i < size; ++i) {GstStructure *s = gst_caps_get_structure (caps, i);GstCapsFeatures *features = gst_caps_get_features (caps, i);g_print ("\t%s %s", (i == 0) ? "caps :" : " ",gst_structure_get_name (s));if (features && (gst_caps_features_is_any (features) || !gst_caps_features_is_equal (features,GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {gchar *features_string = gst_caps_features_to_string (features);g_print ("(%s)", features_string);g_free (features_string);}gst_structure_foreach (s, print_field, NULL);g_print ("\n");}//properties属性字段信息if (props) {g_print ("\tproperties:");gst_structure_foreach (props, print_structure_field, NULL);gst_structure_free (props);g_print ("\n");}//pipeline实例格式str = get_launch_line (device);if (gst_device_has_classes (device, "Source")) //源插件g_print ("\tgst-launch-1.0 %s ! ...\n", str);else if (gst_device_has_classes (device, "Sink")) //sink插件g_print ("\tgst-launch-1.0 ... ! %s\n", str);else if (gst_device_has_classes (device, "CameraSource")) { //摄像头源插件g_print ("\tgst-launch-1.0 %s.vfsrc name=camerasrc ! ... camerasrc.vidsrc ! [video/x-h264] ... \n", str);}g_free (str);g_print ("\n");g_free (name);g_free (device_class);if (caps != NULL)gst_caps_unref (caps);
}
5、输出字段信息
static gboolean
print_field (GQuark field, const GValue * value, gpointer unused)
{gchar *str = gst_value_serialize (value);g_print (", %s=%s", g_quark_to_string (field), str);g_free (str);return TRUE;
}
这篇关于gst-device-monitor-1.0源码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!