Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void DoStart()
- {
- var vss = Source;
- if (!_modeAudio)
- vss = Tokenise(vss);
- AVDictionary* options = null;
- if (_inputFormat == null)
- {
- ffmpeg.av_dict_set(&options, "analyzeduration", _analyzeDuration.ToString(), 0);
- string prefix = vss.ToLower().Substring(0, vss.IndexOf(":", StringComparison.Ordinal));
- switch (prefix)
- {
- case "http":
- case "mmsh":
- case "mms":
- ffmpeg.av_dict_set(&options, "timeout", _timeout.ToString(CultureInfo.InvariantCulture), 0);
- ffmpeg.av_dict_set(&options, "stimeout", (_timeout * 1000).ToString(CultureInfo.InvariantCulture), 0);
- if (_cookies != "")
- {
- ffmpeg.av_dict_set(&options, "cookies", _cookies, 0);
- }
- if (_headers != "")
- {
- ffmpeg.av_dict_set(&options, "headers", _headers, 0);
- }
- if (_userAgent != "")
- {
- ffmpeg.av_dict_set(&options, "user-agent", _userAgent, 0);
- }
- break;
- case "tcp":
- case "udp":
- case "rtp":
- case "sdp":
- case "mmst":
- case "ftp":
- ffmpeg.av_dict_set(&options, "timeout", _timeout.ToString(CultureInfo.InvariantCulture), 0);
- break;
- case "rtsp":
- case "rtmp":
- ffmpeg.av_dict_set(&options, "stimeout", (_timeout * 1000).ToString(CultureInfo.InvariantCulture), 0);
- if (_userAgent != "")
- {
- ffmpeg.av_dict_set(&options, "user-agent", _userAgent, 0);
- }
- break;
- }
- ffmpeg.av_dict_set(&options, "rtsp_transport", _rtsPmode, 0);
- }
- ffmpeg.av_dict_set(&options, "rtbufsize", "10000000", 0);
- var lo = _options.Split(Environment.NewLine.ToCharArray());
- foreach (var nv in lo)
- {
- if (!string.IsNullOrEmpty(nv))
- {
- var i = nv.IndexOf('=');
- if (i > -1)
- {
- var n = nv.Substring(0, i).Trim();
- var v = nv.Substring(i + 1).Trim();
- if (!string.IsNullOrEmpty(n) && !string.IsNullOrEmpty(v))
- {
- int j;
- if (int.TryParse(v, out j))
- {
- ffmpeg.av_dict_set_int(&options, n, j, 0);
- }
- else
- {
- ffmpeg.av_dict_set(&options, n, v, 0);
- }
- }
- }
- }
- }
- _stopReadingFrames = false;
- try
- {
- Program.FfmpegMutex.WaitOne();
- var pFormatContext = ffmpeg.avformat_alloc_context();
- _lastPacket = DateTime.UtcNow;
- _interruptCallback = InterruptCb;
- _interruptCallbackAddress = Marshal.GetFunctionPointerForDelegate(_interruptCallback);
- pFormatContext->interrupt_callback.callback = _interruptCallbackAddress;
- pFormatContext->interrupt_callback.opaque = null;
- if (ffmpeg.avformat_open_input(&pFormatContext, vss, _inputFormat, &options) != 0)
- {
- throw new ApplicationException(@"Could not open source");
- }
- _formatContext = pFormatContext;
- SetupFormat();
- }
- catch (Exception ex)
- {
- ErrorHandler?.Invoke(ex.Message);
- _res = ReasonToFinishPlaying.VideoSourceError;
- PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_res));
- AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_res));
- }
- finally
- {
- try
- {
- Program.FfmpegMutex.ReleaseMutex();
- }
- catch
- {
- }
- }
- _starting = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement