An error occurred while loading the file. Please try again.
-
Yunqing Wang authored
Implemented parallel loopfiltering, which uses existing tile- decoding threads. Each thread works on one row, and when that row is loopfiltered, it moves to next unattended row. To ensure the correct filtering order, threads are synchronized and one superblock is filtered only if the superblocks it depends on are filtered already. To reduce synchronization overhead and speed up the decoder, we use nsync > 1 for high resolution. Performance tests: 1. on desktop: 8-tile 4k video using 8 threads, speedup: 70% - 80% 4-tile HD video using 4 threads, speedup: ~35% 2. on mobile device(Nexus 7): 4-tile 1080p video using 4 threads, speedup: 18% - 25% 4-tile 1080p video using 2 threads, speedup: 10% - 15% Change-Id: If54b4a11960dd706c22d5ad145ad94156031f36a
903801f1
vpxdec.c 34.52 KiB
/*
* Copyright (c) 2010 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.
*/
/* This is a simple program that reads ivf files and decodes them
* using the new interface. Decoded frames are output as YV12 raw.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#define VPX_CODEC_DISABLE_COMPAT 1
#include "vpx_config.h"
#include "vpx/vpx_decoder.h"
#include "vpx_ports/vpx_timer.h"
#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
#include "vpx/vp8dx.h"
#endif
#if CONFIG_MD5
#include "md5_utils.h"
#endif
#include "tools_common.h"
#include "nestegg/include/nestegg/nestegg.h"
#include "third_party/libyuv/include/libyuv/scale.h"
#if CONFIG_OS_SUPPORT
#if defined(_MSC_VER)
#include <io.h>
#define snprintf _snprintf
#define isatty _isatty
#define fileno _fileno
#else
#include <unistd.h>
#endif
#endif
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
static const char *exec_name;
static const struct {
char const *name;
const vpx_codec_iface_t *(*iface)(void);
unsigned int fourcc;
unsigned int fourcc_mask;
} ifaces[] = {
#if CONFIG_VP8_DECODER
{"vp8", vpx_codec_vp8_dx, VP8_FOURCC_MASK, 0x00FFFFFF},
#endif
#if CONFIG_VP9_DECODER
{"vp9", vpx_codec_vp9_dx, VP9_FOURCC_MASK, 0x00FFFFFF},
#endif
};
#include "args.h"
static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1,
"Number of times to decode the file");
static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
"Codec to use");
static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
"Output raw YV12 frames");
static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0,
"Output raw I420 frames");
static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0,
"Flip the chroma planes in the output");
static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0,
"Don't process the decoded frames");
static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0,
"Show progress after each frame decodes");
static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1,
"Stop decoding after n frames");
static const arg_def_t skiparg = ARG_DEF(NULL, "skip", 1,
"Skip the first n input frames");
static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0,
"Postprocess decoded frames");
static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0,
"Show timing summary");
static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
"Output file name pattern (see below)");
static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1,
"Max threads to use");
static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0,
"Show version string");
static const arg_def_t error_concealment = ARG_DEF(NULL, "error-concealment", 0,
"Enable decoder error-concealment");
static const arg_def_t scalearg = ARG_DEF("S", "scale", 0,
"Scale output frames uniformly");
#if CONFIG_MD5
static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0,
"Compute the MD5 sum of the decoded frame");
#endif
static const arg_def_t *all_args[] = {
&codecarg, &use_yv12, &use_i420, &flipuvarg, &noblitarg,
&progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile,
&threadsarg, &verbosearg, &scalearg,
#if CONFIG_MD5
&md5arg,
#endif
&error_concealment,
NULL
};
#if CONFIG_VP8_DECODER
static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1,
"Enable VP8 postproc add noise");
static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0,
"Enable VP8 deblocking");
static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1,
"Enable VP8 demacroblocking, w/ level");
static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1,
"Enable VP8 visible debug info");
static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1,
"Display only selected reference frame per macro block");
static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1,
"Display only selected macro block modes");
static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1,
"Display only selected block modes");
static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1,
"Draw only selected motion vectors");
static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0,
"Enable multiframe quality enhancement");
static const arg_def_t *vp8_pp_args[] = {
&addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
&pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe,
NULL
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
};
#endif
void usage_exit() {
int i;
fprintf(stderr, "Usage: %s <options> filename\n\n"
"Options:\n", exec_name);
arg_show_usage(stderr, all_args);
#if CONFIG_VP8_DECODER
fprintf(stderr, "\nVP8 Postprocessing Options:\n");
arg_show_usage(stderr, vp8_pp_args);
#endif
fprintf(stderr,
"\nOutput File Patterns:\n\n"
" The -o argument specifies the name of the file(s) to "
"write to. If the\n argument does not include any escape "
"characters, the output will be\n written to a single file. "
"Otherwise, the filename will be calculated by\n expanding "
"the following escape characters:\n");
fprintf(stderr,
"\n\t%%w - Frame width"
"\n\t%%h - Frame height"
"\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
"\n\n Pattern arguments are only supported in conjunction "
"with the --yv12 and\n --i420 options. If the -o option is "
"not specified, the output will be\n directed to stdout.\n"
);
fprintf(stderr, "\nIncluded decoders:\n\n");
for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
fprintf(stderr, " %-6s - %s\n",
ifaces[i].name,
vpx_codec_iface_name(ifaces[i].iface()));
exit(EXIT_FAILURE);
}
static unsigned int mem_get_le16(const void *vmem) {
unsigned int val;
const unsigned char *mem = (const unsigned char *)vmem;
val = mem[1] << 8;
val |= mem[0];
return val;
}
static unsigned int mem_get_le32(const void *vmem) {
unsigned int val;
const unsigned char *mem = (const unsigned char *)vmem;
val = mem[3] << 24;
val |= mem[2] << 16;
val |= mem[1] << 8;
val |= mem[0];
return val;
}
enum file_kind {
RAW_FILE,
IVF_FILE,
WEBM_FILE
};
struct input_ctx {
enum file_kind kind;
FILE *infile;
nestegg *nestegg_ctx;
nestegg_packet *pkt;
unsigned int chunk;
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
unsigned int chunks;
unsigned int video_track;
};
#define IVF_FRAME_HDR_SZ (sizeof(uint32_t) + sizeof(uint64_t))
#define RAW_FRAME_HDR_SZ (sizeof(uint32_t))
static int read_frame(struct input_ctx *input,
uint8_t **buf,
size_t *buf_sz,
size_t *buf_alloc_sz) {
char raw_hdr[IVF_FRAME_HDR_SZ];
size_t new_buf_sz;
FILE *infile = input->infile;
enum file_kind kind = input->kind;
if (kind == WEBM_FILE) {
if (input->chunk >= input->chunks) {
unsigned int track;
do {
/* End of this packet, get another. */
if (input->pkt)
nestegg_free_packet(input->pkt);
if (nestegg_read_packet(input->nestegg_ctx, &input->pkt) <= 0
|| nestegg_packet_track(input->pkt, &track))
return 1;
} while (track != input->video_track);
if (nestegg_packet_count(input->pkt, &input->chunks))
return 1;
input->chunk = 0;
}
if (nestegg_packet_data(input->pkt, input->chunk, buf, buf_sz))
return 1;
input->chunk++;
return 0;
}
/* For both the raw and ivf formats, the frame size is the first 4 bytes
* of the frame header. We just need to special case on the header
* size.
*/
else if (fread(raw_hdr, kind == IVF_FILE
? IVF_FRAME_HDR_SZ : RAW_FRAME_HDR_SZ, 1, infile) != 1) {
if (!feof(infile))
fprintf(stderr, "Failed to read frame size\n");
new_buf_sz = 0;
} else {
new_buf_sz = mem_get_le32(raw_hdr);
if (new_buf_sz > 256 * 1024 * 1024) {
fprintf(stderr, "Error: Read invalid frame size (%u)\n",
(unsigned int)new_buf_sz);
new_buf_sz = 0;
}
if (kind == RAW_FILE && new_buf_sz > 256 * 1024)
fprintf(stderr, "Warning: Read invalid frame size (%u)"
" - not a raw file?\n", (unsigned int)new_buf_sz);
if (new_buf_sz > *buf_alloc_sz) {
uint8_t *new_buf = realloc(*buf, 2 * new_buf_sz);
if (new_buf) {
*buf = new_buf;
*buf_alloc_sz = 2 * new_buf_sz;
} else {
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
fprintf(stderr, "Failed to allocate compressed data buffer\n");
new_buf_sz = 0;
}
}
}
*buf_sz = new_buf_sz;
if (!feof(infile)) {
if (fread(*buf, 1, *buf_sz, infile) != *buf_sz) {
fprintf(stderr, "Failed to read full frame\n");
return 1;
}
return 0;
}
return 1;
}
void *out_open(const char *out_fn, int do_md5) {
void *out = NULL;
if (do_md5) {
#if CONFIG_MD5
MD5Context *md5_ctx = out = malloc(sizeof(MD5Context));
(void)out_fn;
MD5Init(md5_ctx);
#endif
} else {
FILE *outfile = out = strcmp("-", out_fn) ? fopen(out_fn, "wb")
: set_binary_mode(stdout);
if (!outfile) {
fprintf(stderr, "Failed to output file");
exit(EXIT_FAILURE);
}
}
return out;
}
void out_put(void *out, const uint8_t *buf, unsigned int len, int do_md5) {
if (do_md5) {
#if CONFIG_MD5
MD5Update(out, buf, len);
#endif
} else {
(void) fwrite(buf, 1, len, out);
}
}
void out_close(void *out, const char *out_fn, int do_md5) {
if (do_md5) {
#if CONFIG_MD5
uint8_t md5[16];
int i;
MD5Final(md5, out);
free(out);
for (i = 0; i < 16; i++)
printf("%02x", md5[i]);
printf(" %s\n", out_fn);
#endif
} else {
fclose(out);
}
}