Esempio n. 1
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()
Esempio n. 2
0
 def test_resume_reading(self, fs_carriage_impl):
     fs_carriage_impl.on_new_data = MagicMock(return_value=None)
     test_manifest_path = os.path.join(self.test_data_dir_path, "manifest_testSeq.txt")
     fs_reader = FilesystemReader(test_manifest_path, fs_carriage_impl, False)
     test_xml = None
     with open(test_manifest_path, "r") as test_manifest:
         manifest_line = test_manifest.readline()
         availability_time_str, test_xml_file_name = manifest_line.rstrip().split(",")
         test_xml_file_path = os.path.join(self.test_data_dir_path, test_xml_file_name)
         with open(test_xml_file_path, "r") as test_xml_file:
             test_xml = test_xml_file.read()
     fs_reader.resume_reading()
     data = [availability_time_str, test_xml]
     fs_carriage_impl.on_new_data.assert_called_once_with(data)
 def test_resume_reading(self, fs_carriage_impl):
     fs_carriage_impl.on_new_data = MagicMock(return_value=None)
     test_manifest_path = os.path.join(self.test_data_dir_path, 'manifest_testSeq.txt')
     fs_reader = FilesystemReader(test_manifest_path, fs_carriage_impl, False)
     test_xml = None
     with open(test_manifest_path, 'r') as test_manifest:
         manifest_line = test_manifest.readline()
         availability_time_str, test_xml_file_name = manifest_line.rstrip().split(',')
         test_xml_file_path = os.path.join(self.test_data_dir_path, test_xml_file_name)
         with open(test_xml_file_path, 'r') as test_xml_file:
             test_xml = test_xml_file.read()
     fs_reader.resume_reading()
     data = [availability_time_str, test_xml]
     fs_carriage_impl.on_new_data.assert_called_once_with(data)
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()
Esempio n. 5
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()
Esempio n. 6
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()
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':
        if args.timeshift > 0.0:
            buffer_size = math.ceil(args.timeshift / args.interval)
            outbound_carriage = RotatingFolderExport(args.output_folder, 'ebuttd-encode-{counter}.xml', buffer_size)
        else:
            outbound_carriage = SimpleFolderExport(args.output_folder, 'ebuttd-encode-{counter}.xml')
    else:
        raise Exception('Invalid output format: {}'.format(args.output_format))

    if args.utc_clock is True:
        reference_clock = UTCClock()
    else:
        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

    if args.media_time_zero_offset != 'current':
        media_time_zero += bindings.ebuttdt.LimitedClockTimingType(str(args.media_time_zero_offset)).timedelta

    # This used to be controllable. For now we start segmentation whenever the script was started in time.
    # This flag could be used to mitigate the encoder running too fast in the future and ahead of the time
    # window as it is getting populated with data. This is not needed when the segmentation will be moved from a
    # timer to a reference clock polling based triggering mechanism.
    segmentation_starts = None

    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=args.nowait is False and start_timer or (lambda x: None),
        discard=args.discard,
        segmentation_starts=segmentation_starts,
        implicit_ns=args.implicit_ns
    )

    if manifest_path:
        fs_reader.resume_reading()
        last_timing_event = ebuttd_converter._sequence.timeline[-1]
        last_segment_end = timedelta()
        while last_segment_end < last_timing_event.when:
            last_segment_end = ebuttd_converter.convert_next_segment()
        # 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()

        start_timer(ebuttd_converter)

        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()