Browse code

Add RTP packetization of VP8

Patch by Josh Allmann, joshua dot allmann at gmail

Originally committed as revision 24797 to svn://svn.ffmpeg.org/ffmpeg/trunk

Josh Allmann authored on 2010/08/16 23:21:17
Showing 5 changed files
... ...
@@ -219,6 +219,7 @@ OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
219 219
                                             rtpenc_mpv.o     \
220 220
                                             rtpenc.o      \
221 221
                                             rtpenc_h264.o \
222
+                                            rtpenc_vp8.o  \
222 223
                                             rtpenc_xiph.o \
223 224
                                             avc.o
224 225
 OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o httpauth.o
... ...
@@ -55,6 +55,7 @@ static int is_supported(enum CodecID id)
55 55
     case CODEC_ID_AMR_WB:
56 56
     case CODEC_ID_VORBIS:
57 57
     case CODEC_ID_THEORA:
58
+    case CODEC_ID_VP8:
58 59
         return 1;
59 60
     default:
60 61
         return 0;
... ...
@@ -144,6 +145,9 @@ static int rtp_write_header(AVFormatContext *s1)
144 144
         s->max_payload_size -= 6; // ident+frag+tdt/vdt+pkt_num+pkt_length
145 145
         s->num_frames = 0;
146 146
         goto defaultcase;
147
+    case CODEC_ID_VP8:
148
+        av_log(s1, AV_LOG_WARNING, "RTP VP8 payload is still experimental\n");
149
+        break;
147 150
     case CODEC_ID_AMR_NB:
148 151
     case CODEC_ID_AMR_WB:
149 152
         if (!s->max_frames_per_packet)
... ...
@@ -407,6 +411,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
407 407
     case CODEC_ID_THEORA:
408 408
         ff_rtp_send_xiph(s1, pkt->data, size);
409 409
         break;
410
+    case CODEC_ID_VP8:
411
+        ff_rtp_send_vp8(s1, pkt->data, size);
412
+        break;
410 413
     default:
411 414
         /* better than nothing : send the codec raw data */
412 415
         rtp_send_raw(s1, pkt->data, size);
... ...
@@ -68,5 +68,6 @@ void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size);
68 68
 void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size);
69 69
 void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size);
70 70
 void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size);
71
+void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size);
71 72
 
72 73
 #endif /* AVFORMAT_RTPENC_H */
73 74
new file mode 100644
... ...
@@ -0,0 +1,47 @@
0
+/*
1
+ * RTP VP8 Packetizer
2
+ * Copyright (c) 2010 Josh Allmann
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "rtpenc.h"
22
+
23
+/* Based on a draft spec for VP8 RTP.
24
+ * ( http://www.webmproject.org/code/specs/rtp/ ) */
25
+void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buf, int size)
26
+{
27
+    RTPMuxContext *s = s1->priv_data;
28
+    int len, max_packet_size;
29
+
30
+    s->buf_ptr      = s->buf;
31
+    s->timestamp    = s->cur_timestamp;
32
+    max_packet_size = s->max_payload_size - 1; // minus one for header byte
33
+
34
+    *s->buf_ptr++ = 1; // 0b1 indicates start of frame
35
+    while (size > 0) {
36
+        len = FFMIN(size, max_packet_size);
37
+
38
+        memcpy(s->buf_ptr, buf, len);
39
+        ff_rtp_send_data(s1, s->buf, len+1, size == len); // marker bit is last packet in frame
40
+
41
+        size         -= len;
42
+        buf          += len;
43
+        s->buf_ptr    = s->buf;
44
+        *s->buf_ptr++ = 0; // payload descriptor
45
+    }
46
+}
... ...
@@ -412,6 +412,10 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
412 412
                                     c->width, c->height, pix_fmt, config);
413 413
             break;
414 414
         }
415
+        case CODEC_ID_VP8:
416
+            av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n",
417
+                                     payload_type);
418
+            break;
415 419
         default:
416 420
             /* Nothing special to do here... */
417 421
             break;