public bool HasDialog(
LiveStreamDlg dialog
)
dialog
A LiveStreamDlg dialog.
True indicates that the dialog is available. Otherwise, the value is false.
You must lock the capture devices with LockDevices before calling this function.
using Leadtools;
using Leadtools.MediaStreaming;
public Server _server = null;
public bool _result = false;
LiveStreamDevConfig devconfig;
public class DesktopWin : System.Windows.Forms.IWin32Window
{
public DesktopWin()
{
}
public IntPtr Handle
{
get { return IntPtr.Zero; }
}
}
public void CreateOrReplaceLiveStreamExample()
{
try
{
int StreamIndex = 0;
string strPath = "Live/Stream1"; // live stream's path to find
// video device's name on my system (LEAD RTSP Source)
string strVideoDevice = "@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE48-38C5-11D5-91F6-00104BDB8FF9}";
// audio device's name on my system (Microphone (HD Pro Webcam C920))
string strAudioDevice = "@device:cm:{33D9A762-90C8-11D0-BD43-00A0C911CE86}\\wave:{9D2FBF73-D543-44DA-8846-AE780EE65484}";
// create an instance of the server object
_server = new Leadtools.MediaStreaming.Server();
// retrieve a copy of the Live Streams
LiveStreams Streams = _server.GetLiveStreams();
LiveStream stream = null;
// search for existing stream with same path
for (StreamIndex = 0; StreamIndex < Streams.Count; StreamIndex++)
{
stream = Streams.GetLiveStream(StreamIndex);
if (stream.Path == strPath)
break;
stream.Dispose();
stream = null;
}
if (stream == null)
{
// create a new stream
StreamIndex = -1;
stream = Streams.CreateLiveStream();
}
// set the stream path
stream.Path = strPath;
// setup to recompress, change this to true if you want to use the device built-in compression
stream.UseDeviceEncoding = false;
// select video device
Leadtools.MediaStreaming.Devices videodevices;
videodevices = stream.VideoDevices;
int index = -1;
index = videodevices.IndexOf(strVideoDevice);
videodevices.Selection = index;
// select audio device
Leadtools.MediaStreaming.Devices audiodevices;
audiodevices = stream.AudioDevices;
index = -1;
index = audiodevices.IndexOf(strAudioDevice);
audiodevices.Selection = index;
/** alternative method of selection
if(index >= 0)
{
Leadtools.MediaStreaming.Device device;
device = audiodevices.[index];
device.Selected = true;
}
else
{
audiodevices.Selection = -1;
}
**/
// lock the devices so we can edit their properties
devconfig = stream.DeviceConfig;
devconfig.LockDevices();
DesktopWin win = new DesktopWin();
// show the main video device property page, if available
if (devconfig.HasDialog(LiveStreamDlg.VideoDevice))
{
devconfig.ShowDialog(LiveStreamDlg.VideoDevice, win);
}
// show the main audio device property page, if available
if (devconfig.HasDialog(LiveStreamDlg.AudioDevice))
{
devconfig.ShowDialog(LiveStreamDlg.AudioDevice, win);
}
// setup output video
if (devconfig.IsVideoEncoded) // the video is already encoded, the video output settings are ignored
{
stream.UseVideoInputSize = true;
// if UseVideoInputSize is true, then the width and height are ignored
stream.VideoWidth = 320;
stream.VideoHeight = 240;
stream.UseVideoInputFrameRate = true;
// if UseVideoInputFrameRate is true, then the frame rate is ignored
stream.VideoFrameRate = 29.97;
stream.VideoBitRate = 700000;
stream.QSVAcceleration = true;
stream.CUDAAcceleration = true;
}
// setup output audio
if (devconfig.IsAudioEncoded) // the audio is already encoded, the audio output settings are ignored
{
int nCount = 0;
Leadtools.MediaStreaming.AudioTypes audiotypes = null;
audiotypes = stream.AudioTypes;
nCount = audiotypes.Count;
for (index = 0; index < nCount; index++)
{
Leadtools.MediaStreaming.AudioType audiotype = audiotypes[index];
if (audiotype.Channels == 2 && audiotype.BitRate == 192000 && audiotype.SampleRate == 44100)
{
audiotype.Selected = true;
// alternative method of selection
// audiotypes.Selection = index;
break;
}
}
}
// setup output fragment size
stream.MinimumFragmentDuration = 2.0;
// add or replace stream
if (StreamIndex < 0)
Streams.AddLiveStream(stream);
else
Streams.SetLiveStream(StreamIndex, stream);
_server.SetLiveStreams(Streams);
if (devconfig != null)
devconfig.UnlockDevices();
_result = true;
}
catch (Exception)
{
if (devconfig != null)
devconfig.UnlockDevices();
_result = false;
}
}