예제 #1
0
파일: UPnP.cpp 프로젝트: MrMC/mrmc
  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);
  }
예제 #2
0
파일: UPnP.cpp 프로젝트: MrMC/mrmc
  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;
  }
예제 #3
0
/*----------------------------------------------------------------------
|   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;
}
예제 #4
0
/*----------------------------------------------------------------------
|   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;
}
예제 #5
0
/*----------------------------------------------------------------------
|   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;
}
예제 #6
0
/*----------------------------------------------------------------------
|   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;
}
예제 #7
0
 virtual bool OnMRAdded(PLT_DeviceDataReference& device )
 {
   CPlayerCoreFactory::Get().OnPlayerDiscovered((const char*)device->GetUUID()
                                         ,(const char*)device->GetFriendlyName()
                                         , EPC_UPNPPLAYER);
   return true;
 }
예제 #8
0
/*----------------------------------------------------------------------
|   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;

    if (!device->GetType().StartsWith("urn:schemas-upnp-org:device:MediaServer"))
        return NPT_FAILURE;
    
    type = "urn:schemas-upnp-org:service:ContentDirectory:*";
    if (NPT_FAILED(device->FindServiceByType(type, serviceCDS))) {
        NPT_LOG_WARNING_2("Service %s not found in device \"%s\"", 
            type.GetChars(),
            device->GetFriendlyName().GetChars());
        return NPT_FAILURE;
    } else {
        // in case it's a newer upnp implementation, force to 1
        serviceCDS->ForceVersion(1);
    }
    
    type = "urn:schemas-upnp-org:service:ConnectionManager:*";
    if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) {
        NPT_LOG_WARNING_2("Service %s not found in device \"%s\"", 
            type.GetChars(), 
            device->GetFriendlyName().GetChars());
        return NPT_FAILURE;
    } else {
        // in case it's a newer upnp implementation, force to 1
        serviceCMR->ForceVersion(1);
    }
    
    {
        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_1("Device Found: %s", (const char*)*device);

        m_MediaServers.Add(device);
    }

    if (m_Delegate && m_Delegate->OnMSAdded(device)) {
        m_CtrlPoint->Subscribe(serviceCDS);
        m_CtrlPoint->Subscribe(serviceCMR);
    }
    
    return NPT_SUCCESS;
}
예제 #9
0
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;
}
예제 #10
0
/*----------------------------------------------------------------------
|   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);
}
/*----------------------------------------------------------------------
|   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;
}
예제 #12
0
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;
}
예제 #13
0
파일: UPnP.cpp 프로젝트: MrMC/mrmc
    // PLT_MediaContainerChangesListener methods
    virtual void OnContainerChanged(PLT_DeviceDataReference& device,
                                    const char*              item_id,
                                    const char*              update_id)
    {
        NPT_String path = "upnp://"+device->GetUUID()+"/";
        if (!NPT_StringsEqual(item_id, "0")) {
            std::string id(CURL::Encode(item_id));
            URIUtils::AddSlashAtEnd(id);
            path += id.c_str();
        }

        CLog::Log(LOGDEBUG, "UPNP: notfified container update %s", (const char*)path);
        CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH);
        message.SetStringParam(path.GetChars());
        g_windowManager.SendThreadMessage(message);
    }
예제 #14
0
/*----------------------------------------------------------------------
|   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);
}
예제 #15
0
/*----------------------------------------------------------------------
|   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;
}
예제 #16
0
void
GPAC_MediaController::OnMSRemoved(PLT_DeviceDataReference& device)
{
    NPT_String uuid = device->GetUUID();

     gf_mx_p(m_ControlPointLock);
	u32 i, count;
	count = gf_list_count(m_MediaServers);
	for (i=0; i<count; i++) {
		GPAC_MediaServerItem *ms = (GPAC_MediaServerItem *) gf_list_get(m_MediaServers, i);
		if (ms->m_UUID==uuid) {
			delete ms;
			gf_list_rem(m_MediaServers, i);
			break;
		}
	}
	m_pUPnP->OnMediaServerAdd(device, 0);
    gf_mx_v(m_ControlPointLock);
}
/*----------------------------------------------------------------------
|   PLT_MicroMediaController::OnMRRemoved
+---------------------------------------------------------------------*/
void
PLT_MicroMediaController::OnMRRemoved(PLT_DeviceDataReference& device)
{
    NPT_String uuid = device->GetUUID();

    {
        NPT_AutoLock lock(m_MediaRenderers);
        m_MediaRenderers.Erase(uuid);
    }

    {
        NPT_AutoLock lock(m_CurMediaRendererLock);

        // if it's the currently selected one, we have to get rid of it
        if (!m_CurMediaRenderer.IsNull() && m_CurMediaRenderer == device) {
            m_CurMediaRenderer = NULL;
        }
    }
}
예제 #18
0
/*----------------------------------------------------------------------
|   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);
            }       
        }
    }        
}
예제 #19
0
/*----------------------------------------------------------------------
|   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;
}
예제 #20
0
/*----------------------------------------------------------------------
|   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;
}
예제 #21
0
NPT_Result GPAC_GenericController::OnDeviceRemoved(PLT_DeviceDataReference& device)
{
	u32 i, count;
	GPAC_DeviceItem *item = NULL;
	NPT_String uuid = device->GetUUID();
	gf_mx_p(m_ControlPointLock);
	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_list_rem(m_Devices, i);
			break;
		}
		item = NULL;
	}
	if (item) {
		m_pUPnP->OnDeviceAdd(item, 0);
		delete item;
	}
	gf_mx_v(m_ControlPointLock);
	return NPT_SUCCESS;
}
예제 #22
0
/*----------------------------------------------------------------------
|   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());
    }
}
예제 #23
0
/*----------------------------------------------------------------------
|   CMediaCrawler::OnBrowseRoot
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::OnBrowseRoot(PLT_ActionReference& action)
{
    NPT_String browseFlagValue;
    if (NPT_FAILED(action->GetArgumentValue("BrowseFlag", browseFlagValue))) {
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowse - invalid arguments.");
        return NPT_FAILURE;
    }

    /* extract browseFlag */
    BrowseFlags browseFlag;
    if (NPT_FAILED(GetBrowseFlag(browseFlagValue, browseFlag))) {
        /* error */
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowseRoot - BrowseFlag value not allowed.");
        action->SetError(402,"Invalid BrowseFlag arg.");
        return NPT_FAILURE;
    }

    if (browseFlag == BROWSEMETADATA) {
        PLT_MediaContainer item;
        item.m_Title = "Root";
        item.m_ParentID = "-1";
        item.m_ObjectID = "0";
        item.m_ChildrenCount = GetMediaServers().GetItemCount();
        item.m_ObjectClass.type = "object.container";

        /* convert item to didl */
        NPT_String filter;
        action->GetArgumentValue("Filter", filter);
        NPT_String tmp;
        NPT_CHECK_SEVERE(PLT_Didl::ToDidl(item, filter, tmp));

        /* add didl header and footer */
        NPT_String didl = didl_header + tmp + didl_footer;

        action->SetArgumentValue("Result", didl);
        action->SetArgumentValue("NumberReturned", "1");
        action->SetArgumentValue("TotalMatches", "1");

        // update ID may be wrong here, it should be the one of the container?
        action->SetArgumentValue("UpdateId", "1");
        // TODO: We need to keep track of the overall updateID of the CDS
    } else {
        NPT_String startingInd;
        NPT_String reqCount;
        NPT_String filter;

        NPT_CHECK_SEVERE(action->GetArgumentValue("StartingIndex", startingInd));
        NPT_CHECK_SEVERE(action->GetArgumentValue("RequestedCount", reqCount));   
        NPT_CHECK_SEVERE(action->GetArgumentValue("Filter", filter));

        unsigned long start_index, req_count;
        if (NPT_FAILED(startingInd.ToInteger(start_index)) ||
            NPT_FAILED(reqCount.ToInteger(req_count))) {
            return NPT_FAILURE;
        }   
                    
        unsigned long cur_index = 0;
        unsigned long num_returned = 0;
        unsigned long total_matches = 0;
        //unsigned long update_id = 0;
        PLT_MediaContainer item;
        NPT_String tmp;
        NPT_String didl = didl_header;

        // populate a list of containers (one container per known servers)
        const NPT_Lock<PLT_DeviceDataReferenceList>& devices = GetMediaServers();
        NPT_Lock<PLT_DeviceDataReferenceList>::Iterator entry = devices.GetFirstItem();
        while (entry) {
            PLT_DeviceDataReference device = (*entry);
            item.m_Title = device->GetFriendlyName();
            item.m_ObjectID = FormatObjectId(device->GetUUID(), "0");
            item.m_ParentID = "0";
            item.m_ObjectClass.type = "object.container";

            if ((cur_index >= start_index) && ((num_returned < req_count) || (req_count == 0))) {
                NPT_CHECK_SEVERE(PLT_Didl::ToDidl(item, filter, tmp));

                didl += tmp;
                num_returned++;
            }
            cur_index++;
            total_matches++;  

            ++entry;
        }

        didl += didl_footer;

        action->SetArgumentValue("Result", didl);
        action->SetArgumentValue("NumberReturned", NPT_String::FromInteger(num_returned));
        action->SetArgumentValue("TotalMatches", NPT_String::FromInteger(total_matches));
        action->SetArgumentValue("UpdateId", "1");
    }

    return NPT_SUCCESS;
}
예제 #24
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::BrowseSync
+---------------------------------------------------------------------*/
NPT_Result
PLT_SyncMediaBrowser::BrowseSync(PLT_DeviceDataReference&      device, 
                                 const char*                   object_id, 
                                 PLT_MediaObjectListReference& list,
                                 bool                          metadata, /* = false */
                                 NPT_Int32                     start, /* = 0 */
                                 NPT_Cardinal                  max_results /* = 0 */)
{
    NPT_Result res = NPT_FAILURE;
    NPT_Int32  index = start;

    // reset output params
    list = NULL;

    // look into cache first
    if (m_UseCache && NPT_SUCCEEDED(m_Cache.Get(device->GetUUID(), object_id, list))) return NPT_SUCCESS;

    do {	
        PLT_BrowseDataReference browse_data(new PLT_BrowseData());

        // send off the browse packet.  Note that this will
        // not block.  There is a call to WaitForResponse in order
        // to block until the response comes back.
        res = BrowseSync(
            browse_data,
            device,
            (const char*)object_id,
            index,
            metadata?1:30, // DLNA recommendations for browsing children is no more than 30 at a time
            metadata);		
        NPT_CHECK_LABEL_WARNING(res, done);
        
        if (NPT_FAILED(browse_data->res)) {
            res = browse_data->res;
            NPT_CHECK_LABEL_WARNING(res, done);
        }

        if (browse_data->info.items->GetItemCount() == 0)
            break;

        if (list.IsNull()) {
            list = browse_data->info.items;
        } else {
            list->Add(*browse_data->info.items);
            // clear the list items so that the data inside is not
            // cleaned up by PLT_MediaItemList dtor since we copied
            // each pointer into the new list.
            browse_data->info.items->Clear();
        }

        // stop now if our list contains exactly what the server said it had.
        // Note that the server could return 0 if it didn't know how many items were
        // available. In this case we have to continue browsing until
        // nothing is returned back by the server.
        // Unless we were told to stop after reaching a certain amount to avoid
        // length delays
        if ((browse_data->info.tm && browse_data->info.tm == list->GetItemCount()) ||
            (max_results && list->GetItemCount() >= max_results))
            break;

        // ask for the next chunk of entries
        index = list->GetItemCount();
    } while(1);

done:
    // cache the result
    if (m_UseCache && NPT_SUCCEEDED(res) && !list.IsNull() && list->GetItemCount()) {
        m_Cache.Put(device->GetUUID(), object_id, list);
    }

    // clear entire cache data for device if failed, the device could be gone
    if (NPT_FAILED(res) && m_UseCache) m_Cache.Clear(device->GetUUID());
    
    return res;
}
예제 #25
0
/*----------------------------------------------------------------------
|   PLT_MediaController::OnDeviceAdded
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnDeviceAdded(PLT_DeviceDataReference& device)
{
    // verify the device implements the function we need
    PLT_Service* serviceAVT = NULL;
    PLT_Service* serviceCMR;
	PLT_Service* serviceRC;
    NPT_String   type;
    
    if (!device->GetType().StartsWith("urn:schemas-upnp-org:device:MediaRenderer"))
        return NPT_FAILURE;

    // optional service
    type = "urn:schemas-upnp-org:service:AVTransport:*";
    if (NPT_SUCCEEDED(device->FindServiceByType(type, serviceAVT))) {
        // in case it's a newer upnp implementation, force to 1
        NPT_LOG_FINE_1("Service %s found", (const char*)type);
        serviceAVT->ForceVersion(1);
    }
    
    // required services
    type = "urn:schemas-upnp-org:service:ConnectionManager:*";
    if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) {
        NPT_LOG_FINE_1("Service %s not found", (const char*)type);
        return NPT_FAILURE;
    } else {
        // in case it's a newer upnp implementation, force to 1
        serviceCMR->ForceVersion(1);
    }

	type = "urn:schemas-upnp-org:service:RenderingControl:*";
    if (NPT_FAILED(device->FindServiceByType(type, serviceRC))) {
        NPT_LOG_FINE_1("Service %s not found", (const char*)type);
        return NPT_FAILURE;
    } else {
        // in case it's a newer upnp implementation, force to 1
        serviceRC->ForceVersion(1);
    }

    {
        NPT_AutoLock lock(m_MediaRenderers);

        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_WARNING_1("Device (%s) is already in our list!", (const char*)uuid);
            return NPT_FAILURE;
        }

        NPT_LOG_FINE_1("Device Found: %s", (const char*)*device);

        m_MediaRenderers.Add(device);
    }
    
    if (m_Delegate && m_Delegate->OnMRAdded(device)) {
        // subscribe to services eventing only if delegate wants it
        if (serviceAVT) m_CtrlPoint->Subscribe(serviceAVT);

        // subscribe to required services
		m_CtrlPoint->Subscribe(serviceCMR);
		m_CtrlPoint->Subscribe(serviceRC);
    }

    return NPT_SUCCESS;
}
예제 #26
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::Browse
+---------------------------------------------------------------------*/
NPT_Result
PLT_SyncMediaBrowser::Browse(PLT_DeviceDataReference&      device, 
                             const char*                   object_id, 
                             PLT_MediaObjectListReference& list)
{
    NPT_Result res = NPT_FAILURE;
    NPT_Int32  index = 0;

    // reset output params
    list = NULL;

    // look into cache first
    if (m_UseCache && NPT_SUCCEEDED(m_Cache.Get(device->GetUUID(), object_id, list))) return NPT_SUCCESS;

    do {	
        PLT_BrowseDataReference browse_data(new PLT_BrowseData());

        // send off the browse packet.  Note that this will
        // not block.  There is a call to WaitForResponse in order
        // to block until the response comes back.
        res = Browse(browse_data,
            device,
            (const char*)object_id,
            index,
            1024,
            false,
            "*",
            "");		
        NPT_CHECK_LABEL_WARNING(res, done);
        
        if (NPT_FAILED(browse_data->res)) {
            res = browse_data->res;
            NPT_CHECK_LABEL_WARNING(res, done);
        }

        if (browse_data->info.items->GetItemCount() == 0)
            break;

        if (list.IsNull()) {
            list = browse_data->info.items;
        } else {
            list->Add(*browse_data->info.items);
            // clear the list items so that the data inside is not
            // cleaned up by PLT_MediaItemList dtor since we copied
            // each pointer into the new list.
            browse_data->info.items->Clear();
        }

        // stop now if our list contains exactly what the server said it had
        if (browse_data->info.tm && browse_data->info.tm == list->GetItemCount())
            break;

        // ask for the next chunk of entries
        index = list->GetItemCount();
    } while(1);

done:
    // cache the result
    if (m_UseCache && NPT_SUCCEEDED(res) && !list.IsNull() && list->GetItemCount()) {
        m_Cache.Put(device->GetUUID(), object_id, list);
    }

    // clear entire cache data for device if failed, the device could be gone
    if (NPT_FAILED(res) && m_UseCache) m_Cache.Clear(device->GetUUID());
    
    return res;
}
예제 #27
0
 virtual void OnMRRemoved(PLT_DeviceDataReference& device )
 {
   CPlayerCoreFactory::Get().OnPlayerRemoved((const char*)device->GetUUID());
 }