/*---------------------------------------------------------------------- | PLT_MediaBrowser::OnDeviceRemoved +---------------------------------------------------------------------*/ NPT_Result PLT_MediaBrowser::OnDeviceRemoved(PLT_DeviceDataReference& device) { PLT_DeviceDataReference data; { NPT_AutoLock lock(m_MediaServers); // only release if we have kept it around NPT_String uuid = device->GetUUID(); // is it a new device? if (NPT_FAILED(NPT_ContainerFind(m_MediaServers, PLT_DeviceDataFinder(uuid), data))) { NPT_LOG_WARNING_1("Device (%s) not found in our list!", (const char*)uuid); return NPT_FAILURE; } NPT_LOG_FINE("Device Removed:"); device->ToLog(NPT_LOG_LEVEL_FINE); m_MediaServers.Remove(device); } if (m_Listener) { m_Listener->OnMSAddedRemoved(device, 0); } return NPT_SUCCESS; }
static bool FindDeviceWait(CUPnP* upnp, const char* uuid, PLT_DeviceDataReference& device) { bool client_started = upnp->IsClientStarted(); upnp->StartClient(); // look for device in our list // (and wait for it to respond for 5 secs if we're just starting upnp client) NPT_TimeStamp watchdog; NPT_System::GetCurrentTimeStamp(watchdog); watchdog += 5.f; for (;;) { if (NPT_SUCCEEDED(upnp->m_MediaBrowser->FindServer(uuid, device)) && !device.IsNull()) break; // fail right away if device not found and upnp client was already running if (client_started) return false; // otherwise check if we've waited long enough without success NPT_TimeStamp now; NPT_System::GetCurrentTimeStamp(now); if (now > watchdog) return false; // sleep a bit and try again NPT_System::Sleep(NPT_TimeInterval((double)1)); } return !device.IsNull(); }
virtual bool OnMRAdded(PLT_DeviceDataReference& device ) { CPlayerCoreFactory::Get().OnPlayerDiscovered((const char*)device->GetUUID() ,(const char*)device->GetFriendlyName() , EPC_UPNPPLAYER); return true; }
void PLT_MicroMediaController::SetEmbeddedServer(const char* embeddedServerName){ NPT_AutoLock lock(m_CurMediaServerLock); PopDirectoryStackToRoot(); NPT_Result res = NPT_FAILURE; //const char embeddedServerName[]="Embedded Media Server"; while(res!=NPT_SUCCESS){ //printf("waiting for the embedded server to come up!\n"); const NPT_Lock<PLT_DeviceMap>& deviceList = GetMediaServersMap(); const NPT_List<PLT_DeviceMapEntry*>& entries = deviceList.GetEntries(); NPT_List<PLT_DeviceMapEntry*>::Iterator entry = entries.GetFirstItem(); while (entry) { PLT_DeviceDataReference device = (*entry)->GetValue(); NPT_String name = device->GetFriendlyName(); if(0 == strcmp(embeddedServerName, name)){ printf("****server discovered and set****\n"); m_CurMediaServer = device; res = NPT_SUCCESS; break; } ++entry; } } }
/*---------------------------------------------------------------------- | PLT_MediaBrowser::OnDeviceRemoved +---------------------------------------------------------------------*/ NPT_Result PLT_MediaBrowser::OnDeviceRemoved(PLT_DeviceDataReference& device) { if (!device->GetType().StartsWith("urn:schemas-upnp-org:device:MediaServer")) return NPT_FAILURE; { NPT_AutoLock lock(m_MediaServers); // only release if we have kept it around PLT_DeviceDataReference data; NPT_String uuid = device->GetUUID(); // Have we seen that device? if (NPT_FAILED(NPT_ContainerFind(m_MediaServers, PLT_DeviceDataFinder(uuid), data))) { NPT_LOG_WARNING_1("Device (%s) not found in our list!", (const char*)uuid); return NPT_FAILURE; } NPT_LOG_FINE_1("Device Removed: %s", (const char*)*device); m_MediaServers.Remove(device); } if (m_Delegate) { m_Delegate->OnMSRemoved(device); } return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::ChooseDevice +---------------------------------------------------------------------*/ PLT_DeviceDataReference PLT_MicroMediaController::ChooseDevice(const NPT_Lock<PLT_DeviceMap>& deviceList) { PLT_StringMap namesTable; PLT_DeviceDataReference* result = NULL; NPT_String chosenUUID; NPT_AutoLock lock(m_MediaServers); // create a map with the device UDN -> device Name const NPT_List<PLT_DeviceMapEntry*>& entries = deviceList.GetEntries(); NPT_List<PLT_DeviceMapEntry*>::Iterator entry = entries.GetFirstItem(); while (entry) { PLT_DeviceDataReference device = (*entry)->GetValue(); NPT_String name = device->GetFriendlyName(); namesTable.Put((*entry)->GetKey(), name); ++entry; } // ask user to choose chosenUUID = ChooseIDFromTable(namesTable); if (chosenUUID.GetLength()) { deviceList.Get(chosenUUID, result); } return result?*result:PLT_DeviceDataReference(); // return empty reference if not device was selected }
/*---------------------------------------------------------------------- | CUPnPDirectory::GetFriendlyName +---------------------------------------------------------------------*/ const char* CUPnPDirectory::GetFriendlyName(const char* url) { NPT_String path = url; if (!path.EndsWith("/")) path += "/"; if (path.Left(7).Compare("upnp://", true) != 0) { return NULL; } else if (path.Compare("upnp://", true) == 0) { return "UPnP Media Servers (Auto-Discover)"; } // look for nextslash int next_slash = path.Find('/', 7); if (next_slash == -1) return NULL; NPT_String uuid = path.SubString(7, next_slash-7); NPT_String object_id = path.SubString(next_slash+1, path.GetLength()-next_slash-2); // look for device PLT_DeviceDataReference device; if(!FindDeviceWait(CUPnP::GetInstance(), uuid, device)) return NULL; return (const char*)device->GetFriendlyName(); }
bool InvokeUpdateObject(const char* id, const char* curr_value, const char* new_value) { CURL url(id); PLT_DeviceDataReference device; PLT_Service* cds; PLT_ActionReference action; CLog::Log(LOGDEBUG, "UPNP: attempting to invoke UpdateObject for %s", id); // check this server supports UpdateObject action NPT_CHECK_LABEL(FindServer(url.GetHostName().c_str(), device),failed); NPT_CHECK_LABEL(device->FindServiceById("urn:upnp-org:serviceId:ContentDirectory", cds),failed); NPT_CHECK_LABEL(m_CtrlPoint->CreateAction( device, "urn:schemas-upnp-org:service:ContentDirectory:1", "UpdateObject", action), failed); NPT_CHECK_LABEL(action->SetArgumentValue("ObjectID", url.GetFileName().c_str()), failed); NPT_CHECK_LABEL(action->SetArgumentValue("CurrentTagValue", curr_value), failed); NPT_CHECK_LABEL(action->SetArgumentValue("NewTagValue", new_value), failed); NPT_CHECK_LABEL(m_CtrlPoint->InvokeAction(action, NULL),failed); CLog::Log(LOGDEBUG, "UPNP: invoked UpdateObject successfully"); return true; failed: CLog::Log(LOGINFO, "UPNP: invoking UpdateObject failed"); return false; }
/*---------------------------------------------------------------------- | PLT_DeviceData::SetDescription +---------------------------------------------------------------------*/ NPT_Result PLT_DeviceData::SetDescription(PLT_DeviceDataReference& root_device, NPT_TimeInterval leasetime, NPT_HttpUrl description_url, const char* description, const NPT_HttpRequestContext& context) { NPT_XmlParser parser; NPT_XmlNode* tree = NULL; NPT_Result res; NPT_XmlElementNode* root = NULL; NPT_String URLBase; // create new device if none passed if (root_device.IsNull()) { root_device = new PLT_DeviceData(description_url, "", leasetime); } res = parser.Parse(description, tree); NPT_CHECK_LABEL_SEVERE(res, cleanup); root = tree->AsElementNode(); if (!root || root->GetTag() != "root" || !root->GetNamespace() || *root->GetNamespace() != "urn:schemas-upnp-org:device-1-0") { NPT_LOG_INFO_1("root namespace is invalid: %s", (root&&root->GetNamespace())?root->GetNamespace()->GetChars():"null"); NPT_CHECK_LABEL_SEVERE(NPT_FAILURE, cleanup); } // look for optional URLBase element if (NPT_SUCCEEDED(PLT_XmlHelper::GetChildText(root, "URLBase", URLBase))) { NPT_HttpUrl url(URLBase); // Some devices like Connect360 try to be funny - not so if (url.GetHost().ToLowercase() == "localhost" || url.GetHost().ToLowercase() == "127.0.0.1") { url.SetHost(context.GetRemoteAddress().GetIpAddress().ToString()); } root_device->SetURLBase(url); } else { // No URLBase, derive from description url root_device->SetURLBase(description_url); } // at least one root device child element is required NPT_XmlElementNode* device; if (!(device = PLT_XmlHelper::GetChild(root, "device"))) { NPT_CHECK_LABEL_SEVERE(NPT_FAILURE, cleanup); } res = SetDescriptionDevice(root_device, device, context); cleanup: // delete the tree delete tree; return res; }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::HandleCmd_stop +---------------------------------------------------------------------*/ void PLT_MicroMediaController::HandleCmd_stop() { PLT_DeviceDataReference device; GetCurMediaRenderer(device); if (!device.IsNull()) { Stop(device, 0, NULL); } }
virtual void OnMRRemoved(PLT_DeviceDataReference& device ) { if (device->GetUUID().IsEmpty() || device->GetUUID().GetChars() == NULL) return; std::string uuid(device->GetUUID().GetChars()); unregisterRenderer(uuid); m_registeredRenderers.erase(uuid); }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::HandleCmd_unmute +---------------------------------------------------------------------*/ void PLT_MicroMediaController::HandleCmd_unmute() { PLT_DeviceDataReference device; GetCurMediaRenderer(device); if (!device.IsNull()) { SetMute(device, 0, "Master", false, NULL); } }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::HandleCmd_open +---------------------------------------------------------------------*/ void PLT_MicroMediaController::HandleCmd_open() { NPT_String object_id; PLT_StringMap tracks; PLT_DeviceDataReference device; GetCurMediaRenderer(device); if (!device.IsNull()) { // get the protocol info to try to see in advance if a track would play on the device // issue a browse DoBrowse(); if (!m_MostRecentBrowseResults.IsNull()) { // create a map item id -> item title NPT_List<PLT_MediaObject*>::Iterator item = m_MostRecentBrowseResults->GetFirstItem(); while (item) { if (!(*item)->IsContainer()) { tracks.Put((*item)->m_ObjectID, (*item)->m_Title); } ++item; } // let the user choose which one object_id = ChooseIDFromTable(tracks); if (object_id.GetLength()) { // look back for the PLT_MediaItem in the results PLT_MediaObject* track = NULL; if (NPT_SUCCEEDED(NPT_ContainerFind(*m_MostRecentBrowseResults, PLT_MediaItemIDFinder(object_id), track))) { if (track->m_Resources.GetItemCount() > 0) { // look for best resource to use by matching each resource to a sink advertised by renderer NPT_Cardinal resource_index = 0; if (NPT_FAILED(FindBestResource(device, *track, resource_index))) { printf("No matching resource\n"); return; } // invoke the setUri printf("Issuing SetAVTransportURI with url=%s & didl=%s", (const char*)track->m_Resources[resource_index].m_Uri, (const char*)track->m_Didl); SetAVTransportURI(device, 0, track->m_Resources[resource_index].m_Uri, track->m_Didl, NULL); } else { printf("Couldn't find the proper resource\n"); } } else { printf("Couldn't find the track\n"); } } m_MostRecentBrowseResults = NULL; } } }
virtual bool OnMRAdded(PLT_DeviceDataReference& device ) { if (device->GetUUID().IsEmpty() || device->GetUUID().GetChars() == NULL) return false; CPlayerCoreFactory::GetInstance().OnPlayerDiscovered((const char*)device->GetUUID() ,(const char*)device->GetFriendlyName() , EPC_UPNPPLAYER); m_registeredRenderers.insert(std::string(device->GetUUID().GetChars())); return true; }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::HandleCmd_getmr +---------------------------------------------------------------------*/ void PLT_MicroMediaController::HandleCmd_getmr() { PLT_DeviceDataReference device; GetCurMediaRenderer(device); if (!device.IsNull()) { printf("Current media renderer: %s\n", (const char*)device->GetFriendlyName()); } else { // this output is taken care of by the GetCurMediaRenderer call } }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::OnMRAdded +---------------------------------------------------------------------*/ bool PLT_MicroMediaController::OnMRAdded(PLT_DeviceDataReference& device) { NPT_String uuid = device->GetUUID(); // test if it's a media renderer PLT_Service* service; if (NPT_SUCCEEDED(device->FindServiceByType("urn:schemas-upnp-org:service:AVTransport:*", service))) { NPT_AutoLock lock(m_MediaRenderers); m_MediaRenderers.Put(uuid, device); } return true; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::OnDeviceAdded +---------------------------------------------------------------------*/ NPT_Result PLT_SyncMediaBrowser::OnDeviceAdded(PLT_DeviceDataReference& device) { NPT_String uuid = device->GetUUID(); // test if it's a media server PLT_Service* service; if (NPT_SUCCEEDED(device->FindServiceByType("urn:schemas-upnp-org:service:ContentDirectory:*", service))) { NPT_AutoLock lock(m_MediaServers); m_MediaServers.Put(uuid, device); } return PLT_MediaBrowser::OnDeviceAdded(device); }
bool GPAC_MediaController::OnMSAdded(PLT_DeviceDataReference& device) { NPT_String uuid = device->GetUUID(); gf_mx_p(m_ControlPointLock); // test if it's a media server PLT_Service* service; if (NPT_SUCCEEDED(device->FindServiceByType("urn:schemas-upnp-org:service:ContentDirectory:1", service))) { gf_list_add(m_MediaServers, new GPAC_MediaServerItem(device, uuid) ); } m_pUPnP->OnMediaServerAdd(device, 1); gf_mx_v(m_ControlPointLock); return true; }
/*---------------------------------------------------------------------- | PLT_MediaBrowser::Search +---------------------------------------------------------------------*/ NPT_Result PLT_MediaBrowser::Search(PLT_DeviceDataReference& device, const char* container_id, const char* search_criteria, NPT_UInt32 start_index, NPT_UInt32 count, const char* filter, void* userdata) { // verify device still in our list PLT_DeviceDataReference device_data; NPT_CHECK_WARNING(FindServer(device->GetUUID(), device_data)); // create action PLT_ActionReference action; NPT_CHECK_SEVERE(m_CtrlPoint->CreateAction( device, "urn:schemas-upnp-org:service:ContentDirectory:1", "Search", action)); // Set the container id PLT_Arguments args; if (NPT_FAILED(action->SetArgumentValue("ContainerID", container_id))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Search Criteria if (NPT_FAILED(action->SetArgumentValue("SearchCriteria", search_criteria))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Filter if (NPT_FAILED(action->SetArgumentValue("Filter", filter))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Starting Index if (NPT_FAILED(action->SetArgumentValue("StartingIndex", NPT_String::FromInteger(start_index)))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Requested Count if (NPT_FAILED(action->SetArgumentValue("RequestedCount", NPT_String::FromInteger(count)))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Requested Count if (NPT_FAILED(action->SetArgumentValue("SortCriteria", ""))) { return NPT_ERROR_INVALID_PARAMETERS; } // invoke the action if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) { return NPT_ERROR_INVALID_PARAMETERS; } return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_MediaBrowser::Browse +---------------------------------------------------------------------*/ NPT_Result PLT_MediaBrowser::Browse(PLT_DeviceDataReference& device, const char* obj_id, NPT_UInt32 start_index, NPT_UInt32 count, bool browse_metadata, const char* filter, const char* sort_criteria, void* userdata) { // verify device still in our list PLT_DeviceDataReference device_data; NPT_CHECK_WARNING(FindServer(device->GetUUID(), device_data)); // create action PLT_ActionReference action; NPT_CHECK_SEVERE(m_CtrlPoint->CreateAction( device, "urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", action)); // Set the object id PLT_Arguments args; if (NPT_FAILED(action->SetArgumentValue("ObjectID", obj_id))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the browse_flag if (NPT_FAILED(action->SetArgumentValue("BrowseFlag", browse_metadata?"BrowseMetadata":"BrowseDirectChildren"))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Filter if (NPT_FAILED(action->SetArgumentValue("Filter", filter))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Starting Index if (NPT_FAILED(action->SetArgumentValue("StartingIndex", NPT_String::FromInteger(start_index)))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Requested Count if (NPT_FAILED(action->SetArgumentValue("RequestedCount", NPT_String::FromInteger(count)))) { return NPT_ERROR_INVALID_PARAMETERS; } // set the Requested Count if (NPT_FAILED(action->SetArgumentValue("SortCriteria", sort_criteria))) { return NPT_ERROR_INVALID_PARAMETERS; } // invoke the action if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) { return NPT_ERROR_INVALID_PARAMETERS; } return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::OnDeviceRemoved +---------------------------------------------------------------------*/ NPT_Result PLT_SyncMediaBrowser::OnDeviceRemoved(PLT_DeviceDataReference& device) { NPT_String uuid = device->GetUUID(); // Remove from our list of servers first if found { NPT_AutoLock lock(m_MediaServers); m_MediaServers.Erase(uuid); } // clear cache for that device if (m_UseCache) m_Cache.Clear(device.AsPointer()->GetUUID()); return PLT_MediaBrowser::OnDeviceRemoved(device); }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::HandleCmd_seek +---------------------------------------------------------------------*/ void PLT_MicroMediaController::HandleCmd_seek(const char* command) { PLT_DeviceDataReference device; GetCurMediaRenderer(device); if (!device.IsNull()) { // remove first part of command ("seek") NPT_String target = command; NPT_List<NPT_String> args = target.Split(" "); if (args.GetItemCount() < 2) return; args.Erase(args.GetFirstItem()); target = NPT_String::Join(args, " "); Seek(device, 0, (target.Find(":")!=-1)?"REL_TIME":"X_DLNA_REL_BYTE", target, NULL); } }
/*---------------------------------------------------------------------- | PLT_MediaBrowser::OnDeviceAdded +---------------------------------------------------------------------*/ NPT_Result PLT_MediaBrowser::OnDeviceAdded(PLT_DeviceDataReference& device) { // verify the device implements the function we need PLT_Service* serviceCDS; PLT_Service* serviceCMR; NPT_String type; type = "urn:schemas-upnp-org:service:ContentDirectory:1"; if (NPT_FAILED(device->FindServiceByType(type, serviceCDS))) { NPT_LOG_WARNING_1("Service %s not found", (const char*)type); return NPT_FAILURE; } type = "urn:schemas-upnp-org:service:ConnectionManager:1"; if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) { NPT_LOG_WARNING_1("Service %s not found", (const char*)type); return NPT_FAILURE; } { NPT_AutoLock lock(m_MediaServers); PLT_DeviceDataReference data; NPT_String uuid = device->GetUUID(); // is it a new device? if (NPT_SUCCEEDED(NPT_ContainerFind(m_MediaServers, PLT_DeviceDataFinder(uuid), data))) { NPT_LOG_WARNING_1("Device (%s) is already in our list!", (const char*)uuid); return NPT_FAILURE; } NPT_LOG_FINE("Device Found:"); device->ToLog(NPT_LOG_LEVEL_FINE); m_MediaServers.Add(device); } if (m_Listener) { m_Listener->OnMSAddedRemoved(device, 1); } m_CtrlPoint->Subscribe(serviceCDS); m_CtrlPoint->Subscribe(serviceCMR); return NPT_SUCCESS; }
NPT_Result GPAC_GenericController::OnDeviceAdded(PLT_DeviceDataReference& device) { GPAC_DeviceItem *item; NPT_String uuid = device->GetUUID(); gf_mx_p(m_ControlPointLock); u32 i, count = gf_list_count(m_Devices); for (i=0; i<count; i++) { item = (GPAC_DeviceItem *) gf_list_get(m_Devices, i); if (item->m_UUID == uuid ) { gf_mx_v(m_ControlPointLock); return NPT_SUCCESS; } } item = new GPAC_DeviceItem(device, device->GetUUID() ); gf_list_add(m_Devices, item ); m_pUPnP->OnDeviceAdd(item, 1); gf_mx_v(m_ControlPointLock); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::OnMSStateVariablesChanged +---------------------------------------------------------------------*/ void PLT_SyncMediaBrowser::OnMSStateVariablesChanged(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars) { NPT_AutoLock lock(m_MediaServers); PLT_DeviceDataReference device; const NPT_List<PLT_DeviceMapEntry*>::Iterator it = m_MediaServers.GetEntries().Find(PLT_DeviceMapFinderByUUID(service->GetDevice()->GetUUID())); if (!it) return; // device with this service has gone away device = (*it)->GetValue(); PLT_StateVariable* var = PLT_StateVariable::Find(*vars, "ContainerUpdateIDs"); if (var) { // variable found, parse value NPT_String value = var->GetValue(); NPT_String item_id, update_id; int index; while (value.GetLength()) { // look for container id index = value.Find(','); if (index < 0) break; item_id = value.Left(index); value = value.SubString(index+1); // look for update id if (value.GetLength()) { index = value.Find(','); update_id = (index<0)?value:value.Left(index); value = (index<0)?"":value.SubString(index+1); // clear cache for that device if (m_UseCache) m_Cache.Clear(device->GetUUID(), item_id); // notify listener if (m_ContainerListener) m_ContainerListener->OnContainerChanged(device, item_id, update_id); } } } }
/*---------------------------------------------------------------------- | PLT_MediaController::GetProtocolInfoSink +---------------------------------------------------------------------*/ NPT_Result PLT_MediaController::GetProtocolInfoSink(PLT_DeviceDataReference& device, NPT_List<NPT_String>& sinks) { PLT_DeviceDataReference renderer; NPT_CHECK_WARNING(FindRenderer(device->GetUUID(), renderer)); // look for ConnectionManager service PLT_Service* serviceCMR; NPT_CHECK_SEVERE(device->FindServiceByType( "urn:schemas-upnp-org:service:ConnectionManager:*", serviceCMR)); NPT_String value; NPT_CHECK_SEVERE(serviceCMR->GetStateVariableValue( "SinkProtocolInfo", value)); sinks = value.Split(","); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_MicroMediaController::DoBrowse +---------------------------------------------------------------------*/ NPT_Result PLT_MicroMediaController::DoBrowse(const char* object_id, /* = NULL */ bool metadata /* = false */) { NPT_Result res = NPT_FAILURE; PLT_DeviceDataReference device; GetCurMediaServer(device); if (!device.IsNull()) { NPT_String cur_object_id; m_CurBrowseDirectoryStack.Peek(cur_object_id); // send off the browse packet and block res = BrowseSync( device, object_id?object_id:(const char*)cur_object_id, m_MostRecentBrowseResults, metadata); } return res; }
/*---------------------------------------------------------------------- | PLT_MediaController::OnDeviceAdded +---------------------------------------------------------------------*/ NPT_Result PLT_MediaController::OnDeviceAdded(PLT_DeviceDataReference& device) { PLT_DeviceDataReference data; NPT_String uuid = device->GetUUID(); // is it a new device? if (NPT_SUCCEEDED(NPT_ContainerFind(m_MediaRenderers, PLT_DeviceDataFinder(uuid), data))) { NPT_LOG_FINE_1("Device (%s) is already in our list!", (const char*)uuid); return NPT_FAILURE; } NPT_LOG_FINE("Device Found:"); device->ToLog(NPT_LOG_LEVEL_FINE); // verify the device implements the function we need PLT_Service* serviceAVT; PLT_Service* serviceCMR; NPT_String type; type = "urn:schemas-upnp-org:service:AVTransport:1"; if (NPT_FAILED(device->FindServiceByType(type, serviceAVT))) { NPT_LOG_FINE_1("Service %s not found", (const char*)type); return NPT_FAILURE; } type = "urn:schemas-upnp-org:service:ConnectionManager:1"; if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) { NPT_LOG_FINE_1("Service %s not found", (const char*)type); return NPT_FAILURE; } m_MediaRenderers.Add(device); if (m_Listener) { m_Listener->OnMRAddedRemoved(device, 1); } // subscribe to AVT eventing m_CtrlPoint->Subscribe(serviceAVT); return NPT_SUCCESS; }
static std::string LookupUPnPHost(const std::string& uuid) { #ifdef HAS_UPNP UPNP::CUPnP* upnp = UPNP::CUPnP::GetInstance(); if (!upnp->IsClientStarted()) { upnp->StartClient(); upnpInitReady = CDateTime::GetCurrentDateTime() + CDateTimeSpan(0, 0, 0, 10); } PLT_SyncMediaBrowser* browser = upnp->m_MediaBrowser; PLT_DeviceDataReference device; if (browser && NPT_SUCCEEDED(browser->FindServer(uuid.c_str(), device)) && !device.IsNull()) return (const char*)device->GetURLBase().GetHost(); #endif return ""; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::OnMSAddedRemoved +---------------------------------------------------------------------*/ void PLT_SyncMediaBrowser::OnMSAddedRemoved(PLT_DeviceDataReference& device, int added) { NPT_String uuid = device->GetUUID(); if (added) { // test if it's a media server m_MediaServers.Lock(); PLT_Service* service; if (NPT_SUCCEEDED(device->FindServiceByType("urn:schemas-upnp-org:service:ContentDirectory:1", service))) { m_MediaServers.Put(uuid, device); } m_MediaServers.Unlock(); } else { /* removed */ // Remove from our list of servers first if found m_MediaServers.Lock(); m_MediaServers.Erase(uuid); m_MediaServers.Unlock(); // clear cache for that device if (m_UseCache) m_Cache.Clear(device.AsPointer()->GetUUID()); } }