From patchwork Fri Dec 29 22:06:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 7024 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp10985023jad; Fri, 29 Dec 2017 14:06:26 -0800 (PST) X-Google-Smtp-Source: ACJfBoty1VlbYe7Dul6RZxQwO//MGkDEckTbV9ql2rsrFmAJchXFpELe7/UI/sO2TDKGLQHpFq6p X-Received: by 10.28.132.209 with SMTP id g200mr27321763wmd.91.1514585186251; Fri, 29 Dec 2017 14:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514585186; cv=none; d=google.com; s=arc-20160816; b=azuYur3QS6uAvodqrFwNwYRbEdZKTcVTjsatQqfpJBfeFYY82I3cTeaFwUNY7GwxJU dnl6dv3czJBHrraTNndLGtSEcP4wh4o6Ba68VrOZE1yxGAt5VX6+HvtT9c1yc2HIn8/S Jd0YfnrLkPR5v6S8SBMoHJlNxHGBRyBMIy5J6/4UnwD3H+B7sEdGtcuR8ZazEaqv5IwY iC/+tKmxTeRt7cfNFUPtlPEGhEjjpC0CiuYogRSRi5I6g/Sn0VJx1cFzaRfYh2LTHuNR cEU3rhciJZ1zTW66ymlrrzPGc31NqjxhxuojmL6w+Qsi69I10xMLdee/FTu4f1+NieuF 6rgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=xwhPdHBNbCmLReryBrzt8AivwHO4WoO+8onSsuzgewM=; b=Scafg9I7kun7FsHKON3UyyV7f4JODArmatGv5qPKWp/EP3CfOat1FMdVUZI6xq5H55 vDIy8UiKQFf54Kq8R+OnTFnNoz56ZzGj20+nraABSbx/x3KIAl2dkOvAg5KijYCwFfie 2lHYI6a6ZuEZ315qhMJYpucLYBlT7BdrKXG6KDuwWuG7EFBFj2UZ3D0lYmDZdyZNmh1i Tl4/f+NkfwzFggUMZMnDDlp5HcQUoXJeksmuSmU536msWlp+33G/LhEmtndcmm2i4yzU K6Eekde/0Of2txbhM7uSC+AJPBwnmYfIcpH/2eK+SuuBbT+Yk+DChOSMKRV6SxFdv1Wv DTLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=HVusNDlm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m4si5314561wrg.302.2017.12.29.14.06.25; Fri, 29 Dec 2017 14:06:26 -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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=HVusNDlm; 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 6588168997A; Sat, 30 Dec 2017 00:06:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 446EB68993B for ; Sat, 30 Dec 2017 00:06:03 +0200 (EET) Received: by mail-pl0-f67.google.com with SMTP id g2so23624258pli.8 for ; Fri, 29 Dec 2017 14:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=caViKRzqM6LMG6XN4BJ8n0oL6l+hh2dFKqTBYc5g41o=; b=HVusNDlmyzmV/aYYyzdglX5C3ntX1LXNHjXmpG/Y0cQDKxK/eg76Ou1zJdiu26fNES uNbwmp5A2DtxbmwWOBcDUgqvKK+weP2g7t4syL0/uNfnJkDnnzjDfGoC9IjwDBS4JyfI XnTm7LzzUb4uFJXIyZH7Qt1PUaVbAUfraZkeYEtFOmiZNqrFkSc3odlbDIwdNrFZs5Su Ax9MBVo74BW34ZlASeyZAqey8uq/2PsZpjU/A/3Z3C/kKQWdk2C6oHm3JOo5iR/SoDHn kyxVYUi717Y34kXJfc58PrgY7zHvSmufQHAvYuvRUEkDXd62fS266wsS83yX4EmlU40u nc+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=caViKRzqM6LMG6XN4BJ8n0oL6l+hh2dFKqTBYc5g41o=; b=NMC/rInS1Mu776ymFKJjf91yRO9YPyN+JE8K7MiRBO5GqvAnAEryVRcP6+hCRaiIqU U4jqpx/EDOrUgEWSDLZINuR349AFAh+8wfAeYgpqBlDNJCMYa/KQVNT0Dd+p18SKq2R5 0KX6rB4h1MQnx/NvgE9VU/fa9Ugh69SqutAh38jTYBD/m10BIvHhpImS5ye1tQXyAdtk ry/vGeCodwy1jjhnLDB2P2eBWAXJurejThU30qSyQrhEBBD3dPv5x1ErI/hbh87e5Xou qjG6o/R/TFzPu5GDfkbDbz2pYM+WZ+7O1E1/gkxxRimtE2DENw+T/xK73zIv5RP8THxJ WUrA== X-Gm-Message-State: AKGB3mJHDICmX1+o5OAPjlCz63196URt1wsihU4V7o9MaiH3QHtpVbBZ cRzdyHiCRm/SI8UbTDTDAx0UXOk+ X-Received: by 10.124.25.1 with SMTP id c1mr35635156plz.179.1514585176069; Fri, 29 Dec 2017 14:06:16 -0800 (PST) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id s14sm83011713pfe.36.2017.12.29.14.06.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Dec 2017 14:06:15 -0800 (PST) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Dec 2017 14:06:05 -0800 Message-Id: <20171229220606.29155-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add new_http_request callback 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: anssi.hannula@iki.fi, Aman Gupta , kjeyapal@akamai.com, wm4 , lq@chinaffmpeg.org MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta This callback is implemented on AVIOContext which are backed by an HTTP URLContext. This allows the owner of the IO context to both discover that it is capable of making additional http requests, and to make such requests without including http.h. In particular this avoids the use of internal functions to fetch the URLContext, and prevents accidentally calling ff_http_do_new_request on a URLContext which is not actually part of an HTTPContext. Signed-off-by: Aman Gupta Signed-off-by: wm4 --- libavformat/avio.h | 6 ++++++ libavformat/aviobuf.c | 10 ++++++++++ libavformat/http.c | 2 ++ libavformat/url.h | 1 + 4 files changed, 19 insertions(+) diff --git a/libavformat/avio.h b/libavformat/avio.h index 75912ce6be..640ca9f9e2 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -349,6 +349,12 @@ typedef struct AVIOContext { * Try to buffer at least this amount of data before flushing it */ int min_packet_size; + + /** + * Make a new request on the underlying http connection. + * This is internal only, do not use from outside. + */ + int (*new_http_request)(struct AVIOContext *pb, const char *uri); } AVIOContext; /** diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 86eb6579f4..8530c78823 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -922,6 +922,14 @@ static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, i return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags); } +static int io_new_http_request(AVIOContext *s, const char *uri) +{ + URLContext *uc = ffio_geturlcontext(s); + if (!uc) + return AVERROR(ENOSYS); + return uc->prot->url_new_http_request(uc, uri); +} + int ffio_fdopen(AVIOContext **s, URLContext *h) { AVIOInternal *internal = NULL; @@ -970,6 +978,8 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) if (h->prot->url_read_seek) (*s)->seekable |= AVIO_SEEKABLE_TIME; + if (h->prot->url_new_http_request) + (*s)->new_http_request = io_new_http_request; } (*s)->short_seek_get = io_short_seek; (*s)->av_class = &ff_avio_class; diff --git a/libavformat/http.c b/libavformat/http.c index a376f1a488..1dad129bdd 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -1712,6 +1712,7 @@ const URLProtocol ff_http_protocol = { .url_write = http_write, .url_seek = http_seek, .url_close = http_close, + .url_new_http_request= ff_http_do_new_request, .url_get_file_handle = http_get_file_handle, .url_get_short_seek = http_get_short_seek, .url_shutdown = http_shutdown, @@ -1732,6 +1733,7 @@ const URLProtocol ff_https_protocol = { .url_write = http_write, .url_seek = http_seek, .url_close = http_close, + .url_new_http_request= ff_http_do_new_request, .url_get_file_handle = http_get_file_handle, .url_get_short_seek = http_get_short_seek, .url_shutdown = http_shutdown, diff --git a/libavformat/url.h b/libavformat/url.h index 4750bfff82..2f2d62e54f 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -62,6 +62,7 @@ typedef struct URLProtocol { int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options); int (*url_accept)(URLContext *s, URLContext **c); int (*url_handshake)(URLContext *c); + int (*url_new_http_request)(URLContext *h, const char *uri); /** * Read data from the protocol.