]> git.sesse.net Git - nageru/commitdiff
Make the muxing buffer configurable, and 10 MB (since 1 MB is too little for our...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 00:49:06 +0000 (01:49 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 00:49:06 +0000 (01:49 +0100)
defs.h
httpd.cpp

diff --git a/defs.h b/defs.h
index 7b3a9ae39e91921f374dae94b98c8c0b132ce0c5..3b48cddc6c1df9885efc0112faad7fa96a42b239 100644 (file)
--- 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)
index 689291e2c7628644f4f4b4ee5aa9c94cb870264d..e71f40e2e52844604849cba0ff395d8a85c83d53 100644 (file)
--- 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));