mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-18 07:18:34 +00:00
[libvpx] Update to v1.17.0-97-gd3335af9e
This commit is contained in:
1 parent
7481baed18
commit
a55111af58
615 files changed
+68654
-28912
No files matched your search
@@ -1,123 +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 <assert.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../tools_common.h"
|
||||
#include "../vp9/encoder/vp9_resize.h"
|
||||
|
||||
static const char *exec_name = NULL;
|
||||
|
||||
static void usage() {
|
||||
printf("Usage:\n");
|
||||
printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ",
|
||||
exec_name);
|
||||
printf("<output_yuv> [<frames>]\n");
|
||||
}
|
||||
|
||||
void usage_exit(void) {
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int parse_dim(char *v, int *width, int *height) {
|
||||
char *x = strchr(v, 'x');
|
||||
if (x == NULL) x = strchr(v, 'X');
|
||||
if (x == NULL) return 0;
|
||||
*width = atoi(v);
|
||||
*height = atoi(&x[1]);
|
||||
if (*width <= 0 || *height <= 0)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fin, *fout;
|
||||
FILE *fpin, *fpout;
|
||||
uint8_t *inbuf, *outbuf;
|
||||
uint8_t *inbuf_u, *outbuf_u;
|
||||
uint8_t *inbuf_v, *outbuf_v;
|
||||
int f, frames;
|
||||
int width, height, target_width, target_height;
|
||||
|
||||
exec_name = argv[0];
|
||||
|
||||
if (argc < 5) {
|
||||
printf("Incorrect parameters:\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
fin = argv[1];
|
||||
fout = argv[4];
|
||||
if (!parse_dim(argv[2], &width, &height)) {
|
||||
printf("Incorrect parameters: %s\n", argv[2]);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (!parse_dim(argv[3], &target_width, &target_height)) {
|
||||
printf("Incorrect parameters: %s\n", argv[3]);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
fpin = fopen(fin, "rb");
|
||||
if (fpin == NULL) {
|
||||
printf("Can't open file %s to read\n", fin);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
fpout = fopen(fout, "wb");
|
||||
if (fpout == NULL) {
|
||||
printf("Can't open file %s to write\n", fout);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc >= 6)
|
||||
frames = atoi(argv[5]);
|
||||
else
|
||||
frames = INT_MAX;
|
||||
|
||||
printf("Input size: %dx%d\n", width, height);
|
||||
printf("Target size: %dx%d, Frames: ", target_width, target_height);
|
||||
if (frames == INT_MAX)
|
||||
printf("All\n");
|
||||
else
|
||||
printf("%d\n", frames);
|
||||
|
||||
inbuf = (uint8_t *)malloc(width * height * 3 / 2);
|
||||
outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
|
||||
inbuf_u = inbuf + width * height;
|
||||
inbuf_v = inbuf_u + width * height / 4;
|
||||
outbuf_u = outbuf + target_width * target_height;
|
||||
outbuf_v = outbuf_u + target_width * target_height / 4;
|
||||
f = 0;
|
||||
while (f < frames) {
|
||||
if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break;
|
||||
vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height,
|
||||
width, outbuf, target_width, outbuf_u, outbuf_v,
|
||||
target_width / 2, target_height, target_width);
|
||||
fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
|
||||
f++;
|
||||
}
|
||||
printf("%d frames processed\n", f);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
|
||||
free(inbuf);
|
||||
free(outbuf);
|
||||
return 0;
|
||||
}
|
||||
@@ -192,7 +192,8 @@ int main(int argc, char **argv) {
|
||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||
|
||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||
if (res)
|
||||
die("Failed to get default codec config: %s", vpx_codec_err_to_string(res));
|
||||
|
||||
cfg.g_w = info.frame_width;
|
||||
cfg.g_h = info.frame_height;
|
||||
|
||||
@@ -73,12 +73,15 @@
|
||||
// This example does not special case any error return codes. If there was
|
||||
// an error, a descriptive message is printed and the program exits. With
|
||||
// few exceptions, vpx_codec functions return an enumerated error status,
|
||||
// with the value `0` indicating success.
|
||||
// with the value `0` indicating success. VP8 may return success for a
|
||||
// corrupted frame, so the VP8D_GET_FRAME_CORRUPTED control is checked after
|
||||
// every decode.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vpx/vp8dx.h"
|
||||
#include "vpx/vpx_decoder.h"
|
||||
|
||||
#include "../tools_common.h"
|
||||
@@ -124,10 +127,14 @@ int main(int argc, char **argv) {
|
||||
vpx_codec_iter_t iter = NULL;
|
||||
vpx_image_t *img = NULL;
|
||||
size_t frame_size = 0;
|
||||
int corrupted = 0;
|
||||
const unsigned char *frame =
|
||||
vpx_video_reader_get_frame(reader, &frame_size);
|
||||
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
||||
die_codec(&codec, "Failed to decode frame.");
|
||||
if (vpx_codec_control(&codec, VP8D_GET_FRAME_CORRUPTED, &corrupted))
|
||||
die_codec(&codec, "Failed to get frame corrupted state.");
|
||||
if (corrupted) die("Frame %d is corrupted.", frame_cnt);
|
||||
|
||||
while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) {
|
||||
vpx_img_write(img, outfile);
|
||||
|
||||
@@ -202,7 +202,8 @@ int main(int argc, char **argv) {
|
||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||
|
||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||
if (res)
|
||||
die("Failed to get default codec config: %s", vpx_codec_err_to_string(res));
|
||||
|
||||
cfg.g_w = info.frame_width;
|
||||
cfg.g_h = info.frame_height;
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef struct {
|
||||
int speed; // speed setting for codec
|
||||
int threads;
|
||||
int aqmode; // turns on aq-mode=3 (cyclic_refresh): 0=off, 1=on.
|
||||
int use_psnr;
|
||||
// private storage for vpx_svc_encode
|
||||
void *internal;
|
||||
} SvcContext;
|
||||
@@ -58,6 +59,7 @@ typedef struct SvcInternal {
|
||||
double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V
|
||||
uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS];
|
||||
uint32_t bytes_sum[VPX_SS_MAX_LAYERS];
|
||||
int number_of_frames[VPX_SS_MAX_LAYERS];
|
||||
|
||||
// codec encoding values
|
||||
int width; // width of highest layer
|
||||
@@ -65,7 +67,6 @@ typedef struct SvcInternal {
|
||||
int kf_dist; // distance between keyframes
|
||||
|
||||
// state variables
|
||||
int psnr_pkt_received;
|
||||
int layer;
|
||||
int use_multiple_frame_contexts;
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options) {
|
||||
if (svc_ctx == NULL || options == NULL || si == NULL) {
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
}
|
||||
strncpy(si->options, options, sizeof(si->options));
|
||||
strncpy(si->options, options, sizeof(si->options) - 1);
|
||||
si->options[sizeof(si->options) - 1] = '\0';
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@@ -381,7 +381,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 sl, tl;
|
||||
SvcInternal_t *const si = get_svc_internal(svc_ctx);
|
||||
if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL ||
|
||||
enc_cfg == NULL) {
|
||||
@@ -433,7 +433,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
|
||||
}
|
||||
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;
|
||||
const int i = sl * svc_ctx->temporal_layers + tl;
|
||||
si->svc_params.max_quantizers[i] = MAX_QUANTIZER;
|
||||
si->svc_params.min_quantizers[i] = 0;
|
||||
if (enc_cfg->rc_end_usage == VPX_CBR &&
|
||||
@@ -503,7 +503,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
|
||||
|
||||
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;
|
||||
const int i = sl * svc_ctx->temporal_layers + tl;
|
||||
if (enc_cfg->rc_end_usage == VPX_CBR &&
|
||||
enc_cfg->g_pass == VPX_RC_ONE_PASS) {
|
||||
si->svc_params.max_quantizers[i] = enc_cfg->rc_max_quantizer;
|
||||
@@ -516,7 +516,11 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
|
||||
enc_cfg->g_error_resilient = 1;
|
||||
|
||||
// Initialize codec
|
||||
res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, VPX_CODEC_USE_PSNR);
|
||||
vpx_codec_flags_t flags = 0;
|
||||
if (svc_ctx->use_psnr) {
|
||||
flags |= VPX_CODEC_USE_PSNR;
|
||||
}
|
||||
res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, flags);
|
||||
if (res != VPX_CODEC_OK) {
|
||||
svc_log(svc_ctx, SVC_LOG_ERROR, "svc_enc_init error\n");
|
||||
return res;
|
||||
@@ -536,8 +540,6 @@ 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;
|
||||
const vpx_codec_cx_pkt_t *cx_pkt;
|
||||
SvcInternal_t *const si = get_svc_internal(svc_ctx);
|
||||
if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) {
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
@@ -548,17 +550,6 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
|
||||
if (res != VPX_CODEC_OK) {
|
||||
return res;
|
||||
}
|
||||
// save compressed data
|
||||
iter = NULL;
|
||||
while ((cx_pkt = vpx_codec_get_cx_data(codec_ctx, &iter))) {
|
||||
switch (cx_pkt->kind) {
|
||||
case VPX_CODEC_PSNR_PKT: {
|
||||
}
|
||||
++si->psnr_pkt_received;
|
||||
break;
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@@ -570,7 +561,6 @@ static double calc_psnr(double d) {
|
||||
|
||||
// dump accumulated statistics and reset accumulated values
|
||||
void vpx_svc_dump_statistics(SvcContext *svc_ctx) {
|
||||
int number_of_frames;
|
||||
int i, j;
|
||||
uint32_t bytes_total = 0;
|
||||
double scale[COMPONENTS];
|
||||
@@ -581,19 +571,18 @@ void vpx_svc_dump_statistics(SvcContext *svc_ctx) {
|
||||
SvcInternal_t *const si = get_svc_internal(svc_ctx);
|
||||
if (svc_ctx == NULL || si == NULL) return;
|
||||
|
||||
number_of_frames = si->psnr_pkt_received;
|
||||
if (number_of_frames <= 0) return;
|
||||
|
||||
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, si->psnr_sum[i][0] / number_of_frames,
|
||||
si->psnr_sum[i][1] / number_of_frames,
|
||||
si->psnr_sum[i][2] / number_of_frames,
|
||||
si->psnr_sum[i][3] / number_of_frames, si->bytes_sum[i]);
|
||||
"Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u], "
|
||||
"Number_of_frames %d \n",
|
||||
i, si->psnr_sum[i][0] / si->number_of_frames[i],
|
||||
si->psnr_sum[i][1] / si->number_of_frames[i],
|
||||
si->psnr_sum[i][2] / si->number_of_frames[i],
|
||||
si->psnr_sum[i][3] / si->number_of_frames[i], si->bytes_sum[i],
|
||||
si->number_of_frames[i]);
|
||||
// the following psnr calculation is deduced from ffmpeg.c#print_report
|
||||
y_scale = si->width * si->height * 255.0 * 255.0 * number_of_frames;
|
||||
y_scale = si->width * si->height * 255.0 * 255.0 * si->number_of_frames[i];
|
||||
scale[1] = y_scale;
|
||||
scale[2] = scale[3] = y_scale / 4; // U or V
|
||||
scale[0] = y_scale * 1.5; // total
|
||||
@@ -610,17 +599,17 @@ void vpx_svc_dump_statistics(SvcContext *svc_ctx) {
|
||||
mse[1], mse[2], mse[3]);
|
||||
|
||||
bytes_total += si->bytes_sum[i];
|
||||
// Clear sums for next time.
|
||||
}
|
||||
// Clear sums for next time.
|
||||
for (i = 0; i < svc_ctx->spatial_layers; ++i) {
|
||||
si->bytes_sum[i] = 0;
|
||||
si->number_of_frames[i] = 0;
|
||||
for (j = 0; j < COMPONENTS; ++j) {
|
||||
si->psnr_sum[i][j] = 0;
|
||||
si->sse_sum[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// only display statistics once
|
||||
si->psnr_pkt_received = 0;
|
||||
|
||||
svc_log(svc_ctx, SVC_LOG_INFO, "Total Bytes=[%u]\n", bytes_total);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name,
|
||||
int main(int argc, char **argv) {
|
||||
FILE *infile = NULL;
|
||||
int w, h;
|
||||
vpx_codec_ctx_t codec;
|
||||
vpx_codec_enc_cfg_t cfg;
|
||||
vpx_image_t raw;
|
||||
vpx_codec_err_t res;
|
||||
@@ -228,7 +227,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Configuration
|
||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||
if (res)
|
||||
die("Failed to get default codec config: %s", vpx_codec_err_to_string(res));
|
||||
|
||||
cfg.g_w = w;
|
||||
cfg.g_h = h;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
@@ -438,7 +437,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Other-resolution encoder settings */
|
||||
for (i = 1; i < NUM_ENCODERS; i++) {
|
||||
memcpy(&cfg[i], &cfg[0], sizeof(vpx_codec_enc_cfg_t));
|
||||
cfg[i] = cfg[0];
|
||||
|
||||
cfg[i].rc_target_bitrate = target_bitrate[i];
|
||||
|
||||
|
||||
@@ -140,7 +140,8 @@ int main(int argc, char **argv) {
|
||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||
|
||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||
if (res)
|
||||
die("Failed to get default codec config: %s", vpx_codec_err_to_string(res));
|
||||
|
||||
cfg.g_w = info.frame_width;
|
||||
cfg.g_h = info.frame_height;
|
||||
|
||||
@@ -96,7 +96,8 @@ int main(int argc, char **argv) {
|
||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||
|
||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||
if (res)
|
||||
die("Failed to get default codec config: %s", vpx_codec_err_to_string(res));
|
||||
|
||||
cfg.g_w = info.frame_width;
|
||||
cfg.g_h = info.frame_height;
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
* that benefit from a scalable bitstream.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@@ -24,14 +27,16 @@
|
||||
#include "../tools_common.h"
|
||||
#include "../video_writer.h"
|
||||
|
||||
#include "../vpx_ports/bitops.h"
|
||||
#include "../vpx_ports/vpx_timer.h"
|
||||
#include "./svc_context.h"
|
||||
#include "vpx/vp8cx.h"
|
||||
#include "vpx/vpx_decoder.h"
|
||||
#include "vpx/vpx_encoder.h"
|
||||
#include "../vpxstats.h"
|
||||
#include "vp9/encoder/vp9_encoder.h"
|
||||
#include "./y4minput.h"
|
||||
|
||||
#define OUTPUT_FRAME_STATS 0
|
||||
#define OUTPUT_RC_STATS 1
|
||||
|
||||
#define SIMULCAST_MODE 0
|
||||
@@ -88,6 +93,8 @@ static const arg_def_t bitrates_arg =
|
||||
ARG_DEF("bl", "bitrates", 1, "bitrates[sl * num_tl + tl]");
|
||||
static const arg_def_t dropframe_thresh_arg =
|
||||
ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)");
|
||||
static const arg_def_t psnr_arg =
|
||||
ARG_DEF(NULL, "psnr", 1, "Enable PSNR computation and statistics");
|
||||
static const struct arg_enum_list tune_content_enum[] = {
|
||||
{ "default", VP9E_CONTENT_DEFAULT },
|
||||
{ "screen", VP9E_CONTENT_SCREEN },
|
||||
@@ -141,6 +148,7 @@ static const arg_def_t *svc_args[] = { &frames_arg,
|
||||
&dropframe_thresh_arg,
|
||||
&tune_content_arg,
|
||||
&inter_layer_pred_arg,
|
||||
&psnr_arg,
|
||||
NULL };
|
||||
|
||||
static const uint32_t default_frames_to_skip = 0;
|
||||
@@ -200,6 +208,7 @@ static void parse_command_line(int argc, const char **argv_,
|
||||
#endif
|
||||
svc_ctx->speed = default_speed;
|
||||
svc_ctx->threads = default_threads;
|
||||
svc_ctx->use_psnr = 0;
|
||||
|
||||
// start with default encoder configuration
|
||||
res = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), enc_cfg, 0);
|
||||
@@ -315,7 +324,6 @@ static void parse_command_line(int argc, const char **argv_,
|
||||
break;
|
||||
default:
|
||||
die("Error: Invalid bit depth selected (%d)\n", enc_cfg->g_bit_depth);
|
||||
break;
|
||||
}
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
} else if (arg_match(&arg, &dropframe_thresh_arg, argi)) {
|
||||
@@ -324,6 +332,8 @@ static void parse_command_line(int argc, const char **argv_,
|
||||
app_input->tune_content = arg_parse_uint(&arg);
|
||||
} else if (arg_match(&arg, &inter_layer_pred_arg, argi)) {
|
||||
app_input->inter_layer_pred = arg_parse_uint(&arg);
|
||||
} else if (arg_match(&arg, &psnr_arg, argi)) {
|
||||
svc_ctx->use_psnr = arg_parse_uint(&arg);
|
||||
} else {
|
||||
++argj;
|
||||
}
|
||||
@@ -776,8 +786,8 @@ static void svc_output_rc_stats(
|
||||
int count = 0;
|
||||
double sum_bitrate = 0.0;
|
||||
double sum_bitrate2 = 0.0;
|
||||
vp9_zero(sizes);
|
||||
vp9_zero(sizes_parsed);
|
||||
memset(sizes, 0, sizeof(sizes));
|
||||
memset(sizes_parsed, 0, sizeof(sizes_parsed));
|
||||
vpx_codec_control(codec, VP9E_GET_SVC_LAYER_ID, layer_id);
|
||||
parse_superframe_index(cx_pkt->data.frame.buf, cx_pkt->data.frame.sz,
|
||||
sizes_parsed, &count);
|
||||
@@ -880,7 +890,9 @@ int main(int argc, const char **argv) {
|
||||
int pts = 0; /* PTS starts at 0 */
|
||||
int frame_duration = 1; /* 1 timebase tick per frame */
|
||||
int end_of_stream = 0;
|
||||
#if OUTPUT_FRAME_STATS
|
||||
int frames_received = 0;
|
||||
#endif
|
||||
#if OUTPUT_RC_STATS
|
||||
VpxVideoWriter *outfile[VPX_SS_MAX_LAYERS] = { NULL };
|
||||
struct RateControlStats rc;
|
||||
@@ -1126,41 +1138,65 @@ int main(int argc, const char **argv) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
#if OUTPUT_FRAME_STATS
|
||||
printf("SVC frame: %d, kf: %d, size: %d, pts: %d\n", frames_received,
|
||||
!!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY),
|
||||
(int)cx_pkt->data.frame.sz, (int)cx_pkt->data.frame.pts);
|
||||
*/
|
||||
if (enc_cfg.ss_number_layers == 1 && enc_cfg.ts_number_layers == 1)
|
||||
si->bytes_sum[0] += (int)cx_pkt->data.frame.sz;
|
||||
++frames_received;
|
||||
#endif
|
||||
if (enc_cfg.ss_number_layers > 1) {
|
||||
uint64_t sizes[8] = { 0 };
|
||||
int count = 0;
|
||||
int num_layers_encoded = 0;
|
||||
parse_superframe_index(cx_pkt->data.frame.buf,
|
||||
cx_pkt->data.frame.sz, sizes, &count);
|
||||
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
|
||||
if (cx_pkt->data.frame.spatial_layer_encoded[sl]) {
|
||||
si->bytes_sum[sl] += (int)sizes[num_layers_encoded];
|
||||
num_layers_encoded++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
si->bytes_sum[0] += (int)cx_pkt->data.frame.sz;
|
||||
}
|
||||
#if CONFIG_VP9_DECODER && !SIMULCAST_MODE
|
||||
if (vpx_codec_decode(&decoder, cx_pkt->data.frame.buf,
|
||||
(unsigned int)cx_pkt->data.frame.sz, NULL, 0))
|
||||
die_codec(&decoder, "Failed to decode frame.");
|
||||
vpx_codec_control(&encoder, VP9E_GET_SVC_LAYER_ID, &layer_id);
|
||||
// Don't look for mismatch on top spatial and top temporal layers as
|
||||
// they are non reference frames. Don't look at frames whose top
|
||||
// spatial layer is dropped.
|
||||
if ((enc_cfg.ss_number_layers > 1 || enc_cfg.ts_number_layers > 1) &&
|
||||
cx_pkt->data.frame
|
||||
.spatial_layer_encoded[enc_cfg.ss_number_layers - 1] &&
|
||||
!(layer_id.temporal_layer_id > 0 &&
|
||||
layer_id.temporal_layer_id ==
|
||||
(int)enc_cfg.ts_number_layers - 1)) {
|
||||
test_decode(&encoder, &decoder, frame_cnt, &mismatch_seen);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case VPX_CODEC_PSNR_PKT: {
|
||||
SvcInternal_t *const si = (SvcInternal_t *)svc_ctx.internal;
|
||||
sl = cx_pkt->data.psnr.spatial_layer_id;
|
||||
si->number_of_frames[sl]++;
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
si->psnr_sum[sl][j] += cx_pkt->data.psnr.psnr[j];
|
||||
si->sse_sum[sl][j] += cx_pkt->data.psnr.sse[j];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VPX_CODEC_STATS_PKT: {
|
||||
stats_write(&app_input.rc_stats, cx_pkt->data.twopass_stats.buf,
|
||||
cx_pkt->data.twopass_stats.sz);
|
||||
break;
|
||||
}
|
||||
default: { break; }
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_VP9_DECODER && !SIMULCAST_MODE
|
||||
vpx_codec_control(&encoder, VP9E_GET_SVC_LAYER_ID, &layer_id);
|
||||
// Don't look for mismatch on top spatial and top temporal layers as they
|
||||
// are non reference frames.
|
||||
if ((enc_cfg.ss_number_layers > 1 || enc_cfg.ts_number_layers > 1) &&
|
||||
!(layer_id.temporal_layer_id > 0 &&
|
||||
layer_id.temporal_layer_id == (int)enc_cfg.ts_number_layers - 1 &&
|
||||
cx_pkt->data.frame
|
||||
.spatial_layer_encoded[enc_cfg.ss_number_layers - 1])) {
|
||||
test_decode(&encoder, &decoder, frame_cnt, &mismatch_seen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!end_of_stream) {
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
static const char *exec_name;
|
||||
|
||||
void usage_exit() {
|
||||
void usage_exit(void) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s <width> <height> <infile> <outfile> "
|
||||
"<frame> <limit(optional)>\n",
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
$make -j32
|
||||
|
||||
* Build vp9 fuzzer
|
||||
$ $CXX $CXXFLAGS -std=gnu++11 -DDECODER=vp9 \
|
||||
-fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \
|
||||
$ $CXX $CXXFLAGS -std=gnu++17 -Wall -Wextra -Wimplicit-fallthrough \
|
||||
-DDECODER=vp9 -fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \
|
||||
../libvpx/examples/vpx_dec_fuzzer.cc -o ./vpx_dec_fuzzer_vp9 \
|
||||
./libvpx.a -Wl,--end-group
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "third_party/nalloc/nalloc.h"
|
||||
#include "vpx/vp8dx.h"
|
||||
#include "vpx/vpx_decoder.h"
|
||||
#include "vpx_ports/mem_ops.h"
|
||||
@@ -85,33 +86,64 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (size <= IVF_FILE_HDR_SZ) {
|
||||
return 0;
|
||||
}
|
||||
nalloc_init(nullptr);
|
||||
|
||||
vpx_codec_ctx_t codec;
|
||||
// Set thread count in the range [1, 64].
|
||||
const unsigned int threads = (data[IVF_FILE_HDR_SZ] & 0x3f) + 1;
|
||||
vpx_codec_dec_cfg_t cfg = { threads, 0, 0 };
|
||||
if (vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, 0)) {
|
||||
vpx_codec_flags_t flags = 0;
|
||||
if ((data[IVF_FILE_HDR_SZ] & 0x40) != 0) {
|
||||
flags |= VPX_CODEC_USE_POSTPROC;
|
||||
}
|
||||
vpx_codec_err_t err =
|
||||
vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, flags);
|
||||
if (err == VPX_CODEC_INCAPABLE) {
|
||||
// vpx_codec_dec_init may fail with VPX_CODEC_USE_POSTPROC
|
||||
// if the library is configured with --disable-postproc.
|
||||
flags = 0;
|
||||
if (vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, flags)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (err != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nalloc_start(data, size);
|
||||
|
||||
if (threads > 1) {
|
||||
const int enable = (data[IVF_FILE_HDR_SZ] & 0xa0) != 0;
|
||||
const vpx_codec_err_t err =
|
||||
vpx_codec_control(&codec, VP9D_SET_LOOP_FILTER_OPT, enable);
|
||||
static_cast<void>(err);
|
||||
err = vpx_codec_control(&codec, VP9D_SET_LOOP_FILTER_OPT, enable);
|
||||
}
|
||||
|
||||
data += IVF_FILE_HDR_SZ;
|
||||
size -= IVF_FILE_HDR_SZ;
|
||||
|
||||
int frame_cnt = 0;
|
||||
while (size > IVF_FRAME_HDR_SZ) {
|
||||
size_t frame_size = mem_get_le32(data);
|
||||
size -= IVF_FRAME_HDR_SZ;
|
||||
data += IVF_FRAME_HDR_SZ;
|
||||
frame_size = std::min(size, frame_size);
|
||||
|
||||
const vpx_codec_err_t err =
|
||||
vpx_codec_decode(&codec, data, frame_size, nullptr, 0);
|
||||
vpx_codec_stream_info_t stream_info;
|
||||
stream_info.sz = sizeof(stream_info);
|
||||
err = vpx_codec_peek_stream_info(VPXD_INTERFACE(DECODER), data, size,
|
||||
&stream_info);
|
||||
|
||||
++frame_cnt;
|
||||
if (flags & VPX_CODEC_USE_POSTPROC) {
|
||||
if (frame_cnt % 16 == 4) {
|
||||
vp8_postproc_cfg_t pp = { 0, 0, 0 };
|
||||
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) goto fail;
|
||||
} else if (frame_cnt % 16 == 12) {
|
||||
vp8_postproc_cfg_t pp = { VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE, 4,
|
||||
0 };
|
||||
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
err = vpx_codec_decode(&codec, data, frame_size, nullptr, 0);
|
||||
static_cast<void>(err);
|
||||
vpx_codec_iter_t iter = nullptr;
|
||||
vpx_image_t *img = nullptr;
|
||||
@@ -120,6 +152,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
data += frame_size;
|
||||
size -= frame_size;
|
||||
}
|
||||
fail:
|
||||
vpx_codec_destroy(&codec);
|
||||
nalloc_end();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Fuzzer for libvpx encoders
|
||||
* ==========================
|
||||
* Requirements
|
||||
* --------------
|
||||
* Requires Clang 6.0 or above as -fsanitize=fuzzer is used as a linker
|
||||
* option.
|
||||
|
||||
* Steps to build
|
||||
* --------------
|
||||
* Clone libvpx repository
|
||||
$git clone https://chromium.googlesource.com/webm/libvpx
|
||||
|
||||
* Create a directory in parallel to libvpx and change directory
|
||||
$mkdir vpx_enc_fuzzer
|
||||
$cd vpx_enc_fuzzer/
|
||||
|
||||
* Enable sanitizers (Supported: address integer memory thread undefined)
|
||||
$source ../libvpx/tools/set_analyzer_env.sh address
|
||||
|
||||
* Configure libvpx.
|
||||
* Note --size-limit and VPX_MAX_ALLOCABLE_MEMORY are defined to avoid
|
||||
* Out of memory errors when running generated fuzzer binary
|
||||
$../libvpx/configure --disable-unit-tests --size-limit=12288x12288 \
|
||||
--extra-cflags="-fsanitize=fuzzer-no-link \
|
||||
-DVPX_MAX_ALLOCABLE_MEMORY=1073741824" \
|
||||
--disable-webm-io --enable-debug --enable-vp8-encoder \
|
||||
--enable-vp9-encoder --disable-examples
|
||||
|
||||
* Build libvpx
|
||||
$make -j32
|
||||
|
||||
* Build vp9 fuzzer
|
||||
$ $CXX $CXXFLAGS -std=gnu++17 -Wall -Wextra -Wimplicit-fallthrough \
|
||||
-DENCODER=vp9 -fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \
|
||||
../libvpx/examples/vpx_enc_fuzzer.cc -o ./vpx_enc_fuzzer_vp9 \
|
||||
./libvpx.a -Wl,--end-group
|
||||
|
||||
* ENCODER should be defined as vp9 or vp8 to enable vp9/vp8
|
||||
*
|
||||
* create a corpus directory and copy some ivf files there.
|
||||
* Based on which codec (vp8/vp9) is being tested, it is recommended to
|
||||
* have corresponding ivf files in corpus directory
|
||||
* Empty corpus directory also is acceptable, though not recommended
|
||||
$mkdir CORPUS && cp some-files CORPUS
|
||||
|
||||
* Run fuzzing:
|
||||
$./vpx_enc_fuzzer_vp9 CORPUS
|
||||
|
||||
* References:
|
||||
* http://llvm.org/docs/LibFuzzer.html
|
||||
* https://github.com/google/oss-fuzz
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vpx/vp8cx.h"
|
||||
#include "vpx/vpx_encoder.h"
|
||||
#include "vpx_ports/mem_ops.h"
|
||||
#include "third_party/nalloc/nalloc.h"
|
||||
|
||||
// fuzz header to have config options, before raw image data
|
||||
#define FUZZ_HDR_SZ 32
|
||||
|
||||
#define VPXC_INTERFACE(name) VPXC_INTERFACE_(name)
|
||||
#define VPXC_INTERFACE_(name) vpx_codec_##name##_cx()
|
||||
|
||||
extern "C" void usage_exit(void) { exit(EXIT_FAILURE); }
|
||||
|
||||
static int vpx_img_plane_width(const vpx_image_t *img, int plane) {
|
||||
if (plane > 0 && img->x_chroma_shift > 0)
|
||||
return (img->d_w + 1) >> img->x_chroma_shift;
|
||||
else
|
||||
return img->d_w;
|
||||
}
|
||||
|
||||
static int vpx_img_plane_height(const vpx_image_t *img, int plane) {
|
||||
if (plane > 0 && img->y_chroma_shift > 0)
|
||||
return (img->d_h + 1) >> img->y_chroma_shift;
|
||||
else
|
||||
return img->d_h;
|
||||
}
|
||||
|
||||
static int fuzz_vpx_img_read(vpx_image_t *img, const uint8_t *data,
|
||||
size_t size) {
|
||||
int plane;
|
||||
// TODO: wtc - Need to clamp the sample values so that they are in range
|
||||
// For example, if the bit depth is 10, the sample values must be <= 1023.
|
||||
assert(img->bit_depth == 8);
|
||||
const size_t bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
|
||||
|
||||
if (size == 0) return 0;
|
||||
size_t used = 0;
|
||||
for (plane = 0; plane < 3; ++plane) {
|
||||
unsigned char *buf = img->planes[plane];
|
||||
const int stride = img->stride[plane];
|
||||
int w = vpx_img_plane_width(img, plane);
|
||||
const int h = vpx_img_plane_height(img, plane);
|
||||
int y;
|
||||
|
||||
// Assuming that for nv12 we read all chroma data at once
|
||||
if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break;
|
||||
// NV12 UV plane is interleaved, so it has twice the width of a subsampled
|
||||
// plane.
|
||||
if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = w * 2;
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
size_t nb = bytespp * w;
|
||||
if (nb > size - used) {
|
||||
nb = size - used;
|
||||
}
|
||||
memcpy(buf, data, nb);
|
||||
memset(buf + nb, 0, bytespp * w - nb);
|
||||
buf += stride;
|
||||
data += nb;
|
||||
used += nb;
|
||||
}
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
|
||||
int frame_index, int flags, FILE *out,
|
||||
vpx_enc_deadline_t quality) {
|
||||
int got_pkts = 0;
|
||||
vpx_codec_iter_t iter = nullptr;
|
||||
const vpx_codec_cx_pkt_t *pkt = nullptr;
|
||||
const vpx_codec_err_t res =
|
||||
vpx_codec_encode(codec, img, frame_index, 1, flags, quality);
|
||||
if (res != VPX_CODEC_OK) return 0;
|
||||
|
||||
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != nullptr) {
|
||||
got_pkts = 1;
|
||||
|
||||
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
||||
if (fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, out) !=
|
||||
pkt->data.frame.sz)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return got_pkts;
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (size <= FUZZ_HDR_SZ) {
|
||||
return 0;
|
||||
}
|
||||
nalloc_init(nullptr);
|
||||
|
||||
int keyframe_interval = 0;
|
||||
int frame_count = 0;
|
||||
vpx_codec_ctx_t codec;
|
||||
vpx_image_t raw;
|
||||
vpx_codec_enc_cfg_t cfg;
|
||||
vpx_enc_deadline_t quality = VPX_DL_GOOD_QUALITY;
|
||||
|
||||
if ((data[0] & 0x80) != 0) {
|
||||
keyframe_interval = 8;
|
||||
}
|
||||
if ((data[0] & 0x40) != 0) {
|
||||
quality = VPX_DL_REALTIME;
|
||||
} else if ((data[0] & 0x20) != 0) {
|
||||
quality = VPX_DL_BEST_QUALITY;
|
||||
}
|
||||
const int max_frames = (quality == VPX_DL_BEST_QUALITY) ? 150 : 300;
|
||||
|
||||
if (vpx_codec_enc_config_default(VPXC_INTERFACE(ENCODER), &cfg, 0)) abort();
|
||||
FILE *out = fopen("/dev/null", "wb");
|
||||
|
||||
switch (data[0] & 0x1F) {
|
||||
case 0:
|
||||
cfg.g_w = 64;
|
||||
cfg.g_h = 1;
|
||||
break;
|
||||
case 1:
|
||||
cfg.g_w = 1;
|
||||
cfg.g_h = 48;
|
||||
break;
|
||||
case 2:
|
||||
cfg.g_w = 1;
|
||||
cfg.g_h = 1;
|
||||
break;
|
||||
case 3:
|
||||
cfg.g_w = 4;
|
||||
cfg.g_h = 4;
|
||||
break;
|
||||
case 4:
|
||||
cfg.g_w = 16;
|
||||
cfg.g_h = 16;
|
||||
break;
|
||||
default:
|
||||
cfg.g_w = 64;
|
||||
cfg.g_h = 48;
|
||||
break;
|
||||
}
|
||||
cfg.g_timebase.num = 1;
|
||||
cfg.g_timebase.den = 30; // fps
|
||||
cfg.rc_target_bitrate = 200;
|
||||
cfg.g_error_resilient = 1;
|
||||
|
||||
if (vpx_codec_enc_init(&codec, VPXC_INTERFACE(ENCODER), &cfg, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
nalloc_start(data, size);
|
||||
// We may want to add more config options (for more complex encoders as seen
|
||||
// in the examples) in the future while still maintaining the same format (so
|
||||
// that generated corpus is still valid). So we reserve FUZZ_HDR_SZ=32 bytes
|
||||
// for this even if we just use one byte so far.
|
||||
data += FUZZ_HDR_SZ;
|
||||
size -= FUZZ_HDR_SZ;
|
||||
|
||||
// Encode frames.
|
||||
for (int i = 0; i < max_frames; ++i) {
|
||||
int flags = 0;
|
||||
size_t size_read = fuzz_vpx_img_read(&raw, data, size);
|
||||
if (size_read == 0) break;
|
||||
data += size_read;
|
||||
size -= size_read;
|
||||
if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
|
||||
flags |= VPX_EFLAG_FORCE_KF;
|
||||
encode_frame(&codec, &raw, frame_count++, flags, out, quality);
|
||||
}
|
||||
|
||||
// Flush encoder.
|
||||
while (encode_frame(&codec, nullptr, -1, 0, out, quality)) {
|
||||
}
|
||||
|
||||
fail:
|
||||
nalloc_end();
|
||||
vpx_img_free(&raw);
|
||||
vpx_codec_destroy(&codec);
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
@@ -32,8 +32,6 @@
|
||||
|
||||
#define zero(Dest) memset(&(Dest), 0, sizeof(Dest))
|
||||
|
||||
static const char *exec_name;
|
||||
|
||||
void usage_exit(void) { exit(EXIT_FAILURE); }
|
||||
|
||||
// Denoiser states for vp8, for temporal denoising.
|
||||
@@ -607,19 +605,24 @@ static void set_temporal_layer_pattern(int layering_mode,
|
||||
}
|
||||
|
||||
#if ROI_MAP
|
||||
static void read_mask(FILE *mask_file, int *seg_map) {
|
||||
static int read_mask(FILE *mask_file, int *seg_map, int allowed_mask_rows,
|
||||
int allowed_mask_cols) {
|
||||
int mask_rows, mask_cols, i, j;
|
||||
int *map_start = seg_map;
|
||||
fscanf(mask_file, "%d %d\n", &mask_cols, &mask_rows);
|
||||
if (fscanf(mask_file, "%d %d\n", &mask_cols, &mask_rows) != 2) return 0;
|
||||
if (mask_rows != allowed_mask_rows || mask_cols != allowed_mask_cols) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < mask_rows; i++) {
|
||||
for (j = 0; j < mask_cols; j++) {
|
||||
fscanf(mask_file, "%d ", &seg_map[j]);
|
||||
if (fscanf(mask_file, "%d ", &seg_map[j]) != 1) return 0;
|
||||
// reverse the bit
|
||||
seg_map[j] = 1 - seg_map[j];
|
||||
}
|
||||
seg_map += mask_cols;
|
||||
}
|
||||
seg_map = map_start;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -679,7 +682,6 @@ int main(int argc, char **argv) {
|
||||
input_ctx.only_i420 = 1;
|
||||
input_ctx.bit_depth = 0;
|
||||
|
||||
exec_name = argv[0];
|
||||
// Check usage and arguments.
|
||||
if (argc < min_args) {
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
@@ -965,12 +967,16 @@ int main(int argc, char **argv) {
|
||||
argv[argc - 1], frame_cnt);
|
||||
mask_file = fopen(mask_file_name, "r");
|
||||
if (mask_file != NULL) {
|
||||
read_mask(mask_file, mask_map);
|
||||
int mask_is_valid = read_mask(mask_file, mask_map, mask_rows, mask_cols);
|
||||
fclose(mask_file);
|
||||
// set_roi_map(encoder->name, &cfg, &roi);
|
||||
set_roi_skip_map(&cfg, &roi, mask_map, prev_mask_map, frame_cnt);
|
||||
if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi))
|
||||
die_codec(&codec, "Failed to set ROI map");
|
||||
if (mask_is_valid) {
|
||||
// set_roi_map(encoder->name, &cfg, &roi);
|
||||
set_roi_skip_map(&cfg, &roi, mask_map, prev_mask_map, frame_cnt);
|
||||
if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi))
|
||||
die_codec(&codec, "Failed to set ROI map");
|
||||
} else {
|
||||
die_codec(&codec, "Mask input is invalid for ROI map");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
frame_avail = read_frame(&input_ctx, &raw);
|
||||
|
||||
Reference in new issue
Block a user