Example #1
0
        public async Task <AsyncCallbackMsg> StartPushLiveStream(List <LiveVideoStream> liveVideoStreamInfos,
                                                                 string pushLiveUrl)
        {
            if (string.IsNullOrEmpty(pushLiveUrl))
            {
                return(AsyncCallbackMsg.GenerateMsg(Messages.WarningLivePushLiveUrlNotSet));
            }

            LiveVideoParameter liveParam = LiveParam;

            liveParam.Url1 = pushLiveUrl;

            if (liveParam.Width == 0 || liveParam.Height == 0 || liveParam.VideoBitrate == 0)
            {
                return(AsyncCallbackMsg.GenerateMsg(Messages.WarningLiveResolutionNotSet));
            }

            Log.Logger.Debug(
                $"【server push live begins】:width={liveParam.Width}, height={liveParam.Height}, bitrate={liveParam.VideoBitrate}, url={liveParam.Url1}, videos={liveVideoStreamInfos.Count}");

            for (int i = 0; i < liveVideoStreamInfos.Count; i++)
            {
                Log.Logger.Debug(
                    $"video{i + 1}:x={liveVideoStreamInfos[i].X}, y={liveVideoStreamInfos[i].Y}, width={liveVideoStreamInfos[i].Width}, height={liveVideoStreamInfos[i].Height}");
            }

            AsyncCallbackMsg startLiveStreamResult =
                await _sdkService.StartLiveStream(liveParam, liveVideoStreamInfos.ToArray(), liveVideoStreamInfos.Count);

            if (startLiveStreamResult.Status == 0)
            {
                LiveId = int.Parse(startLiveStreamResult.Data.ToString());

                HasPushLiveSuccessfully = true;
                Log.Logger.Debug($"【server push live succeeded】:liveId={LiveId}");
            }
            else
            {
                HasPushLiveSuccessfully = false;
                Log.Logger.Error($"【server push live failed】:{startLiveStreamResult.Message}");
            }

            return(startLiveStreamResult);
        }
        public LiveVideoParameter GetLiveParam()
        {
            // get live configuration from local xml file
            if (!File.Exists(ConfigFile))
            {
                LiveParam = new LiveVideoParameter();
                return(new LiveVideoParameter());
            }
            try
            {
                LiveVideoParameter liveParam = new LiveVideoParameter
                {
                    AudioBitrate   = 64,
                    BitsPerSample  = 16,
                    Channels       = 1,
                    IsLive         = true,
                    IsRecord       = false,
                    SampleRate     = 8000,
                    RecordFilePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),

                    Url1         = GlobalData.Instance.AggregatedConfig.LocalLiveConfig.PushLiveStreamUrl,
                    VideoBitrate = int.Parse(GlobalData.Instance.AggregatedConfig.LocalLiveConfig.CodeRate)
                };

                string[] resolutionStrings =
                    GlobalData.Instance.AggregatedConfig.LocalLiveConfig.Resolution.Split(new[] { '*' },
                                                                                          StringSplitOptions.RemoveEmptyEntries);

                liveParam.Width  = int.Parse(resolutionStrings[0]);
                liveParam.Height = int.Parse(resolutionStrings[1]);


                LiveParam = liveParam;
                return(liveParam);
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"【get local push live param exception】:{ex}");
                LiveParam = new LiveVideoParameter();
                return(new LiveVideoParameter());
            }
        }