]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_h261.c
mov: move stsd finalization to an appropriate place
[ffmpeg] / libavformat / rtpdec_h261.c
index b2d2a53f1cb314fcca0a70e6afac1b8e6189d19c..b1bd1e04756bf7c1b514de71ba58936225e2f3a4 100644 (file)
  * 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"
 
 #define RTP_H261_PAYLOAD_HEADER_SIZE 4
@@ -32,24 +34,14 @@ struct PayloadContext {
     uint32_t     timestamp;
 };
 
-static void h261_free_dyn_buffer(AVIOContext **dyn_buf)
-{
-    uint8_t *ptr_dyn_buffer;
-    avio_close_dyn_buf(*dyn_buf, &ptr_dyn_buffer);
-    av_free(ptr_dyn_buffer);
-    *dyn_buf = NULL;
-}
-
-static av_cold void h261_free_context(PayloadContext *pl_ctx)
+static av_cold void h261_close_context(PayloadContext *pl_ctx)
 {
     /* return if context is invalid */
     if (!pl_ctx)
         return;
 
     /* free buffer if it is valid */
-    if (pl_ctx->buf) {
-        h261_free_dyn_buffer(&pl_ctx->buf);
-    }
+    ffio_free_dyn_buf(&pl_ctx->buf);
 }
 
 static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx,
@@ -62,7 +54,7 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx
 
     /* drop data of previous packets in case of non-continuous (lossy) packet stream */
     if (rtp_h261_ctx->buf && rtp_h261_ctx->timestamp != *timestamp) {
-        h261_free_dyn_buffer(&rtp_h261_ctx->buf);
+        ffio_free_dyn_buf(&rtp_h261_ctx->buf);
         rtp_h261_ctx->endbyte_bits = 0;
     }
 
@@ -127,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;
@@ -177,7 +169,7 @@ RTPDynamicProtocolHandler ff_h261_dynamic_handler = {
     .codec_id          = AV_CODEC_ID_H261,
     .need_parsing      = AVSTREAM_PARSE_FULL,
     .priv_data_size    = sizeof(PayloadContext),
-    .free              = h261_free_context,
+    .close             = h261_close_context,
     .parse_packet      = h261_handle_packet,
     .static_payload_id = 31,
 };