[FFmpeg-cvslog] rtp: Convert to the new bitstream reader

Alexandra Hájková git at videolan.org
Fri May 19 12:00:48 EEST 2017


ffmpeg | branch: master | Alexandra Hájková <alexandra at khirnov.net> | Sun Apr 17 16:59:24 2016 +0200| [b1e7394ea0428318c0407a6c030577196fe834a9] | committer: Diego Biurrun

rtp: Convert to the new bitstream reader

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b1e7394ea0428318c0407a6c030577196fe834a9
---

 libavformat/rtpdec_h261.c         | 19 ++++++++++---------
 libavformat/rtpdec_h263_rfc2190.c | 19 ++++++++++---------
 libavformat/rtpdec_latm.c         | 24 +++++++++++++-----------
 libavformat/rtpdec_mpeg4.c        | 16 +++++++++-------
 libavformat/rtpdec_qt.c           | 31 ++++++++++++++++---------------
 libavformat/rtpenc_h263_rfc2190.c | 29 +++++++++++++++--------------
 6 files changed, 73 insertions(+), 65 deletions(-)

diff --git a/libavformat/rtpdec_h261.c b/libavformat/rtpdec_h261.c
index 00086c21c5..b1bd1e0475 100644
--- a/libavformat/rtpdec_h261.c
+++ b/libavformat/rtpdec_h261.c
@@ -19,7 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/get_bits.h"
+#include "libavcodec/bitstream.h"
+
 #include "avformat.h"
 #include "avio_internal.h"
 #include "rtpdec_formats.h"
@@ -118,18 +119,18 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx
             avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
         } else {
             /* ebit/sbit values inconsistent, assuming packet loss */
-            GetBitContext gb;
-            init_get_bits(&gb, buf, len*8 - ebit);
-            skip_bits(&gb, sbit);
+            BitstreamContext bc;
+            bitstream_init(&bc, buf, len * 8 - ebit);
+            bitstream_skip(&bc, sbit);
             if (rtp_h261_ctx->endbyte_bits) {
-                rtp_h261_ctx->endbyte |= get_bits(&gb, 8 - rtp_h261_ctx->endbyte_bits);
+                rtp_h261_ctx->endbyte |= bitstream_read(&bc, 8 - rtp_h261_ctx->endbyte_bits);
                 avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
             }
-            while (get_bits_left(&gb) >= 8)
-                avio_w8(rtp_h261_ctx->buf, get_bits(&gb, 8));
-            rtp_h261_ctx->endbyte_bits = get_bits_left(&gb);
+            while (bitstream_bits_left(&bc) >= 8)
+                avio_w8(rtp_h261_ctx->buf, bitstream_read(&bc, 8));
+            rtp_h261_ctx->endbyte_bits = bitstream_bits_left(&bc);
             if (rtp_h261_ctx->endbyte_bits)
-                rtp_h261_ctx->endbyte = get_bits(&gb, rtp_h261_ctx->endbyte_bits) <<
+                rtp_h261_ctx->endbyte = bitstream_read(&bc, rtp_h261_ctx->endbyte_bits) <<
                                         (8 - rtp_h261_ctx->endbyte_bits);
             ebit = 0;
             len  = 0;
diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c
index 019eea779b..5744d71da0 100644
--- a/libavformat/rtpdec_h263_rfc2190.c
+++ b/libavformat/rtpdec_h263_rfc2190.c
@@ -30,7 +30,8 @@
 #include "rtpdec_formats.h"
 #include "libavutil/attributes.h"
 #include "libavutil/intreadwrite.h"
-#include "libavcodec/get_bits.h"
+
+#include "libavcodec/bitstream.h"
 
 struct PayloadContext {
     AVIOContext *buf;
@@ -141,18 +142,18 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             avio_w8(data->buf, data->endbyte);
         } else {
             /* Start/end skip bits not matching - missed packets? */
-            GetBitContext gb;
-            init_get_bits(&gb, buf, len*8 - ebit);
-            skip_bits(&gb, sbit);
+            BitstreamContext bc;
+            bitstream_init(&bc, buf, len * 8 - ebit);
+            bitstream_skip(&bc, sbit);
             if (data->endbyte_bits) {
-                data->endbyte |= get_bits(&gb, 8 - data->endbyte_bits);
+                data->endbyte |= bitstream_read(&bc, 8 - data->endbyte_bits);
                 avio_w8(data->buf, data->endbyte);
             }
-            while (get_bits_left(&gb) >= 8)
-                avio_w8(data->buf, get_bits(&gb, 8));
-            data->endbyte_bits = get_bits_left(&gb);
+            while (bitstream_bits_left(&bc) >= 8)
+                avio_w8(data->buf, bitstream_read(&bc, 8));
+            data->endbyte_bits = bitstream_bits_left(&bc);
             if (data->endbyte_bits)
-                data->endbyte = get_bits(&gb, data->endbyte_bits) <<
+                data->endbyte = bitstream_read(&bc, data->endbyte_bits) <<
                                 (8 - data->endbyte_bits);
             ebit = 0;
             len = 0;
diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index df85ed3615..bb826269b0 100644
--- a/libavformat/rtpdec_latm.c
+++ b/libavformat/rtpdec_latm.c
@@ -19,11 +19,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avstring.h"
+
+#include "libavcodec/bitstream.h"
+
 #include "avio_internal.h"
 #include "rtpdec_formats.h"
 #include "internal.h"
-#include "libavutil/avstring.h"
-#include "libavcodec/get_bits.h"
 
 struct PayloadContext {
     AVIOContext *dyn_buf;
@@ -92,7 +94,7 @@ static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data,
 static int parse_fmtp_config(AVStream *st, const char *value)
 {
     int len = ff_hex_to_data(NULL, value), i, ret = 0;
-    GetBitContext gb;
+    BitstreamContext bc;
     uint8_t *config;
     int audio_mux_version, same_time_framing, num_programs, num_layers;
 
@@ -101,12 +103,12 @@ static int parse_fmtp_config(AVStream *st, const char *value)
     if (!config)
         return AVERROR(ENOMEM);
     ff_hex_to_data(config, value);
-    init_get_bits(&gb, config, len*8);
-    audio_mux_version = get_bits(&gb, 1);
-    same_time_framing = get_bits(&gb, 1);
-    skip_bits(&gb, 6); /* num_sub_frames */
-    num_programs      = get_bits(&gb, 4);
-    num_layers        = get_bits(&gb, 3);
+    bitstream_init(&bc, config, len * 8);
+    audio_mux_version = bitstream_read(&bc, 1);
+    same_time_framing = bitstream_read(&bc, 1);
+    bitstream_skip(&bc, 6); /* num_sub_frames */
+    num_programs      = bitstream_read(&bc, 4);
+    num_layers        = bitstream_read(&bc, 3);
     if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 ||
         num_layers != 0) {
         avpriv_report_missing_feature(NULL, "LATM config (%d,%d,%d,%d)",
@@ -116,7 +118,7 @@ static int parse_fmtp_config(AVStream *st, const char *value)
         goto end;
     }
     av_freep(&st->codecpar->extradata);
-    st->codecpar->extradata_size = (get_bits_left(&gb) + 7)/8;
+    st->codecpar->extradata_size = (bitstream_bits_left(&bc) + 7) / 8;
     st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size +
                                          AV_INPUT_BUFFER_PADDING_SIZE);
     if (!st->codecpar->extradata) {
@@ -124,7 +126,7 @@ static int parse_fmtp_config(AVStream *st, const char *value)
         goto end;
     }
     for (i = 0; i < st->codecpar->extradata_size; i++)
-        st->codecpar->extradata[i] = get_bits(&gb, 8);
+        st->codecpar->extradata[i] = bitstream_read(&bc, 8);
 
 end:
     av_free(config);
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index 00a732b1cc..b3cd6c9404 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -27,11 +27,13 @@
  * @author Romain Degez
  */
 
-#include "rtpdec_formats.h"
-#include "internal.h"
 #include "libavutil/attributes.h"
 #include "libavutil/avstring.h"
-#include "libavcodec/get_bits.h"
+
+#include "libavcodec/bitstream.h"
+
+#include "rtpdec_formats.h"
+#include "internal.h"
 
 #define MAX_AAC_HBR_FRAME_SIZE 8191
 
@@ -113,7 +115,7 @@ static int parse_fmtp_config(AVCodecParameters *par, const char *value)
 static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
 {
     int au_headers_length, au_header_size, i;
-    GetBitContext getbitcontext;
+    BitstreamContext bctx;
 
     if (len < 2)
         return AVERROR_INVALIDDATA;
@@ -134,7 +136,7 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
     if (len < data->au_headers_length_bytes)
         return AVERROR_INVALIDDATA;
 
-    init_get_bits(&getbitcontext, buf, data->au_headers_length_bytes * 8);
+    bitstream_init(&bctx, buf, data->au_headers_length_bytes * 8);
 
     /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */
     au_header_size = data->sizelength + data->indexlength;
@@ -151,8 +153,8 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
     }
 
     for (i = 0; i < data->nb_au_headers; ++i) {
-        data->au_headers[i].size  = get_bits_long(&getbitcontext, data->sizelength);
-        data->au_headers[i].index = get_bits_long(&getbitcontext, data->indexlength);
+        data->au_headers[i].size  = bitstream_read(&bctx, data->sizelength);
+        data->au_headers[i].index = bitstream_read(&bctx, data->indexlength);
     }
 
     return 0;
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index 97df210916..2c0f8188b6 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -25,13 +25,14 @@
  * @author Ronald S. Bultje <rbultje at ronald.bitfreak.net>
  */
 
+#include "libavcodec/bitstream.h"
+
 #include "avformat.h"
 #include "internal.h"
 #include "avio_internal.h"
 #include "rtp.h"
 #include "rtpdec.h"
 #include "isom.h"
-#include "libavcodec/get_bits.h"
 
 struct PayloadContext {
     AVPacket pkt;
@@ -45,7 +46,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
                                int len, uint16_t seq, int flags)
 {
     AVIOContext pb;
-    GetBitContext gb;
+    BitstreamContext bc;
     int packing_scheme, has_payload_desc, has_packet_info, alen,
         has_marker_bit = flags & RTP_FLAG_MARKER,
         keyframe;
@@ -71,38 +72,38 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
      * The RTP payload is described in:
      * http://developer.apple.com/quicktime/icefloe/dispatch026.html
      */
-    init_get_bits(&gb, buf, len << 3);
+    bitstream_init(&bc, buf, len << 3);
     ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
 
     if (len < 4)
         return AVERROR_INVALIDDATA;
 
-    skip_bits(&gb, 4); // version
-    if ((packing_scheme = get_bits(&gb, 2)) == 0)
+    bitstream_skip(&bc, 4); // version
+    if ((packing_scheme = bitstream_read(&bc, 2)) == 0)
         return AVERROR_INVALIDDATA;
-    keyframe            = get_bits1(&gb);
-    has_payload_desc    = get_bits1(&gb);
-    has_packet_info     = get_bits1(&gb);
-    skip_bits(&gb, 23); // reserved:7, cache payload info:1, payload ID:15
+    keyframe            = bitstream_read_bit(&bc);
+    has_payload_desc    = bitstream_read_bit(&bc);
+    has_packet_info     = bitstream_read_bit(&bc);
+    bitstream_skip(&bc, 23); // reserved:7, cache payload info:1, payload ID:15
 
     if (has_payload_desc) {
         int data_len, pos, is_start, is_finish;
         uint32_t tag;
 
-        pos = get_bits_count(&gb) >> 3;
+        pos = bitstream_tell(&bc) >> 3;
         if (pos + 12 > len)
             return AVERROR_INVALIDDATA;
 
-        skip_bits(&gb, 2); // has non-I-frames:1, is sparse:1
-        is_start  = get_bits1(&gb);
-        is_finish = get_bits1(&gb);
+        bitstream_skip(&bc, 2); // has non-I-frames:1, is sparse:1
+        is_start  = bitstream_read_bit(&bc);
+        is_finish = bitstream_read_bit(&bc);
         if (!is_start || !is_finish) {
             avpriv_request_sample(s, "RTP-X-QT with payload description "
                                   "split over several packets");
             return AVERROR_PATCHWELCOME;
         }
-        skip_bits(&gb, 12); // reserved
-        data_len = get_bits(&gb, 16);
+        bitstream_skip(&bc, 12); // reserved
+        data_len = bitstream_read(&bc, 16);
 
         avio_seek(&pb, pos + 4, SEEK_SET);
         tag = avio_rl32(&pb);
diff --git a/libavformat/rtpenc_h263_rfc2190.c b/libavformat/rtpenc_h263_rfc2190.c
index b8d7a0ab1c..750a52bcd8 100644
--- a/libavformat/rtpenc_h263_rfc2190.c
+++ b/libavformat/rtpenc_h263_rfc2190.c
@@ -19,10 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/bitstream.h"
+#include "libavcodec/put_bits.h"
+
 #include "avformat.h"
 #include "rtpenc.h"
-#include "libavcodec/put_bits.h"
-#include "libavcodec/get_bits.h"
 
 struct H263Info {
     int src;
@@ -103,7 +104,7 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,
 {
     RTPMuxContext *s = s1->priv_data;
     int len, sbits = 0, ebits = 0;
-    GetBitContext gb;
+    BitstreamContext bc;
     struct H263Info info = { 0 };
     struct H263State state = { 0 };
     int mb_info_pos = 0, mb_info_count = mb_info_size / 12;
@@ -111,17 +112,17 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,
 
     s->timestamp = s->cur_timestamp;
 
-    init_get_bits(&gb, buf, size*8);
-    if (get_bits(&gb, 22) == 0x20) { /* Picture Start Code */
-        info.tr  = get_bits(&gb, 8);
-        skip_bits(&gb, 2); /* PTYPE start, H.261 disambiguation */
-        skip_bits(&gb, 3); /* Split screen, document camera, freeze picture release */
-        info.src = get_bits(&gb, 3);
-        info.i   = get_bits(&gb, 1);
-        info.u   = get_bits(&gb, 1);
-        info.s   = get_bits(&gb, 1);
-        info.a   = get_bits(&gb, 1);
-        info.pb  = get_bits(&gb, 1);
+    bitstream_init(&bc, buf, size * 8);
+    if (bitstream_read(&bc, 22) == 0x20) { /* Picture Start Code */
+        info.tr  = bitstream_read(&bc, 8);
+        bitstream_skip(&bc, 2); /* PTYPE start, H.261 disambiguation */
+        bitstream_skip(&bc, 3); /* Split screen, document camera, freeze picture release */
+        info.src = bitstream_read(&bc, 3);
+        info.i   = bitstream_read(&bc, 1);
+        info.u   = bitstream_read(&bc, 1);
+        info.s   = bitstream_read(&bc, 1);
+        info.a   = bitstream_read(&bc, 1);
+        info.pb  = bitstream_read(&bc, 1);
     }
 
     while (size > 0) {



More information about the ffmpeg-cvslog mailing list