Commit fd330d26 authored by Mickaël Turnel's avatar Mickaël Turnel

Merge branch 'feature/encoder_cleanup'

parents e7722332 26176787
......@@ -171,48 +171,6 @@ static void msopenh264_enc_uninit(MSFilter *f) {
* Methods to configure the encoder *
*****************************************************************************/
static int msopenh264_enc_set_fps(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
float *fps = static_cast<float *>(arg);
e->setFPS(*fps);
return 0;
}
static int msopenh264_enc_get_fps(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
float *fps = static_cast<float *>(arg);
*fps = e->getFPS();
return 0;
}
static int msopenh264_enc_set_bitrate(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
int *bitrate = static_cast<int *>(arg);
e->setBitrate(*bitrate);
return 0;
}
static int msopenh264_enc_get_bitrate(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
int *bitrate = static_cast<int *>(arg);
*bitrate = e->getBitrate();
return 0;
}
static int msopenh264_enc_set_vsize(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
MSVideoSize *vsize = static_cast<MSVideoSize *>(arg);
e->setSize(*vsize);
return 0;
}
static int msopenh264_enc_get_vsize(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
MSVideoSize *vsize = static_cast<MSVideoSize *>(arg);
*vsize = e->getSize();
return 0;
}
static int msopenh264_enc_add_fmtp(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
const char *fmtp = static_cast<const char *>(arg);
......@@ -253,10 +211,10 @@ static int msopenh264_enc_get_configuration_list(MSFilter *f, void *arg) {
return 0;
}
static int msopenh264_enc_set_configuration_list(MSFilter *f, void *arg) {
static int msopenh264_enc_get_configuration(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
const MSVideoConfiguration **vconf_list = static_cast<const MSVideoConfiguration **>(arg);
e->setConfigurationList(*vconf_list);
MSVideoConfiguration *vconf = static_cast<MSVideoConfiguration *>(arg);
*vconf = e->getConfiguration();
return 0;
}
......@@ -268,12 +226,6 @@ static int msopenh264_enc_set_configuration(MSFilter *f, void *arg) {
}
static MSFilterMethod msopenh264_enc_methods[] = {
{ MS_FILTER_SET_FPS, msopenh264_enc_set_fps },
{ MS_FILTER_GET_FPS, msopenh264_enc_get_fps },
{ MS_FILTER_SET_BITRATE, msopenh264_enc_set_bitrate },
{ MS_FILTER_GET_BITRATE, msopenh264_enc_get_bitrate },
{ MS_FILTER_SET_VIDEO_SIZE, msopenh264_enc_set_vsize },
{ MS_FILTER_GET_VIDEO_SIZE, msopenh264_enc_get_vsize },
{ MS_FILTER_ADD_FMTP, msopenh264_enc_add_fmtp },
{ MS_FILTER_REQ_VFU, msopenh264_enc_req_vfu },
{ MS_VIDEO_ENCODER_REQ_VFU, msopenh264_enc_req_vfu },
......@@ -281,7 +233,7 @@ static MSFilterMethod msopenh264_enc_methods[] = {
{ MS_VIDEO_ENCODER_NOTIFY_FIR, msopenh264_enc_notify_fir },
{ MS_VIDEO_ENCODER_ENABLE_AVPF, msopenh264_enc_enable_avpf },
{ MS_VIDEO_ENCODER_GET_CONFIGURATION_LIST, msopenh264_enc_get_configuration_list },
{ MS_VIDEO_ENCODER_SET_CONFIGURATION_LIST, msopenh264_enc_set_configuration_list },
{ MS_VIDEO_ENCODER_GET_CONFIGURATION, msopenh264_enc_get_configuration },
{ MS_VIDEO_ENCODER_SET_CONFIGURATION, msopenh264_enc_set_configuration },
{ 0, NULL }
};
......
......@@ -72,7 +72,6 @@ MSOpenH264Encoder::MSOpenH264Encoder(MSFilter *f)
if (ret != 0) {
ms_error("OpenH264 encoder: Failed to create encoder: %li", ret);
}
setConfigurationList(NULL);
}
MSOpenH264Encoder::~MSOpenH264Encoder()
......@@ -228,33 +227,6 @@ void MSOpenH264Encoder::uninitialize()
mInitialized = false;
}
void MSOpenH264Encoder::setFPS(float fps)
{
mVConf.fps = fps;
setConfiguration(mVConf);
}
void MSOpenH264Encoder::setBitrate(int bitrate)
{
if (isInitialized()) {
// Encoding is already ongoing, do not change video size, only bitrate.
mVConf.required_bitrate = bitrate;
setConfiguration(mVConf);
} else {
MSVideoConfiguration best_vconf = ms_video_find_best_configuration_for_bitrate(mVConfList, bitrate, ms_factory_get_cpu_count(mFilter->factory));
setConfiguration(best_vconf);
}
}
void MSOpenH264Encoder::setSize(MSVideoSize size)
{
MSVideoConfiguration best_vconf = ms_video_find_best_configuration_for_size(mVConfList, size, ms_factory_get_cpu_count(mFilter->factory));
mVConf.vsize = size;
mVConf.fps = best_vconf.fps;
mVConf.bitrate_limit = best_vconf.bitrate_limit;
setConfiguration(mVConf);
}
void MSOpenH264Encoder::addFmtp(const char *fmtp)
{
char value[12];
......@@ -265,23 +237,20 @@ void MSOpenH264Encoder::addFmtp(const char *fmtp)
}
}
void MSOpenH264Encoder::setConfigurationList(const MSVideoConfiguration *confList) {
MSVideoSize vsize;
if (confList == NULL) {
mVConfList = openh264_conf_list;
} else {
mVConfList = confList;
}
MS_VIDEO_SIZE_ASSIGN(vsize, CIF);
mVConf = ms_video_find_best_configuration_for_size(mVConfList, vsize, ms_factory_get_cpu_count(mFilter->factory));
}
void MSOpenH264Encoder::setConfiguration(MSVideoConfiguration conf)
{
MSVideoSize vsize = mVConf.vsize;
mVConf = conf;
if (mVConf.required_bitrate > mVConf.bitrate_limit)
mVConf.required_bitrate = mVConf.bitrate_limit;
if (isInitialized()) {
/* Do not change video size if encoder is running */
if (!ms_video_size_equal(mVConf.vsize, vsize)) {
ms_warning("Video configuration: cannot change video size when encoder is running, actual=%dx%d, wanted=%dx%d", vsize.width, vsize.height, mVConf.vsize.width, mVConf.vsize.height);
mVConf.vsize = vsize;
}
ms_filter_lock(mFilter);
applyBitrate();
ms_filter_unlock(mFilter);
......
......@@ -34,16 +34,10 @@ public:
bool isInitialized() const { return mInitialized; }
void feed();
void uninitialize();
void setFPS(float fps);
float getFPS() const { return mVConf.fps; }
void setBitrate(int bitrate);
int getBitrate() const { return mVConf.required_bitrate; }
void setSize(MSVideoSize size);
MSVideoSize getSize() const { return mVConf.vsize; }
void addFmtp(const char *fmtp);
const MSVideoConfiguration *getConfigurationList() const { return mVConfList; }
void setConfigurationList(const MSVideoConfiguration *confList);
void setConfiguration(MSVideoConfiguration conf);
MSVideoConfiguration getConfiguration() { return mVConf; }
void requestVFU();
void enableAVPF(bool enable) { mAVPFEnabled = enable; }
void notifyPLI();
......
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