]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/ogg.c
Winnov WNV1 video decoder, courtesy of Konstantin Shishkov
[ffmpeg] / libavformat / ogg.c
index 65c507c240a644ed54e5649b40715543ec769314..c30ccd2f2473eb28921b6bbec032bcbc492bf5d8 100644 (file)
@@ -36,14 +36,14 @@ static int ogg_write_header(AVFormatContext *avfcontext)
     ogg_packet *op= &context->op;    
     int n, i;
 
-    av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
-
     ogg_stream_init(&context->os, 31415);
     
     for(n = 0 ; n < avfcontext->nb_streams ; n++) {
         AVCodecContext *codec = &avfcontext->streams[n]->codec;
         uint8_t *p= codec->extradata;
         
+        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++];
@@ -62,16 +62,15 @@ static int ogg_write_header(AVFormatContext *avfcontext)
     return 0 ;
 }
 
-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)
 {
     OggContext *context = avfcontext->priv_data ;
-    AVCodecContext *avctx= &avfcontext->streams[stream_index]->codec;
+    AVCodecContext *avctx= &avfcontext->streams[pkt->stream_index]->codec;
     ogg_packet *op= &context->op;
     ogg_page og ;
+    int64_t pts;
 
-    pts= av_rescale(pts, avctx->sample_rate, AV_TIME_BASE);
+    pts= av_rescale(pkt->pts, avctx->sample_rate, AV_TIME_BASE);
 
 //    av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
 
@@ -86,8 +85,8 @@ static int ogg_write_packet(AVFormatContext *avfcontext,
        context->header_handled = 1 ;
     }
 
-    op->packet = (uint8_t*) buf;
-    op->bytes  = size;
+    op->packet = (uint8_t*) pkt->data;
+    op->bytes  = pkt->size;
     op->b_o_s  = op->packetno == 0;
     op->granulepos= pts;
 
@@ -171,13 +170,11 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
     uint8_t *p;
     int i;
      
-    avfcontext->ctx_flags |= AVFMTCTX_NOHEADER;
-     
     ogg_sync_init(&context->oy) ;
     buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
 
     if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
-       return -EIO ;
+       return AVERROR_IO ;
     
     ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;   
     ogg_sync_pageout(&context->oy, &og) ;
@@ -189,6 +186,7 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
     ast = av_new_stream(avfcontext, 0) ;
     if(!ast)
        return AVERROR_NOMEM ;
+    av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
 
     codec= &ast->codec;
     codec->codec_type = CODEC_TYPE_AUDIO;
@@ -197,8 +195,10 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
         if(next_packet(avfcontext, &op)){
             return -1;
         }
+        if(op.bytes >= (1<<16) || op.bytes < 0)
+            return -1;
         codec->extradata_size+= 2 + op.bytes;
-        codec->extradata= av_realloc(codec->extradata, codec->extradata_size);
+        codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
         p= codec->extradata + codec->extradata_size - 2 - op.bytes;
         *(p++)= op.bytes>>8;
         *(p++)= op.bytes&0xFF;
@@ -213,11 +213,14 @@ static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
     ogg_packet op ;
 
     if(next_packet(avfcontext, &op)) 
-       return -EIO ;
+       return AVERROR_IO ;
     if(av_new_packet(pkt, op.bytes) < 0)
-       return -EIO ;
+       return AVERROR_IO ;
     pkt->stream_index = 0 ;
     memcpy(pkt->data, op.packet, op.bytes);
+    if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)
+        pkt->pts= av_rescale(op.granulepos, AV_TIME_BASE, avfcontext->streams[0]->codec.sample_rate);
+//    printf("%lld %d %d\n", pkt->pts, (int)op.granulepos, avfcontext->streams[0]->codec.sample_rate);
 
     return op.bytes;
 }