Exemplo n.º 1
0
 def __init__(
     self,
     node_id,
     carriage_impl,
     outbound_carriage_impl,
     reference_clock,
     segment_length,
     media_time_zero,
     segment_timer,
     discard,
 ):
     super(EBUTTDEncoder, self).__init__(
         node_id=node_id, carriage_impl=carriage_impl, reference_clock=reference_clock
     )
     self._outbound_carriage_impl = outbound_carriage_impl
     # We need clock factory to figure the timesync out
     self._last_segment_end = reference_clock.get_time()
     self._segment_length = timedelta(seconds=segment_length)
     media_clock = MediaClock()
     media_clock.adjust_time(timedelta(), media_time_zero)
     self._ebuttd_converter = EBUTT3EBUTTDConverter(media_clock=media_clock)
     self._default_ebuttd_doc = EBUTTDDocument(lang="en-GB")
     self._default_ebuttd_doc.validate()
     self._segment_timer = segment_timer
     self._discard = discard
Exemplo n.º 2
0
class EBUTTDEncoder(AbstractCombinedNode):

    _ebuttd_converter = None
    _default_ns = None
    _default_ebuttd_doc = None
    _expects = EBUTT3Document
    _provides = EBUTTDDocument

    def __init__(self,
                 node_id,
                 media_time_zero,
                 default_ns=False,
                 producer_carriage=None,
                 consumer_carriage=None,
                 **kwargs):
        super(EBUTTDEncoder,
              self).__init__(producer_carriage=producer_carriage,
                             consumer_carriage=consumer_carriage,
                             node_id=node_id,
                             **kwargs)
        self._default_ns = default_ns
        media_clock = MediaClock()
        media_clock.adjust_time(timedelta(), media_time_zero)
        self._ebuttd_converter = EBUTT3EBUTTDConverter(media_clock=media_clock)
        self._default_ebuttd_doc = EBUTTDDocument(lang='en-GB')
        self._default_ebuttd_doc.set_implicit_ns(self._default_ns)
        self._default_ebuttd_doc.validate()

    def process_document(self, document, **kwargs):
        # Convert each received document into EBU-TT-D
        if self.is_document(document):
            self.limit_sequence_to_one(document)

            converted_doc = EBUTTDDocument.create_from_raw_binding(
                self._ebuttd_converter.convert_document(document.binding))
            # Specify the time_base since the FilesystemProducerImpl can't derive it otherwise.
            # Hard coded to 'media' because that's all that's permitted in EBU-TT-D. Alternative
            # would be to extract it from the EBUTTDDocument but since it's the only permitted
            # value that would be an unnecessary overhead...
            self.producer_carriage.emit_data(data=converted_doc,
                                             sequence_identifier='default',
                                             time_base='media',
                                             **kwargs)
Exemplo n.º 3
0
 def __init__(self,
              node_id,
              media_time_zero,
              default_ns=False,
              producer_carriage=None,
              consumer_carriage=None,
              **kwargs):
     super(EBUTTDEncoder,
           self).__init__(producer_carriage=producer_carriage,
                          consumer_carriage=consumer_carriage,
                          node_id=node_id,
                          **kwargs)
     self._default_ns = default_ns
     media_clock = MediaClock()
     media_clock.adjust_time(timedelta(), media_time_zero)
     self._ebuttd_converter = EBUTT3EBUTTDConverter(media_clock=media_clock)
     self._default_ebuttd_doc = EBUTTDDocument(lang='en-GB')
     self._default_ebuttd_doc.set_implicit_ns(self._default_ns)
     self._default_ebuttd_doc.validate()
Exemplo n.º 4
0
 def convert_next_segment(self):
     # Figure out begin and end
     ebutt3_doc = self.get_segment(begin=self.last_segment_end, end=self.last_segment_end + self._segment_length)
     if ebutt3_doc is not None:
         ebuttd_bindings = self._ebuttd_converter.convert_element(ebutt3_doc.binding, dataset={})
         ebuttd_doc = EBUTTDDocument.create_from_raw_binding(ebuttd_bindings)
         ebuttd_doc.validate()
     else:
         ebuttd_doc = self._default_ebuttd_doc
     self.increment_last_segment_end(self._segment_length)
     self._outbound_carriage_impl.emit_document(ebuttd_doc)
 def __init__(self, node_id, carriage_impl, outbound_carriage_impl, reference_clock,
              segment_length, media_time_zero, segment_timer, discard):
     super(EBUTTDEncoder, self).__init__(
         node_id=node_id,
         carriage_impl=carriage_impl,
         reference_clock=reference_clock
     )
     self._outbound_carriage_impl = outbound_carriage_impl
     # We need clock factory to figure the timesync out
     self._last_segment_end = reference_clock.get_time()
     self._segment_length = timedelta(seconds=segment_length)
     media_clock = MediaClock()
     media_clock.adjust_time(timedelta(), media_time_zero)
     self._ebuttd_converter = EBUTT3EBUTTDConverter(
         media_clock=media_clock
     )
     self._default_ebuttd_doc = EBUTTDDocument(lang='en-GB')
     self._default_ebuttd_doc.validate()
     self._segment_timer = segment_timer
     self._discard = discard
 def convert_next_segment(self):
     # Figure out begin and end
     ebutt3_doc = self.get_segment(
         begin=self.last_segment_end,
         end=self.last_segment_end + self._segment_length
     )
     if ebutt3_doc is not None:
         ebuttd_bindings = self._ebuttd_converter.convert_element(ebutt3_doc.binding, dataset={})
         ebuttd_doc = EBUTTDDocument.create_from_raw_binding(ebuttd_bindings)
         ebuttd_doc.validate()
     else:
         ebuttd_doc = self._default_ebuttd_doc
     self.increment_last_segment_end(self._segment_length)
     self._outbound_carriage_impl.emit_document(ebuttd_doc)
Exemplo n.º 7
0
    def process_document(self, document, **kwargs):
        # Convert each received document into EBU-TT-D
        if self.is_document(document):
            self.limit_sequence_to_one(document)

            converted_doc = EBUTTDDocument.create_from_raw_binding(
                self._ebuttd_converter.convert_document(document.binding))
            # Specify the time_base since the FilesystemProducerImpl can't derive it otherwise.
            # Hard coded to 'media' because that's all that's permitted in EBU-TT-D. Alternative
            # would be to extract it from the EBUTTDDocument but since it's the only permitted
            # value that would be an unnecessary overhead...
            self.producer_carriage.emit_data(data=converted_doc,
                                             sequence_identifier='default',
                                             time_base='media',
                                             **kwargs)
Exemplo n.º 8
0
class EBUTTDEncoder(SimpleConsumer):

    _last_segment_end = None
    _segment_length = None
    _ebuttd_converter = None
    _default_ebuttd_doc = None
    _outbound_carriage_impl = None
    _segment_timer = None
    _discard = None

    def __init__(
        self,
        node_id,
        carriage_impl,
        outbound_carriage_impl,
        reference_clock,
        segment_length,
        media_time_zero,
        segment_timer,
        discard,
    ):
        super(EBUTTDEncoder, self).__init__(
            node_id=node_id, carriage_impl=carriage_impl, reference_clock=reference_clock
        )
        self._outbound_carriage_impl = outbound_carriage_impl
        # We need clock factory to figure the timesync out
        self._last_segment_end = reference_clock.get_time()
        self._segment_length = timedelta(seconds=segment_length)
        media_clock = MediaClock()
        media_clock.adjust_time(timedelta(), media_time_zero)
        self._ebuttd_converter = EBUTT3EBUTTDConverter(media_clock=media_clock)
        self._default_ebuttd_doc = EBUTTDDocument(lang="en-GB")
        self._default_ebuttd_doc.validate()
        self._segment_timer = segment_timer
        self._discard = discard

    @property
    def last_segment_end(self):
        return self._last_segment_end

    @property
    def segment_length(self):
        return self._segment_length

    def increment_last_segment_end(self, increment_by):
        self._last_segment_end += increment_by
        return self._last_segment_end

    def process_document(self, document):
        sequence_missing = self._sequence is None
        super(EBUTTDEncoder, self).process_document(document)
        # segmentation, conversion... here
        if sequence_missing and self._sequence is not None:
            # Ok we just got a relevant document. Let's call the function
            # that schedules the periodic segmentation.
            self._segment_timer = self._segment_timer(self)

    def get_segment(self, begin=None, end=None):
        if self._sequence is not None:
            segment_doc = self._sequence.extract_segment(begin=begin, end=end, discard=self._discard)
            return segment_doc
        return None

    def convert_next_segment(self):
        # Figure out begin and end
        ebutt3_doc = self.get_segment(begin=self.last_segment_end, end=self.last_segment_end + self._segment_length)
        if ebutt3_doc is not None:
            ebuttd_bindings = self._ebuttd_converter.convert_element(ebutt3_doc.binding, dataset={})
            ebuttd_doc = EBUTTDDocument.create_from_raw_binding(ebuttd_bindings)
            ebuttd_doc.validate()
        else:
            ebuttd_doc = self._default_ebuttd_doc
        self.increment_last_segment_end(self._segment_length)
        self._outbound_carriage_impl.emit_document(ebuttd_doc)
class EBUTTDEncoder(SimpleConsumer):

    _last_segment_end = None
    _segment_length = None
    _ebuttd_converter = None
    _default_ebuttd_doc = None
    _outbound_carriage_impl = None
    _segment_timer = None
    _discard = None

    def __init__(self, node_id, carriage_impl, outbound_carriage_impl, reference_clock,
                 segment_length, media_time_zero, segment_timer, discard):
        super(EBUTTDEncoder, self).__init__(
            node_id=node_id,
            carriage_impl=carriage_impl,
            reference_clock=reference_clock
        )
        self._outbound_carriage_impl = outbound_carriage_impl
        # We need clock factory to figure the timesync out
        self._last_segment_end = reference_clock.get_time()
        self._segment_length = timedelta(seconds=segment_length)
        media_clock = MediaClock()
        media_clock.adjust_time(timedelta(), media_time_zero)
        self._ebuttd_converter = EBUTT3EBUTTDConverter(
            media_clock=media_clock
        )
        self._default_ebuttd_doc = EBUTTDDocument(lang='en-GB')
        self._default_ebuttd_doc.validate()
        self._segment_timer = segment_timer
        self._discard = discard

    @property
    def last_segment_end(self):
        return self._last_segment_end

    @property
    def segment_length(self):
        return self._segment_length

    def increment_last_segment_end(self, increment_by):
        self._last_segment_end += increment_by
        return self._last_segment_end

    def process_document(self, document):
        sequence_missing = self._sequence is None
        super(EBUTTDEncoder, self).process_document(document)
        # segmentation, conversion... here
        if sequence_missing and self._sequence is not None:
            # Ok we just got a relevant document. Let's call the function
            # that schedules the periodic segmentation.
            self._segment_timer = self._segment_timer(self)

    def get_segment(self, begin=None, end=None):
        if self._sequence is not None:
            segment_doc = self._sequence.extract_segment(begin=begin, end=end, discard=self._discard)
            return segment_doc
        return None

    def convert_next_segment(self):
        # Figure out begin and end
        ebutt3_doc = self.get_segment(
            begin=self.last_segment_end,
            end=self.last_segment_end + self._segment_length
        )
        if ebutt3_doc is not None:
            ebuttd_bindings = self._ebuttd_converter.convert_element(ebutt3_doc.binding, dataset={})
            ebuttd_doc = EBUTTDDocument.create_from_raw_binding(ebuttd_bindings)
            ebuttd_doc.validate()
        else:
            ebuttd_doc = self._default_ebuttd_doc
        self.increment_last_segment_end(self._segment_length)
        self._outbound_carriage_impl.emit_document(ebuttd_doc)
Exemplo n.º 10
0
 def convert_data(self, data, **kwargs):
     return EBUTTDDocument.create_from_xml(data), kwargs
Exemplo n.º 11
0
 def convert_data(self, data, **kwargs):
     return EBUTTDDocument.create_from_raw_binding(
         self._converter.convert_document(data)), kwargs