1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include <kitchensink/kitchensink.h>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdbool.h>
/*
* Note! This example does not do proper error handling etc.
* It is for example use only!
*/
const char *stream_types[] = {
"KIT_STREAMTYPE_UNKNOWN",
"KIT_STREAMTYPE_VIDEO",
"KIT_STREAMTYPE_AUDIO",
"KIT_STREAMTYPE_DATA",
"KIT_STREAMTYPE_SUBTITLE",
"KIT_STREAMTYPE_ATTACHMENT"
};
int main(int argc, char *argv[]) {
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
Kit_Source *src = NULL;
SDL_Event event;
int err = 0;
bool run = false;
const char* filename = NULL;
if(argc != 2) {
fprintf(stderr, "Usage: exampleplay <filename>\n");
return 0;
}
filename = argv[1];
err = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
window = SDL_CreateWindow("Example Player", -1, -1, 1280, 800, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
Kit_Init(KIT_INIT_FORMATS|KIT_INIT_NETWORK);
if(err != 0 || window == NULL || renderer == NULL) {
fprintf(stderr, "Unable to initialize SDL!\n");
return 1;
}
// Open up the sourcefile.
src = Kit_CreateSourceFromUrl(filename);
if(src == NULL) {
fprintf(stderr, "Unable to load file '%s': %s\n", filename, Kit_GetError());
return 1;
}
// Print stream information
Kit_StreamInfo info;
for(int i = 0; i < Kit_GetSourceStreamCount(src); i++) {
err = Kit_GetSourceStreamInfo(src, &info, i);
if(err) {
fprintf(stderr, "Unable to fetch stream #%d information: %s.\n", i, Kit_GetError());
return 1;
}
fprintf(stderr, "Stream #%d: %s\n", i, stream_types[info.type]);
}
// Initialize codecs.
// We could choose streams before this if we wanted to; now we just use the defaults (best guesses)
if(Kit_InitSourceCodecs(src)) {
fprintf(stderr, "Error while initializing codecs: %s", Kit_GetError());
return 1;
}
while(run) {
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_KEYUP:
if(event.key.keysym.sym == SDLK_ESCAPE) {
run = false;
}
break;
case SDL_QUIT:
run = false;
break;
}
}
}
Kit_CloseSource(src);
Kit_Quit();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
|