Commit c6b9039f authored by John Koleszar's avatar John Koleszar

Restyle code

Approximate the Google style guide[1] so that that there's a written
document to follow and tools to check compliance[2].

[1]: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
[2]: http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py

Change-Id: Idf40e3d8dddcc72150f6af127b13e5dab838685f
parent 8697c6e4
......@@ -25,8 +25,7 @@ extern void die(const char *fmt, ...);
#endif
struct arg arg_init(char **argv)
{
struct arg arg_init(char **argv) {
struct arg a;
a.argv = argv;
......@@ -37,8 +36,7 @@ struct arg arg_init(char **argv)
return a;
}
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv)
{
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
struct arg arg;
if (!argv[0] || argv[0][0] != '-')
......@@ -48,23 +46,19 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv)
if (def->short_name
&& strlen(arg.argv[0]) == strlen(def->short_name) + 1
&& !strcmp(arg.argv[0] + 1, def->short_name))
{
&& !strcmp(arg.argv[0] + 1, def->short_name)) {
arg.name = arg.argv[0] + 1;
arg.val = def->has_val ? arg.argv[1] : NULL;
arg.argv_step = def->has_val ? 2 : 1;
}
else if (def->long_name)
{
} else if (def->long_name) {
int name_len = strlen(def->long_name);
if (strlen(arg.argv[0]) >= name_len + 2
&& arg.argv[0][1] == '-'
&& !strncmp(arg.argv[0] + 2, def->long_name, name_len)
&& (arg.argv[0][name_len+2] == '='
|| arg.argv[0][name_len+2] == '\0'))
{
&& (arg.argv[0][name_len + 2] == '='
|| arg.argv[0][name_len + 2] == '\0')) {
arg.name = arg.argv[0] + 2;
arg.val = arg.name[name_len] == '=' ? arg.name + name_len + 1 : NULL;
......@@ -79,8 +73,7 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv)
die("Error: option %s requires no argument.\n", arg.name);
if (arg.name
&& (arg.val || !def->has_val))
{
&& (arg.val || !def->has_val)) {
arg.def = def;
*arg_ = arg;
return 1;
......@@ -90,8 +83,7 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv)
}
const char *arg_next(struct arg *arg)
{
const char *arg_next(struct arg *arg) {
if (arg->argv[0])
arg->argv += arg->argv_step;
......@@ -99,8 +91,7 @@ const char *arg_next(struct arg *arg)
}
char **argv_dup(int argc, const char **argv)
{
char **argv_dup(int argc, const char **argv) {
char **new_argv = malloc((argc + 1) * sizeof(*argv));
memcpy(new_argv, argv, argc * sizeof(*argv));
......@@ -109,25 +100,21 @@ char **argv_dup(int argc, const char **argv)
}
void arg_show_usage(FILE *fp, const struct arg_def *const *defs)
{
void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
char option_text[40] = {0};
for (; *defs; defs++)
{
for (; *defs; defs++) {
const struct arg_def *def = *defs;
char *short_val = def->has_val ? " <arg>" : "";
char *long_val = def->has_val ? "=<arg>" : "";
if (def->short_name && def->long_name)
{
if (def->short_name && def->long_name) {
char *comma = def->has_val ? "," : ", ";
snprintf(option_text, 37, "-%s%s%s --%s%6s",
def->short_name, short_val, comma,
def->long_name, long_val);
}
else if (def->short_name)
} else if (def->short_name)
snprintf(option_text, 37, "-%s%s",
def->short_name, short_val);
else if (def->long_name)
......@@ -136,13 +123,12 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs)
fprintf(fp, " %-37s\t%s\n", option_text, def->desc);
if(def->enums)
{
if (def->enums) {
const struct arg_enum_list *listptr;
fprintf(fp, " %-37s\t ", "");
for(listptr = def->enums; listptr->name; listptr++)
for (listptr = def->enums; listptr->name; listptr++)
fprintf(fp, "%s%s", listptr->name,
listptr[1].name ? ", " : "\n");
}
......@@ -150,15 +136,13 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs)
}
unsigned int arg_parse_uint(const struct arg *arg)
{
unsigned int arg_parse_uint(const struct arg *arg) {
long int rawval;
char *endptr;
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0')
{
if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= 0 && rawval <= UINT_MAX)
return rawval;
......@@ -171,15 +155,13 @@ unsigned int arg_parse_uint(const struct arg *arg)
}
int arg_parse_int(const struct arg *arg)
{
int arg_parse_int(const struct arg *arg) {
long int rawval;
char *endptr;
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0')
{
if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX)
return rawval;
......@@ -192,13 +174,11 @@ int arg_parse_int(const struct arg *arg)
}
struct vpx_rational
{
struct vpx_rational {
int num; /**< fraction numerator */
int den; /**< fraction denominator */
};
struct vpx_rational arg_parse_rational(const struct arg *arg)
{
struct vpx_rational arg_parse_rational(const struct arg *arg) {
long int rawval;
char *endptr;
struct vpx_rational rat;
......@@ -206,50 +186,44 @@ struct vpx_rational arg_parse_rational(const struct arg *arg)
/* parse numerator */
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '/')
{
if (arg->val[0] != '\0' && endptr[0] == '/') {
if (rawval >= INT_MIN && rawval <= INT_MAX)
rat.num = rawval;
else die("Option %s: Value %ld out of range for signed int\n",
arg->name, rawval);
}
else die("Option %s: Expected / at '%c'\n", arg->name, *endptr);
} else die("Option %s: Expected / at '%c'\n", arg->name, *endptr);
/* parse denominator */
rawval = strtol(endptr + 1, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0')
{
if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX)
rat.den = rawval;
else die("Option %s: Value %ld out of range for signed int\n",
arg->name, rawval);
}
else die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
} else die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
return rat;
}
int arg_parse_enum(const struct arg *arg)
{
int arg_parse_enum(const struct arg *arg) {
const struct arg_enum_list *listptr;
long int rawval;
char *endptr;
/* First see if the value can be parsed as a raw value */
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0')
{
if (arg->val[0] != '\0' && endptr[0] == '\0') {
/* Got a raw value, make sure it's valid */
for(listptr = arg->def->enums; listptr->name; listptr++)
if(listptr->val == rawval)
for (listptr = arg->def->enums; listptr->name; listptr++)
if (listptr->val == rawval)
return rawval;
}
/* Next see if it can be parsed as a string */
for(listptr = arg->def->enums; listptr->name; listptr++)
if(!strcmp(arg->val, listptr->name))
for (listptr = arg->def->enums; listptr->name; listptr++)
if (!strcmp(arg->val, listptr->name))
return listptr->val;
die("Option %s: Invalid value '%s'\n", arg->name, arg->val);
......@@ -257,9 +231,8 @@ int arg_parse_enum(const struct arg *arg)
}
int arg_parse_enum_or_int(const struct arg *arg)
{
if(arg->def->enums)
int arg_parse_enum_or_int(const struct arg *arg) {
if (arg->def->enums)
return arg_parse_enum(arg);
return arg_parse_int(arg);
}
......@@ -13,8 +13,7 @@
#define ARGS_H
#include <stdio.h>
struct arg
{
struct arg {
char **argv;
const char *name;
const char *val;
......@@ -22,15 +21,13 @@ struct arg
const struct arg_def *def;
};
struct arg_enum_list
{
struct arg_enum_list {
const char *name;
int val;
};
#define ARG_ENUM_LIST_END {0}
typedef struct arg_def
{
typedef struct arg_def {
const char *short_name;
const char *long_name;
int has_val;
......
This diff is collapsed.
......@@ -25,19 +25,16 @@
static char *exec_name;
static int verbose = 0;
static const struct
{
static const struct {
const char *name;
const vpx_codec_iface_t *iface;
} ifaces[] =
{
} ifaces[] = {
#if CONFIG_VP8_DECODER
{"vp8", &vpx_codec_vp8_dx_algo},
#endif
};
static void usage_exit(void)
{
static void usage_exit(void) {
int i;
printf("Usage: %s <options>\n\n"
......@@ -61,8 +58,7 @@ static void usage_exit(void)
exit(EXIT_FAILURE);
}
static void usage_error(const char *fmt, ...)
{
static void usage_error(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
......@@ -70,16 +66,14 @@ static void usage_error(const char *fmt, ...)
usage_exit();
}
void my_mem_dtor(vpx_codec_mmap_t *mmap)
{
void my_mem_dtor(vpx_codec_mmap_t *mmap) {
if (verbose)
printf("freeing segment %d\n", mmap->id);
free(mmap->priv);
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
vpx_codec_ctx_t decoder;
vpx_codec_iface_t *iface = ifaces[0].iface;
vpx_codec_iter_t iter;
......@@ -92,12 +86,9 @@ int main(int argc, char **argv)
exec_name = argv[0];
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--codec"))
{
if (i + 1 < argc)
{
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--codec")) {
if (i + 1 < argc) {
int j, k = -1;
i++;
......@@ -111,25 +102,19 @@ int main(int argc, char **argv)
else
usage_error("Error: Unrecognized argument (%s) to --codec\n",
argv[i]);
}
else
} else
usage_error("Error: Option --codec requires argument.\n");
}
else if (!strcmp(argv[i], "-v"))
} else if (!strcmp(argv[i], "-v"))
verbose = 1;
else if (!strcmp(argv[i], "-h"))
if (i + 1 < argc)
{
if (i + 1 < argc) {
h = atoi(argv[++i]);
}
else
} else
usage_error("Error: Option -h requires argument.\n");
else if (!strcmp(argv[i], "-w"))
if (i + 1 < argc)
{
if (i + 1 < argc) {
w = atoi(argv[++i]);
}
else
} else
usage_error("Error: Option -w requires argument.\n");
else if (!strcmp(argv[i], "--help"))
usage_exit();
......@@ -141,8 +126,7 @@ int main(int argc, char **argv)
printf("Using built-in defaults. For options, rerun with --help\n\n");
/* XMA mode is not supported on all decoders! */
if (!(vpx_codec_get_caps(iface) & VPX_CODEC_CAP_XMA))
{
if (!(vpx_codec_get_caps(iface) & VPX_CODEC_CAP_XMA)) {
printf("%s does not support XMA mode!\n", vpx_codec_iface_name(iface));
return EXIT_FAILURE;
}
......@@ -157,8 +141,7 @@ int main(int argc, char **argv)
cfg.h = h;
/* Initialize the decoder in XMA mode. */
if (vpx_codec_dec_init(&decoder, iface, &cfg, VPX_CODEC_USE_XMA))
{
if (vpx_codec_dec_init(&decoder, iface, &cfg, VPX_CODEC_USE_XMA)) {
printf("Failed to initialize decoder in XMA mode: %s\n", vpx_codec_error(&decoder));
return EXIT_FAILURE;
}
......@@ -168,16 +151,14 @@ int main(int argc, char **argv)
*/
iter = NULL;
do
{
do {
vpx_codec_mmap_t mmap;
unsigned int align;
res = vpx_codec_get_mem_map(&decoder, &mmap, &iter);
align = mmap.align ? mmap.align - 1 : 0;
if (!res)
{
if (!res) {
if (verbose)
printf("Allocating segment %u, size %lu, align %u %s\n",
mmap.id, mmap.sz, mmap.align,
......@@ -192,19 +173,15 @@ int main(int argc, char **argv)
mmap.dtor = my_mem_dtor;
alloc_sz += mmap.sz + align;
if (vpx_codec_set_mem_map(&decoder, &mmap, 1))
{
if (vpx_codec_set_mem_map(&decoder, &mmap, 1)) {
printf("Failed to set mmap: %s\n", vpx_codec_error(&decoder));
return EXIT_FAILURE;
}
}
else if (res != VPX_CODEC_LIST_END)
{
} else if (res != VPX_CODEC_LIST_END) {
printf("Failed to get mmap: %s\n", vpx_codec_error(&decoder));
return EXIT_FAILURE;
}
}
while (res != VPX_CODEC_LIST_END);
} while (res != VPX_CODEC_LIST_END);
printf("%s\n %d bytes external memory required for %dx%d.\n",
decoder.name, alloc_sz, cfg.w, cfg.h);
......
//#include <strmif.h>
// #include <strmif.h>
#include "EbmlBufferWriter.h"
#include "EbmlWriter.h"
//#include <cassert>
//#include <limits>
//#include <malloc.h> //_alloca
// #include <cassert>
// #include <limits>
// #include <malloc.h> //_alloca
#include <stdlib.h>
#include <wchar.h>
#include <string.h>
void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len)
{
void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len) {
unsigned char *src = glob->buf;
src += glob->offset;
memcpy(src, buffer_in, len);
glob->offset += len;
}
static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned char *q)
{
while (q != p)
{
static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned char *q) {
while (q != p) {
--q;
unsigned long cbWritten;
memcpy(&(glob->buf[glob->offset]), q, 1);
glob->offset ++;
glob->offset++;
}
}
void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len)
{
//assert(buf);
void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) {
// assert(buf);
const unsigned char *const p = (const unsigned char *)(buffer_in);
const unsigned char *const q = p + len;
......@@ -39,17 +35,15 @@ void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len)
}
void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long class_id)
{
void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long class_id) {
Ebml_WriteID(glob, class_id);
ebmlLoc->offset = glob->offset;
//todo this is always taking 8 bytes, this may need later optimization
// todo this is always taking 8 bytes, this may need later optimization
unsigned long long unknownLen = 0x01FFFFFFFFFFFFFFLLU;
Ebml_Serialize(glob, (void *)&unknownLen, 8); //this is a key that says lenght unknown
Ebml_Serialize(glob, (void *)&unknownLen, 8); // this is a key that says lenght unknown
}
void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc)
{
void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc) {
unsigned long long size = glob->offset - ebmlLoc->offset - 8;
unsigned long long curOffset = glob->offset;
glob->offset = ebmlLoc->offset;
......
#ifndef EBMLBUFFERWRITER_HPP
#define EBMLBUFFERWRITER_HPP
typedef struct
{
typedef struct {
unsigned long long offset;
} EbmlLoc;
typedef struct
{
typedef struct {
unsigned char *buf;
unsigned int length;
unsigned int offset;
......
......@@ -10,10 +10,9 @@
#ifndef MKV_DEFS_HPP
#define MKV_DEFS_HPP 1
//Commenting out values not available in webm, but available in matroska
// Commenting out values not available in webm, but available in matroska
enum mkv
{
enum mkv {
EBML = 0x1A45DFA3,
EBMLVersion = 0x4286,
EBMLReadVersion = 0x42F7,
......@@ -32,14 +31,14 @@ enum mkv
SignatureElements = 0x7E5B,
SignatureElementList = 0x7E7B,
SignedElement = 0x6532,
//segment
// segment
Segment = 0x18538067,
//Meta Seek Information
// Meta Seek Information
SeekHead = 0x114D9B74,
Seek = 0x4DBB,
SeekID = 0x53AB,
SeekPosition = 0x53AC,
//Segment Information
// Segment Information
Info = 0x1549A966,
// SegmentUID = 0x73A4,
// SegmentFilename = 0x7384,
......@@ -58,7 +57,7 @@ enum mkv
// Title = 0x7BA9,
MuxingApp = 0x4D80,
WritingApp = 0x5741,
//Cluster
// Cluster
Cluster = 0x1F43B675,
Timecode = 0xE7,
// SilentTracks = 0x5854,
......@@ -86,7 +85,7 @@ enum mkv
// Cluster_Duration = 0xCF,
SimpleBlock = 0xA3,
// EncryptedBlock = 0xAF,
//Track
// Track
Tracks = 0x1654AE6B,
TrackEntry = 0xAE,
TrackNumber = 0xD7,
......@@ -117,7 +116,7 @@ enum mkv
// TrackTranslateEditionUID = 0x66FC,
// TrackTranslateCodec = 0x66BF,
// TrackTranslateTrackID = 0x66A5,
//video
// video
Video = 0xE0,
FlagInterlaced = 0x9A,
StereoMode = 0x53B8,
......@@ -134,16 +133,16 @@ enum mkv
// ColourSpace = 0x2EB524,
// GammaValue = 0x2FB523,
FrameRate = 0x2383E3,
//end video
//audio
// end video
// audio
Audio = 0xE1,
SamplingFrequency = 0xB5,
OutputSamplingFrequency = 0x78B5,
Channels = 0x9F,
// ChannelPositions = 0x7D7B,
BitDepth = 0x6264,
//end audio
//content encoding
// end audio
// content encoding
// ContentEncodings = 0x6d80,
// ContentEncoding = 0x6240,
// ContentEncodingOrder = 0x5031,
......@@ -159,8 +158,8 @@ enum mkv
// ContentSigKeyID = 0x47e4,
// ContentSigAlgo = 0x47e5,
// ContentSigHashAlgo = 0x47e6,
//end content encoding
//Cueing Data
// end content encoding
// Cueing Data
Cues = 0x1C53BB6B,
CuePoint = 0xBB,
CueTime = 0xB3,
......@@ -174,7 +173,7 @@ enum mkv
// CueRefCluster = 0x97,
// CueRefNumber = 0x535F,
// CueRefCodecState = 0xEB,
//Attachment
// Attachment
// Attachments = 0x1941A469,
// AttachedFile = 0x61A7,
// FileDescription = 0x467E,
......@@ -183,7 +182,7 @@ enum mkv
// FileData = 0x465C,
// FileUID = 0x46AE,
// FileReferral = 0x4675,
//Chapters
// Chapters
// Chapters = 0x1043A770,
// EditionEntry = 0x45B9,
// EditionUID = 0x45BC,
......@@ -211,7 +210,7 @@ enum mkv
// ChapProcessCommand = 0x6911,
// ChapProcessTime = 0x6922,
// ChapProcessData = 0x6933,
//Tagging
// Tagging
// Tags = 0x1254C367,
// Tag = 0x7373,
// Targets = 0x63C0,
......
......@@ -18,14 +18,12 @@
#define LITERALU64(n) n##LLU
#endif
void Ebml_WriteLen(EbmlGlobal *glob, long long val)
{
//TODO check and make sure we are not > than 0x0100000000000000LLU
unsigned char size = 8; //size in bytes to output
unsigned long long minVal = LITERALU64(0x00000000000000ff); //mask to compare for byte size
for (size = 1; size < 8; size ++)
{
void Ebml_WriteLen(EbmlGlobal *glob, long long val) {
// TODO check and make sure we are not > than 0x0100000000000000LLU
unsigned char size = 8; // size in bytes to output
unsigned long long minVal = LITERALU64(0x00000000000000ff); // mask to compare for byte size
for (size = 1; size < 8; size ++) {
if (val < minVal)
break;