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
This diff is collapsed.
...@@ -13,29 +13,26 @@ ...@@ -13,29 +13,26 @@
#define ARGS_H #define ARGS_H
#include <stdio.h> #include <stdio.h>
struct arg struct arg {
{ char **argv;
char **argv; const char *name;
const char *name; const char *val;
const char *val; unsigned int argv_step;
unsigned int argv_step; const struct arg_def *def;
const struct arg_def *def;
}; };
struct arg_enum_list struct arg_enum_list {
{ const char *name;
const char *name; int val;
int val;
}; };
#define ARG_ENUM_LIST_END {0} #define ARG_ENUM_LIST_END {0}
typedef struct arg_def typedef struct arg_def {
{ const char *short_name;
const char *short_name; const char *long_name;
const char *long_name; int has_val;
int has_val; const char *desc;
const char *desc; const struct arg_enum_list *enums;
const struct arg_enum_list *enums;
} arg_def_t; } arg_def_t;
#define ARG_DEF(s,l,v,d) {s,l,v,d, NULL} #define ARG_DEF(s,l,v,d) {s,l,v,d, NULL}
#define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e} #define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e}
......
This diff is collapsed.
This diff is collapsed.
//#include <strmif.h> // #include <strmif.h>
#include "EbmlBufferWriter.h" #include "EbmlBufferWriter.h"
#include "EbmlWriter.h" #include "EbmlWriter.h"
//#include <cassert> // #include <cassert>
//#include <limits> // #include <limits>
//#include <malloc.h> //_alloca // #include <malloc.h> //_alloca
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#include <string.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;
unsigned char *src = glob->buf; src += glob->offset;
src += glob->offset; memcpy(src, buffer_in, len);
memcpy(src, buffer_in, len); glob->offset += len;
glob->offset += len;
} }
static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned char *q) static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned char *q) {
{ while (q != p) {
while (q != p) --q;
{
--q;
unsigned long cbWritten; unsigned long cbWritten;
memcpy(&(glob->buf[glob->offset]), q, 1); memcpy(&(glob->buf[glob->offset]), q, 1);
glob->offset ++; glob->offset++;
} }
} }
void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) {
{ // assert(buf);
//assert(buf);
const unsigned char *const p = (const unsigned char *)(buffer_in); const unsigned char *const p = (const unsigned char *)(buffer_in);
const unsigned char *const q = p + len; const unsigned char *const q = p + len;
_Serialize(glob, p, q); _Serialize(glob, p, q);
} }
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);
Ebml_WriteID(glob, class_id); ebmlLoc->offset = glob->offset;
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;
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 size = glob->offset - ebmlLoc->offset - 8; unsigned long long curOffset = glob->offset;
unsigned long long curOffset = glob->offset; glob->offset = ebmlLoc->offset;
glob->offset = ebmlLoc->offset; size |= 0x0100000000000000LLU;
size |= 0x0100000000000000LLU; Ebml_Serialize(glob, &size, 8);
Ebml_Serialize(glob, &size, 8); glob->offset = curOffset;
glob->offset = curOffset;
} }
#ifndef EBMLBUFFERWRITER_HPP #ifndef EBMLBUFFERWRITER_HPP
#define EBMLBUFFERWRITER_HPP #define EBMLBUFFERWRITER_HPP
typedef struct typedef struct {
{ unsigned long long offset;
unsigned long long offset;
} EbmlLoc; } EbmlLoc;
typedef struct typedef struct {
{ unsigned char *buf;
unsigned char *buf; unsigned int length;
unsigned int length; unsigned int offset;
unsigned int offset;
} EbmlGlobal; } EbmlGlobal;
......
...@@ -10,37 +10,36 @@ ...@@ -10,37 +10,36 @@
#ifndef MKV_DEFS_HPP #ifndef MKV_DEFS_HPP
#define MKV_DEFS_HPP 1 #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,
EBML = 0x1A45DFA3, EBMLVersion = 0x4286,
EBMLVersion = 0x4286, EBMLReadVersion = 0x42F7,
EBMLReadVersion = 0x42F7, EBMLMaxIDLength = 0x42F2,
EBMLMaxIDLength = 0x42F2, EBMLMaxSizeLength = 0x42F3,
EBMLMaxSizeLength = 0x42F3, DocType = 0x4282,
DocType = 0x4282, DocTypeVersion = 0x4287,
DocTypeVersion = 0x4287, DocTypeReadVersion = 0x4285,
DocTypeReadVersion = 0x4285,
// CRC_32 = 0xBF, // CRC_32 = 0xBF,
Void = 0xEC, Void = 0xEC,
SignatureSlot = 0x1B538667, SignatureSlot = 0x1B538667,
SignatureAlgo = 0x7E8A, SignatureAlgo = 0x7E8A,
SignatureHash = 0x7E9A, SignatureHash = 0x7E9A,
SignaturePublicKey = 0x7EA5, SignaturePublicKey = 0x7EA5,
Signature = 0x7EB5, Signature = 0x7EB5,
SignatureElements = 0x7E5B, SignatureElements = 0x7E5B,
SignatureElementList = 0x7E7B, SignatureElementList = 0x7E7B,
SignedElement = 0x6532, SignedElement = 0x6532,
//segment // segment
Segment = 0x18538067, Segment = 0x18538067,
//Meta Seek Information // Meta Seek Information
SeekHead = 0x114D9B74, SeekHead = 0x114D9B74,
Seek = 0x4DBB, Seek = 0x4DBB,
SeekID = 0x53AB, SeekID = 0x53AB,
SeekPosition = 0x53AC, SeekPosition = 0x53AC,
//Segment Information // Segment Information
Info = 0x1549A966, Info = 0x1549A966,
// SegmentUID = 0x73A4, // SegmentUID = 0x73A4,
// SegmentFilename = 0x7384, // SegmentFilename = 0x7384,
// PrevUID = 0x3CB923, // PrevUID = 0x3CB923,
...@@ -52,61 +51,61 @@ enum mkv ...@@ -52,61 +51,61 @@ enum mkv
// ChapterTranslateEditionUID = 0x69FC, // ChapterTranslateEditionUID = 0x69FC,
// ChapterTranslateCodec = 0x69BF, // ChapterTranslateCodec = 0x69BF,
// ChapterTranslateID = 0x69A5, // ChapterTranslateID = 0x69A5,
TimecodeScale = 0x2AD7B1, TimecodeScale = 0x2AD7B1,
Segment_Duration = 0x4489, Segment_Duration = 0x4489,
DateUTC = 0x4461, DateUTC = 0x4461,
// Title = 0x7BA9, // Title = 0x7BA9,
MuxingApp = 0x4D80, MuxingApp = 0x4D80,
WritingApp = 0x5741, WritingApp = 0x5741,
//Cluster // Cluster
Cluster = 0x1F43B675, Cluster = 0x1F43B675,
Timecode = 0xE7, Timecode = 0xE7,
// SilentTracks = 0x5854, // SilentTracks = 0x5854,
// SilentTrackNumber = 0x58D7, // SilentTrackNumber = 0x58D7,
// Position = 0xA7, // Position = 0xA7,
PrevSize = 0xAB, PrevSize = 0xAB,
BlockGroup = 0xA0, BlockGroup = 0xA0,
Block = 0xA1, Block = 0xA1,
// BlockVirtual = 0xA2, // BlockVirtual = 0xA2,
// BlockAdditions = 0x75A1, // BlockAdditions = 0x75A1,
// BlockMore = 0xA6, // BlockMore = 0xA6,
// BlockAddID = 0xEE, // BlockAddID = 0xEE,
// BlockAdditional = 0xA5, // BlockAdditional = 0xA5,
BlockDuration = 0x9B, BlockDuration = 0x9B,
// ReferencePriority = 0xFA, // ReferencePriority = 0xFA,
ReferenceBlock = 0xFB, ReferenceBlock = 0xFB,
// ReferenceVirtual = 0xFD, // ReferenceVirtual = 0xFD,
// CodecState = 0xA4, // CodecState = 0xA4,
// Slices = 0x8E, // Slices = 0x8E,
// TimeSlice = 0xE8, // TimeSlice = 0xE8,
LaceNumber = 0xCC, LaceNumber = 0xCC,
// FrameNumber = 0xCD, // FrameNumber = 0xCD,
// BlockAdditionID = 0xCB, // BlockAdditionID = 0xCB,
// MkvDelay = 0xCE, // MkvDelay = 0xCE,
// Cluster_Duration = 0xCF, // Cluster_Duration = 0xCF,
SimpleBlock = 0xA3, SimpleBlock = 0xA3,
// EncryptedBlock = 0xAF, // EncryptedBlock = 0xAF,
//Track // Track
Tracks = 0x1654AE6B, Tracks = 0x1654AE6B,
TrackEntry = 0xAE, TrackEntry = 0xAE,
TrackNumber = 0xD7, TrackNumber = 0xD7,
TrackUID = 0x73C5, TrackUID = 0x73C5,
TrackType = 0x83, TrackType = 0x83,
FlagEnabled = 0xB9, FlagEnabled = 0xB9,
FlagDefault = 0x88, FlagDefault = 0x88,
FlagForced = 0x55AA, FlagForced = 0x55AA,
FlagLacing = 0x9C, FlagLacing = 0x9C,
// MinCache = 0x6DE7, // MinCache = 0x6DE7,
// MaxCache = 0x6DF8, // MaxCache = 0x6DF8,
DefaultDuration = 0x23E383, DefaultDuration = 0x23E383,
// TrackTimecodeScale = 0x23314F, // TrackTimecodeScale = 0x23314F,
// TrackOffset = 0x537F, // TrackOffset = 0x537F,
// MaxBlockAdditionID = 0x55EE, // MaxBlockAdditionID = 0x55EE,
Name = 0x536E, Name = 0x536E,
Language = 0x22B59C, Language = 0x22B59C,
CodecID = 0x86, CodecID = 0x86,
CodecPrivate = 0x63A2, CodecPrivate = 0x63A2,
CodecName = 0x258688, CodecName = 0x258688,
// AttachmentLink = 0x7446, // AttachmentLink = 0x7446,
// CodecSettings = 0x3A9697, // CodecSettings = 0x3A9697,
// CodecInfoURL = 0x3B4040, // CodecInfoURL = 0x3B4040,
...@@ -117,33 +116,33 @@ enum mkv ...@@ -117,33 +116,33 @@ enum mkv
// TrackTranslateEditionUID = 0x66FC, // TrackTranslateEditionUID = 0x66FC,
// TrackTranslateCodec = 0x66BF, // TrackTranslateCodec = 0x66BF,
// TrackTranslateTrackID = 0x66A5, // TrackTranslateTrackID = 0x66A5,
//video // video
Video = 0xE0, Video = 0xE0,
FlagInterlaced = 0x9A, FlagInterlaced = 0x9A,
StereoMode = 0x53B8, StereoMode = 0x53B8,
PixelWidth = 0xB0, PixelWidth = 0xB0,
PixelHeight = 0xBA, PixelHeight = 0xBA,
PixelCropBottom = 0x54AA, PixelCropBottom = 0x54AA,
PixelCropTop = 0x54BB, PixelCropTop = 0x54BB,
PixelCropLeft = 0x54CC, PixelCropLeft = 0x54CC,
PixelCropRight = 0x54DD, PixelCropRight = 0x54DD,
DisplayWidth = 0x54B0, DisplayWidth = 0x54B0,
DisplayHeight = 0x54BA, DisplayHeight = 0x54BA,
DisplayUnit = 0x54B2, DisplayUnit = 0x54B2,
AspectRatioType = 0x54B3, AspectRatioType = 0x54B3,
// ColourSpace = 0x2EB524, // ColourSpace = 0x2EB524,
// GammaValue = 0x2FB523, // GammaValue = 0x2FB523,
FrameRate = 0x2383E3, FrameRate = 0x2383E3,
//end video // end video
//audio // audio
Audio = 0xE1, Audio = 0xE1,
SamplingFrequency = 0xB5, SamplingFrequency = 0xB5,
OutputSamplingFrequency = 0x78B5, OutputSamplingFrequency = 0x78B5,
Channels = 0x9F, Channels = 0x9F,
// ChannelPositions = 0x7D7B, // ChannelPositions = 0x7D7B,
BitDepth = 0x6264, BitDepth = 0x6264,
//end audio // end audio
//content encoding // content encoding
// ContentEncodings = 0x6d80, // ContentEncodings = 0x6d80,
// ContentEncoding = 0x6240, // ContentEncoding = 0x6240,
// ContentEncodingOrder = 0x5031, // ContentEncodingOrder = 0x5031,
...@@ -159,22 +158,22 @@ enum mkv ...@@ -159,22 +158,22 @@ enum mkv
// ContentSigKeyID = 0x47e4, // ContentSigKeyID = 0x47e4,
// ContentSigAlgo = 0x47e5, // ContentSigAlgo = 0x47e5,
// ContentSigHashAlgo = 0x47e6, // ContentSigHashAlgo = 0x47e6,
//end content encoding // end content encoding
//Cueing Data // Cueing Data
Cues = 0x1C53BB6B, Cues = 0x1C53BB6B,
CuePoint = 0xBB, CuePoint = 0xBB,
CueTime = 0xB3, CueTime = 0xB3,
CueTrackPositions = 0xB7, CueTrackPositions = 0xB7,
CueTrack = 0xF7, CueTrack = 0xF7,
CueClusterPosition = 0xF1, CueClusterPosition = 0xF1,
CueBlockNumber = 0x5378, CueBlockNumber = 0x5378,
// CueCodecState = 0xEA, // CueCodecState = 0xEA,
// CueReference = 0xDB, // CueReference = 0xDB,
// CueRefTime = 0x96, // CueRefTime = 0x96,
// CueRefCluster = 0x97, // CueRefCluster = 0x97,
// CueRefNumber = 0x535F, // CueRefNumber = 0x535F,
// CueRefCodecState = 0xEB, // CueRefCodecState = 0xEB,
//Attachment // Attachment
// Attachments = 0x1941A469, // Attachments = 0x1941A469,
// AttachedFile = 0x61A7, // AttachedFile = 0x61A7,
// FileDescription = 0x467E, // FileDescription = 0x467E,
...@@ -183,7 +182,7 @@ enum mkv ...@@ -183,7 +182,7 @@ enum mkv
// FileData = 0x465C, // FileData = 0x465C,
// FileUID = 0x46AE, // FileUID = 0x46AE,
// FileReferral = 0x4675, // FileReferral = 0x4675,
//Chapters // Chapters
// Chapters = 0x1043A770, // Chapters = 0x1043A770,
// EditionEntry = 0x45B9, // EditionEntry = 0x45B9,
// EditionUID = 0x45BC, // EditionUID = 0x45BC,
...@@ -211,7 +210,7 @@ enum mkv ...@@ -211,7 +210,7 @@ enum mkv
// ChapProcessCommand = 0x6911, // ChapProcessCommand = 0x6911,
// ChapProcessTime = 0x6922, // ChapProcessTime = 0x6922,
// ChapProcessData = 0x6933, // ChapProcessData = 0x6933,
//Tagging // Tagging
// Tags = 0x1254C367, // Tags = 0x1254C367,
// Tag = 0x7373, // Tag = 0x7373,
// Targets = 0x63C0, // Targets = 0x63C0,
......
...@@ -18,154 +18,136 @@ ...@@ -18,154 +18,136 @@
#define LITERALU64(n) n##LLU #define LITERALU64(n) n##LLU
#endif #endif
void Ebml_WriteLen(EbmlGlobal *glob, long long val) void Ebml_WriteLen(EbmlGlobal *glob, long long val) {
{ // TODO check and make sure we are not > than 0x0100000000000000LLU
//TODO check and make sure we are not > than 0x0100000000000000LLU unsigned char size = 8; // size in bytes to output
unsigned char size = 8; //size in bytes to output unsigned long long minVal = LITERALU64(0x00000000000000ff); // mask to compare for byte size
unsigned long long minVal = LITERALU64(0x00000000000000ff); //mask to compare for byte size
for (size = 1; size < 8; size ++) {
for (size = 1; size < 8; size ++) if (val < minVal)
{ break;
if (val < minVal)
break;
minVal = (minVal << 7);
}
val |= (LITERALU64(0x000000000000080) << ((size - 1) * 7)); minVal = (minVal << 7);
}
Ebml_Serialize(glob, (void *) &val, sizeof(val), size); val |= (LITERALU64(0x000000000000080) << ((size - 1) * 7));
Ebml_Serialize(glob, (void *) &val, sizeof(val), size);
} }
void Ebml_WriteString(EbmlGlobal *glob, const char *str) void Ebml_WriteString(EbmlGlobal *glob, const char *str) {
{ const size_t size_ = strlen(str);
const size_t size_ = strlen(str); const unsigned long long size = size_;
const unsigned long long size = size_; Ebml_WriteLen(glob, size);
Ebml_WriteLen(glob, size); // TODO: it's not clear from the spec whether the nul terminator
//TODO: it's not clear from the spec whether the nul terminator // should be serialized too. For now we omit the null terminator.
//should be serialized too. For now we omit the null terminator. Ebml_Write(glob, str, size);
Ebml_Write(glob, str, size);
} }
void Ebml_WriteUTF8(EbmlGlobal *glob, const wchar_t *wstr) void Ebml_WriteUTF8(EbmlGlobal *glob, const wchar_t *wstr) {
{ const size_t strlen = wcslen(wstr);
const size_t strlen = wcslen(wstr);
//TODO: it's not clear from the spec whether the nul terminator // TODO: it's not clear from the spec whether the nul terminator
//should be serialized too. For now we include it. // should be serialized too. For now we include it.
const unsigned long long size = strlen; const unsigned long long size = strlen;
Ebml_WriteLen(glob, size); Ebml_WriteLen(glob, size);
Ebml_Write(glob, wstr, size); Ebml_Write(glob, wstr, size);
} }
void Ebml_WriteID(EbmlGlobal *glob, unsigned long class_id) void Ebml_WriteID(EbmlGlobal *glob, unsigned long class_id) {
{ int len;
int len;
if (class_id >= 0x01000000) if (class_id >= 0x01000000)
len = 4; len = 4;
else if (class_id >= 0x00010000) else if (class_id >= 0x00010000)
len = 3; len = 3;
else if (class_id >= 0x00000100) else if (class_id >= 0x00000100)
len = 2; len = 2;
else else
len = 1; len = 1;
Ebml_Serialize(glob, (void *)&class_id, sizeof(class_id), len); Ebml_Serialize(glob, (void *)&class_id, sizeof(class_id), len);
} }
void Ebml_SerializeUnsigned64(EbmlGlobal *glob, unsigned long class_id, uint64_t ui) void Ebml_SerializeUnsigned64(EbmlGlobal *glob, unsigned long class_id, uint64_t ui) {
{ unsigned char sizeSerialized = 8 | 0x80;
unsigned char sizeSerialized = 8 | 0x80; Ebml_WriteID(glob, class_id);
Ebml_WriteID(glob, class_id); Ebml_Serialize(glob, &sizeSerialized, sizeof(sizeSerialized), 1);
Ebml_Serialize(glob, &sizeSerialized, sizeof(sizeSerialized), 1); Ebml_Serialize(glob, &ui, sizeof(ui), 8);
Ebml_Serialize(glob, &ui, sizeof(ui), 8);
} }
void Ebml_SerializeUnsigned(EbmlGlobal *glob, unsigned long class_id, unsigned long ui) void Ebml_SerializeUnsigned(EbmlGlobal *glob, unsigned long class_id, unsigned long ui) {
{ unsigned char size = 8; // size in bytes to output
unsigned char size = 8; //size in bytes to output unsigned char sizeSerialized = 0;
unsigned char sizeSerialized = 0; unsigned long minVal;
unsigned long minVal;
Ebml_WriteID(glob, class_id);
minVal = 0x7fLU; //mask to compare for byte size
for (size = 1; size < 4; size ++) Ebml_WriteID(glob, class_id);
{ minVal = 0x7fLU; // mask to compare for byte size
if (ui < minVal)
{
break;
}
minVal <<= 7; for (size = 1; size < 4; size ++) {
if (ui < minVal) {
break;
} }
sizeSerialized = 0x80 | size; minVal <<= 7;
Ebml_Serialize(glob, &sizeSerialized, sizeof(sizeSerialized), 1); }
Ebml_Serialize(glob, &ui, sizeof(ui), size);
sizeSerialized = 0x80 | size;
Ebml_Serialize(glob, &sizeSerialized, sizeof(sizeSerialized), 1);
Ebml_Serialize(glob, &ui, sizeof(ui), size);
} }