- AVCodecContext *codec = &avfcontext->streams[n]->codec;
- uint8_t *p= codec->extradata;
-
+ AVCodecContext *codec = avfcontext->streams[n]->codec;
+ uint8_t *headers = codec->extradata;
+ int headers_len = codec->extradata_size;
+ uint8_t *header_start[3];
+ int header_len[3];
+ int i, j;
+
av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
- for(i=0; i < codec->extradata_size; i+= op->bytes){
- op->bytes = p[i++]<<8;
- op->bytes+= p[i++];
+ for(j=1,i=0;i<2;++i, ++j) {
+ header_len[i]=0;
+ while(j<headers_len && headers[j]==0xff) {
+ header_len[i]+=0xff;
+ ++j;
+ }
+ header_len[i]+=headers[j];
+ }
+ header_len[2]=headers_len-header_len[0]-header_len[1]-j;
+ headers+=j;
+ header_start[0] = headers;
+ header_start[1] = header_start[0] + header_len[0];
+ header_start[2] = header_start[1] + header_len[1];
+
+ for(i=0; i < 3; ++i){
+ op->bytes = header_len[i];
op->b_o_s= op->packetno==0;
ogg_stream_packetin(&context->os, op);
op->b_o_s= op->packetno==0;
ogg_stream_packetin(&context->os, op);
-static int ogg_write_packet(AVFormatContext *avfcontext,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts)
+static int ogg_write_packet(AVFormatContext *avfcontext, AVPacket *pkt)
// av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
/* flush header packets so audio starts on a new page */
if(!context->header_handled) {
// av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
/* flush header packets so audio starts on a new page */
if(!context->header_handled) {
- while(ogg_stream_flush(&context->os, &og)) {
- put_buffer(&avfcontext->pb, og.header, og.header_len) ;
- put_buffer(&avfcontext->pb, og.body, og.body_len) ;
- put_flush_packet(&avfcontext->pb);
- }
- context->header_handled = 1 ;
+ while(ogg_stream_flush(&context->os, &og)) {
+ put_buffer(&avfcontext->pb, og.header, og.header_len) ;
+ put_buffer(&avfcontext->pb, og.body, og.body_len) ;
+ put_flush_packet(&avfcontext->pb);
+ }
+ context->header_handled = 1 ;
while(ogg_stream_pageout(&context->os, &og)) {
put_buffer(&avfcontext->pb, og.header, og.header_len);
while(ogg_stream_pageout(&context->os, &og)) {
put_buffer(&avfcontext->pb, og.header, og.header_len);
- put_buffer(&avfcontext->pb, og.body, og.body_len);
- put_flush_packet(&avfcontext->pb);
- }
+ put_buffer(&avfcontext->pb, og.body, og.body_len);
+ put_flush_packet(&avfcontext->pb);
+ }
- put_buffer(&avfcontext->pb, og.header, og.header_len) ;
- put_buffer(&avfcontext->pb, og.body, og.body_len) ;
- put_flush_packet(&avfcontext->pb);
+ put_buffer(&avfcontext->pb, og.header, og.header_len) ;
+ put_buffer(&avfcontext->pb, og.body, og.body_len) ;
+ put_flush_packet(&avfcontext->pb);
static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
OggContext *context = avfcontext->priv_data ;
ogg_page og ;
static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
OggContext *context = avfcontext->priv_data ;
ogg_page og ;
- /* while no pages are available, read in more data to the sync */
- while(ogg_sync_pageout(&context->oy, &og) != 1) {
- buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
- if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
- return 1 ;
- ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
- }
-
- /* got a page. Feed it into the stream and get the packet */
- if(ogg_stream_pagein(&context->os, &og) != 0)
- return 1 ;
+ /* while no pages are available, read in more data to the sync */
+ while(ogg_sync_pageout(&context->oy, &og) != 1) {
+ buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
+ if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
+ return 1 ;
+ ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
+ }
+
+ /* got a page. Feed it into the stream and get the packet */
+ if(ogg_stream_pagein(&context->os, &og) != 0)
+ return 1 ;
static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
{
OggContext *context = avfcontext->priv_data;
static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
{
OggContext *context = avfcontext->priv_data;
ogg_sync_init(&context->oy) ;
buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
ogg_sync_init(&context->oy) ;
buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
ogg_sync_pageout(&context->oy, &og) ;
ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
ogg_stream_pagein(&context->os, &og) ;
ogg_sync_pageout(&context->oy, &og) ;
ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
ogg_stream_pagein(&context->os, &og) ;
/* currently only one vorbis stream supported */
ast = av_new_stream(avfcontext, 0) ;
if(!ast)
/* currently only one vorbis stream supported */
ast = av_new_stream(avfcontext, 0) ;
if(!ast)
av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
codec= &ast->codec;
av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
codec= &ast->codec;
- codec->extradata= av_realloc(codec->extradata, codec->extradata_size);
+ codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ memset(codec->extradata + codec->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
pkt->stream_index = 0 ;
memcpy(pkt->data, op.packet, op.bytes);
if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)
pkt->stream_index = 0 ;
memcpy(pkt->data, op.packet, op.bytes);
if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)