Exemplo n.º 1
0
    def test_packetize_one_small(self):
        packages = [bytes([0xFF, 0xFF])]
        packetize_packages = H264Encoder._packetize(packages)
        self.assertListEqual(packages, packetize_packages)

        packages = [bytes([0xFF]) * 1300]
        packetize_packages = H264Encoder._packetize(packages)
        self.assertListEqual(packages, packetize_packages)
Exemplo n.º 2
0
    def test_split_bitstream(self):
        packages = list(H264Encoder._split_bitstream(b'\00\00\01\ff\00\00\01\ff'))
        self.assertEqual(len(packages), 2)

        packages = list(H264Encoder._split_bitstream(b'\00\00\00\01\ff'))
        self.assertEqual(len(packages), 1)

        packages = list(H264Encoder._split_bitstream(b'\00\00\00\00\00\00\01\ff\00\00\00\00\00'))
        self.assertEqual(len(packages), 1)
Exemplo n.º 3
0
    def test_packetize_multiple_small(self):
        packages = [bytes([0x01, 0xFF])] * 9
        packetize_packages = H264Encoder._packetize(packages)
        self.assertEqual(len(packetize_packages), 1)
        self.assertEqual(packetize_packages[0][0] & 0x1F, 24)

        packages = [bytes([0x01, 0xFF])] * 10
        packetize_packages = H264Encoder._packetize(packages)
        self.assertEqual(len(packetize_packages), 2)
        self.assertEqual(packetize_packages[0][0] & 0x1F, 24)
        self.assertEqual(packetize_packages[1], packages[-1])
Exemplo n.º 4
0
    def test_split_bitstream(self):
        # No start code
        packages = list(H264Encoder._split_bitstream(b"\x00\x00\x00\x00"))
        self.assertEqual(packages, [])

        # 3-byte start code
        packages = list(
            H264Encoder._split_bitstream(b"\x00\x00\x01\xFF\x00\x00\x01\xFB")
        )
        self.assertEqual(packages, [b"\xFF", b"\xFB"])

        # 4-byte start code
        packages = list(
            H264Encoder._split_bitstream(b"\x00\x00\x00\x01\xFF\x00\x00\x00\x01\xFB")
        )
        self.assertEqual(packages, [b"\xFF", b"\xFB"])

        # Multiple bytes in a packet
        packages = list(
            H264Encoder._split_bitstream(
                b"\x00\x00\x00\x01\xFF\xAB\xCD\x00\x00\x00\x01\xFB"
            )
        )
        self.assertEqual(packages, [b"\xFF\xAB\xCD", b"\xFB"])

        # Skip leading 0s
        packages = list(H264Encoder._split_bitstream(b"\x00\x00\x00\x01\xFF"))
        self.assertEqual(packages, [b"\xFF"])

        # Both leading and trailing 0s
        packages = list(
            H264Encoder._split_bitstream(
                b"\x00\x00\x00\x00\x00\x00\x01\xFF\x00\x00\x00\x00\x00"
            )
        )
        self.assertEqual(packages, [b"\xFF\x00\x00\x00\x00\x00"])
Exemplo n.º 5
0
 def test_packetize_two_small(self):
     packages = [bytes([0x01, 0xFF]), bytes([0xFF, 0xFF])]
     packetize_packages = H264Encoder._packetize(packages)
     self.assertEqual(len(packetize_packages), 1)
     self.assertEqual(packetize_packages[0][0] & 0x1F, 24)
Exemplo n.º 6
0
 def test_packetize_one_big(self):
     packages = [bytes([0xFF, 0xFF] * 1000)]
     packetize_packages = H264Encoder._packetize(packages)
     self.assertEqual(len(packetize_packages), 2)
     self.assertEqual(packetize_packages[0][0] & 0x1F, 28)
     self.assertEqual(packetize_packages[1][0] & 0x1F, 28)