From 8e79ce9e238b14e3d2c216000e7c5bf4716e8ba9 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 14 Nov 2015 01:49:06 +0100 Subject: [PATCH] Make the muxing buffer configurable, and 10 MB (since 1 MB is too little for our streams when in MP4). --- defs.h | 3 +++ httpd.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/defs.h b/defs.h index 7b3a9ae..3b48cdd 100644 --- a/defs.h +++ b/defs.h @@ -13,4 +13,7 @@ #define STREAM_MUX_NAME "mpegts" #define MUX_OPTS {} +// In bytes. Beware, if too small, stream clients will start dropping data. +#define MUX_BUFFER_SIZE 10485760 + #endif // !defined(_DEFS_H) diff --git a/httpd.cpp b/httpd.cpp index 689291e..e71f40e 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -73,8 +73,10 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, assert(oformat != nullptr); HTTPD::Stream *stream = new HTTPD::Stream(oformat, width, height); streams.push_back(stream); + + // Does not strictly have to be equal to MUX_BUFFER_SIZE. MHD_Response *response = MHD_create_response_from_callback( - (size_t)-1, 1048576, &HTTPD::Stream::reader_callback_thunk, stream, &HTTPD::free_stream); + (size_t)-1, MUX_BUFFER_SIZE, &HTTPD::Stream::reader_callback_thunk, stream, &HTTPD::free_stream); int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); //MHD_destroy_response(response); @@ -168,8 +170,8 @@ HTTPD::Stream::Stream(AVOutputFormat *oformat, int width, int height) { AVFormatContext *avctx = avformat_alloc_context(); avctx->oformat = oformat; - uint8_t *buf = (uint8_t *)av_malloc(1048576); - avctx->pb = avio_alloc_context(buf, 1048576, 1, this, nullptr, &HTTPD::Stream::write_packet_thunk, nullptr); + uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE); + avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, this, nullptr, &HTTPD::Stream::write_packet_thunk, nullptr); avctx->flags = AVFMT_FLAG_CUSTOM_IO; mux.reset(new Mux(avctx, width, height)); -- 2.39.2