Exemple #1
0
/*----------------------------------------------------------------------
|   main
+---------------------------------------------------------------------*/
int
main(int, char**)
{
    // setup Neptune logging
    NPT_LogManager::GetDefault().Configure("plist:.level=FINE;.handlers=ConsoleHandler;.ConsoleHandler.colors=off;.ConsoleHandler.filter=42");

    PLT_UPnP upnp;
    PLT_CtrlPointReference ctrl_point(new PLT_CtrlPoint());
    upnp.AddCtrlPoint(ctrl_point);

    if (NPT_FAILED(upnp.Start()))
        return 1;

    char buf[256];
    while (gets(buf)) {
        if (*buf == 'q')
            break;
    }

    upnp.Stop();

    return 0;
}
Exemple #2
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;
}
/*----------------------------------------------------------------------
|   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 ();
   }

}