Commit 03848f5c authored by Tom Finegan's avatar Tom Finegan

Move WebM writing support out of vpxenc.c.

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
parent dde8069e
......@@ -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
......
......@@ -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>
......@@ -20,6 +23,18 @@
#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__)
......@@ -27,3 +42,17 @@ FILE *set_binary_mode(FILE *stream) {
#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");
}
......@@ -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_
......@@ -50,8 +50,6 @@
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);
......@@ -59,10 +57,10 @@ static const struct {
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
};
......@@ -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"
......@@ -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;
......@@ -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);
......
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (c) 2013 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.
*/
#ifndef WEBMENC_H_
#define WEBMENC_H_
#include <stdio.h>
#include <stdlib.h>
#if defined(_MSC_VER)
/* MSVS doesn't define off_t */
typedef __int64 off_t;
#else
#include <stdint.h>
#endif
#include "tools_common.h"
#include "vpx/vpx_encoder.h"
typedef off_t EbmlLoc;
struct cue_entry {
unsigned int time;
uint64_t loc;
};
struct EbmlGlobal {
int debug;
FILE *stream;
int64_t last_pts_ms;
vpx_rational_t framerate;
/* These pointers are to the start of an element */
off_t position_reference;
off_t seek_info_pos;
off_t segment_info_pos;
off_t track_pos;
off_t cue_pos;
off_t cluster_pos;
/* This pointer is to a specific element to be serialized */
off_t track_id_pos;
/* These pointers are to the size field of the element */
EbmlLoc startSegment;
EbmlLoc startCluster;
uint32_t cluster_timecode;
int cluster_open;
struct cue_entry *cue_list;
unsigned int cues;
};
/* Stereo 3D packed frame format */
typedef enum stereo_format {
STEREO_FORMAT_MONO = 0,
STEREO_FORMAT_LEFT_RIGHT = 1,
STEREO_FORMAT_BOTTOM_TOP = 2,
STEREO_FORMAT_TOP_BOTTOM = 3,
STEREO_FORMAT_RIGHT_LEFT = 11
} stereo_format_t;
void write_webm_seek_element(struct EbmlGlobal *ebml,
unsigned int id,
off_t pos);
void write_webm_file_header(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const struct vpx_rational *fps,
stereo_format_t stereo_fmt,
unsigned int fourcc);
void write_webm_block(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const vpx_codec_cx_pkt_t *pkt);
void write_webm_file_footer(struct EbmlGlobal *glob, int hash);
#endif // WEBMENC_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment