1 | /* $Id: EbmlWriter.h 65435 2017-01-24 16:53:55Z 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 VBOX_WITH_LIBVPX
|
---|
22 | # ifdef _MSC_VER
|
---|
23 | # pragma warning(push)
|
---|
24 | # pragma warning(disable: 4668) /* vpx_codec.h(64) : warning C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
|
---|
25 | # include <vpx/vpx_encoder.h>
|
---|
26 | # pragma warning(pop)
|
---|
27 | # else
|
---|
28 | # include <vpx/vpx_encoder.h>
|
---|
29 | # endif
|
---|
30 | #endif /* VBOX_WITH_LIBVPX */
|
---|
31 |
|
---|
32 | #include <iprt/file.h>
|
---|
33 |
|
---|
34 | class WebMWriter_Impl;
|
---|
35 |
|
---|
36 | class WebMWriter
|
---|
37 | {
|
---|
38 |
|
---|
39 | public:
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Supported audio codecs.
|
---|
43 | */
|
---|
44 | enum AudioCodec
|
---|
45 | {
|
---|
46 | /** No audio codec specified. */
|
---|
47 | AudioCodec_Unknown = 0,
|
---|
48 | /** Opus. */
|
---|
49 | AudioCodec_Opus = 1
|
---|
50 | };
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Supported video codecs.
|
---|
54 | */
|
---|
55 | enum VideoCodec
|
---|
56 | {
|
---|
57 | /** No video codec specified. */
|
---|
58 | VideoCodec_None = 0,
|
---|
59 | /** VP8. */
|
---|
60 | VideoCodec_VP8 = 1
|
---|
61 | };
|
---|
62 |
|
---|
63 | #ifdef VBOX_WITH_LIBVPX
|
---|
64 | /**
|
---|
65 | * Block data for VP8-encoded video data.
|
---|
66 | */
|
---|
67 | struct BlockData_VP8
|
---|
68 | {
|
---|
69 | const vpx_codec_enc_cfg_t *pCfg;
|
---|
70 | const vpx_codec_cx_pkt_t *pPkt;
|
---|
71 | };
|
---|
72 | #endif /* VBOX_WITH_LIBVPX */
|
---|
73 |
|
---|
74 | #ifdef VBOX_WITH_LIBOPUS
|
---|
75 | /**
|
---|
76 | * Block data for Opus-encoded audio data.
|
---|
77 | */
|
---|
78 | struct BlockData_Opus
|
---|
79 | {
|
---|
80 | /** Pointer to encoded Opus audio data. */
|
---|
81 | const void *pvData;
|
---|
82 | /** Size (in bytes) of encoded Opus audio data. */
|
---|
83 | size_t cbData;
|
---|
84 | /** Timestamp (in ms). */
|
---|
85 | uint64_t uTimestampMs;
|
---|
86 | };
|
---|
87 | #endif /* VBOX_WITH_LIBOPUS */
|
---|
88 |
|
---|
89 | public:
|
---|
90 |
|
---|
91 | WebMWriter();
|
---|
92 | virtual ~WebMWriter();
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Creates output file.
|
---|
96 | *
|
---|
97 | * @param a_pszFilename Name of the file to create.
|
---|
98 | * @param a_fOpen File open mode of type RTFILE_O_.
|
---|
99 | * @param a_enmAudioCodec Audio codec to use.
|
---|
100 | * @param a_enmVideoCodec Video codec to use.
|
---|
101 | *
|
---|
102 | * @returns VBox status code. */
|
---|
103 | int Create(const char *a_pszFilename, uint64_t a_fOpen,
|
---|
104 | WebMWriter::AudioCodec a_enmAudioCodec, WebMWriter::VideoCodec a_enmVideoCodec);
|
---|
105 |
|
---|
106 | /** Closes output file. */
|
---|
107 | int Close(void);
|
---|
108 |
|
---|
109 | int AddAudioTrack(uint16_t uHz, uint8_t cChannels, uint8_t cBits, uint8_t *puTrack);
|
---|
110 |
|
---|
111 | int AddVideoTrack(uint16_t uWidth, uint16_t uHeight, double dbFPS, uint8_t *puTrack);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Writes a block of compressed data.
|
---|
115 | *
|
---|
116 | * @param uTrack Track number to write data to.
|
---|
117 | * @param pvData Pointer to block data to write.
|
---|
118 | * @param cbData Size (in bytes) of block data to write.
|
---|
119 | *
|
---|
120 | * @returns VBox status code.
|
---|
121 | */
|
---|
122 | int WriteBlock(uint8_t uTrack, const void *pvData, size_t cbData);
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Gets current output file size.
|
---|
126 | *
|
---|
127 | * @returns File size in bytes.
|
---|
128 | */
|
---|
129 | uint64_t GetFileSize(void);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Gets current free storage space available for the file.
|
---|
133 | *
|
---|
134 | * @returns Available storage free space.
|
---|
135 | */
|
---|
136 | uint64_t GetAvailableSpace(void);
|
---|
137 |
|
---|
138 | private:
|
---|
139 |
|
---|
140 | /** WebMWriter implementation.
|
---|
141 | * To isolate some include files. */
|
---|
142 | WebMWriter_Impl *m_pImpl;
|
---|
143 |
|
---|
144 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(WebMWriter);
|
---|
145 | };
|
---|
146 |
|
---|
147 | #endif /* ____EBMLWRITER */
|
---|