
AudioResample **pResample 指针的地址图解
AudioResample **pResample; // pResample 存储 AudioResample* 的地址
AudioResample *ar = *pResample; // ar 现在指向 AudioResample 结构体
pResample→ 指向AudioResample*的地址 (0x2000)*pResample→ 取出AudioResample*,得到0x3000ar = *pResample→ar现在存储0x3000,和*pResample指向同一块AudioResample结构体的内存
再看一个demo
AVFilterGraph **graph
AVFilterGraph *filter_graph = avfilter_graph_alloc();
*graph = filter_graph;
AVFilterGraph **graph;声明了一个AVFilterGraph*的指针的指针,意思是graph是一个指向AVFilterGraph*类型的指针。AVFilterGraph *filter_graph = avfilter_graph_alloc();通过avfilter_graph_alloc()函数创建并分配一个新的AVFilterGraph对象,并将其指针赋给filter_graph。
最后一行 *graph = filter_graph;
*graph表示解引用graph,也就是访问graph指向的AVFilterGraph*位置。filter_graph是已经分配好的AVFilterGraph*,所以*graph = filter_graph;这行代码的意思是将filter_graph的值(即指针)赋给graph指向的内存位置。
具体操作
在调用 avfilter_graph_alloc() 后,filter_graph 指向了一个有效的 AVFilterGraph 对象。而 *graph = filter_graph; 是将这个指针存储在 graph 指向的内存中。换句话说,graph 指向一个指针,并且这行代码让它指向了 filter_graph。
总结
*graph = filter_graph; 的作用是:
- 将
filter_graph指向的AVFilterGraph对象的指针赋给graph指向的位置。 - 在执行此操作后,
*graph和filter_graph会指向相同的AVFilterGraph实例。 
*graph = filter_graph;赋值后的graph跟filter_graph关系图

再举个例子
avformat_alloc_output_context2(AVFormatContext **avctx)
调用是这样的avformat_alloc_output_context2(&outFormatCtx
avformat_alloc_output_context2() 内部:
avctx等于&outFormatCtx,即AVFormatContext **avctx = &outFormatCtx*avctx等于outFormatCtx,这个函数内部会分配AVFormatContext并赋值给*avctx- 这样
outFormatCtx就会指向新分配的AVFormatContext结构体 avctx是指向outFormatCtx地址的指针- *avctx=null 则
outFormatCtx这个指针指向的地址设为null outFormatCtx这个指针指向的值也为null

2663

被折叠的 条评论
为什么被折叠?



