diff --git a/audio/audio_driver.c b/audio/audio_driver.c index bc2231c76e..9f4999f304 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -183,6 +183,8 @@ static void *audio_driver_resampler_data = NULL; static const audio_driver_t *current_audio = NULL; static void *audio_driver_context_audio_data = NULL; +static bool audio_suspended = false; + enum resampler_quality audio_driver_get_resampler_quality(void) { settings_t *settings = config_get_ptr(); @@ -559,6 +561,9 @@ void audio_driver_set_nonblocking_state(bool enable) **/ static void audio_driver_flush(const int16_t *data, size_t samples) { + if (audio_suspended) + return; + struct resampler_data src_data; bool is_perfcnt_enable = false; bool is_paused = false; @@ -696,6 +701,9 @@ static void audio_driver_flush(const int16_t *data, size_t samples) **/ void audio_driver_sample(int16_t left, int16_t right) { + if (audio_suspended) + return; + audio_driver_output_samples_conv_buf[audio_driver_data_ptr++] = left; audio_driver_output_samples_conv_buf[audio_driver_data_ptr++] = right; @@ -1286,11 +1294,31 @@ bool audio_driver_owns_driver(void) return audio_driver_data_own; } +void audio_driver_suspend(void) +{ + audio_suspended = true; +} + +bool audio_driver_is_suspended(void) +{ + return audio_suspended; +} + +void audio_driver_resume(void) +{ + audio_suspended = false; +} + void audio_driver_set_active(void) { audio_driver_active = true; } +bool audio_driver_is_active(void) +{ + return audio_driver_active; +} + void audio_driver_destroy(void) { audio_driver_active = false; diff --git a/audio/audio_driver.h b/audio/audio_driver.h index 9e050de794..0054050184 100644 --- a/audio/audio_driver.h +++ b/audio/audio_driver.h @@ -152,8 +152,16 @@ void audio_driver_set_own_driver(void); void audio_driver_unset_own_driver(void); +void audio_driver_suspend(void); + +bool audio_driver_is_suspended(void); + +void audio_driver_resume(void); + void audio_driver_set_active(void); +bool audio_driver_is_active(void); + void audio_driver_destroy(void); void audio_driver_deinit_resampler(void); diff --git a/dynamic.c b/dynamic.c index 9c09c2fc96..6a8ede407d 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1692,6 +1692,25 @@ bool rarch_environment_cb(unsigned cmd, void *data) ledintf->set_led_state = led_driver_set_led; } break; + + case RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE: + { + int result = 0; + if (!audio_driver_is_suspended() && audio_driver_is_active()) + { + result |= 2; + } + if (video_driver_is_active() && !video_driver_is_stub_frame()) + { + result |= 1; + } + if (data != NULL) + { + int* result_p = (int*)data; + *result_p = result; + } + } + break; default: RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index e953666ebd..f8051f02bf 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -1585,6 +1585,11 @@ void video_driver_unset_stub_frame(void) frame_bak = NULL; } +bool video_driver_is_stub_frame(void) +{ + return current_video->frame == video_null.frame; +} + bool video_driver_supports_recording(void) { settings_t *settings = config_get_ptr(); @@ -2146,6 +2151,11 @@ void video_driver_set_active(void) video_driver_active = true; } +void video_driver_unset_active(void) +{ + video_driver_active = false; +} + bool video_driver_is_active(void) { return video_driver_active; diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 8a09fea33c..ca3401953b 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -905,6 +905,7 @@ void video_driver_destroy(void); void video_driver_set_cached_frame_ptr(const void *data); void video_driver_set_stub_frame(void); void video_driver_unset_stub_frame(void); +bool video_driver_is_stub_frame(void); bool video_driver_supports_recording(void); bool video_driver_supports_viewport_read(void); bool video_driver_supports_read_frame_raw(void); @@ -949,6 +950,7 @@ bool video_driver_is_video_cache_context(void); void video_driver_set_video_cache_context_ack(void); bool video_driver_is_video_cache_context_ack(void); void video_driver_set_active(void); +void video_driver_unset_active(void); bool video_driver_is_active(void); bool video_driver_gpu_record_init(unsigned size); void video_driver_gpu_record_deinit(void); diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index e15403d8b6..7d0cf19a20 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -1113,6 +1113,7 @@ struct retro_led_interface retro_set_led_state_t set_led_state; }; +#define RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE (47 | RETRO_ENVIRONMENT_EXPERIMENTAL) #define RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE (41 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* const struct retro_hw_render_interface ** --