[FFmpeg-cvslog] r10469 - in trunk/libavformat: rtp.c rtp_mpv.c

lucabe subversion
Mon Sep 10 09:01:30 CEST 2007


Author: lucabe
Date: Mon Sep 10 09:01:29 2007
New Revision: 10469

Log:
Fix timestamps in RTP packets (now, MPEG1 video with B frames works correctly)


Modified:
   trunk/libavformat/rtp.c
   trunk/libavformat/rtp_mpv.c

Modified: trunk/libavformat/rtp.c
==============================================================================
--- trunk/libavformat/rtp.c	(original)
+++ trunk/libavformat/rtp.c	Mon Sep 10 09:01:29 2007
@@ -737,6 +737,7 @@ static int rtp_write_header(AVFormatCont
 // following 2 FIXMies could be set based on the current time, theres normaly no info leak, as rtp will likely be transmitted immedeatly
     s->base_timestamp = 0; /* FIXME: was random(), what should this be? */
     s->timestamp = s->base_timestamp;
+    s->cur_timestamp = 0;
     s->ssrc = 0; /* FIXME: was random(), what should this be? */
     s->first_packet = 1;
     s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
@@ -746,14 +747,13 @@ static int rtp_write_header(AVFormatCont
         return AVERROR(EIO);
     s->max_payload_size = max_packet_size - 12;
 
+    av_set_pts_info(st, 32, 1, 90000);
     switch(st->codec->codec_id) {
     case CODEC_ID_MP2:
     case CODEC_ID_MP3:
         s->buf_ptr = s->buf + 4;
-        s->cur_timestamp = 0;
         break;
     case CODEC_ID_MPEG1VIDEO:
-        s->cur_timestamp = 0;
         break;
     case CODEC_ID_MPEG2TS:
         n = s->max_payload_size / TS_PACKET_SIZE;
@@ -835,24 +835,19 @@ static void rtp_send_samples(AVFormatCon
     /* not needed, but who nows */
     if ((size % sample_size) != 0)
         av_abort();
+    n = 0;
     while (size > 0) {
-        len = (max_packet_size - (s->buf_ptr - s->buf));
-        if (len > size)
-            len = size;
+        s->buf_ptr = s->buf;
+        len = FFMIN(max_packet_size, size);
 
         /* copy data */
         memcpy(s->buf_ptr, buf1, len);
         s->buf_ptr += len;
         buf1 += len;
         size -= len;
-        n = (s->buf_ptr - s->buf);
-        /* if buffer full, then send it */
-        if (n >= max_packet_size) {
-            ff_rtp_send_data(s1, s->buf, n, 0);
-            s->buf_ptr = s->buf;
-            /* update timestamp */
-            s->timestamp += n / sample_size;
-        }
+        s->timestamp = s->cur_timestamp + n / sample_size;
+        ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
+        n += (s->buf_ptr - s->buf);
     }
 }
 
@@ -862,7 +857,6 @@ static void rtp_send_mpegaudio(AVFormatC
                                const uint8_t *buf1, int size)
 {
     RTPDemuxContext *s = s1->priv_data;
-    AVStream *st = s1->streams[0];
     int len, count, max_packet_size;
 
     max_packet_size = s->max_payload_size;
@@ -873,11 +867,11 @@ static void rtp_send_mpegaudio(AVFormatC
         if (len > 4) {
             ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
             s->buf_ptr = s->buf + 4;
-            /* 90 KHz time stamp */
-            s->timestamp = s->base_timestamp +
-                (s->cur_timestamp * 90000LL) / st->codec->sample_rate;
         }
     }
+    if (s->buf_ptr == s->buf + 4) {
+        s->timestamp = s->cur_timestamp;
+    }
 
     /* add the packet */
     if (size > max_packet_size) {
@@ -909,14 +903,12 @@ static void rtp_send_mpegaudio(AVFormatC
         memcpy(s->buf_ptr, buf1, size);
         s->buf_ptr += size;
     }
-    s->cur_timestamp += st->codec->frame_size;
 }
 
 static void rtp_send_raw(AVFormatContext *s1,
                          const uint8_t *buf1, int size)
 {
     RTPDemuxContext *s = s1->priv_data;
-    AVStream *st = s1->streams[0];
     int len, max_packet_size;
 
     max_packet_size = s->max_payload_size;
@@ -926,15 +918,12 @@ static void rtp_send_raw(AVFormatContext
         if (len > size)
             len = size;
 
-        /* 90 KHz time stamp */
-        s->timestamp = s->base_timestamp +
-            av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
+        s->timestamp = s->cur_timestamp;
         ff_rtp_send_data(s1, buf1, len, (len == size));
 
         buf1 += len;
         size -= len;
     }
-    s->cur_timestamp++;
 }
 
 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
@@ -982,6 +971,7 @@ static int rtp_write_packet(AVFormatCont
         s->last_octet_count = s->octet_count;
         s->first_packet = 0;
     }
+    s->cur_timestamp = s->base_timestamp + pkt->pts;
 
     switch(st->codec->codec_id) {
     case CODEC_ID_PCM_MULAW:

Modified: trunk/libavformat/rtp_mpv.c
==============================================================================
--- trunk/libavformat/rtp_mpv.c	(original)
+++ trunk/libavformat/rtp_mpv.c	Mon Sep 10 09:01:29 2007
@@ -28,7 +28,6 @@
 void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
 {
     RTPDemuxContext *s = s1->priv_data;
-    AVStream *st = s1->streams[0];
     int len, h, max_packet_size;
     uint8_t *q;
     int begin_of_slice, end_of_slice, frame_type, temporal_reference;
@@ -105,8 +104,7 @@ void ff_rtp_send_mpegvideo(AVFormatConte
         q += len;
 
         /* 90 KHz time stamp */
-        s->timestamp = s->base_timestamp +
-            av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
+        s->timestamp = s->cur_timestamp;
         ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
 
         buf1 += len;
@@ -114,7 +112,6 @@ void ff_rtp_send_mpegvideo(AVFormatConte
         begin_of_slice = end_of_slice;
         end_of_slice = 0;
     }
-    s->cur_timestamp++;
 }
 
 




More information about the ffmpeg-cvslog mailing list