b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | #include "ring_tele.h" |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 6 | #include "lynq/lynq-qser-audio.h" |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 7 | |
| 8 | static int playback_handle = 1; |
| 9 | |
| 10 | void player_cmd_proc(char *cmdstr) |
| 11 | { |
| 12 | if (strcmp(cmdstr, "P\n") == 0) |
| 13 | { |
| 14 | qser_AudPlayer_Pause(playback_handle); |
| 15 | } |
| 16 | else if (strcmp(cmdstr, "R\n") == 0) |
| 17 | { |
| 18 | qser_AudPlayer_Resume(playback_handle); |
| 19 | } |
| 20 | else if (strcmp(cmdstr, "T\n") == 0) |
| 21 | { |
| 22 | qser_AudPlayer_Stop(playback_handle); |
| 23 | } |
| 24 | else |
| 25 | { |
| 26 | printf("Unknown command: %s", cmdstr); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | void capture_cmd_proc(char *cmdstr) |
| 31 | { |
| 32 | if (strcmp(cmdstr, "P\n") == 0) |
| 33 | { |
| 34 | qser_AudRecorder_Pause(); |
| 35 | } |
| 36 | else if (strcmp(cmdstr, "R\n") == 0) |
| 37 | { |
| 38 | qser_AudRecorder_Resume(); |
| 39 | } |
| 40 | else if (strcmp(cmdstr, "T\n") == 0) |
| 41 | { |
| 42 | qser_AudRecorder_Stop(); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | printf("Unknown command: %s", cmdstr); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | int main(int argc, char *argv[]) |
| 51 | { |
| 52 | if (argc < 2) |
| 53 | { |
| 54 | printf("Usage: %s <play|recd|playbuf> [file]\n", argv[0]); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | const char *action = argv[1]; |
| 59 | const char *file = argv[2]; |
| 60 | |
| 61 | int g_audio_owner_id = 0; |
| 62 | char player_device[] = "device1"; |
| 63 | char recorder_device[] = "device2"; |
| 64 | char cmdstr[256]; |
| 65 | |
| 66 | _cb_onPlayer cb_fun = [](int result) |
| 67 | { |
| 68 | if (result == 0) |
| 69 | { |
| 70 | printf("Audio recorder opened successfully.\n"); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | printf("Failed to open audio recorder, error code: %d\n", result); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | if (strcmp(action, "playbuf") == 0) |
| 79 | { |
| 80 | int player_open_result = qser_AudPlayer_Open(player_device, cb_fun); |
| 81 | if (player_open_result != 0) |
| 82 | { |
| 83 | printf("Failed to open audio player.\n"); |
| 84 | return 1; |
| 85 | } |
| 86 | qser_AudPlayer_PlayPcmBuf(PCM_DATA, PCM_DATA_SIZE, 640, 3, 1, 8000, g_audio_owner_id); |
| 87 | while (1) |
| 88 | { |
| 89 | printf("Please input a player command (P/R/T/exit) :\n"); |
| 90 | if (fgets(cmdstr, sizeof(cmdstr), stdin) != NULL) |
| 91 | { |
| 92 | if (strcmp(cmdstr, "exit\n") == 0) |
| 93 | { |
| 94 | qser_AudPlayer_Close(playback_handle); |
| 95 | break; |
| 96 | } |
| 97 | player_cmd_proc(cmdstr); |
| 98 | } |
| 99 | } |
| 100 | qser_AudPlayer_Close(playback_handle); |
| 101 | } |
| 102 | else if (strcmp(action, "play") == 0) |
| 103 | { |
| 104 | int player_open_result = qser_AudPlayer_Open(player_device, cb_fun); |
| 105 | if (player_open_result != 0) |
| 106 | { |
| 107 | printf("Failed to open audio player.\n"); |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | qser_AudPlayer_PlayFrmFile(g_audio_owner_id, file, 0); |
| 112 | |
| 113 | while (1) |
| 114 | { |
| 115 | printf("Please input a player command (P/R/T/exit) :\n"); |
| 116 | if (fgets(cmdstr, sizeof(cmdstr), stdin) != NULL) |
| 117 | { |
| 118 | if (strcmp(cmdstr, "exit\n") == 0) |
| 119 | { |
| 120 | qser_AudPlayer_Close(playback_handle); |
| 121 | break; |
| 122 | } |
| 123 | player_cmd_proc(cmdstr); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | qser_AudPlayer_Close(playback_handle); |
| 128 | } |
| 129 | else if (strcmp(action, "recd") == 0) |
| 130 | { |
| 131 | int recorder_open_result = qser_AudRecorder_Open(recorder_device, cb_fun); |
| 132 | if (recorder_open_result != 0) { |
| 133 | printf("Failed to open audio recorder.\n"); |
| 134 | return 1; |
| 135 | } |
| 136 | |
| 137 | qser_AudRecorder_StartRecord(g_audio_owner_id, file, 0); |
| 138 | |
| 139 | while (1) |
| 140 | { |
| 141 | printf("Please input a player command (P/R/T/exit) :\n"); |
| 142 | if (fgets(cmdstr, sizeof(cmdstr), stdin) != NULL) |
| 143 | { |
| 144 | if (strcmp(cmdstr, "exit\n") == 0) |
| 145 | { |
| 146 | qser_AudRecorder_Close(); |
| 147 | break; |
| 148 | } |
| 149 | capture_cmd_proc(cmdstr); |
| 150 | } |
| 151 | } |
| 152 | qser_AudRecorder_Close(); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | printf("Unknown action: %s\n", action); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | qser_Audio_Deinit(); |
| 161 | |
| 162 | return 0; |
| 163 | } |