1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef OGG_STREAM_H
4 #define OGG_STREAM_H
5 
6 #include "System/Misc/SpringTime.h"
7 
8 #include <al.h>
9 #include <ogg/ogg.h>
10 #include <vorbis/vorbisfile.h>
11 
12 #include <string>
13 #include <vector>
14 
15 
16 class COggStream
17 {
18 public:
19 	typedef std::vector<std::string> TagVector;
20 	COggStream(ALuint _source);
21 	~COggStream();
22 
23 	void Play(const std::string& path, float volume);
24 	void Stop();
25 	bool TogglePause();
26 	void Update();
27 
28 	float GetPlayTime() const;
29 	float GetTotalTime();
30 	bool Valid() const;
31 	bool IsFinished();
32 
33 	const TagVector& VorbisTags() const;
34 
35 private:
36 	void DisplayInfo();
37 	bool IsPlaying();
38 	bool StartPlaying();
39 
40 	bool DecodeStream(ALuint buffer);
41 	void EmptyBuffers();
42 	void ReleaseBuffers();
43 
44 	/**
45 	 * @brief Decode next part of the stream and queue it for playing
46 	 * @return whether it is the end of the stream
47 	 *   (check for IsPlaying() whether the complete stream was played)
48 	 */
49 	bool UpdateBuffers();
50 
51 	OggVorbis_File oggStream;
52 	vorbis_info* vorbisInfo;
53 
54 	static const unsigned int BUFFER_SIZE = (512 * 1024); // 512KB
55 	static const unsigned int NUM_BUFFERS = 2;
56 
57 	char pcmDecodeBuffer[BUFFER_SIZE];
58 
59 	ALuint buffers[NUM_BUFFERS];
60 	ALuint source;
61 	ALenum format;
62 
63 	bool stopped;
64 	bool paused;
65 
66 	spring_time msecsPlayed;
67 	spring_time lastTick;
68 
69 	std::vector<std::string> vorbisTags;
70 	std::string vendor;
71 };
72 
73 #endif // OGG_STREAM_H
74