-
Notifications
You must be signed in to change notification settings - Fork 8
/
DecoderFFmpeg.h
63 lines (46 loc) · 1.61 KB
/
DecoderFFmpeg.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
#pragma once
#include "Decoder.h"
#include <string>
struct AVCodecContext;
struct AVFormatContext;
struct AVFrame;
struct AVPacket;
struct SwrContext;
class DecoderFFmpeg : public Decoder
{
public:
// 'filename' - file name.
// 'context' - context for which the decoder is to be used.
// Throws a std::runtime_error exception if the file could not be loaded.
DecoderFFmpeg( const std::wstring& filename, const Context context );
~DecoderFFmpeg() override;
// 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.
long Read( float* buffer, const long sampleCount ) override;
// Seeks to a 'position' in the stream, in seconds.
// Returns the new position in seconds.
double Seek( const double position ) override;
private:
// Deccodes the next chunk of data into the sample buffer, returning whether any data was decoded.
bool Decode();
// Converts data from the 'frame' into the sample buffer.
void ConvertSampleData( const AVFrame* frame );
// FFmpeg format context.
AVFormatContext* m_FormatContext = nullptr;
// FFmpeg decoder context.
AVCodecContext* m_DecoderContext = nullptr;
// FFmpeg current packet.
AVPacket* m_Packet = nullptr;
// FFmpeg current frame.
AVFrame* m_Frame = nullptr;
// FFmpeg resampler context.
SwrContext* m_ResamplerContext = nullptr;
// Index of the 'best' stream.
int m_StreamIndex = 0;
// Interleaved sample buffer.
std::vector<float> m_Buffer;
// Current buffer position.
size_t m_BufferPosition = 0;
};