Merge commit '233d2fa0443197df12b4f7823d591dad964149b3'
authorHendrik Leppkes <h.leppkes@gmail.com>
Tue, 27 Oct 2015 12:47:32 +0000 (13:47 +0100)
committerHendrik Leppkes <h.leppkes@gmail.com>
Tue, 27 Oct 2015 12:49:37 +0000 (13:49 +0100)
* commit '233d2fa0443197df12b4f7823d591dad964149b3':
  kvazaar: Add libkvazaar HEVC encoder

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
configure
libavcodec/libkvazaar.c

diff --cc configure
+++ b/configure
@@@ -5346,43 -4423,23 +5346,43 @@@ enabled libgsm            && { for gsm_
                                     check_lib "${gsm_hdr}" gsm_create -lgsm && break;
                                 done || die "ERROR: libgsm not found"; }
  enabled libilbc           && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
- enabled libkvazaar        && require_pkg_config "kvazaar >= 0.7.0" kvazaar.h kvz_api_get
+ enabled libkvazaar        && require_pkg_config "kvazaar >= 0.7.1" kvazaar.h kvz_api_get
  enabled libmfx            && require_pkg_config libmfx "mfx/mfxvideo.h" MFXInit
 +enabled libmodplug        && require_pkg_config libmodplug libmodplug/modplug.h ModPlug_Load
  enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
 +enabled libnut            && require libnut libnut.h nut_demuxer_init -lnut
  enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
  enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
 -enabled libopencv         && require_pkg_config opencv opencv/cv.h cvCreateImageHeader
 +enabled libopencv         && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
  enabled libopenh264       && require_pkg_config openh264 wels/codec_api.h WelsGetCodecVersion
 -enabled libopenjpeg       && { { check_header openjpeg.h && check_lib2 openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC; } ||
 -                               { require_pkg_config libopenjpeg1 openjpeg.h opj_version -DOPJ_STATIC; } }
 +enabled libopenjpeg       && { check_lib openjpeg.h opj_version -lopenmj2 -DOPJ_STATIC ||
 +                               check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
 +                               check_lib openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
 +                               die "ERROR: libopenjpeg not found"; }
  enabled libopus           && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
 -enabled libpulse          && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
 +enabled libpulse          && require_pkg_config libpulse pulse/pulseaudio.h pa_context_new
 +enabled libquvi           && require_pkg_config libquvi quvi/quvi.h quvi_init
  enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
 +enabled librubberband     && require_pkg_config "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
  enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
 +enabled libshine          && require_pkg_config shine shine/layer3.h shine_encode_buffer
 +enabled libsmbclient      && { use_pkg_config smbclient libsmbclient.h smbc_init ||
 +                               require smbclient libsmbclient.h smbc_init -lsmbclient; }
  enabled libsnappy         && require snappy snappy-c.h snappy_compress -lsnappy
 +enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr && LIBSOXR="-lsoxr"
 +enabled libssh            && require_pkg_config libssh libssh/sftp.h sftp_init
  enabled libspeex          && require_pkg_config speex speex/speex.h speex_decoder_init -lspeex
 +enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
 +    media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
 +    media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder -lgnustl_static
 +enabled libtesseract      && require_pkg_config tesseract tesseract/capi.h TessBaseAPICreate
  enabled libtheora         && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
 -enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame
 +enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame &&
 +                             { check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
 +                               die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
 +enabled libutvideo        && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++
 +enabled libv4l2           && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
 +enabled libvidstab        && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
  enabled libvo_aacenc      && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
  enabled libvo_amrwbenc    && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
  enabled libvorbis         && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
  #include <kvazaar.h>
  #include <string.h>
  
- #include "libavutil/imgutils.h"
 +#include "libavutil/avassert.h"
  #include "libavutil/dict.h"
- #include "libavutil/opt.h"
+ #include "libavutil/error.h"
+ #include "libavutil/imgutils.h"
+ #include "libavutil/internal.h"
  #include "libavutil/pixdesc.h"
+ #include "libavutil/opt.h"
  #include "avcodec.h"
  #include "internal.h"
  
@@@ -43,25 -45,30 +46,24 @@@ typedef struct LibkvazaarContext 
  
  static av_cold int libkvazaar_init(AVCodecContext *avctx)
  {
-     int retval = 0;
+     LibkvazaarContext *const ctx = avctx->priv_data;
+     const kvz_api *const api = ctx->api = kvz_api_get(8);
      kvz_config *cfg = NULL;
      kvz_encoder *enc = NULL;
-     const kvz_api *const api = kvz_api_get(8);
-     LibkvazaarContext *const ctx = avctx->priv_data;
  
-     // Kvazaar requires width and height to be multiples of eight.
 -    if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
 -        av_log(avctx, AV_LOG_ERROR,
 -               "Set -strict experimental to use this encoder.\n");
 -        return AVERROR_EXPERIMENTAL;
 -    }
 -
+     /* Kvazaar requires width and height to be multiples of eight. */
      if (avctx->width % 8 || avctx->height % 8) {
-         av_log(avctx, AV_LOG_ERROR, "Video dimensions are not a multiple of 8.\n");
-         retval = AVERROR_INVALIDDATA;
-         goto done;
+         av_log(avctx, AV_LOG_ERROR,
+                "Video dimensions are not a multiple of 8 (%dx%d).\n",
+                avctx->width, avctx->height);
+         return AVERROR(ENOSYS);
      }
  
-     cfg = api->config_alloc();
+     ctx->config = cfg = api->config_alloc();
      if (!cfg) {
-         av_log(avctx, AV_LOG_ERROR, "Could not allocate kvazaar config structure.\n");
-         retval = AVERROR(ENOMEM);
-         goto done;
+         av_log(avctx, AV_LOG_ERROR,
+                "Could not allocate kvazaar config structure.\n");
+         return AVERROR(ENOMEM);
      }
  
      if (!api->config_init(cfg)) {
@@@ -136,18 -154,14 +149,16 @@@ static int libkvazaar_encode(AVCodecCon
                               const AVFrame *frame,
                               int *got_packet_ptr)
  {
-     int retval = 0;
-     kvz_picture *img_in = NULL;
-     kvz_data_chunk *data_out = NULL;
-     uint32_t len_out = 0;
+     LibkvazaarContext *ctx = avctx->priv_data;
+     kvz_picture *input_pic = NULL;
      kvz_picture *recon_pic = NULL;
      kvz_frame_info frame_info;
-     LibkvazaarContext *ctx = avctx->priv_data;
+     kvz_data_chunk *data_out = NULL;
+     uint32_t len_out = 0;
+     int retval = 0;
  
 +    *got_packet_ptr = 0;
 +
      if (frame) {
          if (frame->width != ctx->config->width ||
                  frame->height != ctx->config->height) {
                            frame->format, frame->width, frame->height);
          }
  
-         img_in->pts = frame->pts;
+         input_pic->pts = frame->pts;
      }
  
-     if (!ctx->api->encoder_encode(ctx->encoder, img_in,
-                                   &data_out, &len_out,
-                                   &recon_pic, NULL,
-                                   &frame_info)) {
+     retval = ctx->api->encoder_encode(ctx->encoder,
+                                       input_pic,
+                                       &data_out, &len_out,
+                                       &recon_pic, NULL,
+                                       &frame_info);
+     if (!retval) {
          av_log(avctx, AV_LOG_ERROR, "Failed to encode frame.\n");
-         retval = AVERROR_EXTERNAL;
+         retval = AVERROR_INVALIDDATA;
          goto done;
      }
++    else
++        retval = 0; /* kvazaar returns 1 on success */
  
      if (data_out) {
          kvz_data_chunk *chunk = NULL;
@@@ -247,10 -259,12 +259,11 @@@ static const enum AVPixelFormat pix_fmt
      AV_PIX_FMT_NONE
  };
  
+ #define OFFSET(x) offsetof(LibkvazaarContext, x)
+ #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  static const AVOption options[] = {
-     { "kvazaar-params", "Set kvazaar parameters as a comma-separated list of name=value pairs.",
-       offsetof(LibkvazaarContext, kvz_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0,
-       AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+     { "kvazaar-params", "Set kvazaar parameters as a comma-separated list of key=value pairs.",
+         OFFSET(kvz_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
 -
      { NULL },
  };