Revision 6d8f985e libavformat/ogg.c

View differences:

libavformat/ogg.c
14 14
#include "avformat.h"
15 15
#include "oggvorbis.h"
16 16

  
17
#undef NDEBUG
18
#include <assert.h>
19

  
17 20
#define DECODER_BUFFER_SIZE 4096
18 21

  
19 22

  
......
21 24
    /* output */
22 25
    ogg_stream_state os ;
23 26
    int header_handled ;
24
    ogg_int64_t base_packet_no ;
25
    ogg_int64_t base_granule_pos ;
27
    ogg_packet op;
26 28

  
27 29
    /* input */
28 30
    ogg_sync_state oy ;
......
40 42
    vorbis_block vb ;
41 43
    ogg_packet header, header_comm, header_code ; 
42 44
    int n ;
43
    
45

  
46
    av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
47

  
44 48
    ogg_stream_init(&context->os, 31415);
45 49
    
46 50
    for(n = 0 ; n < avfcontext->nb_streams ; n++) {
......
79 83
	/* end of vorbis specific code */
80 84

  
81 85
	context->header_handled = 0 ;
82
	context->base_packet_no = 0 ;
83 86
    }
84 87
    
85 88
    return 0 ;
......
88 91

  
89 92
static int ogg_write_packet(AVFormatContext *avfcontext,
90 93
			    int stream_index,
91
			    const uint8_t *buf, int size, int64_t force_pts)
94
			    const uint8_t *buf, int size, int64_t pts)
92 95
{
93 96
    OggContext *context = avfcontext->priv_data ;
94
    ogg_packet *op ;
97
    AVCodecContext *avctx= &avfcontext->streams[stream_index]->codec;
98
    ogg_packet *op= &context->op;
95 99
    ogg_page og ;
96
    int l = 0 ;
97
    
100

  
101
    pts= av_rescale(pts, avctx->sample_rate, AV_TIME_BASE);
102

  
103
    if(!size){
104
//        av_log(avfcontext, AV_LOG_DEBUG, "zero packet\n");
105
        return 0;
106
    }
107
//    av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
108

  
98 109
    /* flush header packets so audio starts on a new page */
99 110

  
100 111
    if(!context->header_handled) {
......
106 117
	context->header_handled = 1 ;
107 118
    }
108 119

  
109
    while(l < size) {
110
	op = (ogg_packet*)(buf + l) ;
111
	op->packet = (uint8_t*) buf + l + sizeof( ogg_packet) ; /* fix data pointer */
112

  
113
	if(!context->base_packet_no) { /* this is the first packet */
114
	    context->base_packet_no = op->packetno ; 
115
	    context->base_granule_pos = op->granulepos ;
116
	}
117

  
118
	/* correct the fields in the packet -- essential for streaming */
119

  
120
	op->packetno -= context->base_packet_no ;
121
	op->granulepos -= context->base_granule_pos ;
122

  
123
	ogg_stream_packetin(&context->os, op) ;
124
	l += sizeof(ogg_packet) + op->bytes ;
125

  
126
	while(ogg_stream_pageout(&context->os, &og)) {
127
	    put_buffer(&avfcontext->pb, og.header, og.header_len) ;
128
	    put_buffer(&avfcontext->pb, og.body, og.body_len) ;
129
	    put_flush_packet(&avfcontext->pb);
130
	}
131
    }
120
    op->packet = (uint8_t*) buf;
121
    op->bytes  = size;
122
    op->b_o_s  = op->packetno == 0;
123
    op->granulepos= pts;
124

  
125
    /* correct the fields in the packet -- essential for streaming */
126
                                                        
127
    ogg_stream_packetin(&context->os, op);              
128
                                                        
129
    while(ogg_stream_pageout(&context->os, &og)) {
130
        put_buffer(&avfcontext->pb, og.header, og.header_len);
131
	put_buffer(&avfcontext->pb, og.body, og.body_len);     
132
	put_flush_packet(&avfcontext->pb);
133
    }                                                   
134
    op->packetno++;
132 135

  
133 136
    return 0;
134 137
}

Also available in: Unified diff