/* $Id$ */
/** @file
* EbmlWriter.cpp - EBML writer + WebM container
*/
/*
* Copyright (C) 2013-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* This code is based on:
*
* 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.
*/
#include <list>
#include <stack>
#include "EbmlWriter.h"
/* Matroska EBML Class IDs supported by WebM */
enum Mkv
{
// CRC_32 = 0xBF,
//segment
//Meta Seek Information
//Segment Information
// SegmentUID = 0x73A4,
// SegmentFilename = 0x7384,
// PrevUID = 0x3CB923,
// PrevFilename = 0x3C83AB,
// NextUID = 0x3EB923,
// NextFilename = 0x3E83BB,
// SegmentFamily = 0x4444,
// ChapterTranslate = 0x6924,
// ChapterTranslateEditionUID = 0x69FC,
// ChapterTranslateCodec = 0x69BF,
// ChapterTranslateID = 0x69A5,
// Title = 0x7BA9,
//Cluster
// SilentTracks = 0x5854,
// SilentTrackNumber = 0x58D7,
// Position = 0xA7,
// BlockVirtual = 0xA2,
// BlockAdditions = 0x75A1,
// BlockMore = 0xA6,
// BlockAddID = 0xEE,
// BlockAdditional = 0xA5,
// ReferencePriority = 0xFA,
// ReferenceVirtual = 0xFD,
// CodecState = 0xA4,
// Slices = 0x8E,
// TimeSlice = 0xE8,
// FrameNumber = 0xCD,
// BlockAdditionID = 0xCB,
// MkvDelay = 0xCE,
// Cluster_Duration = 0xCF,
// EncryptedBlock = 0xAF,
//Track
// MinCache = 0x6DE7,
// MaxCache = 0x6DF8,
// TrackTimecodeScale = 0x23314F,
// TrackOffset = 0x537F,
// MaxBlockAdditionID = 0x55EE,
// AttachmentLink = 0x7446,
// CodecSettings = 0x3A9697,
// CodecInfoURL = 0x3B4040,
// CodecDownloadURL = 0x26B240,
// CodecDecodeAll = 0xAA,
// TrackOverlay = 0x6FAB,
// TrackTranslate = 0x6624,
// TrackTranslateEditionUID = 0x66FC,
// TrackTranslateCodec = 0x66BF,
// TrackTranslateTrackID = 0x66A5,
//video
// StereoMode = 0x53B8,
// ColourSpace = 0x2EB524,
// GammaValue = 0x2FB523,
//end video
//audio
// ChannelPositions = 0x7D7B,
//end audio
//content encoding
// ContentEncodings = 0x6d80,
// ContentEncoding = 0x6240,
// ContentEncodingOrder = 0x5031,
// ContentEncodingScope = 0x5032,
// ContentEncodingType = 0x5033,
// ContentCompression = 0x5034,
// ContentCompAlgo = 0x4254,
// ContentCompSettings = 0x4255,
// ContentEncryption = 0x5035,
// ContentEncAlgo = 0x47e1,
// ContentEncKeyID = 0x47e2,
// ContentSignature = 0x47e3,
// ContentSigKeyID = 0x47e4,
// ContentSigAlgo = 0x47e5,
// ContentSigHashAlgo = 0x47e6,
//end content encoding
//Cueing Data
// CueCodecState = 0xEA,
// CueReference = 0xDB,
// CueRefTime = 0x96,
// CueRefCluster = 0x97,
// CueRefNumber = 0x535F,
// CueRefCodecState = 0xEB,
//Attachment
// Attachments = 0x1941A469,
// AttachedFile = 0x61A7,
// FileDescription = 0x467E,
// FileName = 0x466E,
// FileMimeType = 0x4660,
// FileData = 0x465C,
// FileUID = 0x46AE,
// FileReferral = 0x4675,
//Chapters
// Chapters = 0x1043A770,
// EditionEntry = 0x45B9,
// EditionUID = 0x45BC,
// EditionFlagHidden = 0x45BD,
// EditionFlagDefault = 0x45DB,
// EditionFlagOrdered = 0x45DD,
// ChapterAtom = 0xB6,
// ChapterUID = 0x73C4,
// ChapterTimeStart = 0x91,
// ChapterTimeEnd = 0x92,
// ChapterFlagHidden = 0x98,
// ChapterFlagEnabled = 0x4598,
// ChapterSegmentUID = 0x6E67,
// ChapterSegmentEditionUID = 0x6EBC,
// ChapterPhysicalEquiv = 0x63C3,
// ChapterTrack = 0x8F,
// ChapterTrackNumber = 0x89,
// ChapterDisplay = 0x80,
// ChapString = 0x85,
// ChapLanguage = 0x437C,
// ChapCountry = 0x437E,
// ChapProcess = 0x6944,
// ChapProcessCodecID = 0x6955,
// ChapProcessPrivate = 0x450D,
// ChapProcessCommand = 0x6911,
// ChapProcessTime = 0x6922,
// ChapProcessData = 0x6933,
//Tagging
// Tags = 0x1254C367,
// Tag = 0x7373,
// Targets = 0x63C0,
// TargetTypeValue = 0x68CA,
// TargetType = 0x63CA,
// Tagging_TrackUID = 0x63C5,
// Tagging_EditionUID = 0x63C9,
// Tagging_ChapterUID = 0x63C4,
// AttachmentUID = 0x63C6,
// SimpleTag = 0x67C8,
// TagName = 0x45A3,
// TagLanguage = 0x447A,
// TagDefault = 0x4484,
// TagString = 0x4487,
// TagBinary = 0x4485,
};
class Ebml
{
public:
private:
struct EbmlSubElement
{
};
public:
/* Creates EBML output file. */
{
}
/* Returns file size. */
{
return RTFileTell(m_File);
}
/* Get reference to file descriptor */
{
return m_File;
}
/* Returns available space on storage. */
{
}
/* Closes the file. */
inline void close()
{
}
/* Starts an EBML sub-element. */
{
/* store the current file offset. */
/* Indicates that size of the element
* is unkown (as according to EBML specs).
*/
return *this;
}
/* Ends an EBML sub-element. */
{
/* Class ID on the top of the stack should match the class ID passed
* to the function. Otherwise it may mean that we have a bug in the code.
*/
/* make sure that size will be serialized as uint64 */
m_Elements.pop();
return *this;
}
/* Serializes a null-terminated string. */
{
return *this;
}
/* Serializes an UNSIGNED integer
* If size is zero then it will be detected automatically. */
{
return *this;
}
/* Serializes a floating point value.
* Only 8-bytes double precision values are supported
* by this function.
*/
{
writeSize(sizeof(double));
return *this;
}
/* Writes raw data to file. */
{
}
/* Writes an unsigned integer of variable of fixed size. */
{
/* convert to big-endian */
}
/* Writes EBML class ID to file.
* EBML ID already has a UTF8-like represenation
* so getSizeOfUInt is used to determine
* the number of its bytes.
*/
{
}
/* Writes data size value. */
{
/* The following expression defines the size of the value that will be serialized
* as an EBML UTF-8 like integer (with trailing bits represeting its size):
1xxx xxxx - value 0 to 2^7-2
01xx xxxx xxxx xxxx - value 0 to 2^14-2
001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2
0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2
0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2
0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2
0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2
0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2
*/
/* One is subtracted in order to avoid loosing significant bit when size = 8. */
}
/* Size calculation for variable size UNSIGNED integer.
* The function defines the size of the number by trimming
* consequent trailing zero bytes starting from the most significant.
* The following statement is always true:
* 1 <= getSizeOfUInt(arg) <= 8.
*
* Every !(arg & (UINT64_MAX << X)) expression gives one
* if an only if all the bits from X to 63 are set to zero.
*/
{
}
private:
void operator=(const Ebml &);
};
class WebMWriter_Impl
{
struct CueEntry
{
};
bool m_bDebug;
bool m_bClusterOpen;
public:
WebMWriter_Impl() :
m_bDebug(false),
m_iLastPtsMs(-1),
m_iInitialPtsMs(-1),
m_Framerate(),
m_uSeekInfoPos(0),
m_uTrackPos(0),
m_uCuePos(0),
m_uClusterPos(0),
m_uTrackIdPos(0),
m_uStartSegment(0),
m_bClusterOpen(false) {}
const struct vpx_rational *a_pFps)
{
m_Framerate = *a_pFps;
}
const vpx_codec_cx_pkt_t *a_pPkt)
{
bool bStartCluster = false;
/* Calculate the PTS of this frame in milliseconds */
if (iPtsMs <= m_iLastPtsMs)
if (m_iInitialPtsMs < 0)
/* Calculate the relative time of this block */
bStartCluster = 1;
else
if (bStartCluster || fKeyframe)
{
if (m_bClusterOpen)
/* Open a new cluster */
uBlockTimecode = 0;
m_bClusterOpen = true;
/* Save a cue point if this is a keyframe. */
if (fKeyframe)
{
}
}
/* Write a Simple Block */
m_Ebml.writeUnsignedInteger((fKeyframe ? 0x80 : 0) | (a_pPkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE ? 0x08 : 0), 1);
}
{
if (m_bClusterOpen)
{
}
}
friend class WebMWriter;
private:
void writeSeekInfo()
{
if (m_uSeekInfoPos)
else
}
};
WebMWriter::~WebMWriter()
{
delete m_Impl;
}
{
}
{
}
{
try
{
}
catch(int rc)
{
return rc;
}
return VINF_SUCCESS;
}
{
try
{
}
catch(int rc)
{
return rc;
}
return VINF_SUCCESS;
}
{
try
{
}
catch(int rc)
{
return rc;
}
return VINF_SUCCESS;
}
{
}
{
}