Ok, looks good except x265_ssim should not be extern, and should be a part of common.cpp and not api.cpp.
On Tue, Feb 25, 2014 at 2:33 PM, <sa...@multicorewareinc.com> wrote: > # HG changeset patch > # User Sagar Kotecha <sa...@multicorewareinc.com> > # Date 1393318766 -19800 > # Tue Feb 25 14:29:26 2014 +0530 > # Node ID 504c2a959e5815cb3020033289137f64cb458aee > # Parent a36a669d09e89332dd91817afdf139853ba3ad03 > Add x265 API defination to api.cpp > > diff -r a36a669d09e8 -r 504c2a959e58 source/common/common.cpp > --- a/source/common/common.cpp Tue Feb 25 02:22:06 2014 -0600 > +++ b/source/common/common.cpp Tue Feb 25 14:29:26 2014 +0530 > @@ -134,23 +134,3 @@ > va_end(arg); > } > > -extern "C" > -x265_picture *x265_picture_alloc() > -{ > - return (x265_picture*)x265_malloc(sizeof(x265_picture)); > -} > - > -extern "C" > -void x265_picture_init(x265_param *param, x265_picture *pic) > -{ > - memset(pic, 0, sizeof(x265_picture)); > - > - pic->bitDepth = param->internalBitDepth; > - pic->colorSpace = param->internalCsp; > -} > - > -extern "C" > -void x265_picture_free(x265_picture *p) > -{ > - return x265_free(p); > -} > diff -r a36a669d09e8 -r 504c2a959e58 source/encoder/CMakeLists.txt > --- a/source/encoder/CMakeLists.txt Tue Feb 25 02:22:06 2014 -0600 > +++ b/source/encoder/CMakeLists.txt Tue Feb 25 14:29:26 2014 +0530 > @@ -58,4 +58,5 @@ > compress.cpp > reference.cpp reference.h > encoder.cpp encoder.h > + api.cpp > weightPrediction.cpp) > diff -r a36a669d09e8 -r 504c2a959e58 source/encoder/api.cpp > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/source/encoder/api.cpp Tue Feb 25 14:29:26 2014 +0530 > @@ -0,0 +1,199 @@ > > +/***************************************************************************** > + * Copyright (C) 2013 x265 project > + * > + * Authors: Steve Borho <st...@borho.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., 51 Franklin Street, Fifth Floor, Boston, MA 02111, > USA. > + * > + * This program is also available under a commercial proprietary license. > + * For more information, contact us at licens...@multicorewareinc.com. > + > *****************************************************************************/ > + > +#include "TLibCommon/CommonDef.h" > +#include "param.h" > +#include "encoder.h" > +#include "frameencoder.h" > + > +using namespace x265; > + > +extern "C" > +x265_encoder *x265_encoder_open(x265_param *param) > +{ > + x265_setup_primitives(param, -1); // -1 means auto-detect if > uninitialized > + > + if (x265_check_params(param)) > + return NULL; > + > + if (x265_set_globals(param)) > + return NULL; > + > + Encoder *encoder = new Encoder; > + if (encoder) > + { > + // these may change params for auto-detect, etc > + encoder->determineLevelAndProfile(param); > + encoder->configure(param); > + > + // save a copy of final parameters in TEncCfg > + memcpy(&encoder->param, param, sizeof(*param)); > + > + x265_print_params(param); > + encoder->create(); > + encoder->init(); > + } > + > + return encoder; > +} > + > +extern "C" > +int x265_encoder_headers(x265_encoder *enc, x265_nal **pp_nal, uint32_t > *pi_nal) > +{ > + if (!pp_nal || !enc) > + return 0; > + > + Encoder *encoder = static_cast<Encoder*>(enc); > + > + int ret = 0; > + NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 }; > + if (!encoder->getStreamHeaders(nalunits)) > + { > + int nalcount = encoder->extractNalData(nalunits); > + *pp_nal = &encoder->m_nals[0]; > + if (pi_nal) *pi_nal = nalcount; > + } > + else if (pi_nal) > + { > + *pi_nal = 0; > + ret = -1; > + } > + > + for (int i = 0; i < MAX_NAL_UNITS; i++) > + { > + if (nalunits[i]) > + { > + free(nalunits[i]->m_nalUnitData); > + X265_FREE(nalunits[i]); > + } > + } > + > + return ret; > +} > + > +extern "C" > +int x265_encoder_encode(x265_encoder *enc, x265_nal **pp_nal, uint32_t > *pi_nal, x265_picture *pic_in, x265_picture *pic_out) > +{ > + if (!enc) > + return -1; > + > + Encoder *encoder = static_cast<Encoder*>(enc); > + NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 }; > + int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, nalunits); > + > + if (pp_nal && numEncoded > 0) > + { > + int nalcount = encoder->extractNalData(nalunits); > + *pp_nal = &encoder->m_nals[0]; > + if (pi_nal) *pi_nal = nalcount; > + } > + else if (pi_nal) > + *pi_nal = 0; > + > + for (int i = 0; i < MAX_NAL_UNITS; i++) > + { > + if (nalunits[i]) > + { > + free(nalunits[i]->m_nalUnitData); > + X265_FREE(nalunits[i]); > + } > + } > + > + return numEncoded; > +} > + > +EXTERN_CYCLE_COUNTER(ME); > + > +extern "C" > +void x265_encoder_get_stats(x265_encoder *enc, x265_stats *outputStats, > uint32_t statsSizeBytes) > +{ > + if (enc && outputStats) > + { > + Encoder *encoder = static_cast<Encoder*>(enc); > + encoder->fetchStats(outputStats, statsSizeBytes); > + } > +} > + > +extern "C" > +void x265_encoder_log(x265_encoder* enc, int argc, char **argv) > +{ > + if (enc) > + { > + Encoder *encoder = static_cast<Encoder*>(enc); > + encoder->writeLog(argc, argv); > + } > +} > + > +extern "C" > +void x265_encoder_close(x265_encoder *enc) > +{ > + if (enc) > + { > + Encoder *encoder = static_cast<Encoder*>(enc); > + > + REPORT_CYCLE_COUNTER(ME); > + > + encoder->printSummary(); > + encoder->destroy(); > + delete encoder; > + } > +} > + > +extern "C" > +void x265_cleanup(void) > +{ > + destroyROM(); > + BitCost::destroy(); > +} > + > +extern "C" > +double x265_ssim(double ssim) > +{ > + double inv_ssim = 1 - ssim; > + > + if (inv_ssim <= 0.0000000001) /* Max 100dB */ > + return 100; > + > + return -10.0 * log10(inv_ssim); > +} > + > +extern "C" > +x265_picture *x265_picture_alloc() > +{ > + return (x265_picture*)x265_malloc(sizeof(x265_picture)); > +} > + > +extern "C" > +void x265_picture_init(x265_param *param, x265_picture *pic) > +{ > + memset(pic, 0, sizeof(x265_picture)); > + > + pic->bitDepth = param->internalBitDepth; > + pic->colorSpace = param->internalCsp; > +} > + > +extern "C" > +void x265_picture_free(x265_picture *p) > +{ > + return x265_free(p); > +} > \ No newline at end of file > diff -r a36a669d09e8 -r 504c2a959e58 source/encoder/encoder.cpp > --- a/source/encoder/encoder.cpp Tue Feb 25 02:22:06 2014 -0600 > +++ b/source/encoder/encoder.cpp Tue Feb 25 14:29:26 2014 +0530 > @@ -1587,151 +1587,3 @@ > return nalcount; > } > > -extern "C" > -x265_encoder *x265_encoder_open(x265_param *param) > -{ > - x265_setup_primitives(param, -1); // -1 means auto-detect if > uninitialized > - > - if (x265_check_params(param)) > - return NULL; > - > - if (x265_set_globals(param)) > - return NULL; > - > - Encoder *encoder = new Encoder; > - if (encoder) > - { > - // these may change params for auto-detect, etc > - encoder->determineLevelAndProfile(param); > - encoder->configure(param); > - > - // save a copy of final parameters in TEncCfg > - memcpy(&encoder->param, param, sizeof(*param)); > - > - x265_print_params(param); > - encoder->create(); > - encoder->init(); > - } > - > - return encoder; > -} > - > -extern "C" > -int x265_encoder_headers(x265_encoder *enc, x265_nal **pp_nal, uint32_t > *pi_nal) > -{ > - if (!pp_nal || !enc) > - return 0; > - > - Encoder *encoder = static_cast<Encoder*>(enc); > - > - int ret = 0; > - NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 }; > - if (!encoder->getStreamHeaders(nalunits)) > - { > - int nalcount = encoder->extractNalData(nalunits); > - *pp_nal = &encoder->m_nals[0]; > - if (pi_nal) *pi_nal = nalcount; > - } > - else if (pi_nal) > - { > - *pi_nal = 0; > - ret = -1; > - } > - > - for (int i = 0; i < MAX_NAL_UNITS; i++) > - { > - if (nalunits[i]) > - { > - free(nalunits[i]->m_nalUnitData); > - X265_FREE(nalunits[i]); > - } > - } > - > - return ret; > -} > - > -extern "C" > -int x265_encoder_encode(x265_encoder *enc, x265_nal **pp_nal, uint32_t > *pi_nal, x265_picture *pic_in, x265_picture *pic_out) > -{ > - if (!enc) > - return -1; > - > - Encoder *encoder = static_cast<Encoder*>(enc); > - NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 }; > - int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, nalunits); > - > - if (pp_nal && numEncoded > 0) > - { > - int nalcount = encoder->extractNalData(nalunits); > - *pp_nal = &encoder->m_nals[0]; > - if (pi_nal) *pi_nal = nalcount; > - } > - else if (pi_nal) > - *pi_nal = 0; > - > - for (int i = 0; i < MAX_NAL_UNITS; i++) > - { > - if (nalunits[i]) > - { > - free(nalunits[i]->m_nalUnitData); > - X265_FREE(nalunits[i]); > - } > - } > - > - return numEncoded; > -} > - > -EXTERN_CYCLE_COUNTER(ME); > - > -extern "C" > -void x265_encoder_get_stats(x265_encoder *enc, x265_stats *outputStats, > uint32_t statsSizeBytes) > -{ > - if (enc && outputStats) > - { > - Encoder *encoder = static_cast<Encoder*>(enc); > - encoder->fetchStats(outputStats, statsSizeBytes); > - } > -} > - > -extern "C" > -void x265_encoder_log(x265_encoder* enc, int argc, char **argv) > -{ > - if (enc) > - { > - Encoder *encoder = static_cast<Encoder*>(enc); > - encoder->writeLog(argc, argv); > - } > -} > - > -extern "C" > -void x265_encoder_close(x265_encoder *enc) > -{ > - if (enc) > - { > - Encoder *encoder = static_cast<Encoder*>(enc); > - > - REPORT_CYCLE_COUNTER(ME); > - > - encoder->printSummary(); > - encoder->destroy(); > - delete encoder; > - } > -} > - > -extern "C" > -void x265_cleanup(void) > -{ > - destroyROM(); > - BitCost::destroy(); > -} > - > -extern "C" > -double x265_ssim(double ssim) > -{ > - double inv_ssim = 1 - ssim; > - > - if (inv_ssim <= 0.0000000001) /* Max 100dB */ > - return 100; > - > - return -10.0 * log10(inv_ssim); > -} > _______________________________________________ > x265-devel mailing list > x265-devel@videolan.org > https://mailman.videolan.org/listinfo/x265-devel >
_______________________________________________ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel