[x264-devel] [PATCH 21/32] Include an implementation file to wrap the appropriate call
Vittorio Giovara
vittorio.giovara at gmail.com
Fri Jan 20 15:20:46 CET 2017
This file allocates an internal structure and calls the main API entry
points using the correct function depending on runtime configuration.
---
Makefile | 33 +++++++---
common/api.c | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
common/common.h | 2 +
3 files changed, 215 insertions(+), 7 deletions(-)
create mode 100644 common/api.c
diff --git a/Makefile b/Makefile
index 1475877..11858b3 100644
--- a/Makefile
+++ b/Makefile
@@ -9,16 +9,19 @@ vpath %.asm $(SRCPATH)
vpath %.rc $(SRCPATH)
GENERATED =
+HEADERS =
all: default
default:
+SRCSCOMMON = common/api.c common/cpu.c common/log.c common/mem.c common/picture.c \
+ common/mathematics.c common/param.c common/tables.c common/osdep.c
+
SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
- common/frame.c common/dct.c common/cpu.c common/cabac.c \
- common/common.c common/osdep.c common/rectangle.c \
+ common/frame.c common/dct.c common/cabac.c \
+ common/common.c common/rectangle.c \
common/set.c common/quant.c common/deblock.c common/vlc.c \
common/mvpred.c common/bitstream.c \
- common/log.c common/mem.c common/picture.c common/mathematics.c common/param.c common/tables.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c \
encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
@@ -31,6 +34,7 @@ SRCCLI = x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
filters/video/select_every.c filters/video/crop.c filters/video/depth.c
SRCSO =
+
OBJS =
OBJSO =
OBJCLI =
@@ -176,12 +180,16 @@ endif
common/bitdepth.h: $(SRCPATH)/tools/duplicate.sh $(SRCPATH)/tools/api.list
$(SRCPATH)/tools/duplicate.sh $(SRCPATH)/tools/api.list > $@
-GENERATED += common/bitdepth.h
+HEADERS += common/bitdepth.h
+GENERATED += $(HEADERS)
-OBJS += $(SRCS:%.c=%.o)
+OBJS += $(SRCSCOMMON:%.c=%.o)
OBJCLI += $(SRCCLI:%.c=%.o)
OBJSO += $(SRCSO:%.c=%.o)
+OBJS += $(SRCS:%.c=8bit/%.o)
+OBJS += $(SRCS:%.c=10bit/%.o)
+
.PHONY: all default fprofiled clean distclean install install-* uninstall cli lib-* etags
cli: x264$(EXE)
@@ -214,6 +222,17 @@ example$(EXE): $(GENERATED) .depend $(OBJEXAMPLE) $(LIBX264)
$(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJEXAMPLE): .depend
+%.o: %.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+8bit/%.o: %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
+
+10bit/%.o: %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
+
%.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
$(AS) $(ASFLAGS) -o $@ $<
-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
@@ -228,7 +247,7 @@ $(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJEXAMPLE): .depend
%.o: %.rc x264.h
$(RC) $(RCFLAGS)$@ $<
-.depend: config.mak
+.depend: config.mak $(HEADERS)
@rm -f .depend
@echo 'dependency file generation...'
ifeq ($(COMPILER),CL)
@@ -245,7 +264,7 @@ ifneq ($(wildcard .depend),)
include .depend
endif
-SRC2 = $(SRCS) $(SRCCLI)
+SRC2 = $(SRCS) $(SRCCLI) $(SRCSCOMMON)
# These should cover most of the important codepaths
OPT0 = --crf 30 -b1 -m1 -r1 --me dia --no-cabac --direct temporal --ssim --no-weightb
OPT1 = --crf 16 -b2 -m3 -r3 --me hex --no-8x8dct --direct spatial --no-dct-decimate -t0 --slice-max-mbs 50
diff --git a/common/api.c b/common/api.c
new file mode 100644
index 0000000..3d246d1
--- /dev/null
+++ b/common/api.c
@@ -0,0 +1,187 @@
+/*****************************************************************************
+ * api.c: bitdepth-independent interface
+ *****************************************************************************
+ * Copyright (C) 2003-2017 x264 project
+ *
+ * Authors: Vittorio Giovara <vittorio.giovara at gmail.com>
+ * Luca Barbato <lu_zero at gentoo.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 licensing at x264.com.
+ *****************************************************************************/
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "x264.h"
+
+x264_t *x264_8_encoder_open( x264_param_t * );
+void x264_8_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
+int x264_8_encoder_reconfig( x264_t *, x264_param_t * );
+void x264_8_encoder_parameters( x264_t *, x264_param_t * );
+int x264_8_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
+int x264_8_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
+void x264_8_encoder_close( x264_t * );
+int x264_8_encoder_delayed_frames( x264_t * );
+int x264_8_encoder_maximum_delayed_frames( x264_t *h );
+void x264_8_encoder_intra_refresh( x264_t * );
+int x264_8_encoder_invalidate_reference( x264_t *, int64_t pts );
+
+x264_t *x264_10_encoder_open( x264_param_t * );
+void x264_10_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
+int x264_10_encoder_reconfig( x264_t *, x264_param_t * );
+void x264_10_encoder_parameters( x264_t *, x264_param_t * );
+int x264_10_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
+int x264_10_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
+void x264_10_encoder_close( x264_t * );
+int x264_10_encoder_delayed_frames( x264_t * );
+int x264_10_encoder_maximum_delayed_frames( x264_t *h );
+void x264_10_encoder_intra_refresh( x264_t * );
+int x264_10_encoder_invalidate_reference( x264_t *, int64_t pts );
+
+typedef struct x264_api_t {
+ /* Internal reference to x264_t data */
+ void *x264;
+
+ /* API entry points */
+ void (*x264_nal_encode) ( x264_t *h, uint8_t *dst, x264_nal_t *nal );
+ int (*x264_encoder_reconfig) ( x264_t *, x264_param_t * );
+ void (*x264_encoder_parameters) ( x264_t *, x264_param_t * );
+ int (*x264_encoder_headers) ( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
+ int (*x264_encoder_encode) ( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
+ void (*x264_encoder_close) ( x264_t * );
+ int (*x264_encoder_delayed_frames) ( x264_t * );
+ int (*x264_encoder_maximum_delayed_frames) ( x264_t *h );
+ void (*x264_encoder_intra_refresh) ( x264_t * );
+ int (*x264_encoder_invalidate_reference) ( x264_t *, int64_t pts );
+} x264_api_t;
+
+x264_t *x264_encoder_open( x264_param_t *param )
+{
+ x264_api_t *api;
+
+ api = calloc( 1, sizeof(x264_api_t) );
+ if( !api )
+ return NULL;
+
+ if( param->i_bitdepth == 0 || param->i_bitdepth == 8 ) {
+ api->x264_encoder_reconfig = x264_8_encoder_reconfig;
+ api->x264_encoder_parameters = x264_8_encoder_parameters;
+ api->x264_encoder_headers = x264_8_encoder_headers;
+ api->x264_encoder_encode = x264_8_encoder_encode;
+ api->x264_encoder_close = x264_8_encoder_close;
+ api->x264_encoder_delayed_frames = x264_8_encoder_delayed_frames;
+ api->x264_encoder_maximum_delayed_frames = x264_8_encoder_maximum_delayed_frames;
+ api->x264_encoder_intra_refresh = x264_8_encoder_intra_refresh;
+ api->x264_encoder_invalidate_reference = x264_8_encoder_invalidate_reference;
+
+ api->x264 = x264_8_encoder_open( param );
+ } else if( param->i_bitdepth == 10 ) {
+ api->x264_encoder_reconfig = x264_10_encoder_reconfig;
+ api->x264_encoder_parameters = x264_10_encoder_parameters;
+ api->x264_encoder_headers = x264_10_encoder_headers;
+ api->x264_encoder_encode = x264_10_encoder_encode;
+ api->x264_encoder_close = x264_10_encoder_close;
+ api->x264_encoder_delayed_frames = x264_10_encoder_delayed_frames;
+ api->x264_encoder_maximum_delayed_frames = x264_10_encoder_maximum_delayed_frames;
+ api->x264_encoder_intra_refresh = x264_10_encoder_intra_refresh;
+ api->x264_encoder_invalidate_reference = x264_10_encoder_invalidate_reference;
+
+ api->x264 = x264_10_encoder_open( param );
+ }
+
+ if( !api->x264 ) {
+ x264_encoder_close( (x264_t *) api );
+ return NULL;
+ }
+
+ /* x264_t is opaque */
+ return (x264_t *) api;
+}
+
+void x264_encoder_close( x264_t *h )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ if( api->x264_encoder_close && api->x264 )
+ api->x264_encoder_close( api->x264 );
+
+ free( h );
+}
+
+void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ api->x264_nal_encode( api->x264, dst, nal );
+}
+
+int x264_encoder_reconfig( x264_t *h, x264_param_t *param)
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_reconfig( api->x264, param );
+}
+
+void x264_encoder_parameters( x264_t *h, x264_param_t *param )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ api->x264_encoder_parameters( api->x264, param );
+}
+
+int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_headers( api->x264, pp_nal, pi_nal );
+}
+
+int x264_encoder_encode( x264_t *h, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_encode( api->x264, pp_nal, pi_nal, pic_in, pic_out );
+}
+
+int x264_encoder_delayed_frames( x264_t *h )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_delayed_frames( api->x264 );
+}
+
+int x264_encoder_maximum_delayed_frames( x264_t *h )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_maximum_delayed_frames( api->x264 );
+}
+
+void x264_encoder_intra_refresh( x264_t *h )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ api->x264_encoder_intra_refresh( api->x264 );
+}
+
+int x264_encoder_invalidate_reference( x264_t *h, int64_t pts )
+{
+ x264_api_t *api = (x264_api_t *)h;
+
+ return api->x264_encoder_invalidate_reference( api->x264, pts );
+}
diff --git a/common/common.h b/common/common.h
index d4d94c0..a7d4b41 100644
--- a/common/common.h
+++ b/common/common.h
@@ -27,6 +27,8 @@
#ifndef X264_COMMON_H
#define X264_COMMON_H
+#include "common/bitdepth.h"
+
/****************************************************************************
* Macros
****************************************************************************/
--
2.10.0
More information about the x264-devel
mailing list