Skip to content

Commit

Permalink
Move WebM writing support out of vpxenc.c.
Browse files Browse the repository at this point in the history
This is mainly a clean up patchset. It moves the WebM writing support
out of vpxenc and into its own source file. Changes to tools_common and
vpxdec result from relocation of shared bits of code.

Change-Id: Iee55d3285f56e0a548f791094fb14c5ac5346a26
  • Loading branch information
tomfinegan committed Nov 6, 2013
1 parent dde8069 commit 03848f5
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 436 deletions.
1 change: 1 addition & 0 deletions examples.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ vpxdec.DESCRIPTION = Full featured decoder
UTILS-$(CONFIG_ENCODERS) += vpxenc.c
vpxenc.SRCS += args.c args.h y4minput.c y4minput.h
vpxenc.SRCS += tools_common.c tools_common.h
vpxenc.SRCS += webmenc.c webmenc.h
vpxenc.SRCS += vpx_ports/mem_ops.h
vpxenc.SRCS += vpx_ports/mem_ops_aligned.h
vpxenc.SRCS += vpx_ports/vpx_timer.h
Expand Down
31 changes: 30 additions & 1 deletion tools_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdio.h>
#include "tools_common.h"

#include <stdarg.h>
#include <stdlib.h>

#if defined(_WIN32) || defined(__OS2__)
#include <io.h>
#include <fcntl.h>
Expand All @@ -20,10 +23,36 @@
#endif
#endif

#define LOG_ERROR(label) do {\
const char *l = label;\
va_list ap;\
va_start(ap, fmt);\
if (l)\
fprintf(stderr, "%s: ", l);\
vfprintf(stderr, fmt, ap);\
fprintf(stderr, "\n");\
va_end(ap);\
} while (0)


FILE *set_binary_mode(FILE *stream) {
(void)stream;
#if defined(_WIN32) || defined(__OS2__)
_setmode(_fileno(stream), _O_BINARY);
#endif
return stream;
}

void die(const char *fmt, ...) {
LOG_ERROR(NULL);
usage_exit();
}

void fatal(const char *fmt, ...) {
LOG_ERROR("Fatal");
exit(EXIT_FAILURE);
}

void warn(const char *fmt, ...) {
LOG_ERROR("Warning");
}
20 changes: 17 additions & 3 deletions tools_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef TOOLS_COMMON_H
#define TOOLS_COMMON_H
#ifndef TOOLS_COMMON_H_
#define TOOLS_COMMON_H_

#include <stdio.h>

#define VP8_FOURCC (0x30385056)
#define VP9_FOURCC (0x30395056)
#define VP8_FOURCC_MASK (0x00385056)
#define VP9_FOURCC_MASK (0x00395056)

/* Sets a stdio stream into binary mode */
FILE *set_binary_mode(FILE *stream);

#endif
void die(const char *fmt, ...);
void fatal(const char *fmt, ...);
void warn(const char *fmt, ...);

/* The tool including this file must define usage_exit() */
void usage_exit();

#endif // TOOLS_COMMON_H_
20 changes: 5 additions & 15 deletions vpxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@

static const char *exec_name;

#define VP8_FOURCC (0x00385056)
#define VP9_FOURCC (0x00395056)
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, 0x00FFFFFF},
{"vp8", vpx_codec_vp8_dx, VP8_FOURCC_MASK, 0x00FFFFFF},
#endif
#if CONFIG_VP9_DECODER
{"vp9", vpx_codec_vp9_dx, VP9_FOURCC, 0x00FFFFFF},
{"vp9", vpx_codec_vp9_dx, VP9_FOURCC_MASK, 0x00FFFFFF},
#endif
};

Expand Down Expand Up @@ -143,7 +141,7 @@ static const arg_def_t *vp8_pp_args[] = {
};
#endif

static void usage_exit() {
void usage_exit() {
int i;

fprintf(stderr, "Usage: %s <options> filename\n\n"
Expand Down Expand Up @@ -178,14 +176,6 @@ static void usage_exit() {
exit(EXIT_FAILURE);
}

void die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
usage_exit();
}

static unsigned int mem_get_le16(const void *vmem) {
unsigned int val;
const unsigned char *mem = (const unsigned char *)vmem;
Expand Down Expand Up @@ -575,9 +565,9 @@ file_is_webm(struct input_ctx *input,

codec_id = nestegg_track_codec_id(input->nestegg_ctx, i);
if (codec_id == NESTEGG_CODEC_VP8) {
*fourcc = VP8_FOURCC;
*fourcc = VP8_FOURCC_MASK;
} else if (codec_id == NESTEGG_CODEC_VP9) {
*fourcc = VP9_FOURCC;
*fourcc = VP9_FOURCC_MASK;
} else {
fprintf(stderr, "Not VPx video, quitting.\n");
exit(1);
Expand Down
Loading

0 comments on commit 03848f5

Please sign in to comment.