static ByteBuffer EncodeFlexStreamSend(RtmpContext context, FlexStreamSend msg)
 {
     ByteBuffer output = msg.Data;
     return output;
 }
        public void PushMessage(IPipe pipe, IMessage message)
        {
		    if (message is ResetMessage) 
            {
			    _timeStamper.Reset();
            } 
            else if (message is StatusMessage) 
            {
			    StatusMessage statusMsg = message as StatusMessage;
			    _data.SendStatus(statusMsg.body as StatusASO);
		    }
            else if (message is RtmpMessage)
            {
                // Make sure chunk size has been sent
                if (!_chunkSizeSent)
                    SendChunkSize();

                RtmpMessage rtmpMsg = message as RtmpMessage;
                IRtmpEvent msg = rtmpMsg.body;

                int eventTime = msg.Timestamp;
#if !SILVERLIGHT
                if(log.IsDebugEnabled)
                    log.Debug(string.Format("Message timestamp: {0}", eventTime));
#endif
                if (eventTime < 0)
                {
#if !SILVERLIGHT
                    if (log.IsDebugEnabled)
                        log.Debug(string.Format("Message has negative timestamp: {0}", eventTime));
#endif
                    return;
                }
                byte dataType = msg.DataType;
                // Create a new header for the consumer
                RtmpHeader header = _timeStamper.GetTimeStamp(dataType, eventTime);

                switch (msg.DataType)
                {
                    case Constants.TypeStreamMetadata:
                        Notify notify = new Notify((msg as Notify).Data);
                        notify.Header = header;
                        notify.Timestamp = header.Timer;
                        _data.Write(notify);
                        break;
                    case Constants.TypeFlexStreamEnd:
                        // TODO: okay to send this also to AMF0 clients?
                        FlexStreamSend send = new FlexStreamSend((msg as Notify).Data);
                        send.Header = header;
                        send.Timestamp = header.Timer;
                        _data.Write(send);
                        break;
                    case Constants.TypeVideoData:
                        VideoData videoData = new VideoData((msg as VideoData).Data);
                        videoData.Header = header;
                        videoData.Timestamp = header.Timer;
                        _video.Write(videoData);
                        break;
                    case Constants.TypeAudioData:
                        AudioData audioData = new AudioData((msg as AudioData).Data);
                        audioData.Header = header;
                        audioData.Timestamp = header.Timer;
                        _audio.Write(audioData);
                        break;
                    case Constants.TypePing:
                        Ping ping = new Ping((msg as Ping).PingType, (msg as Ping).Value2, (msg as Ping).Value3, (msg as Ping).Value4);
                        ping.Header = header;
                        _connection.Ping(ping);
                        break;
                    case Constants.TypeBytesRead:
                        BytesRead bytesRead = new BytesRead((msg as BytesRead).Bytes);
                        bytesRead.Header = header;
                        bytesRead.Timestamp = header.Timer;
                        _connection.GetChannel((byte)2).Write(bytesRead);
                        break;
                    default:
                        _data.Write(msg);
                        break;
                }
            }
        }
Example #3
0
 public IMessage PullMessage(IPipe pipe)
 {
     lock (_syncLock)
     {
         if (_pipe != pipe)
             return null;
         if (_reader == null)
             Init();
         if (!_reader.HasMoreTags())
         {
             // TODO send OOBCM to notify EOF
             // Do not unsubscribe as this kills VOD seek while in buffer
             // this.pipe.unsubscribe(this);
             return null;
         }
         ITag tag = _reader.ReadTag();
         IRtmpEvent msg = null;
         int timestamp = tag.Timestamp;
         switch (tag.DataType)
         {
             case Constants.TypeAudioData:
                 msg = new AudioData(tag.Body);
                 break;
             case Constants.TypeVideoData:
                 msg = new VideoData(tag.Body);
                 break;
             case Constants.TypeInvoke:
                 msg = new Invoke(tag.Body);
                 break;
             case Constants.TypeNotify:
                 msg = new Notify(tag.Body);
                 break;
             case Constants.TypeFlexStreamEnd:
                 msg = new FlexStreamSend(tag.Body);
                 break;
             default:
                 log.Warn("Unexpected type " + tag.DataType);
                 msg = new Unknown(tag.DataType, tag.Body);
                 break;
         }
         msg.Timestamp = timestamp;
         RtmpMessage rtmpMsg = new RtmpMessage();
         rtmpMsg.body = msg;
         return rtmpMsg;
     }
 }