From: "John Törnblom" <john.tornblom@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: "John Törnblom" <john.tornblom@gmail.com> Subject: [FFmpeg-devel] [PATCH] fftools/ffplay: Add basic support for game controller input Date: Thu, 1 Aug 2024 20:10:40 +0200 Message-ID: <20240801181040.615664-1-john.tornblom@gmail.com> (raw) --- doc/ffplay.texi | 37 ++++++++++++++++- fftools/ffplay.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 116 insertions(+), 22 deletions(-) diff --git a/doc/ffplay.texi b/doc/ffplay.texi index 93f77eeece..d527a2636e 100644 --- a/doc/ffplay.texi +++ b/doc/ffplay.texi @@ -210,7 +210,7 @@ automatically. @end table -@section While playing +@section Keyboard inputs while playing @table @key @item q, ESC @@ -261,6 +261,12 @@ Seek to the previous/next chapter. or if there are no chapters Seek backward/forward 10 minutes. +@end table + +@section Mouse inputs while playing + +@table @key + @item right mouse click Seek to percentage in file corresponding to fraction of width. @@ -269,6 +275,35 @@ Toggle full screen. @end table +@section Game controller inputs while playing + +@table @key + +@item A +Pause. + +@item B +Cycle subtitle channel in the current program. + +@item X +Cycle audio channel in the current program. + +@item Y +Cycle video channel. + +@item D-pad left/right +Seek backward/forward 10 seconds. + +@item D-pad down/up +Seek backward/forward 1 minute. + +@item left/right shoulder +Seek to the previous/next chapter. +or if there are no chapters +Seek backward/forward 10 minutes. + +@end table + @c man end @include config.texi diff --git a/fftools/ffplay.c b/fftools/ffplay.c index efcd4f6452..8c9c1f9bca 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3349,6 +3349,48 @@ static void event_loop(VideoState *cur_stream) double x; refresh_loop_wait_event(cur_stream, &event); switch (event.type) { + case SDL_CONTROLLERBUTTONDOWN: + switch (event.cbutton.button) { + case SDL_CONTROLLER_BUTTON_A: + toggle_pause(cur_stream); + break; + case SDL_CONTROLLER_BUTTON_B: + stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE); + break; + case SDL_CONTROLLER_BUTTON_X: + stream_cycle_channel(cur_stream, AVMEDIA_TYPE_AUDIO); + break; + case SDL_CONTROLLER_BUTTON_Y: + stream_cycle_channel(cur_stream, AVMEDIA_TYPE_VIDEO); + break; + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + if (cur_stream->ic->nb_chapters <= 1) { + incr = -600.0; + goto do_seek; + } + seek_chapter(cur_stream, -1); + break; + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + if (cur_stream->ic->nb_chapters <= 1) { + incr = 600.0; + goto do_seek; + } + seek_chapter(cur_stream, 1); + break; + case SDL_CONTROLLER_BUTTON_DPAD_UP: + incr = 60.0; + goto do_seek; + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + incr = -60.0; + goto do_seek; + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + incr = seek_interval ? -seek_interval : -10.0; + goto do_seek; + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + incr = seek_interval ? seek_interval : 10.0; + goto do_seek; + } + break; case SDL_KEYDOWN: if (exit_on_keydown || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_q) { do_exit(cur_stream); @@ -3717,31 +3759,42 @@ void show_help_default(const char *opt, const char *arg) show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM); show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM); show_help_children(avfilter_get_class(), AV_OPT_FLAG_FILTERING_PARAM); - printf("\nWhile playing:\n" - "q, ESC quit\n" - "f toggle full screen\n" - "p, SPC pause\n" - "m toggle mute\n" - "9, 0 decrease and increase volume respectively\n" - "/, * decrease and increase volume respectively\n" - "a cycle audio channel in the current program\n" - "v cycle video channel\n" - "t cycle subtitle channel in the current program\n" - "c cycle program\n" - "w cycle video filters or show modes\n" - "s activate frame-step mode\n" - "left/right seek backward/forward 10 seconds or to custom interval if -seek_interval is set\n" - "down/up seek backward/forward 1 minute\n" - "page down/page up seek backward/forward 10 minutes\n" - "right mouse click seek to percentage in file corresponding to fraction of width\n" - "left double-click toggle full screen\n" - ); + printf("\nKeyboard inputs while playing:\n" + " q, ESC quit\n" + " f toggle full screen\n" + " p, SPC pause\n" + " m toggle mute\n" + " 9, 0 decrease and increase volume respectively\n" + " /, * decrease and increase volume respectively\n" + " a cycle audio channel in the current program\n" + " v cycle video channel\n" + " t cycle subtitle channel in the current program\n" + " c cycle program\n" + " w cycle video filters or show modes\n" + " s activate frame-step mode\n" + " left/right seek backward/forward 10 seconds or to custom interval if -seek_interval is set\n" + " down/up seek backward/forward 1 minute\n" + " page down/page up seek backward/forward 10 minutes\n" + "\n" + "Mouse inputs while playing:\n" + " right mouse click seek to percentage in file corresponding to fraction of width\n" + " left double-click toggle full screen\n" + "\n" + "Game controller inputs while playing:\n" + " A pause\n" + " B cycle subtitle channel in the current program\n" + " X cycle audio channel in the current program\n" + " Y cycle video channel\n" + " D-pad left/right seek backward/forward 10 seconds or to custom interval if -seek_interval is set\n" + " D-pad down/up seek backward/forward 1 minute\n" + " left/right shoulder seek backward/forward 10 minutes\n" + ); } /* Called from the main */ int main(int argc, char **argv) { - int flags, ret; + int flags, ret, i; VideoState *is; init_dynload(); @@ -3775,7 +3828,7 @@ int main(int argc, char **argv) if (display_disable) { video_disable = 1; } - flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; + flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER; if (audio_disable) flags &= ~SDL_INIT_AUDIO; else { @@ -3866,6 +3919,12 @@ int main(int argc, char **argv) } } + for (i = 0; i < SDL_NumJoysticks(); i++) { + if (!SDL_GameControllerOpen(i)) { + av_log(NULL, AV_LOG_WARNING, "Failed to a open game controller: %s\n", SDL_GetError()); + } + } + is = stream_open(input_filename, file_iformat); if (!is) { av_log(NULL, AV_LOG_FATAL, "Failed to initialize VideoState!\n"); -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2024-08-01 18:11 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240801181040.615664-1-john.tornblom@gmail.com \ --to=john.tornblom@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git