LEADTOOLS Multimedia API Help > Programming with LEADTOOLS Multimedia > How To > Use IltmmRTPServer to implement a RTSP Server |
1. |
Create an instance of the IltmmRTSPServer interface. This is accomplished using the Win32 CoCreateInstance function, as follows: |
C Source
IltmmRTSPServer* pServer;
CoCreateInstance(&CLSID_ltmmRTSPServer, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmRTSPServer, (void**)&pServer);
C++ Source
IltmmRTSPServer* pServer;
CoCreateInstance(CLSID_ltmmRTSPServer, NULL, CLSCTX_INPROC_SERVER, IID_IltmmRTSPServer, (void**)&pServer);
2. |
Specify the source folder that will contain the media files that will be streamed: |
C Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"c:\\RTSPSourceFolder");
// assign the source file path to the convert object
IltmmRTSPServer_put_SourceFolder(pServer, 0, bstr);
// free the string
SysFreeString(bstr);
C++ Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"c:\\RTSPSourceFolder");
// assign the source file path to the convert object
pServer->put_SourceFolder(0, bstr);
// free the string
SysFreeString(bstr);
|
The above code tells the server to look in the c:\RTSPSourceFolder folder whenever a RTSP client asks for a file to be streamed. We are adding only one source folder, but you can add a second or third folder by changing the index from 0 to 1 and 2. |
3. |
Specify which server address to use. In here, we will use localhost (127.0.0.1). You change this to the IP address of your computer |
C Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"127.0.0.1");
// assign the source file path to the convert object
IltmmRTSPServer_put_TargetAddress(pServer, bstr);
// free the string
SysFreeString(bstr);
C++ Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"127.0.0.1");
// assign the source file path to the convert object
pServer->put_TargetAddress(bstr);
// free the string
SysFreeString(bstr);
|
You can also specify now specify the live latency, security settings and default settings for the encoders (which would be used for automatically recompressing the files whose compression doesn't match the compressions supported by the RTSP server). For best performance, it is recommended that you make sure the files stored in the source folders are already compressed using compression settings compatible with the RTSP Server. |
4. |
Start the server and listen on the default RTSP port (554). If that port is already used by another server, you can start it on another available port: |
C Source
IltmmRTSPServer_StartServer(pServer, ltmmRTSP_DefaultPort);
C++ Source
pServer->StartServer(ltmmRTSP_DefaultPort);
5. |
You can now connect with a RTSP client and stream file using this URL: rtsp://127.0.0.1/file.ext, where c:\RTSPSourceFolder\file.ext is a valid media file.
When you are done, stop the server and release the pServer interface |