From patchwork Wed Oct 12 06:33:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroyuki OYAMA X-Patchwork-Id: 967 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp189055vsd; Tue, 11 Oct 2016 23:34:07 -0700 (PDT) X-Received: by 10.28.50.195 with SMTP id y186mr1107488wmy.111.1476254047635; Tue, 11 Oct 2016 23:34:07 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ju8si8565059wjb.191.2016.10.11.23.34.06; Tue, 11 Oct 2016 23:34:07 -0700 (PDT) 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=@module-jp.20150623.gappssmtp.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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DF4168922B; Wed, 12 Oct 2016 09:34:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 45A7C68921F for ; Wed, 12 Oct 2016 09:33:58 +0300 (EEST) Received: by mail-pf0-f177.google.com with SMTP id 128so14345244pfz.0 for ; Tue, 11 Oct 2016 23:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=module-jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=A9h5JcJZ/02vrBymScE/mHb29ElFWbruJGrjuDPhJvg=; b=xQp1IDBXvTu8dA4kOJZT/k2PF2QEyj0VcHq8UMO0IYXkJwhNmqAK71SVvYjj1nFM3X S/BVJUXyyJ3sHGr11/nb4Goc6RZm7sScTUTGbk+3uNTrOSnTqb6GEk1VJDbb6XdO+78/ KORPChJYRPrKtRPa2fDYwm3YSgcoz/rwCVEGQ2OGmh6+K4O7ghX02op+ut6c7sjMq5tt tbsC7ivzv7HwF/t62V8ogxBnNyAEbXpb4N9hCVzASjbo8Q444vvvP+rZ7yLiFBFbEHsm udrIisuyKc+kaoIS+gXik5Qe+kBR6NrbERGRCvEl+IASfOEqCg8u0BoYLUtafebpppEf ik3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=A9h5JcJZ/02vrBymScE/mHb29ElFWbruJGrjuDPhJvg=; b=MIUKiFOwuAH6jqK24h6VYQ7+I4AyJcJE6SX0gwPRWkZez7pRkDj3ORlC9Q09jSckoC c/4SCEDrffJVamkRKEIrEmHsfd3xYdgxKVN3vHM8s0kl/9dn09/aD9zEcCnV+RCY0JkQ xXAGvrW1vyZgq5OFF/5rXBFzr70pvXThvdruihvT0rvLvG6yeex8SurDUTHbYJHzTvyt kCWjAd6oSufGlbIEK1zujLKZeY5pFPojNwAgEffILc/cDh5uhSQokJH/YnZrBFC6R2TW QCS8FtSxF/dilyZrs/VMpTfr776UTVcVQBBbaFJTy0TPECZnMCvHpc30Jzbf2X3qIjn5 QP5w== X-Gm-Message-State: AA6/9RnzoEVanhN9Pod5QtJ2QjgInrbKFx6fg45+QjT24snttwoE2W+NCCdtRfkdixQRjw== X-Received: by 10.99.62.205 with SMTP id l196mr6575291pga.161.1476254036928; Tue, 11 Oct 2016 23:33:56 -0700 (PDT) Received: from 20201249n.intra.emercury.co.jp (mx-202-32-29-009.mixi.co.jp. [202.32.29.9]) by smtp.gmail.com with ESMTPSA id u17sm8751666pfa.83.2016.10.11.23.33.55 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 11 Oct 2016 23:33:56 -0700 (PDT) From: Hiroyuki OYAMA To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Oct 2016 15:33:44 +0900 Message-Id: <20161012063344.15023-1-oyama@module.jp> X-Mailer: git-send-email 2.8.4 (Apple Git-73) Subject: [FFmpeg-devel] [PATCH] avformat/rtmpproto: Fix RTMP control message handling error in listen mode. 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: Hiroyuki OYAMA MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fix problem to fail by a RTMP Control Message except "Set Chunk Size (1)" after an RTMP handshake. When 'nginx-rtmp-module' relays an RTMP, it sends not only control message 'Set Chunk Size (1)' but also 'Window Acknowledgement Size (5)'. --- libavformat/rtmpproto.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 95d1c1d..b118b4e 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -156,6 +156,8 @@ static const uint8_t rtmp_server_key[] = { }; static int handle_chunk_size(URLContext *s, RTMPPacket *pkt); +static int handle_server_bw(URLContext *s, RTMPPacket *pkt); +static int handle_client_bw(URLContext *s, RTMPPacket *pkt); static int add_tracked_method(RTMPContext *rt, const char *name, int id) { @@ -399,6 +401,9 @@ static int gen_connect(URLContext *s, RTMPContext *rt) return rtmp_send_packet(rt, &pkt, 1); } + +#define RTMP_CTRL_ABORT_MESSAGE (2) + static int read_connect(URLContext *s, RTMPContext *rt) { RTMPPacket pkt = { 0 }; @@ -411,18 +416,42 @@ static int read_connect(URLContext *s, RTMPContext *rt) uint8_t tmpstr[256]; GetByteContext gbc; - if ((ret = ff_rtmp_packet_read(rt->stream, &pkt, rt->in_chunk_size, - &rt->prev_pkt[0], &rt->nb_prev_pkt[0])) < 0) - return ret; - - if (pkt.type == RTMP_PT_CHUNK_SIZE) { - if ((ret = handle_chunk_size(s, &pkt)) < 0) - return ret; - - ff_rtmp_packet_destroy(&pkt); + // handle RTMP Protocol Control Messages + for (;;) { if ((ret = ff_rtmp_packet_read(rt->stream, &pkt, rt->in_chunk_size, &rt->prev_pkt[0], &rt->nb_prev_pkt[0])) < 0) return ret; +#ifdef DEBUG + ff_rtmp_packet_dump(s, &pkt); +#endif + if (pkt.type == RTMP_PT_CHUNK_SIZE) { + if ((ret = handle_chunk_size(s, &pkt)) < 0) { + ff_rtmp_packet_destroy(&pkt); + return ret; + } + } else if (pkt.type == RTMP_CTRL_ABORT_MESSAGE) { + av_log(s, AV_LOG_ERROR, "received abort message\n"); + ff_rtmp_packet_destroy(&pkt); + return AVERROR_UNKNOWN; + } else if (pkt.type == RTMP_PT_BYTES_READ) { + av_log(s, AV_LOG_TRACE, "received acknowledgement\n"); + } else if (pkt.type == RTMP_PT_SERVER_BW) { + if ((ret = handle_server_bw(s, &pkt)) < 0) { + ff_rtmp_packet_destroy(&pkt); + return ret; + } + } else if (pkt.type == RTMP_PT_CLIENT_BW) { + if ((ret = handle_client_bw(s, &pkt)) < 0) { + ff_rtmp_packet_destroy(&pkt); + return ret; + } + } else if (pkt.type == RTMP_PT_INVOKE) { + // received RTMP Command Message + break; + } else { + av_log(s, AV_LOG_ERROR, "Unknown control message type (%d)\n", pkt.type); + } + ff_rtmp_packet_destroy(&pkt); } cp = pkt.data;