]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/sapdec.c
swf: Move shared table out of the header file
[ffmpeg] / libavformat / sapdec.c
index ef1ecc47d7a88568d7d2b98c951f4e2f27d9bd61..c1cdc8fb72f31944be06d50ace6ac4fb12537ce0 100644 (file)
@@ -2,20 +2,20 @@
  * Session Announcement Protocol (RFC 2974) demuxer
  * Copyright (c) 2010 Martin Storsjo
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "network.h"
 #include "os_support.h"
 #include "internal.h"
+#include "avio_internal.h"
+#include "url.h"
 #if HAVE_POLL_H
 #include <poll.h>
 #endif
-#include <sys/time.h>
 
 struct SAPState {
     URLContext *ann_fd;
@@ -50,16 +51,15 @@ static int sap_read_close(AVFormatContext *s)
 {
     struct SAPState *sap = s->priv_data;
     if (sap->sdp_ctx)
-        av_close_input_stream(sap->sdp_ctx);
+        avformat_close_input(&sap->sdp_ctx);
     if (sap->ann_fd)
-        url_close(sap->ann_fd);
+        ffurl_close(sap->ann_fd);
     av_freep(&sap->sdp);
     ff_network_close();
     return 0;
 }
 
-static int sap_read_header(AVFormatContext *s,
-                           AVFormatParameters *ap)
+static int sap_read_header(AVFormatContext *s)
 {
     struct SAPState *sap = s->priv_data;
     char host[1024], path[1024], url[1024];
@@ -83,7 +83,8 @@ static int sap_read_header(AVFormatContext *s,
 
     ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
                 port);
-    ret = url_open(&sap->ann_fd, url, URL_RDONLY);
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ,
+                     &s->interrupt_callback, NULL);
     if (ret)
         goto fail;
 
@@ -91,7 +92,7 @@ static int sap_read_header(AVFormatContext *s,
         int addr_type, auth_len;
         int pos;
 
-        ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf) - 1);
+        ret = ffurl_read(sap->ann_fd, recvbuf, sizeof(recvbuf) - 1);
         if (ret == AVERROR(EAGAIN))
             continue;
         if (ret < 0)
@@ -142,7 +143,7 @@ static int sap_read_header(AVFormatContext *s,
     }
 
     av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp);
-    init_put_byte(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
+    ffio_init_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
                   NULL, NULL);
 
     infmt = av_find_input_format("sdp");
@@ -154,19 +155,20 @@ static int sap_read_header(AVFormatContext *s,
         goto fail;
     }
     sap->sdp_ctx->max_delay = s->max_delay;
-    ap->prealloced_context = 1;
-    ret = av_open_input_stream(&sap->sdp_ctx, &sap->sdp_pb, "temp.sdp",
-                               infmt, ap);
+    sap->sdp_ctx->pb        = &sap->sdp_pb;
+    sap->sdp_ctx->interrupt_callback = s->interrupt_callback;
+    ret = avformat_open_input(&sap->sdp_ctx, "temp.sdp", infmt, NULL);
     if (ret < 0)
         goto fail;
     if (sap->sdp_ctx->ctx_flags & AVFMTCTX_NOHEADER)
         s->ctx_flags |= AVFMTCTX_NOHEADER;
     for (i = 0; i < sap->sdp_ctx->nb_streams; i++) {
-        AVStream *st = av_new_stream(s, i);
+        AVStream *st = avformat_new_stream(s, NULL);
         if (!st) {
             ret = AVERROR(ENOMEM);
             goto fail;
         }
+        st->id = i;
         avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);
         st->time_base = sap->sdp_ctx->streams[i]->time_base;
     }
@@ -181,7 +183,7 @@ fail:
 static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
 {
     struct SAPState *sap = s->priv_data;
-    int fd = url_get_file_handle(sap->ann_fd);
+    int fd = ffurl_get_file_handle(sap->ann_fd);
     int n, ret;
     struct pollfd p = {fd, POLLIN, 0};
     uint8_t recvbuf[1500];
@@ -193,7 +195,7 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
         n = poll(&p, 1, 0);
         if (n <= 0 || !(p.revents & POLLIN))
             break;
-        ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf));
+        ret = ffurl_read(sap->ann_fd, recvbuf, sizeof(recvbuf));
         if (ret >= 8) {
             uint16_t hash = AV_RB16(&recvbuf[2]);
             /* Should ideally check the source IP address, too */
@@ -210,11 +212,12 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
     if (s->ctx_flags & AVFMTCTX_NOHEADER) {
         while (sap->sdp_ctx->nb_streams > s->nb_streams) {
             int i = s->nb_streams;
-            AVStream *st = av_new_stream(s, i);
+            AVStream *st = avformat_new_stream(s, NULL);
             if (!st) {
                 av_free_packet(pkt);
                 return AVERROR(ENOMEM);
             }
+            st->id = i;
             avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);
             st->time_base = sap->sdp_ctx->streams[i]->time_base;
         }
@@ -223,13 +226,12 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
 }
 
 AVInputFormat ff_sap_demuxer = {
-    "sap",
-    NULL_IF_CONFIG_SMALL("SAP input format"),
-    sizeof(struct SAPState),
-    sap_probe,
-    sap_read_header,
-    sap_fetch_packet,
-    sap_read_close,
-    .flags = AVFMT_NOFILE,
+    .name           = "sap",
+    .long_name      = NULL_IF_CONFIG_SMALL("SAP input"),
+    .priv_data_size = sizeof(struct SAPState),
+    .read_probe     = sap_probe,
+    .read_header    = sap_read_header,
+    .read_packet    = sap_fetch_packet,
+    .read_close     = sap_read_close,
+    .flags          = AVFMT_NOFILE,
 };
-