Async 1.8.0
AsyncAudioContainerOpus.h
Go to the documentation of this file.
1
31#ifndef ASYNC_AUDIO_CONTAINER_OPUS_INCLUDED
32#define ASYNC_AUDIO_CONTAINER_OPUS_INCLUDED
33
34
35/****************************************************************************
36 *
37 * System Includes
38 *
39 ****************************************************************************/
40
41#include <ogg/ogg.h>
42#include <vector>
43#include <cstring>
44
45
46/****************************************************************************
47 *
48 * Project Includes
49 *
50 ****************************************************************************/
51
52#include <AsyncAudioContainer.h>
53
54
55/****************************************************************************
56 *
57 * Local Includes
58 *
59 ****************************************************************************/
60
61
62
63/****************************************************************************
64 *
65 * Forward declarations
66 *
67 ****************************************************************************/
68
69
70
71/****************************************************************************
72 *
73 * Namespace
74 *
75 ****************************************************************************/
76
77namespace Async
78{
79
80
81/****************************************************************************
82 *
83 * Forward declarations of classes inside of the declared namespace
84 *
85 ****************************************************************************/
86
87class AudioEncoder;
88
89
90/****************************************************************************
91 *
92 * Defines & typedefs
93 *
94 ****************************************************************************/
95
96
97
98/****************************************************************************
99 *
100 * Exported Global Variables
101 *
102 ****************************************************************************/
103
104
105
106/****************************************************************************
107 *
108 * Class definitions
109 *
110 ****************************************************************************/
111
126{
127 public:
129 static constexpr const char *OBJNAME = "opus";
130
135
139 virtual ~AudioContainerOpus(void);
140
145 virtual const char* mediaType(void) const { return "audio/opus"; }
146
151 virtual const char* filenameExtension(void) const { return "opus"; }
152
161 virtual void endStream(void);
162
171 virtual size_t headerSize(void) const { return m_header.size(); }
172
182 virtual const char* header(void) { return m_header.data(); }
183
184 protected:
185
186 private:
187 static constexpr const size_t FRAME_SIZE = 20;
188
189 Async::AudioEncoder* m_enc;
190 ogg_stream_state m_ogg_stream;
191 ogg_packet m_packet{0};
192 //int m_ogg_serial = 1;
193 int m_pending_packets = 0;
194 AudioContainer* m_container = nullptr;
195 std::vector<char> m_header;
196 std::vector<char> m_block;
197
199 AudioContainerOpus& operator=(const AudioContainerOpus&);
200 void onWriteBlock(const char *buf, size_t len);
201 void onWriteEncodedSamples(const void *data, int len);
202 void oggpackWriteString(oggpack_buffer* oggbuf,
203 const char *str, int lenbits=32);
204 void oggpackWriteCommentList(oggpack_buffer* oggbuf,
205 const std::vector<const char*> &comments);
206 bool writePage(const ogg_page& page, std::vector<char>& buf);
207 bool writeOggOpusHeader(void);
208
209}; /* class AudioContainerOpus */
210
211
212} /* namespace */
213
214#endif /* ASYNC_AUDIO_CONTAINER_OPUS_INCLUDED */
215
216/*
217 * This file has not been truncated
218 */
Base class for audio container handlers.
AudioContainerOpus(void)
Default constructor.
static constexpr const char * OBJNAME
The name of this class when used by the object factory.
virtual size_t headerSize(void) const
Get the size of the header for this container.
virtual const char * mediaType(void) const
Retrieve the media type for the audio container.
virtual const char * filenameExtension(void) const
Get the standard filename extension for the audio container.
virtual const char * header(void)
Get the header data.
virtual void endStream(void)
Indicate to the container that the stream has ended.
virtual ~AudioContainerOpus(void)
Destructor.
AudioContainer(void)
Default constructor.
Base class for an audio encoder.
Namespace for the asynchronous programming classes.