libogg HOWTO(decoding部分)

Decoding

解码比编码复杂,但不过也是以下几步:

while (there is data) {
    extract a page from the data;
    submit it to the stream;
    for (number of packets in the page) {
        get another packet;
        write the packet; //optional
    }
}

显然there isdata 是你的工作 extract a page from the data is mostly done bylibogg with the help of another structure ogg_sync_state (必须通过 (ogg_sync_init()初始化). We use ithere by the name oy:

/* extract a page from the data */

/* 是否有足够的数据组成一个page? */
if (ogg_sync_pageout(&oy, &og) != 1) {
    /* 给ogg_sync_state 一些数据*/
    char * buffer = ogg_sync_buffer(&oy, 8092);
    int written = fread(buffer, 1, 8192, stdin); // orelse
    ogg_sync_wrote(written);
}

The ogg_sync_state stores data that yougive it through the buffer returned by ogg_sync_buffer()。然后你需要确认数据的字节数通过 ogg_sync_wrote()函数. 当 ogg_sync_state 已经给出数据, 你可以调用ogg_sync_pageout() 函数从数据中解出一个page出来 which isthen stored in *og (如果有足够的数据). 如果没有足够的数据可用来提取一个整页,该函数返回0).

注意: You shouldcall ogg_sync_pageout() before giving any datato the sync struct.

ogg_sync_state真正的作用是?我们只知道它从ogg比特流中提取页面出来。但它重要的是, 它可以处理比特流中的错误(如数据丢失)并能找到一个新的页面。

继续解码的步骤. submit it to the stream is just another liboggfunction:

intogg_stream_pagein(ogg_stream_state * os, ogg_page * og);

So, the page given to you by ogg_sync_pageout() can be insertet intothe stream that easily. Now the number of packets in the page can be optained just asnicely:

int ogg_page_packets(ogg_page *og);

doesthe job. 我们继续 get another packet, which is the reverseof encoding:

intogg_stream_packetout(ogg_stream_state * os, ogg_packet * op);

Nowthe 可选择的 write the packet depends again on whatyour decoder does and on whether there are bitstreams grouped to the one youare decoding now. Do with the packets whatever you want.

解码部分的一些函数介绍:

ogg_stream_init

初始化ogg_stream_state结构体,分配适当的内存准备编码或解码

ogg_page_serialno

返回当前页面逻辑比特流唯一的序列号。

ogg_sync_buffer

为了从同步层读取数据,公开了一个缓冲区。提供一个适当大小的缓冲区来进行写操作。

ogg_sync_pageout

从同步层输出一个page,将保存在 ogg_sync_state结构体中的数据加入ogg_page中.为了确保数据不在 ogg_sync_state结构体中,它应该在读入数据到buffer之前调用。

ogg_stream_pagein

它将一个page拆分为对编解码引擎有效的packet形式,提交一个完整的page到数据流层。这个函数添加一个完整的页面到比特流。它一般是在ogg_sync_pageout函数使用之后才使用

ogg_stream_packetout

/*输出一个包到编解码器的解码引擎。*/这个函数组装数据包输出至编解码器解码引擎。

 

vorbis_synthesis

解码一个page到 数据块

vorbis_synthesis_blockin

提交数据块组装成最终的解码音频。

vorbis_synthesis_pcmout

这个函数获取缓冲区包含解码音频样本。


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值