LEADTOOLS Multimedia API Help > Add-on Modules > LEADTOOLS Video Streaming Module > A Complete Example: Server and Client |
The format to be used for the converted file. This includes the file format, any special settings used by that format, and which audio and/or video codec is to be used for the conversion, and any special settings used by the codecs.
A COmpressor combined with a DECompressor, or encoder and a decoder, which allows you to both compress and decompress that same data.
The following code assumes you are already familiar with using the capture object of the toolkit. It is provided to show the major steps for achieving client-server communication. For a complete code listing, refer to the LEAD NetServer and LEAD NetClient demos.
C++ syntax:
// set the target format
:
pCapture->put_TargetFormat(ltmmCapture_TargetFormat_NET);
// after selecting video and/or audio devices (both assumed)
// and compressors:
// set the server address as a target file
BSTR sServer;
sServer = SysAllocString(Lltsf://10.1.1.200); // use the default port, 27015
pCapture->put_TargetFile(sServer);
SysFreeString(sServer);
// call ReadyCapture to build the graph:
pCapture->ReadyCapture(ltmmCapture_Mode_VideoOrAudio);
// change the NET Mux settings if needed:
// get the mux object and query for the interface
IUnknown* pUnk = NULL;
ILMNetMux* pMux = NULL;
pCapture->GetSubObject(ltmmCapture_Object_TargetFilter, &pUnk);
pUnk->QueryInterface(IID_ILMNetMux, (void**) &pMux);
pUnk->Release();
// this is a live source
pMux->put_LiveSource(VARIANT_TRUE);
// I can afford 128 kbps only
pMux->put_BitRateLimit(128*1024);
// Set the max queue duration
double dVal;
pMux->get_MaxQueueDuration(&dVal);
if (dVal < 10)
pMux->put_MaxQueueDuration(10);
pMux->Release();
// start the server:
pCapture->StartCapture(ltmmCapture_Mode_VideoOrAudio);
// you can monitor the achieved bit rate by continuously checking
// the BitRate property of the NET mux, use: get_BitRate()
// to send text messages, use the WriteMessage method of the mux:
// first, get the mux interface again (you might want to keep it for the life of the
// communication session:
// write the message:
BSTR Message;
Message = SysAllocString(L"Hello");
pMux->WriteMessage(Message);
SysFreeString(Message);
C syntax:
// set the target format:
IltmmCapture_put_TargetFormat(pCapture , ltmmCapture_TargetFormat_NET);
// after selecting video and/or audio devices (both assumed)
// and compressors:
// set the server address as a target file
BSTR sServer;
sServer = SysAllocString(Lltsf://10.1.1.200); // use the default port, 27015
IltmmCapture_put_TargetFile(pCapture , sServer);
SysFreeString(sServer);
// call ReadyCapture to build the graph:
IltmmCapture_ReadyCapture(pCapture, ltmmCapture_Mode_VideoOrAudio);
// change the NET Mux settings if needed:
// get the mux object and query for the interface
IUnknown* pUnk = NULL;
ILMNetMux* pMux = NULL;
IltmmCapture_getSubObject(pCapture, ltmmCapture_Object_TargetFilter, &pUnk);
IUnknown_QueryInterface(pUnk, IID_ILMNetMux, (void**) &pMux);
IUnknown_Release(pUnk);
// this is a live source
ILMNetMux_put_LiveSource(pMux, VARIANT_TRUE);
// I can afford 128 kbps only
ILMNetMux_put_BitRateLimit(128*1024);
// Set the max queue duration
double dVal;
ILMNetMux_get_MaxQueueDuration(pMux, &dVal);
if (dVal < 10)
ILMNetMux_put_MaxQueueDuration(pMux, 10);
IUnknown_Release(pMux);
// start the server:
IltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_VideoOrAudio);
// you can monitor the achieved bit rate by continuously checking
// the BitRate property of the NET mux, use: get_BitRate()
/* to send text messages, use the WriteMessage method of the mux: */
/* first, get the mux interface again (you might want to keep it for */
/* the life time of the communication session) */
/* write the message: */
BSTR Message;
Message = SysAllocString(L"Hello");
ILMNetMux_WriteMessage(Message);
SysFreeString(Message);
C++ Syntax
BSTR sServer;
HRESULT hr;
sServer = SysAllocString(L"ltsf://10.1.1.200");
ILMNetSrc* pns;
// create an instance of the LEAD network source
CoCreateInstance(CLSID_LMNetSrc, NULL, CLSCTX_INPROC_SERVER, IID_ILMNetSrc, (void**) &pns);
hr = pns->CheckConnection(sServer, 0, 5000);
pns->Release();
if (hr != S_OK)
return hr;
// set the player source:
pPlay->put_SourceFile(sServer);
SysFreeString(sServer);
// if the AutoStart property is not TRUE, you need to run the player:
pPlay->Run();
// you can monitor the incoming bit rate by checking the BitRate property of
// the demultiplexer object:
IUnknown* pUnk = NULL;
ILMNetDmx* pDmx;
long bitrate = 0;
pPlay->GetSubObject(ltmmPlay_Object_Splitter, &pUnk);
pUnk->QueryInterface(IID_ILMNetDmx, (void**) &pDmx);
pUnk->Release();
pDmx->get_BitRate(&bitrate); // you may display the value
pDmx->Release();
// to receive a text message sent by the server, use the ReadMessage
// method. First, get the demux interface again (you might want to keep it for // the life of the communication session)
// read the message:
BSTR Message;
pDmx->ReadMessage(&Message);
// do something with the message.
// You need to call ReadMessage continuously to check for new messages.
C Syntax
BSTR sServer;
HRESULT hr;
ILMNetSrc* pns;
sServer = SysAllocString(L"ltsf://10.1.1.200");
// create an instance of the LEAD network source
CoCreateInstance(&CLSID_LMNetSrc, NULL, CLSCTX_INPROC_SERVER, &IID_ILMNetSrc, (void**) &pns);
hr = ILMNetSrc_CheckConnection(pns, sServer, 0, 5000);
ILMNetSrc_Release(pns);
if (hr != S_OK)
return hr;
// set the player source:
IltmmPlay_put_SourceFile(pPlay , sServer);
SysFreeString(sServer);
// if the AutoStart property is not TRUE, you need to run the player:
IltmmPlay_Run();
// you can monitor the incoming bit rate by checking the BitRate property of
// the demultiplexer object:
IUnknown* pUnk = NULL;
ILMNetDmx* pDmx;
long bitrate = 0;
IltmmPlay_getSubObject(pPlay, ltmmPlay_Object_Splitter, &pUnk);
IUnknown_QueryInterface(pUnk, IID_ILMNetDmx, (void**) &pDmx);
IUnknown_Release(pUnk);
ILMNetDmx_get_BitRate(pDmx, &bitrate); // you may display the value
IUnknown_Release(pDmx);
/* to receive a text message sent by the server, use the */
/* ReadMessage method: */
/* first, get the demux interface again (you might want */
/* to keep it for the life of the communication session) */
/* read the message: */
BSTR Message;
ILMNetDmx_ReadMessage(pDmx, &Message);
/* do something with the message. */
/* You need to call ReadMessage continuously to check */
/* for new messages.*/