1 | /* $Id: EbmlWriter.h 65256 2017-01-12 11:11:03Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * EbmlWriter.h - EBML writer + WebM container.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.215389.xyz. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____EBMLWRITER
|
---|
19 | #define ____EBMLWRITER
|
---|
20 |
|
---|
21 | #ifdef _MSC_VER
|
---|
22 | # pragma warning(push)
|
---|
23 | # pragma warning(disable: 4668) /* vpx_codec.h(64) : warning C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
|
---|
24 | #include <vpx/vpx_encoder.h>
|
---|
25 | # pragma warning(pop)
|
---|
26 | #else
|
---|
27 | # include <vpx/vpx_encoder.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | #include <iprt/file.h>
|
---|
31 |
|
---|
32 | class WebMWriter_Impl;
|
---|
33 |
|
---|
34 | class WebMWriter
|
---|
35 | {
|
---|
36 |
|
---|
37 | public:
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Supported audio codecs.
|
---|
41 | */
|
---|
42 | enum AudioCodec
|
---|
43 | {
|
---|
44 | /** No audio codec specified. */
|
---|
45 | AudioCodec_Unknown = 0,
|
---|
46 | /** Opus. */
|
---|
47 | AudioCodec_Opus = 1
|
---|
48 | };
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Supported video codecs.
|
---|
52 | */
|
---|
53 | enum VideoCodec
|
---|
54 | {
|
---|
55 | /** No video codec specified. */
|
---|
56 | VideoCodec_None = 0,
|
---|
57 | /** VP8. */
|
---|
58 | VideoCodec_VP8 = 1
|
---|
59 | };
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Block data for VP8-encoded video data.
|
---|
63 | */
|
---|
64 | struct BlockData_VP8
|
---|
65 | {
|
---|
66 | const vpx_codec_enc_cfg_t *pCfg;
|
---|
67 | const vpx_codec_cx_pkt_t *pPkt;
|
---|
68 | };
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Block data for Opus-encoded audio data.
|
---|
72 | */
|
---|
73 | struct BlockData_Opus
|
---|
74 | {
|
---|
75 | /** Pointer to encoded Opus audio data. */
|
---|
76 | const void *pvData;
|
---|
77 | /** Size (in bytes) of encoded Opus audio data. */
|
---|
78 | size_t cbData;
|
---|
79 | };
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Block type to write.
|
---|
83 | */
|
---|
84 | enum BlockType
|
---|
85 | {
|
---|
86 | BlockType_Invalid = 0,
|
---|
87 | BlockType_Audio = 1,
|
---|
88 | BlockType_Video = 2,
|
---|
89 | BlockType_Raw = 3
|
---|
90 | };
|
---|
91 |
|
---|
92 | public:
|
---|
93 |
|
---|
94 | WebMWriter();
|
---|
95 | virtual ~WebMWriter();
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Creates output file.
|
---|
99 | *
|
---|
100 | * @param a_pszFilename Name of the file to create.
|
---|
101 | * @param a_fOpen File open mode of type RTFILE_O_.
|
---|
102 | * @param a_enmAudioCodec Audio codec to use.
|
---|
103 | * @param a_enmVideoCodec Video codec to use.
|
---|
104 | *
|
---|
105 | * @returns VBox status code. */
|
---|
106 | int Create(const char *a_pszFilename, uint64_t a_fOpen,
|
---|
107 | WebMWriter::AudioCodec a_enmAudioCodec, WebMWriter::VideoCodec a_enmVideoCodec);
|
---|
108 |
|
---|
109 | /** Closes output file. */
|
---|
110 | int Close(void);
|
---|
111 |
|
---|
112 | int AddAudioTrack(float fSamplingHz, float fOutputHz, uint8_t cChannels, uint8_t cBitDepth);
|
---|
113 |
|
---|
114 | int AddVideoTrack(uint16_t uWidth, uint16_t uHeight, double dbFPS);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Writes a block of compressed data.
|
---|
118 | *
|
---|
119 | * @param blockType Block type to write.
|
---|
120 | * @param pvData Pointer to block data to write.
|
---|
121 | * @param cbData Size (in bytes) of block data to write.
|
---|
122 | *
|
---|
123 | * @returns VBox status code.
|
---|
124 | */
|
---|
125 | int WriteBlock(WebMWriter::BlockType blockType, const void *pvData, size_t cbData);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Gets current output file size.
|
---|
129 | *
|
---|
130 | * @returns File size in bytes.
|
---|
131 | */
|
---|
132 | uint64_t GetFileSize(void);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Gets current free storage space available for the file.
|
---|
136 | *
|
---|
137 | * @returns Available storage free space.
|
---|
138 | */
|
---|
139 | uint64_t GetAvailableSpace(void);
|
---|
140 |
|
---|
141 | private:
|
---|
142 |
|
---|
143 | /** WebMWriter implementation.
|
---|
144 | * To isolate some include files. */
|
---|
145 | WebMWriter_Impl *m_pImpl;
|
---|
146 |
|
---|
147 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(WebMWriter);
|
---|
148 | };
|
---|
149 |
|
---|
150 | #endif /* ____EBMLWRITER */
|
---|