diff options
author | Tuomas Virtanen <katajakasa@gmail.com> | 2018-06-23 17:53:11 +0300 |
---|---|---|
committer | Tuomas Virtanen <katajakasa@gmail.com> | 2018-06-23 17:53:11 +0300 |
commit | 60dd75397f1ce9c4a56e74ee0bb94cebd4ab831c (patch) | |
tree | 03b39dc8f6f1b2167971dd6b3a7fa89a3ee29bda /examples | |
parent | 329de67ea44552c1d08e23203daee7e878ffd759 (diff) |
Implement new API for subtitle screen size and stream indexes
Diffstat (limited to 'examples')
-rw-r--r-- | examples/example_audio.c | 21 | ||||
-rw-r--r-- | examples/example_cust_video.c | 50 | ||||
-rw-r--r-- | examples/example_video.c | 48 |
3 files changed, 82 insertions, 37 deletions
diff --git a/examples/example_audio.c b/examples/example_audio.c index dae252a..461d54c 100644 --- a/examples/example_audio.c +++ b/examples/example_audio.c @@ -62,11 +62,6 @@ int main(int argc, char *argv[]) { return 1; } - // Disable any video and subtitle streams. If we leave these enabled and then don't - // clear the buffers for these sometimes, decoding will block. - Kit_SetSourceStream(src, KIT_STREAMTYPE_SUBTITLE, -1); - Kit_SetSourceStream(src, KIT_STREAMTYPE_VIDEO, -1); - // Print stream information Kit_StreamInfo sinfo; fprintf(stderr, "Source streams:\n"); @@ -79,8 +74,13 @@ int main(int argc, char *argv[]) { fprintf(stderr, " * Stream #%d: %s\n", i, stream_types[sinfo.type]); } - // Create the player - player = Kit_CreatePlayer(src); + // Create the player. No video, pick best audio stream, no subtitles, no screen + player = Kit_CreatePlayer( + src, + -1, + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO), + -1, + 0, 0); if(player == NULL) { fprintf(stderr, "Unable to create player: %s\n", Kit_GetError()); return 1; @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) { // Refresh audio int queued = SDL_GetQueuedAudioSize(audio_dev); if(queued < AUDIOBUFFER_SIZE) { - ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE - queued); + ret = Kit_GetPlayerAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE - queued); if(ret > 0) { SDL_QueueAudio(audio_dev, audiobuf, ret); } @@ -136,12 +136,11 @@ int main(int argc, char *argv[]) { SDL_Delay(1); } - SDL_CloseAudioDevice(audio_dev); - Kit_ClosePlayer(player); Kit_CloseSource(src); - Kit_Quit(); + + SDL_CloseAudioDevice(audio_dev); SDL_Quit(); return 0; } diff --git a/examples/example_cust_video.c b/examples/example_cust_video.c index d163076..6af6564 100644 --- a/examples/example_cust_video.c +++ b/examples/example_cust_video.c @@ -4,8 +4,6 @@ #include <stdbool.h> /* -* Note! This is the video playback from memory example! -* * Note! This example does not do proper error handling etc. * It is for example use only! */ @@ -146,8 +144,14 @@ int main(int argc, char *argv[]) { fprintf(stderr, " * Stream #%d: %s\n", i, Kit_GetKitStreamTypeString(sinfo.type)); } - // Create the player - player = Kit_CreatePlayer(src); + // Create the player. Pick best video, audio and subtitle streams, and set subtitle + // rendering resolution to screen resolution. + player = Kit_CreatePlayer( + src, + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_VIDEO), + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO), + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_SUBTITLE), + 1280, 720); if(player == NULL) { fprintf(stderr, "Unable to create player: %s\n", Kit_GetError()); return 1; @@ -199,6 +203,7 @@ int main(int argc, char *argv[]) { fflush(stderr); // Initialize video texture. This will probably end up as YV12 most of the time. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_Texture *video_tex = SDL_CreateTexture( renderer, pinfo.video.format, @@ -211,6 +216,7 @@ int main(int argc, char *argv[]) { } // This is the subtitle texture atlas. This contains all the subtitle image fragments. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); // Always nearest for atlas operations SDL_Texture *subtitle_tex = SDL_CreateTexture( renderer, pinfo.subtitle.format, @@ -231,8 +237,12 @@ int main(int argc, char *argv[]) { Kit_PlayerPlay(player); // Get movie area size - int mouse_x = 0, mouse_y = 0; - int size_w = 0, size_h = 0; + int mouse_x = 0; + int mouse_y = 0; + int size_w = 0; + int size_h = 0; + int screen_w = 0; + int screen_h = 0; SDL_RenderGetLogicalSize(renderer, &size_w, &size_h); bool gui_enabled = false; bool fullscreen = false; @@ -270,6 +280,15 @@ int main(int argc, char *argv[]) { mouse_y = event.motion.y; break; + case SDL_WINDOWEVENT: + switch(event.window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + SDL_GetWindowSize(window, &screen_w, &screen_h); + Kit_SetPlayerScreenSize(player, screen_w, screen_h); + break; + } + break; + case SDL_MOUSEBUTTONUP: // 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) { @@ -305,7 +324,7 @@ int main(int argc, char *argv[]) { int need = AUDIOBUFFER_SIZE - queued; while(need > 0) { - ret = Kit_GetAudioData( + ret = Kit_GetPlayerAudioData( player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE); @@ -327,16 +346,19 @@ int main(int argc, char *argv[]) { SDL_RenderClear(renderer); // Refresh videotexture and render it - Kit_GetVideoData(player, video_tex); + Kit_GetPlayerVideoData(player, video_tex); SDL_RenderCopy(renderer, video_tex, NULL, NULL); // Refresh subtitle texture atlas and render subtitle frames from it + // For subtitles, use screen size instead of video size for best quality + SDL_RenderSetLogicalSize(renderer, screen_w, screen_h); SDL_Rect sources[ATLAS_MAX]; SDL_Rect targets[ATLAS_MAX]; - int got = Kit_GetSubtitleData(player, subtitle_tex, sources, targets, ATLAS_MAX); + int got = Kit_GetPlayerSubtitleData(player, subtitle_tex, sources, targets, ATLAS_MAX); for(int i = 0; i < got; i++) { SDL_RenderCopy(renderer, subtitle_tex, &sources[i], &targets[i]); } + SDL_RenderSetLogicalSize(renderer, pinfo.video.width, pinfo.video.height); // Render GUI if(gui_enabled) { @@ -348,15 +370,15 @@ int main(int argc, char *argv[]) { SDL_RenderPresent(renderer); } - SDL_DestroyTexture(subtitle_tex); - SDL_DestroyTexture(video_tex); - SDL_CloseAudioDevice(audio_dev); - Kit_ClosePlayer(player); Kit_CloseSource(src); fclose(fd); - Kit_Quit(); + + SDL_DestroyTexture(subtitle_tex); + SDL_DestroyTexture(video_tex); + SDL_CloseAudioDevice(audio_dev); + SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); diff --git a/examples/example_video.c b/examples/example_video.c index cef613d..90c0a2e 100644 --- a/examples/example_video.c +++ b/examples/example_video.c @@ -121,8 +121,14 @@ int main(int argc, char *argv[]) { fprintf(stderr, " * Stream #%d: %s\n", i, Kit_GetKitStreamTypeString(sinfo.type)); } - // Create the player - player = Kit_CreatePlayer(src); + // Create the player. Pick best video, audio and subtitle streams, and set subtitle + // rendering resolution to screen resolution. + player = Kit_CreatePlayer( + src, + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_VIDEO), + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO), + Kit_GetBestSourceStream(src, KIT_STREAMTYPE_SUBTITLE), + 1280, 720); if(player == NULL) { fprintf(stderr, "Unable to create player: %s\n", Kit_GetError()); return 1; @@ -174,6 +180,7 @@ int main(int argc, char *argv[]) { fflush(stderr); // Initialize video texture. This will probably end up as YV12 most of the time. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_Texture *video_tex = SDL_CreateTexture( renderer, pinfo.video.format, @@ -186,6 +193,7 @@ int main(int argc, char *argv[]) { } // This is the subtitle texture atlas. This contains all the subtitle image fragments. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); // Always nearest for atlas operations SDL_Texture *subtitle_tex = SDL_CreateTexture( renderer, pinfo.subtitle.format, @@ -206,8 +214,12 @@ int main(int argc, char *argv[]) { Kit_PlayerPlay(player); // Get movie area size - int mouse_x = 0, mouse_y = 0; - int size_w = 0, size_h = 0; + int mouse_x = 0; + int mouse_y = 0; + int size_w = 0; + int size_h = 0; + int screen_w = 0; + int screen_h = 0; SDL_RenderGetLogicalSize(renderer, &size_w, &size_h); bool gui_enabled = false; bool fullscreen = false; @@ -245,6 +257,15 @@ int main(int argc, char *argv[]) { mouse_y = event.motion.y; break; + case SDL_WINDOWEVENT: + switch(event.window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + SDL_GetWindowSize(window, &screen_w, &screen_h); + Kit_SetPlayerScreenSize(player, screen_w, screen_h); + break; + } + break; + case SDL_MOUSEBUTTONUP: // 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) { @@ -280,7 +301,7 @@ int main(int argc, char *argv[]) { int need = AUDIOBUFFER_SIZE - queued; while(need > 0) { - ret = Kit_GetAudioData( + ret = Kit_GetPlayerAudioData( player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE); @@ -302,16 +323,19 @@ int main(int argc, char *argv[]) { SDL_RenderClear(renderer); // Refresh videotexture and render it - Kit_GetVideoData(player, video_tex); + Kit_GetPlayerVideoData(player, video_tex); SDL_RenderCopy(renderer, video_tex, NULL, NULL); // Refresh subtitle texture atlas and render subtitle frames from it + // For subtitles, use screen size instead of video size for best quality + SDL_RenderSetLogicalSize(renderer, screen_w, screen_h); SDL_Rect sources[ATLAS_MAX]; SDL_Rect targets[ATLAS_MAX]; - int got = Kit_GetSubtitleData(player, subtitle_tex, sources, targets, ATLAS_MAX); + int got = Kit_GetPlayerSubtitleData(player, subtitle_tex, sources, targets, ATLAS_MAX); for(int i = 0; i < got; i++) { SDL_RenderCopy(renderer, subtitle_tex, &sources[i], &targets[i]); } + SDL_RenderSetLogicalSize(renderer, pinfo.video.width, pinfo.video.height); // Render GUI if(gui_enabled) { @@ -323,14 +347,14 @@ int main(int argc, char *argv[]) { SDL_RenderPresent(renderer); } - SDL_DestroyTexture(subtitle_tex); - SDL_DestroyTexture(video_tex); - SDL_CloseAudioDevice(audio_dev); - Kit_ClosePlayer(player); Kit_CloseSource(src); - Kit_Quit(); + + SDL_DestroyTexture(subtitle_tex); + SDL_DestroyTexture(video_tex); + SDL_CloseAudioDevice(audio_dev); + SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); |