def __init__(self, pagereader):
        """pagereader is a PageReader object"""

        self.__pagereader__ = pagereader
        self.__page__ = Page(packet_continuation=0,
                             stream_beginning=0,
                             stream_end=0,
                             granule_position=0,
                             bitstream_serial_number=0,
                             sequence_number=0,
                             segments=[])
        self.__current_segment__ = 1
def packets_to_pages(packets, bitstream_serial_number,
                     starting_sequence_number=0):
    """given an iterable of packet data strings,
    yields a Page object per Ogg page necessary to hold those packets

    packet_continuation is filled in as needed
    stream_beginning and stream_end are False
    granule_position is 0
    sequence_number increments starting from "starting_sequence_number"
    """

    from audiotools._ogg import Page

    page = Page(
        packet_continuation=False,
        stream_beginning=False,
        stream_end=False,
        granule_position=0,
        bitstream_serial_number=bitstream_serial_number,
        sequence_number=starting_sequence_number,
        segments=[])

    for packet in packets:
        for (i, segment) in enumerate(packet_to_segments(packet)):
            if page.full():
                yield page
                starting_sequence_number += 1
                page = Page(
                    packet_continuation=(i != 0),
                    stream_beginning=False,
                    stream_end=False,
                    granule_position=0,
                    bitstream_serial_number=bitstream_serial_number,
                    sequence_number=starting_sequence_number,
                    segments=[])

            page.append(segment)

    yield page
示例#3
0
def packet_to_pages(packet, bitstream_serial_number,
                    starting_sequence_number=0):
    """given a string of packet data,
    yields a Page object per Ogg page necessary to hold that packet

    packet_continuation is filled in as needed
    stream_beginning and stream_end are False
    granule_position is 0
    sequence_number increments starting from "starting_sequence_number"
    """

    from audiotools._ogg import Page

    page = Page(
        packet_continuation=False,
        stream_beginning=False,
        stream_end=False,
        granule_position=0,
        bitstream_serial_number=bitstream_serial_number,
        sequence_number=starting_sequence_number,
        segments=[])

    for segment in packet_to_segments(packet):
        if (page.full()):
            yield page
            starting_sequence_number += 1
            page = Page(
                packet_continuation=True,
                stream_beginning=False,
                stream_end=False,
                granule_position=0,
                bitstream_serial_number=bitstream_serial_number,
                sequence_number=starting_sequence_number,
                segments=[])

        page.append(segment)

    yield page