@@ -76,6 +76,8 @@ struct q6apm_dai_rtd {
7676 enum stream_state state ;
7777 struct q6apm_graph * graph ;
7878 spinlock_t lock ;
79+ uint32_t initial_samples_drop ;
80+ uint32_t trailing_samples_drop ;
7981 bool notify_on_drain ;
8082};
8183
@@ -632,6 +634,109 @@ static int q6apm_dai_compr_ack(struct snd_soc_component *component, struct snd_c
632634 return count ;
633635}
634636
637+ static int q6apm_dai_compr_set_params (struct snd_soc_component * component ,
638+ struct snd_compr_stream * stream ,
639+ struct snd_compr_params * params )
640+ {
641+ struct snd_compr_runtime * runtime = stream -> runtime ;
642+ struct q6apm_dai_rtd * prtd = runtime -> private_data ;
643+ struct q6apm_dai_data * pdata ;
644+ struct audioreach_module_config cfg ;
645+ struct snd_codec * codec = & params -> codec ;
646+ int dir = stream -> direction ;
647+ int ret ;
648+
649+ pdata = snd_soc_component_get_drvdata (component );
650+ if (!pdata )
651+ return - EINVAL ;
652+
653+ prtd -> periods = runtime -> fragments ;
654+ prtd -> pcm_count = runtime -> fragment_size ;
655+ prtd -> pcm_size = runtime -> fragments * runtime -> fragment_size ;
656+ prtd -> bits_per_sample = 16 ;
657+
658+ prtd -> pos = 0 ;
659+
660+ if (prtd -> next_track != true) {
661+ memcpy (& prtd -> codec , codec , sizeof (* codec ));
662+
663+ ret = q6apm_set_real_module_id (component -> dev , prtd -> graph , codec -> id );
664+ if (ret )
665+ return ret ;
666+
667+ cfg .direction = dir ;
668+ cfg .sample_rate = codec -> sample_rate ;
669+ cfg .num_channels = 2 ;
670+ cfg .bit_width = prtd -> bits_per_sample ;
671+ cfg .fmt = codec -> id ;
672+ memcpy (& cfg .codec , codec , sizeof (* codec ));
673+
674+ ret = q6apm_graph_media_format_shmem (prtd -> graph , & cfg );
675+ if (ret < 0 )
676+ return ret ;
677+
678+ ret = q6apm_graph_media_format_pcm (prtd -> graph , & cfg );
679+ if (ret )
680+ return ret ;
681+
682+ ret = q6apm_map_memory_regions (prtd -> graph , SNDRV_PCM_STREAM_PLAYBACK ,
683+ prtd -> phys , (prtd -> pcm_size / prtd -> periods ),
684+ prtd -> periods );
685+ if (ret < 0 )
686+ return - ENOMEM ;
687+
688+ ret = q6apm_graph_prepare (prtd -> graph );
689+ if (ret )
690+ return ret ;
691+
692+ ret = q6apm_graph_start (prtd -> graph );
693+ if (ret )
694+ return ret ;
695+
696+ } else {
697+ cfg .direction = dir ;
698+ cfg .sample_rate = codec -> sample_rate ;
699+ cfg .num_channels = 2 ;
700+ cfg .bit_width = prtd -> bits_per_sample ;
701+ cfg .fmt = codec -> id ;
702+ memcpy (& cfg .codec , codec , sizeof (* codec ));
703+
704+ ret = audioreach_compr_set_param (prtd -> graph , & cfg );
705+ if (ret < 0 )
706+ return ret ;
707+ }
708+ prtd -> state = Q6APM_STREAM_RUNNING ;
709+
710+ return 0 ;
711+ }
712+
713+ static int q6apm_dai_compr_set_metadata (struct snd_soc_component * component ,
714+ struct snd_compr_stream * stream ,
715+ struct snd_compr_metadata * metadata )
716+ {
717+ struct snd_compr_runtime * runtime = stream -> runtime ;
718+ struct q6apm_dai_rtd * prtd = runtime -> private_data ;
719+ int ret = 0 ;
720+
721+ switch (metadata -> key ) {
722+ case SNDRV_COMPRESS_ENCODER_PADDING :
723+ prtd -> trailing_samples_drop = metadata -> value [0 ];
724+ q6apm_remove_trailing_silence (component -> dev , prtd -> graph ,
725+ prtd -> trailing_samples_drop );
726+ break ;
727+ case SNDRV_COMPRESS_ENCODER_DELAY :
728+ prtd -> initial_samples_drop = metadata -> value [0 ];
729+ q6apm_remove_initial_silence (component -> dev , prtd -> graph ,
730+ prtd -> initial_samples_drop );
731+ break ;
732+ default :
733+ ret = - EINVAL ;
734+ break ;
735+ }
736+
737+ return ret ;
738+ }
739+
635740static const struct snd_compress_ops q6apm_dai_compress_ops = {
636741 .open = q6apm_dai_compr_open ,
637742 .free = q6apm_dai_compr_free ,
@@ -640,6 +745,8 @@ static const struct snd_compress_ops q6apm_dai_compress_ops = {
640745 .pointer = q6apm_dai_compr_pointer ,
641746 .trigger = q6apm_dai_compr_trigger ,
642747 .ack = q6apm_dai_compr_ack ,
748+ .set_params = q6apm_dai_compr_set_params ,
749+ .set_metadata = q6apm_dai_compr_set_metadata ,
643750};
644751
645752static const struct snd_soc_component_driver q6apm_fe_dai_component = {
0 commit comments