Permalink
Browse files

added support for marker manipulation and fixed few little issues

  • Loading branch information...
1 parent a65996f commit 9d7b1d6628e15966d5e767e02f03fe18da493819 @mainiak committed Jan 19, 2013
Showing with 38 additions and 5 deletions.
  1. +21 −0 examples/test.coffee
  2. +17 −5 lib/RtpPacket.coffee
View
@@ -0,0 +1,21 @@
+#!/usr/bin/env coffee
+RtpPacket = require(__dirname + '/../lib/RtpPacket').RtpPacket
+
+buf = new Buffer 4
+buf[0] = 0
+buf[1] = 0
+buf[2] = 0
+buf[3] = 0
+
+rtp1 = new RtpPacket buf
+rtp2 = new RtpPacket rtp1
+
+console.log rtp1.packet
+console.log rtp2.packet
+
+console.log rtp1.marker
+rtp1.marker = true
+console.log rtp1.marker
+
+console.log rtp1.packet
+console.log rtp2.packet
View
@@ -1,9 +1,14 @@
Buffer = require('buffer').Buffer
Number::toUnsigned = ->
- return ((this >>> 1) * 2 + (this & 1))
+ return ((@ >>> 1) * 2 + (@ & 1))
RTP_HEADER_SIZE = 12
+MARKER_BIT = 0x80
+TYPE_MASK = 0x7F
+
+isSet = (where, mask) ->
+ return (mask is (where & mask))
class RtpPacket
constructor: (bufPayload, fullPacket) ->
@@ -32,7 +37,7 @@ class RtpPacket
//EL = 0; // header extension length. not supported yet (16 bits)
###
- fullPacket = false if `full === undefined || full === null`
+ fullPacket = false if `fullPacket === undefined || fullPacket === null`
if fullPacket
@_bufpkt = bufPayload
@@ -54,11 +59,18 @@ class RtpPacket
@_bufpkt[11] = 1
bufPayload.copy @_bufpkt, 12, 0 # append payload data
-RtpPacket::__defineGetter__ 'type', -> return (@_bufpkt[1] & 0x7F)
+RtpPacket::__defineGetter__ 'marker', -> isSet @_bufpkt[1], MARKER_BIT
+RtpPacket::__defineSetter__ 'marker', (set) ->
+ if set
+ @_bufpkt[1] |= MARKER_BIT
+ else
+ @_bufpkt[1] &= ~MARKER_BIT
+
+RtpPacket::__defineGetter__ 'type', -> return (@_bufpkt[1] & TYPE_MASK)
RtpPacket::__defineSetter__ 'type', (val) ->
val = val.toUnsigned()
if val <= 127
- @_bufpkt[1] -= (@_bufpkt[1] & 0x7F)
+ @_bufpkt[1] -= (@_bufpkt[1] & TYPE_MASK)
@_bufpkt[1] |= val
RtpPacket::__defineGetter__ 'seq', -> return (@_bufpkt[2] << 8 | @_bufpkt[3])
@@ -79,7 +91,7 @@ RtpPacket::__defineSetter__ 'time', (val) ->
RtpPacket::__defineGetter__ 'source', -> return (@_bufpkt[8] << 24 | @_bufpkt[9] << 16 | @_bufpkt[10] << 8 | @_bufpkt[11])
RtpPacket::__defineSetter__ 'source', (val) ->
- val = val.toUnsigned();
+ val = val.toUnsigned()
if val <= 4294967295
@_bufpkt[8] = (val >>> 24)
@_bufpkt[9] = (val >>> 16 & 0xFF)

0 comments on commit 9d7b1d6

Please sign in to comment.