/// <summary>
        /// Returns the current filename used for recording
        /// </summary>
        /// <param name="user">User</param>
        /// <returns>filename or null when not recording</returns>
        public string FileName(ref IUser user)
        {
            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return("");
                }

                try
                {
                    RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                    if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard))
                    {
                        return("");
                    }

                    if (_cardHandler.IsLocal == false)
                    {
                        return(RemoteControl.Instance.RecordingFileName(ref user));
                    }
                }
                catch (Exception)
                {
                    Log.Error("card: unable to connect to slave controller at:{0}",
                              _cardHandler.DataBaseCard.ReferencedServer().HostName);
                    return("");
                }

                TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                if (context == null)
                {
                    return(null);
                }
                context.GetUser(ref user);
                ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                if (subchannel == null)
                {
                    return(null);
                }
                return(subchannel.RecordingFileName);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return("");
            }
        }
        private bool StopRecording(ref IUser user, TvCardContext context)
        {
            bool stop = false;

            context.GetUser(ref user);
            ITvSubChannel subchannel = GetSubChannel(user.SubChannel);

            if (subchannel != null)
            {
                subchannel.StopRecording();
                _cardHandler.Card.FreeSubChannel(user.SubChannel);
                if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
                {
                    _cardHandler.Users.RemoveUser(user);
                }
                stop = true;
            }
            else
            {
                Log.Write("card: StopRecording subchannel null, skipping");
            }
            return(stop);
        }
Exemple #3
0
 private bool StopRecording(ref IUser user, TvCardContext context)
 {
   bool stop = false;
   context.GetUser(ref user);
   ITvSubChannel subchannel = GetSubChannel(user.SubChannel);
   if (subchannel != null)
   {
     subchannel.StopRecording();
     _cardHandler.Card.FreeSubChannel(user.SubChannel);
     if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
     {
       _cardHandler.Users.RemoveUser(user);
     }
     stop = true;
   }
   else
   {
     Log.Write("card: StopRecording subchannel null, skipping");        
   }
   return stop;
 }
    public void NonExistingUserGetUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);

      IUser getUser;
      ctx.GetUser(1, out getUser);

      Assert.IsNull(getUser, "user is not null");      
    }
    public void ExistingUserGetUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);

      IUser getUser;
      ctx.GetUser(2, out getUser);

      Assert.NotNull(getUser, "user is null");
      Assert.AreEqual("u1", getUser.Name);
      Assert.AreEqual(2, getUser.SubChannel);
      Assert.AreEqual(1, getUser.CardId);
    }
    public void GetNonExistingUserExistsTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      IUser getUser = new User("u2", false, 2);      
      bool exists = false;
      ctx.GetUser(ref getUser, out exists);

      Assert.IsFalse(exists, "user exists");
    }
    public void GetNonExistingUserWithCardIDTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      IUser getUser = new User("u2", false, 1);
      ctx.GetUser(ref getUser, 2);

      Assert.AreNotEqual(u1.Name, getUser.Name, "user name equal");
      Assert.AreNotEqual(2, getUser.CardId, "user cardid equal");
    }
    public void GetExistingUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);      
      ctx.Add(u1);

      IUser getUser = new User("u1", false, 1);
      ctx.GetUser(ref getUser);

      Assert.AreEqual(u1.Name, getUser.Name, "user name not equal");
      Assert.AreEqual(u1.CardId, getUser.CardId, "user cardid not equal");
    }
        /// <summary>
        /// Starts recording.
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="fileName">Name of the recording file.</param>
        /// <param name="contentRecording">if true then create a content recording else a reference recording</param>
        /// <param name="startTime">not used</param>
        /// <returns></returns>
        public TvResult Start(ref IUser user, ref string fileName, bool contentRecording, long startTime)
        {
            bool useErrorDetection = false;

            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return(TvResult.CardIsDisabled);
                }

                lock (this)
                {
                    try
                    {
                        RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                        if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard))
                        {
                            return(TvResult.CardIsDisabled);
                        }

                        if (_cardHandler.IsLocal == false)
                        {
                            return(RemoteControl.Instance.StartRecording(ref user, ref fileName, contentRecording, startTime));
                        }
                    }
                    catch (Exception)
                    {
                        Log.Error("card: unable to connect to slave controller at:{0}",
                                  _cardHandler.DataBaseCard.ReferencedServer().HostName);
                        return(TvResult.UnknownError);
                    }

                    TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                    if (context == null)
                    {
                        return(TvResult.UnknownChannel);
                    }

                    context.GetUser(ref user);
                    ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                    if (subchannel == null)
                    {
                        return(TvResult.UnknownChannel);
                    }

                    _subchannel = subchannel;

                    //gibman
                    // RecordingFormat 0 = ts
                    // RecordingFormat 1 = mpeg
                    fileName = fileName.Replace("\r\n", " ");
                    fileName = System.IO.Path.ChangeExtension(fileName, ".ts");

                    useErrorDetection = true;

                    if (useErrorDetection)
                    {
                        // fix mantis 0002807: A/V detection for recordings is not working correctly
                        // reset the events ONLY before attaching the observer, at a later position it can already miss the a/v callback.
                        _eventVideo.Reset();
                        _eventAudio.Reset();
                        Log.Debug("Recorder.start add audioVideoEventHandler");
                        ((BaseSubChannel)subchannel).AudioVideoEvent += AudioVideoEventHandler;
                    }

                    Log.Write("card: StartRecording {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName);
                    bool result = subchannel.StartRecording(fileName);
                    bool isScrambled;
                    if (result)
                    {
                        fileName      = subchannel.RecordingFileName;
                        context.Owner = user;
                        if (useErrorDetection)
                        {
                            if (!WaitForRecordingFile(ref user, out isScrambled))
                            {
                                Log.Write("card: Recording failed! {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName);

                                string cardRecordingFolderName = _cardHandler.DataBaseCard.RecordingFolder;
                                Stop(ref user);
                                _cardHandler.Users.RemoveUser(user);

                                string recordingfolderName = System.IO.Path.GetDirectoryName(fileName);
                                if (recordingfolderName == cardRecordingFolderName)
                                {
                                    Utils.FileDelete(fileName);
                                }
                                else
                                {
                                    // delete 0-byte file in case of error
                                    Utils.DeleteFileAndEmptyDirectory(fileName);
                                }
                                ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler;
                                if (isScrambled)
                                {
                                    return(TvResult.ChannelIsScrambled);
                                }
                                return(TvResult.NoVideoAudioDetected);
                            }
                            ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler;
                        }
                    }
                    if (_timeshiftingEpgGrabberEnabled)
                    {
                        Channel channel = Channel.Retrieve(user.IdChannel);
                        if (channel.GrabEpg)
                        {
                            _cardHandler.Card.GrabEpg();
                        }
                        else
                        {
                            Log.Info("TimeshiftingEPG: channel {0} is not configured for grabbing epg", channel.DisplayName);
                        }
                    }

                    return(TvResult.Succeeded);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(TvResult.UnknownError);
        }
        /// <summary>
        /// Stops recording.
        /// </summary>
        /// <param name="user">User</param>
        /// <returns></returns>
        public bool Stop(ref IUser user)
        {
            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return(false);
                }
                Log.Write("card: StopRecording card={0}, user={1}", _cardHandler.DataBaseCard.IdCard, user.Name);
                lock (this)
                {
                    try
                    {
                        RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                        if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard))
                        {
                            return(false);
                        }

                        if (_cardHandler.IsLocal == false)
                        {
                            return(RemoteControl.Instance.StopRecording(ref user));
                        }
                    }
                    catch (Exception)
                    {
                        Log.Error("card: unable to connect to slave controller at:{0}",
                                  _cardHandler.DataBaseCard.ReferencedServer().HostName);
                        return(false);
                    }
                    Log.Write("card: StopRecording for card:{0}", _cardHandler.DataBaseCard.IdCard);
                    TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                    if (context == null)
                    {
                        Log.Write("card: StopRecording context null");
                        return(false);
                    }
                    if (user.IsAdmin)
                    {
                        context.GetUser(ref user);
                        ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                        if (subchannel == null)
                        {
                            Log.Write("card: StopRecording subchannel null, skipping");
                            return(false);
                        }
                        subchannel.StopRecording();
                        _cardHandler.Card.FreeSubChannel(user.SubChannel);
                        if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
                        {
                            _cardHandler.Users.RemoveUser(user);
                        }
                    }

                    IUser[] users = context.Users;
                    for (int i = 0; i < users.Length; ++i)
                    {
                        ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(users[i].SubChannel);
                        if (subchannel != null)
                        {
                            if (subchannel.IsRecording)
                            {
                                Log.Write("card: StopRecording setting new context owner on user '{0}'", users[i].Name);
                                context.Owner = users[i];
                                break;
                            }
                        }
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(false);
        }