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