核心参考 xiph官网
ogg 数据结构
datatype | purpose |
---|---|
ogg_page | This structure encapsulates data into one ogg bitstream page. 编码时page的信息在此输出 |
ogg_stream_state | This structure contains current encode/decode data for a logical bitstream. 代表当前流 |
ogg_packet | This structure encapsulates the data and metadata for a single Ogg packet. 编码时数据输入的结构包 |
ogg_sync_state | Contains bitstream synchronization information. |
以上ogg中最大的结构为ogg流,对比ogg的存储结构来说都是以ogg_page来进行数据分页,但是对于用于来说是以ogg_packet来对数据进行装载和解析。
编码相关
概览
When encoding, the encoding engine will output raw packets which must be placed into an Ogg bitstream. Raw packets are inserted into the stream, and an ogg_page is output when enough packets have been written to create a full page. The pages output are pointers to buffered packet segments, and can then be written out and saved as an ogg stream. There are a couple of basic steps: Use the encoding engine to produce a raw packet of data. Call ogg_stream_packetin to submit a raw packet to the stream. Use ogg_stream_pageout to output a page, if enough data has been submitted. Otherwise, continue submitting data.
意思就是原始数据要封装在ogg_packet中通过ogg_stream_packetin方法写入到ogg_stream_state中,如果包足够通过ogg_stream_pageout方法将数据写在ogg_page中
function | purpose |
---|---|
ogg_stream_packetin | Submits a raw packet to the streaming layer, so that it can be formed into a page. |
ogg_stream_iovecin | iovec version of ogg_stream_packetin() above. |
ogg_stream_pageout | Outputs a completed page if the stream contains enough packets to form a full page. 返回值非0代码输出成功 |
ogg_stream_pageout_fill | Similar to ogg_stream_pageout(), but specifies a page spill threshold in bytes. |
ogg_stream_flush | Forces any remaining packets in the stream to be returned as a page of any size. |
ogg_stream_flush_fill | Similar to ogg_stream_flush(), but specifies a page spill threshold in bytes. |
创建与销毁
创建
ogg_stream_init(&stream_, 0 /* serial number */);
销毁
ogg_stream_clear(&stream_);
编码数据封装
typedef struct {
unsigned char *packet;//数据
long bytes;//数据大小
long b_o_s;//1代表开始包
long e_o_s;//1代表结束包
//A number indicating the position of this packet in the decoded data. This is the last sample, frame or other unit of information ('granule') that can be completely decoded from this packet.
ogg_int64_t granulepos;
ogg_int64_t packetno;//Sequential number of this packet in the ogg bitstream.
} ogg_packet;
单流数据写入
// Write the most recent buffer of Opus data into an Ogg packet.
ogg_packet frame_packet;
frame_packet.b_o_s