Debian Codegraph @

examples/src/decoding.c

raw
1 /*
2 This shows the steps necessary to encode a Kate stream.
3 For clarity, error checking is omitted.
4 For simplicity, the input is assumed to be a single Kate stream.
5 Usually, Kate streams will be multiplexed with other streams (either
6 other Kate streams, or audio, or video). In these cases, the Ogg
7 part will have to be more complex, but the Kate specific code will
8 be the same.
9 */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "common.h"
14
15 /* All the libkate API is available from the main kate header file: */
16
17 #include <kate/oggkate.h>
18
19 int main()
20 {
21 ogg_sync_state oy;
22 ogg_stream_state os;
23 int init=0;
24 ogg_packet op;
25 kate_state k;
26 kate_info ki;
27 kate_comment kc;
28 const kate_event *ev;
29
30 /* for the benefit of windows, which mangles data otherwise */
31 set_binary_file(stdin);
32
33 /* we initialize ogg and kate info/comment structures */
34 ogg_sync_init(&oy);
35 kate_info_init(&ki);
36 kate_comment_init(&kc);
37
38 /*
39 First, read the headers, which must appear first in a Kate stream. When
40 kate_decode_header returns a positive number, all headers have been seen
41 and we're ready to decode data.
42 */
43 do {
44 get_packet(&oy,&os,&init,&op);
45 } while (kate_ogg_decode_headerin(&ki,&kc,&op)==0);
46
47 /*
48 We now have all the information we need from the headers, so we can
49 initialize kate for decoding
50 */
51 kate_decode_init(&k,&ki);
52
53 /*
54 We can now read data, until kate_decode_packetin returns a positive
55 number, signaling the end of the stream
56 */
57 while (1) {
58 if (get_packet(&oy,&os,&init,&op)) break;
59 if (kate_ogg_decode_packetin(&k,&op)>0) break;
60
61 /* we may have an event (eg, text) */
62 if (kate_decode_eventout(&k,&ev)==0) {
63 printf("Kate stream has text: %s\n",ev->text);
64 }
65 }
66
67 /* That's it, we can now cleanup */
68 ogg_stream_clear(&os);
69 ogg_sync_clear(&oy);
70
71 kate_clear(&k);
72 kate_info_clear(&ki);
73 kate_comment_clear(&kc);
74
75 return 0;
76 }
77