def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is a Simple Consumer example')

    consumer_impl = None

    consumer_impl = TwistedConsumerImpl()

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    simple_consumer = SimpleConsumer(
        node_id='simple-consumer',
        carriage_impl=consumer_impl,
        reference_clock=reference_clock
    )

    factory = UserInputServerFactory(
        url='ws://127.0.0.1:9001',
        consumer=TwistedConsumer(
            custom_consumer=consumer_impl
        )
    )
    factory.protocol = UserInputServerProtocol

    factory.listen()

    reactor.run()
Example #2
0
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is the EBU-TT-D encoder')

    manifest_path = args.manifest_path

    websocket_url = args.websocket_url
    websocket_channel = args.websocket_channel

    fs_reader = None

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl()
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = TwistedConsumerImpl()

    if args.output_format == 'xml':
        outbound_carriage = SimpleFolderExport(args.output_folder,
                                               'ebuttd-encode-{}.xml')
    else:
        raise Exception('Invalid output format: {}'.format(args.output_format))

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    media_time_zero = \
        args.media_time_zero == 'current' and reference_clock.get_time() \
        or bindings.ebuttdt.LimitedClockTimingType(str(args.media_time_zero)).timedelta

    ebuttd_converter = EBUTTDEncoder(node_id='simple-consumer',
                                     carriage_impl=consumer_impl,
                                     outbound_carriage_impl=outbound_carriage,
                                     reference_clock=reference_clock,
                                     segment_length=args.interval,
                                     media_time_zero=media_time_zero,
                                     segment_timer=start_timer,
                                     discard=args.discard)

    if manifest_path:
        fs_reader.resume_reading()
        # TODO: Do segmentation in filesystem mode. Especially bad is the tail usecase #209
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}
        factory = BroadcastClientFactory(
            url=websocket_url,
            channels=[websocket_channel],
            consumer=TwistedConsumer(custom_consumer=consumer_impl),
            **factory_args)
        factory.protocol = ClientNodeProtocol

        factory.connect()

        reactor.run()
def main():
    create_loggers()

    parsed_args = parser.parse_args()

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    document_sequence = EBUTT3DocumentSequence(
        sequence_identifier='TestSequence1',
        lang='en-GB',
        reference_clock=reference_clock
    )

    if parsed_args.reference_clock:
        subtitle_tokens = None  # Instead of text we provide the availability time as content.
    else:
        # Let's read our example conversation
        full_text = get_example_data('simple_producer.txt')
        # This makes the source cycle infinitely.
        subtitle_tokens = cycle(tokenize_english_document(full_text))

    factory = wsFactory(u"ws://127.0.0.1:9000")

    factory.protocol = StreamingServerProtocol

    factory.listen()

    # This object is used as flexible binding to the carriage mechanism and twisted integrated as dependency injection
    prod_impl = TwistedProducerImpl()

    simple_producer = SimpleProducer(
        node_id='simple-producer',
        carriage_impl=prod_impl,
        document_sequence=document_sequence,
        input_blocks=subtitle_tokens
    )

    # We are using a pull producer because it is the looping_task timer that triggers the production from the websocket
    # level. Every time the factory gets a pull signal from the timer it tells the producer to generate data.
    TwistedPullProducer(
        consumer=factory,
        custom_producer=prod_impl
    )

    looping_task = task.LoopingCall(factory.pull)

    looping_task.start(2.0)

    reactor.run()
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is a Simple Consumer example')

    manifest_path = args.manifest_path
    websocket_url = args.websocket_url
    websocket_channel = args.websocket_channel
    consumer_impl = None
    fs_reader = None

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl()
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = TwistedConsumerImpl()

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    simple_consumer = SimpleConsumer(
        node_id='simple-consumer',
        carriage_impl=consumer_impl,
        reference_clock=reference_clock
    )

    if manifest_path:
        fs_reader.resume_reading()
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}
        factory = BroadcastClientFactory(
            url=websocket_url,
            channels=[websocket_channel],
            consumer=TwistedConsumer(
                custom_consumer=consumer_impl
            ),
            **factory_args
        )

        factory.protocol = ClientNodeProtocol

        factory.connect()

        reactor.run()
Example #5
0
def then_retiming_delay_node_rejects(gen_document, produced_sequence):
    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'
    carriage = MagicMock(spec=IProducerCarriage)
    carriage.expects.return_value = EBUTT3Document

    delay_float = 5.0

    delay_node = RetimingDelayNode(
        node_id='simple-delay-node',
        producer_carriage=carriage,
        fixed_delay=delay_float,
        document_sequence=produced_sequence
    )
    with pytest.raises(UnexpectedSequenceIdentifierError):
        delay_node.process_document(gen_document)
def main():
    args = parser.parse_args()
    create_loggers()

    do_export = False
    if args.folder_export:
        do_export = True

    sub_consumer_impl = TwistedConsumerImpl()
    sub_prod_impl = None
    if do_export:
        sub_prod_impl = FilesystemProducerImpl(args.folder_export)
    else:
        sub_prod_impl = TwistedProducerImpl()
    carriage_impl = ForwarderCarriageImpl(sub_consumer_impl, sub_prod_impl)

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    dist_node = DistributingNode(
        node_id='distributing-node',
        carriage_impl=carriage_impl,
        reference_clock=reference_clock
    )

    # This factory listens for incoming documents from the user input producer.
    user_input_server_factory = UserInputServerFactory(
        url='ws://127.0.0.1:9001',
        consumer=TwistedConsumer(
            custom_consumer=sub_consumer_impl
        )
    )
    user_input_server_factory.protocol = UserInputServerProtocol
    user_input_server_factory.listen()

    if not do_export:
        # This factory listens for any consumer to forward documents to.
        broadcast_factory = BroadcastServerFactory("ws://127.0.0.1:9000")
        broadcast_factory.protocol = StreamingServerProtocol
        broadcast_factory.listen()

        TwistedPullProducer(
            consumer=broadcast_factory,
            custom_producer=sub_prod_impl
        )

    reactor.run()
def main():
    args = parser.parse_args()
    create_loggers()

    do_export = False
    if args.folder_export:
        do_export = True

    sub_consumer_impl = WebsocketConsumerCarriage()
    sub_prod_impl = None
    if do_export:
        sub_prod_impl = FilesystemProducerImpl(args.folder_export)
    else:
        sub_prod_impl = WebsocketProducerCarriage()

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    dist_node = DistributingNode(
        node_id='distributing-node',
        producer_carriage=sub_prod_impl,
        consumer_carriage=sub_consumer_impl,
        reference_clock=reference_clock
    )

    # This factory listens for incoming documents from the user input producer.
    user_input_server_factory = UserInputServerFactory(
        url=args.websocket_url,
        consumer=TwistedConsumer(
            custom_consumer=sub_consumer_impl
        )
    )
    user_input_server_factory.protocol = UserInputServerProtocol
    user_input_server_factory.listen()

    if not do_export:
        # This factory listens for any consumer to forward documents to.
        broadcast_factory = BroadcastServerFactory("ws://127.0.0.1:9000")
        broadcast_factory.protocol = BroadcastServerProtocol
        broadcast_factory.listen()

        TwistedPushProducer(
            consumer=broadcast_factory,
            custom_producer=sub_prod_impl
        )

    reactor.run()
Example #8
0
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is a Simple Consumer example')

    manifest_path = args.manifest_path
    websocket_url = args.websocket_url
    consumer_impl = None
    fs_reader = None

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl(reference_clock)
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = WebsocketConsumerCarriage()

    simple_consumer = SimpleConsumer(node_id='simple-consumer',
                                     reference_clock=reference_clock)

    # Chaining converter
    ConsumerNodeCarriageAdapter(consumer_node=simple_consumer,
                                consumer_carriage=consumer_impl)

    if manifest_path:
        fs_reader.resume_reading()
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}

        twisted_consumer = TwistedWSConsumer(custom_consumer=consumer_impl)

        factory = BroadcastClientFactory(url=websocket_url,
                                         consumer=twisted_consumer,
                                         **factory_args)

        factory.protocol = BroadcastClientProtocol

        factory.connect()

        reactor.run()
Example #9
0
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is a Simple Consumer example')

    manifest_path = args.manifest_path
    websocket_url = args.websocket_url
    websocket_channel = args.websocket_channel
    consumer_impl = None
    fs_reader = None

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl()
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = TwistedConsumerImpl()

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    simple_consumer = SimpleConsumer(node_id='simple-consumer',
                                     carriage_impl=consumer_impl,
                                     reference_clock=reference_clock)

    if manifest_path:
        fs_reader.resume_reading()
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}
        factory = BroadcastClientFactory(
            url=websocket_url,
            channels=[websocket_channel],
            consumer=TwistedConsumer(custom_consumer=consumer_impl),
            **factory_args)

        factory.protocol = ClientNodeProtocol

        factory.connect()

        reactor.run()
Example #10
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
def main():
    create_loggers()

    parsed_args = parser.parse_args()

    do_export = False
    if parsed_args.folder_export:
        do_export = True

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    document_sequence = EBUTT3DocumentSequence(
        sequence_identifier='TestSequence1',
        lang='en-GB',
        reference_clock=reference_clock
    )

    if parsed_args.reference_clock:
        subtitle_tokens = None  # Instead of text we provide the availability time as content.
    else:
        # Let's read our example conversation
        full_text = get_example_data('simple_producer.txt')
        if do_export:
            subtitle_tokens = iter(tokenize_english_document(full_text))
        else:
            # This makes the source cycle infinitely.
            subtitle_tokens = cycle(tokenize_english_document(full_text))

    # This object is used as flexible binding to the carriage mechanism and twisted integrated as dependency injection
    prod_impl = None
    if do_export:
        prod_impl = FilesystemProducerImpl(parsed_args.folder_export)
    else:
        prod_impl = TwistedProducerImpl()

    simple_producer = SimpleProducer(
        node_id='simple-producer',
        carriage_impl=prod_impl,
        document_sequence=document_sequence,
        input_blocks=subtitle_tokens
    )

    if do_export:
        prod_impl.resume_producing()
    else:
        factory = wsFactory(u"ws://127.0.0.1:9000")

        factory.protocol = StreamingServerProtocol

        factory.listen()

        # We are using a pull producer because it is the looping_task timer that triggers the production from the websocket
        # level. Every time the factory gets a pull signal from the timer it tells the producer to generate data.
        TwistedPullProducer(
            consumer=factory,
            custom_producer=prod_impl
        )

        looping_task = task.LoopingCall(factory.pull)

        looping_task.start(2.0)

        reactor.run()
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is the EBU-TT-D encoder')

    manifest_path = args.manifest_path

    websocket_url = args.websocket_url
    websocket_channel = args.websocket_channel

    fs_reader = None

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl()
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = TwistedConsumerImpl()

    if args.output_format == 'xml':
        outbound_carriage = SimpleFolderExport(args.output_folder, 'ebuttd-encode-{}.xml')
    else:
        raise Exception('Invalid output format: {}'.format(args.output_format))

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    media_time_zero = \
        args.media_time_zero == 'current' and reference_clock.get_time() \
        or bindings.ebuttdt.LimitedClockTimingType(str(args.media_time_zero)).timedelta

    ebuttd_converter = EBUTTDEncoder(
        node_id='simple-consumer',
        carriage_impl=consumer_impl,
        outbound_carriage_impl=outbound_carriage,
        reference_clock=reference_clock,
        segment_length=args.interval,
        media_time_zero=media_time_zero,
        segment_timer=start_timer,
        discard=args.discard
    )

    if manifest_path:
        fs_reader.resume_reading()
        # TODO: Do segmentation in filesystem mode. Especially bad is the tail usecase #209
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}
        factory = BroadcastClientFactory(
            url=websocket_url,
            channels=[websocket_channel],
            consumer=TwistedConsumer(
                custom_consumer=consumer_impl
            ),
            **factory_args
        )
        factory.protocol = ClientNodeProtocol

        factory.connect()

        reactor.run()
def main():
    create_loggers()

    parsed_args = parser.parse_args()

    sequence_identifier = 'TestSequence1'

    do_export = False
    if parsed_args.folder_export:
        do_export = True

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    document_sequence = EBUTT3DocumentSequence(
        sequence_identifier=sequence_identifier,
        lang='en-GB',
        reference_clock=reference_clock
    )

    if parsed_args.reference_clock:
        subtitle_tokens = None  # Instead of text we provide the availability time as content.
    else:
        # Let's read our example conversation
        full_text = get_example_data('simple_producer.txt')
        if do_export:
            subtitle_tokens = iter(tokenize_english_document(full_text))
        else:
            # This makes the source cycle infinitely.
            subtitle_tokens = cycle(tokenize_english_document(full_text))

    # This object is used as flexible binding to the carriage mechanism and twisted integrated as dependency injection
    prod_impl = None
    if do_export:
        prod_impl = FilesystemProducerImpl(parsed_args.folder_export, reference_clock)
    else:
        prod_impl = WebsocketProducerCarriage()
        prod_impl.sequence_identifier = sequence_identifier

    simple_producer = SimpleProducer(
        node_id='simple-producer',
        producer_carriage=None,
        document_sequence=document_sequence,
        input_blocks=subtitle_tokens
    )

    # Chaining a converter
    ProducerNodeCarriageAdapter(
        producer_carriage=prod_impl,
        producer_node=simple_producer
    )

    if do_export:
        prod_impl.resume_producing()
    else:

        twisted_producer = TwistedWSPushProducer(
            custom_producer=prod_impl
        )

        factory = BroadcastServerFactory(
            url=u"ws://127.0.0.1:9000",
            producer=twisted_producer
        )

        factory.protocol = BroadcastServerProtocol

        factory.listen()

        # Here we schedule in the simple producer to create content responding to a periodic interval timer.
        looping_task = task.LoopingCall(simple_producer.process_document)

        looping_task.start(2.0)

        reactor.run()