Esempio n. 1
0
    def test_remove_video_frame(self):
        """
        Video jitter buffer.
        """
        jbuffer = JitterBuffer(capacity=128)

        packet = RtpPacket(sequence_number=0, timestamp=1234)
        packet._data = b"0000"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=1, timestamp=1234)
        packet._data = b"0001"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=2, timestamp=1234)
        packet._data = b"0002"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=3, timestamp=1235)
        packet._data = b"0003"
        frame = jbuffer.add(packet)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.data, b"000000010002")
        self.assertEqual(frame.timestamp, 1234)
Esempio n. 2
0
    def test_add_ordered(self):
        jbuffer = JitterBuffer(capacity=4)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=0, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [0, None, None, None])
        self.assertEqual(jbuffer._origin, 0)
        self.assertFalse(pli_flag)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=1, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [0, 1, None, None])
        self.assertEqual(jbuffer._origin, 0)
        self.assertFalse(pli_flag)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=2, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [0, 1, 2, None])
        self.assertEqual(jbuffer._origin, 0)
        self.assertFalse(pli_flag)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=3, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [0, 1, 2, 3])
        self.assertEqual(jbuffer._origin, 0)
        self.assertFalse(pli_flag)
Esempio n. 3
0
    def test_peek(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        jbuffer.add(b'0002', sequence_number=2, timestamp=1234)
        jbuffer.add(b'0004', sequence_number=4, timestamp=1234)

        frame = jbuffer.peek(0)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.sequence_number, 1)
        self.assertEqual(repr(frame), 'JitterFrame(seq=1, ts=1234)')

        frame = jbuffer.peek(1)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.sequence_number, 2)

        frame = jbuffer.peek(2)
        self.assertIsNone(frame)

        frame = jbuffer.peek(3)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.sequence_number, 4)

        with self.assertRaises(IndexError) as cm:
            jbuffer.peek(4)
        self.assertEqual(str(cm.exception), 'Cannot peek at offset 4, capacity is 4')
Esempio n. 4
0
    def test_add_seq_too_high_discard_one(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0002', sequence_number=2, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0003', sequence_number=3, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0004', sequence_number=4, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0005', sequence_number=5, timestamp=1234)
        self.assertEqual(jbuffer._origin, 2)

        self.assertIsNotNone(jbuffer._packets[0])
        self.assertEqual(jbuffer._packets[0].payload, b'0005')
        self.assertEqual(jbuffer._packets[0].sequence_number, 5)
        self.assertIsNotNone(jbuffer._packets[1])
        self.assertEqual(jbuffer._packets[1].payload, b'0002')
        self.assertEqual(jbuffer._packets[1].sequence_number, 2)
        self.assertIsNotNone(jbuffer._packets[2])
        self.assertEqual(jbuffer._packets[2].payload, b'0003')
        self.assertEqual(jbuffer._packets[2].sequence_number, 3)
        self.assertIsNotNone(jbuffer._packets[3])
        self.assertEqual(jbuffer._packets[3].payload, b'0004')
        self.assertEqual(jbuffer._packets[3].sequence_number, 4)
Esempio n. 5
0
    def test_remove(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        jbuffer.add(b'0002', sequence_number=2, timestamp=1234)
        jbuffer.add(b'0003', sequence_number=3, timestamp=1234)
        jbuffer.add(b'0004', sequence_number=4, timestamp=1234)

        # remove 1 frame
        frames = jbuffer.remove(1)
        self.assertEqual(len(frames), 1)
        self.assertEqual(frames[0].sequence_number, 1)

        # check buffer
        self.assertEqual(jbuffer._head, 1)
        self.assertEqual(jbuffer._origin, 2)
        self.assertIsNone(jbuffer._frames[0])
        self.assertIsNotNone(jbuffer._frames[1])
        self.assertIsNotNone(jbuffer._frames[2])
        self.assertIsNotNone(jbuffer._frames[3])

        # remove 2 frames
        frames = jbuffer.remove(2)
        self.assertEqual(len(frames), 2)
        self.assertEqual(frames[0].sequence_number, 2)
        self.assertEqual(frames[1].sequence_number, 3)

        # check buffer
        self.assertEqual(jbuffer._head, 3)
        self.assertEqual(jbuffer._origin, 4)
        self.assertIsNone(jbuffer._frames[0])
        self.assertIsNone(jbuffer._frames[1])
        self.assertIsNone(jbuffer._frames[2])
        self.assertIsNotNone(jbuffer._frames[3])
Esempio n. 6
0
    def test_add_seq_too_high_reset(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(RtpPacket(sequence_number=0, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)
        self.assertPackets(jbuffer, [0, None, None, None])

        jbuffer.add(RtpPacket(sequence_number=3000, timestamp=1234))
        self.assertEqual(jbuffer._origin, 3000)
        self.assertPackets(jbuffer, [3000, None, None, None])
Esempio n. 7
0
    def test_add_seq_too_low_reset(self):
        jbuffer = JitterBuffer(capacity=4)

        frame = jbuffer.add(RtpPacket(sequence_number=2000, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [2000, None, None, None])
        self.assertEqual(jbuffer._origin, 2000)

        frame = jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, 1, None, None])
        self.assertEqual(jbuffer._origin, 1)
Esempio n. 8
0
    def test_smart_remove(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(RtpPacket(sequence_number=0, timestamp=1234))
        jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
        jbuffer.add(RtpPacket(sequence_number=3, timestamp=1235))
        self.assertEqual(jbuffer._origin, 0)
        self.assertPackets(jbuffer, [0, 1, None, 3])

        # remove 1 packet
        jbuffer.smart_remove(1)
        self.assertEqual(jbuffer._origin, 3)
        self.assertPackets(jbuffer, [None, None, None, 3])
Esempio n. 9
0
    def test_add_seq_too_low_reset(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'2000', sequence_number=2000, timestamp=1234)
        self.assertEqual(jbuffer._origin, 2000)
        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)

        self.assertIsNotNone(jbuffer._packets[0])
        self.assertEqual(jbuffer._packets[0].payload, b'0001')
        self.assertEqual(jbuffer._packets[0].sequence_number, 1)
        self.assertIsNone(jbuffer._packets[1])
        self.assertIsNone(jbuffer._packets[2])
        self.assertIsNone(jbuffer._packets[3])
Esempio n. 10
0
    def test_add_seq_too_high_reset(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'3002', sequence_number=3002, timestamp=1234)
        self.assertEqual(jbuffer._origin, 3002)

        self.assertIsNotNone(jbuffer._packets[0])
        self.assertEqual(jbuffer._packets[0].payload, b'3002')
        self.assertEqual(jbuffer._packets[0].sequence_number, 3002)
        self.assertIsNone(jbuffer._packets[1])
        self.assertIsNone(jbuffer._packets[2])
        self.assertIsNone(jbuffer._packets[3])
Esempio n. 11
0
    def test_add_seq_too_high_drop(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0005', sequence_number=5, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)

        self.assertIsNotNone(jbuffer._frames[0])
        self.assertEqual(jbuffer._frames[0].payload, b'0001')
        self.assertEqual(jbuffer._frames[0].sequence_number, 1)
        self.assertIsNone(jbuffer._frames[1])
        self.assertIsNone(jbuffer._frames[2])
        self.assertIsNone(jbuffer._frames[3])
Esempio n. 12
0
    def test_add_seq_too_low_drop(self):
        jbuffer = JitterBuffer(capacity=4)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=2, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, None, 2, None])
        self.assertEqual(jbuffer._origin, 2)
        self.assertFalse(pli_flag)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=1, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, None, 2, None])
        self.assertEqual(jbuffer._origin, 2)
        self.assertFalse(pli_flag)
Esempio n. 13
0
    def test_add_unordered(self):
        jbuffer = JitterBuffer(capacity=4)

        frame = jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, 1, None, None])
        self.assertEqual(jbuffer._origin, 1)

        frame = jbuffer.add(RtpPacket(sequence_number=3, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, 1, None, 3])
        self.assertEqual(jbuffer._origin, 1)

        frame = jbuffer.add(RtpPacket(sequence_number=2, timestamp=1234))
        self.assertIsNone(frame)
        self.assertPackets(jbuffer, [None, 1, 2, 3])
        self.assertEqual(jbuffer._origin, 1)
Esempio n. 14
0
    def test_add_seq_too_high_discard_four(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(RtpPacket(sequence_number=0, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=2, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=3, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=7, timestamp=1234))
        self.assertEqual(jbuffer._origin, 4)

        self.assertPackets(jbuffer, [None, None, None, 7])
Esempio n. 15
0
    def test_add_seq_too_high_discard_one(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(RtpPacket(sequence_number=0, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=2, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=3, timestamp=1234))
        self.assertEqual(jbuffer._origin, 0)

        jbuffer.add(RtpPacket(sequence_number=4, timestamp=1234))
        self.assertEqual(jbuffer._origin, 1)

        self.assertPackets(jbuffer, [4, 1, 2, 3])
Esempio n. 16
0
    def test_add_seq_too_high_discard_more(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0002', sequence_number=2, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0003', sequence_number=3, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0004', sequence_number=4, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0009', sequence_number=9, timestamp=1234)
        self.assertEqual(jbuffer._origin, 9)

        self.assertIsNotNone(jbuffer._frames[0])
        self.assertEqual(jbuffer._frames[0].payload, b'0009')
        self.assertEqual(jbuffer._frames[0].sequence_number, 9)
        self.assertIsNone(jbuffer._frames[1])
        self.assertIsNone(jbuffer._frames[2])
        self.assertIsNone(jbuffer._frames[3])
Esempio n. 17
0
    def test_pli_flag(self):
        """
        Video jitter buffer.
        """
        jbuffer = JitterBuffer(capacity=128, is_video=True)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=2000, timestamp=1234))
        self.assertIsNone(frame)
        self.assertEqual(jbuffer._origin, 2000)
        self.assertFalse(pli_flag)

        # test_add_seq_too_low_reset for video (capacity >= 128)
        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=1, timestamp=1234))
        self.assertIsNone(frame)
        self.assertEqual(jbuffer._origin, 1)
        self.assertTrue(pli_flag)

        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=128, timestamp=1235))
        self.assertIsNone(frame)
        self.assertEqual(jbuffer._origin, 1)
        self.assertFalse(pli_flag)

        # test_add_seq_too_high_discard_one for video (capacity >= 128)
        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=129, timestamp=1235))
        self.assertIsNone(frame)
        self.assertEqual(jbuffer._origin, 128)
        self.assertTrue(pli_flag)

        # test_add_seq_too_high_reset for video (capacity >= 128)
        pli_flag, frame = jbuffer.add(
            RtpPacket(sequence_number=2000, timestamp=2345))
        self.assertIsNone(frame)
        self.assertEqual(jbuffer._origin, 2000)
        self.assertTrue(pli_flag)
Esempio n. 18
0
    def test_remove_frame(self):
        jbuffer = JitterBuffer(capacity=4)

        packet = RtpPacket(sequence_number=0, timestamp=1234)
        packet._data = b'0000'
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=1, timestamp=1234)
        packet._data = b'0001'
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=2, timestamp=1234)
        packet._data = b'0002'
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=3, timestamp=1235)
        packet._data = b'0003'
        frame = jbuffer.add(packet)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.data, b'000000010002')
        self.assertEqual(frame.timestamp, 1234)
Esempio n. 19
0
    def test_add_ordered(self):
        jbuffer = JitterBuffer(capacity=4)

        jbuffer.add(b'0001', sequence_number=1, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0002', sequence_number=2, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0003', sequence_number=3, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)
        jbuffer.add(b'0004', sequence_number=4, timestamp=1234)
        self.assertEqual(jbuffer._origin, 1)

        self.assertIsNotNone(jbuffer._frames[0])
        self.assertEqual(jbuffer._frames[0].payload, b'0001')
        self.assertEqual(jbuffer._frames[0].sequence_number, 1)
        self.assertIsNotNone(jbuffer._frames[1])
        self.assertEqual(jbuffer._frames[1].payload, b'0002')
        self.assertEqual(jbuffer._frames[1].sequence_number, 2)
        self.assertIsNotNone(jbuffer._frames[2])
        self.assertEqual(jbuffer._frames[2].payload, b'0003')
        self.assertEqual(jbuffer._frames[2].sequence_number, 3)
        self.assertIsNotNone(jbuffer._frames[3])
        self.assertEqual(jbuffer._frames[3].payload, b'0004')
        self.assertEqual(jbuffer._frames[3].sequence_number, 4)
Esempio n. 20
0
    def test_remove_audio_frame(self):
        """
        Audio jitter buffer.
        """
        jbuffer = JitterBuffer(capacity=16, prefetch=4)

        packet = RtpPacket(sequence_number=0, timestamp=1234)
        packet._data = b"0000"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=1, timestamp=1235)
        packet._data = b"0001"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=2, timestamp=1236)
        packet._data = b"0002"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=3, timestamp=1237)
        packet._data = b"0003"
        frame = jbuffer.add(packet)
        self.assertIsNone(frame)

        packet = RtpPacket(sequence_number=4, timestamp=1238)
        packet._data = b"0003"
        frame = jbuffer.add(packet)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.data, b"0000")
        self.assertEqual(frame.timestamp, 1234)

        packet = RtpPacket(sequence_number=5, timestamp=1239)
        packet._data = b"0004"
        frame = jbuffer.add(packet)
        self.assertIsNotNone(frame)
        self.assertEqual(frame.data, b"0001")
        self.assertEqual(frame.timestamp, 1235)