Browse code

rtpenc: packetizer for VP9 RTP payload format (draft v2)

Thomas Volkert authored on 2016/05/30 23:31:52
Showing 7 changed files
... ...
@@ -13,6 +13,7 @@ version <next>:
13 13
 - protocol blacklisting API
14 14
 - MediaCodec H264 decoding
15 15
 - VC-2 HQ RTP payload format (draft v1) depacketizer and packetizer
16
+- VP9 RTP payload format (draft v2) packetizer
16 17
 - AudioToolbox audio decoders
17 18
 - AudioToolbox audio encoders
18 19
 - coreimage filter (GPU based image filtering on OSX)
... ...
@@ -413,6 +413,7 @@ OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
413 413
                                             rtpenc.o      \
414 414
                                             rtpenc_vc2hq.o              \
415 415
                                             rtpenc_vp8.o  \
416
+                                            rtpenc_vp9.o                \
416 417
                                             rtpenc_xiph.o \
417 418
                                             avc.o hevc.o
418 419
 OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o rtspdec.o httpauth.o \
... ...
@@ -75,6 +75,7 @@ static int is_supported(enum AVCodecID id)
75 75
     case AV_CODEC_ID_VORBIS:
76 76
     case AV_CODEC_ID_THEORA:
77 77
     case AV_CODEC_ID_VP8:
78
+    case AV_CODEC_ID_VP9:
78 79
     case AV_CODEC_ID_ADPCM_G722:
79 80
     case AV_CODEC_ID_ADPCM_G726:
80 81
     case AV_CODEC_ID_ILBC:
... ...
@@ -211,6 +212,16 @@ static int rtp_write_header(AVFormatContext *s1)
211 211
             s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1;
212 212
         }
213 213
         break;
214
+    case AV_CODEC_ID_VP9:
215
+        if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
216
+            av_log(s, AV_LOG_ERROR,
217
+                   "Packetizing VP9 is experimental and its specification is "
218
+                   "still in draft state. "
219
+                   "Please set -strict experimental in order to enable it.\n");
220
+            ret = AVERROR_EXPERIMENTAL;
221
+            goto fail;
222
+        }
223
+        break;
214 224
     case AV_CODEC_ID_VORBIS:
215 225
     case AV_CODEC_ID_THEORA:
216 226
         s->max_frames_per_packet = 15;
... ...
@@ -594,6 +605,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
594 594
     case AV_CODEC_ID_VP8:
595 595
         ff_rtp_send_vp8(s1, pkt->data, size);
596 596
         break;
597
+    case AV_CODEC_ID_VP9:
598
+        ff_rtp_send_vp9(s1, pkt->data, size);
599
+        break;
597 600
     case AV_CODEC_ID_ILBC:
598 601
         rtp_send_ilbc(s1, pkt->data, size);
599 602
         break;
... ...
@@ -93,6 +93,7 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size);
93 93
 void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size);
94 94
 void ff_rtp_send_vc2hq(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced);
95 95
 void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size);
96
+void ff_rtp_send_vp9(AVFormatContext *s1, const uint8_t *buff, int size);
96 97
 void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size);
97 98
 
98 99
 const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *av_restrict start,
99 100
new file mode 100644
... ...
@@ -0,0 +1,54 @@
0
+/*
1
+ * RTP packetizer for VP9 payload format (draft version 02) - experimental
2
+ * Copyright (c) 2016 Thomas Volkert <thomas@netzeal.de>
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
+#define RTP_VP9_DESC_REQUIRED_SIZE 1
24
+
25
+void ff_rtp_send_vp9(AVFormatContext *ctx, const uint8_t *buf, int size)
26
+{
27
+    RTPMuxContext *rtp_ctx = ctx->priv_data;
28
+    int len;
29
+
30
+    rtp_ctx->timestamp  = rtp_ctx->cur_timestamp;
31
+    rtp_ctx->buf_ptr    = rtp_ctx->buf;
32
+
33
+    /* mark the first fragment */
34
+    *rtp_ctx->buf_ptr++ = 0x08;
35
+
36
+    while (size > 0) {
37
+        len = FFMIN(size, rtp_ctx->max_payload_size - RTP_VP9_DESC_REQUIRED_SIZE);
38
+
39
+        if (len == size) {
40
+            /* mark the last fragment */
41
+            rtp_ctx->buf[0] |= 0x04;
42
+        }
43
+
44
+        memcpy(rtp_ctx->buf_ptr, buf, len);
45
+        ff_rtp_send_data(ctx, rtp_ctx->buf, len + RTP_VP9_DESC_REQUIRED_SIZE, size == len);
46
+
47
+        size            -= len;
48
+        buf             += len;
49
+
50
+        /* clear the end bit */
51
+        rtp_ctx->buf[0] &= ~0x08;
52
+    }
53
+}
... ...
@@ -657,6 +657,10 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int
657 657
             av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n",
658 658
                                      payload_type);
659 659
             break;
660
+        case AV_CODEC_ID_VP9:
661
+            av_strlcatf(buff, size, "a=rtpmap:%d VP9/90000\r\n",
662
+                                     payload_type);
663
+            break;
660 664
         case AV_CODEC_ID_MJPEG:
661 665
             if (payload_type >= RTP_PT_PRIVATE)
662 666
                 av_strlcatf(buff, size, "a=rtpmap:%d JPEG/90000\r\n",
... ...
@@ -32,8 +32,8 @@
32 32
 // When bumping major check Ticket5467, 5421, 5451(compatibility with Chromium) for regressing
33 33
 // Also please add any ticket numbers that you belive might regress here
34 34
 #define LIBAVFORMAT_VERSION_MAJOR  57
35
-#define LIBAVFORMAT_VERSION_MINOR  37
36
-#define LIBAVFORMAT_VERSION_MICRO 101
35
+#define LIBAVFORMAT_VERSION_MINOR  38
36
+#define LIBAVFORMAT_VERSION_MICRO 100
37 37
 
38 38
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
39 39
                                                LIBAVFORMAT_VERSION_MINOR, \