def _init_source_file(self, kwargs): channels = kwargs.pop(CHANNELS, CHANNELS_DEFAULT) channel = kwargs.pop(CHANNEL, CHANNEL_DEFAULT) self.__config.sample_rate = kwargs.pop(SAMPLE_RATE, None) self.__config.sample_width = kwargs.pop(SAMPLE_WIDTH, None) self.__config.frame_size = kwargs.pop(FRAME_SIZE, FRAME_SIZE_DEFAULT) audio_kwargs = { 'channels': channels, # some formats do not require 'sample_rate': self.__config.sample_rate, # some formats do not require 'sample_width': self.__config.sample_width, # some formats do not require } audio_instance = audio_get_instance(self.__config.filename, **audio_kwargs) channels = audio_instance.get_audio_stream_num() # we allow overriding sample_rate from what is in the file self.__config.sample_width = audio_instance.get_audio_stream_sample_width(channel) if channel >= channels: raise RuntimeError('channels:%s channel:%s inconsistency' % (channels, channel)) if audio_instance.get_audio_stream_sample_rate(channel) is None: raise RuntimeError('stream filename:%s sample_rate not set' % (self.__config.filename)) if self.__config.sample_width is None: raise RuntimeError('stream filename:%s sample_width not set' % (self.__config.filename)) # FIXME here we are only supporting streaming manually with kats # might be interesting to add kalsim support in the future whenever is possible self.__data.audio_data = audio_instance.get_audio_stream_data(channel) self.__data.total_samples = len(audio_instance.get_audio_stream_data(channel)) params = get_user_stream_config(self.__config.sample_width) params[STREAM_NAME] = self.__config.filename params[STREAM_RATE] = self.__config.sample_rate # pointless in qwav with packet_info params[STREAM_DATA_WIDTH] = self.__config.sample_width del audio_instance return params
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 _init_source_file(self, kwargs): channels = kwargs.pop(CHANNELS, CHANNELS_DEFAULT) channel = kwargs.pop(CHANNEL, CHANNEL_DEFAULT) self.__config.sample_rate = kwargs.pop(SAMPLE_RATE, None) self.__config.sample_width = kwargs.pop(SAMPLE_WIDTH, None) self.__config.frame_size = kwargs.pop(FRAME_SIZE, FRAME_SIZE_DEFAULT) audio_kwargs = { 'channels': channels, # some formats do not require 'sample_rate': self.__config.sample_rate, # some formats do not require 'sample_width': self.__config.sample_width, # some formats do not require } audio_instance = audio_get_instance(self.__config.filename, **audio_kwargs) channels = audio_instance.get_audio_stream_num() # we allow overriding sample_rate from what is in the file self.__config.sample_width = audio_instance.get_audio_stream_sample_width(channel) if channel >= channels: raise RuntimeError('channels:%s channel:%s inconsistency' % (channels, channel)) if audio_instance.get_audio_stream_sample_rate(channel) is None: raise RuntimeError('stream filename:%s sample_rate not set' % (self.__config.filename)) if self.__config.sample_width is None: raise RuntimeError('stream filename:%s sample_width not set' % (self.__config.filename)) # kalsim supports raw and wav files with only 1 stream in the file at the file designated # sample_rate file_sample_rate = audio_instance.get_audio_stream_sample_rate(channel) if (channels == 1 and not self.__config.filename.endswith('.qwav') and (self.__config.sample_rate == file_sample_rate or self.__config.sample_rate is None)): if self.__config.sample_rate is None: self.__config.sample_rate = file_sample_rate params = get_file_user_stream_config(self.__config.filename, self.__config.sample_rate, self.__config.sample_width) self.__data.total_samples = len(audio_instance.get_audio_stream_data(channel)) else: audio_data = audio_instance.get_audio_stream_data(channel) if self.__config.sample_rate is None: self.__config.sample_rate = file_sample_rate # check if the format supports packet_info and that packet_info actually is there if (hasattr(audio_instance, 'get_packet_data_size') and audio_instance.get_packet_data_size('audio', channel)): packet_info = audio_instance.get_packet_data('audio', channel) else: packet_info = self._build_default_packet_info(audio_data, self.__config.frame_size, self.__config.sample_rate) self.__data.source_packetiser = Packetiser(self, audio_data, packet_info) params = get_user_stream_config(self.__config.sample_width) params[STREAM_NAME] = self.__config.filename params[STREAM_RATE] = self.__config.sample_rate # pointless in qwav with packet_info params[STREAM_DATA_WIDTH] = self.__config.sample_width del audio_instance return params
def _init_sink_file(self, kwargs): self.__config.channels = 1 self.__config.channel = 0 self.__config.sample_rate = kwargs.pop(SAMPLE_RATE) self.__config.sample_width = kwargs.pop(SAMPLE_WIDTH) self.__config.frame_size = kwargs.pop(FRAME_SIZE, FRAME_SIZE_DEFAULT) # kalsim supports raw and wav files with only 1 stream if not self.__config.filename.endswith('.qwav'): params = get_file_user_stream_config(self.__config.filename, self.__config.sample_rate, self.__config.sample_width) else: self.__data.sink_audio_buffer = [] params = get_user_stream_config(self.__config.sample_width) params[STREAM_NAME] = self.__config.filename params[STREAM_RATE] = self.__config.sample_rate params[STREAM_DATA_WIDTH] = self.__config.sample_width return params
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)