Пример #1
0
 protected override async Task OnCommandPlay(CommandMessage msg, CancellationToken cancel_token)
 {
   var stream_name = StreamName.Parse((string)msg.Arguments[0]);
   var start       = msg.Arguments.Count>1 ? (int)msg.Arguments[1] : -2;
   var duration    = msg.Arguments.Count>2 ? (int)msg.Arguments[2] : -1;
   var reset       = msg.Arguments.Count>3 ? (bool)msg.Arguments[3] : false;
   logger.Debug("Play: {0}, {1}, {2}, {3}", stream_name.ToString(), start, duration, reset);
   if (owner.CheckAuthotization(stream_name.GetParameter("auth"))) {
     this.Channel = await RequestChannel(stream_name, cancel_token);
     this.StreamId = msg.StreamId;
     await SendMessage(2, new UserControlMessage.StreamBeginMessage(this.Now, 0, msg.StreamId), cancel_token);
     if (this.Channel!=null) {
       await SendOnStatus(
         this.StreamId,
         msg.TransactionId+1,
         "status",
         "NetStream.Play.Start",
         stream_name.ToString(),
         cancel_token);
       if (reset) {
         await SendOnStatus(
           this.StreamId,
           msg.TransactionId+1,
           "status",
           "NetStream.Play.Reset",
           stream_name.ToString(),
           cancel_token);
       }
     }
     else {
       await SendOnStatus(
         this.StreamId,
         msg.TransactionId+1,
         "error",
         "NetStream.Play.FileNotFound",
         stream_name.ToString(),
         cancel_token);
     }
   }
   else {
     await SendOnStatus(
       this.StreamId,
       msg.TransactionId+1,
       "error",
       "NetStream.Play.Failed",
       "auth failed",
       cancel_token);
   }
   if (msg.TransactionId!=0) {
     var result = CommandMessage.Create(
       this.ObjectEncoding,
       this.Now,
       msg.StreamId,
       "_result",
       msg.TransactionId,
       null
     );
     await SendMessage(3, result, cancel_token);
   }
   if (this.Channel!=null) {
     await base.OnCommandPlay(msg, cancel_token);
     this.Channel.ContentChanged += OnContentChanged;
     OnContentChanged(this, new EventArgs());
   }
   else {
     Close();
   }
 }
Пример #2
0
 private Task OnCommandDeleteStream(CommandMessage msg, CancellationToken cancel_token)
 {
   Stop(StopReason.OffAir);
   return Task.Delay(0);
 }
Пример #3
0
 private async Task OnCommandPublish(CommandMessage msg, CancellationToken cancel_token)
 {
   var name = (string)msg.Arguments[0];
   var type = (string)msg.Arguments[1];
   Logger.Debug("publish: name {0}, type: {1}", name, type);
   await SendMessage(2, new UserControlMessage.StreamBeginMessage(this.Now, 0, msg.StreamId), cancel_token);
   var status = CommandMessage.Create(
     objectEncoding,
     this.Now,
     msg.StreamId,
     "onStatus",
     0,
     null,
     new AMF.AMFValue(new AMF.AMFObject {
       { "level",       "status" },
       { "code",        "NetStream.Publish.Start" },
       { "description", name },
     })
   );
   await SendMessage(3, status, cancel_token);
   var result = CommandMessage.Create(
     objectEncoding,
     this.Now,
     msg.StreamId,
     "_result",
     msg.TransactionId,
     null
   );
   if (msg.TransactionId!=0) {
     await SendMessage(3, result, cancel_token);
   }
   this.state = ConnectionState.Receiving;
 }
Пример #4
0
 private Task OnCommandClose(CommandMessage msg, CancellationToken cancel_token)
 {
   return Task.Delay(0);
 }
Пример #5
0
 private async Task OnCommandCreateStream(CommandMessage msg, CancellationToken cancel_token)
 {
   var new_stream_id = nextStreamId++;
   var response = CommandMessage.Create(
     objectEncoding,
     this.Now,
     msg.StreamId,
     "_result",
     msg.TransactionId,
     null,
     new AMF.AMFValue(new_stream_id)
   );
   if (msg.TransactionId!=0) {
     await SendMessage(3, response, cancel_token);
   }
 }
Пример #6
0
 private async Task OnCommand(CommandMessage msg, CancellationToken cancel_token)
 {
   if (msg.StreamId==0) {
     Logger.Debug("NetConnection command: {0}", msg.CommandName);
     //NetConnection commands
     switch (msg.CommandName) {
     case "connect":      await OnCommandConnect(msg, cancel_token); break;
     case "call":         await OnCommandCall(msg, cancel_token); break;
     case "close":        await OnCommandClose(msg, cancel_token); break;
     case "createStream": await OnCommandCreateStream(msg, cancel_token); break;
     case "deleteStream": await OnCommandDeleteStream(msg, cancel_token); break;
     }
   }
   else {
     Logger.Debug("NetStream ({0}) command: {1}", msg.StreamId, msg.CommandName);
     //NetStream commands
     switch (msg.CommandName) {
     case "publish": await OnCommandPublish(msg, cancel_token); break;
     case "deleteStream": await OnCommandDeleteStream(msg, cancel_token); break;
     case "play":
     case "play2":
     case "closeStream":
     case "receiveAudio":
     case "receiveVideo":
     case "seek":
     case "pause":
     default:
       break;
     }
   }
 }
Пример #7
0
 private async Task OnCommandConnect(CommandMessage msg, CancellationToken cancel_token)
 {
   objectEncoding = ((int)msg.CommandObject["objectEncoding"])==3 ? 3 : 0;
   clientName     = (string)msg.CommandObject["flashVer"];
   Logger.Debug("connect: objectEncoding {0}, flashVer: {1}", objectEncoding, clientName);
   await SendMessage(2, new SetWindowSizeMessage(this.Now, 0, recvWindowSize), cancel_token);
   await SendMessage(2, new SetPeerBandwidthMessage(this.Now, 0, sendWindowSize, PeerBandwidthLimitType.Hard), cancel_token);
   await SendMessage(2, new UserControlMessage.StreamBeginMessage(this.Now, 0, 0), cancel_token);
   var response = CommandMessage.Create(
     objectEncoding,
     this.Now,
     msg.StreamId,
     "_result",
     msg.TransactionId,
     new AMF.AMFValue(new AMF.AMFObject {
       { "fmsVer",       "FMS/3,5,5,2004" },
       { "capabilities", 31 },
       { "mode",         1 },
     }),
     new AMF.AMFValue(new AMF.AMFObject {
       { "level",          "status" },
       { "code",           "NetConnection.Connect.Success" },
       { "description",    "Connection succeeded" },
       { "data",           new AMF.AMFObject { { "version", "3,5,5,2004" } } },
       { "clientId",       nextClientId++ },
       { "objectEncoding", objectEncoding },
     })
   );
   if (msg.TransactionId!=0) {
     await SendMessage(3, response, cancel_token);
   }
 }
Пример #8
0
		protected virtual async Task OnCommandClose(CommandMessage msg, CancellationToken cancel_token)
		{
		}
Пример #9
0
		protected virtual async Task OnCommandPlay(CommandMessage msg, CancellationToken cancel_token)
		{
			timestampTimer.Start();
		}
Пример #10
0
 protected virtual Task OnCommandPlay(CommandMessage msg, CancellationToken cancel_token)
 {
   timestampTimer.Start();
   return Task.Delay(0);
 }
Пример #11
0
		protected virtual async Task OnCommandConnect(CommandMessage msg, CancellationToken cancel_token)
		{
			logger.Debug("Connect: tcUrl:{0}, app:{1}, flashVer:{2}",
				(string)msg.CommandObject["tcUrl"],
				(string)msg.CommandObject["app"],
				(string)msg.CommandObject["flashVer"]);
			if (msg.CommandObject.ContainsKey("objectEncoding")) {
				objectEncoding = ((int)msg.CommandObject["objectEncoding"])==3 ? 3 : 0;
			}
			else {
				objectEncoding = 0;
			}
			ClientName = (string)msg.CommandObject["flashVer"];
			await SendMessage(2, new SetWindowSizeMessage(this.Now, 0, recvWindowSize), cancel_token);
			await SendMessage(2, new SetPeerBandwidthMessage(this.Now, 0, sendWindowSize, PeerBandwidthLimitType.Hard), cancel_token);
			await SendMessage(2, new UserControlMessage.StreamBeginMessage(this.Now, 0, 0), cancel_token);
			sendChunkSize = 4096;
			await SendMessage(2, new SetChunkSizeMessage(this.Now, 0, sendChunkSize), cancel_token);
			var response = CommandMessage.Create(
				objectEncoding,
				this.Now,
				msg.StreamId,
				"_result",
				msg.TransactionId,
				new AMF.AMFValue(new AMF.AMFObject {
					{ "fmsVer",       "FMS/3,5,5,2004" },
					{ "capabilities", 31 },
					{ "mode",         1 },
				}),
				new AMF.AMFValue(new AMF.AMFObject {
					{ "level",          "status" },
					{ "code",           "NetConnection.Connect.Success" },
					{ "description",    "Connection succeeded." },
					{ "clientId",       nextClientId++ },
					{ "objectEncoding", objectEncoding },
					{ "data",           new AMF.AMFValue(new Dictionary<string,AMF.AMFValue> { { "version", new AMF.AMFValue("5,0,6,6102") } }) },
				})
			);
			if (msg.TransactionId!=0) {
				await SendMessage(3, response, cancel_token);
			}
		}
Пример #12
0
 protected virtual Task OnCommandDeleteStream(CommandMessage msg, CancellationToken cancel_token)
 {
   return Task.Delay(0);
 }
Пример #13
0
 void OnCommandCreateStream(CommandMessage msg)
 {
     var new_stream_id = nextStreamId++;
       var response = CommandMessage.Create(
     objectEncoding,
     this.Now,
     msg.StreamId,
     "_result",
     msg.TransactionId,
     null,
     new AMF.AMFValue(new_stream_id)
       );
       if (msg.TransactionId!=0) {
     SendMessage(3, response);
       }
 }
Пример #14
0
 void OnCommandClose(CommandMessage msg)
 {
 }
Пример #15
0
 void OnCommandCall(CommandMessage msg)
 {
 }
Пример #16
0
 void OnCommand(CommandMessage msg)
 {
     if (msg.StreamId==0) {
     Logger.Debug("NetConnection command: {0}", msg.CommandName);
     //NetConnection commands
     switch (msg.CommandName) {
     case "connect":      OnCommandConnect(msg); break;
     case "call":         OnCommandCall(msg); break;
     case "close":        OnCommandClose(msg); break;
     case "createStream": OnCommandCreateStream(msg); break;
     }
       }
       else {
     Logger.Debug("NetStream ({0}) command: {1}", msg.StreamId, msg.CommandName);
     //NetStream commands
     switch (msg.CommandName) {
     case "publish": OnCommandPublish(msg); break;
     case "play":
     case "play2":
     case "deleteStream":
     case "closeStream":
     case "receiveAudio":
     case "receiveVideo":
     case "seek":
     case "pause":
     default:
       break;
     }
       }
 }