コード例 #1
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)
コード例 #2
0
ファイル: ts.py プロジェクト: 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)
        ]
コード例 #3
0
ファイル: ts.py プロジェクト: 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)]
コード例 #4
0
ファイル: data_group.py プロジェクト: johnoneil/arib
  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)
コード例 #5
0
ファイル: ts.py プロジェクト: 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)]
コード例 #6
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))
コード例 #7
0
ファイル: data_group.py プロジェクト: Miliox/arib
 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)
コード例 #8
0
ファイル: data_group.py プロジェクト: lvella/arib
 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)
コード例 #9
0
ファイル: ts.py プロジェクト: 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)]