@@ -54,6 +54,30 @@ sc_microphone_list_audio_sources(void) {
5454 LOGI ("Audio input format: %s (%s)" ,
5555 input_format -> name ,
5656 input_format -> long_name ? input_format -> long_name : "no description" );
57+
58+ #ifdef __APPLE__
59+ LOGI ("Listing devices via avfoundation (see output above/below):" );
60+
61+ AVDictionary * options = NULL ;
62+ av_dict_set (& options , "list_devices" , "true" , 0 );
63+
64+ AVFormatContext * fmt_ctx = NULL ;
65+ avformat_open_input (& fmt_ctx , "" , input_format , & options );
66+
67+ av_dict_free (& options );
68+ if (fmt_ctx ) {
69+ avformat_close_input (& fmt_ctx );
70+ }
71+
72+ LOGI ("How to use:" );
73+ LOGI (" Use the audio device index with --client-audio-source" );
74+ LOGI (" Format: \":AUDIO_INDEX\" (e.g., \":0\" for first audio device)" );
75+ LOGI ("Examples:" );
76+ LOGI (" scrcpy --client-audio-source :0" );
77+ LOGI (" scrcpy --client-audio-source file:///path/to/audio.mp3" );
78+ return ;
79+ #endif
80+
5781 LOGI ("Available audio sources:" );
5882
5983 AVDeviceInfoList * device_list = NULL ;
@@ -66,9 +90,6 @@ sc_microphone_list_audio_sources(void) {
6690#ifdef _WIN32
6791 LOGI (" - \"audio=DEVICE_NAME\" (for dshow)" );
6892 LOGI (" - Try running 'ffmpeg -list_devices true -f dshow -i dummy' to see available devices" );
69- #elif defined(__APPLE__ )
70- LOGI (" - \":0\" (default microphone)" );
71- LOGI (" - Try running 'ffmpeg -f avfoundation -list_devices true -i \"\"' to see available devices" );
7293#else
7394 LOGI (" - \"default\" (default ALSA device)" );
7495 LOGI (" - \"hw:0,0\" (hardware device)" );
@@ -93,13 +114,10 @@ sc_microphone_list_audio_sources(void) {
93114 avdevice_free_list_devices (& device_list );
94115
95116 LOGI ("How to use:" );
96- LOGI (" Use the device name exactly as shown above with --client-audio-source" );
117+ LOGI (" Pass the device names shown above as --client-audio-source <device> " );
97118 LOGI ("Common microphone devices:" );
98119#ifdef _WIN32
99120 LOGI (" - \"audio=DEVICE_NAME\" (use the exact name from the list)" );
100- #elif defined(__APPLE__ )
101- LOGI (" - \":0\" or \":1\" (device indices for macOS)" );
102- LOGI (" - \"default\" (default microphone)" );
103121#else
104122 LOGI (" - \"default\" (usually your default microphone)" );
105123 LOGI (" - \"hw:CARD,DEV\" devices are hardware devices" );
@@ -289,8 +307,15 @@ sc_microphone_run(void *data) {
289307 }
290308
291309 if (read_ret < 0 ) {
292- // For device input, any error means we should stop
310+ // EAGAIN means no data available yet, retry
311+ if (read_ret == AVERROR (EAGAIN )) {
312+ av_usleep (1000 );
313+ continue ;
314+ }
293315 if (!is_file ) {
316+ char errbuf [128 ];
317+ av_strerror (read_ret , errbuf , sizeof (errbuf ));
318+ LOGD ("av_read_frame error: %d (%s)" , read_ret , errbuf );
294319 break ;
295320 }
296321 continue ;
0 commit comments