Mercurial > libavcodec.hg
comparison oggvorbis.c @ 1924:d9f751c0f488 libavcodec
pts hack (correct solution would be to pass the pts from the encoder to the muxer)
author | michael |
---|---|
date | Sun, 04 Apr 2004 17:06:30 +0000 |
parents | 04f93474b3bb |
children | 48c1033bd23b |
comparison
equal
deleted
inserted
replaced
1923:04f93474b3bb | 1924:d9f751c0f488 |
---|---|
6 | 6 |
7 #include <vorbis/vorbisenc.h> | 7 #include <vorbis/vorbisenc.h> |
8 | 8 |
9 #include "avcodec.h" | 9 #include "avcodec.h" |
10 | 10 |
11 //#define OGGVORBIS_FRAME_SIZE 1024 | 11 #undef NDEBUG |
12 #include <assert.h> | |
13 | |
12 #define OGGVORBIS_FRAME_SIZE 64 | 14 #define OGGVORBIS_FRAME_SIZE 64 |
13 | 15 |
14 #define BUFFER_SIZE (1024*64) | 16 #define BUFFER_SIZE (1024*64) |
15 | 17 |
16 typedef struct OggVorbisContext { | 18 typedef struct OggVorbisContext { |
17 vorbis_info vi ; | 19 vorbis_info vi ; |
18 vorbis_dsp_state vd ; | 20 vorbis_dsp_state vd ; |
19 vorbis_block vb ; | 21 vorbis_block vb ; |
20 uint8_t buffer[BUFFER_SIZE]; | 22 uint8_t buffer[BUFFER_SIZE]; |
21 int buffer_index; | 23 int buffer_index; |
24 int64_t fake_pts; //pts which libavformat will guess, HACK FIXME | |
22 | 25 |
23 /* decoder */ | 26 /* decoder */ |
24 vorbis_comment vc ; | 27 vorbis_comment vc ; |
25 ogg_packet op; | 28 ogg_packet op; |
26 } OggVorbisContext ; | 29 } OggVorbisContext ; |
128 context->buffer_index += op.bytes; | 131 context->buffer_index += op.bytes; |
129 // av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); | 132 // av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
136 l=0; | |
133 if(context->buffer_index){ | 137 if(context->buffer_index){ |
134 ogg_packet *op2= (ogg_packet*)context->buffer; | 138 ogg_packet *op2= (ogg_packet*)context->buffer; |
135 op2->packet = context->buffer + sizeof(ogg_packet); | 139 op2->packet = context->buffer + sizeof(ogg_packet); |
136 l= op2->bytes; | 140 |
141 if(op2->granulepos <= context->fake_pts /*&& (context->fake_pts || context->buffer_index > 4*1024)*/){ | |
142 assert(op2->granulepos == context->fake_pts); | |
143 l= op2->bytes; | |
144 | |
145 memcpy(packets, op2->packet, l); | |
146 context->buffer_index -= l + sizeof(ogg_packet); | |
147 memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); | |
148 } | |
149 // av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); | |
150 } | |
151 | |
152 if(l || context->fake_pts){ | |
153 context->fake_pts += avccontext->frame_size; | |
154 } | |
137 | 155 |
138 memcpy(packets, op2->packet, l); | 156 return l; |
139 context->buffer_index -= l + sizeof(ogg_packet); | |
140 memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); | |
141 | |
142 // av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); | |
143 return l; | |
144 } | |
145 | |
146 return 0; | |
147 } | 157 } |
148 | 158 |
149 | 159 |
150 static int oggvorbis_encode_close(AVCodecContext *avccontext) { | 160 static int oggvorbis_encode_close(AVCodecContext *avccontext) { |
151 OggVorbisContext *context = avccontext->priv_data ; | 161 OggVorbisContext *context = avccontext->priv_data ; |