aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Input/in_avi/ifc_aviaudiodecoder.h
blob: 00994bb8f6df12bf48aa1f15f2699d8aeb4d3c8d (plain) (blame)
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
#pragma once
#include <bfc/dispatch.h>

class NOVTABLE ifc_aviaudiodecoder : public Dispatchable
{
protected:
	ifc_aviaudiodecoder() {}
	~ifc_aviaudiodecoder() {}
public:
	enum
	{
		AVI_SUCCESS = 0,
		AVI_NEED_MORE_INPUT = -1,
		AVI_FAILURE=1,
		AVI_RESYNC=2,
	};
	int OutputFrameSize(uint32_t *frame_size);
	int GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat); // can return an error code for "havn't locked to stream yet"
	// many AVI files arbitrarily divide the data stream (e.g. an MP3 frame might span two chunks).  Others put ALL the audio into ONE chunk. awesome.
	// for this reason, you are given double pointers to the data buffer and a pointer to the data size
	// and you are expected to update it on return
	// if inputBufferBytes != 0, you will be called again with the same data (return AVI_SUCCESS, though)
	// if you were unable to decode because of bitstream errors, return AVI_RESYNC so in_avi can try to correct timing
	int DecodeChunk(uint16_t type, const void **inputBuffer, uint32_t *inputBufferBytes, void *outputBuffer, uint32_t *outputBufferBytes);
	void Flush();
	void Close(); // self-destructs
	void EndOfStream(); // no more input, output anything you have buffered
	DISPATCH_CODES
	{
		OUTPUT_FRAME_SIZE = 0,
			GET_OUTPUT_PROPERTIES = 1,
			DECODE_CHUNK = 2,
			FLUSH = 3,
			CLOSE = 4,
			END_OF_STREAM = 5,
	};
};

inline int ifc_aviaudiodecoder::OutputFrameSize(uint32_t *frame_size)
{
	return _call(OUTPUT_FRAME_SIZE, (int)AVI_FAILURE, frame_size);
}

inline int ifc_aviaudiodecoder::GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat)
{
	return _call(GET_OUTPUT_PROPERTIES, (int)AVI_FAILURE, sampleRate, channels, bitsPerSample, isFloat);
}

inline int ifc_aviaudiodecoder::DecodeChunk(uint16_t type, const void **inputBuffer, uint32_t *inputBufferBytes, void *outputBuffer, uint32_t *outputBufferBytes)
{
	return _call(DECODE_CHUNK, (int)AVI_FAILURE, type, inputBuffer, inputBufferBytes, outputBuffer, outputBufferBytes);
}

inline void ifc_aviaudiodecoder::Flush()
{
	_voidcall(FLUSH);
}

inline void ifc_aviaudiodecoder::Close()
{
	_voidcall(CLOSE);
}

inline void ifc_aviaudiodecoder::EndOfStream()
{
	_voidcall(END_OF_STREAM);
}