From patchwork Thu Jul 16 05:57:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6rmA64+Z7JuQ64uYKERvbmd3b24gS2ltKQ==?= X-Patchwork-Id: 21103 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp980698ybm; Wed, 15 Jul 2020 22:57:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEs6PXPf4kqw9B0rPjXT9ynOgz/r13wlPSUPfWQX32DsD5AxMCYti/hctVkwCyZ/do2rsk X-Received: by 2002:adf:e948:: with SMTP id m8mr3401545wrn.398.1594879069461; Wed, 15 Jul 2020 22:57:49 -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 t3si3890889wrs.207.2020.07.15.22.57.48; Wed, 15 Jul 2020 22:57:49 -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=@o365skt.onmicrosoft.com header.s=selector2-o365skt-onmicrosoft-com header.b=qBEqHLJB; arc=fail (body hash mismatch); 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 0958D68B20F; Thu, 16 Jul 2020 08:57:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from secumail2.sktelecom.com (secumail2.sktelecom.com [203.236.20.243]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24EA86880F3 for ; Thu, 16 Jul 2020 08:57:33 +0300 (EEST) Received: from unknown (HELO SKT-MAILPEDGE1.skt.ad) (203.236.20.107) by 203.236.20.243 with ESMTP; 16 Jul 2020 14:57:28 +0900 X-Original-SENDERIP: 203.236.20.107 X-Original-MAILFROM: dongwon.kim@sk.com Received: from SKT-MAILPALL2.SKT.AD (203.236.13.5) by owa.sktelecom.com (203.236.20.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 16 Jul 2020 14:57:25 +0900 Received: from SKT-MAILPALL1.SKT.AD (150.19.7.214) by SKT-MAILPALL2.SKT.AD (150.19.7.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Thu, 16 Jul 2020 14:57:08 +0900 Received: from SKT-MAILPEDGE1.skt.ad (203.236.20.107) by SKT-MAILPALL1.SKT.AD (150.19.7.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3 via Frontend Transport; Thu, 16 Jul 2020 14:57:08 +0900 Received: from KOR01-PS2-obe.outbound.protection.outlook.com (104.47.109.56) by owa.sktelecom.com (203.236.20.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Thu, 16 Jul 2020 14:57:07 +0900 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iRwkOVa2OnA535zlGu1gVrGaLblTwUbwABgDkMKftYPJ2W43GZLNWAwI+uUF0yqieVWyAZmt7/n2t+1Am7On/gP+ghr87GLGVpGi6lje+QPXLH0M1Bj7xTcW7ggmeQZ4OmAuF935urMusrxbuAzJqIGa+hCw3vGE6XGcwMC4O4jBjGCyOOSrv+oEZIGap0G5qMXftsyTI1nKrJpWRuGn20x+EKgcf3m3pJrpd7w5RTavbizdI96xG2df9BNzDNhC7+gzNomIOYOmNnMAWs9EIlhm5zPoJ0Qw1NaDA1xE8lmgNz1aHzIvmUFcfHg3FIFg9M8WlNSNITPx8QWN5ZzWJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b0orlI7KuiIBFel6hpUqQyEIJERwYHBfCfBvkVqs5bQ=; b=ia0woQl0NFnvU9J47S9U0rceRb7XmOWYWCAXfpyto+eWg7V+NNLk1O5Y7sc0xiT58Q4PDdSSOpEv+Je1K0+Y7utNVzCgL83rBQQSdkwEL1rBn3BYGag0Yw0J5LakZk1ME9VbbupPInRVX78hJyssAjpmAoiAMQqoRVgcTzdKanjlPKCXpAe7vogAeXbj6kCGQ+P5Nf5OL5qJiIIS2vr847tLDktHSuUVyQOKboQBIzvC6Tqzu14TqJ7MNLxikumsy3Cl//UxAAMUP0DzB1L2FVcpVVJ/RsWQ2G1wa9498ytyjzF+OAmNNCZljjevmFba6edltk3uabwH9BPh8oGhgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sktelecom.com; dmarc=pass action=none header.from=sktelecom.com; dkim=pass header.d=sktelecom.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o365skt.onmicrosoft.com; s=selector2-o365skt-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b0orlI7KuiIBFel6hpUqQyEIJERwYHBfCfBvkVqs5bQ=; b=qBEqHLJB9GsrjaBzu/crm+nJ+HGXnhHk9vY5sPquCgMm4e2FbF+kFEFeg5+QUpjx6d76W+FMJQIh1ROuxl3x093+ljOLHOilNrMZTL/C8RlWn/yubUC8XiwLi5dkZeBIL7H2cI0uQO4czeCGYNyc1LQogcyw8oP3DpjXm0AM288= Received: from SL2P216MB0377.KORP216.PROD.OUTLOOK.COM (2603:1096:100:22::23) by SL2P216MB0058.KORP216.PROD.OUTLOOK.COM (2603:1096:100:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18; Thu, 16 Jul 2020 05:57:06 +0000 Received: from SL2P216MB0377.KORP216.PROD.OUTLOOK.COM ([fe80::b876:d193:7efa:8a93]) by SL2P216MB0377.KORP216.PROD.OUTLOOK.COM ([fe80::b876:d193:7efa:8a93%6]) with mapi id 15.20.3174.026; Thu, 16 Jul 2020 05:57:06 +0000 From: =?ks_c_5601-1987?b?sei1v7/4tNQoREsp?= To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] avformat/hls: add supporting fMP4(CMAF) format to seek on HLS demuxer Thread-Index: AQHWWniyd07pLtc/CEKYPE5oMo1sCakIREHggAEOaFCAAGQU8A== Date: Thu, 16 Jul 2020 05:57:06 +0000 Message-ID: References: <20200715072026.349639-1-dongwon.kim@sk.com> In-Reply-To: Accept-Language: ko-KR, en-US Content-Language: ko-KR X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: ffmpeg.org; dkim=none (message not signed) header.d=none;ffmpeg.org; dmarc=none action=none header.from=sktelecom.com; x-originating-ip: [203.236.9.162] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bee124a4-0be8-4f05-e24d-08d8294d122e x-ms-traffictypediagnostic: SL2P216MB0058: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:207; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QiCrU1ECK4jHGVI80vGdAFZb0vZwwwwqfOUIzcojPlI4Tt2uLhO7f3ZQGZe0wV/4xOp0afnXcVGlZrRMUc1Ee/X9gfGZ/m4H34kQ++yFOlOkEIQqi4O24R0VmVeZrTrSHmbQ7qT3uioFolG7auLzVJVjhLZ8mVFpS0ED6NzxUlJ9vrFYoP19HLyaihBZNjABBRTs6vMPfHAbMnC58+9C9qzio2SGJRSO3J9AObuJaxlou/JEGLeRLeVpM8KiBFPyKyR/GXLESSVMcOVXlN5cOVRRLYNAcZLwN8FAkiUwLn464V30VmW0WhgMUrqGqPNNVFSK6WGV3KEbYJQB3nInFg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SL2P216MB0377.KORP216.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(366004)(39860400002)(346002)(376002)(136003)(396003)(55016002)(85182001)(7696005)(5660300002)(6506007)(9686003)(26005)(52536014)(478600001)(316002)(33656002)(71200400001)(86362001)(2906002)(8936002)(66476007)(66946007)(76116006)(186003)(83380400001)(64756008)(66556008)(8676002)(6916009)(2940100002)(66446008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: /vPBtmy6SHYDz/jjw/xlNctIyy4433TZOn0TWhjX8v+DgMaiaE1cX0gzk184xAAt/yYXqgPTVAjeuHFSrOGPubxebBAorUQfJj0Aou3lGjKGLOjf0crn0t0s0PiERouNlHswRvh0JJcLnsCbAunPq1MHrIM6be+N5Q+D0hHZkyxiJvjX0GkjLbElcAEajl+f98MIfUuyGKTp4RcYgqsSf3dHKK3tFknLp9x6S6bdKhgu4gNwX+F6p1wq37HCrwGIfLIZHRq7WIU4TgRG3ZWV2fm2WKf7bXJKPCFhPao5D3BJjTYXBN91RzCC3RRewx0FfoAodw8R4OOBAfxf4M7JVQuyADbcPDbO3z0KME9ExulfUO6Gy4vitRAyPF6OvfKvHUP5MYXQes6KmVPtEOxSLeKL06AI8BPofPF5i+TY1GP0KkY549GrWsESNsnrio/4ycmxjPSsiXM2wkqq46718SHvylz2ba61I51Qzxrqka4= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SL2P216MB0377.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: bee124a4-0be8-4f05-e24d-08d8294d122e X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jul 2020 05:57:06.5479 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5afa09fd-c4be-434d-830d-f4765c449035 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: cQSbKC6pWvJMnV8GnDNrjcuuMpBr4UIetYA4KbaZbe10ndbV1LkNAlIiX664GBh5veuokYYcn0BfwIX4KnGQ7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB0058 X-OriginatorOrg: sktelecom.com Subject: [FFmpeg-devel] [PATCH] avformat/hls: add supporting fMP4(CMAF) format to seek on HLS demuxer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7ZMYu70X8YxW Content-Length: 4244 Signed-off-by: Dongwon Kim --- libavformat/hls.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) pls->seek_flags |= AVSEEK_FLAG_ANY; } + + if (pls->ctx && pls->ctx->iformat && strcmp(pls->ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0) { + pls->init_sec_buf_read_offset = 0; + reopen_demux_for_component(s, pls); + } } c->cur_timestamp = seek_timestamp; -- 2.25.1 diff --git a/libavformat/hls.c b/libavformat/hls.c index ba17c4ed96..561b42ea6b 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -2139,6 +2139,68 @@ static int compare_ts_with_wrapdetect(int64_t ts_a, struct playlist *pls_a, return av_compare_mod(scaled_ts_a, scaled_ts_b, 1LL << 33); } +static int reopen_demux_for_component(AVFormatContext *s, struct +playlist *pls) { + ff_const59 AVInputFormat *in_fmt = NULL; + AVDictionary *in_fmt_opts = NULL; + uint8_t *avio_ctx_buffer = NULL; + int ret = 0; + + if (pls->ctx) { + av_freep(&pls->pb.buffer); + memset(&pls->pb, 0x00, sizeof(AVIOContext)); + pls->ctx->pb = NULL; + avformat_close_input(&pls->ctx); + pls->ctx = NULL; + } + + if (ff_check_interrupt(&s->interrupt_callback)) { + ret = AVERROR_EXIT; + goto fail; + } + + if (!(pls->ctx = avformat_alloc_context())) { + ret = AVERROR(ENOMEM); + goto fail; + } + + avio_ctx_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!avio_ctx_buffer ) { + ret = AVERROR(ENOMEM); + avformat_free_context(pls->ctx); + pls->ctx = NULL; + goto fail; + } + ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, NULL); + pls->pb.seekable = 0; + + if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) + goto fail; + + pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO; + ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Error when loading segment, playlist %d\n", pls->cur_seq_no); + avformat_free_context(pls->ctx); + pls->ctx = NULL; + goto fail; + } + + pls->ctx->pb = &pls->pb; + pls->ctx->io_open = nested_io_open; + + ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); + av_dict_free(&in_fmt_opts); + if (ret < 0) + goto fail; + ret = avformat_find_stream_info(pls->ctx, NULL); + if (ret < 0) + goto fail; + +fail: + return ret; +} + static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) { HLSContext *c = s->priv_data; @@ -2351,6 +2413,11 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, pls->seek_stream_index = -1;