aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-01-31 06:01:58 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-01-31 06:01:58 +0000
commitccf0071dee797b5b7ddcaf8d432a8a84a22f38ae (patch)
tree56556a19383b5c20274c1e3e8ec031f2967362eb
parent4becee2343ff88aad8d80bfc444fbf72b9c8bb30 (diff)
downloadffmpeg-ccf0071dee797b5b7ddcaf8d432a8a84a22f38ae.tar.gz
split av_interleave_per_dts, to avoid code duplication
Originally committed as revision 16884 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/utils.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4a69baae21..be8553bc34 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2585,34 +2585,45 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+ int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
+{
+ AVPacketList **next_point, *this_pktl;
+
+ this_pktl = av_mallocz(sizeof(AVPacketList));
+ this_pktl->pkt= *pkt;
+ if(pkt->destruct == av_destruct_packet)
+ pkt->destruct= NULL; // not shared -> must keep original from being freed
+ else
+ av_dup_packet(&this_pktl->pkt); //shared -> must dup
+
+ next_point = &s->packet_buffer;
+ while(*next_point){
+ if(compare(s, &(*next_point)->pkt, pkt))
+ break;
+ next_point= &(*next_point)->next;
+ }
+ this_pktl->next= *next_point;
+ *next_point= this_pktl;
+}
+
+int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
+{
+ AVStream *st = s->streams[ pkt ->stream_index];
+ AVStream *st2= s->streams[ next->stream_index];
+ int64_t left = st2->time_base.num * (int64_t)st ->time_base.den;
+ int64_t right= st ->time_base.num * (int64_t)st2->time_base.den;
+
+ return next->dts * left > pkt->dts * right; //FIXME this can overflow
+}
+
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
- AVPacketList *pktl, **next_point, *this_pktl;
+ AVPacketList *pktl;
int stream_count=0;
int streams[MAX_STREAMS];
if(pkt){
- AVStream *st= s->streams[ pkt->stream_index];
-
-// assert(pkt->destruct != av_destruct_packet); //FIXME
-
- this_pktl = av_mallocz(sizeof(AVPacketList));
- this_pktl->pkt= *pkt;
- if(pkt->destruct == av_destruct_packet)
- pkt->destruct= NULL; // not shared -> must keep original from being freed
- else
- av_dup_packet(&this_pktl->pkt); //shared -> must dup
-
- next_point = &s->packet_buffer;
- while(*next_point){
- AVStream *st2= s->streams[ (*next_point)->pkt.stream_index];
- int64_t left= st2->time_base.num * (int64_t)st ->time_base.den;
- int64_t right= st ->time_base.num * (int64_t)st2->time_base.den;
- if((*next_point)->pkt.dts * left > pkt->dts * right) //FIXME this can overflow
- break;
- next_point= &(*next_point)->next;
- }
- this_pktl->next= *next_point;
- *next_point= this_pktl;
+ ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
}
memset(streams, 0, sizeof(streams));