Commit 6ec9524c authored by Simon Morlat's avatar Simon Morlat

group IframeRequestLimiter and VideoStarter into mscodecutils.h

refactor IframeRequestLimiter so that it no longer requires a MSTicker (which may be transcient)
update encoders accordingly.
parent b387f62d
......@@ -46,7 +46,6 @@ set(HEADER_FILES
msfilerec.h
msfilter.h
msgenericplc.h
msiframerequestslimiter.h
msinterfaces.h
msitc.h
msjava.h
......@@ -71,7 +70,6 @@ set(HEADER_FILES
stun.h
stun_udp.h
upnp_igd.h
videostarter.h
x11_helper.h
zrtp.h
msrtt4103.h
......
......@@ -26,7 +26,6 @@ mediastreamer2_include_HEADERS=allfilters.h \
msfilerec.h \
msfilter.h \
msgenericplc.h \
msiframerequestslimiter.h \
msinterfaces.h \
msitc.h \
msjava.h \
......@@ -52,7 +51,6 @@ mediastreamer2_include_HEADERS=allfilters.h \
stun.h \
stun_udp.h \
upnp_igd.h \
videostarter.h \
x11_helper.h \
zrtp.h
......
......@@ -166,7 +166,39 @@ struct _MSOfferAnswerProvider{
MSOfferAnswerContext *(*create_context)(void);
};
/**
* A convenience structure and API to intellengently limit the number of key frame request of an encoder.
**/
typedef struct _MSIFrameRequestsLimiterCtx {
uint64_t last_sent_iframe_time;
int min_iframe_interval;
bool_t iframe_required;
} MSIFrameRequestsLimiterCtx;
MS2_PUBLIC void ms_iframe_requests_limiter_init(MSIFrameRequestsLimiterCtx *obj, int min_iframe_interval_ms);
MS2_PUBLIC void ms_iframe_requests_limiter_request_iframe(MSIFrameRequestsLimiterCtx *obj);
MS2_PUBLIC bool_t ms_iframe_requests_limiter_iframe_requested(const MSIFrameRequestsLimiterCtx *obj, uint64_t curtime_ms);
MS2_PUBLIC void ms_iframe_requests_limiter_notify_iframe_sent(MSIFrameRequestsLimiterCtx *obj, uint64_t curtime_ms);
/**
* The goal of this small object is to tell when to send I frames at startup:
* at 2 and 4 seconds.
*/
typedef struct MSVideoStarter {
uint64_t next_time;
int i_frame_count;
bool_t active;
} MSVideoStarter;
MS2_PUBLIC void ms_video_starter_init(MSVideoStarter *vs);
MS2_PUBLIC void ms_video_starter_first_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC bool_t ms_video_starter_need_i_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC void ms_video_starter_deactivate(MSVideoStarter *vs);
#ifdef __cplusplus
}
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef MS_IFRAME_REQUESTS_LIMITER_H
#define MS_IFRAME_REQUESTS_LIMITER_H
#include <mediastreamer2/msticker.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _MSIFrameRequestsLimiterCtx {
const MSTicker *ticker;
bool_t iframe_required;
uint64_t last_sent_iframe_time;
int min_iframe_interval;
} MSIFrameRequestsLimiterCtx;
MS2_PUBLIC void ms_iframe_requests_limiter_init(MSIFrameRequestsLimiterCtx *obj, const MSTicker *t, int min_iframe_interval);
MS2_PUBLIC void ms_iframe_requests_limiter_require_iframe(MSIFrameRequestsLimiterCtx *obj);
MS2_PUBLIC bool_t ms_iframe_requests_limiter_iframe_sending_authorized(const MSIFrameRequestsLimiterCtx *obj);
MS2_PUBLIC void ms_iframe_requests_limiter_notify_iframe_sent(MSIFrameRequestsLimiterCtx *obj);
#ifdef __cplusplus
}
#endif
#endif
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef VIDEOSTARTER_H
#define VIDEOSTARTER_H
#include <mediastreamer2/mscommon.h>
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msqueue.h>
/**
* The goal of this small object is to tell when to send I frames at startup:
* at 2 and 4 seconds.
*/
#ifdef __cplusplus
extern "C"{
#endif
typedef struct MSVideoStarter {
uint64_t next_time;
int i_frame_count;
bool_t active;
} MSVideoStarter;
MS2_PUBLIC void ms_video_starter_init(MSVideoStarter *vs);
MS2_PUBLIC void ms_video_starter_first_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC bool_t ms_video_starter_need_i_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC void ms_video_starter_deactivate(MSVideoStarter *vs);
#ifdef __cplusplus
}
#endif
#endif /* VIDEOSTARTER_H */
......@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msvideo.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/videostarter.h"
#include "mediastreamer2/mscodecutils.h"
#ifdef _WIN32
#include <ws2tcpip.h>
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
Copyright (C) 2016 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -23,8 +23,8 @@
#include "h264utils.h"
#include "mediastreamer2/rfc3984.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/videostarter.h"
#include "mediastreamer2/msiframerequestslimiter.h"
#include "mediastreamer2/mscodecutils.h"
const MSVideoConfiguration h264_video_confs[] = {
MS_VIDEO_CONF(1536000, 2560000, SXGA_MINUS, 25, 2),
......@@ -171,7 +171,7 @@ static void h264_enc_preprocess(MSFilter *f) {
VTH264EncCtx *ctx = (VTH264EncCtx *)f->data;
h264_enc_configure(ctx);
ms_video_starter_init(&ctx->starter);
ms_iframe_requests_limiter_init(&ctx->iframe_limiter, f->ticker, 1000);
ms_iframe_requests_limiter_init(&ctx->iframe_limiter, 1000);
ctx->first_frame = TRUE;
}
......@@ -214,7 +214,7 @@ static void h264_enc_process(MSFilter *f) {
freemsg(frame);
ms_filter_lock(f);
if(ctx->fps_changed || ctx->bitrate_changed || ms_iframe_requests_limiter_iframe_sending_authorized(&ctx->iframe_limiter)) {
if(ctx->fps_changed || ctx->bitrate_changed || ms_iframe_requests_limiter_iframe_requested(&ctx->iframe_limiter, f->ticker->time)) {
CFNumberRef value;
enc_param = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
if(ctx->fps_changed) {
......@@ -227,12 +227,12 @@ static void h264_enc_process(MSFilter *f) {
CFDictionaryAddValue(enc_param, kVTCompressionPropertyKey_AverageBitRate, value);
ctx->bitrate_changed = FALSE;
}
if(ms_iframe_requests_limiter_iframe_sending_authorized(&ctx->iframe_limiter)) {
if(ms_iframe_requests_limiter_iframe_requested(&ctx->iframe_limiter, f->ticker->time)) {
ms_message("MSVTH264Encoder: requesting encoder for I-frame");
int force_keyframe = 1;
value = CFNumberCreate(NULL, kCFNumberIntType, &force_keyframe);
CFDictionaryAddValue(enc_param, kVTEncodeFrameOptionKey_ForceKeyFrame, value);
ms_iframe_requests_limiter_notify_iframe_sent(&ctx->iframe_limiter);
ms_iframe_requests_limiter_notify_iframe_sent(&ctx->iframe_limiter, f->ticker->time);
}
}
ms_filter_unlock(f);
......@@ -345,7 +345,7 @@ static int h264_enc_req_vfu(MSFilter *f, void *ptr) {
VTH264EncCtx *ctx = (VTH264EncCtx *)f->data;
ms_filter_lock(f);
ms_video_starter_deactivate(&ctx->starter);
ms_iframe_requests_limiter_require_iframe(&ctx->iframe_limiter);
ms_iframe_requests_limiter_request_iframe(&ctx->iframe_limiter);
ms_filter_unlock(f);
return 0;
}
......
......@@ -22,7 +22,7 @@
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/msvideo.h"
#include "mediastreamer2/videostarter.h"
#include "mediastreamer2/mscodecutils.h"
#include "vp8rtpfmt.h"
#define PICTURE_ID_ON_16_BITS
......
#include "mediastreamer2/msiframerequestslimiter.h"
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2016 Belledonne Communications SARL
void ms_iframe_requests_limiter_init(MSIFrameRequestsLimiterCtx *obj, const MSTicker *t, int min_iframe_interval) {
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2/mscodecutils.h"
void ms_iframe_requests_limiter_init(MSIFrameRequestsLimiterCtx *obj, int min_iframe_interval) {
memset(obj, 0, sizeof(MSIFrameRequestsLimiterCtx));
obj->ticker = t;
obj->last_sent_iframe_time = t->time;
obj->last_sent_iframe_time = (uint64_t)-1;
obj->min_iframe_interval = min_iframe_interval;
}
void ms_iframe_requests_limiter_require_iframe(MSIFrameRequestsLimiterCtx *obj) {
void ms_iframe_requests_limiter_request_iframe(MSIFrameRequestsLimiterCtx *obj) {
obj->iframe_required = TRUE;
}
bool_t ms_iframe_requests_limiter_iframe_sending_authorized(const MSIFrameRequestsLimiterCtx *obj) {
return obj->iframe_required && (obj->ticker->time - obj->last_sent_iframe_time) > obj->min_iframe_interval;
bool_t ms_iframe_requests_limiter_iframe_requested(const MSIFrameRequestsLimiterCtx *obj, uint64_t curtime) {
return obj->iframe_required && ( obj->last_sent_iframe_time == (uint64_t)-1 || (curtime - obj->last_sent_iframe_time) > obj->min_iframe_interval);
}
void ms_iframe_requests_limiter_notify_iframe_sent(MSIFrameRequestsLimiterCtx *obj) {
void ms_iframe_requests_limiter_notify_iframe_sent(MSIFrameRequestsLimiterCtx *obj, uint64_t curtime) {
obj->iframe_required = FALSE;
obj->last_sent_iframe_time = obj->ticker->time;
obj->last_sent_iframe_time = curtime;
}
......@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <mediastreamer2/videostarter.h>
#include <mediastreamer2/mscodecutils.h>
void ms_video_starter_init(MSVideoStarter *vs) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment