Esempio n. 1
0
 /// <summary>
 /// Creates a new RTSP stream
 /// </summary>
 /// <param name="stream">The rtsp stream</param>
 public void AddStream(RtspStream stream)
 {
     if (_initialized == false)
     {
         return;
     }
     if (_streams.ContainsKey(stream.Name))
     {
         return;
     }
     if (System.IO.File.Exists(stream.FileName))
     {
         Log.Log.WriteFile("RTSP: add stream {0} file:{1}", stream.Name, stream.FileName);
         if (stream.Card != null)
         {
             StreamAddTimeShiftFile(stream.Name, stream.FileName, false, (stream.IsTv ? 0 : 1));
         }
         else
         {
             StreamAddMpegFile(stream.Name, stream.FileName, 0);
         }
         _streams[stream.Name] = stream;
     }
 }
 /// <summary>
 /// Gets the rtsp URL for file located on the tvserver.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <returns>rtsp url</returns>
 public string GetUrlForFile(string fileName)
 {
   if (File.Exists(fileName))
   {
     _streamer.Start();
     string streamName = String.Format("{0:X}", fileName.GetHashCode());
     RtspStream stream = new RtspStream(streamName, fileName, streamName);
     _streamer.AddStream(stream);
     string url = String.Format("rtsp://{0}:{1}/{2}", _ourServer.HostName, _streamer.Port, streamName);
     Log.Info("Controller: streaming url:{0} file:{1}", url, fileName);
     return url;
   }
   return "";
 }
 public string GetRecordingUrl(int idRecording)
 {
   try
   {
     Recording recording = Recording.Retrieve(idRecording);
     if (recording == null)
       return "";
     if (recording.FileName == null)
       return "";
     if (recording.FileName.Length == 0)
       return "";
     if (!IsLocal(recording.ReferencedServer().HostName))
     {
       try
       {
         RemoteControl.HostName = recording.ReferencedServer().HostName;
         return RemoteControl.Instance.GetRecordingUrl(idRecording);
       }
       catch (Exception)
       {
         Log.Error("Controller: unable to connect to slave controller at:{0}", recording.ReferencedServer().HostName);
         return "";
       }
     }
     try
     {
       if (File.Exists(recording.FileName))
       {
         _streamer.Start();
         string streamName = String.Format("{0:X}", recording.FileName.GetHashCode());
         RtspStream stream = new RtspStream(streamName, recording.FileName, recording.Title);
         _streamer.AddStream(stream);
         string url = String.Format("rtsp://{0}:{1}/{2}", _ourServer.HostName, _streamer.Port, streamName);
         Log.Info("Controller: streaming url:{0} file:{1}", url, recording.FileName);
         return url;
       }
     }
     catch (Exception)
     {
       Log.Error("Controller: Can't get recroding url - First catch");
     }
   }
   catch (Exception)
   {
     Log.Error("Controller: Can't get recroding url - Second catch");
   }
   return "";
 }
    /// <summary>
    /// Start timeshifting.
    /// </summary>
    /// <param name="user"></param>
    /// <param name="fileName">Name of the timeshiftfile.</param>
    /// <returns>
    /// TvResult indicating whether method succeeded
    /// </returns>
    public TvResult StartTimeShifting(ref IUser user, ref string fileName)
    {
      if (ValidateTvControllerParams(user))
        return TvResult.UnknownError;
      try
      {
        int cardId = user.CardId;
        if (false == _cards[cardId].IsLocal)
        {
          try
          {
            RemoteControl.HostName = _cards[cardId].DataBaseCard.ReferencedServer().HostName;
            return RemoteControl.Instance.StartTimeShifting(ref user, ref fileName);
          }
          catch (Exception)
          {
            Log.Error("card: unable to connect to slave controller at:{0}",
                      _cards[cardId].DataBaseCard.ReferencedServer().HostName);
            return TvResult.UnknownError;
          }
        }

        Fire(this, new TvServerEventArgs(TvServerEventType.StartTimeShifting, GetVirtualCard(user), (User)user));
        if (_epgGrabber != null)
        {
          _epgGrabber.Stop();
        }

        bool isTimeShifting;
        try
        {
          isTimeShifting = _cards[cardId].TimeShifter.IsTimeShifting(ref user);
        }
        catch (Exception ex)
        {
          isTimeShifting = false;
          Log.Error("Exception in checking  " + ex.Message);
        }
        TvResult result = _cards[cardId].TimeShifter.Start(ref user, ref fileName);
        if (result == TvResult.Succeeded)
        {
          if (!isTimeShifting)
          {
            Log.Info("user:{0} card:{1} sub:{2} add stream:{3}", user.Name, user.CardId, user.SubChannel, fileName);
            if (File.Exists(fileName))
            {
              _streamer.Start();

              //  Default to tv
              bool isTv = true;

              ITvSubChannel subChannel = _cards[cardId].Card.GetSubChannel(user.SubChannel);

              if (subChannel != null && subChannel.CurrentChannel != null)
                isTv = subChannel.CurrentChannel.IsTv;
              else
                Log.Error("SubChannel or CurrentChannel is null when starting streaming");

              RtspStream stream = new RtspStream(String.Format("stream{0}.{1}", cardId, user.SubChannel), fileName,
                                                 _cards[cardId].Card, isTv);
              _streamer.AddStream(stream);
            }
            else
            {
              Log.Write("Controller: streaming: file not found:{0}", fileName);
            }
          }
        }
        return result;
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
      return TvResult.UnknownError;
    }
Esempio n. 5
0
 /// <summary>
 /// Creates a new RTSP stream
 /// </summary>
 /// <param name="stream">The rtsp stream</param>
 public void AddStream(RtspStream stream)
 {
   if (_initialized == false)
     return;
   if (_streams.ContainsKey(stream.Name))
   {
     return;
   }
   if (System.IO.File.Exists(stream.FileName))
   {
     Log.Log.WriteFile("RTSP: add stream {0} file:{1}", stream.Name, stream.FileName);
     if (stream.Card != null)
     {
       StreamAddTimeShiftFile(stream.Name, stream.FileName, false, (stream.IsTv ? 0 : 1));
     }
     else
     {
       StreamAddMpegFile(stream.Name, stream.FileName, 0);
     }
     _streams[stream.Name] = stream;
   }
 }