1 | /* $Id: EbmlWriter.h 65212 2017-01-09 15:57:02Z 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.virtualbox.org. 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 | struct BlockData
|
---|
62 | {
|
---|
63 | void *pvData;
|
---|
64 | size_t cbData;
|
---|
65 | };
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Operation mode -- this specifies what to write.
|
---|
69 | */
|
---|
70 | enum Mode
|
---|
71 | {
|
---|
72 | /** Unknown / invalid mode. */
|
---|
73 | Mode_Unknown = 0,
|
---|
74 | /** Only writes audio. */
|
---|
75 | Mode_Audio = 1,
|
---|
76 | /** Only writes video. */
|
---|
77 | Mode_Video = 2,
|
---|
78 | /** Writes audio and video. */
|
---|
79 | Mode_AudioVideo = 3
|
---|
80 | };
|
---|
81 |
|
---|
82 | public:
|
---|
83 |
|
---|
84 | WebMWriter();
|
---|
85 | virtual ~WebMWriter();
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Creates output file.
|
---|
89 | *
|
---|
90 | * @param a_pszFilename Name of the file to create.
|
---|
91 | * @param a_fOpen File open mode of type RTFILE_O_.
|
---|
92 | * @param a_enmMode Operation mode.
|
---|
93 | * @param a_enmAudioCodec Audio codec to use.
|
---|
94 | * @param a_enmVideoCodec Video codec to use.
|
---|
95 | *
|
---|
96 | * @returns VBox status code. */
|
---|
97 | int create(const char *a_pszFilename, uint64_t a_fOpen, WebMWriter::Mode a_enmMode,
|
---|
98 | WebMWriter::AudioCodec a_enmAudioCodec, WebMWriter::VideoCodec a_enmVideoCodec);
|
---|
99 |
|
---|
100 | /** Closes output file. */
|
---|
101 | void close();
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Writes WebM header to file.
|
---|
105 | * Should be called before any writeBlock call.
|
---|
106 | *
|
---|
107 | * @param a_pCfg Pointer to VPX Codec configuration structure.
|
---|
108 | * @param a_pFps Framerate information (frames per second).
|
---|
109 | *
|
---|
110 | * @returns VBox status code.
|
---|
111 | */
|
---|
112 | int writeHeader(const vpx_codec_enc_cfg_t *a_pCfg, const vpx_rational *a_pFps);
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Writes a block of compressed data.
|
---|
116 | *
|
---|
117 | * @param a_pCfg Pointer to VPX Codec configuration structure.
|
---|
118 | * @param a_pPkt VPX data packet.
|
---|
119 | *
|
---|
120 | * @returns VBox status code.
|
---|
121 | */
|
---|
122 | int writeBlock(const vpx_codec_enc_cfg_t *a_pCfg, const vpx_codec_cx_pkt_t *a_pPkt);
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Writes WebM footer.
|
---|
126 | * No other write functions should be called after this one.
|
---|
127 | *
|
---|
128 | * @param a_u64Hash Hash value for the data written.
|
---|
129 | *
|
---|
130 | * @returns VBox status code.
|
---|
131 | */
|
---|
132 | int writeFooter(uint32_t a_u64Hash);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Gets current output file size.
|
---|
136 | *
|
---|
137 | * @returns File size in bytes.
|
---|
138 | */
|
---|
139 | uint64_t getFileSize(void);
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Gets current free storage space available for the file.
|
---|
143 | *
|
---|
144 | * @returns Available storage free space.
|
---|
145 | */
|
---|
146 | uint64_t getAvailableSpace(void);
|
---|
147 |
|
---|
148 | private:
|
---|
149 |
|
---|
150 | /** WebMWriter implementation.
|
---|
151 | * To isolate some include files. */
|
---|
152 | WebMWriter_Impl *m_pImpl;
|
---|
153 |
|
---|
154 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(WebMWriter);
|
---|
155 | };
|
---|
156 |
|
---|
157 | #endif /* ____EBMLWRITER */
|
---|