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