转自-中华视频网 看代码有一段时间了,一直跟踪代码时注重的都是整个流程及宏观上的结构,看到程序时诸多的img,currSlice,currStream,dp时也没在意,因为知道个大概的意思,后来看的多了,发现这几个变量之间关系不理清对看程序很不利,于是追根溯源跟踪了一遍,大致关系如下(解码器,编码器应该也差不多):
在global.h中有变量类型定义
// image parameters
typedef struct img_par
{
……
Slice *currentSlice;
Macroblock *mb_data;
……
} ImageParameters;
typedef struct
{
……
DataPartition *partArr;
……
} Slice;
typedef struct
{
// CABAC Decoding
int read_len;
int code_len;
int frame_bitoffset;
int bitstream_length;
byte *streamBuffer;
} Bitstream;
typedef struct datapartition
{
Bitstream *bitstream;
DecodingEnvironment de_cabac;
int (*readSyntaxElement)(SyntaxElement *, struct img_par *, struct inp_par *, struct datapartition *);
} DataPartition;
然后在ldecod.c中有:
struct img_par *img; 在global.h中有相对应extern ImageParameters *img;
进入main()中
if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img");
……
malloc_slice(input,img); //肯定是完成对img的一些初始化操作
进去看一下:
Slice *currSlice;
img->currentSlice = (Slice *) calloc(1, sizeof(Slice)); //img与currSlice对应上了
之后进行的对currSlice的操作及对img->currentSlice在进行操作。
跳出来继续main
init(img); //看函数名就知道了
之后进行一系列初始化
进行decode_one_frame
有定义 Slice *currSlice = img->currentSlice;
进入read_new_slice
Slice *currSlice = img->currentSlice; //这里不存在重复定义的情况,虽然外面定义过,但Slice *currSlice是局部变量,没有将其传进来,img是全局变量。
Bitstream *currStream;
进入switch,处理的第一个nalu是pps,进去看一下
DataPartition *dp = AllocPartition(1);
memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1); //变量与nalu对应上了,
dummy = InterpretSPS (dp, sps);
进去看一下
Bitstream *s = p->bitstream;
……
sps->profile_idc = u_v (8, "SPS: profile_idc" , s); //对应上了
跳出来继续switch
进 case NALU_TYPE_IDR:看一下
currStream = currSlice->partArr[0].bitstream;
memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); //这里几个变量之间的关系全对应上了,也和码流对应上了
|