]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtp.c
do not force the halfpel filter coeffs to be retransmitted on every frame
[ffmpeg] / libavformat / rtp.c
index 359b1f2c9e923b25b2262fa94f737ba3d1768583..f45ad3752efd16340a5bdee0173e7eb24ef4bbff 100644 (file)
 #include "bitstream.h"
 
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
+#include "network.h"
 
 #include "rtp_internal.h"
 #include "rtp_h264.h"
+#include "rtp_mpv.h"
 
 //#define DEBUG
 
@@ -190,7 +187,7 @@ static void register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler)
     RTPFirstDynamicPayloadHandler= handler;
 }
 
-void av_register_rtp_dynamic_payload_handlers()
+void av_register_rtp_dynamic_payload_handlers(void)
 {
     register_dynamic_payload_handler(&mp4v_es_handler);
     register_dynamic_payload_handler(&mpeg4_generic_handler);
@@ -211,7 +208,6 @@ int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
     return -1;
 }
 
-/* return < 0 if unknown payload type */
 int rtp_get_payload_type(AVCodecContext *codec)
 {
     int i, payload_type;
@@ -227,24 +223,14 @@ int rtp_get_payload_type(AVCodecContext *codec)
     return payload_type;
 }
 
-static inline uint32_t decode_be32(const uint8_t *p)
-{
-    return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
-}
-
-static inline uint64_t decode_be64(const uint8_t *p)
-{
-    return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
-}
-
 static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
 {
     if (buf[1] != 200)
         return -1;
-    s->last_rtcp_ntp_time = decode_be64(buf + 8);
+    s->last_rtcp_ntp_time = AV_RB64(buf + 8);
     if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
         s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
-    s->last_rtcp_timestamp = decode_be32(buf + 16);
+    s->last_rtcp_timestamp = AV_RB32(buf + 16);
     return 0;
 }
 
@@ -340,11 +326,6 @@ static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32
 }
 #endif
 
-/**
- * some rtp servers assume client is dead if they don't hear from them...
- * so we send a Receiver Report to the provided ByteIO context
- * (we don't have access to the rtcp handle from here)
- */
 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
 {
     ByteIOContext pb;
@@ -479,7 +460,7 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r
         case CODEC_ID_MP3:
         case CODEC_ID_MPEG4:
         case CODEC_ID_H264:
-            st->need_parsing = 1;
+            st->need_parsing = AVSTREAM_PARSE_FULL;
             break;
         default:
             break;
@@ -525,7 +506,7 @@ static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)
     infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);
 
     /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving)
-       In my test, the faad decoder doesnt behave correctly when sending each AU one by one
+       In my test, the FAAD decoder does not behave correctly when sending each AU one by one
        but does when sending the whole as one big packet...  */
     infos->au_headers[0].size = 0;
     infos->au_headers[0].index = 0;
@@ -623,9 +604,9 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
         return -1;
     }
     payload_type = buf[1] & 0x7f;
-    seq  = (buf[2] << 8) | buf[3];
-    timestamp = decode_be32(buf + 4);
-    ssrc = decode_be32(buf + 8);
+    seq  = AV_RB16(buf + 2);
+    timestamp = AV_RB32(buf + 4);
+    ssrc = AV_RB32(buf + 8);
     /* store the ssrc in the RTPDemuxContext */
     s->ssrc = ssrc;
 
@@ -664,7 +645,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
             /* better than nothing: skip mpeg audio RTP header */
             if (len <= 4)
                 return -1;
-            h = decode_be32(buf);
+            h = AV_RB32(buf);
             len -= 4;
             buf += 4;
             av_new_packet(pkt, len);
@@ -674,7 +655,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
             /* better than nothing: skip mpeg video RTP header */
             if (len <= 4)
                 return -1;
-            h = decode_be32(buf);
+            h = AV_RB32(buf);
             buf += 4;
             len -= 4;
             if (h & (1 << 26)) {
@@ -761,7 +742,7 @@ static int rtp_write_header(AVFormatContext *s1)
 
     max_packet_size = url_fget_max_packet_size(&s1->pb);
     if (max_packet_size <= 12)
-        return AVERROR_IO;
+        return AVERROR(EIO);
     s->max_payload_size = max_packet_size - 12;
 
     switch(st->codec->codec_id) {
@@ -808,7 +789,7 @@ static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
 
 /* send an rtp packet. sequence number is incremented, but the caller
    must update the timestamp itself */
-static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
+void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
 {
     RTPDemuxContext *s = s1->priv_data;
 
@@ -856,7 +837,7 @@ static void rtp_send_samples(AVFormatContext *s1,
         n = (s->buf_ptr - s->buf);
         /* if buffer full, then send it */
         if (n >= max_packet_size) {
-            rtp_send_data(s1, s->buf, n, 0);
+            ff_rtp_send_data(s1, s->buf, n, 0);
             s->buf_ptr = s->buf;
             /* update timestamp */
             s->timestamp += n / sample_size;
@@ -879,7 +860,7 @@ static void rtp_send_mpegaudio(AVFormatContext *s1,
     len = (s->buf_ptr - s->buf);
     if ((len + size) > max_packet_size) {
         if (len > 4) {
-            rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
+            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 +
@@ -901,7 +882,7 @@ static void rtp_send_mpegaudio(AVFormatContext *s1,
             s->buf[2] = count >> 8;
             s->buf[3] = count;
             memcpy(s->buf + 4, buf1, len);
-            rtp_send_data(s1, s->buf, len + 4, 0);
+            ff_rtp_send_data(s1, s->buf, len + 4, 0);
             size -= len;
             buf1 += len;
             count += len;
@@ -920,55 +901,6 @@ static void rtp_send_mpegaudio(AVFormatContext *s1,
     s->cur_timestamp += st->codec->frame_size;
 }
 
-/* NOTE: a single frame must be passed with sequence header if
-   needed. XXX: use slices. */
-static void 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;
-
-    max_packet_size = s->max_payload_size;
-
-    while (size > 0) {
-        /* XXX: more correct headers */
-        h = 0;
-        if (st->codec->sub_id == 2)
-            h |= 1 << 26; /* mpeg 2 indicator */
-        q = s->buf;
-        *q++ = h >> 24;
-        *q++ = h >> 16;
-        *q++ = h >> 8;
-        *q++ = h;
-
-        if (st->codec->sub_id == 2) {
-            h = 0;
-            *q++ = h >> 24;
-            *q++ = h >> 16;
-            *q++ = h >> 8;
-            *q++ = h;
-        }
-
-        len = max_packet_size - (q - s->buf);
-        if (len > size)
-            len = size;
-
-        memcpy(q, buf1, len);
-        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
-        rtp_send_data(s1, s->buf, q - s->buf, (len == size));
-
-        buf1 += len;
-        size -= len;
-    }
-    s->cur_timestamp++;
-}
-
 static void rtp_send_raw(AVFormatContext *s1,
                          const uint8_t *buf1, int size)
 {
@@ -986,7 +918,7 @@ static void rtp_send_raw(AVFormatContext *s1,
         /* 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
-        rtp_send_data(s1, buf1, len, (len == size));
+        ff_rtp_send_data(s1, buf1, len, (len == size));
 
         buf1 += len;
         size -= len;
@@ -1012,7 +944,7 @@ static void rtp_send_mpegts_raw(AVFormatContext *s1,
 
         out_len = s->buf_ptr - s->buf;
         if (out_len >= s->max_payload_size) {
-            rtp_send_data(s1, s->buf, out_len, 0);
+            ff_rtp_send_data(s1, s->buf, out_len, 0);
             s->buf_ptr = s->buf;
         }
     }
@@ -1062,7 +994,7 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
         rtp_send_mpegaudio(s1, buf1, size);
         break;
     case CODEC_ID_MPEG1VIDEO:
-        rtp_send_mpegvideo(s1, buf1, size);
+        ff_rtp_send_mpegvideo(s1, buf1, size);
         break;
     case CODEC_ID_MPEG2TS:
         rtp_send_mpegts_raw(s1, buf1, size);
@@ -1075,12 +1007,6 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
     return 0;
 }
 
-static int rtp_write_trailer(AVFormatContext *s1)
-{
-    //    RTPDemuxContext *s = s1->priv_data;
-    return 0;
-}
-
 AVOutputFormat rtp_muxer = {
     "rtp",
     "RTP output format",
@@ -1091,5 +1017,4 @@ AVOutputFormat rtp_muxer = {
     CODEC_ID_NONE,
     rtp_write_header,
     rtp_write_packet,
-    rtp_write_trailer,
 };