]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/sapenc.c
dv: use AVStream.index instead of abusing AVStream.id
[ffmpeg] / libavformat / sapenc.c
index 9bbacef6801c409a55b4076892399a9f3140f783..1575848b3ac752ff27d83b3a3baa31a8611459da 100644 (file)
@@ -2,31 +2,34 @@
  * Session Announcement Protocol (RFC 2974) muxer
  * 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 "avformat.h"
+#include "libavutil/parseutils.h"
 #include "libavutil/random_seed.h"
 #include "libavutil/avstring.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/time.h"
 #include "internal.h"
 #include "network.h"
 #include "os_support.h"
 #include "rtpenc_chain.h"
+#include "url.h"
 
 struct SAPState {
     uint8_t    *ann;
@@ -45,19 +48,19 @@ static int sap_write_close(AVFormatContext *s)
         if (!rtpctx)
             continue;
         av_write_trailer(rtpctx);
-        url_fclose(rtpctx->pb);
+        avio_close(rtpctx->pb);
         avformat_free_context(rtpctx);
         s->streams[i]->priv_data = NULL;
     }
 
     if (sap->last_time && sap->ann && sap->ann_fd) {
         sap->ann[0] |= 4; /* Session deletion*/
-        url_write(sap->ann_fd, sap->ann, sap->ann_size);
+        ffurl_write(sap->ann_fd, sap->ann, sap->ann_size);
     }
 
     av_freep(&sap->ann);
     if (sap->ann_fd)
-        url_close(sap->ann_fd);
+        ffurl_close(sap->ann_fd);
     ff_network_close();
     return 0;
 }
@@ -87,23 +90,22 @@ static int sap_write_header(AVFormatContext *s)
     option_list = strrchr(path, '?');
     if (option_list) {
         char buf[50];
-        if (find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
+        if (av_find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
             port = strtol(buf, NULL, 10);
         }
-        if (find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
+        if (av_find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
             same_port = strtol(buf, NULL, 10);
         }
-        if (find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
+        if (av_find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
             ttl = strtol(buf, NULL, 10);
         }
-        if (find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
+        if (av_find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
             av_strlcpy(announce_addr, buf, sizeof(announce_addr));
         }
     }
 
     if (!announce_addr[0]) {
-        struct addrinfo hints, *ai = NULL;
-        memset(&hints, 0, sizeof(hints));
+        struct addrinfo hints = { 0 }, *ai = NULL;
         hints.ai_family = AF_UNSPEC;
         if (getaddrinfo(host, NULL, &hints, &ai)) {
             av_log(s, AV_LOG_ERROR, "Unable to resolve %s\n", host);
@@ -144,25 +146,28 @@ static int sap_write_header(AVFormatContext *s)
                     "?ttl=%d", ttl);
         if (!same_port)
             base_port += 2;
-        ret = url_open(&fd, url, URL_WRONLY);
+        ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
         if (ret) {
             ret = AVERROR(EIO);
             goto fail;
         }
-        s->streams[i]->priv_data = contexts[i] =
-            ff_rtp_chain_mux_open(s, s->streams[i], fd, 0);
+        ret = ff_rtp_chain_mux_open(&contexts[i], s, s->streams[i], fd, 0);
+        if (ret < 0)
+            goto fail;
+        s->streams[i]->priv_data = contexts[i];
         av_strlcpy(contexts[i]->filename, url, sizeof(contexts[i]->filename));
     }
 
     ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
                 "?ttl=%d&connect=1", ttl);
-    ret = url_open(&sap->ann_fd, url, URL_WRONLY);
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE,
+                     &s->interrupt_callback, NULL);
     if (ret) {
         ret = AVERROR(EIO);
         goto fail;
     }
 
-    udp_fd = url_get_file_handle(sap->ann_fd);
+    udp_fd = ffurl_get_file_handle(sap->ann_fd);
     if (getsockname(udp_fd, (struct sockaddr*) &localaddr, &addrlen)) {
         ret = AVERROR(EIO);
         goto fail;
@@ -206,8 +211,8 @@ static int sap_write_header(AVFormatContext *s)
     av_strlcpy(&sap->ann[pos], "application/sdp", sap->ann_size - pos);
     pos += strlen(&sap->ann[pos]) + 1;
 
-    if (avf_sdp_create(contexts, s->nb_streams, &sap->ann[pos],
-                       sap->ann_size - pos)) {
+    if (av_sdp_create(contexts, s->nb_streams, &sap->ann[pos],
+                      sap->ann_size - pos)) {
         ret = AVERROR_INVALIDDATA;
         goto fail;
     }
@@ -216,7 +221,7 @@ static int sap_write_header(AVFormatContext *s)
     pos += strlen(&sap->ann[pos]);
     sap->ann_size = pos;
 
-    if (sap->ann_size > url_get_max_packet_size(sap->ann_fd)) {
+    if (sap->ann_size > sap->ann_fd->max_packet_size) {
         av_log(s, AV_LOG_ERROR, "Announcement too large to send in one "
                                 "packet\n");
         goto fail;
@@ -237,9 +242,9 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
     int64_t now = av_gettime();
 
     if (!sap->last_time || now - sap->last_time > 5000000) {
-        int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
+        int ret = ffurl_write(sap->ann_fd, sap->ann, sap->ann_size);
         /* Don't abort even if we get "Destination unreachable" */
-        if (ret < 0 && ret != FF_NETERROR(ECONNREFUSED))
+        if (ret < 0 && ret != AVERROR(ECONNREFUSED))
             return ret;
         sap->last_time = now;
     }
@@ -248,16 +253,13 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
 }
 
 AVOutputFormat ff_sap_muxer = {
-    "sap",
-    NULL_IF_CONFIG_SMALL("SAP output format"),
-    NULL,
-    NULL,
-    sizeof(struct SAPState),
-    CODEC_ID_AAC,
-    CODEC_ID_MPEG4,
-    sap_write_header,
-    sap_write_packet,
-    sap_write_close,
-    .flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER,
+    .name              = "sap",
+    .long_name         = NULL_IF_CONFIG_SMALL("SAP output"),
+    .priv_data_size    = sizeof(struct SAPState),
+    .audio_codec       = AV_CODEC_ID_AAC,
+    .video_codec       = AV_CODEC_ID_MPEG4,
+    .write_header      = sap_write_header,
+    .write_packet      = sap_write_packet,
+    .write_trailer     = sap_write_close,
+    .flags             = AVFMT_NOFILE | AVFMT_GLOBALHEADER,
 };
-