ALSA中变量值衩莫名改变
平台信息:arm/android中alsa-lib
下面是我分析alsa-lib时pcm_plug.c中的一个函数,在这里如下红色部分代码,打印出来的LOG如下信息。
chang channels:tt_ssize=2,tt_cused=1,tt_sused=2,float=4
rpolicy=3,clt->channels=1,slv->channels=2,
v=-0.000000
srcs=2,sc=2,cc=1
v=0.000000,srcs=4
v=0.000000
srcs=2,sc=2,cc=1
v=0.000000,srcs=4
change_channel:format=2,channels=2,t[0]=0.000000,t[1]=0.000000,tt_ssize=0,tt_cused=15,tt_sused=8
这个函数没有被其它线程调 用,开始我用LOGCAT打印结果一样,后来又写了一个loghl函数将它打印到文件中,结果也是一样的。但是为什么nsrcs的值会改变呢?还有tt_ssize值也会改变,
请高手指点一下。
- static int snd_pcm_plug_change_channels(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_plug_params_t *clt, snd_pcm_plug_params_t *slv)
- {
- snd_pcm_plug_t *plug = pcm->private_data;
- unsigned int tt_ssize, tt_cused, tt_sused;
- snd_pcm_route_ttable_entry_t *ttable;
- int err;
- //10-01 22:48:32.117 I/ ( 683): client->format=2,client->channels=1,client->rate=8000,client->access=3
- //10-01 22:48:32.117 I/ ( 683): slave->format=2,slave->channel=2,slave->rate=48000,slave->access=0
- if (clt->channels == slv->channels &&
- (!plug->ttable || !plug->ttable_last))
- return 0;
- if (clt->rate != slv->rate &&
- clt->channels > slv->channels)
- return 0;
- assert(snd_pcm_format_linear(slv->format));
- tt_ssize = slv->channels;
- tt_cused = clt->channels;
- tt_sused = slv->channels;
- ttable = alloca(tt_cused * tt_sused * sizeof(*ttable));
- loghl("chang channels:tt_ssize=%d,tt_cused=%d,tt_sused=%d,float=%d\n",tt_ssize,tt_cused,tt_sused,sizeof(*ttable));
- if (plug->ttable) { /* expand or shrink table */
- unsigned int c = 0, s = 0;
- for (c = 0; c < tt_cused; c++) {
- for (s = 0; s < tt_sused; s++) {
- snd_pcm_route_ttable_entry_t v;
- if (c >= plug->tt_cused)
- v = 0;
- else if (s >= plug->tt_sused)
- v = 0;
- else
- v = plug->ttable[c * plug->tt_ssize + s];
- ttable[c * tt_ssize + s] = v;
- }
- }
- plug->ttable_ok = 1;
- } else {
- unsigned int k;
- unsigned int c = 0, s = 0;
- enum snd_pcm_plug_route_policy rpolicy = plug->route_policy;
- int n;
- for (k = 0; k < tt_cused * tt_sused; ++k)
- ttable[k] = 0;
- if (rpolicy == PLUG_ROUTE_POLICY_DEFAULT) {
- rpolicy = PLUG_ROUTE_POLICY_COPY;
- /* it's hack for mono conversion */
- if (clt->channels == 1 || slv->channels == 1)
- rpolicy = PLUG_ROUTE_POLICY_AVERAGE;
- }
- switch (rpolicy) {
- case PLUG_ROUTE_POLICY_AVERAGE:
- case PLUG_ROUTE_POLICY_DUP:
- if (clt->channels > slv->channels) {
- n = clt->channels;
- } else {
- n = slv->channels;
- }
- loghl("rpolicy=%d,clt->channels=%d,slv->channels=%d,\n",rpolicy,clt->channels,slv->channels);
- while (n-- > 0) {
- snd_pcm_route_ttable_entry_t v = SND_PCM_PLUGIN_ROUTE_FULL;
- loghl("v=%f\n",v);
- if (rpolicy == PLUG_ROUTE_POLICY_AVERAGE) {
- if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
- clt->channels > slv->channels) {
- int srcs = clt->channels / slv->channels;
- if (s < clt->channels % slv->channels)
- srcs++;
- v /= srcs;
- } else if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
- slv->channels > clt->channels) {
- int srcs = slv->channels / clt->channels;
- [color=Red]loghl("srcs=%d,sc=%d,cc=%d\n",srcs,slv->channels,clt->channels);[/color] if (s < slv->channels % clt->channels)
- {srcs++;
- loghl("src add before src=%d,now src=%d\n",srcs-1,srcs);
- }
- [color=Red]loghl("v=%f,srcs=%d\n",v,srcs);[/color] v /= srcs;
- }
- }
- ttable[c * tt_ssize + s] = v;
- if (++c == clt->channels)
- c = 0;
- if (++s == slv->channels)
- s = 0;
- }
- break;
- case PLUG_ROUTE_POLICY_COPY:
- if (clt->channels < slv->channels) {
- n = clt->channels;
- } else {
- n = slv->channels;
- }
- for (c = 0; (int)c < n; c++)
- ttable[c * tt_ssize + c] = SND_PCM_PLUGIN_ROUTE_FULL;
- break;
- default:
- SNDERR("Invalid route policy");
- break;
- }
- }
- loghl("change_channel:format=%d,channels=%d,t[0]=%f,t[1]=%f,tt_ssize=%d,tt_cused=%d,tt_sused=%d\n",slv->format,slv->channels,ttable[0],ttable[1],
- tt_ssize,tt_cused,tt_sused);
- err = snd_pcm_route_open(new, NULL, slv->format, (int) slv->channels, ttable, tt_ssize, tt_cused, tt_sused, plug->gen.slave, plug->gen.slave != plug->req_slave);
- if (err < 0)
- return err;
- slv->channels = clt->channels;
- slv->access = clt->access;
- if (snd_pcm_format_linear(clt->format))
- slv->format = clt->format;
- return 1;
- }
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论