Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["authenticated"] == null)
     Response.Redirect("Login.aspx");
       List<string> recPaths = new List<string>();
       ServiceInterface server = new ServiceInterface();
       if (hfAction.Value != "")
       {
     if (hfAction.Value == "0")
       server.StopTimeShifting(Int32.Parse(hfIdChannel.Value), Int32.Parse(hfIdCard.Value), hfUsername.Value);
     else if (hfAction.Value == "1")
       server.StopRecording(Int32.Parse(hfIdChannel.Value), Int32.Parse(hfIdCard.Value), hfUsername.Value);
     hfAction.Value = "";
       }
       List<WebTvServerStatus> states = server.GetTvServerStatus();
       DataTable dt=new DataTable();
       dt.Columns.Add("name",typeof(string));
       dt.Columns.Add("type",typeof(string));
       dt.Columns.Add("state",typeof(string));
       dt.Columns.Add("channel",typeof(string));
       dt.Columns.Add("user",typeof(string));
       dt.Columns.Add("action", typeof(string));
       foreach (WebTvServerStatus state in states)
       {
     if (!recPaths.Contains(state.recordingFolder))
       recPaths.Add(state.recordingFolder);
     DataRow row = dt.NewRow();
     row["name"] = state.cardName;
     row["type"] = state.cardTypeStr;
     row["state"] = state.statusStr;
     row["channel"] = state.channel;
     row["user"] = state.userName;
     if ((CardStatus)state.status == CardStatus.TimeShifting)
     {
       row["action"]="<input type=\"button\" ID=\"btn\" Value=\"Stop timeshift\" onclick=KickSession("+state.idCard.ToString()+","+state.idChannel.ToString()+",'"+state.userName+"',0); />";
     }
     else if ((CardStatus)state.status == CardStatus.Recording)
     {
       row["action"] = "<input type=\"button\" ID=\"btn\" Value=\"Stop recording\" onclick=KickSession(" + state.idCard.ToString() + "," + state.idChannel.ToString() + ",'" + state.userName + "',1); />";
     }
     dt.Rows.Add(row);
       }
       grid.DataSource = dt;
       grid.DataBind();
       RefreshServerInfo(recPaths);
 }
Пример #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string filename="";

          if (Request.QueryString["sectoken"] == null)
          {
        Utils.Log("Streamer.aspx: ERROR: No sectoken for authentication provided");
        return;
          }
          string uid; string pwd;
          Utils.GetLogin(out uid, out pwd);
          string sectoken = Request.QueryString["sectoken"];
          string decrypt = CryptoHelper.Crypt(sectoken, false);
          if (decrypt.Length < 10)
          {
        Utils.Log("Streamer.aspx: ERROR: Invalid sectoken");
        return;
          }
          decrypt = decrypt.Remove(0, 8);
          if (decrypt != uid + pwd)
          {
        Utils.Log("Streamer.aspx: ERROR: Invalid sectoken");
        return;
          }

          List<EncoderConfig> cfgs = Utils.LoadConfig();
          EncoderConfig cfg = cfgs[Int32.Parse(Request.QueryString["idProfile"])];

          ServiceInterface server = new ServiceInterface();
          if (Request.QueryString["idChannel"]!=null)
          {
        if (server.GetChannel(Int32.Parse(Request.QueryString["idChannel"])).isRadio)
          bufferSize = 2560;
        WebTvResult res = server.StartTimeShifting(Int32.Parse(Request.QueryString["idChannel"]));
        if (res.result != 0)
        {
          Utils.Log("Streamer.aspx: ERROR: StartTimeShifting failed with error: " + res.result.ToString());
          Response.Output.WriteLine("ERROR: StartTimeShifting failed with error: " + res.result.ToString());
          Response.End();
          return;
        }
        usedCard = res.user.idCard;
        usedChannel = res.user.idChannel;
        tvServerUsername = res.user.name;
        if (cfg.inputMethod == TransportMethod.Filename)
          filename = res.rtspURL;
        else
          filename = res.timeshiftFile;
          }
          else if (Request.QueryString["idRecording"]!=null)
          {
        WebRecording rec=server.GetRecording(Int32.Parse(Request.QueryString["idRecording"]));
        filename = rec.fileName;
          }
          else if (Request.QueryString["idMovie"]!=null)
          {
        WebMovie movie=server.GetMovie(Int32.Parse(Request.QueryString["idMovie"]));
        filename=movie.file;
          }
          else if (Request.QueryString["idMusicTrack"]!=null)
          {
        WebMusicTrack track = server.GetMusicTrack(Int32.Parse(Request.QueryString["idMusicTrack"]));
        filename = track.file;
          }
          else if (Request.QueryString["idTvSeries"] != null)
          {
        WebSeries series = server.GetTvSeries(Request.QueryString["idTvSeries"]);
        filename = series.filename;
          }
          else if (Request.QueryString["idMovingPicture"] != null)
          {
        WebMovingPicture pic = server.GetMovingPicture(Int32.Parse(Request.QueryString["idMovingPicture"]));
        filename = pic.filename;
          }
          if (!File.Exists(filename) && !filename.StartsWith("rtsp://"))
          {
        Utils.Log("Streamer.aspx: Requested file " + filename + " does not exist.");
        return;
          }
          Response.Clear();
          Response.Buffer=false;
          Response.BufferOutput=false;
          Response.AppendHeader("Connection","Keep-Alive");
          Response.ContentType="video/x-msvideo";
          Response.StatusCode=200;

          Stream mediaStream=null;
          EncoderWrapper encoder=null;
          Stream outStream = null;

          if (cfg.inputMethod != TransportMethod.Filename)
          {
        if (Request.QueryString["idChannel"] != null)
        {
          mediaStream = new TsBuffer(filename);
        }
        else
          mediaStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        encoder=new EncoderWrapper(mediaStream,cfg);
          }
          else
        encoder=new EncoderWrapper(filename,cfg);

          if (cfg.useTranscoding)
        outStream = encoder;
          else
        outStream = mediaStream;

          byte[] buffer = new byte[bufferSize];
          int read;
          try
          {
        while ((read = outStream.Read(buffer, 0, buffer.Length)) > 0)
        {
          try
          {
            Response.OutputStream.Write(buffer, 0, read);
          }
          catch (Exception)
          {
            break; // stream is closed
          }
          if (Request.QueryString["idChannel"] != null)
            server.SendHeartBeat(usedChannel, usedCard, tvServerUsername);
        }
          }
          catch (Exception ex)
          {
        Utils.Log("Streamer.aspx: Exception raised="+ex.Message+Environment.NewLine+ex.StackTrace);
          }
          if (mediaStream!=null)
        mediaStream.Close();
          if (Request.QueryString["idChannel"] != null)
        server.StopTimeShifting(usedChannel, usedCard, tvServerUsername);
          encoder.StopProcess();
        Response.End();
    }