From patchwork Tue Dec 22 00:35:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 24612 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A95E444A0ED for ; Tue, 22 Dec 2020 03:00:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E46868A898; Tue, 22 Dec 2020 03:00:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f193.google.com (mail-il1-f193.google.com [209.85.166.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 733C468A7D4 for ; Tue, 22 Dec 2020 03:00:08 +0200 (EET) Received: by mail-il1-f193.google.com with SMTP id k8so10561575ilr.4 for ; Mon, 21 Dec 2020 17:00:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d6fmBjXYSn9JUhWJEvkcVKJ5EelUSosaJMYAulJo7BM=; b=QQ9aGYnSb4fuCaYv8EMKJlJljin3H9H+xqGx0w1o5qOFRukDahBUWcpCquBuOvukne BabIGtcSiS5lF5oxfJolLupbuodFvP/6mAwtcJ+1XfUtkQUaov8ueOHkJj67z93lLJWW dTQqe6T0lH5D/94LOV+CFy7bpwa+cSVllJweHV5d/ndNEwXXzzu3CGIz04d3CKQ0bB47 O0Cj6RT9f/Hi1Hl0SxL1jP4kYAM82qxTGHzd/zoVqQvQsF5A4yCZ7Ii9OFqs38KNKJJ6 d4FmaIUGwe87VyhcT37QZ6XtwSSutdBnnkH/F0XJE/dNISqpqnALWRbc1ITJUXHUtSat J1iQ== X-Gm-Message-State: AOAM532lnhfOPRdaGbvnLF/DFYpo+8n0l9JPQuP6hbEHHf0s0eGzw6Kz u1QtRq3Rg3fXyhAvP/EoV9KROWV51jsKpikc X-Google-Smtp-Source: ABdhPJyOuDlmZgThRJGlyzOQtozcq49d+lU/KBYcRsEG/mrIk9GmJr5L71rQ2FmiWYYLfceptJlMng== X-Received: by 2002:a63:d650:: with SMTP id d16mr17276827pgj.277.1608597383225; Mon, 21 Dec 2020 16:36:23 -0800 (PST) Received: from tmm1-imac.lan (ip72-194-222-34.sb.sd.cox.net. [72.194.222.34]) by smtp.gmail.com with ESMTPSA id z7sm18320780pfq.193.2020.12.21.16.36.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 16:36:22 -0800 (PST) From: Aman Karmani To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Dec 2020 16:35:58 -0800 Message-Id: <20201222003600.27621-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/rtsp: add support for satip:// X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aman Karmani Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Karmani The SAT>IP protocol[1] is similar to RTSP. However SAT>IP servers are assumed to speak only MP2T, so DESCRIBE is not used in the same way. When no streams are active, DESCRIBE will return 404 according to the spec (see section 3.5.7). When streams are active, DESCRIBE will return a list of all current streams along with information about their signal strengths. Previously, attemping to use ffmpeg with a rtsp:// url that points to a SAT>IP server would work with some devices and fail due to 404 response on others. Further, if the SAT>IP server was already streaming, ffmpeg would incorrectly consume the DESCRIBE SDP response and join an existing tuner instead of requesting a new session with the URL provided by the user. These issues have been noted by many users across the internet[2][3]. This commit adds proper spec-compliant support for SAT>IP, including: - support for the satip:// psuedo-protocol - avoiding the use of DESCRIBE - parsing and consuming the com.ses.streamID response header - using "Transport: RTP/AVP;unicast" because the optional "/UDP" suffix confuses some servers [1] https://www.satip.info/sites/satip/files/resource/satip_specification_version_1_2_2.pdf [2] https://stackoverflow.com/questions/61194344/does-ffmpeg-violate-the-satip-specification-describe-syntax [3] https://github.com/kodi-pvr/pvr.iptvsimple/issues/196 --- libavformat/rtsp.c | 52 ++++++++++++++++++++++++++++++++++++++----- libavformat/rtsp.h | 6 +++++ libavformat/rtspdec.c | 1 + 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index c7ffa07d9e..4a863dbac3 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -252,6 +252,24 @@ static void finalize_rtp_handler_init(AVFormatContext *s, RTSPStream *rtsp_st, } } +static int init_satip_stream(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + RTSPStream *rtsp_st; + rtsp_st = av_mallocz(sizeof(RTSPStream)); + if (!rtsp_st) + return AVERROR(ENOMEM); + rtsp_st->stream_index = -1; + dynarray_add(&rt->rtsp_streams, + &rt->nb_rtsp_streams, rtsp_st); + av_strlcpy(rtsp_st->control_url, + rt->control_uri, sizeof(rtsp_st->control_url)); + rtsp_st->sdp_payload_type = 33; // MP2T + init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL); + finalize_rtp_handler_init(s, rtsp_st, NULL); + return 0; +} + /* parse the rtpmap description: /[/] */ static int sdp_parse_rtpmap(AVFormatContext *s, AVStream *st, RTSPStream *rtsp_st, @@ -1116,6 +1134,9 @@ void ff_rtsp_parse_line(AVFormatContext *s, } else if (av_stristart(p, "Content-Type:", &p)) { p += strspn(p, SPACE_CHARS); av_strlcpy(reply->content_type, p, sizeof(reply->content_type)); + } else if (av_stristart(p, "com.ses.streamID:", &p)) { + p += strspn(p, SPACE_CHARS); + av_strlcpy(reply->stream_id, p, sizeof(reply->stream_id)); } } @@ -1495,8 +1516,10 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, rtp_opened: port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle); have_port: - snprintf(transport, sizeof(transport) - 1, - "%s/UDP;", trans_pref); + av_strlcat(transport, trans_pref, sizeof(transport)); + av_strlcat(transport, + rt->server_type == RTSP_SERVER_SATIP ? ";" : "/UDP;", + sizeof(transport)); if (rt->server_type != RTSP_SERVER_REAL) av_strlcat(transport, "unicast;", sizeof(transport)); av_strlcatf(transport, sizeof(transport), @@ -1559,6 +1582,15 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, goto fail; } + if (rt->server_type == RTSP_SERVER_SATIP && reply->stream_id[0]) { + char proto[128], host[128], path[512], auth[128]; + int port; + av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), + &port, path, sizeof(path), rt->control_uri); + ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host, + port, "/stream=%s", reply->stream_id); + } + /* XXX: same protocol for all streams is required */ if (i > 0) { if (reply->transports[0].lower_transport != rt->lower_transport || @@ -1710,6 +1742,9 @@ redirect: lower_rtsp_proto = "tls"; default_port = RTSPS_DEFAULT_PORT; rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP; + } else if (!strcmp(proto, "satip")) { + av_strlcpy(proto, "rtsp", sizeof(proto)); + rt->server_type = RTSP_SERVER_SATIP; } if (*auth) { @@ -1857,7 +1892,9 @@ redirect: /* request options supported by the server; this also detects server * type */ - for (rt->server_type = RTSP_SERVER_RTP;;) { + if (rt->server_type != RTSP_SERVER_SATIP) + rt->server_type = RTSP_SERVER_RTP; + for (;;) { cmd[0] = 0; if (rt->server_type == RTSP_SERVER_REAL) av_strlcat(cmd, @@ -1892,9 +1929,12 @@ redirect: break; } - if (CONFIG_RTSP_DEMUXER && s->iformat) - err = ff_rtsp_setup_input_streams(s, reply); - else if (CONFIG_RTSP_MUXER) + if (CONFIG_RTSP_DEMUXER && s->iformat) { + if (rt->server_type == RTSP_SERVER_SATIP) + err = init_satip_stream(s); + else + err = ff_rtsp_setup_input_streams(s, reply); + } else if (CONFIG_RTSP_MUXER) err = ff_rtsp_setup_output_streams(s, host); else av_assert0(0); diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index b74cdc148a..c7c3b3cb52 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -188,6 +188,11 @@ typedef struct RTSPMessageHeader { * Content type header */ char content_type[64]; + + /** + * Stream ID header + */ + char stream_id[64]; } RTSPMessageHeader; /** @@ -210,6 +215,7 @@ enum RTSPServerType { RTSP_SERVER_RTP, /**< Standards-compliant RTP-server */ RTSP_SERVER_REAL, /**< Realmedia-style server */ RTSP_SERVER_WMS, /**< Windows Media server */ + RTSP_SERVER_SATIP,/**< SAT>IP server */ RTSP_SERVER_NB }; diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index bfbb01d586..113da975e1 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -724,6 +724,7 @@ static int rtsp_probe(const AVProbeData *p) #if CONFIG_TLS_PROTOCOL av_strstart(p->filename, "rtsps:", NULL) || #endif + av_strstart(p->filename, "satip:", NULL) || av_strstart(p->filename, "rtsp:", NULL)) return AVPROBE_SCORE_MAX; return 0; From patchwork Tue Dec 22 00:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 24611 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DEF5244B1D0 for ; Tue, 22 Dec 2020 02:43:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BBC9368A898; Tue, 22 Dec 2020 02:43:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1988689CFE for ; Tue, 22 Dec 2020 02:43:09 +0200 (EET) Received: by mail-il1-f170.google.com with SMTP id t9so10548617ilf.2 for ; Mon, 21 Dec 2020 16:43:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O8zxD9zn/8ttW91G56LSfJtZ86B5SkXGE8kO9Dj8jqk=; b=i6EvJpAN9E8WB84z9niQZXJ94vEwBFGPRNiJz2TfOzGcaLlnJL0e+4a7DH5hFyiGpm DvApt+mHsbP3f0Vu9gu2Q8qr6IgXfjEz2rXF2V6UJFrp8lARpiqoOWG6CL6Ns5XTR7CR 9uKWHYxCei0LNSfq3iXdFDaJ8C0hRZdOG1cBpo1Em4K1+8yD7TRBjwFt1e78sL3HayWs ALn01coD6uHt8yGoHDmrdNvw+7pRjveU/qfG5TriaMXWbm5KEmftHlhDvxroFpI0yhvU lyPzgmzMi6E3nie3ZCUfRLRcgiia6RoIU/7qxgpjMCni05gzoqA/y8gLsyREsagwrs2+ UsKg== X-Gm-Message-State: AOAM5300uPhMFozwjPb8zngxsdr7OyNt/WSlFkX6tKnwnNkwqOzQbll3 jflY1dupTFbeUN6XE9yTUyZWegAhqOuO+SUm X-Google-Smtp-Source: ABdhPJzQeW34NDmEfHR3jW+NedSMAho6sBqnPSMkLxysIXSYewYrvChxT5shZZJ7OVNRq7dP5tulbQ== X-Received: by 2002:a63:794:: with SMTP id 142mr17271504pgh.187.1608597384611; Mon, 21 Dec 2020 16:36:24 -0800 (PST) Received: from tmm1-imac.lan (ip72-194-222-34.sb.sd.cox.net. [72.194.222.34]) by smtp.gmail.com with ESMTPSA id z7sm18320780pfq.193.2020.12.21.16.36.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 16:36:23 -0800 (PST) From: Aman Karmani To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Dec 2020 16:35:59 -0800 Message-Id: <20201222003600.27621-2-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201222003600.27621-1-ffmpeg@tmm1.net> References: <20201222003600.27621-1-ffmpeg@tmm1.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avformat/rtpdec_mpegts: add ff_mpegtsraw_dynamic_handler X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aman Karmani Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Karmani Passthrough handler which can be used to receive MP2T stream over RTP, and repackage it into a AV_CODEC_ID_MPEG2TS data stream. Signed-off-by: Aman Karmani --- libavformat/rtpdec_formats.h | 1 + libavformat/rtpdec_mpegts.c | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h index dad2b8ac1b..ce349292df 100644 --- a/libavformat/rtpdec_formats.h +++ b/libavformat/rtpdec_formats.h @@ -74,6 +74,7 @@ extern const RTPDynamicProtocolHandler ff_mpeg_audio_robust_dynamic_handler; extern const RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler; extern const RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler; extern const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler; +extern const RTPDynamicProtocolHandler ff_mpegtsraw_dynamic_handler; extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler; extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler; extern const RTPDynamicProtocolHandler ff_qcelp_dynamic_handler; diff --git a/libavformat/rtpdec_mpegts.c b/libavformat/rtpdec_mpegts.c index 405271f744..6d5a547030 100644 --- a/libavformat/rtpdec_mpegts.c +++ b/libavformat/rtpdec_mpegts.c @@ -20,6 +20,7 @@ */ #include "libavutil/attributes.h" +#include "libavformat/internal.h" #include "mpegts.h" #include "rtpdec_formats.h" @@ -28,6 +29,7 @@ struct PayloadContext { int read_buf_index; int read_buf_size; uint8_t buf[RTP_MAX_PACKET_LENGTH]; + AVStream *raw; }; static void mpegts_close_context(PayloadContext *data) @@ -89,6 +91,50 @@ static int mpegts_handle_packet(AVFormatContext *ctx, PayloadContext *data, return 0; } +static av_cold int mpegtsraw_init(AVFormatContext *ctx, int st_index, + PayloadContext *data) +{ + AVStream *st; + st = avformat_new_stream(ctx, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS; + data->raw = st; + return 0; +} + +static int mpegtsraw_handle_packet(AVFormatContext *ctx, PayloadContext *data, + AVStream *st, AVPacket *pkt, uint32_t *timestamp, + const uint8_t *buf, int len, uint16_t seq, + int flags) +{ + int ret; + + // We don't want to use the RTP timestamps at all. If the mpegts demuxer + // doesn't set any pts/dts, the generic rtpdec code shouldn't try to + // fill it in either, since the mpegts and RTP timestamps are in totally + // different ranges. + *timestamp = RTP_NOTS_VALUE; + + if (!buf || len < 188) { + return AVERROR_INVALIDDATA; + } + + if ((ret = av_new_packet(pkt, len)) < 0) + return ret; + memcpy(pkt->data, buf, len); + pkt->stream_index = data->raw->index; + return 0; +} + +static void mpegtsraw_close_context(PayloadContext *data) +{ + if (!data) + return; + data->raw = NULL; +} + const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler = { .codec_type = AVMEDIA_TYPE_DATA, .priv_data_size = sizeof(PayloadContext), @@ -97,3 +143,12 @@ const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler = { .close = mpegts_close_context, .static_payload_id = 33, }; + +const RTPDynamicProtocolHandler ff_mpegtsraw_dynamic_handler = { + .codec_type = AVMEDIA_TYPE_DATA, + .priv_data_size = sizeof(PayloadContext), + .parse_packet = mpegtsraw_handle_packet, + .init = mpegtsraw_init, + .close = mpegtsraw_close_context, + .static_payload_id = 33, +}; From patchwork Tue Dec 22 00:36:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 24610 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9C4A444B7CB for ; Tue, 22 Dec 2020 02:42:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68D5568A882; Tue, 22 Dec 2020 02:42:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 75F9B68A878 for ; Tue, 22 Dec 2020 02:41:57 +0200 (EET) Received: by mail-il1-f195.google.com with SMTP id q1so10539165ilt.6 for ; Mon, 21 Dec 2020 16:41:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=083d9c3QJRuG2WUO4RF9KcPbOniTCjbvbfX5Te/07Y8=; b=Sr1XcKhArU3YfAEV8qi0xyH3Kegpcr7p/ahb+aZuYRso0mTwKX6S3zVKiJ3KBKsbrn pdxcCvgTnsNs3+KpClLNNkhh4IV0NzyMtCF2SJTD+ilHnP6bd4oB0SuGRm0vM7C87kH2 W30NDII2gvdpO+FZrZHQJ0COLUXv1z6BgFKXOi5XUYGX9O8FXiDaIhg7GyBPhcs8qScC I675geEh2fzxXZAQQ+O6lRqKxPHZEDwsZyZk8pdhKtNjk29bixeGsg9BUU0DQvoVdxy1 5Bpv2zAESMKOHBPv/SUQk//ZfdDbq2HYqaPGQp1HNMODbVK1ozAUdWZd0ccilRTCsBHD armg== X-Gm-Message-State: AOAM5327mlGCJaOBpR0abzXTwyBTMEw5a1Guf6yKqTwEHgHBeyfEG9Ov 2Tro7AMrh/r4SMEP298vGBKtR6Tc3KQF6+4c X-Google-Smtp-Source: ABdhPJxtDhVij4WVGsJNBw6wGm0cd1DdO9X0NP6hWNJGmQQLoniNIeW/etXFiu5IgeujP4qyq8QcxA== X-Received: by 2002:a63:4566:: with SMTP id u38mr17566942pgk.423.1608597386131; Mon, 21 Dec 2020 16:36:26 -0800 (PST) Received: from tmm1-imac.lan (ip72-194-222-34.sb.sd.cox.net. [72.194.222.34]) by smtp.gmail.com with ESMTPSA id z7sm18320780pfq.193.2020.12.21.16.36.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 16:36:25 -0800 (PST) From: Aman Karmani To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Dec 2020 16:36:00 -0800 Message-Id: <20201222003600.27621-3-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201222003600.27621-1-ffmpeg@tmm1.net> References: <20201222003600.27621-1-ffmpeg@tmm1.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/rtsp: add satip_raw flag to receive raw mpegts stream X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aman Karmani Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Karmani This can be used to receive the raw mpegts stream from a SAT>IP server, by letting avformat handle the RTSP/RTP/UDP negotiation and setup, but then simply passing the MP2T stream through instead of demuxing it further. For example, this command would demux/remux the mpegts stream: ffmpeg -i 'satip://192.168.1.99:554/?src=1&freq=12188&pol=h&ro=0.35&msys=dvbs&mtype=qpsk&plts=off&sr=27500&fec=34&pids=0,17,18,167,136,47,71' -map 0 -c copy -f mpegts -y remux.ts Whereas this command would simply save the original stream with the original PIDs and PAT/PMT/etc: ffmpeg -rtsp_flags satip_raw -i 'satip://192.168.1.99:554/?src=1&freq=12188&pol=h&ro=0.35&msys=dvbs&mtype=qpsk&plts=off&sr=27500&fec=34&pids=0,17,18,167,136,47,71' -map 0 -c copy -f mpegtsraw -y raw.ts Signed-off-by: Aman Karmani --- libavformat/rtsp.c | 6 +++++- libavformat/rtsp.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 4a863dbac3..d3864c0c67 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -89,6 +89,7 @@ const AVOption ff_rtsp_options[] = { RTSP_FLAG_OPTS("rtsp_flags", "set RTSP flags"), { "listen", "wait for incoming connections", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_LISTEN}, 0, 0, DEC, "rtsp_flags" }, { "prefer_tcp", "try RTP via TCP first, if available", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_PREFER_TCP}, 0, 0, DEC|ENC, "rtsp_flags" }, + { "satip_raw", "export raw MPEG-TS stream instead of demuxing", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_SATIP_RAW}, 0, 0, DEC, "rtsp_flags" }, RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"), { "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC }, { "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, @@ -256,6 +257,9 @@ static int init_satip_stream(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; + const RTPDynamicProtocolHandler *handler = + (rt->rtsp_flags & RTSP_FLAG_SATIP_RAW) ? &ff_mpegtsraw_dynamic_handler : + &ff_mpegts_dynamic_handler; rtsp_st = av_mallocz(sizeof(RTSPStream)); if (!rtsp_st) return AVERROR(ENOMEM); @@ -265,7 +269,7 @@ static int init_satip_stream(AVFormatContext *s) av_strlcpy(rtsp_st->control_url, rt->control_uri, sizeof(rtsp_st->control_url)); rtsp_st->sdp_payload_type = 33; // MP2T - init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL); + init_rtp_handler(handler, rtsp_st, NULL); finalize_rtp_handler_init(s, rtsp_st, NULL); return 0; } diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index c7c3b3cb52..8a9424a1c5 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -429,6 +429,7 @@ typedef struct RTSPState { #define RTSP_FLAG_RTCP_TO_SOURCE 0x8 /**< Send RTCP packets to the source address of received packets. */ #define RTSP_FLAG_PREFER_TCP 0x10 /**< Try RTP via TCP first if possible. */ +#define RTSP_FLAG_SATIP_RAW 0x20 /**< Export SAT>IP stream as raw MPEG-TS */ typedef struct RTSPSource { char addr[128]; /**< Source-specific multicast include source IP address (from SDP content) */