Esempio n. 1
0
def update_children_timing(element, timebase, delay_int):

    # if the element has a child
    if hasattr(element, 'orderedContent'):

        children = element.orderedContent()

        for child in children:

            if hasattr(child.value, 'end') and child.value.end != None:

                if timebase == 'clock':
                    delay = LimitedClockTimingType(
                        timedelta(seconds=delay_int))
                    child.value.end = LimitedClockTimingType(
                        child.value.end.timedelta + delay.timedelta)
                elif timebase == 'media':
                    delay = FullClockTimingType(timedelta(seconds=delay_int))
                    child.value.end = FullClockTimingType(
                        child.value.end.timedelta + delay.timedelta)

            if hasattr(child.value, 'begin') and child.value.begin != None:

                if timebase == 'clock':
                    delay = LimitedClockTimingType(
                        timedelta(seconds=delay_int))
                    child.value.begin = LimitedClockTimingType(
                        child.value.begin.timedelta + delay.timedelta)
                elif timebase == 'media':
                    delay = FullClockTimingType(timedelta(seconds=delay_int))
                    child.value.begin = FullClockTimingType(
                        child.value.begin.timedelta + delay.timedelta)

            else:
                update_children_timing(child.value, timebase, delay_int)
Esempio n. 2
0
def update_body_timing(body, timebase, delay_int):

    if hasattr(body, 'begin'):
        assert body.begin == None, "The body already has a begin time"

    # we always update the begin attribute, regardless of the presence of a begin or end attribute
    if timebase == 'clock':
        delay = LimitedClockTimingType(timedelta(seconds=delay_int))
        body.begin = LimitedClockTimingType(delay.timedelta)

    elif timebase == 'media':
        delay = FullClockTimingType(timedelta(seconds=delay_int))
        body.begin = FullClockTimingType(delay.timedelta)

    # if the body has an end attribute, we add to it the value of the delay
    if hasattr(body, 'end') and body.end != None:

        if timebase == 'clock':
            delay = LimitedClockTimingType(timedelta(seconds=delay_int))
            body.end = LimitedClockTimingType(body.end.timedelta +
                                              delay.timedelta)

        elif timebase == 'media':
            delay = FullClockTimingType(timedelta(seconds=delay_int))
            body.end = FullClockTimingType(body.end.timedelta +
                                           delay.timedelta)
def then_delta_should_be_correct(delay_offset, test_context):

    delay_timedelta = LimitedClockTimingType(delay_offset).timedelta
    avail_timedelta = LimitedClockTimingType(
        test_context['doc'].avail_time).timedelta
    emission_timedelta = LimitedClockTimingType(
        test_context['doc'].emission).timedelta

    assert emission_timedelta - avail_timedelta >= delay_timedelta
Esempio n. 4
0
def timestr_to_timedelta(time_str, time_base):
    if time_base == 'clock':
        return LimitedClockTimingType(time_str).timedelta
    elif time_base == 'media':
        return FullClockTimingType(time_str).timedelta
    elif time_base == 'smpte':
        raise NotImplementedError('SMPTE needs implementation')
    def process_document(self, document):

        activation_time = self._reference_clock.get_time() + timedelta(seconds=1)

        if self._input_blocks:
            try:
                lines = self._input_blocks.next()
            except StopIteration:
                raise EndOfData(END_OF_DATA)
        else:
            lines = [LimitedClockTimingType(activation_time)]

        document = self._document_sequence.new_document()

        # Add default style
        document.binding.head.styling = styling(
            style_type(
                id='defaultStyle1',
                backgroundColor="rgb(0, 0, 0)",
                color="rgb(255, 255, 255)",
                linePadding="0.5c",
                fontFamily="sansSerif"
            )
        )
        document.binding.head.layout = layout(
            region_type(
                id='bottomRegion',
                origin='14.375% 60%',
                extent='71.25% 24%',
                displayAlign='after',
                writingMode='lrtb',
                overflow="visible"
            )
        )
        document.add_div(
            self._create_fragment(
                lines,
                'defaultStyle1'
            ),
        )

        document.set_dur(LimitedClockTimingType(timedelta(seconds=1)))
        document.set_begin(LimitedClockTimingType(activation_time))

        document.validate()

        self._carriage_impl.emit_document(document)
def given_buffer_delay(delay_offset, test_context, gen_document, temp_dir):

    gen_document.availability_time = LimitedClockTimingType(
        '00:00:00.0').timedelta

    # the first delay node applies no delay
    carriage_delay1 = FilesystemProducerImpl(os.path.join(temp_dir, 'initial'))
    delay_float1 = LimitedClockTimingType(
        '00:00:00.0').timedelta.total_seconds()

    buffer_delay_node1 = BufferDelayNode(node_id='simple-delay-node',
                                         producer_carriage=None,
                                         fixed_delay=delay_float1)

    ProducerNodeCarriageAdapter(producer_node=buffer_delay_node1,
                                producer_carriage=carriage_delay1)

    buffer_delay_node1.process_document(
        document=gen_document.get_xml(),
        time_base=gen_document.time_base,
        availability_time=gen_document.availability_time,
        sequence_identifier=gen_document.sequence_identifier,
        sequence_number=gen_document.sequence_number)

    # the second delay node applies a delay of delay_offset
    carriage_delay2 = FilesystemProducerImpl(os.path.join(temp_dir, 'buffer'))
    delay_float2 = LimitedClockTimingType(
        delay_offset).timedelta.total_seconds()

    buffer_delay_node2 = BufferDelayNode(node_id='simple-delay-node',
                                         producer_carriage=None,
                                         fixed_delay=delay_float2)

    ProducerNodeCarriageAdapter(producer_node=buffer_delay_node2,
                                producer_carriage=carriage_delay2)

    buffer_delay_node2.process_document(
        document=gen_document.get_xml(),
        time_base=gen_document.time_base,
        availability_time=gen_document.availability_time,
        sequence_identifier=gen_document.sequence_identifier,
        sequence_number=gen_document.sequence_number)
    test_context['doc'] = gen_document
Esempio n. 7
0
def when_retiming_delay(delay, test_context, gen_document):

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'
    carriage = MagicMock(spec=IProducerCarriage)
    carriage.expects.return_value = EBUTT3Document

    delay_float = LimitedClockTimingType(delay).timedelta.total_seconds()

    delay_node = RetimingDelayNode(
        node_id='simple-delay-node',
        producer_carriage=carriage,
        fixed_delay=delay_float,
        document_sequence='delayed_sequence',
    )
    delay_node.process_document(gen_document)
    # As long as you operate on a document produced by the given statement you do not have to do this step unless
    # you wanted to be compatible with some pre-existing implemented when statements expecting the
    # document in the test_context fixture.
    test_context['doc'] = gen_document
Esempio n. 8
0
def then_updated_span2_computed_end_time(test_context, updated_span2_end):
    if updated_span2_end != '':
        assert test_context['doc'].binding.body.div[0].p[0].span[1].computed_end_time == LimitedClockTimingType(updated_span2_end).timedelta
    else:
        assert test_context['doc'].binding.body.div[0].p[0].span[1].computed_end_time is None
Esempio n. 9
0
def then_updated_p_computed_begin_time(test_context, updated_p_begin):
    if updated_p_begin != '':
        assert test_context['doc'].binding.body.div[0].p[0].computed_begin_time == LimitedClockTimingType(updated_p_begin).timedelta
    else:
        assert test_context['doc'].binding.body.div[0].p[0].computed_begin_time is None
Esempio n. 10
0
def then_availability_time(delayed_avail_time, test_context):
    delayed_avail_time_float = LimitedClockTimingType(delayed_avail_time).timedelta
    assert test_context['doc'].availability_time == delayed_avail_time_float
Esempio n. 11
0
 def _get_timing_type(self, value):
     if self.reference_clock.time_base == 'clock':
         return LimitedClockTimingType(value)
 def _get_timing_type(self, value):
     return LimitedClockTimingType(value)