From patchwork Thu May 10 15:41:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Holljes X-Patchwork-Id: 8911 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp1223271jad; Thu, 10 May 2018 08:49:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqD+/epwP/97Z5uwZyKqC4j91QdrUGkkXYqU+R9OBa70hiE4jLkCMXHJSYTJ2uOIGGUFgJF X-Received: by 2002:adf:c4c3:: with SMTP id o3-v6mr1739346wrf.108.1525967386648; Thu, 10 May 2018 08:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525967386; cv=none; d=google.com; s=arc-20160816; b=k8Klf7mvyGOJGCJqS1QVKkP0sVRb0WJ1YUiArjPkiCIVms8btBB+SfDzIWh8119saC Sl89tZL5vOWR6JWe/zHHX39Wi7xWsll0shbHsRIacoDtAKAp7OKOgBO6lLH6ZtK1FpDj 400KmfrjnvOxvcC2iAv05BMeNSwV6rmZyi/tlsF1fsKbA1gJGqxzExd8rdeE3Xf5xMvS HmIsO9LNAzA5u6MjsFC1miObRvSlYw42xbZBBMC+MiRz1vj8D64nLNpLdRlFoyaS5JRE 4hoXacXYyO8qi0SWEzJrTuFwoepE2ljF07GEaQz1MTBZXpY3Vpb/Vg1EkjCS/44Ye+94 mnSg== 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=oNAYcViKbjwPlHUjpxfmXc0DknT3TXHjBXRz3gWcZj0=; b=vxLbhxpuC2v/YdfM/77/XbUU+U2Pbg8MBE/4nnPHxcOsVm2XFxKHlca3W7t78Ipq2f ao/D4A5UZqh6A74m0ns4oqgOmMLA0aR3vcksURj91BBKsoUQ8TwCpBEcpfQFuxFSKYdg aKDkEWpH15tfDBk8J9yMNScHNCRkEWVXT8k/lUu1MjSfyemhzSFeMXJskfBwXAYwrV3v 5WJW/VNGOkqTVqFw8vsbZa37I4L+fxWYSSmu40v2samhfzjxrbJZYABsMnx7sQ+z/B+z DylLN3jtNOI0hbpRnuL3UMhRWxmrYqy02Njq8qmQnS8MwoAhDsH/YCRqt8f87K1RKeYo 9grg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=Tu2EP+hC; 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 o41-v6si1028389wrc.284.2018.05.10.08.49.46; Thu, 10 May 2018 08:49:46 -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=Tu2EP+hC; 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 1333268A833; Thu, 10 May 2018 18:49:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A09E68A824 for ; Thu, 10 May 2018 18:49:03 +0300 (EEST) Received: by mail-wm0-f66.google.com with SMTP id l1-v6so5235488wmb.2 for ; Thu, 10 May 2018 08:49:39 -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=dOnG/3KMVkuZrZdIlimfY0cjG8Ui38iQpR6gIESKKiU=; b=Tu2EP+hCE8PTVwkmybSeKljMNSKThUIyAe6Vtjlzx69bDHeEHDBiS5liS78RuK6DWN O71LC920ePh7bNwWvIFxxkaQmkzNGsSOWAxX9QW522pYzFj3jhmHwR9osvB/6NaT3UYc NrrkeGS5HCbTQS5TLPjS99w+ZQ/yC2R185u9WmU43CjDs2u0dhL9fAALLEZaFehDPBv2 kgJH2VDwebh4W6xfrbCKgdZ0vh+MqYStV/Y0kCo6RH1ZgL9LbMkGyYAoEOwf4mSu1+Rt 4h+RFvH3kxGO4ON8cqL3+i4vy9XS51DWiviEU6UnjtS2SrL31xNUcs8/GAS2WRJNRSE1 FsRg== 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=dOnG/3KMVkuZrZdIlimfY0cjG8Ui38iQpR6gIESKKiU=; b=IbX+ph2NJM2Wpc40ZB6vAp8EK7GUCTP2e9SAhSz7MH6hc+9jimmj/xUFsqAMSh93Yi eBUCiuD7/08Uhw4vYJcVpGMBHUjM2RPqx/XL6cV4vtYadfqYl4nfj5SSrHv3CTRpzHrS lRxs4X6KH0/NBN233npA5BrmI8Rb77hOBcfSywX9WQU5+8G14LoNiChAPcfGHurmbgv5 mMsSoSFoVfGNS3T7EPWDE1yAbmYaROSi509og0Z2ULgdaYNDOl7+TvIQbtXNwm5fTAHW tLcFUjyNkGnBLEmmMBIgt3w9F9XhvPoX5ThyBzPHheIMpYYm7AVHFSbGZ7hmJT0rtLwp 30oQ== X-Gm-Message-State: ALKqPwf55JcaqRPZf8wvor/qQxr006Hjz75uuBpCWgoYySt0O25BFhmh CbuAIrPUy/anLf3NrOSI67teZA== X-Received: by 2002:a1c:63c5:: with SMTP id x188-v6mr1672493wmb.61.1525966911757; Thu, 10 May 2018 08:41:51 -0700 (PDT) Received: from localhost.localdomain (cebit2017.teco.kit.edu. [129.13.169.177]) by smtp.gmail.com with ESMTPSA id x63-v6sm1853472wma.25.2018.05.10.08.41.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 May 2018 08:41:51 -0700 (PDT) From: Stephan Holljes To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 May 2018 17:41:26 +0200 Message-Id: <20180510154126.30789-6-klaxa1337@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180510154126.30789-1-klaxa1337@googlemail.com> References: <20180510154126.30789-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 | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Documentation.txt diff --git a/Documentation.txt b/Documentation.txt new file mode 100644 index 0000000..5b52c89 --- /dev/null +++ b/Documentation.txt @@ -0,0 +1,84 @@ +About +----- + +In its current for this is a HTTP live-streaming server. A media file can be +streamed to a number of clients with the correct media file being muxed on- +the-fly for each client starting at the current position in the stream. +The stream received by the clients is simply a 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.