代码审查所需的帮助. (大胆)(C)
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; Q2.你可以看到CP-> write_audio将调用do_write,它将调用CP-> write_audio.什么时候会结束? 解决方法
数据地址作为参数传递给flow_execute.因此,该过程可以使数据成为NULL指针,这将使测试失败.同样,输入时数据可能为NULL. 分配的使用似乎有点奇怪,但我的直觉是这两次发生,它是跟踪flow_execute是否改变数据的存储方式,这将导致分配不再等于数据.然后可以执行后处理.一个猜测.
看起来很奇怪.另一个猜测:你确定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() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |