2828#include <stddef.h>
2929#include <stdint.h>
3030
31- static int mux_set_values (struct comp_data * cd , struct sof_mux_config * cfg )
31+ static int mux_set_values (struct comp_data * cd , struct sof_ipc_mux_config * cfg )
3232{
3333 uint8_t i ;
3434 uint8_t j ;
35+ uint8_t used_streams ;
36+ uint32_t num_ch_map , ch_index , ext_id , ch_mask ;
37+ uint32_t * data ;
38+
39+ struct mux_stream_data streams [MUX_MAX_STREAMS ];
40+
41+ data = (uint32_t * )& cfg -> streams ;
42+ num_ch_map = * data ++ ;
43+ trace_mux ("num_ch_map = %d" , num_ch_map );
44+ //if (num_ch_map == 0)
45+ // return -EINVAL;
46+
47+ used_streams = 0 ;
48+
49+ for (i = 0 ; i < num_ch_map ; i ++ ) {
50+ ch_index = * data ++ ;
51+ ext_id = * data ++ ;
52+ ch_mask = * data ++ ;
53+
54+ trace_mux ("ch_i = %d, ext_id = %d, ch_m = %d" ,
55+ ch_index , ext_id , ch_mask );
56+
57+ for (j = 0 ; j < used_streams ; j ++ ) {
58+ if (ext_id == streams [j ].pipeline_id )
59+ break ;
60+ }
61+
62+ if (j == used_streams )
63+ used_streams ++ ;
64+
65+ streams [j ].pipeline_id = ext_id ;
66+ streams [j ].mask [ch_index ] = ch_mask ;
67+
68+ data += MAX (__builtin_popcount (ch_mask ), 1 );
69+
70+ trace_mux ("builtin_popcount = %d" , __builtin_popcount (ch_mask ));
71+ }
72+
3573
3674 /* check if number of streams configured doesn't exceed maximum */
3775 if (cfg -> num_streams > MUX_MAX_STREAMS ) {
@@ -45,18 +83,18 @@ static int mux_set_values(struct comp_data *cd, struct sof_mux_config *cfg)
4583 /* check if all streams configured have distinct IDs */
4684 for (i = 0 ; i < cfg -> num_streams ; i ++ ) {
4785 for (j = i + 1 ; j < cfg -> num_streams ; j ++ ) {
48- if (cfg -> streams [i ].pipeline_id ==
49- cfg -> streams [j ].pipeline_id ) {
86+ if (streams [i ].pipeline_id ==
87+ streams [j ].pipeline_id ) {
5088 trace_mux_error ("mux_set_values() error: "
5189 "multiple configured streams "
5290 "have same pipeline ID = %u" ,
53- cfg -> streams [i ].pipeline_id );
91+ streams [i ].pipeline_id );
5492 return - EINVAL ;
5593 }
5694 }
5795 }
5896
59- /* check if number of channels per stream doesn't exceed maximum */
97+ /* check if number of channels per stream doesn't exceed maximum
6098 for (i = 0; i < cfg->num_streams; i++) {
6199 if (cfg->streams[i].num_channels > PLATFORM_MAX_CHANNELS) {
62100 trace_mux_error("mux_set_values() error: configured "
@@ -67,15 +105,16 @@ static int mux_set_values(struct comp_data *cd, struct sof_mux_config *cfg)
67105 return -EINVAL;
68106 }
69107 }
108+ */
70109
71110 cd -> config .num_channels = cfg -> num_channels ;
72111 cd -> config .frame_format = cfg -> frame_format ;
73112
74113 for (i = 0 ; i < cfg -> num_streams ; i ++ ) {
75- cd -> config .streams [i ].num_channels = cfg -> streams [i ].num_channels ;
76- cd -> config .streams [i ].pipeline_id = cfg -> streams [i ].pipeline_id ;
77- for (j = 0 ; j < cfg -> streams [ i ]. num_channels ; j ++ )
78- cd -> config .streams [i ].mask [j ] = cfg -> streams [i ].mask [j ];
114+ cd -> config .streams [i ].num_channels = streams [i ].num_channels ;
115+ cd -> config .streams [i ].pipeline_id = streams [i ].pipeline_id ;
116+ for (j = 0 ; j < PLATFORM_MAX_CHANNELS ; j ++ )
117+ cd -> config .streams [i ].mask [j ] = streams [i ].mask [j ];
79118 }
80119
81120 return 0 ;
@@ -105,16 +144,16 @@ static struct comp_dev *mux_new(struct sof_ipc_comp *comp)
105144 memcpy (& dev -> comp , comp , sizeof (struct sof_ipc_comp_process ));
106145
107146 cd = rzalloc (RZONE_RUNTIME , SOF_MEM_CAPS_RAM ,
108- sizeof (* cd ) + MUX_MAX_STREAMS * sizeof ( struct mux_stream_data ) );
147+ sizeof (* cd ));
109148 if (!cd ) {
149+ trace_mux ("alloc failed mux new" );
110150 rfree (dev );
111151 return NULL ;
112152 }
113153
114154 comp_set_drvdata (dev , cd );
115155
116- memcpy_s (& cd -> config , sizeof (struct sof_mux_config ) +
117- MUX_MAX_STREAMS * sizeof (struct mux_stream_data ),
156+ memcpy_s (& cd -> config , sizeof (struct sof_ipc_mux_config ),
118157 ipc_process -> data , bs );
119158
120159 /* verification of initial parameters */
@@ -157,14 +196,14 @@ static int mux_ctrl_set_cmd(struct comp_dev *dev,
157196 struct sof_ipc_ctrl_data * cdata )
158197{
159198 struct comp_data * cd = comp_get_drvdata (dev );
160- struct sof_mux_config * cfg ;
199+ struct sof_ipc_mux_config * cfg ;
161200 int ret = 0 ;
162201
163202 trace_mux ("mux_ctrl_set_cmd(), cdata->cmd = 0x%08x" , cdata -> cmd );
164203
165204 switch (cdata -> cmd ) {
166205 case SOF_CTRL_CMD_BINARY :
167- cfg = (struct sof_mux_config * )cdata -> data -> data ;
206+ cfg = (struct sof_ipc_mux_config * )cdata -> data -> data ;
168207
169208 ret = mux_set_values (cd , cfg );
170209 break ;
0 commit comments