summaryrefslogtreecommitdiff
path: root/examples/example_video.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example_video.c')
-rw-r--r--examples/example_video.c56
1 files changed, 25 insertions, 31 deletions
diff --git a/examples/example_video.c b/examples/example_video.c
index 1f411ca..94bb738 100644
--- a/examples/example_video.c
+++ b/examples/example_video.c
@@ -10,7 +10,7 @@
* It is for example use only!
*/
-#define AUDIOBUFFER_SIZE (32768)
+#define AUDIOBUFFER_SIZE (1024 * 64)
void render_gui(SDL_Renderer *renderer, double percent) {
@@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
// Initialize Kitchensink with network support and all formats.
- err = Kit_Init(KIT_INIT_FORMATS|KIT_INIT_NETWORK);
+ err = Kit_Init(KIT_INIT_NETWORK|KIT_INIT_ASS);
if(err != 0) {
fprintf(stderr, "Unable to initialize Kitchensink: %s", Kit_GetError());
return 1;
@@ -181,6 +181,8 @@ int main(int argc, char *argv[]) {
// Print some format info
fprintf(stderr, "Texture type: %s\n", Kit_GetSDLPixelFormatString(pinfo.video.format));
fprintf(stderr, "Audio format: %s\n", Kit_GetSDLAudioFormatString(pinfo.audio.format));
+ fprintf(stderr, "Subtitle format: %s\n", Kit_GetSDLPixelFormatString(pinfo.subtitle.format));
+ fflush(stderr);
// Initialize textures
SDL_Texture *video_tex = SDL_CreateTexture(
@@ -193,8 +195,19 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Error while attempting to create a video texture\n");
return 1;
}
+ SDL_Texture *subtitle_tex = SDL_CreateTexture(
+ renderer,
+ pinfo.subtitle.format,
+ SDL_TEXTUREACCESS_STATIC,
+ pinfo.video.width,
+ pinfo.video.height);
+ if(subtitle_tex == NULL) {
+ fprintf(stderr, "Error while attempting to create a subtitle texture\n");
+ return 1;
+ }
- fflush(stderr);
+ // Make sure subtitle texture is in correct blendmode
+ SDL_SetTextureBlendMode(subtitle_tex, SDL_BLENDMODE_BLEND);
// Set logical size for the renderer. This way when we scale, we keep aspect ratio.
SDL_RenderSetLogicalSize(renderer, pinfo.video.width, pinfo.video.height);
@@ -222,30 +235,6 @@ int main(int argc, char *argv[]) {
if(event.key.keysym.sym == SDLK_ESCAPE) {
run = false;
}
- if(event.key.keysym.sym == SDLK_q) {
- // Start or unpause the video
- Kit_PlayerPlay(player);
- }
- if(event.key.keysym.sym == SDLK_w) {
- // Pause playback
- Kit_PlayerPause(player);
- }
- if(event.key.keysym.sym == SDLK_e) {
- // Stop playback (will close the window)
- Kit_PlayerStop(player);
- }
- if(event.key.keysym.sym == SDLK_RIGHT) {
- // Skip 10 seconds forwards or to the end of the file
- if(Kit_PlayerSeek(player, 10.0) != 0) {
- fprintf(stderr, "%s\n", Kit_GetError());
- }
- }
- if(event.key.keysym.sym == SDLK_LEFT) {
- // Seek 10 seconds backwards or to the start of the file
- if(Kit_PlayerSeek(player, -10.0) != 0) {
- fprintf(stderr, "%s\n", Kit_GetError());
- }
- }
break;
case SDL_KEYDOWN:
@@ -270,7 +259,7 @@ int main(int argc, char *argv[]) {
// Handle user clicking the progress bar
if(mouse_x >= 30 && mouse_x <= size_w-30 && mouse_y >= size_h - 60 && mouse_y <= size_h - 40) {
double pos = ((double)mouse_x - 30) / ((double)size_w - 60);
- double m_time = Kit_GetPlayerDuration(player) * pos - Kit_GetPlayerPosition(player);
+ double m_time = Kit_GetPlayerDuration(player) * pos;
if(Kit_PlayerSeek(player, m_time) != 0) {
fprintf(stderr, "%s\n", Kit_GetError());
}
@@ -300,7 +289,10 @@ int main(int argc, char *argv[]) {
SDL_LockAudio();
while(need > 0) {
- ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE, (size_t)SDL_GetQueuedAudioSize(audio_dev));
+ ret = Kit_GetAudioData(
+ player,
+ (unsigned char*)audiobuf,
+ AUDIOBUFFER_SIZE);
need -= ret;
if(ret > 0) {
SDL_QueueAudio(audio_dev, audiobuf, ret);
@@ -317,9 +309,10 @@ int main(int argc, char *argv[]) {
SDL_RenderClear(renderer);
// Refresh videotexture and render it
- Kit_GetVideoData(player, video_tex);
+ Kit_GetVideoDataTexture(player, video_tex);
SDL_RenderCopy(renderer, video_tex, NULL, NULL);
- Kit_GetSubtitleData(player, renderer);
+ Kit_GetSubtitleDataTexture(player, subtitle_tex);
+ SDL_RenderCopy(renderer, subtitle_tex, NULL, NULL);
// Render GUI
if(gui_enabled) {
@@ -331,6 +324,7 @@ int main(int argc, char *argv[]) {
SDL_RenderPresent(renderer);
}
+ SDL_DestroyTexture(subtitle_tex);
SDL_DestroyTexture(video_tex);
SDL_CloseAudioDevice(audio_dev);