Esempio n. 1
0
/*----------------------------------------------------------------------
|   PLT_SsdpAnnounceInterfaceIterator class
+---------------------------------------------------------------------*/
NPT_Result
PLT_SsdpAnnounceInterfaceIterator::operator()(NPT_NetworkInterface*& net_if) const 
{
    // don't use this interface address if it's not broadcast capable
    if (m_Broadcast && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST)) {
        return NPT_FAILURE;
    }

    NPT_List<NPT_NetworkInterfaceAddress>::Iterator niaddr = 
        net_if->GetAddresses().GetFirstItem();
    if (!niaddr) return NPT_FAILURE;

    // Remove disconnected interfaces
    NPT_IpAddress addr = (*niaddr).GetPrimaryAddress();
    if (!addr.ToString().Compare("0.0.0.0")) return NPT_FAILURE;
    
    if (!m_Broadcast && 
        !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_MULTICAST) && 
        !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_LOOPBACK)) {
        NPT_LOG_INFO_2("Not a valid interface: %s (flags: %d)", 
                       (const char*)addr.ToString(), net_if->GetFlags());
        return NPT_FAILURE;
    }

    NPT_HttpUrl            url;
    NPT_UdpMulticastSocket multicast_socket;
    NPT_UdpSocket          broadcast_socket;
    NPT_UdpSocket*         socket;

    if (m_Broadcast) {
        url = NPT_HttpUrl((*niaddr).GetBroadcastAddress().ToString(), 1900, "*");
        socket = &broadcast_socket;
    } else {
        url = NPT_HttpUrl("239.255.255.250", 1900, "*");    
        NPT_CHECK_SEVERE(multicast_socket.SetInterface(addr));
        socket = &multicast_socket;
        multicast_socket.SetTimeToLive(PLT_Constants::GetInstance().GetAnnounceMulticastTimeToLive());
    }
    
    NPT_HttpRequest req(url, "NOTIFY", NPT_HTTP_PROTOCOL_1_1);
    PLT_HttpHelper::SetHost(req, "239.255.255.250:1900");
    
    // Location header valid only for ssdp:alive or ssdp:update messages
    if (m_Type != PLT_ANNOUNCETYPE_BYEBYE) {
        PLT_UPnPMessageHelper::SetLocation(req, m_Device->GetDescriptionUrl(addr.ToString()));
    }

    NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_Type));

#if defined(PLATINUM_UPNP_SPECS_STRICT)
    // delay alive only as we don't want to delay when stopping
    if (m_Type != PLT_ANNOUNCETYPE_BYEBYE) {
        NPT_System::Sleep(NPT_TimeInterval(PLT_DLNA_SSDP_DELAY_GROUP));
    }
    
    NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_Type));
#endif

    return NPT_SUCCESS;
}
Esempio n. 2
0
File: UPnP.cpp Progetto: MrMC/mrmc
/*----------------------------------------------------------------------
|   CUPnP::CreateServer
+---------------------------------------------------------------------*/
CUPnPServer*
CUPnP::CreateServer(int port /* = 0 */)
{
    CUPnPServer* device =
        new CUPnPServer(CSysInfo::GetDeviceName().c_str(),
                        CUPnPSettings::GetInstance().GetServerUUID().length() ? CUPnPSettings::GetInstance().GetServerUUID().c_str() : NULL,
                        port);

    // trying to set optional upnp values for XP UPnP UI Icons to detect us
    // but it doesn't work anyways as it requires multicast for XP to detect us
    device->m_PresentationURL =
        NPT_HttpUrl(m_IP.c_str(),
                    CSettings::GetInstance().GetInt(CSettings::SETTING_SERVICES_WEBSERVERPORT),
                    "/").ToString();

    device->m_ModelName        = "MrMC";
    device->m_ModelNumber      = CSysInfo::GetVersion().c_str();
    device->m_ModelDescription = "MrMC - Media Server";
    device->m_ModelURL         = "http://mrmc.tv/";
    device->m_Manufacturer     = "MrMC Foundation";
    device->m_ManufacturerURL  = "http://mrmc.tv/";

    device->SetDelegate(device);
    return device;
}
Esempio n. 3
0
/*----------------------------------------------------------------------
|   PLT_FileMediaServer::SetupDevice
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::SetupDevice()
{
    // FIXME: hack for now: find the first valid non local ip address
    // to use in item resources. TODO: we should advertise all ips as
    // multiple resources instead.
    NPT_List<NPT_String> ips;
    PLT_UPnPMessageHelper::GetIPAddresses(ips);
    if (ips.GetItemCount() == 0) return NPT_ERROR_INTERNAL;

    // set the base paths for content and album arts
    m_FileBaseUri     = NPT_HttpUrl(*ips.GetFirstItem(), GetPort(), "/content");
    m_AlbumArtBaseUri = NPT_HttpUrl(*ips.GetFirstItem(), GetPort(), "/albumart");

    return PLT_MediaServer::SetupDevice();
}
Esempio n. 4
0
File: UPnP.cpp Progetto: Ilia/xbmc
/*----------------------------------------------------------------------
|   CUPnP::CreateServer
+---------------------------------------------------------------------*/
CUPnPServer*
CUPnP::CreateServer(int port /* = 0 */)
{
    CUPnPServer* device =
        new CUPnPServer(g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME),
                        g_settings.m_UPnPUUIDServer.length()?g_settings.m_UPnPUUIDServer.c_str():NULL,
                        port);

    // trying to set optional upnp values for XP UPnP UI Icons to detect us
    // but it doesn't work anyways as it requires multicast for XP to detect us
    device->m_PresentationURL =
        NPT_HttpUrl(m_IP,
                    atoi(g_guiSettings.GetString("services.webserverport")),
                    "/").ToString();

    device->m_ModelName        = "XBMC Media Center";
    device->m_ModelNumber      = g_infoManager.GetVersion().c_str();
    device->m_ModelDescription = "XBMC Media Center - Media Server";
    device->m_ModelURL         = "http://www.xbmc.org/";
    device->m_Manufacturer     = "Team XBMC";
    device->m_ManufacturerURL  = "http://www.xbmc.org/";

    device->SetDelegate(device);
    return device;
}
Esempio n. 5
0
/*----------------------------------------------------------------------
|   PLT_DeviceData::GetURLBase
+---------------------------------------------------------------------*/
NPT_HttpUrl
PLT_DeviceData::GetURLBase()
{
    return NPT_HttpUrl(m_URLDescription.GetHost(),
                       m_URLDescription.GetPort(),
                       m_URLBasePath);
}
Esempio n. 6
0
/*----------------------------------------------------------------------
|   PLT_SsdpAnnounceInterfaceIterator class
+---------------------------------------------------------------------*/
NPT_Result
PLT_SsdpAnnounceInterfaceIterator::operator()(NPT_NetworkInterface*& net_if) const 
{
    // don't use this interface address if it's not broadcast capable
    if (m_Broadcast && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST)) {
        return NPT_FAILURE;
    }

    NPT_List<NPT_NetworkInterfaceAddress>::Iterator niaddr = 
        net_if->GetAddresses().GetFirstItem();
    if (!niaddr) return NPT_FAILURE;

    // Remove disconnected interfaces
    NPT_IpAddress addr =  (*niaddr).GetPrimaryAddress();
    if (!addr.ToString().Compare("0.0.0.0")) return NPT_FAILURE;

    NPT_HttpUrl            url;
    NPT_UdpMulticastSocket multicast_socket;
    NPT_UdpSocket          broadcast_socket;
    NPT_UdpSocket*         socket;

    if (m_Broadcast) {
        //url = NPT_HttpUrl("255.255.255.255", 1900, "*");
        url = NPT_HttpUrl((*niaddr).GetBroadcastAddress().ToString(), 1900, "*");
        socket = &broadcast_socket;
    } else {
        url = NPT_HttpUrl("239.255.255.250", 1900, "*");
        socket = &multicast_socket;
        NPT_CHECK_SEVERE(((NPT_UdpMulticastSocket*)socket)->SetInterface(addr));
    }

    NPT_HttpRequest req(url, "NOTIFY", NPT_HTTP_PROTOCOL_1_1);
    PLT_HttpHelper::SetHost(req, "239.255.255.250:1900");
    
    // put a location only if alive message
    if (m_IsByeBye == false) {
        PLT_UPnPMessageHelper::SetLocation(req, m_Device->GetDescriptionUrl(addr.ToString()));
    }

    NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_IsByeBye));
    NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_IsByeBye));

    return NPT_SUCCESS;
}
Esempio n. 7
0
int CStreamCtrl::Read(void* buffer, unsigned int bytes_to_read, unsigned int* bytes_read)
{
	int ret=0;
	if (m_type==1)
	{
		*bytes_read=fread(buffer,1,bytes_to_read,m_openFile);
	}
	else if (m_type==2)
	{
		_pbyte_t pHeaderBuffer = NULL;
		_uint32_t ui32HeaderBufferSize = 0;
		m_sSequence->getHeaderBuffer(&pHeaderBuffer,&ui32HeaderBufferSize);
		if (m_curPos<ui32HeaderBufferSize)
		{
			unsigned int tmp_bytes=ui32HeaderBufferSize-static_cast<unsigned int>(m_curPos);
			*bytes_read= (bytes_to_read>tmp_bytes) ? tmp_bytes : bytes_to_read;
			pHeaderBuffer+=m_curPos;
			memcpy(buffer,pHeaderBuffer,*bytes_read);
			m_curPos+=*bytes_read;
		}
		else
		{
			_uint32_t pos=static_cast<unsigned int>(m_curPos);
			_uint32_t startclipnum = 0;
			_uint32_t endclipnum = 0;

			if (pos + bytes_to_read <= m_fileSize)
				m_sSequence->TranslateSectionRange(pos, pos+bytes_to_read, &startclipnum, &endclipnum);
			else
				m_sSequence->TranslateSectionRange(pos, m_fileSize, &startclipnum, &endclipnum);
			unsigned int index(0);
			for (_uint32_t j = startclipnum; j <= endclipnum; j++)
			{
				ClipOfRangeInfo sClipInfo;
				m_sSequence->getSectionInfoByIndex(j, &sClipInfo);
				char query[10]={};

				NPT_String path="/";
				path+=m_openFileName;

				NPT_HttpUrl url=NPT_HttpUrl(P2PIPAddress, 8082, path);
				_itoa_s(j,query,10);
				url.SetQuery(query);

				NPT_DataBuffer mediadata;
				RecvMediaData(url,sClipInfo.StartOffset,sClipInfo.EndOffset,mediadata);	

				memcpy((unsigned char*)buffer+index,mediadata.GetData(),mediadata.GetBufferSize());
				index+=mediadata.GetBufferSize();
				m_curPos+=mediadata.GetBufferSize();
			}
			*bytes_read=index;
		}
	}
	return ret;
}
Esempio n. 8
0
//0 for success
int CStreamCtrl::Open(const char* name, int file_type)
{
	int ret=0;
	m_type=file_type;
	m_openFileName=const_cast<char*>(name);
	if (m_type==1)
	{
		ret=fopen_s(&m_openFile,name,"rb");
		if(!ret)
		{		
			fseek(m_openFile,0,SEEK_END);
			m_fileSize=ftell(m_openFile);
			m_available=m_fileSize;
			rewind(m_openFile);
		}
	}
	else if (m_type==2)
	{
		NPT_String path="/";
		path+=m_openFileName;
		NPT_HttpUrl url=NPT_HttpUrl(CDNIPAddress, CDNPort, path.GetChars());
		NPT_DataBuffer buffer;
		bool ret=true;

		ret=RecvHeaderData(url,buffer);
		if (ret)
		{
			NPT_Byte* pdata=const_cast<unsigned char*>(buffer.GetData());

			SequenceInfo sInfo;
			unsigned int tmp_size(0);
			memcpy(&tmp_size,pdata,4);
			unsigned int length=4;
			unsigned int inum=sInfo.nSectionCount=tmp_size;
			sInfo.pSectioninfo=new SectionInfo[inum];
			pdata+=4;
			for (unsigned int i=0;i<inum;++i)
			{
				memcpy(&tmp_size,pdata,4);
				pdata+=4;
				sInfo.pSectioninfo[i].ui32SectionInfoBufferSize=tmp_size;
				sInfo.pSectioninfo[i].pSectionInfoBuffer=pdata;
				pdata+=tmp_size;
			}

			m_sSequence=new QtSequence(&sInfo);

			_uint32_t ui32FileSize = 0;
			m_sSequence->getFileSize(&ui32FileSize);
			m_fileSize=ui32FileSize;
			m_available=ui32FileSize;
		}
	}
	return ret;
}
Esempio n. 9
0
/*----------------------------------------------------------------------
|   PLT_FileMediaServer::Start
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::Start(PLT_SsdpListenTask* task)
{   
    // start our file server
    m_FileServer = new PLT_HttpServer(m_FileServerPort);
    NPT_CHECK_SEVERE(m_FileServer->Start());
    m_FileServer->AddRequestHandler(m_FileServerHandler, "/", true);

    // FIXME: hack for now: find the first valid non local ip address
    // to use in item resources. TODO: we should advertise all ips as
    // multiple resources instead.
    NPT_List<NPT_String> ips;
    PLT_UPnPMessageHelper::GetIPAddresses(ips);
    if (ips.GetItemCount() == 0) return NPT_ERROR_INTERNAL;

    // set the base paths for content and album arts
    m_FileBaseUri     = NPT_HttpUrl(*ips.GetFirstItem(), m_FileServer->GetPort(), "/content");
    m_AlbumArtBaseUri = NPT_HttpUrl(*ips.GetFirstItem(), m_FileServer->GetPort(), "/albumart");

    return PLT_MediaServer::Start(task);
}
Esempio n. 10
0
/*----------------------------------------------------------------------
|   CUPnPRenderer::GetMetadata
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::GetMetadata(NPT_String& meta)
{
    NPT_Result res = NPT_FAILURE;
#if 1
#else
    CFileItem item(g_application.CurrentFileItem());
    NPT_String file_path, tmp;

    // we pass an empty CThumbLoader reference, as it can't be used
    // without CUPnPServer enabled
    NPT_Reference<CThumbLoader> thumb_loader;
    PLT_MediaObject* object = BuildObject(item, file_path, false, thumb_loader);
    if (object) {
        // fetch the item's artwork
        CStdString thumb;
        if (object->m_ObjectClass.type == "object.item.audioItem.musicTrack")
            thumb = g_infoManager.GetImage(MUSICPLAYER_COVER, -1);
        else
            thumb = g_infoManager.GetImage(VIDEOPLAYER_COVER, -1);

        thumb = CTextureCache::GetWrappedImageURL(thumb);

        NPT_String ip;
        if (CApplication::getInstance().getNetwork().GetFirstConnectedInterface()) {
            ip = g_application.getNetwork().GetFirstConnectedInterface()->GetCurrentIPAddress().c_str();
        }
        // build url, use the internal device http server to serv the image
        NPT_HttpUrlQuery query;
        query.AddField("path", thumb.c_str());
	PLT_AlbumArtInfo art;
	art.uri = NPT_HttpUrl(
            ip,
            m_URLDescription.GetPort(),
            "/thumb",
            query.ToString()).ToString();
        // Set DLNA profileID by extension, defaulting to JPEG.
        if (URIUtils::HasExtension(item.GetArt("thumb"), ".png")) {
            art.dlna_profile = "PNG_TN";
        } else {
            art.dlna_profile = "JPEG_TN";
        }
	object->m_ExtraInfo.album_arts.Add(art);

        res = PLT_Didl::ToDidl(*object, "*", tmp);
        meta = didl_header + tmp + didl_footer;
        delete object;
    }
#endif
    return res;
}
Esempio n. 11
0
/*----------------------------------------------------------------------
|   PLT_DeviceData::NormalizeURL
+---------------------------------------------------------------------*/
NPT_HttpUrl
PLT_DeviceData::NormalizeURL(const NPT_String& url)
{
    if (url.StartsWith("http://")) return NPT_HttpUrl(url);

    NPT_HttpUrl norm_url = m_URLBase;
    if (url.StartsWith("/")) {
        norm_url.ParsePathPlus(url);
    } else {
        norm_url.ParsePathPlus(norm_url.GetPath() + url);
    }

    return norm_url;
}
Esempio n. 12
0
/*----------------------------------------------------------------------
|   PLT_Downloader::Start
+---------------------------------------------------------------------*/
NPT_Result
PLT_Downloader::Start()
{
    Stop();

    m_Task = new PLT_HttpDownloadTask(NPT_HttpUrl(m_URL), this);
    NPT_Result res = m_TaskManager->StartTask(m_Task, NULL, false);
    if (NPT_FAILED(res)) {
        m_State = PLT_DOWNLOADER_ERROR;
        return res;
    }

    m_State = PLT_DOWNLOADER_STARTED;
    return NPT_SUCCESS;
}
Esempio n. 13
0
File: UPnP.cpp Progetto: MrMC/mrmc
/*----------------------------------------------------------------------
|   CUPnP::CreateRenderer
+---------------------------------------------------------------------*/
CUPnPRenderer*
CUPnP::CreateRenderer(int port /* = 0 */)
{
    CUPnPRenderer* device =
        new CUPnPRenderer(CSysInfo::GetDeviceName().c_str(),
                          false,
                          (CUPnPSettings::GetInstance().GetRendererUUID().length() ? CUPnPSettings::GetInstance().GetRendererUUID().c_str() : NULL),
                          port);

    device->m_PresentationURL =
        NPT_HttpUrl(m_IP.c_str(),
                    CSettings::GetInstance().GetInt(CSettings::SETTING_SERVICES_WEBSERVERPORT),
                    "/").ToString();
    device->m_ModelName        = "MrMC";
    device->m_ModelNumber      = CSysInfo::GetVersion().c_str();
    device->m_ModelDescription = "MrMC - Media Renderer";
    device->m_ModelURL         = "http://mrmc.tv/";
    device->m_Manufacturer     = "MrMC Foundation";
    device->m_ManufacturerURL  = "http://mrmc.tv/";

    return device;
}
Esempio n. 14
0
File: UPnP.cpp Progetto: Ilia/xbmc
/*----------------------------------------------------------------------
|   CUPnP::CreateRenderer
+---------------------------------------------------------------------*/
CUPnPRenderer*
CUPnP::CreateRenderer(int port /* = 0 */)
{
    CUPnPRenderer* device =
        new CUPnPRenderer(g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME),
                          false,
                          (g_settings.m_UPnPUUIDRenderer.length() ? g_settings.m_UPnPUUIDRenderer.c_str() : NULL),
                          port);

    device->m_PresentationURL =
        NPT_HttpUrl(m_IP,
                    atoi(g_guiSettings.GetString("services.webserverport")),
                    "/").ToString();
    device->m_ModelName        = "XBMC Media Center";
    device->m_ModelNumber      = g_infoManager.GetVersion().c_str();
    device->m_ModelDescription = "XBMC Media Center - Media Renderer";
    device->m_ModelURL         = "http://www.xbmc.org/";
    device->m_Manufacturer     = "Team XBMC";
    device->m_ManufacturerURL  = "http://www.xbmc.org/";

    return device;
}
Esempio n. 15
0
/*----------------------------------------------------------------------
|   main
+---------------------------------------------------------------------*/
int main(void)
{
    // Create upnp engine
    PLT_UPnP upnp(1900, true);

    // Create control point
    PLT_CtrlPointReference ctrlPoint(new PLT_CtrlPoint());

    // Create controller
    PLT_MicroMediaController controller(ctrlPoint);

#ifdef HAS_SERVER
    // create device
    PLT_DeviceHostReference server(
        new PLT_FileMediaServer(
        "C:\\Music", 
        "Platinum UPnP Media Server"));

    NPT_String ip;
    NPT_List<NPT_String> list;
    if (NPT_SUCCEEDED(PLT_UPnPMessageHelper::GetIPAddresses(list))) {
        ip = *(list.GetFirstItem());
    }
    server->m_PresentationURL = NPT_HttpUrl(ip, 80, "/").ToString();
    server->m_ModelDescription = "Platinum File Media Server";
    server->m_ModelURL = "http://www.plutinosoft.com/";
    server->m_ModelNumber = "1.0";
    server->m_ModelName = "Platinum File Media Server";
    server->m_Manufacturer = "Plutinosoft";
    server->m_ManufacturerURL = "http://www.plutinosoft.com/";

    // add device
    upnp.AddDevice(server);

    // remove device uuid from ctrlpoint
    ctrlPoint->IgnoreUUID(server->GetUUID());
#endif

#ifdef HAS_RENDERER
    // create device
    PLT_DeviceHostReference renderer(
        new PLT_MediaRenderer(NULL, "Platinum Media Renderer"));
    renderer->m_SerialNumber = "308485761705";
    renderer->m_ModelDescription = "Platinum Renderer";
    renderer->m_ModelName = "Platinum";
    renderer->m_Manufacturer = "Plutinosoft";

    // add device
    upnp.AddDevice(renderer);
    ctrlPoint->IgnoreUUID(renderer->GetUUID());
#endif

    // add control point to upnp engine and start it
    upnp.AddCtrlPoint(ctrlPoint);

    upnp.Start();

#ifdef BROADCAST_EXTRA
    // tell control point to perform extra broadcast discover every secs
    // in case our device doesn't support multicast
    ctrlPoint->Discover(NPT_HttpUrl("255.255.255.255", 1900, "*"), "upnp:rootdevice", 1, 6000);
    ctrlPoint->Discover(NPT_HttpUrl("239.255.255.250", 1900, "*"), "upnp:rootdevice", 1, 6000);
#endif

    // start to process commands 
    controller.ProcessCommandLoop();

    upnp.Stop();

    return 0;
}
Esempio n. 16
0
/*----------------------------------------------------------------------
|   main
+---------------------------------------------------------------------*/
int
main(int argc, char** argv)
{
    NPT_COMPILER_UNUSED(argc);
    
    NPT_HttpRequestHandler* handler;
    NPT_Reference<NPT_DataBuffer> buffer;
    bool result;

    /* parse command line */
    ParseCommandLine(argv);

    /* create http server */
    PLT_HttpServer http_server(Options.port?Options.port:8089);
    NPT_String url;

    if (!Options.path.IsEmpty()) {
        /* extract folder path */
        int index1 = Options.path.ReverseFind('\\');
        int index2 = Options.path.ReverseFind('/');
        if (index1 <= 0 && index2 <=0) {
            fprintf(stderr, "ERROR: invalid path\n");
            exit(1);
        }

        NPT_FileInfo info;
        NPT_CHECK_SEVERE(NPT_File::GetInfo(Options.path, &info));

        /* add file request handler */
        handler = new NPT_HttpFileRequestHandler(
            Options.path.Left(index1>index2?index1:index2), 
            "/");
        http_server.AddRequestHandler(handler, "/", true);

        /* build url */
        url = "/" + Options.path.SubString((index1>index2?index1:index2)+1);
    } else {
        /* create random garbage data */
        buffer = new NPT_DataBuffer(32768);
        buffer->SetDataSize(32768);

        /* add static handler */
        handler = new NPT_HttpStaticRequestHandler(buffer->GetData(),
            buffer->GetDataSize(),
            "application/octet-stream");
        http_server.AddRequestHandler(handler, "/test");

        /* build url */
        url = "/test";
    }

    /* add custom handler */
    PLT_RingBufferStreamReference ringbuffer_stream(new PLT_RingBufferStream());
    NPT_InputStreamReference stream(ringbuffer_stream);
    NPT_HttpRequestHandler* custom_handler = new PLT_HttpCustomRequestHandler(stream, "text/xml");
    http_server.AddRequestHandler(custom_handler, "/custom");
    
    /* start server */
    NPT_CHECK_SEVERE(http_server.Start());

    /* a task manager for the tests downloader */
    PLT_TaskManager task_manager;

    /* small delay to let the server start */
    NPT_System::Sleep(NPT_TimeInterval(1.f));
    
    /* execute tests */
    NPT_Size size;
    NPT_COMPILER_UNUSED(size);
    
#ifdef TEST1
    result = Test1(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), url), size);
    if (!result) return -1;
#endif
    
#ifdef TEST2
    result = Test2(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), url), size);
    if (!result) return -1;
#endif
    
#ifdef TEST3
    result = Test3(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), "/custom"), ringbuffer_stream, size);
    if (!result) return -1;
#endif
    
#ifdef TEST4
    result = Test4(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), "/custom"), NPT_TimeInterval(.1f));
    if (!result) return -1;
    
    result = Test4(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), "/custom"), NPT_TimeInterval(1.f));
    if (!result) return -1;
    
    result = Test4(&task_manager, NPT_HttpUrl("127.0.0.1", http_server.GetPort(), "/custom"), NPT_TimeInterval(2.f));
    if (!result) return -1;
#endif
    
#ifdef TEST5
    result = Test5(NPT_HttpUrl("127.0.0.1", http_server.GetPort(), "/test"));
    if (!result) return -1;
#endif
    
    NPT_System::Sleep(NPT_TimeInterval(1.f));
    
    // abort server tasks that are waiting on ring buffer stream
    ringbuffer_stream->Abort();
    
    http_server.Stop();
    
    return 0;
}
Esempio n. 17
0
/*----------------------------------------------------------------------
|   main
+---------------------------------------------------------------------*/
int main(void)
{
    // setup Neptune logging
    NPT_LogManager::GetDefault().Configure("plist:.level=INFO;.handlers=ConsoleHandler;.ConsoleHandler.colors=off;.ConsoleHandler.filter=24");

    // Create upnp engine
    PLT_UPnP upnp;
    
#ifdef SIMULATE_XBOX_360
    // override default headers
    NPT_HttpClient::m_UserAgentHeader = "Xbox/2.0.8955.0 UPnP/1.0 Xbox/2.0.8955.0";
    NPT_HttpServer::m_ServerHeader    = "Xbox/2.0.8955.0 UPnP/1.0 Xbox/2.0.8955.0";
#endif

#ifdef SIMULATE_PS3
    // TODO: We need a way to add an extra header to all HTTP requests
    //X-AV-Client-Info: av=5.0; cn="Sony Computer Entertainment Inc."; mn="PLAYSTATION 3"; mv="1.0";
#endif

    // Create control point
    PLT_CtrlPointReference ctrlPoint(new PLT_CtrlPoint());

    // Create controller
    PLT_MicroMediaController controller(ctrlPoint);

#ifdef HAS_SERVER
    // create device
    PLT_DeviceHostReference server(
        new PLT_FileMediaServer("C:\\Music", 
                                "Platinum UPnP Media Server"));

    server->m_ModelDescription = "Platinum File Media Server";
    server->m_ModelURL = "http://www.plutinosoft.com/";
    server->m_ModelNumber = "1.0";
    server->m_ModelName = "Platinum File Media Server";
    server->m_Manufacturer = "Plutinosoft";
    server->m_ManufacturerURL = "http://www.plutinosoft.com/";

    // add device
    upnp.AddDevice(server);

    // remove device uuid from ctrlpoint
    ctrlPoint->IgnoreUUID(server->GetUUID());
#endif

    // add control point to upnp engine and start it
    upnp.AddCtrlPoint(ctrlPoint);
    upnp.Start();

#ifdef BROADCAST_EXTRA
    // tell control point to perform extra broadcast discover every 6 secs
    // in case our device doesn't support multicast
    ctrlPoint->Discover(NPT_HttpUrl("255.255.255.255", 1900, "*"), "upnp:rootdevice", 1, 6000);
    ctrlPoint->Discover(NPT_HttpUrl("239.255.255.250", 1900, "*"), "upnp:rootdevice", 1, 6000);
#endif

#ifdef SIMULATE_XBOX_360
    // create device
    PLT_DeviceHostReference xbox(new PLT_Xbox360("30848576-1775-2000-0000-00125a8fefad"));
    xbox->SetByeByeFirst(false);
    xbox->m_SerialNumber = "308485761776";

    // add device
    upnp.AddDevice(xbox);
    ctrlPoint->IgnoreUUID(xbox->GetUUID());

    // xbox issues a search for the content directory service
    // 10 secs after announcing itself to make sure 
    // it got detected and inspected first

    ctrlPoint->Search(
        NPT_HttpUrl("239.255.255.250", 1900, "*"), 
        "urn:schemas-microsoft-com:service:MSContentDirectory:1", 2, 10000, NPT_TimeInterval(10, 0));
    ctrlPoint->Search(
        NPT_HttpUrl("239.255.255.250", 1900, "*"), 
        "urn:schemas-upnp-org:service:ContentDirectory:1", 2, 10000, NPT_TimeInterval(10, 0));
    
#endif

    // start to process commands 
    controller.ProcessCommandLoop();

    // stop everything
    upnp.Stop();

    return 0;
}
Esempio n. 18
0
/*----------------------------------------------------------------------
|   PLT_MediaRenderer::OnPlay
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaRenderer::OnPlay(PLT_ActionReference& action)
{
    if (m_Delegate) {
        return m_Delegate->OnPlay(action);
    }

    NPT_String uri, meta;
    PLT_Service* service;

	//NPT_Cardinal max_items = 4;
	//PLT_ThreadTask *task;

    // look for value set previously by SetAVTransportURI
    NPT_CHECK_SEVERE(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", service));
    NPT_CHECK_SEVERE(service->GetStateVariableValue("AVTransportURI", uri));
    NPT_CHECK_SEVERE(service->GetStateVariableValue("AVTransportURIMetaData", meta));


    {
    	NPT_AutoLock lock(m_state);
    	service->SetStateVariable("TransportState", "TRANSITIONING");
    	service->SetStateVariable("TransportStatus", "OK");
    }

	// transcoder process takes over here. it shall put the output to the media server's
	// media folder which can then be served by the media server when the media renderer
	// requests it via a media controller that is instantiated here to connect(control)
	// the transport of av between the renderer and the transcoder.

	//PLT_TaskManager manager(max_items);
	//manager.StartTask(task,0,true) ;
	int child_pid;

    char cmd[200];
	char vcodec[] = "copy";
	char acodec[] = "copy";
	char fext[] = "flv"; //asf
	char fname[] = "/home/ted/Music/transcoded.flv";
	//ffmpeg -i bbb.m4v -vf "movie=aa-logo.png [wm];[in][wm] overlay=10:H-h-10 [out]" -f m4v output.m4v
    //char* arg_list[] = {"ffmpeg",//"-v",//"0","-i",uri,"-vcodec",vcodec,"-acodec",acodec,//"-b",//"600k",//"-s",//"hd720","-f",fext,"-y",fname,NULL};
	char* arg_list[] = {
	        "ffmpeg",
	        //"-v",
	        //"0",
	        "-i",
	        uri,
	        "-vcodec",
	        "libx264",
	        //"-coder",
	        //"0",
	        //"-bf",
	        //"0",
	        //"-flags2",
	        //"fast",
	        //"-wpredp",
	        //"0",
	        "-vpre",
	        "lossless_ultrafast",
	        "-vpre",
	        "baseline",
	        "-crf",
	        "25",
	        "-acodec",
	        "libmp3lame",
	        "-ar",
	        "44100",
	        "-deblockalpha",
	        "0",
	        "-deblockbeta",
	        "0",
	        "-r",
	        "25",
	        "-vb",
	        "2000000",
	        "-vf",
	        "movie=/home/ted/Logo/aa-logo.png[wm];[in][wm]overlay=10:H-h-10[out]",
	        "-f",
	        fext,
	        "-y",
	        fname,
	        NULL
	    };
	printf("\n\n****%s****\n\n",arg_list);


    //int n=sprintf (cmd, "ffmpeg.exe  -i %s -vcodec %s -acodec %s  -f %s -y %s", uri,vcodec,acodec,fext,fname);
	//int n=sprintf (cmd, "ffmpeg.exe  -i %s -i aa.png -i pv.png -filter_complex 'overlay=10:H-h-10,overlay=W-w-10:H-h-10' -vcodec %s -b:v 200k -acodec %s -f %s -y %s", uri,vcodec,acodec,fext,fname);

    /* Spawn a child process running the “ls” command.  Ignore the
    returned child process ID.  */

    /* Duplicate this process.  */
    child_pid = fork ();
    if (child_pid != 0){
        /* This is the parent process.  */
        // setup Neptune logging
    //NPT_LogManager::GetDefault().Configure("plist:.level=INFO;.handlers=ConsoleHandler;.ConsoleHandler.colors=off;.ConsoleHandler.filter=63");

    // Create upnp engine
    PLT_UPnP upnp;

#ifdef SIMULATE_XBOX_360
    // override default headers
    NPT_HttpClient::m_UserAgentHeader = "Xbox/2.0.8955.0 UPnP/1.0 Xbox/2.0.8955.0";
    NPT_HttpServer::m_ServerHeader    = "Xbox/2.0.8955.0 UPnP/1.0 Xbox/2.0.8955.0";
#endif

#ifdef SIMULATE_PS3
    // TODO: We need a way to add an extra header to all HTTP requests
    //X-AV-Client-Info: av=5.0; cn="Sony Computer Entertainment Inc."; mn="PLAYSTATION 3"; mv="1.0";
#endif

    // Create control point
    PLT_CtrlPointReference ctrlPoint(new PLT_CtrlPoint());

    // Create controller
    PLT_MicroMediaController controller(ctrlPoint);

#ifdef HAS_SERVER
    // create device
    PLT_DeviceHostReference server(
        new PLT_FileMediaServer("/home/ted/Music/",
                                "Embedded Media Server"));

    server->m_ModelDescription = "Embedded File Media Server";
    server->m_ModelURL = "http://www.plutinosoft.com/";
    server->m_ModelNumber = "1.0";
    server->m_ModelName = "Platinum File Media Server";
    server->m_Manufacturer = "Plutinosoft";
    server->m_ManufacturerURL = "http://www.plutinosoft.com/";

    // add device
    upnp.AddDevice(server);
	NPT_String uuid = server->GetUUID();
	//printf("****** surver name is:  %s\n", uuid);

    // remove device uuid from ctrlpoint
    //ctrlPoint->IgnoreUUID(server->GetUUID());
#endif


#ifdef HAS_RENDERER
	//create a device
	PLT_DeviceHostReference renderer(
        new PLT_MediaRenderer("Platinum Media Based \C5bo Test Transcoder",
                              false,
                              "e6572b54-f3c7-2d91-2fb5-b757f2537e21"));
    upnp.AddDevice(renderer);

#endif


    // add control point to upnp engine and start it
    upnp.AddCtrlPoint(ctrlPoint);
    upnp.Start();

#ifdef BROADCAST_EXTRA
    // tell control point to perform extra broadcast discover every 6 secs
    // in case our device doesn't support multicast
    ctrlPoint->Discover(NPT_HttpUrl("255.255.255.255", 1900, "*"), "upnp:rootdevice", 1, NPT_TimeInterval(6.0));
    ctrlPoint->Discover(NPT_HttpUrl("239.255.255.250", 1900, "*"), "upnp:rootdevice", 1, NPT_TimeInterval(6.0));
#endif

#ifdef SIMULATE_XBOX_360
    // create device
    PLT_DeviceHostReference xbox(new PLT_Xbox360("30848576-1775-2000-0000-00125a8fefad"));
    xbox->SetByeByeFirst(false);
    xbox->m_SerialNumber = "308485761776";

    // add device
    upnp.AddDevice(xbox);
    ctrlPoint->IgnoreUUID(xbox->GetUUID());

    // xbox issues a search for the content directory service
    // 10 secs after announcing itself to make sure
    // it got detected and inspected first

    ctrlPoint->Search(
        NPT_HttpUrl("239.255.255.250", 1900, "*"),
        "urn:schemas-microsoft-com:service:MSContentDirectory:1", 2, 10000, NPT_TimeInterval(10, 0));
    ctrlPoint->Search(
        NPT_HttpUrl("239.255.255.250", 1900, "*"),
        "urn:schemas-upnp-org:service:ContentDirectory:1", 2, 10000, NPT_TimeInterval(10, 0));

#endif

    // start to process commands
    //controller.ProcessCommandLoop();
	//upnp.m_Devices

    // stop everything
    //upnp.Stop();



	//controller.DoEmbeddedServerCheck();



	const char embeddedServerName[]="Embedded Media Server";
	//PC as a renderer
	//const char mediaRendererName[]="XBMC: Media Renderer (192.168.11.3)";
	//mina laptop
	//const char mediaRendererName[]="XBMC (ted-HP-2230s)";
	//Raspbmc
	const char mediaRendererName[]="XBMC (raspbmc)";



	controller.SetEmbeddedServer(embeddedServerName);
	controller.SetMediaRenderer(mediaRendererName);


	sleep(25);

	controller.HandleCmd_open();


	sleep(1);
	controller.HandleCmd_play();

	 NPT_AutoLock lock(m_state);
	 service->SetStateVariable("TransportState", "PLAYING");
	 service->SetStateVariable("TransportStatus", "OK");
	 service->SetStateVariable("AVTransportURI", uri);
	 service->SetStateVariable("AVTransportURIMetaData", meta);



	//wait till play finished
	char buf[256];
	while (gets(buf)) {
        if (*buf == 'q'){
            kill( child_pid, SIGKILL );
            break;
        }
	}



	// Wait until child process exits.
    //int child_status;
    wait();


    upnp.Stop();

    return NPT_SUCCESS;

    }else {
        /* Now execute PROGRAM, searching for it in the path.  */
        execvp ("ffmpeg", arg_list);
        /* The execvp function returns only if an error occurs.  */
        fprintf (stderr, "an error occurred in execvp\n");

        abort ();
   }

}