public int SetMediaFile(string fileName) { Log($"File Selected {fileName}"); if (streamType == StreamType.FILE) { int ret = decoder.Open(null, DecoderRequestsBuffer, fileSize); return(ret); } else if (streamType == StreamType.TORRENT) { Pause(); aDone = false; vDone = false; sDone = false; lock (localFocusPoints) { foreach (KeyValuePair <long, Tuple <long, int> > curLFPKV in localFocusPoints) { tsStream.DeleteFocusPoint(curLFPKV.Key); } localFocusPoints.Clear(); } fileIndex = torrent.file.paths.IndexOf(fileName); fileSize = torrent.file.lengths[fileIndex]; fileDistance = 0; for (int i = 0; i < fileIndex; i++) { fileDistance += torrent.file.lengths[i]; } if (!torrent.data.files[fileIndex].FileCreated) { tsStream.IncludeFiles(new List <string>() { fileName }); } if (!torrent.data.files[fileIndex].FileCreated && !tsStream.isRunning) { tsStream.Start(); } // Decoder - Opening Format Contexts (cancellation?) -> DecoderRequests Feed with null? Log($"[BB OPENING 1]"); int ret = decoder.Open(null, DecoderRequestsBuffer, fileSize); return(ret); } return(-1); }
// Public Exposure public int Open(string url) { int ret; if (decoder != null) { decoder.Pause(); } Initialize(); if ((ret = decoder.Open(url)) != 0) { return(ret); } if (!decoder.isReady) { return(-1); } isReady = true; CurTime = 0; audioExternalDelay = 0; subsExternalDelay = 0; hasAudio = decoder.hasAudio; hasVideo = decoder.hasVideo; hasSubs = decoder.hasSubs; Width = (hasVideo) ? decoder.vStreamInfo.width : 0; Height = (hasVideo) ? decoder.vStreamInfo.height : 0; Duration = (hasVideo) ? decoder.vStreamInfo.durationTicks : decoder.aStreamInfo.durationTicks; return(0); }
public void Open(string url) { int ret; lock (lockOpening) { if (decoder.status == Codecs.FFmpeg.Status.OPENING) { Thread.Sleep(50); } if (openOrBuffer != null) { openOrBuffer.Abort(); } if (decoder != null) { decoder.Pause(); } Initialize(); status = Status.OPENING; } Log($"Opening {url}"); string ext = url.Substring(url.LastIndexOf(".") + 1); string scheme = url.Substring(0, url.IndexOf(":")); if (ext.ToLower() == "torrent" || scheme.ToLower() == "magnet") { isTorrent = true; openOrBuffer = new Thread(() => { try { if (scheme.ToLower() == "magnet") { ret = streamer.Open(url, MediaStreamer.StreamType.TORRENT); } else { ret = streamer.Open(url, MediaStreamer.StreamType.TORRENT, false); } if (ret != 0) { status = Status.FAILED; OpenTorrentSuccessClbk?.BeginInvoke(false, null, null); return; } status = Status.OPENED; OpenTorrentSuccessClbk?.BeginInvoke(true, null, null); } catch (ThreadAbortException) { return; } }); openOrBuffer.SetApartmentState(ApartmentState.STA); openOrBuffer.Start(); } else { lock (lockOpening) { if (decoder.status == Codecs.FFmpeg.Status.OPENING) { Thread.Sleep(50); } isTorrent = false; decoder.Open(url); if (!decoder.isReady) { status = Status.FAILED; return; } InitializeEnv(); status = Status.OPENED; } } }