forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriver.c
1819 lines (1510 loc) · 47.4 KB
/
driver.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "general.h"
#include "libretro.h"
#include <stdint.h>
#include <string.h>
#include <math.h>
#include "compat/posix_string.h"
#include "audio/utils.h"
#include "gfx/video_thread_wrapper.h"
#include "audio/audio_thread_wrapper.h"
#include "gfx/gfx_common.h"
#include <string/string_list.h>
#ifdef HAVE_X11
#include "gfx/context/x11_common.h"
#endif
#ifdef HAVE_MENU
#include "menu/menu_common.h"
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
driver_t driver;
static const audio_driver_t *audio_drivers[] = {
#ifdef HAVE_ALSA
&audio_alsa,
#ifndef __QNX__
&audio_alsathread,
#endif
#endif
#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD)
&audio_oss,
#endif
#ifdef HAVE_RSOUND
&audio_rsound,
#endif
#ifdef HAVE_COREAUDIO
&audio_coreaudio,
#endif
#ifdef HAVE_AL
&audio_openal,
#endif
#ifdef HAVE_SL
&audio_opensl,
#endif
#ifdef HAVE_ROAR
&audio_roar,
#endif
#ifdef HAVE_JACK
&audio_jack,
#endif
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
&audio_sdl,
#endif
#ifdef HAVE_XAUDIO
&audio_xa,
#endif
#ifdef HAVE_DSOUND
&audio_dsound,
#endif
#ifdef HAVE_PULSE
&audio_pulse,
#endif
#ifdef __CELLOS_LV2__
&audio_ps3,
#endif
#ifdef XENON
&audio_xenon360,
#endif
#ifdef GEKKO
&audio_gx,
#endif
#ifdef EMSCRIPTEN
&audio_rwebaudio,
#endif
#ifdef PSP
&audio_psp1,
#endif
&audio_null,
NULL,
};
const char* config_get_audio_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; audio_drivers[option_k]; option_k++)
{
const char *opt = audio_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
static const video_driver_t *video_drivers[] = {
#ifdef HAVE_OPENGL
&video_gl,
#endif
#ifdef XENON
&video_xenon360,
#endif
#if defined(_XBOX) && (defined(HAVE_D3D8) || defined(HAVE_D3D9)) || defined(HAVE_WIN32_D3D9)
&video_d3d,
#endif
#ifdef SN_TARGET_PSP2
&video_vita,
#endif
#ifdef PSP
&video_psp1,
#endif
#ifdef HAVE_SDL
&video_sdl,
#endif
#ifdef HAVE_SDL2
&video_sdl2,
#endif
#ifdef HAVE_XVIDEO
&video_xvideo,
#endif
#ifdef GEKKO
&video_gx,
#endif
#ifdef HAVE_VG
&video_vg,
#endif
#ifdef HAVE_OMAP
&video_omap,
#endif
#ifdef HAVE_EXYNOS
&video_exynos,
#endif
&video_null,
NULL,
};
const char* config_get_video_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; video_drivers[option_k]; option_k++)
{
const char *opt = video_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
static const input_driver_t *input_drivers[] = {
#ifdef __CELLOS_LV2__
&input_ps3,
#endif
#if defined(SN_TARGET_PSP2) || defined(PSP)
&input_psp,
#endif
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
&input_sdl,
#endif
#ifdef HAVE_DINPUT
&input_dinput,
#endif
#ifdef HAVE_X11
&input_x,
#endif
#ifdef XENON
&input_xenon360,
#endif
#if defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
&input_xinput,
#endif
#ifdef GEKKO
&input_gx,
#endif
#ifdef ANDROID
&input_android,
#endif
#ifdef HAVE_UDEV
&input_udev,
#endif
#if defined(__linux__) && !defined(ANDROID)
&input_linuxraw,
#endif
#if defined(IOS) || defined(OSX)
/* Don't use __APPLE__ as it breaks basic SDL builds */
&input_apple,
#endif
#ifdef __QNX__
&input_qnx,
#endif
#ifdef EMSCRIPTEN
&input_rwebinput,
#endif
&input_null,
NULL,
};
const char* config_get_input_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; input_drivers[option_k]; option_k++)
{
const char *opt = input_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
static const input_osk_driver_t *osk_drivers[] = {
#ifdef __CELLOS_LV2__
&input_ps3_osk,
#endif
&input_null_osk,
NULL,
};
const char* config_get_osk_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; osk_drivers[option_k]; option_k++)
{
const char *opt = osk_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
static const camera_driver_t *camera_drivers[] = {
#ifdef HAVE_V4L2
&camera_v4l2,
#endif
#ifdef EMSCRIPTEN
&camera_rwebcam,
#endif
#ifdef ANDROID
&camera_android,
#endif
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_4_0)
&camera_apple,
#endif
&camera_null,
NULL,
};
const char* config_get_camera_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; camera_drivers[option_k]; option_k++)
{
const char *opt = camera_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
static const location_driver_t *location_drivers[] = {
#ifdef ANDROID
&location_android,
#endif
#if defined(IOS) || defined(OSX)
#ifdef HAVE_LOCATION
&location_apple,
#endif
#endif
&location_null,
NULL,
};
const char* config_get_location_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; location_drivers[option_k]; option_k++)
{
const char *opt = location_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
#ifdef HAVE_MENU
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
#ifdef IOS
&menu_ctx_ios,
#endif
#if defined(HAVE_RMENU)
&menu_ctx_rmenu,
#endif
#if defined(HAVE_RMENU_XUI)
&menu_ctx_rmenu_xui,
#endif
#if defined(HAVE_LAKKA)
&menu_ctx_lakka,
#endif
#if defined(HAVE_GLUI)
&menu_ctx_glui,
#endif
#if defined(HAVE_XMB)
&menu_ctx_xmb,
#endif
#if defined(HAVE_RGUI)
&menu_ctx_rgui,
#endif
NULL
};
const char* config_get_menu_driver_options(void)
{
union string_list_elem_attr attr;
char *options = NULL;
int option_k = 0;
int options_len = 0;
struct string_list *options_l = NULL;
attr.i = 0;
options_l = (struct string_list*)string_list_new();
for (option_k = 0; menu_ctx_drivers[option_k]; option_k++)
{
const char *opt = menu_ctx_drivers[option_k]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
#endif
static const void *find_driver_nonempty(const char *label, int i,
char *str, size_t sizeof_str)
{
const void *drv = NULL;
if (!strcmp(label, "camera_driver"))
{
drv = camera_drivers[i];
if (drv)
strlcpy(str, camera_drivers[i]->ident, sizeof_str);
}
else if (!strcmp(label, "location_driver"))
{
drv = location_drivers[i];
if (drv)
strlcpy(str, location_drivers[i]->ident, sizeof_str);
}
else if (!strcmp(label, "osk_driver"))
{
drv = osk_drivers[i];
if (drv)
strlcpy(str, osk_drivers[i]->ident, sizeof_str);
}
#ifdef HAVE_MENU
else if (!strcmp(label, "menu_driver"))
{
drv = menu_ctx_drivers[i];
if (drv)
strlcpy(str, menu_ctx_drivers[i]->ident, sizeof_str);
}
#endif
else if (!strcmp(label, "input_driver"))
{
drv = input_drivers[i];
if (drv)
strlcpy(str, input_drivers[i]->ident, sizeof_str);
}
else if (!strcmp(label, "input_joypad_driver"))
{
drv = joypad_drivers[i];
if (drv)
strlcpy(str, joypad_drivers[i]->ident, sizeof_str);
}
else if (!strcmp(label, "video_driver"))
{
drv = video_drivers[i];
if (drv)
strlcpy(str, video_drivers[i]->ident, sizeof_str);
}
else if (!strcmp(label, "audio_driver"))
{
drv = audio_drivers[i];
if (drv)
strlcpy(str, audio_drivers[i]->ident, sizeof_str);
}
return drv;
}
static int find_driver_index(const char * label, const char *drv)
{
unsigned i;
char str[PATH_MAX];
const void *obj = NULL;
for (i = 0; (obj = (const void*)
find_driver_nonempty(label, i, str, sizeof(str))) != NULL; i++)
{
if (!obj)
return -1;
if (str[0] == '\0')
break;
if (!strcasecmp(drv, str))
return i;
}
return -1;
}
void find_prev_driver(const char *label, char *str, size_t sizeof_str)
{
int i = find_driver_index(label, str);
if (i > 0)
find_driver_nonempty(label, i - 1, str, sizeof_str);
else
RARCH_WARN(
"Couldn't find any previous driver (current one: \"%s\").\n", str);
}
void find_next_driver(const char *label, char *str, size_t sizeof_str)
{
int i = find_driver_index(label, str);
if (i >= 0)
find_driver_nonempty(label, i + 1, str, sizeof_str);
else
RARCH_WARN("Couldn't find any next driver (current one: \"%s\").\n", str);
}
static void find_osk_driver(void)
{
int i = find_driver_index("osk_driver", g_settings.osk.driver);
if (i >= 0)
driver.osk = osk_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n",
g_settings.osk.driver);
RARCH_LOG_OUTPUT("Available OSK drivers are:\n");
for (d = 0; osk_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", osk_drivers[d]->ident);
RARCH_WARN("Going to default to first OSK driver...\n");
driver.osk = osk_drivers[0];
if (!driver.osk)
rarch_fail(1, "find_osk_driver()");
}
}
static void init_osk(void)
{
/* Resource leaks will follow if osk is initialized twice. */
if (driver.osk_data)
return;
find_osk_driver();
/* FIXME - refactor params later based on semantics */
driver.osk_data = driver.osk->init(0);
if (!driver.osk_data)
{
RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n");
driver.osk_active = false;
}
}
static void uninit_osk(void)
{
if (driver.osk_data && driver.osk && driver.osk->free)
driver.osk->free(driver.osk_data);
driver.osk_data = NULL;
}
static void find_camera_driver(void)
{
int i = find_driver_index("camera_driver", g_settings.camera.driver);
if (i >= 0)
driver.camera = camera_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any camera driver named \"%s\"\n",
g_settings.camera.driver);
RARCH_LOG_OUTPUT("Available camera drivers are:\n");
for (d = 0; camera_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", camera_drivers[d]->ident);
RARCH_WARN("Going to default to first camera driver...\n");
driver.camera = camera_drivers[0];
if (!driver.camera)
rarch_fail(1, "find_camera_driver()");
}
}
bool driver_camera_start(void)
{
if (driver.camera && driver.camera_data && driver.camera->start)
{
if (g_settings.camera.allow)
return driver.camera->start(driver.camera_data);
msg_queue_push(g_extern.msg_queue,
"Camera is explicitly disabled.\n", 1, 180);
}
return false;
}
void driver_camera_stop(void)
{
if (driver.camera && driver.camera->stop && driver.camera_data)
driver.camera->stop(driver.camera_data);
}
void driver_camera_poll(void)
{
if (driver.camera && driver.camera->poll && driver.camera_data)
driver.camera->poll(driver.camera_data,
g_extern.system.camera_callback.frame_raw_framebuffer,
g_extern.system.camera_callback.frame_opengl_texture);
}
static void init_camera(void)
{
/* Resource leaks will follow if camera is initialized twice. */
if (driver.camera_data)
return;
find_camera_driver();
driver.camera_data = driver.camera->init(
*g_settings.camera.device ? g_settings.camera.device : NULL,
g_extern.system.camera_callback.caps,
g_settings.camera.width ?
g_settings.camera.width : g_extern.system.camera_callback.width,
g_settings.camera.height ?
g_settings.camera.height : g_extern.system.camera_callback.height);
if (!driver.camera_data)
{
RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n");
driver.camera_active = false;
}
if (g_extern.system.camera_callback.initialized)
g_extern.system.camera_callback.initialized();
}
static void uninit_camera(void)
{
if (driver.camera_data && driver.camera)
{
if (g_extern.system.camera_callback.deinitialized)
g_extern.system.camera_callback.deinitialized();
if (driver.camera->free)
driver.camera->free(driver.camera_data);
}
driver.camera_data = NULL;
}
static void find_location_driver(void)
{
int i = find_driver_index("location_driver", g_settings.location.driver);
if (i >= 0)
driver.location = location_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any location driver named \"%s\"\n",
g_settings.location.driver);
RARCH_LOG_OUTPUT("Available location drivers are:\n");
for (d = 0; location_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", location_drivers[d]->ident);
RARCH_WARN("Going to default to first location driver...\n");
driver.location = location_drivers[0];
if (!driver.location)
rarch_fail(1, "find_location_driver()");
}
}
bool driver_location_start(void)
{
if (driver.location && driver.location_data && driver.location->start)
{
if (g_settings.location.allow)
return driver.location->start(driver.location_data);
msg_queue_push(g_extern.msg_queue, "Location is explicitly disabled.\n", 1, 180);
}
return false;
}
void driver_location_stop(void)
{
if (driver.location && driver.location->stop && driver.location_data)
driver.location->stop(driver.location_data);
}
void driver_location_set_interval(unsigned interval_msecs,
unsigned interval_distance)
{
if (driver.location && driver.location->set_interval
&& driver.location_data)
driver.location->set_interval(driver.location_data,
interval_msecs, interval_distance);
}
bool driver_location_get_position(double *lat, double *lon,
double *horiz_accuracy, double *vert_accuracy)
{
if (driver.location && driver.location->get_position
&& driver.location_data)
return driver.location->get_position(driver.location_data,
lat, lon, horiz_accuracy, vert_accuracy);
*lat = 0.0;
*lon = 0.0;
*horiz_accuracy = 0.0;
*vert_accuracy = 0.0;
return false;
}
static void init_location(void)
{
/* Resource leaks will follow if location interface is initialized twice. */
if (driver.location_data)
return;
find_location_driver();
driver.location_data = driver.location->init();
if (!driver.location_data)
{
RARCH_ERR("Failed to initialize location driver. Will continue without location.\n");
driver.location_active = false;
}
if (g_extern.system.location_callback.initialized)
g_extern.system.location_callback.initialized();
}
static void uninit_location(void)
{
if (driver.location_data && driver.location)
{
if (g_extern.system.location_callback.deinitialized)
g_extern.system.location_callback.deinitialized();
if (driver.location->free)
driver.location->free(driver.location_data);
}
driver.location_data = NULL;
}
#ifdef HAVE_MENU
static void find_menu_driver(void)
{
int i = find_driver_index("menu_driver", g_settings.menu.driver);
if (i >= 0)
driver.menu_ctx = menu_ctx_drivers[i];
else
{
unsigned d;
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n",
g_settings.menu.driver);
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
for (d = 0; menu_ctx_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_ctx_drivers[d]->ident);
RARCH_WARN("Going to default to first menu driver...\n");
driver.menu_ctx = menu_ctx_drivers[0];
if (!driver.menu_ctx)
rarch_fail(1, "find_menu_driver()");
}
}
#endif
static void find_audio_driver(void)
{
int i = find_driver_index("audio_driver", g_settings.audio.driver);
if (i >= 0)
driver.audio = audio_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any audio driver named \"%s\"\n",
g_settings.audio.driver);
RARCH_LOG_OUTPUT("Available audio drivers are:\n");
for (d = 0; audio_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", audio_drivers[d]->ident);
RARCH_WARN("Going to default to first audio driver...\n");
driver.audio = audio_drivers[0];
if (!driver.audio)
rarch_fail(1, "find_audio_driver()");
}
}
static void find_video_driver(void)
{
int i;
#if defined(HAVE_OPENGL) && defined(HAVE_FBO)
if (g_extern.system.hw_render_callback.context_type)
{
RARCH_LOG("Using HW render, OpenGL driver forced.\n");
driver.video = &video_gl;
return;
}
#endif
if (driver.frontend_ctx &&
driver.frontend_ctx->get_video_driver)
{
driver.video = driver.frontend_ctx->get_video_driver();
if (driver.video)
return;
RARCH_WARN("Frontend supports get_video_driver() but did not specify one.\n");
}
i = find_driver_index("video_driver", g_settings.video.driver);
if (i >= 0)
driver.video = video_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any video driver named \"%s\"\n",
g_settings.video.driver);
RARCH_LOG_OUTPUT("Available video drivers are:\n");
for (d = 0; video_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", video_drivers[d]->ident);
RARCH_WARN("Going to default to first video driver...\n");
driver.video = video_drivers[0];
if (!driver.video)
rarch_fail(1, "find_video_driver()");
}
}
static void find_input_driver(void)
{
int i = find_driver_index("input_driver", g_settings.input.driver);
if (i >= 0)
driver.input = input_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any input driver named \"%s\"\n",
g_settings.input.driver);
RARCH_LOG_OUTPUT("Available input drivers are:\n");
for (d = 0; input_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", input_drivers[d]->ident);
RARCH_WARN("Going to default to first input driver...\n");
driver.input = input_drivers[0];
if (!driver.input)
rarch_fail(1, "find_input_driver()");
}
}
void init_drivers_pre(void)
{
find_audio_driver();
find_video_driver();
find_input_driver();
find_camera_driver();
find_location_driver();
find_osk_driver();
#ifdef HAVE_MENU
find_menu_driver();
#endif
}
static void adjust_system_rates(void)
{
float timing_skew;
const struct retro_system_timing *info =
(const struct retro_system_timing*)&g_extern.system.av_info.timing;
g_extern.system.force_nonblock = false;
if (info->fps <= 0.0 || info->sample_rate <= 0.0)
return;
timing_skew = fabs(1.0f - info->fps / g_settings.video.refresh_rate);
if (timing_skew > g_settings.audio.max_timing_skew)
{
/* We don't want to adjust pitch too much. If we have extreme cases,
* just don't readjust at all. */
RARCH_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n",
g_settings.video.refresh_rate,
(float)info->fps);
/* We won't be able to do VSync reliably as game FPS > monitor FPS. */
if (info->fps > g_settings.video.refresh_rate)
{
g_extern.system.force_nonblock = true;
RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n");
}
g_extern.audio_data.in_rate = info->sample_rate;
}
else
g_extern.audio_data.in_rate = info->sample_rate *
(g_settings.video.refresh_rate / info->fps);
RARCH_LOG("Set audio input rate to: %.2f Hz.\n",
g_extern.audio_data.in_rate);
if (driver.video_data)
{
if (g_extern.system.force_nonblock)
rarch_main_command(RARCH_CMD_VIDEO_SET_NONBLOCKING_STATE);
else
driver_set_nonblock_state(driver.nonblock_state);
}
}
void driver_set_monitor_refresh_rate(float hz)
{
char msg[PATH_MAX];
snprintf(msg, sizeof(msg), "Setting refresh rate to: %.3f Hz.", hz);
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
RARCH_LOG("%s\n", msg);
g_settings.video.refresh_rate = hz;
adjust_system_rates();
g_extern.audio_data.orig_src_ratio =
g_extern.audio_data.src_ratio =
(double)g_settings.audio.out_rate / g_extern.audio_data.in_rate;
}
void driver_set_nonblock_state(bool nonblock)
{
/* Only apply non-block-state for video if we're using vsync. */
if (driver.video_active && driver.video_data)
{
bool video_nonblock = nonblock;
if (!g_settings.video.vsync || g_extern.system.force_nonblock)
video_nonblock = true;
driver.video->set_nonblock_state(driver.video_data, video_nonblock);
}
if (driver.audio_active && driver.audio_data)
driver.audio->set_nonblock_state(driver.audio_data,
g_settings.audio.sync ? nonblock : true);
g_extern.audio_data.chunk_size = nonblock ?
g_extern.audio_data.nonblock_chunk_size :
g_extern.audio_data.block_chunk_size;
}
bool driver_set_rumble_state(unsigned port,
enum retro_rumble_effect effect, uint16_t strength)
{