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

Use set configuration instead of set fps, vsize and bitrate

parent e7722332
......@@ -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);
......@@ -260,6 +218,13 @@ static int msopenh264_enc_set_configuration_list(MSFilter *f, void *arg) {
return 0;
}
static int msopenh264_enc_get_configuration(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
MSVideoConfiguration *vconf = static_cast<MSVideoConfiguration *>(arg);
*vconf = e->getConfiguration();
return 0;
}
static int msopenh264_enc_set_configuration(MSFilter *f, void *arg) {
MSOpenH264Encoder *e = static_cast<MSOpenH264Encoder *>(f->data);
MSVideoConfiguration *vconf = static_cast<MSVideoConfiguration *>(arg);
......@@ -268,12 +233,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 },
......@@ -282,6 +241,7 @@ static MSFilterMethod msopenh264_enc_methods[] = {
{ 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 }
};
......
......@@ -228,33 +228,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];
......@@ -278,10 +251,15 @@ void MSOpenH264Encoder::setConfigurationList(const MSVideoConfiguration *confLis
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 */
mVConf.vsize = vsize;
ms_filter_lock(mFilter);
applyBitrate();
ms_filter_unlock(mFilter);
......
......@@ -34,16 +34,11 @@ 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