Newer
Older
* 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.
#if defined(_WIN32) || defined(__OS2__) || !CONFIG_OS_SUPPORT
#define USE_POSIX_MMAP 0
#else
#define USE_POSIX_MMAP 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "vpx/vpx_encoder.h"
#if USE_POSIX_MMAP
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#endif
#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
#include "vpx/vp8cx.h"
#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
#include "vpx_ports/mem_ops.h"
#include "vpx_ports/vpx_timer.h"
#include "y4minput.h"
#include "libmkv/EbmlWriter.h"
#include "libmkv/EbmlIDs.h"
#include "third_party/libyuv/include/libyuv/scale.h"
/* Need special handling of these functions on Windows */
#if defined(_MSC_VER)
/* MSVS doesn't define off_t, and uses _f{seek,tell}i64 */
typedef __int64 off_t;
#define fseeko _fseeki64
#define ftello _ftelli64
#elif defined(_WIN32)
/* MinGW defines off_t as long
and uses f{seek,tell}o64/off64_t for large files */
#define fseeko fseeko64
#define ftello ftello64
#define LITERALU64(hi,lo) ((((uint64_t)hi)<<32)|lo)
/* We should use 32-bit file operations in WebM file format
* when building ARM executable file (.axf) with RVCT */
#if !CONFIG_OS_SUPPORT
typedef long off_t;
#define fseeko fseek
#define ftello ftell
#endif
/* Swallow warnings about unused results of fread/fwrite */
static size_t wrap_fread(void *ptr, size_t size, size_t nmemb,
FILE *stream) {
return fread(ptr, size, nmemb, stream);
}
#define fread wrap_fread
static size_t wrap_fwrite(const void *ptr, size_t size, size_t nmemb,
FILE *stream) {
return fwrite(ptr, size, nmemb, stream);
#define VP8_FOURCC (0x30385056)
#define VP9_FOURCC (0x30395056)
#if CONFIG_VP8_ENCODER && CONFIG_VP8_DECODER
{"vp8", &vpx_codec_vp8_cx, &vpx_codec_vp8_dx, VP8_FOURCC},
#elif CONFIG_VP8_ENCODER && !CONFIG_VP8_DECODER
{"vp8", &vpx_codec_vp8_cx, NULL, VP8_FOURCC},
{"vp9", &vpx_codec_vp9_cx, &vpx_codec_vp9_dx, VP9_FOURCC},
#elif CONFIG_VP9_ENCODER && !CONFIG_VP9_DECODER
{"vp9", &vpx_codec_vp9_cx, NULL, VP9_FOURCC},
#endif
};
static void usage_exit();
const char *l=label;\
va_list ap;\
va_start(ap, fmt);\
if(l)\
vfprintf(stderr, fmt, ap);\
fprintf(stderr, "\n");\
va_end(ap);\
void fatal(const char *fmt, ...) {
LOG_ERROR("Fatal");
exit(EXIT_FAILURE);
void warn(const char *fmt, ...) {
LOG_ERROR("Warning");
static void warn_or_exit_on_errorv(vpx_codec_ctx_t *ctx, int fatal,
const char *s, va_list ap) {
if (ctx->err) {
const char *detail = vpx_codec_error_detail(ctx);
vfprintf(stderr, s, ap);
fprintf(stderr, ": %s\n", vpx_codec_error(ctx));
if (fatal)
exit(EXIT_FAILURE);
static void ctx_exit_on_error(vpx_codec_ctx_t *ctx, const char *s, ...) {
va_list ap;
va_start(ap, s);
warn_or_exit_on_errorv(ctx, 1, s, ap);
va_end(ap);
}
static void warn_or_exit_on_error(vpx_codec_ctx_t *ctx, int fatal,
const char *s, ...) {
va_list ap;
va_start(ap, s);
warn_or_exit_on_errorv(ctx, fatal, s, ap);
va_end(ap);
}
/* This structure is used to abstract the different ways of handling
* first pass statistics.
*/
typedef struct {
vpx_fixed_buf_t buf;
int pass;
FILE *file;
char *buf_ptr;
size_t buf_alloc_sz;
int stats_open_file(stats_io_t *stats, const char *fpf, int pass) {
int res;
if (pass == 0) {
stats->file = fopen(fpf, "wb");
stats->buf.sz = 0;
stats->buf.buf = NULL,
res = (stats->file != NULL);
} else {
Loading full blame...