def __init__(self, **kwargs): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log inherit_docstring(self) DefaultValidatingDraft4Validator(PARAM_SCHEMA).validate(kwargs) self.__helper = argparse.Namespace() # helper modules self.__helper.uut = get_instance('uut') self.__helper.hydra_prot = get_instance('hydra_protocol') self.__helper.kalcmd = get_instance('kalcmd') self.__config = argparse.Namespace() # configuration values self.__config.service_tag = kwargs.get(SERVICE_TAG) self.__config.hci_handle = kwargs.get(HCI_HANDLE, self.__config.service_tag) self.__config.wallclock_accuracy = kwargs.get(WALLCLOCK_ACCURACY) self.__config.wallclock_handle = kwargs.get(WALLCLOCK_HANDLE) self.__config.wallclock_offset = kwargs.get(WALLCLOCK_OFFSET) self.__config.next_slot_time = kwargs.get(NEXT_SLOT_TIME) self.__config.role = kwargs.get(ROLE) self.__config.air_compression_factor = kwargs.get(AIR_COMPRESSION_FACTOR) self.__config.air_buffer_size = kwargs.get(AIR_BUFFER_SIZE) self.__config.air_packet_length = kwargs.get(AIR_PACKET_LENGTH) self.__config.tesco = kwargs.get(TESCO) self.__config.wesco = kwargs.get(WESCO) self.__config.slot_occupancy = kwargs.get(SLOT_OCCUPANCY) # calculate/update other parameters self.__config.wallclock_period = \ WALLCLOCK_UPDATE_PERIOD * (1 + self.__config.wallclock_accuracy / 1e6) if self.__config.role == ROLE_SLAVE: self.__config.to_air_latency = (self.__config.wesco + 1) * \ TIMESLOT_DURATION_US + TIMESLOT_FRACTION self.__config.from_air_latency = -125 else: self.__config.to_air_latency = -125 self.__config.from_air_latency = (self.__config.wesco + 1) * \ TIMESLOT_DURATION_US + TIMESLOT_FRACTION self.__data = argparse.Namespace() # data values self.__data.started = False # service has not been started self.__data.channel_ready = [False, False] # none of the possible channels are ready yet self.__data.bt_clock = 0 # bluetooth wallclock (2*slot) self.__data.wallclock_remain = 0 # remainder for bluetooth clock (usec units) self.__data.wallclock_timer_id = None self.__data.to_air_read_handle = None self.__data.to_air_write_handle = None self.__data.to_air_aux_handle = None self.__data.from_air_read_handle = None self.__data.from_air_write_handle = None self.__data.from_air_aux_handle = None self.__data.msg_handler = self.__helper.hydra_prot.install_message_handler( self._message_received) if kwargs: self._log.warning('unknown kwargs:%s', str(kwargs))
def __init__(self, stream_type, *_, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self._log_param = OrderedDict() if not hasattr( self, '_log_param') else self._log_param self._log_param['id'] = None self._kalcmd = get_instance('kalcmd') self._kalcmd_stream = get_instance('kalcmd_stream') self._stream_type = stream_type self._stream_id = None self.__callback = {} self.__callback[CALLBACK_EOF] = self.eof self.__callback[CALLBACK_DATA_EVENT] = kwargs.pop( 'callback_data_event', None) # initialise default values self.__parameters = {} for entry in self.__param_schema: if entry in kwargs or self.__param_schema[entry][ PARAM_DEFAULT] is not None: self.__parameters[entry] = kwargs.pop( entry, self.__param_schema[entry][PARAM_DEFAULT]) if stream_type == STREAM_TYPE_SOURCE: self.__parameters[STREAM_DIRECTION] = STREAM_DIRECTION_READ else: self.__parameters[STREAM_DIRECTION] = STREAM_DIRECTION_WRITE # for kalsim handled stream provide parameters to StreamBase if they are # not already provided if self.__parameters[STREAM_BACKING] == STREAM_BACKING_FILE: if (STREAM_NAME not in kwargs and STREAM_FILENAME in self.__parameters and self.__parameters[STREAM_FILENAME]): kwargs[STREAM_NAME] = self.__parameters[STREAM_FILENAME] if STREAM_RATE not in kwargs and self.__parameters[ STREAM_FLOW_CONTROL_RATE]: kwargs[STREAM_RATE] = self.__parameters[ STREAM_FLOW_CONTROL_RATE] if STREAM_DATA_WIDTH not in kwargs and self.__parameters[ STREAM_FORMAT]: kwargs[STREAM_DATA_WIDTH] = self.__parameters[STREAM_FORMAT] # verify whether the resource file exists or not,if not then raise meaningful # trace output, the traceback will provide the info about file status # os.stat() is used to find whether file exists or not if (stream_type == STREAM_TYPE_SOURCE and self.__parameters[STREAM_BACKING] == STREAM_BACKING_FILE): os.stat(self.__parameters[STREAM_FILENAME]) super(KalsimStream, self).__init__(stream_type, **kwargs)
def _compute_audioslot(self, stream_type): # to compute the audioslot we have to count how many instances have # we registered of name stream_XXX that are of our type (source or sink) # and that are of type StreamHw val = 0 names = get_instance_names() for stream_name in names: if stream_name.startswith('stream_'): val += sum([ get_instance(stream_name, ind).get_type() == stream_type for ind in range(get_instance_num(stream_name)) if isinstance(get_instance(stream_name, ind), StreamHw) ]) return val
def __init__(self, hydra_protocol, service_type, device_type, service_tag, **kwargs): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log self._hydra_protocol = hydra_protocol self._kalcmd = get_instance('kalcmd') self._service_type = service_type self._device_type = device_type self._service_tag = service_tag self._buffer_size = None self._buffer_width = None self._md_buffer_size = None self._md_buffer_width = None self._kick_required = kwargs.pop('kick_required', 0) self._space_handler = kwargs.pop('space_handler', None) self._kwargs = kwargs self._started = False self.param = argparse.Namespace() self.param.endpoint_id = None self.param.data_rd_handle = None self.param.data_wr_handle = None self.param.meta_data_rd_handle = None self.param.meta_data_wr_handle = None self.param.kick_status_bits = None self.param.kick_block_id = None self._msg_handler = self._hydra_protocol.install_message_handler(self._message_received)
def create(self): ''' Start service and create stream TODO: If stream_type of a SCO Processing Service instance is easily available, raise a RuntimeError if we are trying to start two instances with the same stream_type and hci_handle. ''' if self.__config.stream is not None: stream = get_instance('stream_sco') if stream.get_type() == self.get_type(): raise RuntimeError('trying to start two sco streams of same type') self.__data.sco_service = stream.get_sco_service() else: if self.__config.service_tag is not None: service_tag = self.__config.service_tag else: service_tag = get_instance_num('sco_processing_service') + 100 self.__data.sco_service = HydraScoProcessingService(service_tag=service_tag, **self._sco_kwargs) register_instance('sco_processing_service', self.__data.sco_service) self.__data.sco_service.start() self.__data.sco_service.config() return super(StreamHydraSco, self).create()
def _background_thread(self): self._log.debug('acat firmware log background thread starting') processor = 0 proc = 'p%s' % (processor) proc_analysis = getattr(self._acat_session, proc) analysis = proc_analysis.available_analyses[ANALYSIS_DEBUG_LOG] analysis.set_debug_log_level(self._firmware_log_level) def callback(timer_id): _ = timer_id try: data = analysis.get_debug_log() if data: for entry in data: self._log_acat.info( str(entry.decode('utf-8')).rstrip('\r\n')) except Exception: # pylint:disable=broad-except self._log.error('unable to get firmware log') if not self._lock.is_set(): uut.timer_add_relative(self._firmware_log_timer_update_period, callback=callback) time.sleep(1) # give time for uut to be up and running uut = get_instance('uut') uut.timer_add_relative(self._firmware_log_timer_update_period, callback=callback) while True: time.sleep(0.2) if self._lock.is_set(): break self._log.info('acat firmware log background thread exiting')
def start(self): ''' Starts streaming all source and sink streams in the already built internal graph ''' # operators for operator in self._inst.op: if operator is not None: operator.start() kalcmd = get_instance('kalcmd') with kalcmd.get_lock_object(): # sink streams for ind, stream in enumerate(self._inst.st): if stream is not None: _, stream_type, _, _ = self._graph.get_stream(None, ind) if stream_type == STREAM_TYPE_SINK: stream.start() # source streams for ind, stream in enumerate(self._inst.st): if stream is not None: _, stream_type, _, _ = self._graph.get_stream(None, ind) if stream_type == STREAM_TYPE_SOURCE: stream.start() # koperators for operator in self._inst.kop: if operator is not None: operator.start()
def __init__(self, stream_type, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log inherit_docstring(self) # initialise default values self.__parameters = {} for entry in self.__param_schema: if entry in kwargs or self.__param_schema[entry][ PARAM_DEFAULT] is not None: self.__parameters[entry] = kwargs.pop( entry, self.__param_schema[entry][PARAM_DEFAULT]) # only if the external packetiser is not used then we can handle backing and control drive if not self.__parameters[EXTERNAL_PACKETISER]: raise RuntimeError( 'hydra_audio_metadata requires external packetiser') # this instance is associated with a hydra_audio stream self._stream_hydra_audio = get_instance('stream_hydra_audio', self.__parameters[HYDRA_AUDIO]) self._hydra_kwargs = kwargs self._hydra_kwargs.update({ HYDRA_TYPE: HYDRA_TYPE_SUBSYSTEM, HYDRA_BAC_HANDLE: 0, # we will modify this when we know the handle STREAM_FLOW_CONTROL_BLOCK_SIZE: 1, }) super(StreamHydraAudioMetadata, self).__init__(stream_type, **self._hydra_kwargs)
def __init__(self, cap, kymera, *args, **kwargs): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log inherit_docstring(self) self._kymera = kymera cap_data = get_instance('capability_description') try: self._capability = get_capability_name(cap_data, cap) except Exception: # pylint: disable=broad-except self._capability = str(cap) self.cap_id = get_capability_id(cap_data, cap) self._cap_msg = get_capability_msgs(cap_data, cap) self._op_id = None self.__args = [] for entry in args: if not isinstance(entry, list): raise RuntimeError('arg %s invalid should be a list' % (entry)) elif len(entry) != 2: raise RuntimeError('arg %s invalid should be list of 2 elements' % (entry)) elif not isinstance(entry[1], list): raise RuntimeError('arg %s invalid should be a list' % (entry[1])) elif not isinstance(entry[0], int) and entry[0] not in self._cap_msg: raise RuntimeError('arg %s invalid msg unknown' % (entry[0])) self.__args.append(entry) for entry in kwargs: if not isinstance(kwargs[entry], list): raise RuntimeError('kwarg %s invalid should be a list' % (kwargs[entry])) elif entry not in self._cap_msg: raise RuntimeError('kwarg %s invalid msg unknown' % (entry)) self.__args.append([entry, kwargs[entry]]) super(CapabilityGeneric, self).__init__(cap, kymera, *args, **kwargs)
def __init__(self, stream_type, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log inherit_docstring(self) DefaultValidatingDraft4Validator(PARAM_SCHEMA).validate(kwargs) self.__helper = argparse.Namespace() # helper modules self.__helper.uut = get_instance('uut') self.__config = argparse.Namespace() # configuration values self.__config.backing = kwargs.pop(BACKING) self.__config.device = kwargs.pop(DEVICE, 0) # currently unused self.__config.callback_data_received = None # backing=data sink stream callback self.__config.delay = None self.__data = argparse.Namespace() # data values self.__data.loop_timer_id = None # timer when looping self.__data.loop = 1 # number of loops pending self.__data.source_packetiser = None # source with packet based streaming self.__data.sink_timer_id = None # sink manual streaming timer id self.__data.sink_timer_remain = 0.0 # sink manual timer remainder self.__data.sink_audio_buffer = None # sink manual streaming audio data buffer if self.__config.backing == BACKING_FILE: self.__config.filename = kwargs.pop(FILENAME) if stream_type == STREAM_TYPE_SOURCE: self.__config.delay = kwargs.pop(DELAY, DELAY_DEFAULT) else: self.__config.delay = None self.__config.loop = kwargs.pop(LOOP, LOOP_DEFAULT) self.__config.user_callback_eof = kwargs.get( CALLBACK_EOF, lambda *args, **kwargs: None) params = getattr(self, '_init_%s_file' % (stream_type))(kwargs) params[CALLBACK_EOF] = self.__eof # required for loop else: # BACKING_DATA self.__config.sample_width = kwargs.pop(SAMPLE_WIDTH) if stream_type == STREAM_TYPE_SINK: self.__config.sample_rate = kwargs.pop(SAMPLE_RATE) self.__config.frame_size = kwargs.pop(FRAME_SIZE, FRAME_SIZE_DEFAULT) self.__config.callback_consume = kwargs.pop( CALLBACK_CONSUME, None) else: self.__config.frame_size = None self.__config.loop = 1 params = get_user_stream_config(self.__config.sample_width) self.__parameters = {} self.__parameters[HYDRA_TYPE] = HYDRA_TYPE_AUDIO_SLOT self.__parameters[HYDRA_AUDIOSLOT] = self._compute_audioslot( stream_type) if kwargs: self._log.warning('unknown kwargs:%s', str(kwargs)) super(StreamPcm, self).__init__(stream_type, **params)
def __new__(cls, stream_type, *args, **kwargs): filename = kwargs.pop(FILENAME) subinterface = kwargs.pop(SUBINTERFACE) channel = kwargs.pop(CHANNEL, 0) if stream_type != STREAM_TYPE_SOURCE: raise RuntimeError( 'stream_type:%s not supported in packet_metadata streams') audio_file = audio_get_instance(filename) # metadata data metadata = audio_file.get_metadata_stream_data(channel) # metadata packet based info packet_info = [] if (hasattr(audio_file, 'get_packet_data_size') and audio_file.get_packet_data_size('metadata', channel)): packet_info = audio_file.get_packet_data('metadata', channel) else: logging.getLogger(__name__).warning( 'filename %s metadata channel %s not found', filename, channel) logging.getLogger(__name__).info('metadata packets:%s', len(packet_info)) # StreamBase parameters kwargs[STREAM_NAME] = filename kwargs[STREAM_RATE] = 0 kwargs[STREAM_DATA_WIDTH] = 8 kwargs[STREAM_DATA] = metadata # the packetiser will control the streaming of data # here we configure kalsim for insert/extract to stream kwargs[STREAM_BACKING] = STREAM_BACKING_KALCMD kwargs[STREAM_FLOW_CONTROL_DRIVE] = STREAM_FLOW_CONTROL_DRIVE_KALCMD kwargs[EXTERNAL_PACKETISER] = True # in the case of audioslot streams this has to be set in spite of # being kalcmd driven and backed and that stream_insert includes the data width kwargs[STREAM_FORMAT] = 8 # instantiate the requested subinterface stream stream_factory = get_instance('stream') instance = stream_factory.get_instance(subinterface, stream_type, *args, **kwargs) # add methods to the stream that will handle the packet based streaming # pylint: disable=protected-access instance._audio_file = audio_file instance._packetiser = Packetiser(instance, metadata, packet_info) instance.old_start = instance.start instance.start = types.MethodType(start, instance) instance.old_stop = instance.stop instance.stop = types.MethodType(stop, instance) return instance
def __init__(self, stream_type, **kwargs): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log inherit_docstring(self) self._kalcmd = get_instance('kalcmd') # initialise default values self.__parameters = {} for entry in self.__param_schema: if entry in kwargs or self.__param_schema[entry][PARAM_DEFAULT] is not None: self.__parameters[entry] = kwargs.pop(entry, self.__param_schema[entry][PARAM_DEFAULT]) super(StreamHydra, self).__init__(stream_type, **kwargs)
def __init__(self, firmware, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self._log.info('init firmware:%s kwargs:%s', firmware, str(kwargs)) self._log_acat = logging.getLogger('fw_log') self._transport = kwargs.pop(TRANSPORT, TRANSPORT_KALSIM) self._firmware = firmware self._interactive = kwargs.pop(INTERACTIVE, False) self._path = kwargs.pop(PATH, None) self._kal_path = kwargs.pop(KAL_PATH, None) self._bundle = kwargs.pop(BUNDLE, BUNDLE_DEFAULT) self._firmware_log_enable = kwargs.pop(FIRMWARE_LOG_ENABLE, FIRMWARE_LOG_ENABLE_DEFAULT) self._firmware_log_level = kwargs.pop(FIRMWARE_LOG_LEVEL, FIRMWARE_LOG_LEVEL_DEFAULT) self._firmware_log_timer_update_period = kwargs.pop( FIRMWARE_LOG_TIMER_UPDATE_PERIOD, FIRMWARE_LOG_TIMER_UPDATE_PERIOD_DEFAULT) self._analyses = kwargs.pop(ANALYSES, ANALYSES_DEFAULT) self._lock = None self._data_background_thread = None if self._path: par_path = os.path.abspath(os.path.join(self._path, os.pardir)) if par_path not in sys.path: sys.path.insert(1, par_path) import ACAT # @UnresolvedImport pylint: disable=import-error if self._kal_path: kal_dir = os.path.abspath(self._kal_path) else: import kal_python_tools # @UnresolvedImport pylint: disable=import-error kal_dir = os.path.abspath( os.path.dirname(kal_python_tools.__file__)) self._acat = ACAT args = ['-i'] if self._interactive else [] args += ['-b', self._firmware, '-t', kal_dir] args += ['-s', self._transport] if self._transport == TRANSPORT_KALSIM: kalcmd = get_instance('kalcmd') self._kalcmd_acat = KalcmdAcat(kalcmd) args += ['-a', self._kalcmd_acat] for entry in self._bundle: args.append('-j') args.append(entry) self._acat.parse_args(args) self._acat_session = None
def __init__(self, stream, data, packet): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log self._stream = argparse.Namespace() self._stream.stream = stream # self._stream.type = stream.get_type() # should be source self._stream.data = data self._stream.packet = packet self._uut = get_instance('uut') self._state = STATE_STOPPED self._timer_id = None self._packet_index = 0
def __init__(self, stream_type, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log inherit_docstring(self) self._helper = argparse.Namespace() self._helper.uut = get_instance('uut') self._helper.hydra_prot = get_instance('hydra_protocol') self._helper.audio_hydra = None self._msg_handler = None self._total_samples = None self._sent_samples = None # initialise default values self.__parameters = {} for entry in self.__param_schema: if entry in kwargs or self.__param_schema[entry][ PARAM_DEFAULT] is not None: self.__parameters[entry] = kwargs.pop( entry, self.__param_schema[entry][PARAM_DEFAULT]) self._hydra_kwargs = kwargs self._hydra_kwargs.update({ HYDRA_TYPE: HYDRA_TYPE_SUBSYSTEM, HYDRA_BAC_HANDLE: 0, # we will modify this when we know the handle STREAM_FLOW_CONTROL_BLOCK_SIZE: 1, }) # only if the external packetiser is not used then we can handle backing and control drive if not self.__parameters[EXTERNAL_PACKETISER]: self._hydra_kwargs.update({ STREAM_FLOW_CONTROL_DRIVE: STREAM_FLOW_CONTROL_DRIVE_KALCMD, STREAM_BACKING: STREAM_BACKING_FILE, }) super(StreamHydraAudio, self).__init__(stream_type, **self._hydra_kwargs)
def __init__(self, firmware, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self._log.info('init firmware:%s kwargs:%s', firmware, str(kwargs)) self._log_acat = logging.getLogger('fw_log') self._firmware = firmware self._interactive = kwargs.pop(INTERACTIVE, False) self._path = kwargs.pop(PATH, None) self._kal_path = kwargs.pop(KAL_PATH, None) self._bundle = kwargs.pop(BUNDLE, []) self._firmware_log_enable = kwargs.pop(FIRMWARE_LOG_ENABLE, FIRMWARE_LOG_ENABLE_DEFAULT) self._firmware_log_level = kwargs.pop(FIRMWARE_LOG_LEVEL, FIRMWARE_LOG_LEVEL_DEFAULT) self._firmware_log_timer_update_period = kwargs.pop( FIRMWARE_LOG_TIMER_UPDATE_PERIOD, FIRMWARE_LOG_TIMER_UPDATE_PERIOD_DEFAULT) self._lock = None self._data_background_thread = None if not six.PY2: raise RuntimeError('acat is currently only supported for python 2') if self._path: par_path = os.path.abspath(os.path.join(self._path, os.pardir)) if not par_path in sys.path: sys.path.insert(1, par_path) import ACAT # @UnresolvedImport pylint: disable=import-error if self._kal_path: kal_dir = self._kal_path else: import kal_python_tools # @UnresolvedImport pylint: disable=import-error kal_dir = os.path.dirname(kal_python_tools.__file__) self._acat = ACAT kalcmd = get_instance('kalcmd') self._kalcmd_acat = KalcmdAcat(kalcmd) args = ['-i'] if self._interactive else [] args += ['-b', self._firmware, '-t', kal_dir, '-a', self._kalcmd_acat] if self._bundle: args.append('-j') args += self._bundle self._acat.parse_args(args) self._acat_session = None
def __init__(self, hydra_protocol, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self.__config = argparse.Namespace() self.__config.hydra_protocol = hydra_protocol self.__config.uut = get_instance('uut') self.__config.directory = kwargs.pop('directory', None) self.__config.prefix = kwargs.pop('prefix', '') self.__data = argparse.Namespace() self.__data.session = [] self.__data.handle = [] self.__data.last_handle = 0 self.__data.file_data = {} self.__data.pending = [] self.__data.chip_ready = False # load file contents in a dictionary # we are only supporting read access and files are small so this is a simple way to # handle our ftp server if self.__config.directory is not None: wildcard = '%s*.%s' % (self.__config.prefix, FILE_EXTENSION) files = glob.glob(os.path.join(self.__config.directory, wildcard)) for filename in files: with open(filename, 'rb') as handler: self.__data.file_data[os.path.basename( filename)] = handler.read() self._log.info('ftp_server found filename:%s', filename) # install message handler to receive messages from kymera self._msg_handler = self.__config.hydra_protocol.install_message_handler( self._message_received) # send indication to kymera meaning we are ready to receive requests self.__config.hydra_protocol.send_service_advice_indication() # wait for kymera to signal it is ready, if it timeouts we just log and continue timer0 = self.__config.uut.timer_get_time() while self.__config.uut.timer_get_time() - timer0 < CHIP_READY_TIMEOUT: self.__config.uut.timer_wait_relative(0.1) if self.__data.chip_ready: break else: self._log.warning('chip ready message not received')
def get_buffer_stats(read_handle, write_handle, buffer_size=None, buffer_width=None): ''' Get kalcmd buffer statistics The values returned by Kalsim for handle offsets and buffer sizes are in octets and include all the octets in the buffer, useful or wasted. If the BAC sample size is configured to 8|16|24_BIT_UNPACKED a part of the buffer is wasted (e.g. 16_BIT_UNPACKED, only half of the buffer contains useful data - the lower 16 bits of each 32-bit word). Args: read_handle (int): Read BAC handle write_handle (int): Write BAC handle buffer_size (int): Buffer size or None to autodetect buffer_width (int): Buffer width or None to autodetect Returns: tuple: int: Used bytes int: Free bytes ''' kalcmd = get_instance('kalcmd') if buffer_size is None: buffer_size = kalcmd.get_buffer_size(read_handle) if buffer_width is None: buffer_width = kalcmd.get_handle_sample_size(read_handle) rd_offset = kalcmd.get_handle_offset(read_handle) wr_offset = kalcmd.get_handle_offset(write_handle) if wr_offset >= rd_offset: used = wr_offset - rd_offset else: used = buffer_size - (rd_offset - wr_offset) free = buffer_size - used - 1 # FIXME this might only work for unpacked data used = int((used * buffer_width) / 32) free = int((free * buffer_width) / 32) return used, free
def map_endpoint(interface, endpoint_type, kwargs): ''' Remap kymera endpoint Args: interface (str): Interface type endpoint_type (str): Type of endpoint (source or sink) kwargs (dict): Endpoint parameters Returns: dict: Modified (remapped) endpoint parameters ''' outp = kwargs if get_instance_num('uut_mapping'): mapping = get_instance('uut_mapping') entry = copy.deepcopy(kwargs) inp = {'interface': interface, 'type': endpoint_type} inp.update(entry) instance0 = inp.get('instance', None) channel0 = inp.get('channel', None) outp = mapping.map(inp) if outp: instance1 = outp.get('instance', None) channel1 = outp.get('channel', None) logging.getLogger(__name__).info( 'interface:%s endpoint_type:%s instance:%s channel:%s remapped to ' 'instance:%s channel:%s', interface, endpoint_type, instance0, channel0, instance1, channel1) else: outp = {} entry.update(outp) outp = entry outp.pop('interface', None) outp.pop('type', None) return outp
def get_id(self): stream = get_instance('stream_l2cap', self.__stream) return stream.get_endpoint_id()
def __new__(cls, stream_type, *args, **kwargs): filename = kwargs.pop(FILENAME) subinterface = kwargs.pop(SUBINTERFACE) stream_kwargs = {} stream_kwargs[CHANNELS] = kwargs.pop(CHANNELS, 1) stream_kwargs[SAMPLE_RATE] = kwargs.pop(SAMPLE_RATE, 8000) stream_kwargs[SAMPLE_WIDTH] = kwargs.pop(SAMPLE_WIDTH, 16) channel = kwargs.pop(CHANNEL, 0) if stream_type != STREAM_TYPE_SOURCE: raise RuntimeError( 'stream_type:%s not supported in packet_audio streams') audio_file = audio_get_instance(filename, **stream_kwargs) stream_kwargs[CHANNELS] = audio_file.get_audio_stream_num() stream_kwargs[SAMPLE_RATE] = audio_file.get_audio_stream_sample_rate( channel) stream_kwargs[SAMPLE_WIDTH] = audio_file.get_audio_stream_sample_width( channel) # audio data audio_data = audio_file.get_audio_stream_data(channel) # audio packet based data if (hasattr(audio_file, 'get_packet_data_size') and audio_file.get_packet_data_size('audio', channel)): packet_info = audio_file.get_packet_data('audio', channel) else: # we do not have packet based information so we will stream the file # at the right rate in packets of 1 msec # FIXME this does not work for 44.1 KHz sample_rate_khz = int(stream_kwargs[SAMPLE_RATE] / 1000) packet_info = [[ 1000, sample_rate_khz * pos, sample_rate_khz ] for pos in range(int(len(audio_data) / sample_rate_khz))] # FIXME include any pending bytes at the end # do not delay first packet if len(packet_info): packet_info[0][0] = 0 logging.getLogger(__name__).info('metadata packets:%s', len(packet_info)) # StreamBase parameters kwargs[STREAM_NAME] = filename kwargs[STREAM_RATE] = stream_kwargs[SAMPLE_RATE] kwargs[STREAM_DATA_WIDTH] = stream_kwargs[SAMPLE_WIDTH] kwargs[STREAM_DATA] = audio_data # the packetiser will control the streaming of data # here we configure kalsim for insert/extract to stream kwargs[STREAM_BACKING] = STREAM_BACKING_KALCMD kwargs[STREAM_FLOW_CONTROL_DRIVE] = STREAM_FLOW_CONTROL_DRIVE_KALCMD kwargs[EXTERNAL_PACKETISER] = True # in the case of audioslot streams this has to be set in spite of # being kalcmd driven and backed and that stream_insert includes the data width kwargs[STREAM_FORMAT] = audio_file.get_audio_stream_sample_width( channel) # instantiate the requested subinterface stream stream_factory = get_instance('stream') instance = stream_factory.get_instance(subinterface, stream_type, *args, **kwargs) # add methods to the stream that will handle the packet based streaming # pylint: disable=protected-access instance._audio_file = audio_file instance._packetiser = Packetiser(instance, audio_data, packet_info) instance.old_start = instance.start instance.start = types.MethodType(start, instance) instance.old_stop = instance.stop instance.stop = types.MethodType(stop, instance) return instance
def __init__(self): self._cap_description = get_instance('capability_description')
def _compute_audioslot(self, stream_type): return sum([ get_instance('stream_pcm', ind).get_type() == stream_type for ind in range(get_instance_num('stream_pcm')) ])
def create(self, *_, **__): stream = get_instance('stream_sco', self.__stream) self._create('sco', [stream.get_hci_handle(), 0x0000])
def get_id(self): stream = get_instance('stream_timestamped', self.__stream) return stream.get_endpoint_id()
def __init__(self, stream_type, **kwargs): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log inherit_docstring(self) DefaultValidatingDraft4Validator(PARAM_SCHEMA).validate(kwargs) self.__helper = argparse.Namespace() # helper modules self.__helper.uut = get_instance('uut') self.__helper.hydra_prot = get_instance('hydra_protocol') self.__config = argparse.Namespace() # configuration values self.__config.backing = kwargs.pop(BACKING) self.__config.callback_data_received = None # backing=data sink stream callback self.__config.delay = None self.__config.kick_enable = kwargs.pop(KICK_ENABLE, KICK_ENABLE_DEFAULT) self.__config.device_type = kwargs.pop(DEVICE_TYPE, DEVICE_TYPE_DEFAULT) self.__config.service_tag = kwargs.pop(SERVICE_TAG, SERVICE_TAG_DEFAULT) self.__config.data_buffer_size = kwargs.pop(DATA_BUFFER_SIZE, DATA_BUFFER_SIZE_DEFAULT) self.__config.metadata_enable = kwargs.pop(METADATA_ENABLE, METADATA_ENABLE_DEFAULT) self.__config.metadata_format = kwargs.pop(METADATA_FORMAT, METADATA_FORMAT_DEFAULT) # self.__config.metadata_channel = kwargs.pop(METADATA_CHANNEL, METADATA_CHANNEL_DEFAULT) self.__config.metadata_buffer_size = kwargs.pop( METADATA_BUFFER_SIZE, METADATA_BUFFER_SIZE_DEFAULT) self.__config.ttp_delay = kwargs.pop(TTP_DELAY, TTP_DELAY_DEFAULT) self.__data = argparse.Namespace() self.__data.loop_timer_id = None # timer when looping self.__data.loop = 1 self.__data.source_packetiser = None # source with packet based streaming self.__data.source_metadata = None self.__data.source_timer_id = None self.__data.sink_timer_id = None # sink manual streaming timer id self.__data.sink_timer_remain = 0.0 # sink manual timer remainder self.__data.sink_audio_buffer = None # sink manual streaming audio data buffer self.__data.stream2 = None self.__data.total_samples = 0 self.__data.sent_samples = 0 if self.__config.backing == BACKING_FILE: self.__config.filename = kwargs.pop(FILENAME) if stream_type == STREAM_TYPE_SOURCE: self.__config.delay = kwargs.pop(DELAY, DELAY_DEFAULT) else: self.__config.delay = None self.__config.loop = kwargs.pop(LOOP, LOOP_DEFAULT) self.__config.user_callback_eof = kwargs.get( CALLBACK_EOF, lambda *args, **kwargs: None) params = getattr(self, '_init_%s_file' % (stream_type))(kwargs) params[CALLBACK_EOF] = self.__eof # required for loop else: # BACKING_DATA self.__config.sample_width = kwargs.pop(SAMPLE_WIDTH) if stream_type == STREAM_TYPE_SINK: self.__config.frame_size = kwargs.pop(FRAME_SIZE) self.__config.callback_consume = kwargs.pop( CALLBACK_CONSUME, None) else: self.__config.frame_size = None self.__config.loop = 1 params = get_user_stream_config(self.__config.sample_width) self.__parameters = {} self.__parameters[HYDRA_TYPE] = HYDRA_TYPE_SUBSYSTEM self.__parameters[ HYDRA_BAC_HANDLE] = 0 # we will modify this when we know the handle if self.__config.metadata_enable: kwargs2 = get_user_stream_config(8) kwargs2[HYDRA_TYPE] = HYDRA_TYPE_SUBSYSTEM kwargs2[ HYDRA_BAC_HANDLE] = 0 # we will modify this when we know the handle self.__data.stream2 = StreamHydra(stream_type, **kwargs2) if kwargs: self._log.warning('unknown kwargs:%s', str(kwargs)) super(StreamHydraAudioData, self).__init__(stream_type, **params)
def get_id(self): stream = get_instance('stream_hydra_audio', self.__stream) return stream.get_endpoint_id()