Mercurial > hg > forks > bilotrip-mj12
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 |
rev | line source |
---|---|
2 | 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 | 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 | 5 #include <fstream> |
6 #include <vector> | |
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 | 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 | 11 #include <boost/thread.hpp> |
12 #include <boost/bind.hpp> | |
13 #include <boost/thread/mutex.hpp> | |
14 #include <boost/thread/locks.hpp> | |
15 #include <boost/thread/condition.hpp> | |
16 #include <boost/circular_buffer.hpp> | |
17 #include <boost/timer.hpp> | |
18 | |
19 struct OggPlayer::Imp { | |
20 | |
21 Imp() : | |
22 cirbuf(0),video_lock(video_mut, boost::defer_lock){ | |
23 failbit = false; | |
24 playing = false; | |
25 need_close = false; | |
26 time_factor = 1; | |
27 refs = 1; | |
28 } | |
29 | |
30 ~Imp() { | |
31 // open() tears down the partial setup on fail | |
32 if (!failbit) | |
33 close(); | |
34 } | |
35 int queue_page(ogg_page * page); | |
36 bool buffer_data(); | |
37 double get_time(); | |
38 void close(); | |
39 bool init_decoders(); | |
40 bool parse_headers(); | |
41 void open(std::string path, AudioFormat audio_format, int channels, | |
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 | 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 | 46 bool decode_video(); |
47 bool ready(); | |
48 void play(); | |
49 void play_loop(); | |
50 | |
51 bool failbit; | |
52 std::ifstream file_in; | |
53 | |
54 int theora_p; | |
55 int vorbis_p; | |
56 | |
57 ogg_sync_state o_sync; | |
58 | |
26
74b28a572438
Fence some more vorbis-related things.
Matti Hamalainen <ccr@tnsp.org>
parents:
14
diff
changeset
|
59 #ifdef VORBIS_SUPPORT |
2 | 60 vorbis_comment v_comment; |
27 | 61 vorbis_info v_info; |
62 #endif | |
63 | |
2 | 64 theora_info t_info; |
65 theora_comment t_comment; | |
66 | |
67 ogg_page o_page; | |
68 ogg_packet o_packet; | |
69 | |
70 ogg_stream_state o_tsstate; | |
71 ogg_stream_state o_vsstate; | |
72 | |
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 | 76 vorbis_dsp_state v_state; |
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 | 79 |
80 int pp_level_max; | |
81 int pp_level; | |
82 int pp_inc; | |
83 | |
84 char* audio_buffer; | |
85 boost::circular_buffer<char> cirbuf; | |
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 | 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 | 90 |
91 bool playing; | |
92 | |
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 | 97 boost::mutex audio_mut; |
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 | 100 |
101 bool videobuf_ready; | |
102 double videobuf_time; | |
103 | |
104 bool audio_cache_ready; | |
105 | |
106 // This lock should only be used from the main thread | |
107 boost::unique_lock<boost::mutex> video_lock; | |
108 // These variables are used to identify the frames (not just count them, not a debug variable) | |
109 // see video_buffer_try_lock and video_read | |
110 int frame; | |
111 int last_frame_read; | |
112 | |
113 int audio_bytes_played; | |
114 struct AudioGranulePos { | |
115 int pos; | |
116 double set_time; | |
117 }; | |
118 std::deque<AudioGranulePos> audio_granule_poses; | |
119 double time_factor; | |
120 | |
121 struct PixelFormat{ | |
122 void set(int r,int g,int b,int bpp){ | |
123 r_offset = r; | |
124 g_offset = g; | |
125 b_offset = b; | |
126 this->bpp =bpp; | |
127 } | |
128 int r_offset; | |
129 int g_offset; | |
130 int b_offset; | |
131 // if bpp=4 we have an alpha channel at offset 4 | |
132 int bpp; | |
133 | |
134 } pixel_format; | |
135 bool need_close; | |
136 boost::timer timer; | |
137 int refs; | |
138 }; |