def test_on_new_data_raise_XMLParsingFailed(self, node): node.process_document = MagicMock(return_value=None) data = ["18:42:42.42", "test"] fs_consumer_impl = FilesystemConsumerImpl() fs_consumer_impl.register(node) self.assertRaises(XMLParsingFailed, lambda: fs_consumer_impl.on_new_data(data)) assert not node.process_document.called
def test_on_new_data(self, node): node.process_document = MagicMock(return_value=True) node.reference_clock.time_base = "clock" test_xml = None test_xml_file_path = os.path.join(self.test_data_dir_path, "testSeq_1.xml") with open(test_xml_file_path, "r") as test_xml_file: test_xml = test_xml_file.read() data = ["18:42:42.42", test_xml] fs_consumer_impl = FilesystemConsumerImpl() fs_consumer_impl.register(node) fs_consumer_impl.on_new_data(data) assert node.process_document.called
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(): 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()
def test_on_new_data(self): node = MagicMock(spec=IConsumerNode) node.expects.return_value = six.text_type test_xml_file_path = os.path.join(self.test_data_dir_path, 'testSeq_1.xml') with open(test_xml_file_path, 'r') as test_xml_file: test_xml = test_xml_file.read() data = ["18:42:42.42", test_xml] fs_consumer_impl = FilesystemConsumerImpl() fs_consumer_impl.register_consumer_node(node) fs_consumer_impl.on_new_data(data) node.process_document.assert_called_once()
def test_on_new_data(self, node): node.process_document = MagicMock(return_value=True) node.reference_clock.time_base = "clock" test_xml = None test_xml_file_path = os.path.join(self.test_data_dir_path, 'testSeq_1.xml') with open(test_xml_file_path, 'r') as test_xml_file: test_xml = test_xml_file.read() data = ["18:42:42.42", test_xml] fs_consumer_impl = FilesystemConsumerImpl() fs_consumer_impl.register(node) fs_consumer_impl.on_new_data(data) assert node.process_document.called
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()