From patchwork Thu Mar 2 01:42:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Luo X-Patchwork-Id: 2742 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.31.14 with SMTP id f14csp130024vsf; Thu, 2 Mar 2017 23:32:55 -0800 (PST) X-Received: by 10.28.195.197 with SMTP id t188mr1750222wmf.61.1488526375059; Thu, 02 Mar 2017 23:32:55 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h198si1765978wmg.123.2017.03.02.23.32.54; Thu, 02 Mar 2017 23:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D96506882B1; Fri, 3 Mar 2017 09:32:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D18068827B for ; Thu, 2 Mar 2017 04:06:35 +0200 (EET) Received: by mail-pg0-f67.google.com with SMTP id x17so7573902pgi.0 for ; Wed, 01 Mar 2017 18:06:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mmHu/U5vzBr+IR9dVQ/d+gMZ9hQ1H/YxhjWWimrKV7c=; b=j3lRwbXnQi/w+vWpKb7XkLQBx927SaEZsUnpJDyWE/XlkrU32Y/fv11TLLsUohk4BR 4ue+1zWG9G9rM/jN6+5VOHVCCj1pbRB0ENNSv/ngitgtK3zS2r3fWRV/o05nE3KIzgEw G4guGcpFsr448c14PezWDZUoln3GtL/x+3UDwsYJTq/jCjt2IStp/fHeo4k50MUsl+s8 PHSFxl5nEnBUCfWz+lxKU7g6QoRTXVf24d9tOlYbdKVqR0pji/xu/Jt1/nwcIp74mRE/ gDhYoUHwe2+0cGy7yB+tKXXMRqiK3APEWTCene2ZTNms+zLBgQGI1zsgbNXdnaxno8LL D9jg== 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; bh=mmHu/U5vzBr+IR9dVQ/d+gMZ9hQ1H/YxhjWWimrKV7c=; b=OXeUBSEdp0FOXw3WbRbuq1SbNE+5E2kY4Wsan+TCc6dzg6aTFr29yuNucDgQCu6yaw 2F8ozPlgqcOEi1yL3jAMs4hiRpGs8owK0YVF2UGQloBChmz6ANkBiWrCSxjJih7d+zIr gOaRF2jsLrdhrfAkoojJbhBJ2VLHmifMyO715GjJwCQLj23FjQTuoGCZheLdlfCbjOu6 L/dQ9VjKtbo87gxOmcrTQFp+oSPOXn6d08bHOYrd9n/7GwxcN8VbAodWPrqENTUcgPsI 5JExDFLwyvt3VVNRzeqkhPcC4LXP/fetJCuP/Buy9kqAVu7VvP72+V4SMdCq0h7XWhBK Vu5w== X-Gm-Message-State: AMke39lq6OTBjPjwq0qeOe1inhjVRsXNDgxoLxhHsBM6lilGQU0pUr1OWXHxu8DpY1T9oA== X-Received: by 10.84.195.129 with SMTP id j1mr5006739pld.88.1488418976937; Wed, 01 Mar 2017 17:42:56 -0800 (PST) Received: from localhost.localdomain ([27.18.58.230]) by smtp.gmail.com with ESMTPSA id x2sm12870240pfa.71.2017.03.01.17.42.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Mar 2017 17:42:56 -0800 (PST) From: Vincent Luo X-Google-Original-From: Vincent Luo To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Mar 2017 09:42:12 +0800 Message-Id: <1488418932-26817-1-git-send-email-vincent860602@gmail.com> X-Mailer: git-send-email 2.7.4 X-Mailman-Approved-At: Fri, 03 Mar 2017 09:32:39 +0200 Subject: [FFmpeg-devel] [PATCH] update to add preclose function, help to fix rtsp didn't send teardown after ffplay close 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: Vincent Luo MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Vincent Luo --- ffplay.c | 1 + libavformat/avformat.h | 11 ++++++++++- libavformat/rtspdec.c | 9 +++++++++ libavformat/utils.c | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ffplay.c b/ffplay.c index 79dc768..42e538b 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1178,6 +1178,7 @@ static void stream_component_close(VideoState *is, int stream_index) static void stream_close(VideoState *is) { + avformat_preclose_input(&is->ic); //added by vincent 20170228 for send teardown before close(Fix a rtsp issue) /* XXX: use a special url_shutdown call to abort parse cleanly */ is->abort_request = 1; SDL_WaitThread(is->read_tid, NULL); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index f9f4d72..c9f7a39 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -730,13 +730,18 @@ typedef struct AVInputFormat { */ int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); +/** +* The stream is going to be closed. The AVFormatContext and AVStreams are not +* freed by this function +*/ +int (*read_preclose)(struct AVFormatContext *); /** * Close the stream. The AVFormatContext and AVStreams are not * freed by this function */ int (*read_close)(struct AVFormatContext *); - /** +/** * Seek to a given timestamp relative to the frames in * stream component stream_index. * @param stream_index Must not be -1. @@ -2365,6 +2370,10 @@ int av_read_play(AVFormatContext *s); int av_read_pause(AVFormatContext *s); /** +* Call before closing input AVFormatContext. +*/ +void avformat_preclose_input(AVFormatContext **s); +/** * Close an opened input AVFormatContext. Free it and all its contents * and set *s to NULL. */ diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index a722b98..cdcd578 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -53,6 +53,14 @@ static const struct RTSPStatusMessage { { 0, "NULL" } }; +static int rtsp_read_preclose(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + + if (!(rt->rtsp_flags & RTSP_FLAG_LISTEN)) + ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL); + return 0; +} static int rtsp_read_close(AVFormatContext *s) { RTSPState *rt = s->priv_data; @@ -968,6 +976,7 @@ AVInputFormat ff_rtsp_demuxer = { .read_probe = rtsp_probe, .read_header = rtsp_read_header, .read_packet = rtsp_read_packet, + .read_preclose = rtsp_read_preclose, .read_close = rtsp_read_close, .read_seek = rtsp_read_seek, .flags = AVFMT_NOFILE, diff --git a/libavformat/utils.c b/libavformat/utils.c index 5664646..45656c2 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4175,7 +4175,19 @@ void avformat_free_context(AVFormatContext *s) flush_packet_queue(s); av_free(s); } +void avformat_preclose_input(AVFormatContext **ps) +{ + AVFormatContext *s; + + if (!ps || !*ps) + return; + s = *ps; + + if (s->iformat) + if (s->iformat->read_preclose) + s->iformat->read_preclose(s); +} void avformat_close_input(AVFormatContext **ps) { AVFormatContext *s;