Esempio n. 1
0
File: ts.py Progetto: lvella/arib
    def __init__(self, f):
        '''Copy packet data from file f to structure
    '''
        sync_byte = read.ucb(f)
        if sync_byte != TSPacket.SYNC_BYTE:
            raise DecodingError(
                "Incorrect sync byte found at start of TS packet.")
        pid_bytes = read.usb(f)
        self._pid = 0x0fff & pid_bytes
        self._payload_start_indicator = bool(0xf000 & pid_bytes)

        #(2 bit scrambling control =00, 1 bit adaptation exists=true, 1 bit payload exists=true, 4 bit continuity counter =0xc)
        flags_byte = read.ucb(f)
        self._scrambling_control = 0xc0 & flags_byte
        self._adaptation_field_exists = bool(0x20 & flags_byte)
        self._payload_exists = bool(0x10 & flags_byte)
        self._continuity_counter = 0x0f & flags_byte

        if self._adaptation_field_exists:
            self._adaptation_field = AdaptationField(f)
            self._payload = [
                read.ucb(f)
                for x in range(188 - 4 - len(self._adaptation_field))
            ]
        else:
            self._payload = [read.ucb(f) for x in range(188 - 4)]
Esempio n. 2
0
    def __init__(self, f):
        """
    """
        self.TMD = read.ucb(f) >> 6
        if self.TMD == 0b10:
            _t = read.uib(f)
            _ub = read.uic(f) >> 4
            self._OTM = _t | (_ub << 32)
            if DEBUG:
                print("Caption management OTM: " + str(self._OTM))

        self._num_languages = read.ucb(f)
        self._languages = []
        for lang in range(self._num_languages):
            self._languages.append(Language(f))

        self._data_unit_loop_length = read.ui3b(f)
        if DEBUG:
            print('Caption managmentdata : data unit loop length: ' +
                  str(self._data_unit_loop_length))
        bytes_read = 0
        self._data_units = []
        while bytes_read < self._data_unit_loop_length[0]:
            self._data_units.append(DataUnit(f))
            bytes_read += self._data_units[-1].size()
 def __init__(self, f):
     self._args = []
     self._args.append(read.ucb(f) & 0x3f)  #p1
     self._args.append(read.ucb(f) & 0x3f)  #p2
     if DEBUG:
         print(u'APS: --> {:#d},{:#d}>'.format(
             self._args[0], self._args[1]).encode('utf-8'))
 def __init__(self, f):
     '''read from stream until we get "space" and then our CSI
   specific control character.
 '''
     self._args = []
     c = read.ucb(f)
     while c is not 0x20:
         self._args.append(c)
         c = read.ucb(f)
     self._args.append(c)
     #lastly read the command code
     c = read.ucb(f)
     self._args.append(c)
Esempio n. 5
0
 def __init__(self, f):
   '''read from stream until we get "space" and then our CSI
     specific control character.
   '''
   self._args = []
   c = read.ucb(f)
   while c is not 0x20:
     self._args.append(c)
     c = read.ucb(f)
   self._args.append(c)
   #lastly read the command code
   c = read.ucb(f)
   self._args.append(c) 
Esempio n. 6
0
 def __init__(self, f):
   self._unit_separator = read.ucb(f)
   if(self._unit_separator is not 0x1f):
     if DEBUG:
       print 'Unit separator not found at start of data unit.'
     raise ValueError
   self._data_unit_type = read.ucb(f)
   if DEBUG:
     print 'data unit type: ' + str(self._data_unit_type)
   self._data_unit_size = read.ui3b(f)
   if DEBUG:
     print 'DataUnit size found to be: ' + str(self._data_unit_size)
   #self._payload = f.read(self._data_unit_size)
   self._payload = self.load_unit(f)
Esempio n. 7
0
 def __init__(self, f):
   self._unit_separator = read.ucb(f)
   if(self._unit_separator is not 0x1f):
     if DEBUG:
       print 'Unit separator not found at start of data unit.'
     raise ValueError
   self._data_unit_type = read.ucb(f)
   if DEBUG:
     print 'data unit type: ' + str(self._data_unit_type)
   self._data_unit_size = read.ui3b(f)
   if DEBUG:
     print 'DataUnit size found to be: ' + str(self._data_unit_size)
   #self._payload = f.read(self._data_unit_size)
   self._payload = self.load_unit(f)
Esempio n. 8
0
  def __init__(self, f):
    b = read.ucb(f)
    self._font_id = (b & 0xf0) >> 8
    self._mode = (b & 0x0f)
    if self._mode == 0 or self._mode == 0x1:
      self._depth = read.ucb(f)
      self._width = read.ucb(f)
      self._height = read.ucb(f)
      self._pixels = []

      # assuming 4 pixels per byte. How is this tied to depth above? (typical depth = 2)
      for i in range((self._width * self._height)/4):
        self._pixels.append(read.ucb(f))

      tmp_str = str(self._pixels)
      self._hash = hash(tmp_str)

      if DRCS_DEBUG:
        print("DRCS character font id: {id}".format(id=self._font_id))
        print("DRCS character hash: {h}".format(h=self._hash))

      if self._hash in DRCSFont.character_hashes:
        self._character = DRCSFont.character_hashes[self._hash]
      else:
        self._character = u'�'

    else:
        raise ValueError("DRCSFont mode not supported.")
    if DRCS_DEBUG:
      print("DRCS character: font: {font}".format(font=self._font_id))
      px = ''
      i = 0
      for h in range(self._height/2):
        for w in range(self._width/4):
          #px += str(self._pixels[i]) + " "
          p = self._pixels[h * self._width/2 + w]
          if p == 0:
            px += " "
          elif p == 0xff:
            px += "█"
          elif p == 0x0f:
            px += "▐"
          elif p == 0xf0:
            px += "▌"
          else:
            px += "╳"
          i = i + 1
        px += '\n'
      print(px)
Esempio n. 9
0
File: ts.py Progetto: lvella/arib
    def __init__(self, f):
        '''Initialize object off of file descriptor
    '''
        self._discontinuity_indicator = False
        self._random_access_indicator = False
        self._es_priority_indicator = False
        self._pcr_flag = False
        self._ocr_flag = False
        self._splicing_point_flag = False
        self._transport_private_data_flag = False
        self._adaptation_field_extension_flag = False
        self._payload = []
        self._pcr = 0
        self._ocr = 0

        self._adaptation_field_length = read.ucb(f)
        #Adaptation field length CAN be zero if only one byte stuffing is needed
        #So we only draw out other info when it's nonzero.
        if self._adaptation_field_length == 0:
            return
        bytes_read = 0
        flags = read.ucb(f)
        #print('flags {f:02X}'.format(f=flags))
        bytes_read += 1
        self._discontinuity_indicator = bool(flags & 0x80)
        self._random_access_indicator = bool(flags & 0x40)
        self._es_priority_indicator = bool(flags & 0x20)
        self._pcr_flag = bool(flags & 0x10)
        self._ocr_flag = bool(flags & 0x08)
        self._splicing_point_flag = bool(flags & 0x04)
        self._transport_private_data_flag = bool(flags & 0x20)
        self._adaptation_field_extension_flag = bool(flags & 0x01)

        if self._pcr_flag:
            self._pcr = read.uib(f)
            additional_bytes = read.usb(f)
            self._pcr = (self._pcr << 1) | ((additional_bytes >> 15))
            bytes_read += 6
        if self._ocr_flag:
            self._ocr = read.uib(f)
            additional_bytes = read.usb(f)
            bytes_read += 6

        #print ('af length {l} and bytes read {b}'.format(l=self._adaptation_field_length, b=bytes_read))
        self._payload = [
            read.ucb(f)
            for x in range(self._adaptation_field_length - bytes_read)
        ]
Esempio n. 10
0
  def decode(self, f):
    '''Return an object representing the current character
    '''
    b = read.ucb(f)
    if DEBUG:
      print '-->{:02x}'.format(b)
    #the interpretation and how many more bytes we have to read
    #depends upon:
    #1) What code table is this character in? c0? GR? GL? etc.
    #2) What is the current invocation of the code table? i.e. is it pointing
    #to G0, G2, G3, G4 invocation?
    #3) What is the designation (active encoding) for the current invocation.
    #e.g. is g0 loaded with 2 byte kanji? or single byte hiragana etc?
    statement = None
    #handle the current character for current encoding
    if is_control_character(b):
      statement = handle_control_character(b, f)
    elif is_gl_character(b):
      statement = self._GL(b, f)
    elif is_gr_character(b):
      statement = self._GR(b, f)

    #possible internal encoding state change via returned control character.
    self.handle_encoding_change(statement)

    return statement
Esempio n. 11
0
  def decode(self, f):
    '''Return an object representing the current character
    '''
    b = read.ucb(f)
    if DEBUG:
      print '-->{:02x}'.format(b)
    #the interpretation and how many more bytes we have to read
    #depends upon:
    #1) What code table is this character in? c0? GR? GL? etc.
    #2) What is the current invocation of the code table? i.e. is it pointing
    #to G0, G2, G3, G4 invocation?
    #3) What is the designation (active encoding) for the current invocation.
    #e.g. is g0 loaded with 2 byte kanji? or single byte hiragana etc?
    statement = None
    #handle the current character for current encoding
    if is_control_character(b):
      statement = handle_control_character(b, f)
    elif is_gl_character(b):
      statement = self._GL(b, f)
    elif is_gr_character(b):
      statement = self._GR(b, f)

    #possible internal encoding state change via returned control character.
    self.handle_encoding_change(statement)

    return statement
Esempio n. 12
0
  def __init__(self,b, f):
    '''Read from stream two bytes
    :param b: initial byte value read
    :b type: int
    :param f: filestream we're reading from
    :f type: file stream open for binary reading
    '''
    #read the second byte of the 2 byte kanji
    b2 = read.ucb(f)
    self._args = []
    self._args.append(b)
    self._args.append(b2)

    if Gaiji.is_gaiji(self._args):
      #character is outside the shif-jis code set
      self._character = Gaiji.decode(self._args)
    else:
      #form utf-8 encoding of character
      s = u''.join(u'{:02x}'.format(a|0x80) for a in self._args)
      h = s.decode('hex')
      try:
          self._character = h.decode('euc-jisx0213')
      except:
          self._character = u'◻'
    if DEBUG:
      print(u'[{b}][{b2}]-->{char}'.format(b=hex(b), b2=hex(b2), char=self._character).encode('utf-8'))
Esempio n. 13
0
    def __init__(self, b, f):
        '''Read from stream two bytes
    :param b: initial byte value read
    :b type: int
    :param f: filestream we're reading from
    :f type: file stream open for binary reading
    '''
        #read the second byte of the 2 byte kanji
        b2 = read.ucb(f)
        self._args = []
        self._args.append(b)
        self._args.append(b2)

        if Gaiji.is_gaiji(self._args):
            #character is outside the shif-jis code set
            self._character = Gaiji.decode(self._args)
        else:
            #form utf-8 encoding of character
            s = u''.join(u'{:02x}'.format(a | 0x80) for a in self._args)
            h = s.decode('hex')
            try:
                self._character = h.decode('euc-jisx0213')
            except:
                self._character = u'◻'
        if DEBUG:
            print(u'[{b}][{b2}]-->{char}'.format(
                b=hex(b), b2=hex(b2), char=self._character).encode('utf-8'))
Esempio n. 14
0
 def __init__(self, f):
   '''the interpretation and bytes read
   after reading 'ESC' can be complex. Here
   We'll just attempt to successfully read all
   required args, and leave interpretation for later
   '''
   b = read.ucb(f)
   if DEBUG:
     print 'esc first byte is ' + '{:#x}'.format(b)
   self._args = []
   self._args.append(b)
   
   if b in INVOCATION_TABLE:
     if DEBUG:
       print 'ESC INVOCATION {:#x}'.format(b)
     INVOCATION_TABLE[b](f)
     #self._args.append(next)
   elif b in DESIGNATION_TABLE:
     if DEBUG:
       print 'ESC DESIGNATION {:#x}'.format(b)
     d = DESIGNATION_TABLE[b]()
     d.load(self, f)
     #self._args.append(next)
   elif b == TwoByte.CODE:
     if DEBUG:
       print 'ESC TWO BYTE {:#x}'.format(b)
     TwoByte.handler(self, f)
     #self._args.append(next)
   else:
     raise DecodingError()
Esempio n. 15
0
    def __init__(self, f):
        '''the interpretation and bytes read
    after reading 'ESC' can be complex. Here
    We'll just attempt to successfully read all
    required args, and leave interpretation for later
    '''
        b = read.ucb(f)
        if DEBUG:
            print 'esc first byte is ' + '{:#x}'.format(b)
        self._args = []
        self._args.append(b)

        if b in INVOCATION_TABLE:
            if DEBUG:
                print 'ESC INVOCATION {:#x}'.format(b)
            INVOCATION_TABLE[b](f)
            #self._args.append(next)
        elif b in DESIGNATION_TABLE:
            if DEBUG:
                print 'ESC DESIGNATION {:#x}'.format(b)
            d = DESIGNATION_TABLE[b]()
            d.load(self, f)
            #self._args.append(next)
        elif b == TwoByte.CODE:
            if DEBUG:
                print 'ESC TWO BYTE {:#x}'.format(b)
            TwoByte.handler(self, f)
            #self._args.append(next)
        else:
            raise DecodingError()
Esempio n. 16
0
 def __init__(self, f):
   '''
   :param bytes: array of bytes payload
   '''
   self._TMD = read.ucb(f)>>6
   if self._TMD == 0x1 or self._TMD == 0x2:
     # 36 bit STM time, followed by 4 bit reserved data
     # followed by 24 bit data_unit_loop_length.
     # We'll read all that as a single 64 bit value and break it up
     d = read.ulb(f)
     self.STM = d >> 28
     self._data_unit_loop_length = d & 0xffffffff
     if DEBUG:
       print 'CaptionStatementData: STM (time) ' + str(self.STM)
       print 'CaptionStatementData: data unit loop length: ' + str(self._data_unit_loop_length)
   else:
     self.STM = 0
     self._data_unit_loop_length = read.ui3b(f)
   if DEBUG:
     print 'Caption statement: data unit loop length: ' + str(self._data_unit_loop_length)
   bytes_read = 0
   self._data_units = []
   while bytes_read < self._data_unit_loop_length:
     self._data_units.append(DataUnit(f))
     bytes_read += self._data_units[-1].size()
Esempio n. 17
0
File: ts.py Progetto: Miliox/arib
  def __init__(self, f):
    '''Initialize object off of file descriptor
    '''
    self._discontinuity_indicator = False
    self._random_access_indicator = False
    self._es_priority_indicator = False
    self._pcr_flag = False
    self._ocr_flag = False
    self._splicing_point_flag = False
    self._transport_private_data_flag = False
    self._adaptation_field_extension_flag = False
    self._payload = []
    self._pcr = 0
    self._ocr = 0

    self._adaptation_field_length = read.ucb(f)
    #Adaptation field length CAN be zero if only one byte stuffing is needed
    #So we only draw out other info when it's nonzero.
    if self._adaptation_field_length == 0:
      return
    bytes_read = 0
    flags = read.ucb(f)
    #print('flags {f:02X}'.format(f=flags))
    bytes_read += 1
    self._discontinuity_indicator = bool(flags & 0x80)
    self._random_access_indicator = bool(flags & 0x40)
    self._es_priority_indicator = bool(flags & 0x20)
    self._pcr_flag = bool(flags & 0x10)
    self._ocr_flag = bool(flags & 0x08)
    self._splicing_point_flag = bool(flags & 0x04)
    self._transport_private_data_flag = bool(flags & 0x20)
    self._adaptation_field_extension_flag = bool(flags & 0x01)

    if self._pcr_flag:
      self._pcr = read.uib(f)
      additional_bytes= read.usb(f)
      self._pcr = (self._pcr<<1)|((additional_bytes>>15))
      bytes_read += 6
    if self._ocr_flag:
      self._ocr = read.uib(f)
      additional_bytes = read.usb(f)
      bytes_read += 6

    #print ('af length {l} and bytes read {b}'.format(l=self._adaptation_field_length, b=bytes_read))
    self._payload = [read.ucb(f) for x in range(self._adaptation_field_length-bytes_read)]
Esempio n. 18
0
 def handler(esc, f):
     b = read.ucb(f)
     if DEBUG:
         print 'DRCS {:#x}'.format(b)
     if in_code_set_table(b):
         esc._args.append(b)
     else:
         #return  code_set_from_final_byte(b, f)
         raise DecodingError()
Esempio n. 19
0
File: gl.py Progetto: Miliox/arib
  def __init__(self,b, f):
    '''Read from stream two bytes
    '''
    b2 = read.ucb(f)
    self._args = []
    self._args.append(b)
    self._args.append(b2)

    self._value = ((0x0f & b) << 4) | (0x0f & b2)
Esempio n. 20
0
 def handler(esc, f):
   b = read.ucb(f)
   if DEBUG:
     print 'DRCS {:#x}'.format(b)
   if in_code_set_table(b):
     esc._args.append(b)
   else:
     #return  code_set_from_final_byte(b, f)
     raise DecodingError() 
Esempio n. 21
0
    def __init__(self, b, f):
        '''Read from stream two bytes
    '''
        b2 = read.ucb(f)
        self._args = []
        self._args.append(b)
        self._args.append(b2)

        self._value = ((0x0f & b) << 4) | (0x0f & b2)
Esempio n. 22
0
 def __init__(self, f):
   """
   :param f: file descriptor we're reading from
   """
   self._character_code = read.usb(f)
   self._number_of_font = read.ucb(f)
   self._fonts = []
   for i in range(self._number_of_font):
     self._fonts.append(DRCSFont(f))
Esempio n. 23
0
 def handler(esc, f):
   b = read.ucb(f)
   if in_code_set_table(b):
     esc._args.append(b)
     #return  code_set_from_final_byte(b, f)
   elif b in DESIGNATION_TABLE:
     esc._args.append(b)
     d = DESIGNATION_TABLE[b]()
     d.load(esc, f)
   else:
     raise DecodingError() 
Esempio n. 24
0
 def handler(esc, f):
     b = read.ucb(f)
     if in_code_set_table(b):
         esc._args.append(b)
         #return  code_set_from_final_byte(b, f)
     elif b in DESIGNATION_TABLE:
         esc._args.append(b)
         d = DESIGNATION_TABLE[b]()
         d.load(esc, f)
     else:
         raise DecodingError()
Esempio n. 25
0
 def __init__(self, f, data_unit):
   self._unit_separator = data_unit._unit_separator
   self._data_unit_type = data_unit._data_unit_type
   if self._data_unit_type is not DRCS1ByteCharacter.ID:
     if DEBUG:
       print 'this is not a DRCS character'
     raise ValueError
   self._data_unit_size = data_unit._data_unit_size
   self._characters = []
   self._number_of_code = read.ucb(f)
   for i in range(self._number_of_code):
     self._characters.append(DRCSCharacter(f))
Esempio n. 26
0
    def __init__(self, f):
        d = read.ucb(f)
        self._language_tag = d >> 5
        if DEBUG:
            print("caption management language tag: " +
                  str(self._language_tag))
        self._DMF = d & 0x7
        if self._DMF == 0b1100 or self._DMF == 0b1101 or self._DMF == 0b1110:
            self._DC = read.ucb(f)
        else:
            self._DC = 0

        if DEBUG:
            print("caption managment DC: " + str(self._DC))

        self._language_code = ''
        # Py2->unichr, Py3->chr
        # Refer: https://hydrocul.github.io/wiki/programming_languages_diff/string/chr.html
        self._language_code += str(chr(read.ucb(f)))
        self._language_code += str(chr(read.ucb(f)))
        self._language_code += str(chr(read.ucb(f)))
        if DEBUG:
            print("caption managment language code: " +
                  str(self._language_code))

        formats = read.ucb(f)
        self._format = formats >> 4
        if DEBUG:
            print("caption management format: " + str(self._format))

        self._rollup_mode = formats & 0x3
        if DEBUG:
            print("caption management rollup mode: " + str(self._rollup_mode))
Esempio n. 27
0
  def __init__(self, f):
    d = read.ucb(f)
    self._language_tag = d >> 5
    if DEBUG:
      print("caption management language tag: " + str(self._language_tag))
    self._DMF = d & 0x7
    if self._DMF == 0b1100 or self._DMF == 0b1101 or self._DMF == 0b1110:
      self._DC = read.ucb(f)
    else:
      self._DC = 0

    if DEBUG:
      print("caption managment DC: " + str(self._DC))

    self._language_code = ''
    self._language_code += str(unichr(read.ucb(f)))
    self._language_code += str(unichr(read.ucb(f)))
    self._language_code += str(unichr(read.ucb(f)))
    if DEBUG:
      print("caption managment language code: " + str(self._language_code))
    
    formats = read.ucb(f)
    self._format = formats >> 4
    if DEBUG:
      print("caption management format: " + str(self._format))
    
    self._rollup_mode = formats & 0x3
    if DEBUG:
      print("caption management rollup mode: " + str(self._rollup_mode))
Esempio n. 28
0
File: ts.py Progetto: Miliox/arib
  def __init__(self, f):
    '''Copy packet data from file f to structure
    '''
    sync_byte = read.ucb(f)
    if sync_byte != TSPacket.SYNC_BYTE:
      raise DecodingError("Incorrect sync byte found at start of TS packet.")
    pid_bytes = read.usb(f)
    self._pid = 0x0fff & pid_bytes
    self._payload_start_indicator = bool(0xf000 & pid_bytes)

    #(2 bit scrambling control =00, 1 bit adaptation exists=true, 1 bit payload exists=true, 4 bit continuity counter =0xc)
    flags_byte = read.ucb(f)
    self._scrambling_control = 0xc0 & flags_byte
    self._adaptation_field_exists = bool(0x20 & flags_byte)
    self._payload_exists = bool(0x10 & flags_byte)
    self._continuity_counter = 0x0f & flags_byte

    if self._adaptation_field_exists:
      self._adaptation_field = AdaptationField(f)
      self._payload = [read.ucb(f) for x in range(188-4-len(self._adaptation_field))]
    else:
      self._payload = [read.ucb(f) for x in range(188-4)]
Esempio n. 29
0
 def load(self, esc, f):
   b = read.ucb(f)
   if b == DRCS.CODE:
     if DEBUG:
       print 'G3 DRCS {:#x}'.format(b)
     esc._args.append(b)
     DRCS.handler(esc, f)
   elif in_code_set_table(b):
     if DEBUG:
       print 'G3 CODESET {:#x}'.format(b)
     esc._args.append(b)
   else:
     raise DecodingError()
Esempio n. 30
0
 def load(self, esc, f):
     b = read.ucb(f)
     if b == DRCS.CODE:
         if DEBUG:
             print 'G3 DRCS {:#x}'.format(b)
         esc._args.append(b)
         DRCS.handler(esc, f)
     elif in_code_set_table(b):
         if DEBUG:
             print 'G3 CODESET {:#x}'.format(b)
         esc._args.append(b)
     else:
         raise DecodingError()
Esempio n. 31
0
  def __init__(self, f):
    """
    """
    self.TMD = read.ucb(f) >> 6
    if self.TMD == 0b10:
      _t = read.uib(f)
      _ub = read.uic(f) >> 4
      self._OTM = _t | (_ub << 32)
      if DEBUG:
        print "Caption management OTM: " + str(self._OTM)

    self._num_languages = read.ucb(f)
    self._languages = []
    for lang in range(self._num_languages):
      self._languages.append(Language(f))

    self._data_unit_loop_length = read.ui3b(f)
    if DEBUG:
      print 'Caption managmentdata : data unit loop length: ' + str(self._data_unit_loop_length)
    bytes_read = 0
    self._data_units = []
    while bytes_read < self._data_unit_loop_length:
      self._data_units.append(DataUnit(f))
      bytes_read += self._data_units[-1].size()
Esempio n. 32
0
    def __init__(self, f):
        if DEBUG:
            print("__DATA_GROUP_START__")

        self._stuffing_byte = read.ucb(f)
        if DEBUG:
            print hex(self._stuffing_byte)
        if (self._stuffing_byte is not 0x80):
            raise DataGroupParseError(
                "Initial stuffing byte not equal to 0x80: " +
                hex(self._stuffing_byte))

        self._data_identifier = read.ucb(f)
        if DEBUG:
            print hex(self._data_identifier)
        if self._data_identifier is not 0xff:
            raise DataGroupParseError(
                "Initial data identifier is not equal to 0xff" +
                hex(self._data_identifier))

        self._private_stream_id = read.ucb(f)
        if DEBUG:
            print hex(self._private_stream_id)
        if self._private_stream_id is not 0xf0:
            raise DataGroupParseError("Private stream id not equal to 0xf0: " +
                                      hex(self._private_stream_id))

        self._group_id = read.ucb(f)
        if DEBUG:
            print 'group id ' + str((self._group_id >> 2) & (~0x20))
        self._group_link_number = read.ucb(f)
        if DEBUG:
            print str(self._group_link_number)
        self._last_group_link_number = read.ucb(f)
        if DEBUG:
            print str(self._last_group_link_number)
        if self._group_link_number != self._last_group_link_number:
            print("This is data group packet " + str(self._group_link_number) +
                  " of " + str(self._last_group_link_number))
        self._data_group_size = read.usb(f)
        if DEBUG:
            print 'data group size found is ' + str(self._data_group_size)

        if not self.is_management_data():
            self._payload = CaptionStatementData(f)
        else:
            #self._payload = f.read(self._data_group_size)
            #self._payload = read.buffer(f, self._data_group_size)
            self._payload = CaptionManagementData(f)

        self._crc = read.usb(f)
        if DEBUG:
            print 'crc value is ' + str(self._crc)
Esempio n. 33
0
 def __init__(self, f):
   '''
   :param bytes: array of bytes payload
   '''
   self._TMD = read.ucb(f)>>6
   if self._TMD == 0x01 or self._TMD == 0X10:
     self.STM = 0#TODO: read four bytes
   else:
     self.STM = 0
   self._data_unit_loop_length = read.ui3b(f)
   if DEBUG:
     print 'Caption statement: data unit loop length: ' + str(self._data_unit_loop_length)
   #self._payload = f.read(self._data_unit_loop_length)
   bytes_read = 0
   self._data_units = []
   while bytes_read < self._data_unit_loop_length:
     self._data_units.append(DataUnit(f))
     bytes_read += self._data_units[-1].size()
Esempio n. 34
0
 def __init__(self, f):
     '''
 :param bytes: array of bytes payload
 '''
     self._TMD = read.ucb(f) >> 6
     if self._TMD == 0x01 or self._TMD == 0X10:
         self.STM = 0  #TODO: read four bytes
     else:
         self.STM = 0
     self._data_unit_loop_length = read.ui3b(f)
     if DEBUG:
         print 'Caption statement: data unit loop length: ' + str(
             self._data_unit_loop_length)
     #self._payload = f.read(self._data_unit_loop_length)
     bytes_read = 0
     self._data_units = []
     while bytes_read < self._data_unit_loop_length:
         self._data_units.append(DataUnit(f))
         bytes_read += self._data_units[-1].size()
Esempio n. 35
0
  def __init__(self, f):
    if DEBUG:
      print("__DATA_GROUP_START__")

    self._stuffing_byte = read.ucb(f)
    if DEBUG:
      print hex(self._stuffing_byte)
    if(self._stuffing_byte is not 0x80):
      raise DataGroupParseError("Initial stuffing byte not equal to 0x80: " + hex(self._stuffing_byte))

    self._data_identifier = read.ucb(f)
    if DEBUG:
      print hex(self._data_identifier)
    if self._data_identifier is not 0xff:
      raise DataGroupParseError("Initial data identifier is not equal to 0xff" + hex(self._data_identifier))

    self._private_stream_id = read.ucb(f)
    if DEBUG:
     print hex(self._private_stream_id)
    if self._private_stream_id is not 0xf0:
      raise DataGroupParseError("Private stream id not equal to 0xf0: " + hex(self._private_stream_id))

    self._group_id = read.ucb(f)
    if DEBUG:
        print 'group id ' + str((self._group_id >> 2)&(~0x20))
    self._group_link_number = read.ucb(f)
    if DEBUG:
        print str(self._group_link_number)
    self._last_group_link_number = read.ucb(f)
    if DEBUG:
      print str(self._last_group_link_number)
    if self._group_link_number != self._last_group_link_number:
      print("This is data group packet " + str(self._group_link_number) + " of " + str(self._last_group_link_number))
    self._data_group_size = read.usb(f)
    if DEBUG:
      print 'data group size found is ' + str(self._data_group_size)

    if not self.is_management_data():
      self._payload = CaptionStatementData(f)
    else:
      #self._payload = f.read(self._data_group_size)
      #self._payload = read.buffer(f, self._data_group_size)
      self._payload = CaptionManagementData(f)
    
    self._crc = read.usb(f)
    if DEBUG:
      print 'crc value is ' + str(self._crc)
Esempio n. 36
0
 def __init__(self, f):
     self._stuffing_byte = read.ucb(f)
     if DEBUG:
         print str(self._stuffing_byte)
     if (self._stuffing_byte is not 0x80):
         raise ValueError
     self._data_identifier = read.ucb(f)
     if DEBUG:
         print str(self._data_identifier)
     if self._data_identifier is not 0xff:
         raise ValueError
     self._private_stream_id = read.ucb(f)
     if DEBUG:
         print str(self._private_stream_id)
     if self._private_stream_id is not 0xf0:
         raise ValueError
     self._group_id = read.ucb(f)
     if DEBUG:
         print 'group id ' + str((self._group_id >> 2) & (~0x20))
     self._group_link_number = read.ucb(f)
     if DEBUG:
         print str(self._group_link_number)
     self._last_group_link_number = read.ucb(f)
     if DEBUG:
         print str(self._last_group_link_number)
     self._data_group_size = read.usb(f)
     if DEBUG:
         print 'data group size found is ' + str(self._data_group_size)
     if not self.is_management_data():
         self._payload = CaptionStatementData(f)
     else:
         #self._payload = f.read(self._data_group_size)
         self._payload = read.buffer(f, self._data_group_size)
     self._crc = read.usb(f)
     if DEBUG:
         print 'crc value is ' + str(self._crc)
Esempio n. 37
0
 def __init__(self, f):
   self._stuffing_byte = read.ucb(f)
   if DEBUG:
     print str(self._stuffing_byte)
   if(self._stuffing_byte is not 0x80):
     raise ValueError
   self._data_identifier = read.ucb(f)
   if DEBUG:
     print str(self._data_identifier)
   if self._data_identifier is not 0xff:
     raise ValueError
   self._private_stream_id = read.ucb(f)
   if DEBUG:
    print str(self._private_stream_id)
   if self._private_stream_id is not 0xf0:
     raise ValueError
   self._group_id = read.ucb(f)
   if DEBUG:
     print 'group id ' + str((self._group_id >> 2)&(~0x20))
   self._group_link_number = read.ucb(f)
   if DEBUG:
     print str(self._group_link_number)
   self._last_group_link_number = read.ucb(f)
   if DEBUG:
     print str(self._last_group_link_number)
   self._data_group_size = read.usb(f)
   if DEBUG:
     print 'data group size found is ' + str(self._data_group_size)
   if not self.is_management_data():
     self._payload = CaptionStatementData(f)
   else:
     #self._payload = f.read(self._data_group_size)
     self._payload = read.buffer(f, self._data_group_size)
   self._crc = read.usb(f)
   if DEBUG:
     print 'crc value is ' + str(self._crc)
Esempio n. 38
0
 def __init__(self, f):
     self._args = []
     self._args.append(read.ucb(f) & 0x3f)  #p1
     self._args.append(read.ucb(f) & 0x3f)  #p2
Esempio n. 39
0
 def __init__(self,b, f):
   self._args = []
   self._args.append(b)
   self._args.append(read.ucb(f))
Esempio n. 40
0
 def __init__(self, f):
   self._args = []
   p1 = read.ucb(f)
   self._args.append(p1)
   if p1 == 0x20:
     self._args.append(read.ucb(f))
Esempio n. 41
0
 def __init__(self, f):
   self._args = []
   self._args.append(read.ucb(f)&0x3f)#p1
   self._args.append(read.ucb(f)&0x3f)#p2
Esempio n. 42
0
 def __init__(self, f):
   self._code = read.ucb(f)
   self._start = False
   if self._code & 0x1:
     self._start = True
Esempio n. 43
0
 def __init__(self, f):
   self._args = []
   self._args.append(read.ucb(f)&0x3f)#p1
   self._args.append(read.ucb(f)&0x3f)#p2
   if DEBUG:
     print(u'APS: --> {:#d},{:#d}>'.format(self._args[0], self._args[1]).encode('utf-8'))
Esempio n. 44
0
 def __init__(self, f):
   # read the single byte paramter for now but ignore its effect on text placement
   # TODO: implement proper screen text placement
   read.ucb(f)
Esempio n. 45
0
 def __init__(self, f):
     self._args = []
     p1 = read.ucb(f)
     self._args.append(p1)
     if p1 == 0x20:
         self._args.append(read.ucb(f))
Esempio n. 46
0
 def __init__(self, f):
     self._code = read.ucb(f)
     self._start = False
     if self._code & 0x1:
         self._start = True
Esempio n. 47
0
 def __init__(self, f):
     # read the single byte paramter for now but ignore its effect on text placement
     # TODO: implement proper screen text placement
     read.ucb(f)
Esempio n. 48
0
 def __init__(self, b, f):
     self._args = []
     self._args.append(b)
     self._args.append(read.ucb(f))