Mercurial > hg > forks > bilotrip-mj12
annotate liboggplayer-src/src/open_close.cpp @ 14:083c73ceb716
Get rid of the vorbis related code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 05 Aug 2013 16:54:46 +0300 |
parents | 3b6cea0d1980 |
children | 9c63b355c82b |
rev | line source |
---|---|
2 | 1 #include "imp.hpp" |
2 | |
3 void OggPlayer::Imp::close() { | |
4 if(!need_close) return; | |
5 | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
6 #ifdef VORBIS_SUPPORT |
2 | 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
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
14 #endif |
2 | 15 |
16 if (theora_p) { | |
17 ogg_stream_clear(&o_tsstate); | |
18 theora_clear(&t_state); | |
19 } | |
20 theora_comment_clear(&t_comment); | |
21 theora_info_clear(&t_info); | |
22 | |
23 ogg_sync_clear(&o_sync); | |
24 file_in.close(); | |
25 if (audio_buffer){ | |
26 delete[] audio_buffer; | |
27 audio_buffer = NULL; | |
28 } | |
29 need_close = false; | |
30 } | |
31 bool OggPlayer::Imp::parse_headers() { | |
32 int stateflag = 0; | |
33 while (!stateflag) { | |
34 if (!buffer_data()) | |
35 break; | |
36 while (ogg_sync_pageout(&o_sync, &o_page) > 0) { | |
37 ogg_stream_state test; | |
38 | |
39 /* is this a mandated initial header? If not, stop parsing */ | |
40 if (!ogg_page_bos(&o_page)) { | |
41 /* don't leak the page; get it into the appropriate stream */ | |
42 queue_page(&o_page); | |
43 stateflag = 1; | |
44 break; | |
45 } | |
46 | |
47 ogg_stream_init(&test, ogg_page_serialno(&o_page)); | |
48 ogg_stream_pagein(&test, &o_page); | |
49 ogg_stream_packetout(&test, &o_packet); | |
50 | |
51 /* identify the codec: try theora */ | |
52 if (!theora_p && theora_decode_header(&t_info, &t_comment, | |
53 &o_packet) >= 0) { | |
54 /* it is theora */ | |
55 memcpy(&o_tsstate, &test, sizeof(test)); | |
56 theora_p = 1; | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
57 } else |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
58 #ifdef VORBIS_SUPPORT |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
59 if (!vorbis_p && vorbis_synthesis_headerin(&v_info, |
2 | 60 &v_comment, &o_packet) >= 0) { |
61 /* it is vorbis */ | |
62 memcpy(&o_vsstate, &test, sizeof(test)); | |
63 vorbis_p = 1; | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
64 } else |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
65 #endif |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
66 { |
2 | 67 /* whatever it is, we don't care about it */ |
68 ogg_stream_clear(&test); | |
69 } | |
70 } | |
71 } | |
72 | |
73 // we're expecting more header packets. | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
74 while ((theora_p && theora_p < 3) |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
75 #ifdef VORBIS_SUPPORT |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
76 || (vorbis_p && vorbis_p < 3) |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
77 #endif |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
78 ) { |
2 | 79 int ret; |
80 | |
81 // look for further theora headers | |
82 while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout( | |
83 &o_tsstate, &o_packet))) { | |
84 if (ret < 0) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
85 fprintf(stderr, "X: 0\n"); |
2 | 86 return false; |
87 } | |
88 if (theora_decode_header(&t_info, &t_comment, &o_packet)) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
89 fprintf(stderr, "X: 1\n"); |
2 | 90 return false; |
91 } | |
92 theora_p++; | |
93 } | |
94 | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
95 #ifdef VORBIS_SUPPORT |
2 | 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) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
100 fprintf(stderr, "X: 2\n"); |
2 | 101 return false; |
102 } | |
103 if (vorbis_synthesis_headerin(&v_info, &v_comment, &o_packet)) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
104 fprintf(stderr, "X: 3\n"); |
2 | 105 return false; |
106 } | |
107 vorbis_p++; | |
108 if (vorbis_p == 3) | |
109 break; | |
110 } | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
111 #endif |
2 | 112 |
113 // The header pages/packets will arrive before anything else we | |
114 // care about, or the stream is not obeying spec | |
115 | |
116 if (ogg_sync_pageout(&o_sync, &o_page) > 0) { | |
117 queue_page(&o_page); /* demux into the appropriate stream */ | |
118 } else { | |
119 if (!buffer_data()) /* someone needs more data */{ | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
120 fprintf(stderr, "X: 4\n"); |
2 | 121 return false; |
122 } | |
123 } | |
124 } | |
125 return true; | |
126 | |
127 } | |
128 | |
129 bool OggPlayer::Imp::init_decoders() { | |
130 if (theora_p) { | |
131 theora_decode_init(&t_state, &t_info); | |
132 theora_control(&t_state, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max, | |
133 sizeof(pp_level_max)); | |
134 pp_level = pp_level_max; | |
135 theora_control(&t_state, TH_DECCTL_SET_PPLEVEL, &pp_level, | |
136 sizeof(pp_level)); | |
137 pp_inc = 0; | |
138 } else { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
139 fprintf(stderr, "DDD: 0\n"); |
2 | 140 return false; |
141 } | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
142 #ifdef VORBIS_SUPPORT |
2 | 143 if (vorbis_p) { |
144 vorbis_synthesis_init(&v_state, &v_info); | |
145 vorbis_block_init(&v_state, &v_block); | |
146 } else { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
147 fprintf(stderr, "DDD: 1\n"); |
2 | 148 return false; |
149 } | |
8
3b6cea0d1980
Disable audio support from liboggplayer, as it fails due to the video not
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
150 #endif |
2 | 151 return true; |
152 } | |
153 | |
154 void OggPlayer::Imp::open(std::string path, AudioFormat audio_format, int channels, | |
155 int rate, VideoFormat video_format) { | |
156 | |
157 theora_p = 0; | |
158 vorbis_p = 0; | |
159 videobuf_ready = false; | |
160 frame=0; | |
161 last_frame_read=0; | |
162 | |
163 // 1) open the input file | |
164 file_in.open(path.c_str(), std::ios::binary); | |
165 if (file_in.fail()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
166 fprintf(stderr, "XXX: 0\n"); |
2 | 167 failbit = true; |
168 return; | |
169 } | |
170 | |
171 // 2) init some structs | |
172 ogg_sync_init(&o_sync); | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
173 #ifdef VORBIS_SUPPORT |
2 | 174 vorbis_info_init(&v_info); |
175 vorbis_comment_init(&v_comment); | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
176 #endif |
2 | 177 theora_info_init(&t_info); |
178 theora_comment_init(&t_comment); | |
179 | |
180 // 3) parse headers | |
181 if (!failbit && !parse_headers()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
182 fprintf(stderr, "XXX: 1\n"); |
2 | 183 failbit = true; |
184 } | |
185 | |
186 // 3) init decoders | |
187 if (!failbit && !init_decoders()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
188 fprintf(stderr, "XXX: 2\n"); |
2 | 189 failbit = true; |
190 } | |
191 | |
192 // 4) if fail, tear down the partial setup | |
193 if (failbit) { | |
194 theora_info_clear(&t_info); | |
195 theora_comment_clear(&t_comment); | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
196 #ifdef VORBIS_SUPPORT |
2 | 197 vorbis_info_clear(&v_info); |
198 vorbis_comment_clear(&v_comment); | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
199 #endif |
2 | 200 ogg_sync_clear(&o_sync); |
201 file_in.close(); | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
202 fprintf(stderr, "XXX: done\n"); |
2 | 203 return; |
204 } | |
205 | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
206 #ifdef VORBIS_SUPPORT |
2 | 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 } | |
8
3b6cea0d1980
Disable audio support from liboggplayer, as it fails due to the video not
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
214 #endif |
3b6cea0d1980
Disable audio support from liboggplayer, as it fails due to the video not
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
215 |
2 | 216 // play() will allocate memory when needed |
217 audio_buffer_size = 0; | |
218 audio_buffer = NULL; | |
219 | |
220 switch(video_format){ | |
221 //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset); | |
222 case VF_RGB: | |
223 pixel_format.set(0,1,2,3); | |
224 break; | |
225 case VF_BGR: | |
226 pixel_format.set(2,1,0,3); | |
227 break; | |
228 case VF_RGBA: | |
229 pixel_format.set(0,1,2,4); | |
230 break; | |
231 case VF_BGRA: | |
232 pixel_format.set(2,1,0,4); | |
233 break; | |
234 } | |
235 need_close = true; | |
236 } | |
237 |