PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
rpc_server.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2005, ps2dev - http://www.ps2dev.org
7# Licenced under GNU Library General Public License version 2
8*/
9
15#include <stdio.h>
16#include <thbase.h>
17#include <thsemap.h>
18#include <loadcore.h>
19#include <sysmem.h>
20#include <intrman.h>
21#include <sifcmd.h>
22
23#include <audsrv.h>
24#include "audsrv_internal.h"
25#include "common.h"
26#include "rpc_client.h"
27#include "debug_printf.h"
28
29/* rpc server variables */
31static int rpc_buffer[18000/4] __attribute__((__aligned__(4)));
36
37
47static void *rpc_command(int func, unsigned *data, int size)
48{
49 int ret;
50
51 (void)size;
52
53 /* DPRINTF("rpc command %d\n", func); */
54 switch(func)
55 {
56 case AUDSRV_INIT:
57 ret = audsrv_init();
58 initialize_rpc_client();
59 break;
60
62 ret = audsrv_format_ok(data[0], data[1], data[2]);
63 break;
64
65 case AUDSRV_SET_FORMAT:
66 ret = audsrv_set_format(data[0], data[1], data[2]);
67 break;
68
69 case AUDSRV_WAIT_AUDIO:
70 ret = audsrv_wait_audio(data[0]);
71 break;
72
73 case AUDSRV_PLAY_AUDIO:
74 ret = audsrv_play_audio((const char *)&data[1], data[0]);
75 break;
76
77 case AUDSRV_STOP_AUDIO:
78 ret = audsrv_stop_audio();
79 break;
80
81 case AUDSRV_SET_VOLUME:
82 ret = audsrv_set_volume(data[0]);
83 break;
84
85 case AUDSRV_QUIT:
86 ret = audsrv_quit();
87 break;
88
89 case AUDSRV_PLAY_CD:
90 ret = audsrv_play_cd(data[0]);
91 break;
92
93 case AUDSRV_STOP_CD:
94 ret = audsrv_stop_cd();
95 break;
96
97 case AUDSRV_GET_CDPOS:
98 ret = audsrv_get_cdpos();
99 break;
100
101 case AUDSRV_GET_TRACKPOS:
102 ret = audsrv_get_trackpos();
103 break;
104
105 case AUDSRV_SET_THRESHOLD:
106 ret = audsrv_set_threshold(data[0]);
107 break;
108
109 case AUDSRV_GET_NUMTRACKS:
110 ret = audsrv_get_numtracks();
111 break;
112
113 case AUDSRV_GET_TRACKOFFSET:
114 ret = audsrv_get_track_offset(data[0]);
115 break;
116
117 case AUDSRV_PLAY_SECTORS:
118 ret = audsrv_cd_play_sectors(data[0], data[1]);
119 break;
120
121 case AUDSRV_GET_CD_STATUS:
122 ret = audsrv_get_cd_status();
123 break;
124
125 case AUDSRV_GET_CD_TYPE:
126 ret = audsrv_get_cd_type();
127 break;
128
129 case AUDSRV_PAUSE_CD:
130 ret = audsrv_cd_pause();
131 break;
132
133 case AUDSRV_RESUME_CD:
134 ret = audsrv_cd_resume();
135 break;
136
138 ret = audsrv_adpcm_init();
139 break;
140
141 case AUDSRV_LOAD_ADPCM:
142 return audsrv_load_adpcm((u32*)data[0], data[1], data[2]);
143
144 case AUDSRV_PLAY_ADPCM:
145 ret = audsrv_ch_play_adpcm(data[0], data[1]);
146 break;
147
148 case AUDSRV_IS_ADPCM_PLAYING:
149 ret = audsrv_is_adpcm_playing(data[0], data[1]);
150 break;
151
152 case AUDSRV_FREE_ADPCM:
153 ret = free_sample(data[0]);
154 break;
155
156 case AUDSRV_SET_ADPCM_VOL:
157 ret = audsrv_adpcm_set_volume(data[0], data[1], data[2]);
158 break;
159
160 case AUDSRV_AVAILABLE:
161 ret = audsrv_available();
162 break;
163
164 case AUDSRV_QUEUED:
165 ret = audsrv_queued();
166 break;
167
168 default:
169 ret = -1;
170 break;
171 }
172
173 data[0] = ret;
174 return data;
175}
176
182static void rpc_server_thread(void *arg)
183{
184 (void)arg;
185
186 SifInitRpc(0);
187
188 DPRINTF("creating rpc server\n");
189
190 SifSetRpcQueue(&qd, GetThreadId());
191 SifRegisterRpc(&sd0, AUDSRV_IRX, (void *)rpc_command, rpc_buffer, NULL, NULL, &qd);
192 SifRpcLoop(&qd);
193}
194
195int initialize_rpc_thread()
196{
197 int rpc_tid = create_thread(rpc_server_thread, 40, 0);
198 DPRINTF("rpc server thread 0x%x started\n", rpc_tid);
199 return (rpc_tid > 0);
200}
#define AUDSRV_FORMAT_OK
Definition audsrv_rpc.h:28
#define AUDSRV_INIT_ADPCM
Definition audsrv_rpc.h:50
#define AUDSRV_PLAY_CD
Definition audsrv_rpc.h:37
#define AUDSRV_INIT
Definition audsrv_rpc.h:20
int audsrv_queued()
Definition audsrv_rpc.c:554
int audsrv_get_numtracks()
Definition audsrv_rpc.c:224
int audsrv_is_adpcm_playing(int ch, audsrv_adpcm_t *adpcm)
Definition audsrv_rpc.c:487
int audsrv_init()
Definition audsrv_rpc.c:328
int audsrv_get_cd_type()
Definition audsrv_rpc.c:244
int audsrv_play_audio(const char *chunk, int bytes)
Definition audsrv_rpc.c:254
int audsrv_adpcm_init()
Definition audsrv_rpc.c:394
int audsrv_stop_audio()
Definition audsrv_rpc.c:292
int audsrv_ch_play_adpcm(int ch, audsrv_adpcm_t *adpcm)
Definition audsrv_rpc.c:481
int audsrv_play_cd(int track)
Definition audsrv_rpc.c:197
int audsrv_available()
Definition audsrv_rpc.c:549
int audsrv_get_trackpos()
Definition audsrv_rpc.c:219
int audsrv_load_adpcm(audsrv_adpcm_t *adpcm, void *buffer, int size)
Definition audsrv_rpc.c:430
int audsrv_set_volume(int volume)
Definition audsrv_rpc.c:183
int audsrv_get_cdpos()
Definition audsrv_rpc.c:214
int audsrv_stop_cd()
Definition audsrv_rpc.c:207
int audsrv_wait_audio(int bytes)
Definition audsrv_rpc.c:178
int audsrv_get_track_offset(int track)
Definition audsrv_rpc.c:229
int audsrv_set_format(struct audsrv_fmt_t *fmt)
Definition audsrv_rpc.c:159
int audsrv_get_cd_status()
Definition audsrv_rpc.c:249
int audsrv_quit()
Definition audsrv_rpc.c:143
int audsrv_cd_resume()
Definition cdrom.c:307
int audsrv_cd_pause()
Definition cdrom.c:298
int audsrv_format_ok(int freq, int bits, int channels)
Definition audsrv.c:156
int audsrv_cd_play_sectors(int start, int end)
Definition cdrom.c:472
int free_sample(u32 id)
Definition adpcm.c:84
int create_thread(void *func, int priority, void *param)
Definition common.c:34
static void rpc_server_thread(void *arg)
Definition rpc_server.c:182
static SifRpcServerData_t sd0
Definition rpc_server.c:35
static SifRpcDataQueue_t qd
Definition rpc_server.c:33
static void * rpc_command(int func, unsigned *data, int size)
Definition rpc_server.c:47