comparison liboggplayer-src/src/open_close.cpp @ 60:9c63b355c82b

Remove the audio code completely.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 23:45:05 +0300
parents 083c73ceb716
children
comparison
equal deleted inserted replaced
59:3eacedd172ab 60:9c63b355c82b
1 #include "imp.hpp" 1 #include "imp.hpp"
2 2
3 void OggPlayer::Imp::close() { 3 void OggPlayer::Imp::close() {
4 if(!need_close) return; 4 if(!need_close) return;
5
6 #ifdef VORBIS_SUPPORT
7 if (vorbis_p) {
8 ogg_stream_clear(&o_vsstate);
9 vorbis_block_clear(&v_block);
10 vorbis_dsp_clear(&v_state);
11 }
12 vorbis_comment_clear(&v_comment);
13 vorbis_info_clear(&v_info);
14 #endif
15 5
16 if (theora_p) { 6 if (theora_p) {
17 ogg_stream_clear(&o_tsstate); 7 ogg_stream_clear(&o_tsstate);
18 theora_clear(&t_state); 8 theora_clear(&t_state);
19 } 9 }
20 theora_comment_clear(&t_comment); 10 theora_comment_clear(&t_comment);
21 theora_info_clear(&t_info); 11 theora_info_clear(&t_info);
22 12
23 ogg_sync_clear(&o_sync); 13 ogg_sync_clear(&o_sync);
24 file_in.close(); 14 file_in.close();
25 if (audio_buffer){
26 delete[] audio_buffer;
27 audio_buffer = NULL;
28 }
29 need_close = false; 15 need_close = false;
30 } 16 }
31 bool OggPlayer::Imp::parse_headers() { 17 bool OggPlayer::Imp::parse_headers() {
32 int stateflag = 0; 18 int stateflag = 0;
33 while (!stateflag) { 19 while (!stateflag) {
53 &o_packet) >= 0) { 39 &o_packet) >= 0) {
54 /* it is theora */ 40 /* it is theora */
55 memcpy(&o_tsstate, &test, sizeof(test)); 41 memcpy(&o_tsstate, &test, sizeof(test));
56 theora_p = 1; 42 theora_p = 1;
57 } else 43 } else
58 #ifdef VORBIS_SUPPORT
59 if (!vorbis_p && vorbis_synthesis_headerin(&v_info,
60 &v_comment, &o_packet) >= 0) {
61 /* it is vorbis */
62 memcpy(&o_vsstate, &test, sizeof(test));
63 vorbis_p = 1;
64 } else
65 #endif
66 { 44 {
67 /* whatever it is, we don't care about it */ 45 /* whatever it is, we don't care about it */
68 ogg_stream_clear(&test); 46 ogg_stream_clear(&test);
69 } 47 }
70 } 48 }
71 } 49 }
72 50
73 // we're expecting more header packets. 51 // we're expecting more header packets.
74 while ((theora_p && theora_p < 3) 52 while ((theora_p && theora_p < 3)
75 #ifdef VORBIS_SUPPORT
76 || (vorbis_p && vorbis_p < 3)
77 #endif
78 ) { 53 ) {
79 int ret; 54 int ret;
80 55
81 // look for further theora headers 56 // look for further theora headers
82 while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout( 57 while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout(
89 fprintf(stderr, "X: 1\n"); 64 fprintf(stderr, "X: 1\n");
90 return false; 65 return false;
91 } 66 }
92 theora_p++; 67 theora_p++;
93 } 68 }
94
95 #ifdef VORBIS_SUPPORT
96 // look for more vorbis header packets
97 while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(
98 &o_vsstate, &o_packet))) {
99 if (ret < 0) {
100 fprintf(stderr, "X: 2\n");
101 return false;
102 }
103 if (vorbis_synthesis_headerin(&v_info, &v_comment, &o_packet)) {
104 fprintf(stderr, "X: 3\n");
105 return false;
106 }
107 vorbis_p++;
108 if (vorbis_p == 3)
109 break;
110 }
111 #endif
112 69
113 // The header pages/packets will arrive before anything else we 70 // The header pages/packets will arrive before anything else we
114 // care about, or the stream is not obeying spec 71 // care about, or the stream is not obeying spec
115 72
116 if (ogg_sync_pageout(&o_sync, &o_page) > 0) { 73 if (ogg_sync_pageout(&o_sync, &o_page) > 0) {
137 pp_inc = 0; 94 pp_inc = 0;
138 } else { 95 } else {
139 fprintf(stderr, "DDD: 0\n"); 96 fprintf(stderr, "DDD: 0\n");
140 return false; 97 return false;
141 } 98 }
142 #ifdef VORBIS_SUPPORT
143 if (vorbis_p) {
144 vorbis_synthesis_init(&v_state, &v_info);
145 vorbis_block_init(&v_state, &v_block);
146 } else {
147 fprintf(stderr, "DDD: 1\n");
148 return false;
149 }
150 #endif
151 return true; 99 return true;
152 } 100 }
153 101
154 void OggPlayer::Imp::open(std::string path, AudioFormat audio_format, int channels, 102 void OggPlayer::Imp::open(std::string path, AudioFormat audio_format, int channels,
155 int rate, VideoFormat video_format) { 103 int rate, VideoFormat video_format) {
168 return; 116 return;
169 } 117 }
170 118
171 // 2) init some structs 119 // 2) init some structs
172 ogg_sync_init(&o_sync); 120 ogg_sync_init(&o_sync);
173 #ifdef VORBIS_SUPPORT
174 vorbis_info_init(&v_info);
175 vorbis_comment_init(&v_comment);
176 #endif
177 theora_info_init(&t_info); 121 theora_info_init(&t_info);
178 theora_comment_init(&t_comment); 122 theora_comment_init(&t_comment);
179 123
180 // 3) parse headers 124 // 3) parse headers
181 if (!failbit && !parse_headers()) { 125 if (!failbit && !parse_headers()) {
191 135
192 // 4) if fail, tear down the partial setup 136 // 4) if fail, tear down the partial setup
193 if (failbit) { 137 if (failbit) {
194 theora_info_clear(&t_info); 138 theora_info_clear(&t_info);
195 theora_comment_clear(&t_comment); 139 theora_comment_clear(&t_comment);
196 #ifdef VORBIS_SUPPORT
197 vorbis_info_clear(&v_info);
198 vorbis_comment_clear(&v_comment);
199 #endif
200 ogg_sync_clear(&o_sync); 140 ogg_sync_clear(&o_sync);
201 file_in.close(); 141 file_in.close();
202 fprintf(stderr, "XXX: done\n"); 142 fprintf(stderr, "XXX: done\n");
203 return; 143 return;
204 } 144 }
205
206 #ifdef VORBIS_SUPPORT
207 // 5) init audio conversion
208 int ret = SDL_BuildAudioCVT(&cvt, AUDIO_S16, v_info.channels,
209 v_info.rate, audio_format, channels, rate);
210 if (-1 == ret) {
211 failbit = true;
212 return;
213 }
214 #endif
215
216 // play() will allocate memory when needed
217 audio_buffer_size = 0;
218 audio_buffer = NULL;
219 145
220 switch(video_format){ 146 switch(video_format){
221 //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset); 147 //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset);
222 case VF_RGB: 148 case VF_RGB:
223 pixel_format.set(0,1,2,3); 149 pixel_format.set(0,1,2,3);