Commit cf9bde1c authored by Ghislain MARY's avatar Ghislain MARY

Use C++ to code the plugin.

parent 1e985d09
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT([msopenh264],[0.1.0]) AC_INIT([msopenh264],[0.1.0])
AM_INIT_AUTOMAKE([tar-ustar])
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE([tar-ustar])
AC_MSG_CHECKING([warning make an error on compilation]) AC_MSG_CHECKING([warning make an error on compilation])
AC_ARG_ENABLE(strict, AC_ARG_ENABLE(strict,
[ --enable-strict Enable error on compilation warning [default=yes]], [ --enable-strict Enable error on compilation warning [default=yes]],
...@@ -14,7 +14,7 @@ AC_ARG_ENABLE(strict, ...@@ -14,7 +14,7 @@ AC_ARG_ENABLE(strict,
dnl Checks for programs. dnl Checks for programs.
AC_PROG_CC AC_PROG_CXX
AC_LIBTOOL_WIN32_DLL AC_LIBTOOL_WIN32_DLL
AC_DISABLE_STATIC AC_DISABLE_STATIC
......
...@@ -2,10 +2,10 @@ pluginsdir=$(PACKAGE_PLUGINS_DIR) ...@@ -2,10 +2,10 @@ pluginsdir=$(PACKAGE_PLUGINS_DIR)
plugins_LTLIBRARIES=libmsopenh264.la plugins_LTLIBRARIES=libmsopenh264.la
libmsopenh264_la_SOURCES=msopenh264.c libmsopenh264_la_SOURCES=msopenh264.cpp msopenh264dec.cpp msopenh264enc.cpp
libmsopenh264_la_LIBADD=$(MEDIASTREAMER_LIBS) $(OPENH264_LIBS) libmsopenh264_la_LIBADD=$(MEDIASTREAMER_LIBS) $(OPENH264_LIBS)
libmsopenh264_la_LDFLAGS=-module -no-undefined libmsopenh264_la_LDFLAGS=-module -no-undefined
AM_CFLAGS=$(MEDIASTREAMER_CFLAGS) AM_CPPFLAGS=$(MEDIASTREAMER_CFLAGS)
This diff is collapsed.
/*
H.264 encoder/decoder plugin for mediastreamer2 based on the openh264 library.
Copyright (C) 2006-2012 Belledonne Communications, Grenoble
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 "msopenh264dec.h"
MSOpenH264Decoder::MSOpenH264Decoder()
: mDecoder(0), mInitialized(false), mFirstImageDecoded(false)
{
long ret = WelsCreateDecoder(&mDecoder);
if (ret != 0) {
ms_error("%s: Failed creating openh264 decoder: %d", __FUNCTION__, ret);
}
}
MSOpenH264Decoder::~MSOpenH264Decoder()
{
if (mDecoder != 0) {
WelsDestroyDecoder(mDecoder);
}
}
void MSOpenH264Decoder::initialize()
{
mFirstImageDecoded = false;
rfc3984_init(&mUnpacker);
if (mDecoder != 0) {
SDecodingParam params = { 0 };
params.iOutputColorFormat = videoFormatI420;
params.uiTargetDqLayer = (unsigned char) -1;
params.uiEcActiveFlag = 1;
params.sVideoProperty.size = sizeof(params.sVideoProperty);
params.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
long ret = mDecoder->Initialize(&params);
if (ret != 0) {
ms_error("%s: Failed to initialize openh264 decoder: %d", __FUNCTION__, ret);
} else {
mInitialized = true;
}
}
}
void MSOpenH264Decoder::feed(MSFilter *f)
{
if (!isInitialized()){
ms_queue_flush(f->inputs[0]);
return;
}
MSQueue nalus;
ms_queue_init(&nalus);
mblk_t *im;
while ((im = ms_queue_get(f->inputs[0])) != NULL) {
rfc3984_unpack(&mUnpacker, im, &nalus);
if (!ms_queue_empty(&nalus)) {
ms_message("nalus");
// void * pData[3] = { 0 };
// SBufferInfo sDstBufInfo = { 0 };
// mDecoder->DecodeFrame2 (pBuf + iBufPos, iSliceSize, pData, &sDstBufInfo);
// if (sDstBufInfo.iBufferStatus == 1) {
// uint8_t * pDst[3] = { 0 };
// pDst[0] = (uint8_t *)pData[0];
// pDst[1] = (uint8_t *)pData[1];
// pDst[2] = (uint8_t *)pData[2];
// }
}
}
}
void MSOpenH264Decoder::uninitialize()
{
if (mDecoder != 0) {
mDecoder->Uninitialize();
}
mInitialized = false;
}
/*
H.264 encoder/decoder plugin for mediastreamer2 based on the openh264 library.
Copyright (C) 2006-2012 Belledonne Communications, Grenoble
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/msfilter.h"
#include "mediastreamer2/rfc3984.h"
#include "wels/codec_api.h"
class MSOpenH264Decoder {
public:
MSOpenH264Decoder();
virtual ~MSOpenH264Decoder();
bool isInitialized() const { return mInitialized; }
void initialize();
void feed(MSFilter *f);
void uninitialize();
private:
SDecodingParam mDecoderParams;
ISVCDecoder *mDecoder;
Rfc3984Context mUnpacker;
bool mInitialized;
bool mFirstImageDecoded;
};
/*
H.264 encoder/decoder plugin for mediastreamer2 based on the openh264 library.
Copyright (C) 2006-2012 Belledonne Communications, Grenoble
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 "msopenh264enc.h"
#define MS_OPENH264_CONF(required_bitrate, bitrate_limit, resolution, fps) \
{ required_bitrate, bitrate_limit, { MS_VIDEO_SIZE_ ## resolution ## _W, MS_VIDEO_SIZE_ ## resolution ## _H }, fps, NULL }
static const MSVideoConfiguration openh264_conf_list[] = {
#if defined(ANDROID) || (TARGET_OS_IPHONE == 1) || defined(__arm__)
MS_OPENH264_CONF(0, 512000, QVGA, 12)
#else
MS_OPENH264_CONF(1024000, 1536000, SVGA, 25),
MS_OPENH264_CONF( 512000, 1024000, VGA, 25),
MS_OPENH264_CONF( 256000, 512000, VGA, 15),
MS_OPENH264_CONF( 170000, 256000, QVGA, 15),
MS_OPENH264_CONF( 128000, 170000, QCIF, 10),
MS_OPENH264_CONF( 64000, 128000, QCIF, 7),
MS_OPENH264_CONF( 0, 64000, QCIF, 5)
#endif
};
static const MSVideoConfiguration multicore_openh264_conf_list[] = {
#if defined(ANDROID) || (TARGET_OS_IPHONE == 1) || defined(__arm__)
MS_OPENH264_CONF(2048000, 3072000, UXGA, 15),
MS_OPENH264_CONF(1024000, 1536000, SXGA_MINUS, 15),
MS_OPENH264_CONF( 750000, 1024000, XGA, 15),
MS_OPENH264_CONF( 500000, 750000, SVGA, 15),
MS_OPENH264_CONF( 300000, 500000, VGA, 12),
MS_OPENH264_CONF( 0, 300000, QVGA, 12)
#else
MS_OPENH264_CONF(1536000, 2560000, SXGA_MINUS, 15),
MS_OPENH264_CONF(1536000, 2560000, 720P, 15),
MS_OPENH264_CONF(1024000, 1536000, XGA, 15),
MS_OPENH264_CONF( 512000, 1024000, SVGA, 15),
MS_OPENH264_CONF( 256000, 512000, VGA, 15),
MS_OPENH264_CONF( 170000, 256000, QVGA, 15),
MS_OPENH264_CONF( 128000, 170000, QCIF, 10),
MS_OPENH264_CONF( 64000, 128000, QCIF, 7),
MS_OPENH264_CONF( 0, 64000, QCIF, 5)
#endif
};
MSOpenH264Encoder::MSOpenH264Encoder()
: mVConfList(openh264_conf_list), mInitialized(false)
{
if (ms_get_cpu_count() > 1) mVConfList = &multicore_openh264_conf_list[0];
mVConf = ms_video_find_best_configuration_for_bitrate(mVConfList, 384000);
long ret = WelsCreateSVCEncoder(&mEncoder);
if (ret != 0) {
ms_error("%s: Failed creating openh264 encoder: %d", __FUNCTION__, ret);
}
}
MSOpenH264Encoder::~MSOpenH264Encoder()
{
if (mEncoder != 0) {
WelsDestroySVCEncoder(mEncoder);
}
}
void MSOpenH264Encoder::initialize()
{
// TODO
}
void MSOpenH264Encoder::feed(MSFilter *f)
{
if (!isInitialized()){
ms_queue_flush(f->inputs[0]);
return;
}
}
void MSOpenH264Encoder::uninitialize()
{
// TODO
}
void MSOpenH264Encoder::setFps(float fps)
{
// TODO
}
void MSOpenH264Encoder::setBitrate(int bitrate)
{
// TODO
}
void MSOpenH264Encoder::setSize(MSVideoSize size)
{
// TODO
}
void MSOpenH264Encoder::setPixFormat(MSPixFmt format)
{
// TODO
}
void MSOpenH264Encoder::addFmtp(const char *fmtp)
{
// TODO
}
void MSOpenH264Encoder::generateKeyframe()
{
// TODO
}
void MSOpenH264Encoder::setConfiguration(MSVideoConfiguration conf)
{
// TODO
}
/*
H.264 encoder/decoder plugin for mediastreamer2 based on the openh264 library.
Copyright (C) 2006-2012 Belledonne Communications, Grenoble
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/msfilter.h"
#include "mediastreamer2/msvideo.h"
#include "wels/codec_api.h"
class MSOpenH264Encoder {
public:
MSOpenH264Encoder();
virtual ~MSOpenH264Encoder();
void initialize();
bool isInitialized() const { return mInitialized; }
void feed(MSFilter *f);
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 setPixFormat(MSPixFmt format);
void addFmtp(const char *fmtp);
void generateKeyframe();
const MSVideoConfiguration *getConfigurationList() const { return mVConfList; }
void setConfiguration(MSVideoConfiguration conf);
private:
ISVCEncoder *mEncoder;
const MSVideoConfiguration *mVConfList;
MSVideoConfiguration mVConf;
bool mInitialized;
};
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