forked from jfchapman/VUPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncoderOpus.h
65 lines (48 loc) · 1.85 KB
/
EncoderOpus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "Encoder.h"
#include "opusenc.h"
// FLAC encoder
class EncoderOpus : public Encoder
{
public:
EncoderOpus();
virtual ~EncoderOpus();
// Returns the bitrate from the encoder 'settings'.
static int GetBitrate( const std::string& settings );
// Returns the default bitrate;
static int GetDefaultBitrate();
// Returns the minimum bitrate;
static int GetMinimumBitrate();
// Returns the maximum bitrate;
static int GetMaximumBitrate();
// Clamps the bitrate between the allowed limits.
static void LimitBitrate( int& bitrate );
// Opens the encoder.
// 'filename' - (in) output file name without file extension, (out) output file name with file extension.
// 'sampleRate' - sample rate.
// 'channels' - channel count.
// 'bitsPerSample' - bits per sample, if applicable.
// 'totalSamples' - approximate total number of samples to encode, if known.
// 'settings' - encoder settings.
// 'tags' - metadata tags.
// Returns whether the encoder was opened.
bool Open( std::wstring& filename, const long sampleRate, const long channels, const std::optional<long> bitsPerSample, const long long totalSamples, const std::string& settings, const Tags& tags ) override;
// Writes sample data.
// 'samples' - input samples (floating point format scaled to +/-1.0f).
// 'sampleCount' - number of samples to write.
// Returns whether the samples were written successfully.
bool Write( float* samples, const long sampleCount ) override;
// Closes the encoder.
void Close() override;
private:
// Opus encoder write callback.
static int WriteCallback( void *user_data, const unsigned char *ptr, opus_int32 len );
// Opus encoder close callback.
static int CloseCallback( void *user_data );
// Channel count.
long m_Channels;
// Opus encoder object.
OggOpusEnc* m_OpusEncoder;
// Opus encoder callbacks.
OpusEncCallbacks m_Callbacks;
};