From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id BF5A148450 for ; Thu, 1 Aug 2024 18:11:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D09D668D8AF; Thu, 1 Aug 2024 21:11:50 +0300 (EEST) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5993368D60B for ; Thu, 1 Aug 2024 21:11:44 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52ed9b802ceso8908446e87.3 for ; Thu, 01 Aug 2024 11:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722535903; x=1723140703; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=syOrj9Gt4/h9XEmmW2sAn9tnUS8svid5B6bvTFlZHJ8=; b=I/rNeko1Llb37lVw0jI1uIJ480EDh9PbRIRb9+iEa6D4/XqbsxFwrQCJtudzO2OUDC JIvONFNULDO1xW5gvHbCmw1CvCNgVK6zhce4e8G7u4yT+IYPOIDcsTs05jEZz97mEBVK iRsvgS6NMTkh1uTWDIWwQ2Y3H81LmAvnqaQiDgWAuES8BEpwSHbcnWY7UMNAJfdi81J6 kYRD3uz4O+xf94KSk9UIPpvUyxAgU7HA+eByJxGJMR9Q8O8xYXRfIwpzipNGEQpljMLh 0GaayFzlxflFf9rM13SzYnQg9Yb+FqrhwGXZvA+sHZ/dJU3ZSdCvNtH0SdZHTDPIQUVz ABBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722535903; x=1723140703; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=syOrj9Gt4/h9XEmmW2sAn9tnUS8svid5B6bvTFlZHJ8=; b=v3Z9aAvclsEBXPoeFF59KJk81GndwSgIurP9a674M5bWaQBPIZtrDvXTkmFsngasSn XJS4QoDtzQYgSZSVtEUp6eKVtacO6lzHiP6i1+hm7lufnyoLDb7vxhPLXAk4+ObGnvvJ VBZqn8YFVnhq8ZFzagk96VhKOBCdrrrXXmZPQ0KJZO7s3tJ9g9lmziULEMnnDV5FqVs9 A2U1LVsvOibJ/jE5NC82LNvYwdTRRVs2NQ8pIouzFnWsub2KQ3mouiVG9U5znjncsIA+ 8sTxDFIDMdDSHpoYcbNaLU0PNXSL/POX8x9b6rXyFWvXsk1vYFF7YeY9CIpOAu3/7EvY SvJA== X-Gm-Message-State: AOJu0YyKSY4f4FzKGSXrUxRwP55s6juVXQyaxoOORnRr7XgineO5JXZC D97GpbOohRS8VrkKG69W50rrv2igrKebO8H94LkWIfCjyQPTPs1ZMrQnFQ== X-Google-Smtp-Source: AGHT+IG7I+3hVGQPkJtKFQYvMdDnTcG2f3qWdn/Sh6Mbkhz5xRVdCsjS8hJmvBjGoX/aJYjrHSTcVA== X-Received: by 2002:a05:6512:1392:b0:530:ad7d:8957 with SMTP id 2adb3069b0e04-530bb3a2b9bmr596504e87.49.1722535902930; Thu, 01 Aug 2024 11:11:42 -0700 (PDT) Received: from zenbook.sladdsallad.lan (h-46-59-41-160.A163.priv.bahnhof.se. [46.59.41.160]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-530bba3d221sm20083e87.282.2024.08.01.11.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 11:11:41 -0700 (PDT) From: =?UTF-8?q?John=20T=C3=B6rnblom?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Aug 2024 20:10:40 +0200 Message-ID: <20240801181040.615664-1-john.tornblom@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffplay: Add basic support for game controller input X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?UTF-8?q?John=20T=C3=B6rnblom?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- 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".