Exemple #1
0
/*! \fn ILibCreateAsyncSocketModule(void *Chain, int initialBufferSize, ILibAsyncSocket_OnData OnData, ILibAsyncSocket_OnConnect OnConnect, ILibAsyncSocket_OnDisconnect OnDisconnect,ILibAsyncSocket_OnSendOK OnSendOK)
	\brief Creates a new AsyncSocketModule
	\param Chain The chain to add this module to. (Chain must <B>not</B> be running)
	\param initialBufferSize The initial size of the receive buffer
	\param OnData Function Pointer that triggers when Data is received
	\param OnConnect Function Pointer that triggers upon successfull connection establishment
	\param OnDisconnect Function Pointer that triggers upon disconnect
	\param OnSendOK Function Pointer that triggers when pending sends are complete
	\returns An ILibAsyncSocket token
*/
ILibAsyncSocket_SocketModule ILibCreateAsyncSocketModule(void *Chain, int initialBufferSize, ILibAsyncSocket_OnData OnData, ILibAsyncSocket_OnConnect OnConnect, ILibAsyncSocket_OnDisconnect OnDisconnect,ILibAsyncSocket_OnSendOK OnSendOK)
{
	struct ILibAsyncSocketModule *RetVal = (struct ILibAsyncSocketModule*)malloc(sizeof(struct ILibAsyncSocketModule));
	memset(RetVal,0,sizeof(struct ILibAsyncSocketModule));
	RetVal->PreSelect = &ILibAsyncSocket_PreSelect;
	RetVal->PostSelect = &ILibAsyncSocket_PostSelect;
	RetVal->Destroy = &ILibAsyncSocket_Destroy;
	
	RetVal->internalSocket = -1;
	RetVal->OnData = OnData;
	RetVal->OnConnect = OnConnect;
	RetVal->OnDisconnect = OnDisconnect;
	RetVal->OnSendOK = OnSendOK;
	RetVal->buffer = (char*)malloc(initialBufferSize);
	RetVal->InitialSize = initialBufferSize;
	RetVal->MallocSize = initialBufferSize;

	RetVal->LifeTime = ILibCreateLifeTime(Chain);
	RetVal->TimeoutTimer = ILibCreateLifeTime(Chain);

	sem_init(&(RetVal->SendLock),0,1);
	
	RetVal->Chain = Chain;
	ILibAddToChain(Chain,RetVal);

	return((void*)RetVal);
}
// PUBLIC - Creates a Remote I/O Client Device Stack. This stack does not include the UPnP stack
// one must be build into the project with the "Upnp" prefix using Intel Device Builder. All
// callbacks must be externs. Remote I/O can be a root or embedded device.
void* CreateRemoteIO(void* Chain, void* UpnpStack)
{
	if (RemoteIO_RefCounter == 0) sem_init(&RemoteIOLock,0,1);
	RemoteIO_RefCounter++;

	RIO = (struct RIODataObject*)RIO_MALLOC(sizeof(struct RIODataObject));
	memset(RIO,0,sizeof(struct RIODataObject));

	// Start the new Remote IO session
	RIO->Destroy = &RemoteIODestroyChain;
	RIO->Session = ILibCreateAsyncSocketModule(650000,&OnRemoteIODataSink,&OnRemoteIOConnectSink,&OnRemoteIODisconnectSink);

	#ifdef _WIN32_WCE
		CreateThread(NULL,0,RemoteIOSessionThreadEntry,NULL,0,NULL);
	#elif WIN32
		CreateThread(NULL,0,RemoteIOSessionThreadEntry,NULL,0,NULL);
	#elif _POSIX
		pthread_create(&RIOWorkerThread,NULL,RemoteIOSessionThreadEntry,NULL);
	#endif
	
	RIO->RIOmicroStack = UpnpStack;

	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UpnpSetState_RemoteIO_PeerConnection(RIO->RIOmicroStack,"");
	UpnpSetState_ChannelManager_RegisteredChannelList(RIO->RIOmicroStack,"");

	RIO->RIOLifeTime = ILibCreateLifeTime(Chain);
	//ILibAddToChain(Chain,RIO->RIOLifeTime);
	ILibAddToChain(Chain,RIO);

	return RIO;
}
void* ILibCreateMiniWebServer(void *chain,int MaxConnections,void (*OnReceivePtr) (void *ReaderObject, struct packetheader *header, char* buffer, int *BeginPointer, int BufferSize, int done, void* user),void* user)
{
	struct MiniWebServerObject *RetVal = (struct MiniWebServerObject*)MALLOC(sizeof(struct MiniWebServerObject));
	int i;
	WORD wVersionRequested;
	WSADATA wsaData;
	wVersionRequested = MAKEWORD( 1, 1 );
	if (WSAStartup( wVersionRequested, &wsaData ) != 0) {exit(1);}
	
	RetVal->MaxConnections = MaxConnections;
	RetVal->Readers = (struct ILibMWSHTTPReaderObject*)MALLOC(MaxConnections*sizeof(struct ILibMWSHTTPReaderObject));
	RetVal->Terminate = 0;
	RetVal->PreSelect = &ILibMiniWebServerModule_PreSelect;
	RetVal->PostSelect = &ILibMiniWebServerModule_PostSelect;
	RetVal->Destroy = &ILibMiniWebServerModule_Destroy;
	
	memset(RetVal->Readers,0,MaxConnections*sizeof(struct ILibMWSHTTPReaderObject));
	for(i=0;i<MaxConnections;++i)
	{
		RetVal->Readers[i].ClientSocket = ~0;
		RetVal->Readers[i].FunctionCallback = OnReceivePtr;
		RetVal->Readers[i].Parent = RetVal;
		RetVal->Readers[i].user = user;
	}
	
	RetVal->PortNumber = 0;
	
	RetVal->TimerObject = ILibCreateLifeTime(chain);
	ILibAddToChain(chain,RetVal);
	return((void*)RetVal);
}
Exemple #4
0
int main(void)
{
	UPnPmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UPnPmicroStack = UPnPCreateMicroStack(UPnPmicroStackChain,"Intel AV Renderer","fada97a9-5917-4c8f-a2a9-147b44e84953","0000001",1800,0);
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UPnPSetState_RenderingControl_LastChange(UPnPmicroStack,"Sample String");
	UPnPSetState_AVTransport_LastChange(UPnPmicroStack,"Sample String");
	UPnPSetState_ConnectionManager_SourceProtocolInfo(UPnPmicroStack,"Sample String");
	UPnPSetState_ConnectionManager_SinkProtocolInfo(UPnPmicroStack,"Sample String");
	UPnPSetState_ConnectionManager_CurrentConnectionIDs(UPnPmicroStack,"Sample String");
	
	printf("Intel MicroStack 1.0 - Intel AV Renderer\r\n\r\n");
	
	UPnPMonitor = ILibCreateLifeTime(UPnPmicroStackChain);
	UPnPIPAddressLength = ILibGetLocalIPAddressList(&UPnPIPAddressList);
	ILibLifeTime_Add(UPnPMonitor,NULL,4,&UPnPIPAddressMonitor,NULL);
	
	signal(SIGINT,BreakSink);
	ILibStartChain(UPnPmicroStackChain);
	
	return 0;
}
Exemple #5
0
int main(void)
{
	UPnPmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UPnPmicroStack = UPnPCreateMicroStack(UPnPmicroStackChain,"Sample Device","f8b67906-edb8-4701-a9b2-36c29262c82d","0000001",15,0);
	
	UPnPFP_ImportedService_getTcpServer=&UPnPImportedService_getTcpServer;
	UPnPFP_ImportedService_setForce=&UPnPImportedService_setForce;
	UPnPFP_ImportedService_setPage=&UPnPImportedService_setPage;
	UPnPFP_ImportedService_setSerial=&UPnPImportedService_setSerial;
	UPnPFP_ImportedService_setX=&UPnPImportedService_setX;
	UPnPFP_ImportedService_setY=&UPnPImportedService_setY;
	
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UPnPSetState_ImportedService_page(UPnPmicroStack,"Sample String");
	UPnPSetState_ImportedService_x(UPnPmicroStack,25000);
	UPnPSetState_ImportedService_y(UPnPmicroStack,25000);
	UPnPSetState_ImportedService_serial(UPnPmicroStack,"Sample String");
	UPnPSetState_ImportedService_force(UPnPmicroStack,25000);
	
	printf("Intel MicroStack 1.0 \r\n\r\n");
	
	UPnPMonitor = ILibCreateLifeTime(UPnPmicroStackChain);
	UPnPIPAddressLength = ILibGetLocalIPAddressList(&UPnPIPAddressList);
	ILibLifeTime_Add(UPnPMonitor,NULL,4,&UPnPIPAddressMonitor,NULL);
	
	signal(SIGINT,BreakSink);
	ILibStartChain(UPnPmicroStackChain);
	
	free(UPnPIPAddressList);
	return 0;
}
Exemple #6
0
int _tmain(int argc, _TCHAR* argv[])
{
	UpnpmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UpnpmicroStack = UpnpCreateMicroStack(UpnpmicroStackChain,"MicroDMA","6cace70b-ed87-4648-a6ac-46ee6f5e895c","0000001",1800,0);
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UpnpSetState_ConnectionManager_SourceProtocolInfo(UpnpmicroStack,"Sample String");
	UpnpSetState_ConnectionManager_SinkProtocolInfo(UpnpmicroStack,"Sample String");
	UpnpSetState_ConnectionManager_CurrentConnectionIDs(UpnpmicroStack,"Sample String");
	UpnpSetState_RenderingControl_LastChange(UpnpmicroStack,"Sample String");
	UpnpSetState_AVTransport_LastChange(UpnpmicroStack,"Sample String");
	UpnpSetState_RemoteIO_PeerConnection(UpnpmicroStack,"Sample String");
	UpnpSetState_ChannelManager_RegisteredChannelList(UpnpmicroStack,"Sample String");
	
	printf("Intel MicroStack 1.0 - MicroDMA\r\n\r\n");
	CreateThread(NULL,0,&Run,NULL,0,NULL);
	
	UpnpMonitor = ILibCreateLifeTime(UpnpmicroStackChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	
	ILibStartChain(UpnpmicroStackChain);
	
	FREE(UpnpIPAddressList);
	return 0;
}
int main(void)
{
	UpnpmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UpnpmicroStack = UpnpCreateMicroStack(UpnpmicroStackChain,"Intel's Micro Media Server","cefd004c-525b-42f9-95cd-6a9c70371e65","0000001",1800,0);
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UpnpSetState_ContentDirectory_SystemUpdateID(UpnpmicroStack,250);
	UpnpSetState_ConnectionManager_SourceProtocolInfo(UpnpmicroStack,"Sample String");
	UpnpSetState_ConnectionManager_SinkProtocolInfo(UpnpmicroStack,"Sample String");
	UpnpSetState_ConnectionManager_CurrentConnectionIDs(UpnpmicroStack,"Sample String");
	
	printf("Intel MicroStack 1.0 - Intel's Micro Media Server\r\n\r\n");
	
	UpnpMonitor = ILibCreateLifeTime(UpnpmicroStackChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	
	signal(SIGINT,BreakSink);
	ILibStartChain(UpnpmicroStackChain);
	
	FREE(UpnpIPAddressList);
	return 0;
}
void *ILibWebServer_Create(void *Chain, int MaxConnections, int PortNumber,ILibWebServer_Session_OnSession OnSession, void *User)
{
	struct ILibWebServer_StateModule *RetVal = (struct ILibWebServer_StateModule*)MALLOC(sizeof(struct ILibWebServer_StateModule));
	
	memset(RetVal,0,sizeof(struct ILibWebServer_StateModule));

	RetVal->Destroy = &ILibWebServer_Destroy;
	RetVal->Chain = Chain;
	RetVal->OnSession = OnSession;
	RetVal->ServerSocket = ILibCreateAsyncServerSocketModule(
		Chain,
		MaxConnections,
		PortNumber,
		INITIAL_BUFFER_SIZE,
		&ILibWebServer_OnConnect,			// OnConnect
		&ILibWebServer_OnDisconnect,		// OnDisconnect
		&ILibWebServer_OnReceive,			// OnReceive
		&ILibWebServer_OnInterrupt,			// OnInterrupt
		&ILibWebServer_OnSendOK				// OnSendOK
		);
	ILibAsyncServerSocket_SetTag(RetVal->ServerSocket,RetVal);
	RetVal->LifeTime = ILibCreateLifeTime(Chain);
	RetVal->User = User;
	ILibAddToChain(Chain,RetVal);

	return(RetVal);
}
Exemple #9
0
int main(void)
{
	UPnPmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UPnPmicroStack = UPnPCreateMicroStack(UPnPmicroStackChain,"Intel Media Server","35bb3970-f938-4391-b962-c52d566032ea","0000001",1800,0);
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UPnPSetState_ConnectionManager_SourceProtocolInfo(UPnPmicroStack,"Sample String");
	UPnPSetState_ConnectionManager_SinkProtocolInfo(UPnPmicroStack,"Sample String");
	UPnPSetState_ConnectionManager_CurrentConnectionIDs(UPnPmicroStack,"Sample String");
	UPnPSetState_ContentDirectory_TransferIDs(UPnPmicroStack,"Sample String");
	UPnPSetState_ContentDirectory_ContainerUpdateIDs(UPnPmicroStack,"Sample String");
	UPnPSetState_ContentDirectory_SystemUpdateID(UPnPmicroStack,250);
	
	printf("Intel MicroStack 1.0 - Intel Media Server\r\n\r\n");
	
	UPnPMonitor = ILibCreateLifeTime(UPnPmicroStackChain);
	UPnPIPAddressLength = ILibGetLocalIPAddressList(&UPnPIPAddressList);
	ILibLifeTime_Add(UPnPMonitor,NULL,4,&UPnPIPAddressMonitor,NULL);
	
	signal(SIGINT,BreakSink);
	ILibStartChain(UPnPmicroStackChain);
	
	return 0;
}
Exemple #10
0
int main(int argc, char* argv[])
{
	/*
	 *	Set all of the renderer callbacks.
	 *	If the UPnP device has multiple renderers, it will need
	 *	to map function pointer callbacks for each renderer device.
	 */
	MROnVolumeChangeRequest			= &MROnVolumeChangeRequestSink;
	MROnMuteChangeRequest			= &MROnMuteChangeRequestSink;
	MROnMediaChangeRequest			= &MROnMediaChangeRequestSink;
	MROnGetPositionRequest			= &MROnGetPositionRequestSink;
	MROnSeekRequest					= &MROnSeekRequestSink;
	MROnNextPreviousRequest			= &MROnNextPreviousRequestSink;
	MROnStateChangeRequest			= &MROnStateChangeRequestSink;
	MROnPlayModeChangeRequest		= &MROnPlayModeChangeRequestSink;

	/* TODO: Each device must have a unique device identifier (UDN) - The UDN should be generated dynamically*/
	UpnpMicroStackChain = ILibCreateChain();
	UpnpMicroStack = UpnpCreateMicroStack(UpnpMicroStackChain,"MMR Posix-(Basic)","UDN:MMR PosixBasic","000001",1800, 0);
	MR_MediaRendererState = CreateMediaRenderer(UpnpMicroStackChain, UpnpMicroStack, ILibCreateLifeTime(UpnpMicroStackChain));

	/* Start the renderer thread chain */
	printf("Intel MicroStack 1.0 - Micro Media Renderer\r\n\r\n");

	/*
	 *	Set up the solution to periodically monitor 
	 *	the platform's current list of IP addresses.
	 *	This will allow the upnp layers to appropriately
	 *	react to IP address changes.
	 */
	UpnpMonitor = ILibCreateLifeTime(UpnpMicroStackChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);

	/* start UPnP - blocking call*/
	signal(SIGINT,BreakSink);
	ILibStartChain(UpnpMicroStackChain);

	/* be sure to free the address list */
	FREE(UpnpIPAddressList);

	return 0;
}
Exemple #11
0
unsigned long WINAPI UPnPMain(void* ptr)
{
	int i;
	char guid[20];
	char friendlyname[100];
	WSADATA wsaData;

	MmsOnStatsChanged = &MmsOnStatsChangedSink;
	MmsOnTransfersChanged = &MmsMediaTransferStatsSink;

	srand((int)GetTickCount());
	for (i=0;i<19;i++)
	{
		guid[i] = (rand() % 25) + 66;
	}
	guid[19] = 0;

	if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {exit(1);}
	memcpy(friendlyname,"Intel Micro AV Server (",23);
	gethostname(friendlyname+23,68);
	memcpy(friendlyname+strlen(friendlyname),")/Win32\0",8);

	TheChain = ILibCreateChain();
	TheStack = UpnpCreateMicroStack(TheChain, friendlyname, guid, "0000001", 1800, 0);
	InitMms(TheChain, TheStack, ".\\");

	/*
	 *	Set up the app to periodically monitor the available list
	 *	of IP addresses.
	 */
	#ifdef _WINSOCK1
	UpnpMonitor = ILibCreateLifeTime(TheChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	#endif
	#ifdef _WINSOCK2
	UpnpMonitorSocket = socket(AF_INET,SOCK_DGRAM,0);
	WSAIoctl(UpnpMonitorSocket,SIO_ADDRESS_LIST_CHANGE,NULL,0,NULL,0,&UpnpMonitorSocketReserved,&UpnpMonitorSocketStateObject,&UpnpIPAddressMonitor);
	#endif

	ILibStartChain(TheChain);
	StopMms();
	WSACleanup();

	SendMessage(hWndMainWindow, WM_DESTROY, 0, 0);
	return 0;
}
Exemple #12
0
int _tmain(int argc, _TCHAR* argv[])
{
	UpnpmicroStackChain = ILibCreateChain();
	
	/* TODO: Each device must have a unique device identifier (UDN) */
	UpnpmicroStack = UpnpCreateMicroStack(UpnpmicroStackChain,"Remote IO Micro Client","76b5f067-b96f-482b-8c61-dfce4442e719","0000001",1800,0);
	
	/* All evented state variables MUST be initialized before UPnPStart is called. */
	UpnpSetState_RemoteIO_PeerConnection(UpnpmicroStack,"Sample String");
	UpnpSetState_ChannelManager_RegisteredChannelList(UpnpmicroStack,"Sample String");
	
	printf("Intel MicroStack 1.0 - Remote IO Micro Client\r\n\r\n");
	CreateThread(NULL,0,&Run,NULL,0,NULL);
	
	UpnpMonitor = ILibCreateLifeTime(UpnpmicroStackChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	
	ILibStartChain(UpnpmicroStackChain);
	
	FREE(UpnpIPAddressList);
	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	void *ltm;
	char udn[20];
	char friendlyname[100];
	WSADATA wsaData;
	int i;

	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );


	/* Randomized udn generation */
	srand(GetTickCount());
	for (i=0;i<19;i++)
	{
		udn[i] = (rand() % 25) + 66;
	}
	udn[19] = 0;

	/* generate a friendly name that has the host name in it */
	if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {exit(1);}
	memcpy(friendlyname,"Intel Micro AV Renderer (",25);
	gethostname(friendlyname+25,48);
	memcpy(friendlyname+strlen(friendlyname),")/Win32/Emulated Playback\0",26);

	/*
	 *	Set all of the renderer callbacks.
	 *	If the UPnP device has multiple renderers, it will need
	 *	to map function pointer callbacks for each renderer device.
	 */
	MROnVolumeChangeRequest			= &MROnVolumeChangeRequestSink;
	MROnMuteChangeRequest			= &MROnMuteChangeRequestSink;
	MROnMediaChangeRequest			= &MROnMediaChangeRequestSink;
	MROnGetPositionRequest			= &MROnGetPositionRequestSink;
	MROnSeekRequest					= &MROnSeekRequestSink;
	MROnNextPreviousRequest			= &MROnNextPreviousRequestSink;
	MROnStateChangeRequest			= &MROnStateChangeRequestSink;
	MROnPlayModeChangeRequest		= &MROnPlayModeChangeRequestSink;

	/* TODO: Each device must have a unique device identifier (UDN) - The UDN should be generated dynamically*/
	MR_RendererChain = ILibCreateChain();

	MR_UpnpStack = UpnpCreateMicroStack(MR_RendererChain, friendlyname, udn,"000001", 1800, 0);
	MR_ExtendedM3uProcessor = CreatePlaylistParser(MR_RendererChain, 3);

	ltm = ILibCreateLifeTime(MR_RendererChain);
	//ILibAddToChain(MR_RendererChain, ltm);

	MR_MediaRenderer = CreateMediaRenderer(MR_RendererChain, MR_UpnpStack, ltm);
	MR_RendererLogic = RSL_CreateRendererStateLogic
		(
		MR_RendererChain,
		MR_MediaRenderer,
		InstructPlaylistLogic_FindTargetUri,
		InstructCodec_SetupStream,
		InstructCodec_Play,
		InstructCodec_Stop,
		InstructCodec_Pause,
		QueryCodec_IsBusy,
		Validate_MediaUri
		);

	/*
	 *	Initialize codec framework - do this after state machine is initialized.
	 *	Intentionally sleep the processor to allow the codec wrapper thread
	 *	to prime.
	 */
	CodecWrapper_Init(MAX_STREAMS);
	SleepMsTime(100);

	/* Setup a thread to allow user to stop renderer when user hits key */
	CreateThread(NULL,0,&Run,NULL,0,NULL);

	/*
	 *	Initialize the streaming engine to empty or last known stream - 
	 *	do this after streaming framework is set up.
	 */
	RSL_SetMediaUri(MR_RendererLogic, "");

	/*
	 *	Set up the app to periodically monitor the available list
	 *	of IP addresses.
	 */
	#ifdef _WINSOCK1
	UpnpMonitor = ILibCreateLifeTime(MR_RendererChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	#endif
	#ifdef _WINSOCK2
	UpnpMonitorSocket = socket(AF_INET,SOCK_DGRAM,0);
	WSAIoctl(UpnpMonitorSocket,SIO_ADDRESS_LIST_CHANGE,NULL,0,NULL,0,&UpnpMonitorSocketReserved,&UpnpMonitorSocketStateObject,&UpnpIPAddressMonitor);
	#endif

	/* Start the renderer thread chain */
	printf("Intel MicroStack 1.0 - Micro Media Renderer\r\n\r\n");
	ILibStartChain(MR_RendererChain);
	
	/* be sure to free the address list */
	FREE(UpnpIPAddressList);

	/* clean up wsastartup */
	WSACleanup();

	return 0;
}
Exemple #14
0
	//
	// LifeTimeMonitor
	//
	__declspec(dllexport) void* ILibWrapper_CreateLifeTime(void *chain)
	{
		return(ILibCreateLifeTime(chain));
	}
int main(void)
{
	void *tempLTM;
	char udn[20];
	char friendlyname[100];
	int i;

	/* Randomized udn generation */
	srand((unsigned int)time(NULL));
	for (i=0;i<19;i++)
	{
		udn[i] = (rand() % 25) + 66;
	}
	udn[19] = 0;

	memcpy(friendlyname,"Intel Micro AV Renderer (",25);
	gethostname(friendlyname+25,48);
	memcpy(friendlyname+strlen(friendlyname),")/Posix/Emulated Playback\0",26);

	printf("Intel MicroStack 1.0 - Sample Renderer\r\n\r\n");
	
	/*
	 *	Set all of the renderer callbacks.
	 *	If the UPnP device has multiple renderers, it will need
	 *	to map function pointer callbacks for each renderer device.
	 */
	MROnVolumeChangeRequest			= &MROnVolumeChangeRequestSink;
	MROnMuteChangeRequest			= &MROnMuteChangeRequestSink;
	MROnMediaChangeRequest			= &MROnMediaChangeRequestSink;
	MROnGetPositionRequest			= &MROnGetPositionRequestSink;
	MROnSeekRequest					= &MROnSeekRequestSink;
	MROnNextPreviousRequest			= &MROnNextPreviousRequestSink;
	MROnStateChangeRequest			= &MROnStateChangeRequestSink;
	MROnPlayModeChangeRequest		= &MROnPlayModeChangeRequestSink;

	/* TODO: Each device must have a unique device identifier (UDN) - The UDN should be generated dynamically*/
	MR_RendererChain = ILibCreateChain();
	MR_ExtendedM3uProcessor = CreatePlaylistParser(MR_RendererChain, 3);

	/* for some silly reason, I need to create the lifetime, create stack, and add lifetime */
	tempLTM = ILibCreateLifeTime(MR_RendererChain);
	MR_UpnpStack = UpnpCreateMicroStack(MR_RendererChain, friendlyname, udn,"000001", 1800, 0);
	MR_MediaRenderer = CreateMediaRenderer(MR_RendererChain, MR_UpnpStack, tempLTM);
	//ILibAddToChain(MR_RendererChain, tempLTM);

	MR_RendererLogic = RSL_CreateRendererStateLogic
		(
		MR_RendererChain,
		MR_MediaRenderer,
		InstructPlaylistLogic_FindTargetUri,
		InstructCodec_SetupStream,
		InstructCodec_Play,
		InstructCodec_Stop,
		InstructCodec_Pause,
		QueryCodec_IsBusy,
		Validate_MediaUri
		);

	/*
	 *	Initialize codec framework - do this after state machine is initialized.
	 *	Intentionally sleep the processor to allow the codec wrapper thread
	 *	to prime.
	 */
	CodecWrapper_Init(MAX_STREAMS);
	SleepMsTime(100);

	/*
	 *	Initialize the streaming engine to empty or last known stream - 
	 *	do this after streaming framework is set up.
	 */
	RSL_SetMediaUri(MR_RendererLogic, "");

	/*
	 *	Set up the solution to periodically monitor 
	 *	the platform's current list of IP addresses.
	 *	This will allow the upnp layers to appropriately
	 *	react to IP address changes.
	 */
	UpnpMonitor = ILibCreateLifeTime(MR_RendererChain);
	UpnpIPAddressLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);

	/* start UPnP - blocking call*/
	signal(SIGINT,BreakSink);
	ILibStartChain(MR_RendererChain);

	CodecWrapper_UnInit();
	
	/* be sure to free the address list */
	FREE(UpnpIPAddressList);

	return 0;
}
Exemple #16
0
APW APW_Method_Create(void * chain, ILibThreadPool thread_pool, unsigned short port, char* friendly_name, char * mac_addr, char * pwd)
{
    APW apw = NULL;
    APWInternalState inner_state = NULL;

    apw = (APW)MALLOC(sizeof(struct _APW));
    if (apw == NULL) {
        return NULL;
    }
    inner_state = (APWInternalState)MALLOC(sizeof(struct _APWInternalState));
    if (inner_state == NULL) {
        FREE(apw);
        return NULL;
    }
    inner_state->chain = chain;
    inner_state->airplay_token = AirplayCreate(chain, port, friendly_name, mac_addr, pwd);
    if (inner_state->airplay_token == NULL) { // 发现服务创建失败
        FREE(apw);
        FREE(inner_state);
        return NULL;
    }
    AirplaySetTag(inner_state->airplay_token, (void *)apw);
    inner_state->apw_monitor = ILibCreateLifeTime(inner_state->chain);
    ILibLifeTime_AddEx(inner_state->apw_monitor, apw, 0, &apw_last_change_timer_event, NULL);
    sem_init(&inner_state->resource_lock, 0, 1);

    apw->ILib1 = NULL;
    apw->ILib2 = NULL;
    apw->ILib3 = apw_destroy_from_chain;
    apw->internal_state = (void *)inner_state;
    apw->thread_pool = thread_pool;

    AirplayCallbackGetCurrentTransportActions   = (AirplayHandlerGetCurrentTransportActions )&APW_GetCurrentTransportActions;
    AirplayCallbackGetDeviceCapabilities        = (AirplayHandlerGetDeviceCapabilities      )&APW_GetDeviceCapabilities;
    AirplayCallbackGetMediaInfo                 = (AirplayHandlerGetMediaInfo               )&APW_GetMediaInfo;
    AirplayCallbackGetPositionInfo              = (AirplayHandlerGetPositionInfo            )&APW_GetPositionInfo;
    AirplayCallbackGetTransportInfo             = (AirplayHandlerGetTransportInfo           )&APW_GetTransportInfo;
    AirplayCallbackGetTransportSettings         = (AirplayHandlerGetTransportSettings       )&APW_GetTransportSettings;
    AirplayCallbackNext                         = (AirplayHandlerNext                       )&APW_Next;
    AirplayCallbackPause                        = (AirplayHandlerPause                      )&APW_Pause;
    AirplayCallbackPlay                         = (AirplayHandlerPlay                       )&APW_Play;
    AirplayCallbackPrevious                     = (AirplayHandlerPrevious                   )&APW_Previous;
    AirplayCallbackSeek                         = (AirplayHandlerSeek                       )&APW_Seek;
    AirplayCallbackSetAVTransportURI            = (AirplayHandlerSetAVTransportURI          )&APW_SetAVTransportURI;
    AirplayCallbackSetPlayMode                  = (AirplayHandlerSetPlayMode                )&APW_SetPlayMode;
    AirplayCallbackStop                         = (AirplayHandlerStop                       )&APW_Stop;
    AirplayCallbackGetCurrentConnectionIDs      = (AirplayHandlerGetCurrentConnectionIDs    )&APW_GetCurrentConnectionIDs;
    AirplayCallbackGetCurrentConnectionInfo     = (AirplayHandlerGetCurrentConnectionInfo   )&APW_GetCurrentConnectionInfo;
    AirplayCallbackGetProtocolInfo              = (AirplayHandlerGetProtocolInfo            )&APW_GetProtocolInfo;
    AirplayCallbackListPresets                  = (AirplayHandlerListPresets                )&APW_ListPresets;
    AirplayCallbackSelectPreset                 = (AirplayHandlerSelectPreset               )&APW_SelectPreset;
    AirplayCallbackGetBrightness                = (AirplayHandlerGetBrightness              )&APW_GetBrightness;
    AirplayCallbackGetContrast                  = (AirplayHandlerGetContrast                )&APW_GetContrast;
    AirplayCallbackSetBrightness                = (AirplayHandlerSetBrightness              )&APW_SetBrightness;
    AirplayCallbackSetContrast                  = (AirplayHandlerSetContrast                )&APW_SetContrast;
    AirplayCallbackGetMute                      = (AirplayHandlerGetMute                    )&APW_GetMute;
    AirplayCallbackGetVolume                    = (AirplayHandlerGetVolume                  )&APW_GetVolume;
    AirplayCallbackSetMute                      = (AirplayHandlerSetMute                    )&APW_SetMute;
    AirplayCallbackSetVolume                    = (AirplayHandlerSetVolume                  )&APW_SetVolume;
    AirplayCallbackGetPlayStatus                = (AirplayGetPlayStatus                     )&APW_GetStatus;

    ILibAddToChain(chain, apw);

    return apw;
}
int main(void)
{
	char udn[20];
	int i;
	char friendlyname[100];

	#ifdef WIN32
	WSADATA wsaData;
	#endif

	_CrtSetDbgFlag (
		_CRTDBG_ALLOC_MEM_DF       | 
		_CRTDBG_DELAY_FREE_MEM_DF  |
		_CRTDBG_LEAK_CHECK_DF      
		//_CRTDBG_CHECK_ALWAYS_DF
		);

	/* Randomized udn generation */
	#ifdef WIN32
	srand(GetTickCount());
	#endif

	#ifdef _POSIX
	srand((unsigned int)time(NULL));
	#endif

	for (i=0;i<19;i++)
	{
		udn[i] = (rand() % 25) + 66;
	}
	udn[19] = 0;

	/* generate a friendly name that has the host name in it */
	#ifdef WIN32
	if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {exit(1);}
	#endif
	memcpy(friendlyname,"Intel MicroSTB (",16);
	gethostname(friendlyname+16,75);
	#ifdef WIN32
	memcpy(friendlyname+strlen(friendlyname),")/Win32\0",8);
	#endif
	#ifdef _POSIX
	memcpy(friendlyname+strlen(friendlyname),")/Posix\0",8);
	#endif

	/* Setup the callbacks */
	RemoteIOConnectionChanged = &XrtVideo_ConnectionChangedSink;
	RemoteIOReset = &XrtVideo_ResetSink;
	RemoteIOCommand = &XrtVideo_CommandSink;
	
	/* Setup the Remote IO Global Values */
	RemoteIO_Application		= "XRT20:Sample Client";
	RemoteIO_MaxCommandSize		= 65000;			// Set the maximum command size, keep this at 64k
	RemoteIO_DisplayEncoding	= RemoteIO_JPEG;	// Set the image format, see (enum RemoteIOImageFormat) for complete list.
	RemoteIO_DisplayWidth		= 640;				// Set the display width
	RemoteIO_DisplayHeight		= 480;				// Set the display height
	RemoteIO_DeviceInformation	= "";				// Set propriatary information about the device

	/*
	 *	Set of commands that can be sent back to the host PC. These can be used even
	 *	if remoting is not connected. For a device with an IR remote, only SendKeyPress is used.	
	 */
	/*
	RemoteIO_SendCommand(unsigned short command, char* data, int datalength);
	RemoteIO_SendKeyPress(int key);
	RemoteIO_SendKeyUp(int key);
	RemoteIO_SendKeyDown(int key);
	RemoteIO_SendMouseUp(int X,int Y,int Button);
	RemoteIO_SendMouseDown(int X,int Y,int Button);
	RemoteIO_SendMouseMove(int X,int Y);
	*/

	/* renderer callbacks. */
	MROnVolumeChangeRequest			= &MROnVolumeChangeRequestSink;
	MROnMuteChangeRequest			= &MROnMuteChangeRequestSink;
	MROnMediaChangeRequest			= &MROnMediaChangeRequestSink;
	MROnGetPositionRequest			= &MROnGetPositionRequestSink;
	MROnSeekRequest					= &MROnSeekRequestSink;
	MROnNextPreviousRequest			= &MROnNextPreviousRequestSink;
	MROnStateChangeRequest			= &MROnStateChangeRequestSink;
	MROnPlayModeChangeRequest		= &MROnPlayModeChangeRequestSink;



	printf("Intel MicroSTB Sample Client\r\n");

	StbChain = ILibCreateChain();
	StbLTM = ILibCreateLifeTime(StbChain);

	#ifdef _DEBUG
	printf("StbLTM=%p\r\n", StbLTM);
	#endif

	// Create the stack for the Media Server, Media Renderer, and RIOClient
	StbStack = UpnpCreateMicroStack(StbChain,friendlyname, udn, "0000001", 1600, 0);


	InitMms(StbChain, StbStack, ".\\");

	//ILibAddToChain(StbChain, StbLTM); /* seems to resolve dealyed event delivery */

    MR_ExtendedM3uProcessor = CreatePlaylistParser(StbChain, 3);
	MR_MediaRenderer = CreateMediaRenderer(StbChain, StbStack, StbLTM);
	MR_RendererLogic = RSL_CreateRendererStateLogic
		(
		StbChain,
		MR_MediaRenderer,
		InstructPlaylistLogic_FindTargetUri,
		InstructCodec_SetupStream,
		InstructCodec_Play,
		InstructCodec_Stop,
		InstructCodec_Pause,
		QueryCodec_IsBusy,
		Validate_MediaUri
		);


	/* Create the RemoteIO client */
	CreateRemoteIO(StbChain, StbStack);

	/* initialize emulated rendering module */
	CodecWrapper_Init(MAX_STREAMS);

	STBS_Init(StbChain);

	/*
	 *	Set up the app to periodically monitor the available list
	 *	of IP addresses.
	 */
	sem_init(&UpnpIPAddressListLock, 0, 1);

	#ifdef _POSIX
	UpnpMonitor = ILibCreateLifeTime(StbChain);
	UpnpIPAddressListLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	#endif
	#ifdef _WINSOCK1
	UpnpMonitor = ILibCreateLifeTime(StbChain);
	UpnpIPAddressListLength = ILibGetLocalIPAddressList(&UpnpIPAddressList);
	ILibLifeTime_Add(UpnpMonitor,NULL,4,&UpnpIPAddressMonitor,NULL);
	#endif
	#ifdef _WINSOCK2
	UpnpMonitorSocket = socket(AF_INET,SOCK_DGRAM,0);
	WSAIoctl(UpnpMonitorSocket,SIO_ADDRESS_LIST_CHANGE,NULL,0,NULL,0,&UpnpMonitorSocketReserved,&UpnpMonitorSocketStateObject,&UpnpIPAddressMonitor);
	#endif

	// for the media server
	UpdateIPAddresses(UpnpIPAddressList, UpnpIPAddressListLength);

	/* start UPnP - blocking call*/
	#ifdef _POSIX
	signal(SIGINT,BreakSink);
	#endif

	#ifdef WIN32
	/* Setup a thread to allow user to stop renderer when user hits key */
	CreateThread(NULL,0,&Run,NULL,0,NULL);
	#endif

	ILibStartChain(StbChain); 	

	StopMms();
	
	STBS_Uninit();

	/* be sure to FREE the address list */
	sem_destroy(&UpnpIPAddressListLock);
	FREE(UpnpIPAddressList);
	UpnpIPAddressList = NULL;
	
	/* clean up wsastartup */
	#ifdef WIN32
	WSACleanup();
	#endif

	return 0;
}