Пример #1
0
    def test_padding_and_aux_data_default_data(self, parse_code):
        # No data given (default (empty) data should be assumed)
        stream = Stream(
            sequences=[
                Sequence(
                    data_units=[DataUnit(parse_info=ParseInfo(parse_code=parse_code))]
                )
            ]
        )

        assert autofill_parse_offsets(stream) == ([], [(0, 0)])

        parse_info = stream["sequences"][0]["data_units"][0]["parse_info"]
        assert parse_info["next_parse_offset"] == 13
        assert parse_info["previous_parse_offset"] == 0
Пример #2
0
    def test_padding_and_aux_data(self, parse_code):
        stream = Stream(
            sequences=[
                Sequence(
                    data_units=[
                        # Next parse offset not given (should be treated as auto)
                        DataUnit(parse_info=ParseInfo(parse_code=parse_code)),
                        # Next parse offset is explicitly AUTO
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=parse_code,
                                next_parse_offset=AUTO,
                            ),
                        ),
                        # Next parse offset is given (should not be modified)
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=parse_code,
                                next_parse_offset=100,
                            ),
                        ),
                    ]
                )
            ]
        )
        for seq in stream["sequences"]:
            for data_unit in seq["data_units"]:
                if parse_code == tables.ParseCodes.padding_data:
                    data_unit["padding"] = Padding(bytes=b"1234")
                elif parse_code == tables.ParseCodes.auxiliary_data:
                    data_unit["auxiliary_data"] = AuxiliaryData(bytes=b"1234")

        assert autofill_parse_offsets(stream) == ([], [(0, 0), (0, 1), (0, 2)])

        next_parse_offsets = [
            data_unit["parse_info"]["next_parse_offset"]
            for seq in stream["sequences"]
            for data_unit in seq["data_units"]
        ]
        assert next_parse_offsets == [13 + 4, 13 + 4, 100]

        previous_parse_offsets = [
            data_unit["parse_info"]["previous_parse_offset"]
            for seq in stream["sequences"]
            for data_unit in seq["data_units"]
        ]
        assert previous_parse_offsets == [0, 0, 0]
Пример #3
0
    def test_values_to_be_set_later_are_set_to_zero(self, parse_code, explicit_auto):
        stream = Stream(
            sequences=[
                Sequence(
                    data_units=[
                        # An automatically set data unit
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=parse_code,
                            )
                        ),
                        # One which is explicitly set (and should not be overridden)
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=parse_code,
                                next_parse_offset=100,
                                previous_parse_offset=200,
                            )
                        ),
                    ]
                )
            ]
        )
        if explicit_auto:
            parse_info = stream["sequences"][0]["data_units"][0]["parse_info"]
            parse_info["next_parse_offset"] = AUTO
            parse_info["previous_parse_offset"] = AUTO

        assert autofill_parse_offsets(stream) == ([(0, 0)], [(0, 0)])

        parse_info_0 = stream["sequences"][0]["data_units"][0]["parse_info"]
        assert parse_info_0["next_parse_offset"] == 0
        assert parse_info_0["previous_parse_offset"] == 0

        parse_info_1 = stream["sequences"][0]["data_units"][1]["parse_info"]
        assert parse_info_1["next_parse_offset"] == 100
        assert parse_info_1["previous_parse_offset"] == 200
Пример #4
0
    def test_finalizer_works(self):
        f = BytesIO()
        w = BitstreamWriter(f)

        # Sequence with every data unit type and fully automatic numbers
        stream = Stream(
            sequences=[
                Sequence(
                    data_units=[
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.sequence_header
                            ),
                            sequence_header=SequenceHeader(
                                parse_parameters=ParseParameters(major_version=3),
                                video_parameters=SourceParameters(
                                    # Tiny custom frame-size used to reduce test suite
                                    # runtime
                                    frame_size=FrameSize(
                                        custom_dimensions_flag=True,
                                        frame_width=4,
                                        frame_height=4,
                                    )
                                ),
                            ),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.high_quality_picture
                            ),
                            picture_parse=PictureParse(
                                picture_header=PictureHeader(picture_number=0)
                            ),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.low_delay_picture
                            ),
                            picture_parse=PictureParse(
                                picture_header=PictureHeader(picture_number=0)
                            ),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.high_quality_picture_fragment
                            ),
                            fragment_parse=FragmentParse(
                                fragment_header=FragmentHeader(picture_number=0)
                            ),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.high_quality_picture_fragment
                            ),
                            fragment_parse=FragmentParse(
                                fragment_header=FragmentHeader(picture_number=0)
                            ),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.padding_data
                            ),
                            padding=Padding(bytes=b"123"),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.auxiliary_data
                            ),
                            auxiliary_data=AuxiliaryData(bytes=b"123"),
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.end_of_sequence
                            ),
                        ),
                    ]
                )
            ]
        )

        (
            next_parse_offsets_to_autofill,
            previous_parse_offsets_to_autofill,
        ) = autofill_parse_offsets(stream)

        with Serialiser(w, stream, vc2_default_values_with_auto) as serdes:
            vc2.parse_stream(serdes, State())
        w.flush()

        offset_before = w.tell()
        autofill_parse_offsets_finalize(
            w,
            serdes.context,
            next_parse_offsets_to_autofill,
            previous_parse_offsets_to_autofill,
        )
        assert w.tell() == offset_before

        f.seek(0)
        r = BitstreamReader(f)
        with Deserialiser(r) as serdes:
            vc2.parse_stream(serdes, State())

        parse_infos = [
            data_unit["parse_info"]
            for sequence in serdes.context["sequences"]
            for data_unit in sequence["data_units"]
        ]

        # Check for start/end offsets being zero
        assert parse_infos[0]["previous_parse_offset"] == 0
        assert parse_infos[-1]["next_parse_offset"] == 0

        # Check for consistency and plusibility of offsets
        for pi1, pi2 in zip(parse_infos, parse_infos[1:]):
            assert pi1["next_parse_offset"] > 13
            assert pi2["previous_parse_offset"] > 13

            assert pi1["next_parse_offset"] == pi2["previous_parse_offset"]
Пример #5
0
 def test_doesnt_crash_on_empty_stream(self, stream):
     stream_orig = deepcopy(stream)
     assert autofill_parse_offsets(stream) == ([], [])
     assert stream == stream_orig
Пример #6
0
    def test_works_on_multiple_sequences(self):
        f = BytesIO()
        w = BitstreamWriter(f)

        # Sequence with every data unit type and fully automatic numbers
        stream = Stream(
            sequences=[
                Sequence(
                    data_units=[
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.padding_data
                            )
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.padding_data
                            )
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.end_of_sequence
                            )
                        ),
                    ]
                ),
                Sequence(
                    data_units=[
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.padding_data
                            )
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.padding_data
                            )
                        ),
                        DataUnit(
                            parse_info=ParseInfo(
                                parse_code=tables.ParseCodes.end_of_sequence
                            )
                        ),
                    ]
                ),
            ]
        )

        (
            next_parse_offsets_to_autofill,
            previous_parse_offsets_to_autofill,
        ) = autofill_parse_offsets(stream)

        print(stream)
        with Serialiser(w, stream, vc2_default_values_with_auto) as serdes:
            vc2.parse_stream(serdes, State())
        w.flush()

        autofill_parse_offsets_finalize(
            w,
            serdes.context,
            next_parse_offsets_to_autofill,
            previous_parse_offsets_to_autofill,
        )

        f.seek(0)
        r = BitstreamReader(f)
        with Deserialiser(r) as serdes:
            vc2.parse_stream(serdes, State())

        parse_infos = [
            [data_unit["parse_info"] for data_unit in sequence["data_units"]]
            for sequence in serdes.context["sequences"]
        ]

        # Check for start/end offsets being zero
        for sequence_pis in parse_infos:
            assert sequence_pis[0]["previous_parse_offset"] == 0
            assert sequence_pis[-1]["next_parse_offset"] == 0

            # Check for offset correctness
            for pi1, pi2 in zip(sequence_pis, sequence_pis[1:]):
                assert pi1["next_parse_offset"] == 13
                assert pi2["previous_parse_offset"] == 13