forked from jfchapman/VUPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decoder.h
92 lines (66 loc) · 2.48 KB
/
Decoder.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#include <functional>
#include <memory>
#include <optional>
#include <stdexcept>
// Decoder interface.
class Decoder
{
public:
Decoder();
virtual ~Decoder();
// Decoder shared pointer type.
using Ptr = std::shared_ptr<Decoder>;
// A callback which returns true to continue.
using CanContinue = std::function<bool()>;
// Reads sample data.
// 'buffer' - output buffer (floating point format scaled to +/-1.0f).
// 'sampleCount' - number of samples to read.
// Returns the number of samples read, or zero if the stream has ended.
virtual long Read( float* buffer, const long sampleCount ) = 0;
// Seeks to a 'position' in the stream, in seconds.
// Returns the new position in seconds.
virtual float Seek( const float position ) = 0;
// Returns the duration in seconds.
float GetDuration() const;
// Returns the sample rate.
long GetSampleRate() const;
// Returns the number of channels.
long GetChannels() const;
// Returns the number of bits per sample (if relevant).
std::optional<long> GetBPS() const;
// Returns the bitrate in kbps (if relevant).
std::optional<float> GetBitrate() const;
// Returns the track gain, in dB, or nullopt if the calculation failed.
// 'canContinue' - callback which returns whether the calculation can continue.
// 'secondslimit' - number of seconds to devote to calculating an estimate, or 0 to perform a complete calculation.
virtual std::optional<float> CalculateTrackGain( CanContinue canContinue, const float secondsLimit = 0 );
// Skips any leading silence.
void SkipSilence();
// Returns whether stream titles are supported.
virtual bool SupportsStreamTitles() const;
// Returns the current stream title, and the position (in seconds) at which the title last changed.
virtual std::pair<float /*seconds*/, std::wstring /*title*/> GetStreamTitle();
protected:
// Sets the 'duration'.
void SetDuration( const float duration );
// Sets the 'sampleRate'.
void SetSampleRate( const long sampleRate );
// Sets the number of 'channels'.
void SetChannels( const long channels );
// Sets the number of 'bitsPerSample'.
void SetBPS( const std::optional<long> bitsPerSample );
// Sets the 'bitrate' in kbps.
void SetBitrate( const std::optional<float> bitrate );
private:
// Duration in seconds.
float m_Duration;
// Sample rate.
long m_SampleRate;
// Number of channels.
long m_Channels;
// Bits per sample (if relevant).
std::optional<long> m_BPS;
// Bitrate in kbps (if relevant).
std::optional<float> m_Bitrate;
};