您的位置:首页 > 其它

H264分析源码学习之结构体篇——h264_stream_t结构体

2017-02-02 16:33 561 查看
最近学习H264的编解码,因此先学习了解H264的结构。我是通过h264分析开源库的源码进行学习的。首先先从数据结构体入手,通过了解重要的数据结构体来认识H264!

首先,我们需要初略的知道,H264数据流就是由一个一个独立的NALU单元构成:

...NALUNALUNALU...
再深入一点,每一个NALU由NALU header  和 NALU payload 两个部分组成(头信息主要说明此单元负载的数据类型,占一个字节)

...NALU headerNALU payloadNALU header NALU payload...
再深入一点,NALU单元之间需要一个标志来区分开。因此,在一个NALU单元开始前都会有一个开始码(0x000001)

...Start CodeNALU HeaderNALU payloadStart CodeNALU HeaderNALU payload...
其实,H264流就这么简单!

/**
H264 stream
Contains data structures for all NAL types that can be handled by this library.
When reading, data is read into those, and when writing it is written from those.
The reason why they are all contained in one place is that some of them depend on others, we need to
have all of them available to read or write correctly.
*/
/*
h264流的结构体:
包含所有NAL类型的数据结构,可以被这个库处理
当读取时,将数据读入这些数据结构体中,当写入时,从这数据结构体中写入

这个结构体在h264_new()函数中申请内存空间,在h264_free()函数中释放
*/
typedef struct
{
nal_t* nal;				//NALU单元数据结构(句法元素包括:NALU header的信息,指向NALU payload的指针)
sps_t* sps;				//sequence parameter sets序列参数集
pps_t* pps;				//picture parameter sets图片参数集
aud_t* aud;
sei_t* sei; 			//This is a TEMP pointer at whats in h->seis...
int num_seis;
slice_header_t* sh;
slice_data_rbsp_t* slice_data;

sps_t* sps_table[32];
pps_t* pps_table[256];
sei_t** seis;
videoinfo_t* info;

} h264_stream_t;

/**
Create a new H264 stream object.  Allocates all structures contained within it.
@return    the stream object
*/
h264_stream_t* h264_new()
{
h264_stream_t* h = (h264_stream_t*)calloc(1, sizeof(h264_stream_t));

h->nal = (nal_t*)calloc(1, sizeof(nal_t));

// initialize tables
for ( int i = 0; i < 32; i++ ) { h->sps_table[i] = (sps_t*)calloc(1, sizeof(sps_t)); }
for ( int i = 0; i < 256; i++ ) { h->pps_table[i] = (pps_t*)calloc(1, sizeof(pps_t)); }

h->sps = h->sps_table[0];
h->pps = h->pps_table[0];
h->aud = (aud_t*)calloc(1, sizeof(aud_t));
h->num_seis = 0;
h->seis = NULL;
h->sei = NULL;  //This is a TEMP pointer at whats in h->seis...
h->sh = (slice_header_t*)calloc(1, sizeof(slice_header_t));
h->info = (videoinfo_t*)calloc(1, sizeof(videoinfo_t));
h->info->type = 0;
return h;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: