Skip to content

Commit 5dfbd8b

Browse files
committed
More debug
1 parent 8f4d3d7 commit 5dfbd8b

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

android-run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ trap "trap_ctrlc" 2
4646

4747
{
4848
sleep 2
49-
#env PULSE_SERVER=tcp:192.168.42.129:4713 paplay music.ogg
50-
env PULSE_SERVER=tcp:192.168.42.129:4713 pavucontrol
49+
#env PULSE_SERVER=tcp:192.168.42.129:4713 pavucontrol &
50+
env PULSE_SERVER=tcp:192.168.42.129:4713 paplay music.ogg
5151
} &
5252

5353
adb shell "cd /data/local/tmp ; HOME=/data/local/tmp TMPDIR=/data/local/tmp LD_LIBRARY_PATH=/data/local/tmp \

src/modules/module-opensles.c

+34-26
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ struct userdata {
117117

118118
pa_memchunk memchunk;
119119

120-
pa_usec_t block_usec;
121-
pa_usec_t timestamp;
122-
123120
/* OpenSL objects */
124121
SLObjectItf engineObject;
125122
SLObjectItf outputMixObject;
@@ -149,9 +146,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
149146
{
150147
size_t n = 0;
151148

152-
// n = latency in bytes
153-
154-
n += u->memchunk.length;
149+
n += u->samples_per_buf * bytesPerSample();
155150

156151
*((int64_t*) data) = pa_bytes_to_usec(n, &u->sink->sample_spec);
157152
return 0;
@@ -169,8 +164,8 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
169164
pa_assert_se(u = s->userdata);
170165

171166
if (s->thread_info.state == PA_SINK_SUSPENDED || s->thread_info.state == PA_SINK_INIT) {
172-
if (PA_SINK_IS_OPENED(new_state))
173-
u->timestamp = pa_rtclock_now();
167+
if (PA_SINK_IS_OPENED(new_state)) {
168+
}
174169
} else if (PA_SINK_IS_OPENED(s->thread_info.state)) {
175170
if (new_state == PA_SINK_SUSPENDED) {
176171
/* Continuously dropping data (clear counter on entering suspended state. */
@@ -184,24 +179,28 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
184179
return 0;
185180
}
186181

187-
static int process_render(struct userdata *u) {
182+
static int process_render(struct userdata *u, bool opened) {
188183
pa_assert(u);
189184

190185
struct userdata *sys = u; // Just an alias, so I won't need to modify copypasted code
191186
const size_t unit_size = sys->samples_per_buf * bytesPerSample();
192187
void *p;
193188
SLresult result;
194189

195-
pa_sink_render_full(u->sink, unit_size, &u->memchunk);
190+
if (opened) {
191+
pa_sink_render_full(u->sink, unit_size, &u->memchunk);
196192

197-
pa_assert(u->memchunk.length > 0);
193+
pa_assert(u->memchunk.length > 0);
198194

199-
p = pa_memblock_acquire(u->memchunk.memblock);
200-
memcpy(&sys->buf[unit_size * sys->next_buf], (uint8_t*) p + u->memchunk.index, u->memchunk.length);
201-
pa_memblock_release(u->memchunk.memblock);
195+
p = pa_memblock_acquire(u->memchunk.memblock);
196+
memcpy(&sys->buf[unit_size * sys->next_buf], (uint8_t*) p + u->memchunk.index, u->memchunk.length);
197+
pa_memblock_release(u->memchunk.memblock);
202198

203-
pa_memblock_unref(u->memchunk.memblock);
204-
pa_memchunk_reset(&u->memchunk);
199+
pa_memblock_unref(u->memchunk.memblock);
200+
pa_memchunk_reset(&u->memchunk);
201+
} else {
202+
pa_silence_memory(&sys->buf[unit_size * sys->next_buf], unit_size, &u->sink->sample_spec);
203+
}
205204

206205
SLAndroidSimpleBufferQueueState st;
207206
result = GetState(sys->playerBufferQueue, &st);
@@ -210,16 +209,19 @@ static int process_render(struct userdata *u) {
210209
return -1;
211210
}
212211

213-
if (st.count == OPENSLES_BUFFERS)
212+
if (st.count == OPENSLES_BUFFERS) {
213+
pa_log("st.count == OPENSLES_BUFFERS in %s", __func__);
214214
return -1;
215+
}
215216

216217
result = Enqueue(sys->playerBufferQueue,
217218
&sys->buf[unit_size * sys->next_buf], unit_size);
218219

219-
pa_log_debug("Play %d bytes, pos %d result %d data %x", unit_size, (int)(unit_size * sys->next_buf), (int) result, * ((int *) &sys->buf[unit_size * sys->next_buf]));
220+
pa_log_debug("Play %d bytes, pos %d result %d data %x stream opened %d", unit_size, (int)(unit_size * sys->next_buf), (int) result, * ((int *) &sys->buf[unit_size * sys->next_buf]), opened);
220221

221222
if (result == SL_RESULT_SUCCESS) {
222-
if (++sys->next_buf == OPENSLES_BUFFERS)
223+
sys->next_buf += 1;
224+
if (sys->next_buf >= OPENSLES_BUFFERS)
223225
sys->next_buf = 0;
224226
} else {
225227
/* XXX : if writing fails, we don't retry */
@@ -244,14 +246,18 @@ static void thread_func(void *userdata) {
244246
for (;;) {
245247
int ret;
246248

249+
pa_log_debug("%s:%d", __func__, __LINE__);
250+
247251
if (PA_UNLIKELY(u->sink->thread_info.rewind_requested))
248252
pa_sink_process_rewind(u->sink, 0);
249253

250-
/* Render some data and write it to the fifo */
251-
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
252-
if (process_render(u) < 0)
253-
goto fail;
254-
}
254+
pa_log_debug("%s:%d", __func__, __LINE__);
255+
256+
/* Render some data and write it */
257+
if (process_render(u, PA_SINK_IS_OPENED(u->sink->thread_info.state)) < 0)
258+
goto fail;
259+
260+
pa_log_debug("%s:%d", __func__, __LINE__);
255261

256262
if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
257263
goto fail;
@@ -261,6 +267,7 @@ static void thread_func(void *userdata) {
261267
}
262268

263269
fail:
270+
pa_log_debug("pa_rtpoll_run() failed");
264271
/* If this was no regular exit from the loop we have to continue
265272
* processing messages until we received PA_MESSAGE_SHUTDOWN */
266273
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
@@ -277,6 +284,7 @@ static void PlayedCallback (SLAndroidSimpleBufferQueueItf caller, void *pContext
277284

278285
pa_assert (caller == sys->playerBufferQueue);
279286

287+
//pa_log_debug("%s", __func__);
280288
}
281289

282290
int pa__init(pa_module *m) {
@@ -388,8 +396,8 @@ int pa__init(pa_module *m) {
388396
&sys->playerBufferQueue);
389397
CHECK_OPENSL_ERROR("Failed to get buff queue interface");
390398

391-
result = RegisterCallback(sys->playerBufferQueue, PlayedCallback, (void*) u);
392-
CHECK_OPENSL_ERROR("Failed to register buff queue callback.");
399+
//result = RegisterCallback(sys->playerBufferQueue, PlayedCallback, (void*) u);
400+
//CHECK_OPENSL_ERROR("Failed to register buff queue callback.");
393401

394402
// set the player's state to playing
395403
result = SetPlayState(sys->playerPlay, SL_PLAYSTATE_PLAYING);

0 commit comments

Comments
 (0)