diff options
| author | Austin Yuan <shengquan.yuan@intel.com> | 2015-05-20 13:35:55 +0800 |
|---|---|---|
| committer | Austin Yuan <shengquan.yuan@intel.com> | 2015-05-20 13:35:55 +0800 |
| commit | 7d1e1233744f1999201825bbf1f00d8c7001c9b7 (patch) | |
| tree | 648794f6a79ad5ca8da97a377c25f01f6e62d282 /vaenc/va_encode.h | |
libmix-test initial commit
Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
Diffstat (limited to 'vaenc/va_encode.h')
| -rw-r--r-- | vaenc/va_encode.h | 303 |
1 files changed, 303 insertions, 0 deletions
diff --git a/vaenc/va_encode.h b/vaenc/va_encode.h new file mode 100644 index 0000000..11ba3a7 --- /dev/null +++ b/vaenc/va_encode.h @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2007-2013 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chang, Ying<ying.chang@intel.com> + * Lin, Edward <edward.lin@intel.com> + * Liu, Bolun<bolun.liu@intel.com> + * Sun, Jing <jing.a.sun@intel.com> + * Wang, Elaine<elaine.wang@intel.com> + * Yuan, Shengquan<shengquan.yuan@intel.com> + * Zhang, Zhangfei<zhangfei.zhang@intel.com> + */ + +#include "sysdeps.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <assert.h> +#include <va/va.h> +#include "../utils/configrc.h" + +#define MIN(a, b) ((a)>(b)?(b):(a)) +#define MAX(a, b) ((a)>(b)?(a):(b)) + +#define CHECK_VASTATUS(va_status,func) \ + if (va_status != VA_STATUS_SUCCESS) { \ + fprintf(stderr,"%s:%s (%d) failed with %s,exit\n", __func__, func, __LINE__, vaErrorStr(va_status)); \ + exit(1); \ + } + +#define CHECK_VASTATUS_NOEXIT(va_status,func) \ + if (va_status != VA_STATUS_SUCCESS) { \ + fprintf(stderr,"%s:%s (%d) failed with %s,but continue\n", __func__, func, __LINE__, vaErrorStr(va_status)); \ + } + +#define FRAME_P 0 +#define FRAME_B 1 +#define FRAME_I 2 +#define FRAME_IDR 7 + +#define SURFACE_TYPE_VA 1 +#define SURFACE_TYPE_USER_PTR 4 +#define SURFACE_TYPE_GRALLOC 0x00100000 +#define SURFACE_TYPE_GRALLOC_LINEAR 0x00200000 + +#define SURFACE_NUM 16 /* 16 surfaces for source YUV + * 16 surfaces for reference + */ +#define JPEG_SURFACE_NUM 1 /* For 8MP JPEG encoding, 16*8M*1.5B is too large to be allocated */ +#define JPEG_MAX_CODED_BUFFER_SIZE(width, height) ((((((width)+15)/16)*(((height)+15)/16)*1170/4+1024)+0xf)&~0xf) + +#define current_slot (current_frame_display % surface_num) + +#define VAEntrypointMax 11 + +extern VADisplay va_dpy; +extern VAProfile va_profile; +extern char *va_profile_str; +extern char *va_level_str; +extern VAEntrypoint va_entrypoint; +extern VAConfigAttrib config_attrib[VAConfigAttribTypeMax]; +extern unsigned int config_attrib_num; +extern unsigned int surface_num; +extern unsigned int ref_surface_num; +extern unsigned int carc; +extern VASurfaceID src_surface[SURFACE_NUM]; +extern VABufferID coded_buf[SURFACE_NUM]; +extern VASurfaceID ref_surface[SURFACE_NUM]; +extern VAConfigID config_id; +extern VAContextID context_id; + +extern unsigned int frame_width; +extern unsigned int frame_height; +extern unsigned int frame_width_mbaligned; +extern unsigned int frame_height_mbaligned; +extern unsigned int frame_width_aligned; +extern unsigned int frame_height_aligned; +extern unsigned int frame_rate; +extern unsigned int frame_bitrate; +extern unsigned int frame_count; +extern unsigned int frame_coded; +extern unsigned int frame_slice_count; +extern unsigned int frame_slice_height; +extern unsigned int codedbuf_size; +extern double frame_size; +extern unsigned int initial_qp; +extern unsigned int minimal_qp; +extern unsigned int slice_qp; +extern unsigned int intra_period; +extern unsigned int intra_idr_period; +extern unsigned int ip_period; +extern unsigned int rc_mode; + +extern unsigned int vp8_error_resilient; +extern unsigned int kf_auto; +extern unsigned int kf_min_dist; +extern unsigned int kf_max_dist; +extern unsigned int max_frame_size; +extern unsigned int maximum_qp; +extern unsigned int maximum_qp_vp8; +extern unsigned int bit_stuffing_dis; +extern unsigned int write_rec; +extern unsigned int first_frame_width; +extern unsigned int first_frame_height; + +extern unsigned int current_frame_encoding; +extern unsigned int current_frame_display; +extern unsigned int current_IDR_display; +extern unsigned int current_frame_num; +extern unsigned int current_frame_type; + +extern unsigned int misc_priv_type; +extern unsigned int misc_priv_value; + +extern unsigned int surface_type; + +/* h264 specific variables */ +extern unsigned int h264_entropy_mode; /* cabac */ +extern unsigned int h264_8x8_dct; + +extern unsigned int jpeg_quality; + +extern unsigned int encode_syncmode; + +extern unsigned int hrd_buffer_size; + +/* For Adaptive Intra Refresh */ +extern unsigned int enableAIR; +extern unsigned int num_air_mbs; +extern unsigned int airthreshold; +extern unsigned int autotune_air; + +/* For Cyclic Intra Refresh */ +extern unsigned int num_cir_mbs; + +extern unsigned int max_slice_size; + +extern FILE* frame_size_log_fp; + +extern unsigned int ivf_file; +extern unsigned int riff_file; +extern unsigned int correctness_test; +extern unsigned int bitrate_layer0; +extern unsigned int bitrate_layer1; +extern unsigned int bitrate_layer2; +extern unsigned int windows_size; +extern int pm_active; + +int access_statitics(void *p, int encoder_order); +int print_statitics(int frame_number, int width, int height); + +#ifdef ANDROID +#include <va/va_android.h> + +#ifndef __cplusplus +int alloc_gralloc_buffer(int num_buffers, unsigned long *buffers, + int width, int height, int linear); +#endif + +#else +static inline int alloc_gralloc_buffer(int num_buffers, unsigned long *buffers, + int width, int height, int linear) +{ + printf("Shoudnt run into here:%s\n", __func__); + exit(1); +} +#endif + +static inline const char *fourcc_to_string(int fourcc) +{ + switch (fourcc) { + case VA_FOURCC_NV12: + return "NV12"; + case VA_FOURCC_IYUV: + return "IYUV"; + case VA_FOURCC_YV12: + return "YV12"; + case VA_FOURCC_UYVY: + return "UYVY"; + default: + return "Unknown"; + } +} + +static inline int string_to_fourcc(char *str) +{ + int fourcc; + + if (!strncmp(str, "NV12", 4)) + fourcc = VA_FOURCC_NV12; + else if (!strncmp(str, "IYUV", 4)) + fourcc = VA_FOURCC_IYUV; + else if (!strncmp(str, "YV12", 4)) + fourcc = VA_FOURCC_YV12; + else if (!strncmp(str, "UYVY", 4)) + fourcc = VA_FOURCC_UYVY; + else { + printf("Unknow FOURCC\n"); + fourcc = -1; + } + return fourcc; +} + +static inline const char *rc_to_string(int rcmode) +{ + switch (rc_mode) { + case VA_RC_NONE: + return "NONE"; + case VA_RC_CBR: + return "CBR"; + case VA_RC_VBR: + return "VBR"; + case VA_RC_VCM: + return "VCM"; + case VA_RC_CQP: + return "CQP"; + case VA_RC_VBR_CONSTRAINED: + return "VBR_CONSTRAINED"; + default: + return "Unknown"; + } +} + +static inline int get_number(unsigned int numbers[], char *string) +{ + char *endptr = string; + char *nptr = string; + int i = 0; + + while (1) { + numbers[i] = strtol(nptr, &endptr, 0); + + if (numbers[i] ==0 && endptr == nptr) + break; + nptr = endptr + 1; + i++; + } + + return i; +} + +static inline int string_to_rc(char *str) +{ + int rc_mode; + + if (!strncmp(str, "NONE", 4)) + rc_mode = VA_RC_NONE; + else if (!strncmp(str, "CBR", 3)) + rc_mode = VA_RC_CBR; + else if (!strncmp(str, "VBR", 3)) + rc_mode = VA_RC_VBR; + else if (!strncmp(str, "VCM", 3)) + rc_mode = VA_RC_VCM; + else if (!strncmp(str, "CQP", 3)) + rc_mode = VA_RC_CQP; + else if (!strncmp(str, "VBR_CONSTRAINED", 15)) + rc_mode = VA_RC_VBR_CONSTRAINED; + else { + printf("Unknown RC mode\n"); + rc_mode = -1; + } + return rc_mode; +} + +VAStatus create_surfaces(); +VAStatus destroy_surfaces(); +VAStatus get_surface_attrib(); + + +struct codec_table_t { + VAStatus (*get_config)(void); + VAStatus (*render_frame)(unsigned int mask, struct rc_param_t *rc_param); + int (*save_codeddata)(FILE *coded_fp, VACodedBufferSegment *buf_list, VASurfaceID *rec_surfaceid); +}; +extern struct codec_table_t h264_codec; +extern struct codec_table_t mpeg4_codec; +extern struct codec_table_t h263_codec; +extern struct codec_table_t vp8_codec; +extern struct codec_table_t jpeg_codec; +static struct codec_table_t *current_codec = &h264_codec; +extern unsigned int layer_num; |
