This commit is contained in:
Mike Jerris committed 2016-09-26 14:31:51 -04:00
1 parent 2b1f0da5c4
commit 8c5f0301f3
1008 files changed
+110139 -201288

No files matched your search

+71 -101
View File
@@ -33,8 +33,8 @@
#ifndef MINGW_HAS_SECURE_API
// proto from /usr/x86_64-w64-mingw32/include/sec_api/string_s.h
_CRTIMP char *__cdecl strtok_s(char *str, const char *delim, char **context);
#endif /* MINGW_HAS_SECURE_API */
#endif /* __MINGW32__ */
#endif /* MINGW_HAS_SECURE_API */
#endif /* __MINGW32__ */
#ifdef _MSC_VER
#define strdup _strdup
@@ -47,13 +47,11 @@ _CRTIMP char *__cdecl strtok_s(char *str, const char *delim, char **context);
#define MAX_QUANTIZER 63
static const int DEFAULT_SCALE_FACTORS_NUM[VPX_SS_MAX_LAYERS] = {
4, 5, 7, 11, 16
};
static const int DEFAULT_SCALE_FACTORS_NUM[VPX_SS_MAX_LAYERS] = { 4, 5, 7, 11,
16 };
static const int DEFAULT_SCALE_FACTORS_DEN[VPX_SS_MAX_LAYERS] = {
16, 16, 16, 16, 16
};
static const int DEFAULT_SCALE_FACTORS_DEN[VPX_SS_MAX_LAYERS] = { 16, 16, 16,
16, 16 };
typedef enum {
QUANTIZER = 0,
@@ -63,20 +61,17 @@ typedef enum {
ALL_OPTION_TYPES
} LAYER_OPTION_TYPE;
static const int option_max_values[ALL_OPTION_TYPES] = {
63, INT_MAX, INT_MAX, 1
};
static const int option_max_values[ALL_OPTION_TYPES] = { 63, INT_MAX, INT_MAX,
1 };
static const int option_min_values[ALL_OPTION_TYPES] = {
0, 0, 1, 0
};
static const int option_min_values[ALL_OPTION_TYPES] = { 0, 0, 1, 0 };
// One encoded frame
typedef struct FrameData {
void *buf; // compressed data buffer
size_t size; // length of compressed data
vpx_codec_frame_flags_t flags; /**< flags for this frame */
struct FrameData *next;
void *buf; // compressed data buffer
size_t size; // length of compressed data
vpx_codec_frame_flags_t flags; /**< flags for this frame */
struct FrameData *next;
} FrameData;
static SvcInternal_t *get_svc_internal(SvcContext *svc_ctx) {
@@ -91,8 +86,7 @@ static SvcInternal_t *get_svc_internal(SvcContext *svc_ctx) {
return (SvcInternal_t *)svc_ctx->internal;
}
static const SvcInternal_t *get_const_svc_internal(
const SvcContext *svc_ctx) {
static const SvcInternal_t *get_const_svc_internal(const SvcContext *svc_ctx) {
if (svc_ctx == NULL) return NULL;
return (const SvcInternal_t *)svc_ctx->internal;
}
@@ -102,8 +96,8 @@ static void svc_log_reset(SvcContext *svc_ctx) {
si->message_buffer[0] = '\0';
}
static int svc_log(SvcContext *svc_ctx, SVC_LOG_LEVEL level,
const char *fmt, ...) {
static int svc_log(SvcContext *svc_ctx, SVC_LOG_LEVEL level, const char *fmt,
...) {
char buf[512];
int retval = 0;
va_list ap;
@@ -130,14 +124,11 @@ static int svc_log(SvcContext *svc_ctx, SVC_LOG_LEVEL level,
return retval;
}
static vpx_codec_err_t extract_option(LAYER_OPTION_TYPE type,
char *input,
int *value0,
int *value1) {
static vpx_codec_err_t extract_option(LAYER_OPTION_TYPE type, char *input,
int *value0, int *value1) {
if (type == SCALE_FACTOR) {
*value0 = strtol(input, &input, 10);
if (*input++ != '/')
return VPX_CODEC_INVALID_PARAM;
if (*input++ != '/') return VPX_CODEC_INVALID_PARAM;
*value1 = strtol(input, &input, 10);
if (*value0 < option_min_values[SCALE_FACTOR] ||
@@ -148,8 +139,7 @@ static vpx_codec_err_t extract_option(LAYER_OPTION_TYPE type,
return VPX_CODEC_INVALID_PARAM;
} else {
*value0 = atoi(input);
if (*value0 < option_min_values[type] ||
*value0 > option_max_values[type])
if (*value0 < option_min_values[type] || *value0 > option_max_values[type])
return VPX_CODEC_INVALID_PARAM;
}
return VPX_CODEC_OK;
@@ -176,8 +166,7 @@ static vpx_codec_err_t parse_layer_options_from_string(SvcContext *svc_ctx,
for (i = 0; i < svc_ctx->spatial_layers; ++i) {
if (token != NULL) {
res = extract_option(type, token, option0 + i, option1 + i);
if (res != VPX_CODEC_OK)
break;
if (res != VPX_CODEC_OK) break;
token = strtok_r(NULL, delim, &save_ptr);
} else {
break;
@@ -186,7 +175,8 @@ static vpx_codec_err_t parse_layer_options_from_string(SvcContext *svc_ctx,
if (res == VPX_CODEC_OK && i != svc_ctx->spatial_layers) {
svc_log(svc_ctx, SVC_LOG_ERROR,
"svc: layer params type: %d %d values required, "
"but only %d specified\n", type, svc_ctx->spatial_layers, i);
"but only %d specified\n",
type, svc_ctx->spatial_layers, i);
res = VPX_CODEC_INVALID_PARAM;
}
free(input_string);
@@ -233,14 +223,14 @@ static vpx_codec_err_t parse_options(SvcContext *svc_ctx, const char *options) {
si->svc_params.scaling_factor_den);
if (res != VPX_CODEC_OK) break;
} else if (strcmp("max-quantizers", option_name) == 0) {
res = parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
si->svc_params.max_quantizers,
NULL);
res =
parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
si->svc_params.max_quantizers, NULL);
if (res != VPX_CODEC_OK) break;
} else if (strcmp("min-quantizers", option_name) == 0) {
res = parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
si->svc_params.min_quantizers,
NULL);
res =
parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
si->svc_params.min_quantizers, NULL);
if (res != VPX_CODEC_OK) break;
} else if (strcmp("auto-alt-refs", option_name) == 0) {
res = parse_layer_options_from_string(svc_ctx, AUTO_ALT_REF, option_value,
@@ -287,8 +277,7 @@ static vpx_codec_err_t parse_options(SvcContext *svc_ctx, const char *options) {
return res;
}
vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx,
const char *options) {
vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options) {
SvcInternal_t *const si = get_svc_internal(svc_ctx);
if (svc_ctx == NULL || options == NULL || si == NULL) {
return VPX_CODEC_INVALID_PARAM;
@@ -308,34 +297,34 @@ void assign_layer_bitrates(const SvcContext *svc_ctx,
if (si->bitrates[0] != 0) {
enc_cfg->rc_target_bitrate = 0;
for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
enc_cfg->ss_target_bitrate[sl*svc_ctx->temporal_layers] = 0;
enc_cfg->ss_target_bitrate[sl * svc_ctx->temporal_layers] = 0;
for (tl = 0; tl < svc_ctx->temporal_layers; ++tl) {
enc_cfg->ss_target_bitrate[sl*svc_ctx->temporal_layers]
+= (unsigned int)si->bitrates[sl * svc_ctx->temporal_layers + tl];
enc_cfg->layer_target_bitrate[sl*svc_ctx->temporal_layers + tl]
= si->bitrates[sl * svc_ctx->temporal_layers + tl];
enc_cfg->ss_target_bitrate[sl * svc_ctx->temporal_layers] +=
(unsigned int)si->bitrates[sl * svc_ctx->temporal_layers + tl];
enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + tl] =
si->bitrates[sl * svc_ctx->temporal_layers + tl];
}
}
} else {
float total = 0;
float alloc_ratio[VPX_MAX_LAYERS] = {0};
float alloc_ratio[VPX_MAX_LAYERS] = { 0 };
for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
if (si->svc_params.scaling_factor_den[sl] > 0) {
alloc_ratio[sl] = (float)( (sl+1) );
alloc_ratio[sl] = (float)(pow(2, sl));
total += alloc_ratio[sl];
}
}
for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
enc_cfg->ss_target_bitrate[sl] = spatial_layer_target =
(unsigned int)(enc_cfg->rc_target_bitrate *
alloc_ratio[sl] / total);
(unsigned int)(enc_cfg->rc_target_bitrate * alloc_ratio[sl] /
total);
if (svc_ctx->temporal_layering_mode == 3) {
enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers] =
(spatial_layer_target*6)/10; // 60%
(spatial_layer_target * 6) / 10; // 60%
enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + 1] =
(spatial_layer_target*8)/10; // 80%
(spatial_layer_target * 8) / 10; // 80%
enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + 2] =
spatial_layer_target;
} else if (svc_ctx->temporal_layering_mode == 2 ||
@@ -359,7 +348,7 @@ void assign_layer_bitrates(const SvcContext *svc_ctx,
}
} else {
float total = 0;
float alloc_ratio[VPX_MAX_LAYERS] = {0};
float alloc_ratio[VPX_MAX_LAYERS] = { 0 };
for (i = 0; i < svc_ctx->spatial_layers; ++i) {
if (si->svc_params.scaling_factor_den[i] > 0) {
@@ -372,8 +361,9 @@ void assign_layer_bitrates(const SvcContext *svc_ctx,
}
for (i = 0; i < VPX_SS_MAX_LAYERS; ++i) {
if (total > 0) {
enc_cfg->layer_target_bitrate[i] = (unsigned int)
(enc_cfg->rc_target_bitrate * alloc_ratio[i] / total);
enc_cfg->layer_target_bitrate[i] =
(unsigned int)(enc_cfg->rc_target_bitrate * alloc_ratio[i] /
total);
}
}
}
@@ -384,7 +374,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
vpx_codec_iface_t *iface,
vpx_codec_enc_cfg_t *enc_cfg) {
vpx_codec_err_t res;
int i, sl , tl;
int i, sl, tl;
SvcInternal_t *const si = get_svc_internal(svc_ctx);
if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL ||
enc_cfg == NULL) {
@@ -397,13 +387,6 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
si->width = enc_cfg->g_w;
si->height = enc_cfg->g_h;
// wonkap: why is this necessary?
/*if (enc_cfg->kf_max_dist < 2) {
svc_log(svc_ctx, SVC_LOG_ERROR, "key frame distance too small: %d\n",
enc_cfg->kf_max_dist);
return VPX_CODEC_INVALID_PARAM;
}*/
si->kf_dist = enc_cfg->kf_max_dist;
if (svc_ctx->spatial_layers == 0)
@@ -427,7 +410,9 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
for (sl = 0; sl < VPX_SS_MAX_LAYERS; ++sl) {
si->svc_params.scaling_factor_num[sl] = DEFAULT_SCALE_FACTORS_NUM[sl];
si->svc_params.scaling_factor_den[sl] = DEFAULT_SCALE_FACTORS_DEN[sl];
si->svc_params.speed_per_layer[sl] = svc_ctx->speed;
}
for (tl = 0; tl < svc_ctx->temporal_layers; ++tl) {
for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
i = sl * svc_ctx->temporal_layers + tl;
@@ -441,23 +426,21 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
res = parse_options(svc_ctx, si->options);
if (res != VPX_CODEC_OK) return res;
if (svc_ctx->spatial_layers < 1)
svc_ctx->spatial_layers = 1;
if (svc_ctx->spatial_layers < 1) svc_ctx->spatial_layers = 1;
if (svc_ctx->spatial_layers > VPX_SS_MAX_LAYERS)
svc_ctx->spatial_layers = VPX_SS_MAX_LAYERS;
if (svc_ctx->temporal_layers < 1)
svc_ctx->temporal_layers = 1;
if (svc_ctx->temporal_layers < 1) svc_ctx->temporal_layers = 1;
if (svc_ctx->temporal_layers > VPX_TS_MAX_LAYERS)
svc_ctx->temporal_layers = VPX_TS_MAX_LAYERS;
if (svc_ctx->temporal_layers * svc_ctx->spatial_layers > VPX_MAX_LAYERS) {
svc_log(svc_ctx, SVC_LOG_ERROR,
"spatial layers * temporal layers exceeds the maximum number of "
"allowed layers of %d\n",
svc_ctx->spatial_layers * svc_ctx->temporal_layers,
(int) VPX_MAX_LAYERS);
return VPX_CODEC_INVALID_PARAM;
svc_log(svc_ctx, SVC_LOG_ERROR,
"spatial layers * temporal layers exceeds the maximum number of "
"allowed layers of %d\n",
svc_ctx->spatial_layers * svc_ctx->temporal_layers,
(int)VPX_MAX_LAYERS);
return VPX_CODEC_INVALID_PARAM;
}
assign_layer_bitrates(svc_ctx, enc_cfg);
@@ -469,14 +452,13 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
if (svc_ctx->temporal_layers > 1) {
int i;
for (i = 0; i < svc_ctx->temporal_layers; ++i) {
enc_cfg->ts_target_bitrate[i] = enc_cfg->rc_target_bitrate /
svc_ctx->temporal_layers;
enc_cfg->ts_target_bitrate[i] =
enc_cfg->rc_target_bitrate / svc_ctx->temporal_layers;
enc_cfg->ts_rate_decimator[i] = 1 << (svc_ctx->temporal_layers - 1 - i);
}
}
if (svc_ctx->threads)
enc_cfg->g_threads = svc_ctx->threads;
if (svc_ctx->threads) enc_cfg->g_threads = svc_ctx->threads;
// Modify encoder configuration
enc_cfg->ss_number_layers = svc_ctx->spatial_layers;
@@ -514,10 +496,8 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
* Encode a frame into multiple layers
* Create a superframe containing the individual layers
*/
vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx,
vpx_codec_ctx_t *codec_ctx,
struct vpx_image *rawimg,
vpx_codec_pts_t pts,
vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
struct vpx_image *rawimg, vpx_codec_pts_t pts,
int64_t duration, int deadline) {
vpx_codec_err_t res;
vpx_codec_iter_t iter;
@@ -529,8 +509,8 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx,
svc_log_reset(svc_ctx);
res = vpx_codec_encode(codec_ctx, rawimg, pts, (uint32_t)duration, 0,
deadline);
res =
vpx_codec_encode(codec_ctx, rawimg, pts, (uint32_t)duration, 0, deadline);
if (res != VPX_CODEC_OK) {
return res;
}
@@ -547,23 +527,20 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx,
svc_log(svc_ctx, SVC_LOG_DEBUG,
"SVC frame: %d, layer: %d, PSNR(Total/Y/U/V): "
"%2.3f %2.3f %2.3f %2.3f \n",
si->psnr_pkt_received, i,
cx_pkt->data.layer_psnr[i].psnr[0],
si->psnr_pkt_received, i, cx_pkt->data.layer_psnr[i].psnr[0],
cx_pkt->data.layer_psnr[i].psnr[1],
cx_pkt->data.layer_psnr[i].psnr[2],
cx_pkt->data.layer_psnr[i].psnr[3]);
svc_log(svc_ctx, SVC_LOG_DEBUG,
"SVC frame: %d, layer: %d, SSE(Total/Y/U/V): "
"%2.3f %2.3f %2.3f %2.3f \n",
si->psnr_pkt_received, i,
cx_pkt->data.layer_psnr[i].sse[0],
si->psnr_pkt_received, i, cx_pkt->data.layer_psnr[i].sse[0],
cx_pkt->data.layer_psnr[i].sse[1],
cx_pkt->data.layer_psnr[i].sse[2],
cx_pkt->data.layer_psnr[i].sse[3]);
for (j = 0; j < COMPONENTS; ++j) {
si->psnr_sum[i][j] +=
cx_pkt->data.layer_psnr[i].psnr[j];
si->psnr_sum[i][j] += cx_pkt->data.layer_psnr[i].psnr[j];
si->sse_sum[i][j] += cx_pkt->data.layer_psnr[i].sse[j];
}
}
@@ -578,30 +555,25 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx,
}
#endif
#endif
case VPX_CODEC_PSNR_PKT:
{
case VPX_CODEC_PSNR_PKT: {
#if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
int j;
svc_log(svc_ctx, SVC_LOG_DEBUG,
"frame: %d, layer: %d, PSNR(Total/Y/U/V): "
"%2.3f %2.3f %2.3f %2.3f \n",
si->psnr_pkt_received, 0,
cx_pkt->data.layer_psnr[0].psnr[0],
si->psnr_pkt_received, 0, cx_pkt->data.layer_psnr[0].psnr[0],
cx_pkt->data.layer_psnr[0].psnr[1],
cx_pkt->data.layer_psnr[0].psnr[2],
cx_pkt->data.layer_psnr[0].psnr[3]);
for (j = 0; j < COMPONENTS; ++j) {
si->psnr_sum[0][j] +=
cx_pkt->data.layer_psnr[0].psnr[j];
si->psnr_sum[0][j] += cx_pkt->data.layer_psnr[0].psnr[j];
si->sse_sum[0][j] += cx_pkt->data.layer_psnr[0].sse[j];
}
#endif
}
++si->psnr_pkt_received;
break;
default: {
++si->psnr_pkt_received;
break;
}
default: { break; }
}
}
@@ -639,7 +611,6 @@ const char *vpx_svc_dump_statistics(SvcContext *svc_ctx) {
svc_log(svc_ctx, SVC_LOG_INFO, "\n");
for (i = 0; i < svc_ctx->spatial_layers; ++i) {
svc_log(svc_ctx, SVC_LOG_INFO,
"Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u]\n",
i, (double)si->psnr_sum[i][0] / number_of_frames,
@@ -690,4 +661,3 @@ void vpx_svc_release(SvcContext *svc_ctx) {
svc_ctx->internal = NULL;
}
}
+21 -46
View File
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*!\file
* \brief Provides the high level interface to wrap decoder algorithms.
*
@@ -19,67 +18,50 @@
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_version.h"
#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
#define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
int vpx_codec_version(void) {
return VERSION_PACKED;
}
int vpx_codec_version(void) { return VERSION_PACKED; }
const char *vpx_codec_version_str(void) { return VERSION_STRING_NOSP; }
const char *vpx_codec_version_str(void) {
return VERSION_STRING_NOSP;
}
const char *vpx_codec_version_extra_str(void) {
return VERSION_EXTRA;
}
const char *vpx_codec_version_extra_str(void) { return VERSION_EXTRA; }
const char *vpx_codec_iface_name(vpx_codec_iface_t *iface) {
return iface ? iface->name : "<invalid interface>";
}
const char *vpx_codec_err_to_string(vpx_codec_err_t err) {
const char *vpx_codec_err_to_string(vpx_codec_err_t err) {
switch (err) {
case VPX_CODEC_OK:
return "Success";
case VPX_CODEC_ERROR:
return "Unspecified internal error";
case VPX_CODEC_MEM_ERROR:
return "Memory allocation error";
case VPX_CODEC_ABI_MISMATCH:
return "ABI version mismatch";
case VPX_CODEC_OK: return "Success";
case VPX_CODEC_ERROR: return "Unspecified internal error";
case VPX_CODEC_MEM_ERROR: return "Memory allocation error";
case VPX_CODEC_ABI_MISMATCH: return "ABI version mismatch";
case VPX_CODEC_INCAPABLE:
return "Codec does not implement requested capability";
case VPX_CODEC_UNSUP_BITSTREAM:
return "Bitstream not supported by this decoder";
case VPX_CODEC_UNSUP_FEATURE:
return "Bitstream required feature not supported by this decoder";
case VPX_CODEC_CORRUPT_FRAME:
return "Corrupt frame detected";
case VPX_CODEC_INVALID_PARAM:
return "Invalid parameter";
case VPX_CODEC_LIST_END:
return "End of iterated list";
case VPX_CODEC_CORRUPT_FRAME: return "Corrupt frame detected";
case VPX_CODEC_INVALID_PARAM: return "Invalid parameter";
case VPX_CODEC_LIST_END: return "End of iterated list";
}
return "Unrecognized error code";
}
const char *vpx_codec_error(vpx_codec_ctx_t *ctx) {
const char *vpx_codec_error(vpx_codec_ctx_t *ctx) {
return (ctx) ? vpx_codec_err_to_string(ctx->err)
: vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM);
: vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM);
}
const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx) {
const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx) {
if (ctx && ctx->err)
return ctx->priv ? ctx->priv->err_detail : ctx->err_detail;
return NULL;
}
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) {
vpx_codec_err_t res;
@@ -99,15 +81,11 @@ vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) {
return SAVE_STATUS(ctx, res);
}
vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface) {
return (iface) ? iface->caps : 0;
}
vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx,
int ctrl_id,
...) {
vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...) {
vpx_codec_err_t res;
if (!ctx || !ctrl_id)
@@ -117,11 +95,11 @@ vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx,
else {
vpx_codec_ctrl_fn_map_t *entry;
res = VPX_CODEC_ERROR;
res = VPX_CODEC_INCAPABLE;
for (entry = ctx->iface->ctrl_maps; entry && entry->fn; entry++) {
if (!entry->ctrl_id || entry->ctrl_id == ctrl_id) {
va_list ap;
va_list ap;
va_start(ap, ctrl_id);
res = entry->fn((vpx_codec_alg_priv_t *)ctx->priv, ap);
@@ -135,16 +113,14 @@ vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx,
}
void vpx_internal_error(struct vpx_internal_error_info *info,
vpx_codec_err_t error,
const char *fmt,
...) {
vpx_codec_err_t error, const char *fmt, ...) {
va_list ap;
info->error_code = error;
info->has_detail = 0;
if (fmt) {
size_t sz = sizeof(info->detail);
size_t sz = sizeof(info->detail);
info->has_detail = 1;
va_start(ap, fmt);
@@ -153,6 +129,5 @@ void vpx_internal_error(struct vpx_internal_error_info *info,
info->detail[sz - 1] = '\0';
}
if (info->setjmp)
longjmp(info->jmp, info->error_code);
if (info->setjmp) longjmp(info->jmp, info->error_code);
}
+26 -35
View File
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*!\file
* \brief Provides the high level interface to wrap decoder algorithms.
*
@@ -16,17 +15,16 @@
#include <string.h>
#include "vpx/internal/vpx_codec_internal.h"
#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
#define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
return (vpx_codec_alg_priv_t *)ctx->priv;
}
vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
vpx_codec_iface_t *iface,
vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
vpx_codec_iface_t *iface,
const vpx_codec_dec_cfg_t *cfg,
vpx_codec_flags_t flags,
int ver) {
vpx_codec_flags_t flags, int ver) {
vpx_codec_err_t res;
if (ver != VPX_DECODER_ABI_VERSION)
@@ -35,7 +33,8 @@ vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
res = VPX_CODEC_INVALID_PARAM;
else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION)
res = VPX_CODEC_ABI_MISMATCH;
else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_POSTPROC))
else if ((flags & VPX_CODEC_USE_POSTPROC) &&
!(iface->caps & VPX_CODEC_CAP_POSTPROC))
res = VPX_CODEC_INCAPABLE;
else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) &&
!(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT))
@@ -63,15 +62,14 @@ vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
const uint8_t *data,
unsigned int data_sz,
vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
const uint8_t *data,
unsigned int data_sz,
vpx_codec_stream_info_t *si) {
vpx_codec_err_t res;
if (!iface || !data || !data_sz || !si
|| si->sz < sizeof(vpx_codec_stream_info_t))
if (!iface || !data || !data_sz || !si ||
si->sz < sizeof(vpx_codec_stream_info_t))
res = VPX_CODEC_INVALID_PARAM;
else {
/* Set default/unknown values */
@@ -84,8 +82,7 @@ vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
return res;
}
vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
vpx_codec_stream_info_t *si) {
vpx_codec_err_t res;
@@ -104,12 +101,9 @@ vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
const uint8_t *data,
unsigned int data_sz,
void *user_priv,
long deadline) {
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data,
unsigned int data_sz, void *user_priv,
long deadline) {
vpx_codec_err_t res;
/* Sanity checks */
@@ -126,8 +120,7 @@ vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
vpx_codec_iter_t *iter) {
vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter) {
vpx_image_t *img;
if (!ctx || !iter || !ctx->iface || !ctx->priv)
@@ -138,16 +131,15 @@ vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
return img;
}
vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
vpx_codec_put_frame_cb_fn_t cb,
void *user_priv) {
vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
vpx_codec_put_frame_cb_fn_t cb,
void *user_priv) {
vpx_codec_err_t res;
if (!ctx || !cb)
res = VPX_CODEC_INVALID_PARAM;
else if (!ctx->iface || !ctx->priv
|| !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
else if (!ctx->iface || !ctx->priv ||
!(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
res = VPX_CODEC_ERROR;
else {
ctx->priv->dec.put_frame_cb.u.put_frame = cb;
@@ -158,16 +150,15 @@ vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx
return SAVE_STATUS(ctx, res);
}
vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
vpx_codec_put_slice_cb_fn_t cb,
void *user_priv) {
vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
vpx_codec_put_slice_cb_fn_t cb,
void *user_priv) {
vpx_codec_err_t res;
if (!ctx || !cb)
res = VPX_CODEC_INVALID_PARAM;
else if (!ctx->iface || !ctx->priv
|| !(ctx->iface->caps & VPX_CODEC_CAP_PUT_SLICE))
else if (!ctx->iface || !ctx->priv ||
!(ctx->iface->caps & VPX_CODEC_CAP_PUT_SLICE))
res = VPX_CODEC_ERROR;
else {
ctx->priv->dec.put_slice_cb.u.put_slice = cb;
+48 -70
View File
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*!\file
* \brief Provides the high level interface to wrap encoder algorithms.
*
@@ -18,17 +17,16 @@
#include "vpx_config.h"
#include "vpx/internal/vpx_codec_internal.h"
#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
#define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
return (vpx_codec_alg_priv_t *)ctx->priv;
}
vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
vpx_codec_iface_t *iface,
vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
vpx_codec_iface_t *iface,
const vpx_codec_enc_cfg_t *cfg,
vpx_codec_flags_t flags,
int ver) {
vpx_codec_flags_t flags, int ver) {
vpx_codec_err_t res;
if (ver != VPX_ENCODER_ABI_VERSION)
@@ -39,11 +37,10 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
res = VPX_CODEC_ABI_MISMATCH;
else if (!(iface->caps & VPX_CODEC_CAP_ENCODER))
res = VPX_CODEC_INCAPABLE;
else if ((flags & VPX_CODEC_USE_PSNR)
&& !(iface->caps & VPX_CODEC_CAP_PSNR))
else if ((flags & VPX_CODEC_USE_PSNR) && !(iface->caps & VPX_CODEC_CAP_PSNR))
res = VPX_CODEC_INCAPABLE;
else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION)
&& !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION))
else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) &&
!(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION))
res = VPX_CODEC_INCAPABLE;
else {
ctx->iface = iface;
@@ -62,13 +59,9 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
vpx_codec_iface_t *iface,
vpx_codec_enc_cfg_t *cfg,
int num_enc,
vpx_codec_flags_t flags,
vpx_rational_t *dsf,
int ver) {
vpx_codec_err_t vpx_codec_enc_init_multi_ver(
vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg,
int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver) {
vpx_codec_err_t res = VPX_CODEC_OK;
if (ver != VPX_ENCODER_ABI_VERSION)
@@ -79,11 +72,10 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
res = VPX_CODEC_ABI_MISMATCH;
else if (!(iface->caps & VPX_CODEC_CAP_ENCODER))
res = VPX_CODEC_INCAPABLE;
else if ((flags & VPX_CODEC_USE_PSNR)
&& !(iface->caps & VPX_CODEC_CAP_PSNR))
else if ((flags & VPX_CODEC_USE_PSNR) && !(iface->caps & VPX_CODEC_CAP_PSNR))
res = VPX_CODEC_INCAPABLE;
else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION)
&& !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION))
else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) &&
!(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION))
res = VPX_CODEC_INCAPABLE;
else {
int i;
@@ -110,8 +102,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
* resolution always use the same frame_type chosen by the
* lowest-resolution encoder.
*/
if (mr_cfg.mr_encoder_id)
cfg->kf_mode = VPX_KF_DISABLED;
if (mr_cfg.mr_encoder_id) cfg->kf_mode = VPX_KF_DISABLED;
ctx->iface = iface;
ctx->name = iface->name;
@@ -121,8 +112,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
res = ctx->iface->init(ctx, &mr_cfg);
if (res) {
const char *error_detail =
ctx->priv ? ctx->priv->err_detail : NULL;
const char *error_detail = ctx->priv ? ctx->priv->err_detail : NULL;
/* Destroy current ctx */
ctx->err_detail = error_detail;
vpx_codec_destroy(ctx);
@@ -136,8 +126,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
}
}
if (res)
break;
if (res) break;
ctx++;
cfg++;
@@ -150,10 +139,9 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
vpx_codec_enc_cfg_t *cfg,
unsigned int usage) {
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
vpx_codec_enc_cfg_t *cfg,
unsigned int usage) {
vpx_codec_err_t res;
vpx_codec_enc_cfg_map_t *map;
int i;
@@ -179,30 +167,28 @@ vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
return res;
}
#if ARCH_X86 || ARCH_X86_64
/* On X86, disable the x87 unit's internal 80 bit precision for better
* consistency with the SSE unit's 64 bit precision.
*/
#include "vpx_ports/x86.h"
#define FLOATING_POINT_INIT() do {\
#define FLOATING_POINT_INIT() \
do { \
unsigned short x87_orig_mode = x87_set_double_precision();
#define FLOATING_POINT_RESTORE() \
x87_set_control_word(x87_orig_mode); }while(0)
#define FLOATING_POINT_RESTORE() \
x87_set_control_word(x87_orig_mode); \
} \
while (0)
#else
static void FLOATING_POINT_INIT() {}
static void FLOATING_POINT_RESTORE() {}
#endif
vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
const vpx_image_t *img,
vpx_codec_pts_t pts,
unsigned long duration,
vpx_enc_frame_flags_t flags,
unsigned long deadline) {
vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
vpx_codec_pts_t pts, unsigned long duration,
vpx_enc_frame_flags_t flags,
unsigned long deadline) {
vpx_codec_err_t res = VPX_CODEC_OK;
if (!ctx || (img && !duration))
@@ -220,8 +206,8 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
FLOATING_POINT_INIT();
if (num_enc == 1)
res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts,
duration, flags, deadline);
res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts, duration, flags,
deadline);
else {
/* Multi-resolution encoding:
* Encode multi-levels in reverse order. For example,
@@ -234,8 +220,8 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
if (img) img += num_enc - 1;
for (i = num_enc - 1; i >= 0; i--) {
if ((res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts,
duration, flags, deadline)))
if ((res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts, duration,
flags, deadline)))
break;
ctx--;
@@ -250,7 +236,6 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
vpx_codec_iter_t *iter) {
const vpx_codec_cx_pkt_t *pkt = NULL;
@@ -273,18 +258,18 @@ const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
vpx_codec_priv_t *const priv = ctx->priv;
char *const dst_buf = (char *)priv->enc.cx_data_dst_buf.buf;
if (dst_buf &&
pkt->data.raw.buf != dst_buf &&
if (dst_buf && pkt->data.raw.buf != dst_buf &&
pkt->data.raw.sz + priv->enc.cx_data_pad_before +
priv->enc.cx_data_pad_after <= priv->enc.cx_data_dst_buf.sz) {
priv->enc.cx_data_pad_after <=
priv->enc.cx_data_dst_buf.sz) {
vpx_codec_cx_pkt_t *modified_pkt = &priv->enc.cx_data_pkt;
memcpy(dst_buf + priv->enc.cx_data_pad_before, pkt->data.raw.buf,
pkt->data.raw.sz);
*modified_pkt = *pkt;
modified_pkt->data.raw.buf = dst_buf;
modified_pkt->data.raw.sz += priv->enc.cx_data_pad_before +
priv->enc.cx_data_pad_after;
modified_pkt->data.raw.sz +=
priv->enc.cx_data_pad_before + priv->enc.cx_data_pad_after;
pkt = modified_pkt;
}
@@ -297,13 +282,11 @@ const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
return pkt;
}
vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
const vpx_fixed_buf_t *buf,
unsigned int pad_before,
unsigned int pad_after) {
if (!ctx || !ctx->priv)
return VPX_CODEC_INVALID_PARAM;
unsigned int pad_before,
unsigned int pad_after) {
if (!ctx || !ctx->priv) return VPX_CODEC_INVALID_PARAM;
if (buf) {
ctx->priv->enc.cx_data_dst_buf = *buf;
@@ -319,8 +302,7 @@ vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
return VPX_CODEC_OK;
}
const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx) {
const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx) {
vpx_image_t *img = NULL;
if (ctx) {
@@ -337,8 +319,7 @@ const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx) {
return img;
}
vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) {
vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) {
vpx_fixed_buf_t *buf = NULL;
if (ctx) {
@@ -355,9 +336,8 @@ vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) {
return buf;
}
vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
const vpx_codec_enc_cfg_t *cfg) {
vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
const vpx_codec_enc_cfg_t *cfg) {
vpx_codec_err_t res;
if (!ctx || !ctx->iface || !ctx->priv || !cfg)
@@ -370,7 +350,6 @@ vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list,
const struct vpx_codec_cx_pkt *pkt) {
if (list->cnt < list->max) {
@@ -381,9 +360,8 @@ int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list,
return 1;
}
const vpx_codec_cx_pkt_t *vpx_codec_pkt_list_get(struct vpx_codec_pkt_list *list,
vpx_codec_iter_t *iter) {
const vpx_codec_cx_pkt_t *vpx_codec_pkt_list_get(
struct vpx_codec_pkt_list *list, vpx_codec_iter_t *iter) {
const vpx_codec_cx_pkt_t *pkt;
if (!(*iter)) {
+47 -93
View File
@@ -15,10 +15,8 @@
#include "vpx/vpx_integer.h"
#include "vpx_mem/vpx_mem.h"
static vpx_image_t *img_alloc_helper(vpx_image_t *img,
vpx_img_fmt_t fmt,
unsigned int d_w,
unsigned int d_h,
static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt,
unsigned int d_w, unsigned int d_h,
unsigned int buf_align,
unsigned int stride_align,
unsigned char *img_data) {
@@ -27,68 +25,44 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
int align;
/* Treat align==0 like align==1 */
if (!buf_align)
buf_align = 1;
if (!buf_align) buf_align = 1;
/* Validate alignment (must be power of 2) */
if (buf_align & (buf_align - 1))
goto fail;
if (buf_align & (buf_align - 1)) goto fail;
/* Treat align==0 like align==1 */
if (!stride_align)
stride_align = 1;
if (!stride_align) stride_align = 1;
/* Validate alignment (must be power of 2) */
if (stride_align & (stride_align - 1))
goto fail;
if (stride_align & (stride_align - 1)) goto fail;
/* Get sample size for this format */
switch (fmt) {
case VPX_IMG_FMT_RGB32:
case VPX_IMG_FMT_RGB32_LE:
case VPX_IMG_FMT_ARGB:
case VPX_IMG_FMT_ARGB_LE:
bps = 32;
break;
case VPX_IMG_FMT_ARGB_LE: bps = 32; break;
case VPX_IMG_FMT_RGB24:
case VPX_IMG_FMT_BGR24:
bps = 24;
break;
case VPX_IMG_FMT_BGR24: bps = 24; break;
case VPX_IMG_FMT_RGB565:
case VPX_IMG_FMT_RGB565_LE:
case VPX_IMG_FMT_RGB555:
case VPX_IMG_FMT_RGB555_LE:
case VPX_IMG_FMT_UYVY:
case VPX_IMG_FMT_YUY2:
case VPX_IMG_FMT_YVYU:
bps = 16;
break;
case VPX_IMG_FMT_YVYU: bps = 16; break;
case VPX_IMG_FMT_I420:
case VPX_IMG_FMT_YV12:
case VPX_IMG_FMT_VPXI420:
case VPX_IMG_FMT_VPXYV12:
bps = 12;
break;
case VPX_IMG_FMT_VPXYV12: bps = 12; break;
case VPX_IMG_FMT_I422:
case VPX_IMG_FMT_I440:
bps = 16;
break;
case VPX_IMG_FMT_I444:
bps = 24;
break;
case VPX_IMG_FMT_I42016:
bps = 24;
break;
case VPX_IMG_FMT_I440: bps = 16; break;
case VPX_IMG_FMT_I444: bps = 24; break;
case VPX_IMG_FMT_I42016: bps = 24; break;
case VPX_IMG_FMT_I42216:
case VPX_IMG_FMT_I44016:
bps = 32;
break;
case VPX_IMG_FMT_I44416:
bps = 48;
break;
default:
bps = 16;
break;
case VPX_IMG_FMT_I44016: bps = 32; break;
case VPX_IMG_FMT_I44416: bps = 48; break;
default: bps = 16; break;
}
/* Get chroma shift values for this format */
@@ -99,12 +73,8 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
case VPX_IMG_FMT_VPXYV12:
case VPX_IMG_FMT_I422:
case VPX_IMG_FMT_I42016:
case VPX_IMG_FMT_I42216:
xcs = 1;
break;
default:
xcs = 0;
break;
case VPX_IMG_FMT_I42216: xcs = 1; break;
default: xcs = 0; break;
}
switch (fmt) {
@@ -114,12 +84,8 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
case VPX_IMG_FMT_VPXI420:
case VPX_IMG_FMT_VPXYV12:
case VPX_IMG_FMT_I42016:
case VPX_IMG_FMT_I44016:
ycs = 1;
break;
default:
ycs = 0;
break;
case VPX_IMG_FMT_I44016: ycs = 1; break;
default: ycs = 0; break;
}
/* Calculate storage sizes given the chroma subsampling */
@@ -135,8 +101,7 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
if (!img) {
img = (vpx_image_t *)calloc(1, sizeof(vpx_image_t));
if (!img)
goto fail;
if (!img) goto fail;
img->self_allocd = 1;
} else {
@@ -146,18 +111,17 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
img->img_data = img_data;
if (!img_data) {
const uint64_t alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ?
(uint64_t)h * s * bps / 8 : (uint64_t)h * s;
const uint64_t alloc_size = (fmt & VPX_IMG_FMT_PLANAR)
? (uint64_t)h * s * bps / 8
: (uint64_t)h * s;
if (alloc_size != (size_t)alloc_size)
goto fail;
if (alloc_size != (size_t)alloc_size) goto fail;
img->img_data = (uint8_t *)vpx_memalign(buf_align, (size_t)alloc_size);
img->img_data_owner = 1;
}
if (!img->img_data)
goto fail;
if (!img->img_data) goto fail;
img->fmt = fmt;
img->bit_depth = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 16 : 8;
@@ -172,39 +136,30 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = stride_in_bytes >> xcs;
/* Default viewport to entire image */
if (!vpx_img_set_rect(img, 0, 0, d_w, d_h))
return img;
if (!vpx_img_set_rect(img, 0, 0, d_w, d_h)) return img;
fail:
vpx_img_free(img);
return NULL;
}
vpx_image_t *vpx_img_alloc(vpx_image_t *img,
vpx_img_fmt_t fmt,
unsigned int d_w,
unsigned int d_h,
unsigned int align) {
vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt,
unsigned int d_w, unsigned int d_h,
unsigned int align) {
return img_alloc_helper(img, fmt, d_w, d_h, align, align, NULL);
}
vpx_image_t *vpx_img_wrap(vpx_image_t *img,
vpx_img_fmt_t fmt,
unsigned int d_w,
unsigned int d_h,
unsigned int stride_align,
unsigned char *img_data) {
vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w,
unsigned int d_h, unsigned int stride_align,
unsigned char *img_data) {
/* By setting buf_align = 1, we don't change buffer alignment in this
* function. */
return img_alloc_helper(img, fmt, d_w, d_h, 1, stride_align, img_data);
}
int vpx_img_set_rect(vpx_image_t *img,
unsigned int x,
unsigned int y,
unsigned int w,
unsigned int h) {
unsigned char *data;
int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y,
unsigned int w, unsigned int h) {
unsigned char *data;
if (x + w <= img->w && y + h <= img->h) {
img->d_w = w;
@@ -213,7 +168,7 @@ int vpx_img_set_rect(vpx_image_t *img,
/* Calculate plane pointers */
if (!(img->fmt & VPX_IMG_FMT_PLANAR)) {
img->planes[VPX_PLANE_PACKED] =
img->img_data + x * img->bps / 8 + y * img->stride[VPX_PLANE_PACKED];
img->img_data + x * img->bps / 8 + y * img->stride[VPX_PLANE_PACKED];
} else {
const int bytes_per_sample =
(img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
@@ -225,8 +180,8 @@ int vpx_img_set_rect(vpx_image_t *img,
data += img->h * img->stride[VPX_PLANE_ALPHA];
}
img->planes[VPX_PLANE_Y] = data + x * bytes_per_sample +
y * img->stride[VPX_PLANE_Y];
img->planes[VPX_PLANE_Y] =
data + x * bytes_per_sample + y * img->stride[VPX_PLANE_Y];
data += img->h * img->stride[VPX_PLANE_Y];
if (!(img->fmt & VPX_IMG_FMT_UV_FLIP)) {
@@ -262,24 +217,23 @@ void vpx_img_flip(vpx_image_t *img) {
img->planes[VPX_PLANE_Y] += (signed)(img->d_h - 1) * img->stride[VPX_PLANE_Y];
img->stride[VPX_PLANE_Y] = -img->stride[VPX_PLANE_Y];
img->planes[VPX_PLANE_U] += (signed)((img->d_h >> img->y_chroma_shift) - 1)
* img->stride[VPX_PLANE_U];
img->planes[VPX_PLANE_U] += (signed)((img->d_h >> img->y_chroma_shift) - 1) *
img->stride[VPX_PLANE_U];
img->stride[VPX_PLANE_U] = -img->stride[VPX_PLANE_U];
img->planes[VPX_PLANE_V] += (signed)((img->d_h >> img->y_chroma_shift) - 1)
* img->stride[VPX_PLANE_V];
img->planes[VPX_PLANE_V] += (signed)((img->d_h >> img->y_chroma_shift) - 1) *
img->stride[VPX_PLANE_V];
img->stride[VPX_PLANE_V] = -img->stride[VPX_PLANE_V];
img->planes[VPX_PLANE_ALPHA] += (signed)(img->d_h - 1) * img->stride[VPX_PLANE_ALPHA];
img->planes[VPX_PLANE_ALPHA] +=
(signed)(img->d_h - 1) * img->stride[VPX_PLANE_ALPHA];
img->stride[VPX_PLANE_ALPHA] = -img->stride[VPX_PLANE_ALPHA];
}
void vpx_img_free(vpx_image_t *img) {
if (img) {
if (img->img_data && img->img_data_owner)
vpx_free(img->img_data);
if (img->img_data && img->img_data_owner) vpx_free(img->img_data);
if (img->self_allocd)
free(img);
if (img->self_allocd) free(img);
}
}
-24
View File
@@ -1,24 +0,0 @@
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include "vpx/internal/vpx_psnr.h"
#define MAX_PSNR 100.0
double vpx_sse_to_psnr(double samples, double peak, double sse) {
if (sse > 0.0) {
const double psnr = 10.0 * log10(samples * peak * peak / sse);
return psnr > MAX_PSNR ? MAX_PSNR : psnr;
} else {
return MAX_PSNR;
}
}