1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2019 Intel Corporation. All rights reserved. 4 * 5 * Author: Artur Kloniecki <arturx.kloniecki@linux.intel.com> 6 */ 7 8 /** 9 * \file include/sof/audio/mux.h 10 * \brief Multiplexer component header file 11 * \authors Artur Kloniecki <arturx.kloniecki@linux.intel.com> 12 */ 13 14 #ifndef __SOF_AUDIO_MUX_H__ 15 #define __SOF_AUDIO_MUX_H__ 16 17 #if CONFIG_COMP_MUX 18 19 #include <sof/common.h> 20 #include <sof/platform.h> 21 #include <sof/trace/trace.h> 22 #include <sof/ut.h> 23 #include <user/trace.h> 24 #include <stdint.h> 25 26 struct comp_buffer; 27 struct comp_dev; 28 29 /** \brief Supported streams count. */ 30 #define MUX_MAX_STREAMS 4 31 32 /** guard against invalid amount of streams defined */ 33 STATIC_ASSERT(MUX_MAX_STREAMS < PLATFORM_MAX_STREAMS, 34 unsupported_amount_of_streams_for_mux); 35 36 struct mux_copy_elem { 37 uint32_t stream_id; 38 uint32_t in_ch; 39 uint32_t out_ch; 40 41 void *dest; 42 void *src; 43 44 uint32_t dest_inc; 45 uint32_t src_inc; 46 }; 47 48 struct mux_look_up { 49 uint32_t num_elems; 50 struct mux_copy_elem copy_elem[PLATFORM_MAX_CHANNELS]; 51 }; 52 53 struct mux_stream_data { 54 uint32_t pipeline_id; 55 uint8_t num_channels_deprecated; /* deprecated in ABI 3.15 */ 56 uint8_t mask[PLATFORM_MAX_CHANNELS]; 57 58 uint8_t reserved[(20 - PLATFORM_MAX_CHANNELS - 1) % 4]; // padding to ensure proper alignment of following instances 59 }; 60 61 typedef void(*demux_func)(struct comp_dev *dev, struct audio_stream *sink, 62 const struct audio_stream *source, uint32_t frames, 63 struct mux_look_up *look_up); 64 typedef void(*mux_func)(struct comp_dev *dev, struct audio_stream *sink, 65 const struct audio_stream **sources, uint32_t frames, 66 struct mux_look_up *look_up); 67 68 /** 69 * \brief Mux/Demux component config structure. 70 * 71 * The multiplexer/demultiplexer component copies its input audio channels 72 * into output audio channels according to a specific routing matrix. 73 * Multiplexer has multiple input audio streams and a single audio output 74 * stream. Demultiplexer has a single input stream and multiple output streams. 75 * 76 * Struct sof_mux_config includes array of mux_stream_data struct elements - 77 * streams[]. Each element of streams[] array refers to streams on "many" side 78 * of mux/demux component i.e. input streams for mux and output streams for 79 * demux. 80 * 81 * Struct mux_stream_data consists mask[] array. 82 * In the mux case, one mask[] element per input channel - each mask shows, to 83 * which output channel data should be copied. 84 * In the demux case, one mask[] element per output channel - each mask shows, 85 * from which input channel data should be taken. 86 * 87 * Mux example: 88 * Assuming that below mask array refers to x input stream: 89 * mask[] = { 0b00000001, 90 * 0b00000100 } 91 * it means that: 92 * - first input channel of stream x (mask[0]) will be copied to first output 93 * channel (0b00000001 & BIT(0)); 94 * - second input channel of stream x (mask[1]) will be copied to third output 95 * channel (0b00000100 & BIT(2)). 96 * 97 * Demux example: 98 * Assuming that below mask array refers to x output stream: 99 * mask[] = { 0b00000001, 100 * 0b00000100 } 101 * it means that: 102 * - first input channel (0b00000001 & BIT(0)) will be copied to first output 103 * (mask[0]) channel of stream x; 104 * - third input channel (0b00000100 & BIT(2)) will be copied to second output 105 * (mask[1]) channel of stream x. 106 */ 107 struct sof_mux_config { 108 uint16_t frame_format_deprecated; /* deprecated in ABI 3.15 */ 109 uint16_t num_channels_deprecated; /* deprecated in ABI 3.15 */ 110 uint16_t num_streams; 111 112 uint16_t reserved; // padding to ensure proper alignment 113 114 struct mux_stream_data streams[]; 115 }; 116 117 struct comp_data { 118 union { 119 mux_func mux; 120 demux_func demux; 121 }; 122 123 struct mux_look_up lookup[MUX_MAX_STREAMS]; 124 struct mux_look_up active_lookup; 125 struct sof_mux_config config; 126 }; 127 128 struct comp_func_map { 129 uint16_t frame_format; 130 mux_func mux_proc_func; 131 demux_func demux_proc_func; 132 }; 133 134 extern const struct comp_func_map mux_func_map[]; 135 136 void mux_prepare_look_up_table(struct comp_dev *dev); 137 void demux_prepare_look_up_table(struct comp_dev *dev); 138 139 mux_func mux_get_processing_function(struct comp_dev *dev); 140 demux_func demux_get_processing_function(struct comp_dev *dev); 141 142 #ifdef UNIT_TEST 143 void sys_comp_mux_init(void); 144 145 #if CONFIG_FORMAT_S16LE 146 int32_t calc_sample_s16le(const struct audio_stream *source, 147 uint32_t offset, uint8_t mask); 148 #endif /* CONFIG_FORMAT_S16LE */ 149 #if CONFIG_FORMAT_S24LE 150 int32_t calc_sample_s24le(const struct audio_stream *source, 151 uint32_t offset, uint8_t mask); 152 #endif /* CONFIG_FORMAT_S24LE */ 153 #if CONFIG_FORMAT_S32LE 154 int64_t calc_sample_s32le(const struct audio_stream *source, 155 uint32_t offset, uint8_t mask); 156 #endif /* CONFIG_FORMAT_S32LE */ 157 #endif /* UNIT_TEST */ 158 159 #endif /* CONFIG_COMP_MUX */ 160 161 #endif /* __SOF_AUDIO_MUX_H__ */ 162