From patchwork Sun May 13 00:07:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Holljes X-Patchwork-Id: 8936 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp2441971jad; Sat, 12 May 2018 17:15:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKMgrlONA0gUfcbL+VPzkalvpZpnpVd12MMD0S1UkulDw6BwNbdOMjd2BMqHasbWsM49ki X-Received: by 2002:adf:ad61:: with SMTP id p88-v6mr2895491wrc.24.1526170557431; Sat, 12 May 2018 17:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526170557; cv=none; d=google.com; s=arc-20160816; b=E8MgxTkiv6g5WLaE4ORWn7ciIok8tU9gTmSbhnnztGnaM0/xflG2IYGEU2rhKrW+1A 44zj/gWQ51bH88Jea5tprUG2UZsN8F4vQJh3FJmamFae1YZxT33xQeUK5ic9a4bAio30 7lXD30+pHKOqi4BRTLokD5ZxwU7kif1kRvbhyry+DV8Z4daGn0kbQDgr9YwiRO/g98Ul paq5a7yvWUx4amEXAX8Kv/GfVcmNqE++rzu23l4anThmWufWdKMk5UcyzlSGpbSYuC5w 15uqoQA2dToL9EOfZpBwvGG1jd6OxOOaYOGZKlOStod9aCs8ZEZnjpS6bhii7zPVI1BM wbzg== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=RW9owli3XY0/6IwUw5zqsigBBCUi8xprHRJzK2f80BE=; b=pTWXQR8RGeKTFfiV4YdtPvOyJHE2ZWFHh2EOP2vPyxumPclUcf2eWVlofbgQ+oR98g J7PZwPIzB+ykyDm1felva39LVYKh/ZKpGgwxVwtN5ySve2WcAD6cUSWpytUHl6RIFpN8 O7LjTxI05IU8/D+bp4z/hN9Y85kpU99Q+FmBQImA+GNJsDCABgTjOnzGilhlhYbSTNGu UAxnZZxGvFFLlWjk38hOkzBS7Z3cLLLBmF7kGAgJ3LAH5N8eO515lriPgpcsPj0hA7ah dQMEsIwwJBmCdNFhA3wnIDSvnMDnjC/nE3Q79JbL0DoKHw/XNFzqkuD53t3QpS0Zc1Io 8cjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=acWZN03J; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t126-v6si3075315wmg.43.2018.05.12.17.15.57; Sat, 12 May 2018 17:15:57 -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=@googlemail.com header.s=20161025 header.b=acWZN03J; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7011768A469; Sun, 13 May 2018 03:15:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FE77680439 for ; Sun, 13 May 2018 03:15:12 +0300 (EEST) Received: by mail-wr0-f194.google.com with SMTP id p18-v6so8684136wrm.1 for ; Sat, 12 May 2018 17:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xUXdjiotOdjaR98uGmqh8wUld+aFW4UiR50K8rhYlxA=; b=acWZN03JKe4XWR0/XkjvHIB8OHzNY2db5EXuVB4tnWALzsOQfJJV8AjYlmBzqmO6HK yb6TLH9LjhrUvH1aR38gWB+8gz8yPsYpMNKc/3GOJAsbEglwJ7UM5GHKtK6pI7zo/b/C 9mMZXRYiBiCJhkb9OvlL2adKSU1KczxR7c7pnXJRitudnjXrFHav6lZlPYGtsNKFFv7W 5fp5Z6aC3ug37JQm50HIv/0R3wr4ryMxeDOKMX0WhVLjFQKNtU73iTJUBWMDdfwSqH+I XtOh4kQ2piza3QugeMlDvXhmHorFfv3r49vyrVU+OSSWGMlp2XFAkvQfQNzsq3Tqi8xy VdNA== 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; bh=xUXdjiotOdjaR98uGmqh8wUld+aFW4UiR50K8rhYlxA=; b=aUd4HksLwFw92aPa6aJuSZrAnGQKT3voMEWsBfvGeQTLyUENqVU9Ljw0qY7083PLg0 Jo+qzgP4Jiy/efsl9YUkoM22YNzO/HSO52PF+FAqE92edAsKR9eCqf0eZ5cIiOpOCHBp hgdBv/O8+MJhoIjUmqlUwP2T5YfG6oh9PEcaxPTPUGLZjYPleqTMkTlekny1VzxAxkPt 85Th49OzGjb5XOsMBrsQTLSG953C1WBYGtIpDt9DRmi01C2+BuazxLIWw8q90F1w3XAX Ib8GQmxvJ39Zc7nB+V5N7pJ7BSPnCdXMlAwvdNwqIEkNfATaAxlZEKhmdiC2PX7yv6Yd dF8g== X-Gm-Message-State: ALKqPwc3qGyxwzvTognmWXFicLV6XMfONBejKewnYOi5dbKDmI56qdrR W0PRKU8zDjWLD2cCvqJbikR24g== X-Received: by 2002:adf:d1d1:: with SMTP id m17-v6mr3171277wri.96.1526170089776; Sat, 12 May 2018 17:08:09 -0700 (PDT) Received: from localhost.localdomain ([46.5.2.0]) by smtp.gmail.com with ESMTPSA id r14-v6sm8245469wra.41.2018.05.12.17.08.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 May 2018 17:08:07 -0700 (PDT) From: Stephan Holljes To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 May 2018 02:07:40 +0200 Message-Id: <20180513000740.12548-6-klaxa1337@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180513000740.12548-1-klaxa1337@googlemail.com> References: <20180510154126.30789-1-klaxa1337@googlemail.com> <20180513000740.12548-1-klaxa1337@googlemail.com> Subject: [FFmpeg-devel] [PATCH 5/5] ffserver: Add basic documentation of the architecture 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: Stephan Holljes MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Stephan Holljes --- Documentation.txt | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Documentation.txt diff --git a/Documentation.txt b/Documentation.txt new file mode 100644 index 0000000..9a7f0bf --- /dev/null +++ b/Documentation.txt @@ -0,0 +1,89 @@ +About +----- + +In its current form this is an HTTP live-streaming server. A media resource can +be streamed to a number of clients in real-time. The server interally reads the +input in real-time, like a media-player. It keeps a short cirular buffer to be +able to send clients data to fill their own buffers. This is to prevent media +players from stuttering because not enough data is available. Clients that +connect are sent this buffer and any further data read from the file. This +means that clients that connect later than the server was, "join" whereever +the server is currently reading (including the short buffer). +The stream received by the clients is simply an HTTP response to an HTTP +request. + + +Documentation +------------- + +The current implementation has three different types of work that is done in +different threads. These types are: reading a stream, accepting HTTP +connections and writing media data to clients. + +The design tries to follow a Publisher-Subscriber-Pattern. The PublisherContext +struct contains buffers of read media data and the list of clients. Clients +themselves contain a buffer of media data that still has to be sent to them. + +The reading thread takes care of segmenting the stream into independent chunks +of data and pushing it to the PublisherContext, which publishes the new Segment +to connected clients. This publishing only adds this Segment to the client's +buffer. + +The writing thread does the actual writing of data over the network. It checks +each client's state and if there is data available that can be written to that +client it is sent. + +The accept thread accepts new clients over HTTP and if not all client slots are +in use, writes the stream-header and adds the client to the PublisherContext. + +A Segment is only stored in memory once and is refcounted. Buffers in the +PublisherContext and clients contain pointers to Segments. + +Buffers are implemented using AVFifoBuffer. + +Client states are protected by pthread-mutex-locks, making it possible to run +multiple write threads. + +HTTPD-API +--------- + +To be independent of a specific http server implementation, an interface is +provided that an http server implementation has to provide. At the time of +writing an implementation using the libavformat http server is provided. + +The HTTPDInterface struct takes the following function pointers: + +struct HTTPDInterface { + int (*init) (void **server, struct HTTPDConfig config); + int (*free) (void *server); + int (*accept)(void *server, struct HTTPClient **client, int reply_code); + int (*write) (void *server, struct HTTPClient *client, const unsigned char *buf, int size); + int (*read) (void *server, struct HTTPClient *client, unsigned char *buf, int size); + void (*close)(void *server, struct HTTPClient *client); + void (*shutdown)(void *server); +}; + + +Usage +----- + +Currently streams can be supplied as a stream through stdin or any ffmpeg- +compatible URI, e.g. files or network locations. Examples: + +cat somefile.mkv | ./ffserver + +./ffserver somefile.mkv + +./ffserver http://somehost/somefile.mkv + +This will start reading the file and open port 8080 for HTTP client connections. +The stream is read in real time from whatever resource it is retrieved. +Currently a maximum of 16 clients is implemented. + +The server responds to any GET request with the mediastream. Any other request +is answered with a HTTP 400 error. +If the maximum number of clients is reached the server responds with a 503 HTTP +error if a new client wants to connect. + +Once the stream ends the server will write all the remaining data to all +connected clients before closing the connections and exiting.