annotate liboggplayer-src/src/imp.hpp @ 59:3eacedd172ab

Fence some lingering audio code, based on fixes from visy.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 23:27:37 +0300
parents e29773ac3ceb
children 9c63b355c82b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include <oggplayer.h>
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
2 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "SDL_audiocvt.hpp"
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
4 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <fstream>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include <vector>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <theora/theora.h>
26
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
8 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <vorbis/codec.h>
26
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
10 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <boost/thread.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <boost/bind.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include <boost/thread/mutex.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <boost/thread/locks.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include <boost/thread/condition.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #include <boost/circular_buffer.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include <boost/timer.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 struct OggPlayer::Imp {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 Imp() :
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 cirbuf(0),video_lock(video_mut, boost::defer_lock){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 failbit = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 playing = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 need_close = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 time_factor = 1;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 refs = 1;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 ~Imp() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 // open() tears down the partial setup on fail
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 if (!failbit)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 int queue_page(ogg_page * page);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 bool buffer_data();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 double get_time();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 void close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 bool init_decoders();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 bool parse_headers();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 void open(std::string path, AudioFormat audio_format, int channels,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 int rate, VideoFormat video_format);
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
43 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 bool decode_audio();
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
45 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 bool decode_video();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 bool ready();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 void play();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 void play_loop();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 bool failbit;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 std::ifstream file_in;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 int theora_p;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 int vorbis_p;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 ogg_sync_state o_sync;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
26
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
59 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 vorbis_comment v_comment;
27
e29773ac3ceb Fix a #ifdef fence.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
61 vorbis_info v_info;
e29773ac3ceb Fix a #ifdef fence.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
62 #endif
e29773ac3ceb Fix a #ifdef fence.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
63
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 theora_info t_info;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 theora_comment t_comment;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 ogg_page o_page;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 ogg_packet o_packet;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 ogg_stream_state o_tsstate;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 ogg_stream_state o_vsstate;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 theora_state t_state;
26
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
74
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
75 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 vorbis_dsp_state v_state;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 vorbis_block v_block;
26
74b28a572438 Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
78 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 int pp_level_max;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 int pp_level;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 int pp_inc;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 char* audio_buffer;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 boost::circular_buffer<char> cirbuf;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 unsigned int audio_buffer_size;
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
87 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 SDL_AudioCVT cvt;
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
89 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 bool playing;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 boost::thread play_thread;
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
94 boost::mutex video_mut;
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
95 boost::condition_variable video_ready_cond;
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
96 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 boost::mutex audio_mut;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 boost::condition_variable audio_ready_cond;
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
99 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 bool videobuf_ready;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 double videobuf_time;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 bool audio_cache_ready;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 // This lock should only be used from the main thread
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 boost::unique_lock<boost::mutex> video_lock;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 // These variables are used to identify the frames (not just count them, not a debug variable)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 // see video_buffer_try_lock and video_read
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 int frame;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 int last_frame_read;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 int audio_bytes_played;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 struct AudioGranulePos {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 int pos;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 double set_time;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 };
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 std::deque<AudioGranulePos> audio_granule_poses;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 double time_factor;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 struct PixelFormat{
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 void set(int r,int g,int b,int bpp){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 r_offset = r;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 g_offset = g;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 b_offset = b;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 this->bpp =bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 int r_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 int g_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 int b_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 // if bpp=4 we have an alpha channel at offset 4
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 int bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 } pixel_format;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 bool need_close;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 boost::timer timer;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 int refs;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 };