| 1 |
/* |
| 2 |
This shows how to use the high level decoding API to easily decode |
| 3 |
a Kate stream. |
| 4 |
For clarity, error checking is omitted. |
| 5 |
For simplicity, the input is assumed to be a single Kate stream. |
| 6 |
Usually, Kate streams will be multiplexed with other streams (either |
| 7 |
other Kate streams, or audio, or video). In these cases, the Ogg |
| 8 |
part will have to be more complex, but the Kate specific code will |
| 9 |
be the same. |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <string.h> |
| 14 |
#include <ogg/ogg.h> |
| 15 |
#include "common.h" |
| 16 |
|
| 17 |
/* All the libkate API is available from the main kate header file: */ |
| 18 |
|
| 19 |
#include <kate/kate.h> |
| 20 |
|
| 21 |
int main() |
| 22 |
{ |
| 23 |
ogg_sync_state oy; |
| 24 |
ogg_stream_state os; |
| 25 |
int init=0; |
| 26 |
ogg_packet op; |
| 27 |
kate_state k; |
| 28 |
const kate_event *ev; |
| 29 |
kate_packet kp; |
| 30 |
|
| 31 |
/* for the benefit of windows, which mangles data otherwise */ |
| 32 |
set_binary_file(stdin); |
| 33 |
|
| 34 |
/* we initialize ogg and the kate state */ |
| 35 |
ogg_sync_init(&oy); |
| 36 |
int ret=kate_high_decode_init(&k); |
| 37 |
|
| 38 |
/* |
| 39 |
We then read packets and feed them to the libkate high level API. When |
| 40 |
kate_high_decode_packetin returns a positive number, this signals the |
| 41 |
end of the stream. |
| 42 |
*/ |
| 43 |
while (1) { |
| 44 |
if (get_packet(&oy,&os,&init,&op)) break; |
| 45 |
kate_packet_wrap(&kp,op.bytes,op.packet); |
| 46 |
if (kate_high_decode_packetin(&k,&kp,&ev)>0) break; |
| 47 |
/* if the event is non NULL, we have an event */ |
| 48 |
if (ev) { |
| 49 |
printf("Kate stream has text: %s\n",ev->text); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/* That's it, we can now cleanup */ |
| 54 |
ogg_stream_clear(&os); |
| 55 |
ogg_sync_clear(&oy); |
| 56 |
|
| 57 |
kate_high_decode_clear(&k); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |
| 61 |
|