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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "imp.hpp"
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 void OggPlayer::Imp::close() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 if(!need_close) return;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
6 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 if (vorbis_p) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 ogg_stream_clear(&o_vsstate);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 vorbis_block_clear(&v_block);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 vorbis_dsp_clear(&v_state);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 vorbis_comment_clear(&v_comment);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 if (theora_p) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 ogg_stream_clear(&o_tsstate);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 theora_clear(&t_state);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 theora_comment_clear(&t_comment);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 theora_info_clear(&t_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 ogg_sync_clear(&o_sync);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 file_in.close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 if (audio_buffer){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 delete[] audio_buffer;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 audio_buffer = NULL;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 need_close = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 bool OggPlayer::Imp::parse_headers() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 int stateflag = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 while (!stateflag) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 if (!buffer_data())
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 while (ogg_sync_pageout(&o_sync, &o_page) > 0) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 ogg_stream_state test;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 /* is this a mandated initial header? If not, stop parsing */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 if (!ogg_page_bos(&o_page)) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 /* don't leak the page; get it into the appropriate stream */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 queue_page(&o_page);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 stateflag = 1;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 ogg_stream_init(&test, ogg_page_serialno(&o_page));
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 ogg_stream_pagein(&test, &o_page);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 ogg_stream_packetout(&test, &o_packet);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 /* identify the codec: try theora */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 if (!theora_p && theora_decode_header(&t_info, &t_comment,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 &o_packet) >= 0) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 /* it is theora */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 memcpy(&o_tsstate, &test, sizeof(test));
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 &v_comment, &o_packet) >= 0) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 /* it is vorbis */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 memcpy(&o_vsstate, &test, sizeof(test));
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 /* whatever it is, we don't care about it */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 ogg_stream_clear(&test);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 int ret;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 // look for further theora headers
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout(
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 &o_tsstate, &o_packet))) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 theora_p++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
95 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 // look for more vorbis header packets
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 &o_vsstate, &o_packet))) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 vorbis_p++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 if (vorbis_p == 3)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
111 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 // The header pages/packets will arrive before anything else we
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 // care about, or the stream is not obeying spec
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 if (ogg_sync_pageout(&o_sync, &o_page) > 0) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 queue_page(&o_page); /* demux into the appropriate stream */
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 } else {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 return true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 bool OggPlayer::Imp::init_decoders() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 if (theora_p) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 theora_decode_init(&t_state, &t_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 theora_control(&t_state, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 sizeof(pp_level_max));
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 pp_level = pp_level_max;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 theora_control(&t_state, TH_DECCTL_SET_PPLEVEL, &pp_level,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 sizeof(pp_level));
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 pp_inc = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 }
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
142 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 if (vorbis_p) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 vorbis_synthesis_init(&v_state, &v_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 vorbis_block_init(&v_state, &v_block);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 return true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 void OggPlayer::Imp::open(std::string path, AudioFormat audio_format, int channels,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 int rate, VideoFormat video_format) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 theora_p = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 vorbis_p = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 videobuf_ready = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 frame=0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 last_frame_read=0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 // 1) open the input file
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 file_in.open(path.c_str(), std::ios::binary);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 failbit = true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 return;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 // 2) init some structs
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 vorbis_info_init(&v_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 theora_info_init(&t_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 theora_comment_init(&t_comment);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 // 3) parse headers
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 failbit = true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 // 3) init decoders
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 failbit = true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 // 4) if fail, tear down the partial setup
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 if (failbit) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 theora_info_clear(&t_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 vorbis_info_clear(&v_info);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 ogg_sync_clear(&o_sync);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 return;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
206 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 // 5) init audio conversion
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 int ret = SDL_BuildAudioCVT(&cvt, AUDIO_S16, v_info.channels,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 v_info.rate, audio_format, channels, rate);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 if (-1 == ret) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 failbit = true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 return;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 // play() will allocate memory when needed
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 audio_buffer_size = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 audio_buffer = NULL;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 switch(video_format){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 case VF_RGB:
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 pixel_format.set(0,1,2,3);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 case VF_BGR:
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 pixel_format.set(2,1,0,3);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 case VF_RGBA:
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 pixel_format.set(0,1,2,4);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 case VF_BGRA:
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 pixel_format.set(2,1,0,4);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 break;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 need_close = true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237