OSDN Git Service

rtpdec: Use ffio_free_dyn_buf
[android-x86/external-ffmpeg.git] / libavformat / rtpdec_svq3.c
index e93e31c..030b379 100644 (file)
 /**
  * @file
  * @brief RTP support for the SV3V (SVQ3) payload
- * (http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization)
  * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+ * @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization
  */
 
 #include <string.h>
 #include "libavutil/intreadwrite.h"
+#include "avio_internal.h"
 #include "rtp.h"
 #include "rtpdec.h"
 #include "rtpdec_formats.h"
@@ -41,7 +42,8 @@ struct PayloadContext {
 static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
                               AVStream *st, AVPacket *pkt,
                               uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     int config_packet, start_packet, end_packet;
 
@@ -68,12 +70,12 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
         AV_WB32(st->codec->extradata + 4, len);
         memcpy(st->codec->extradata + 8, buf, len);
 
-        /* We set codec_id to CODEC_ID_NONE initially to
+        /* We set codec_id to AV_CODEC_ID_NONE initially to
          * delay decoder initialization since extradata is
          * carried within the RTP stream, not SDP. Here,
-         * by setting codec_id to CODEC_ID_SVQ3, we are signalling
+         * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
          * to the decoder that it is OK to initialize. */
-        st->codec->codec_id = CODEC_ID_SVQ3;
+        st->codec->codec_id = AV_CODEC_ID_SVQ3;
 
         return AVERROR(EAGAIN);
     }
@@ -81,11 +83,7 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
     if (start_packet) {
         int res;
 
-        if (sv->pktbuf) {
-            uint8_t *tmp;
-            url_close_dyn_buf(sv->pktbuf, &tmp);
-            av_free(tmp);
-        }
+        ffio_free_dyn_buf(&sv->pktbuf);
         if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
             return res;
         sv->timestamp   = *timestamp;
@@ -97,38 +95,27 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
     avio_write(sv->pktbuf, buf, len);
 
     if (end_packet) {
-        av_init_packet(pkt);
-        pkt->stream_index = st->index;
+        int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
+        if (ret < 0)
+            return ret;
+
         *timestamp        = sv->timestamp;
-        pkt->size         = url_close_dyn_buf(sv->pktbuf, &pkt->data);
-        pkt->destruct     = av_destruct_packet;
-        sv->pktbuf        = NULL;
         return 0;
     }
 
     return AVERROR(EAGAIN);
 }
 
-static PayloadContext *svq3_extradata_new(void)
-{
-    return av_mallocz(sizeof(PayloadContext));
-}
-
 static void svq3_extradata_free(PayloadContext *sv)
 {
-    if (sv->pktbuf) {
-        uint8_t *buf;
-        url_close_dyn_buf(sv->pktbuf, &buf);
-        av_free(buf);
-    }
-    av_free(sv);
+    ffio_free_dyn_buf(&sv->pktbuf);
 }
 
 RTPDynamicProtocolHandler ff_svq3_dynamic_handler = {
     .enc_name         = "X-SV3V-ES",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
-    .codec_id         = CODEC_ID_NONE,      // see if (config_packet) above
-    .open             = svq3_extradata_new,
-    .close            = svq3_extradata_free,
+    .codec_id         = AV_CODEC_ID_NONE,      // see if (config_packet) above
+    .priv_data_size   = sizeof(PayloadContext),
+    .free             = svq3_extradata_free,
     .parse_packet     = svq3_parse_packet,
 };