Beispiel #1
0
 public void RemoveFromTsPoos(TorrentStream ts)
 {
     List<TorrentStream> list = this._tsPool;
     bool lockTaken = false;
     try
     {
         Monitor.Enter((object)list, ref lockTaken);
         if (!this._tsPool.Contains(ts))
             return;
         ts.Disconnect(true);
         this._tsPool.Remove(ts);
     }
     finally
     {
         if (lockTaken)
             Monitor.Exit((object)list);
     }
 }
 public override void Play(MyWebRequest req)
 {
     GetStream getStream = GetStream.Run(this._device.Proxy.SessionState.session, int.Parse(req.Parameters["id"].Split("#".ToCharArray(), 2)[0]));
     if (!getStream.IsSuccess())
     {
         if (getStream.error != ApiError.incorrect)
             throw new Exception(getStream.error.ToString());
         while (!this._device.Proxy.Login() && this._device.Proxy.SessionState.error == ApiError.noconnect)
             TtvProxy.Log.WriteInfo("Попыдка авторизации на torrent-tv.ru");
         if (!this._device.Proxy.SessionState.IsSuccess())
             throw new Exception("No authorized");
         this.Play(req);
     }
     else
     {
         TorrentStream ts = this._device.Proxy.GetTsClient(getStream.source);
         Task<string> task;
         if (ts == null)
         {
             if (!req.Client.Connected)
                 return;
             ts = new TorrentStream(req.Client);
             ts.Connect();
             task = ts.Play(getStream.source, getStream.type, 0);
             if (task != null)
                 this._device.Proxy.AddToTsPool(ts);
         }
         else
         {
             task = ts.GetPlayTask();
             ts.Owner.Add(req.Client);
         }
         if (task != null && !task.IsCompleted)
             task.Wait();
         else if (task == null)
             throw new FileNotFoundException();
         if (string.IsNullOrEmpty(task.Result))
         {
             this._device.Proxy.RemoveFromTsPoos(ts);
             req.GetResponse().SendText("AceStream TimeOut");
         }
         else
         {
             string result = task.Result;
             string str = string.Empty;
             try
             {
                 str = this._device.Proxy.FindBroadcastUrl(result);
                 if (string.IsNullOrEmpty(str))
                     str = this._device.Proxy.StartBroadcastStream(result, (string)null);
                 this._device.Proxy.AddVlcBroadcastClient(str, req.Client);
                 req.GetResponse().SendStream(str, (Action<MyWebRequest>)null);
                 if (req.Client.Connected)
                     req.Client.Close();
                 if (!this._device.Proxy.StopBroadcast(str, result))
                     return;
                 ts.Disconnect(true);
                 this._device.Proxy.RemoveFromTsPoos(ts);
             }
             catch (Exception ex)
             {
                 TtvProxy.Log.WriteError(ex.Message);
                 ts.Disconnect(true);
                 this._device.Proxy.RemoveFromTsPoos(ts);
                 this._device.Proxy.StopBroadcast(str, result);
             }
         }
     }
 }
Beispiel #3
0
 public void AddToTsPool(TorrentStream ts)
 {
     List<TorrentStream> list = this._tsPool;
     bool lockTaken = false;
     try
     {
         Monitor.Enter((object)list, ref lockTaken);
         this._tsPool.Add(ts);
     }
     finally
     {
         if (lockTaken)
             Monitor.Exit((object)list);
     }
 }