Mercurial > hg > forks > bilotrip-mj12
annotate 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 |
rev | line source |
---|---|
2 | 1 #include "imp.hpp" |
2 | |
3 void OggPlayer::Imp::close() { | |
4 if(!need_close) return; | |
5 | |
6 if (theora_p) { | |
7 ogg_stream_clear(&o_tsstate); | |
8 theora_clear(&t_state); | |
9 } | |
10 theora_comment_clear(&t_comment); | |
11 theora_info_clear(&t_info); | |
12 | |
13 ogg_sync_clear(&o_sync); | |
14 file_in.close(); | |
15 need_close = false; | |
16 } | |
17 bool OggPlayer::Imp::parse_headers() { | |
18 int stateflag = 0; | |
19 while (!stateflag) { | |
20 if (!buffer_data()) | |
21 break; | |
22 while (ogg_sync_pageout(&o_sync, &o_page) > 0) { | |
23 ogg_stream_state test; | |
24 | |
25 /* is this a mandated initial header? If not, stop parsing */ | |
26 if (!ogg_page_bos(&o_page)) { | |
27 /* don't leak the page; get it into the appropriate stream */ | |
28 queue_page(&o_page); | |
29 stateflag = 1; | |
30 break; | |
31 } | |
32 | |
33 ogg_stream_init(&test, ogg_page_serialno(&o_page)); | |
34 ogg_stream_pagein(&test, &o_page); | |
35 ogg_stream_packetout(&test, &o_packet); | |
36 | |
37 /* identify the codec: try theora */ | |
38 if (!theora_p && theora_decode_header(&t_info, &t_comment, | |
39 &o_packet) >= 0) { | |
40 /* it is theora */ | |
41 memcpy(&o_tsstate, &test, sizeof(test)); | |
42 theora_p = 1; | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
43 } else |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
44 { |
2 | 45 /* whatever it is, we don't care about it */ |
46 ogg_stream_clear(&test); | |
47 } | |
48 } | |
49 } | |
50 | |
51 // we're expecting more header packets. | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
52 while ((theora_p && theora_p < 3) |
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
53 ) { |
2 | 54 int ret; |
55 | |
56 // look for further theora headers | |
57 while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout( | |
58 &o_tsstate, &o_packet))) { | |
59 if (ret < 0) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
60 fprintf(stderr, "X: 0\n"); |
2 | 61 return false; |
62 } | |
63 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
|
64 fprintf(stderr, "X: 1\n"); |
2 | 65 return false; |
66 } | |
67 theora_p++; | |
68 } | |
69 | |
70 // The header pages/packets will arrive before anything else we | |
71 // care about, or the stream is not obeying spec | |
72 | |
73 if (ogg_sync_pageout(&o_sync, &o_page) > 0) { | |
74 queue_page(&o_page); /* demux into the appropriate stream */ | |
75 } else { | |
76 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
|
77 fprintf(stderr, "X: 4\n"); |
2 | 78 return false; |
79 } | |
80 } | |
81 } | |
82 return true; | |
83 | |
84 } | |
85 | |
86 bool OggPlayer::Imp::init_decoders() { | |
87 if (theora_p) { | |
88 theora_decode_init(&t_state, &t_info); | |
89 theora_control(&t_state, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max, | |
90 sizeof(pp_level_max)); | |
91 pp_level = pp_level_max; | |
92 theora_control(&t_state, TH_DECCTL_SET_PPLEVEL, &pp_level, | |
93 sizeof(pp_level)); | |
94 pp_inc = 0; | |
95 } else { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
96 fprintf(stderr, "DDD: 0\n"); |
2 | 97 return false; |
98 } | |
99 return true; | |
100 } | |
101 | |
102 void OggPlayer::Imp::open(std::string path, AudioFormat audio_format, int channels, | |
103 int rate, VideoFormat video_format) { | |
104 | |
105 theora_p = 0; | |
106 vorbis_p = 0; | |
107 videobuf_ready = false; | |
108 frame=0; | |
109 last_frame_read=0; | |
110 | |
111 // 1) open the input file | |
112 file_in.open(path.c_str(), std::ios::binary); | |
113 if (file_in.fail()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
114 fprintf(stderr, "XXX: 0\n"); |
2 | 115 failbit = true; |
116 return; | |
117 } | |
118 | |
119 // 2) init some structs | |
120 ogg_sync_init(&o_sync); | |
121 theora_info_init(&t_info); | |
122 theora_comment_init(&t_comment); | |
123 | |
124 // 3) parse headers | |
125 if (!failbit && !parse_headers()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
126 fprintf(stderr, "XXX: 1\n"); |
2 | 127 failbit = true; |
128 } | |
129 | |
130 // 3) init decoders | |
131 if (!failbit && !init_decoders()) { | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
132 fprintf(stderr, "XXX: 2\n"); |
2 | 133 failbit = true; |
134 } | |
135 | |
136 // 4) if fail, tear down the partial setup | |
137 if (failbit) { | |
138 theora_info_clear(&t_info); | |
139 theora_comment_clear(&t_comment); | |
140 ogg_sync_clear(&o_sync); | |
141 file_in.close(); | |
7
26ee741f8c08
Add some primitive debugging in the liboggplayer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
142 fprintf(stderr, "XXX: done\n"); |
2 | 143 return; |
144 } | |
145 | |
146 switch(video_format){ | |
147 //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset); | |
148 case VF_RGB: | |
149 pixel_format.set(0,1,2,3); | |
150 break; | |
151 case VF_BGR: | |
152 pixel_format.set(2,1,0,3); | |
153 break; | |
154 case VF_RGBA: | |
155 pixel_format.set(0,1,2,4); | |
156 break; | |
157 case VF_BGRA: | |
158 pixel_format.set(2,1,0,4); | |
159 break; | |
160 } | |
161 need_close = true; | |
162 } | |
163 |