23 #include "mediabrowser_private.h"
24 #include "mediabrowser.h"
35 if (strcmp_s((gchar *)udn, strlen((gchar *)udn), gwData->udn, &result) == EOK &&
44 browse_remote_directory(GUPnPServiceInfo *browserService, gchar *root,
int startIndex,
int maxCount, guint *totalResults, gchar **result)
46 gchar *browseFlag = BROWSE_MODE_CHILD_NODE;
48 gchar *sortCriteria =
"";
50 guint numberReturned, totalMatches, updateId;
51 gboolean status =
TRUE;
54 GUPnPServiceProxyAction *action = gupnp_service_proxy_action_new(
"Browse",
55 "ObjectID", G_TYPE_STRING, root,
"BrowseFlag", G_TYPE_STRING, browseFlag,
56 "Filter", G_TYPE_STRING, filter,
"StartingIndex", G_TYPE_INT, startIndex,
57 "RequestedCount", G_TYPE_INT, maxCount,
"SortCriteria", G_TYPE_STRING, sortCriteria,
59 gupnp_service_proxy_call_action(browserService, action, NULL, &error);
62 gupnp_service_proxy_action_get_result(action,
63 &error,
"Result", G_TYPE_STRING, result,
64 "NumberReturned ", G_TYPE_INT, &numberReturned,
65 "TotalMatches", G_TYPE_INT, &totalMatches,
66 "UpdateID ", G_TYPE_INT, &updateId,
68 g_clear_pointer(&action, gupnp_service_proxy_action_unref);
71 gupnp_service_proxy_send_action(browserService,
"Browse", &error,
72 "ObjectID", G_TYPE_STRING, root,
"BrowseFlag", G_TYPE_STRING, browseFlag,
73 "Filter", G_TYPE_STRING, filter,
"StartingIndex", G_TYPE_INT, startIndex,
74 "RequestedCount", G_TYPE_INT, maxCount,
"SortCriteria", G_TYPE_STRING, sortCriteria,
76 "Result", G_TYPE_STRING, result,
77 "NumberReturned ", G_TYPE_INT, &numberReturned,
78 "TotalMatches", G_TYPE_INT, &totalMatches,
79 "UpdateID ", G_TYPE_INT, &updateId,
84 g_message(
"[%s] UPNP Browse call failed : %s\n", __FUNCTION__, error->message);
85 g_clear_error(&error);
91 bool browse_remote_dir_with_udn(
const char *server_udn,
const char *path_id,
int start_index,
92 int max_entries,
int *totalCount,
char **results)
94 GList *msListItem = NULL;
96 msListItem = g_list_find_custom(msList, server_udn, (GCompareFunc)
g_list_find_udn);
97 g_mutex_unlock(locker);
99 if (NULL == msListItem)
101 g_message(
"[%s] Failed to identify the device in cache %s ", __FUNCTION__, server_udn);
106 return browse_remote_directory(msConfig->browserService, path_id, start_index, max_entries, totalCount, results);
110 device_proxy_available_mr_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
112 g_message(
"%s] Found a new UPNP media server", __FUNCTION__);
113 if ((NULL == cp) || (NULL == dproxy))
115 g_message(
"[%s] Got empty control point or device proxy. Leaving", __FUNCTION__);
118 gchar *data = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO(dproxy));
119 g_message(
"[%s] Got UDN as %s ", __FUNCTION__, data);
120 GList *msListItem = NULL;
122 g_mutex_lock(locker);
123 msListItem = g_list_find_custom(msList, data, (GCompareFunc)
g_list_find_udn);
124 g_mutex_unlock(locker);
125 if (NULL != msListItem)
127 g_message(
"[%s] Existing device, ignoring.", __FUNCTION__);
131 mserver->friendlyname = NULL;
132 mserver->udn = strdup(data);
135 data = gupnp_device_info_get_friendly_name(GUPNP_DEVICE_INFO(dproxy));
136 g_message(
"[%s] Got Friendly name as %s ", __FUNCTION__, data);
137 mserver->friendlyname = strdup(data);
144 mserver->browserService = gupnp_device_info_get_service(GUPNP_DEVICE_INFO(dproxy), XUPNP_SERVICE_CONTENT_DIR);
146 g_mutex_lock(locker);
147 msList = g_list_append(msList, mserver);
148 g_mutex_unlock(locker);
152 device_proxy_unavailable_mr_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
155 g_message(
"Mediaserver disconnected event received.");
156 if ((NULL == cp) || (NULL == dproxy))
158 g_message(
"[%s] Got empty control point or device proxy. Leaving", __FUNCTION__);
161 gchar *data = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO(dproxy));
162 g_message(
"[%s] Got UDN as %s ", __FUNCTION__, data);
164 GList *msListItem = NULL;
165 g_mutex_lock(locker);
168 if (NULL != msListItem)
171 msList = g_list_remove_link(msList, msListItem);
172 g_mutex_unlock(locker);
175 free(msItem->friendlyname);
177 g_clear_object(&(msItem->browserService));
180 g_list_free(msListItem);
184 g_message(
"[%s] Not found in cache. ", __FUNCTION__);
193 g_message(
"[%s] Registering media renderer device ", __FUNCTION__);
194 cp_media_rndr = gupnp_control_point_new(context, XUPNP_DEVICE_MEDIASERVER_CONTROL_URN);
195 g_signal_connect(cp_media_rndr,
"device-proxy-available", G_CALLBACK(device_proxy_available_mr_cb), NULL);
196 g_signal_connect(cp_media_rndr,
"device-proxy-unavailable", G_CALLBACK(device_proxy_unavailable_mr_cb), NULL);
197 gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(cp_media_rndr),
TRUE);
204 locker = g_mutex_new();
212 g_mutex_free(locker);