]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_xiph.c
Merge commit '82b6e451161f19ab90bfb9565b710021caf5dcbd'
[ffmpeg] / libavformat / rtpdec_xiph.c
index 53b49752787a3193b38ec104be6487dea0400af0..a09653f34053193d346c9409f5257780f829c220 100644 (file)
@@ -33,6 +33,7 @@
 #include "libavutil/base64.h"
 #include "libavcodec/bytestream.h"
 
+#include "avio_internal.h"
 #include "internal.h"
 #include "rtpdec.h"
 #include "rtpdec_formats.h"
@@ -49,35 +50,10 @@ struct PayloadContext {
     int split_pkts;
 };
 
-static PayloadContext *xiph_new_context(void)
+static void xiph_close_context(PayloadContext * data)
 {
-    return av_mallocz(sizeof(PayloadContext));
-}
-
-static inline void free_fragment_if_needed(PayloadContext * data)
-{
-    if (data->fragment) {
-        uint8_t* p;
-        avio_close_dyn_buf(data->fragment, &p);
-        av_free(p);
-        data->fragment = NULL;
-    }
-}
-
-static void xiph_free_context(PayloadContext * data)
-{
-    free_fragment_if_needed(data);
+    ffio_free_dyn_buf(&data->fragment);
     av_freep(&data->split_buf);
-    av_freep(&data);
-}
-
-static av_cold int xiph_vorbis_init(AVFormatContext *ctx, int st_index,
-                                    PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_HEADERS;
-    return 0;
 }
 
 
@@ -183,7 +159,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
         int res;
 
         // end packet has been lost somewhere, so drop buffered data
-        free_fragment_if_needed(data);
+        ffio_free_dyn_buf(&data->fragment);
 
         if((res = avio_open_dyn_buf(&data->fragment)) < 0)
             return res;
@@ -196,7 +172,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
         if (data->timestamp != *timestamp) {
             // skip if fragmented timestamp is incorrect;
             // a start packet has been lost somewhere
-            free_fragment_if_needed(data);
+            ffio_free_dyn_buf(&data->fragment);
             av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match!\n");
             return AVERROR_INVALIDDATA;
         }
@@ -309,7 +285,7 @@ parse_packed_headers(const uint8_t * packed_headers,
 static int xiph_parse_fmtp_pair(AVFormatContext *s,
                                 AVStream* stream,
                                 PayloadContext *xiph_data,
-                                char *attr, char *value)
+                                const char *attr, const char *value)
 {
     AVCodecContext *codec = stream->codec;
     int result = 0;
@@ -394,19 +370,19 @@ RTPDynamicProtocolHandler ff_theora_dynamic_handler = {
     .enc_name         = "theora",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_THEORA,
+    .priv_data_size   = sizeof(PayloadContext),
     .parse_sdp_a_line = xiph_parse_sdp_line,
-    .alloc            = xiph_new_context,
-    .free             = xiph_free_context,
-    .parse_packet     = xiph_handle_packet
+    .close            = xiph_close_context,
+    .parse_packet     = xiph_handle_packet,
 };
 
 RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = {
     .enc_name         = "vorbis",
     .codec_type       = AVMEDIA_TYPE_AUDIO,
     .codec_id         = AV_CODEC_ID_VORBIS,
-    .init             = xiph_vorbis_init,
+    .need_parsing     = AVSTREAM_PARSE_HEADERS,
+    .priv_data_size   = sizeof(PayloadContext),
     .parse_sdp_a_line = xiph_parse_sdp_line,
-    .alloc            = xiph_new_context,
-    .free             = xiph_free_context,
-    .parse_packet     = xiph_handle_packet
+    .close            = xiph_close_context,
+    .parse_packet     = xiph_handle_packet,
 };