comparison oggenc.c @ 4310:92117125e17c libavformat

use new ff_interleave_add_packet
author bcoudurier
date Sat, 31 Jan 2009 06:08:42 +0000
parents 549a09cf23fe
children 03065a598506
comparison
equal deleted inserted replaced
4309:24450a206efa 4310:92117125e17c
200 } while (size > 0 || ret == 255*255); // need to output a last nil page 200 } while (size > 0 || ret == 255*255); // need to output a last nil page
201 201
202 return 0; 202 return 0;
203 } 203 }
204 204
205 static int ogg_compare_granule(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
206 {
207 AVStream *st2 = s->streams[next->stream_index];
208 AVStream *st = s->streams[pkt ->stream_index];
209
210 int64_t next_granule = av_rescale_q(next->pts + next->duration,
211 st2->time_base, AV_TIME_BASE_Q);
212 int64_t cur_granule = av_rescale_q(pkt ->pts + pkt ->duration,
213 st ->time_base, AV_TIME_BASE_Q);
214 return next_granule > cur_granule;
215 }
216
205 int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) 217 int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
206 { 218 {
207 AVPacketList *pktl, **next_point, *this_pktl; 219 AVPacketList *pktl;
208 int stream_count = 0; 220 int stream_count = 0;
209 int streams[MAX_STREAMS] = {0}; 221 int streams[MAX_STREAMS] = {0};
210 int interleaved = 0; 222 int interleaved = 0;
211 223
212 if (pkt) { 224 if (pkt) {
213 AVStream *st = s->streams[pkt->stream_index]; 225 ff_interleave_add_packet(s, pkt, ogg_compare_granule);
214 this_pktl = av_mallocz(sizeof(AVPacketList));
215 this_pktl->pkt = *pkt;
216 if (pkt->destruct == av_destruct_packet)
217 pkt->destruct = NULL; // not shared -> must keep original from being freed
218 else
219 av_dup_packet(&this_pktl->pkt); // shared -> must dup
220 next_point = &s->packet_buffer;
221 while (*next_point) {
222 AVStream *st2 = s->streams[(*next_point)->pkt.stream_index];
223 AVPacket *next_pkt = &(*next_point)->pkt;
224 int64_t cur_granule, next_granule;
225 next_granule = av_rescale_q(next_pkt->pts + next_pkt->duration,
226 st2->time_base, AV_TIME_BASE_Q);
227 cur_granule = av_rescale_q(pkt->pts + pkt->duration,
228 st->time_base, AV_TIME_BASE_Q);
229 if (next_granule > cur_granule)
230 break;
231 next_point= &(*next_point)->next;
232 }
233 this_pktl->next= *next_point;
234 *next_point= this_pktl;
235 } 226 }
236 227
237 pktl = s->packet_buffer; 228 pktl = s->packet_buffer;
238 while (pktl) { 229 while (pktl) {
239 if (streams[pktl->pkt.stream_index] == 0) 230 if (streams[pktl->pkt.stream_index] == 0)