]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7519: increase default video buffer to 2mb in avformat and add vbuf file param...
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 15 Apr 2015 17:56:07 +0000 (12:56 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:20 +0000 (12:47 -0500)
src/include/switch_module_interfaces.h
src/mod/formats/mod_avformat/mod_avformat.c
src/switch_core_file.c

index 3a50709b4d170561e8934c26cecf1cd76c00fa04..88387033cc4cc246a640c4c02cbe027fb9223d5f 100644 (file)
@@ -307,6 +307,7 @@ typedef struct switch_mm_s {
        int vw;
        int vh;
        float fps;
+       int vbuf;
 } switch_mm_t;
 
 /*! an abstract representation of a file handle (some parameters based on compat with libsndfile) */
index 46a59f90a9848158926bfb4c226801544ef3f8e7..abeec3633ee55d25b012958ecdd0041047199832 100644 (file)
@@ -177,6 +177,8 @@ static switch_status_t add_stream(OutputStream *ost, AVFormatContext *oc, AVCode
        AVCodecContext *c;
        switch_status_t status = SWITCH_STATUS_FALSE;
        int threads = switch_core_cpu_count();
+       int buffer_bytes = 2097152; /* 2 mb */
+
        /* find the encoder */
        *codec = avcodec_find_encoder(codec_id);
        if (!(*codec)) {
@@ -217,6 +219,13 @@ static switch_status_t add_stream(OutputStream *ost, AVFormatContext *oc, AVCode
                break;
 
        case AVMEDIA_TYPE_VIDEO:
+
+               if (mm) {
+                       if (mm->vbuf) {
+                               buffer_bytes = mm->vbuf;
+                       }
+               }
+
                c->codec_id = codec_id;
                c->bit_rate = 1000000;
                /* Resolution must be a multiple of two. */
@@ -227,7 +236,8 @@ static switch_status_t add_stream(OutputStream *ost, AVFormatContext *oc, AVCode
                c->gop_size      = 25; /* emit one intra frame every x frames at most */
                c->pix_fmt       = AV_PIX_FMT_YUV420P;
                c->thread_count  = threads;
-               c->rc_initial_buffer_occupancy = 1024 * 1024 * 8;
+               c->rc_initial_buffer_occupancy = buffer_bytes * 8;
+
                if (codec_id == AV_CODEC_ID_VP8) {
                        av_set_options_string(c, "quality=realtime", "=", ":");
                }
index 356a96669c3ad9e4daf3e2b2e182161a90185ba7..528681363fd89f8f560c23d877ca39338fbe3500 100644 (file)
@@ -157,6 +157,22 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
                                fh->mm.fps = ftmp;
                        }
                }
+
+               if ((val = switch_event_get_header(fh->params, "vbuf"))) {
+                       tmp = atoi(val);
+
+                       if (strrchr(val, 'k')) {
+                               tmp *= 1024;
+                       } else if (strrchr(val, 'm')) {
+                               tmp *= 1048576;
+                       }
+                       
+                       if (tmp > 0 && tmp < 52428800 /*50mb*/) {
+                               fh->mm.vbuf = tmp;
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid buffer size: %d\n", tmp);
+                       }
+               }
        }
 
        if (switch_directory_exists(file_path, fh->memory_pool) == SWITCH_STATUS_SUCCESS) {