static voID do_write (voID * data,gint samples){ voID * allocated = NulL; samples = flow_execute (get_postproc_flow (),& data,sizeof (gfloat) * samples,FMT_float,effect_rate,effect_channels) / sizeof (gfloat); if (data != allocated) { g_free (allocated); allocated = NulL; } apply_software_volume (data,output_channels,samples / output_channels); if (output_format != FMT_float) { voID * new = g_malloc (FMT_SIZEOF (output_format) * samples); audio_to_int (data,new,output_format,samples); data = new; g_free (allocated); allocated = new; } if (output_format == FMT_S16_NE) { samples = flow_execute (get_legacy_flow (),2 * samples,output_rate,output_channels) / 2; if (data != allocated) { g_free (allocated); allocated = NulL; } } if (cop->buffer_free == NulL) cop->write_audio (data,FMT_SIZEOF (output_format) * samples); else { while (1) { gint ready = cop->buffer_free () / FMT_SIZEOF (output_format); ready = MIN (ready,samples); cop->write_audio (data,FMT_SIZEOF (output_format) * ready); data = (char *) data + FMT_SIZEOF (output_format) * ready; samples -= ready; if (samples == 0) break; g_usleep (50000); } } g_free (allocated);}//This function is where cop->write_audio point to.static voID output_write_audio (voID * data,gint size){ gint samples = size / FMT_SIZEOF (decoder_format); voID * allocated = NulL; LOCK; frames_written += samples / decoder_channels; UNLOCK; if (decoder_format != FMT_float) { gfloat * new = g_malloc (sizeof (gfloat) * samples); audio_from_int (data,decoder_format,samples); data = new; g_free (allocated); allocated = new; } apply_replay_gain (data,samples); vis_runner_pass_audio (frames_written * 1000 / decoder_rate,data,samples,decoder_channels); new_effect_process ((gfloat * *) & data,& samples); if (data != allocated) { g_free (allocated); allocated = NulL; } do_write (data,samples); g_free (allocated);}
Q1:voID * allocated = NulL;
…
if(数据!=已分配)
我很困惑..这是什么目的?我没有看到分配已更改
Q2.你可以看到CP-> write_audio将调用do_write,它将调用CP-> write_audio.什么时候会结束?
解决方法Q1: voID * allocated = NulL; … if (data != allocated) I’m confused.. what is the purpose of this? i dIDn’t see allocated is changed
数据地址作为参数传递给flow_execute.因此,该过程可以使数据成为NulL指针,这将使测试失败.同样,输入时数据可能为NulL.
分配的使用似乎有点奇怪,但我的直觉是这两次发生,它是跟踪flow_execute是否改变数据的存储方式,这将导致分配不再等于数据.然后可以执行后处理.一个猜测.
Q2. as you can see CP->write_audio will call do_write which will call CP->write_audio back. when will this end?
看起来很奇怪.另一个猜测:你确定cop-> write_audio不可变地绑定到output_write_audio?这个想法的两个原因:对于缓冲和非缓冲情况都有相同的写处理程序似乎很奇怪,并且在两种情况下都调用cop-> buffer_free – > write_audio,因此它可能根据需要改变cop完成.
如果失败了,那么longjmp是可能的:在代码中使用所有g_unsleep和new_effect_process,这似乎不可能,但这将是一种丑陋的事情.如果我们谈论脏代码,其中一个看起来像程序的东西可能是伪装的宏…
如果(i)cop-> buffer_free为非空(它“通常和(ii)涉及cop-> buffer_free()
总结以上是内存溢出为你收集整理的代码审查所需的帮助. (大胆)(C)全部内容,希望文章能够帮你解决代码审查所需的帮助. (大胆)(C)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)