     @receivedBytes = 0
     @stream_switched = false
     @server = server
-    @lastTimestamp = 0
-    @offsetTimestamp = 0
+    @lastTimestamp = { 'audio': 0, 'video': 0 }
+    @offsetTimestamp = { 'audio': 0, 'video': 0 }
+
+  from_packet: (pkt) ->
+    if (pkt.avType == 'audio')
+      if @audio_stream
+        console.log 'Audio filter'
+        return (@audio_stream == pkt.stream)
+    return @stream == pkt.stream
 
   clearTimeout: ->
     if @timeoutTimer?

        console.log "metadata re-sent"

      for rtmpMessage in msgs
        session.lastTimestamp = rtmpMessage.timestamp = session.offsetTimestamp + session.getScaledTimestamp(rtmpMessage.originalTimestamp) % TIMESTAMP_ROUNDOFF 

      if msgs.length > 1
        buf = createRTMPAggregateMessage msgs, session.chunkSize


  for session in allSessions
    msgs = [];
    msgs2 = []
    for rtmpMessage, i in rtmpMessagesToSend
      msgs.push rtmpMessage if session.from_packet(rtmpMessage)

    if not msgs? || msgs.length == 0
      continue

    #console.log "lets stream"
    #fixme -> remove the ! and test again, this was a hack for stream switching
    if session.isWaitingForKeyFrame
      if session.stream.isVideoStarted  # has video stream
        for rtmpMessage, i in msgs
          if rtmpMessage.avType is 'video' and rtmpMessage.isKeyFrame
            session.isPlaying = true
            session.playStartTimestamp = rtmpMessage.originalTimestamp
            session.isWaitingForKeyFrame = false
            msgs2 = msgs[i..]
            break
      else  # audio only
        session.isPlaying = true
        session.playStartTimestamp = msgs[0].originalTimestamp
        session.isWaitingForKeyFrame = false
        msgs2 = msgs
    else
      msgs2 = msgs

    msgs2 = msgs;

    if not msgs? || msgs.length == 0
      continue
