Create RTSP Stream Example for C++

HRESULT CreateRTSPStream(IltmsServer* server, LPCTSTR path, LPCTSTR url) 
{ 
	HRESULT hr; 
	long streamcount; 
	long streamindex; 
	CComPtr<IltmsLiveStreams> streams; 
	CComPtr<IltmsLiveStream> stream; 
 
	hr = server->GetLiveStreams(&streams); 
	if (FAILED(hr)) 
		goto error; 
 
	// search for existing stream with same path 
	hr = streams->get_Count(&streamcount); 
	if (FAILED(hr)) 
		goto error; 
 
	for (streamindex = 0; streamindex < streamcount; streamindex++) 
	{ 
		CComBSTR v; 
 
		hr = streams->GetLiveStream(streamindex, &stream); 
		if (FAILED(hr)) 
			goto error; 
 
		hr = stream->get_Path(&v); 
		if (FAILED(hr)) 
			goto error; 
		if (CStringW(path).CompareNoCase(v) == 0) 
			break; 
		stream = NULL; 
	} 
	if (!stream) 
	{ 
		// create a new stream 
		streamindex = -1; 
		hr = streams->CreateLiveStream(&stream); 
		if (FAILED(hr)) 
			goto error; 
 
	} 
	// set the stream path 
	hr = stream->put_Path(CComBSTR(path)); 
	if (FAILED(hr)) 
		goto error; 
 
	// create the RTSP device 
	{ 
		CComPtr<IltmsDevices> devices; 
		long index = -1; 
		stream->get_VideoDevices(&devices); 
		hr = devices->Find(CComBSTR(_T("@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE48-38C5-11D5-91F6-00104BDB8FF9}")), &index); 
		if (FAILED(hr)) 
			goto error; 
		hr = devices->put_Selection(index); 
		if (FAILED(hr)) 
			goto error; 
	} 
	// set the device RTSP URL 
	hr = stream->put_VideoDeviceURL(CComBSTR(url)); 
	if (FAILED(hr)) 
		goto error; 
 
	// add or replace stream 
	if (streamindex < 0) 
		hr = streams->AddLiveStream(stream); 
	else 
		hr = streams->SetLiveStream(streamindex, stream); 
	if (FAILED(hr)) 
		goto error; 
 
	hr = server->SetLiveStreams(streams); 
	if (FAILED(hr)) 
		goto error; 
 
 
error: 
	return hr; 
} 
Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Media Streaming C API Help