Re: [x265] [PATCH] Add x265 API defination to api.cpp

2014-02-25 Thread Deepthi Nandakumar
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 +
 +++ b/source/encoder/api.cppTue 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_castEncoder*(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_castEncoder*(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];
 

Re: [x265] [PATCH] Add x265 API defination to api.cpp

2014-02-25 Thread Sagar Kotecha
Sent new patch

With Regards,
Sagar


On Tue, Feb 25, 2014 at 2:37 PM, Deepthi Nandakumar 
deep...@multicorewareinc.com wrote:

 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 +
 +++ b/source/encoder/api.cppTue 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_castEncoder*(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_castEncoder*(enc);
 +NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 };
 +int numEncoded = encoder-encode(!pic_in, pic_in, pic_out, nalunits);
 +
 +if 

Re: [x265] [PATCH] Add x265 API defination to api.cpp

2014-02-25 Thread Steve Borho
On Tue, Feb 25, 2014 at 3:25 AM,  sa...@multicorewareinc.com wrote:
 # HG changeset patch
 # User Sagar Kotecha sa...@multicorewareinc.com
 # Date 1393320320 -19800
 #  Tue Feb 25 14:55:20 2014 +0530
 # Node ID 559ef195b954fa4d3c8bbc9bf8b7619991596c36
 # Parent  a36a669d09e89332dd91817afdf139853ba3ad03
 Add x265 API defination to api.cpp

Queued, with one nit fix


 diff -r a36a669d09e8 -r 559ef195b954 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:55:20 2014 +0530
 @@ -134,23 +134,12 @@
  va_end(arg);
  }

 -extern C
 -x265_picture *x265_picture_alloc()
 +double x265_ssim(double ssim)
  {
 -return (x265_picture*)x265_malloc(sizeof(x265_picture));
 -}
 +double inv_ssim = 1 - ssim;

 -extern C
 -void x265_picture_init(x265_param *param, x265_picture *pic)
 -{
 -memset(pic, 0, sizeof(x265_picture));
 +if (inv_ssim = 0.01) /* Max 100dB */
 +return 100;

 -pic-bitDepth = param-internalBitDepth;
 -pic-colorSpace = param-internalCsp;
 -}
 -
 -extern C
 -void x265_picture_free(x265_picture *p)
 -{
 -return x265_free(p);
 -}
 +return -10.0 * log10(inv_ssim);
 +}
 \ No newline at end of file

When you see this in the diff, add a blank line to the end of the file

 diff -r a36a669d09e8 -r 559ef195b954 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:55:20 2014 +0530
 @@ -58,4 +58,5 @@
  compress.cpp
  reference.cpp reference.h
  encoder.cpp encoder.h
 +api.cpp
  weightPrediction.cpp)
 diff -r a36a669d09e8 -r 559ef195b954 source/encoder/api.cpp
 --- /dev/null   Thu Jan 01 00:00:00 1970 +
 +++ b/source/encoder/api.cppTue Feb 25 14:55:20 2014 +0530
 @@ -0,0 +1,188 @@
 +/*
 + * 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_castEncoder*(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_castEncoder*(enc);
 +NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 };
 +int numEncoded 

Re: [x265] [PATCH] Add x265 API defination to api.cpp

2014-02-25 Thread Steve Borho
On Tue, Feb 25, 2014 at 3:07 AM, Deepthi Nandakumar
deep...@multicorewareinc.com wrote:
 Ok, looks good except x265_ssim should not be extern, and should be a part
 of common.cpp and not api.cpp.

So long as x265_ssim() is declared in x265.h, its implementation must
be defined extern C.

if the declaration is moved to common.h, then we can remove the C
decoration, but we should do that together with all of the pending API
changes so we don't bump the build number too frequently.  The
function is very poorly named, when it is removed from the public API
it should be given a descriptive name.

-- 
Steve Borho
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel