obs-audio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <inttypes.h>
  15. #include "obs-internal.h"
  16. #include "util/util_uint64.h"
  17. struct ts_info {
  18. uint64_t start;
  19. uint64_t end;
  20. };
  21. #define DEBUG_AUDIO 0
  22. #define DEBUG_LAGGED_AUDIO 0
  23. static void push_audio_tree(obs_source_t *parent, obs_source_t *source, void *p)
  24. {
  25. struct obs_core_audio *audio = p;
  26. if (da_find(audio->render_order, &source, 0) == DARRAY_INVALID) {
  27. obs_source_t *s = obs_source_get_ref(source);
  28. if (s)
  29. da_push_back(audio->render_order, &s);
  30. }
  31. UNUSED_PARAMETER(parent);
  32. }
  33. static inline size_t convert_time_to_frames(size_t sample_rate, uint64_t t)
  34. {
  35. return (size_t)util_mul_div64(t, sample_rate, 1000000000ULL);
  36. }
  37. static inline void mix_audio(struct audio_output_data *mixes, obs_source_t *source, size_t channels, size_t sample_rate,
  38. struct ts_info *ts)
  39. {
  40. size_t total_floats = AUDIO_OUTPUT_FRAMES;
  41. size_t start_point = 0;
  42. if (source->audio_ts < ts->start || ts->end <= source->audio_ts)
  43. return;
  44. if (source->audio_ts != ts->start) {
  45. start_point = convert_time_to_frames(sample_rate, source->audio_ts - ts->start);
  46. if (start_point == AUDIO_OUTPUT_FRAMES)
  47. return;
  48. total_floats -= start_point;
  49. }
  50. for (size_t mix_idx = 0; mix_idx < MAX_AUDIO_MIXES; mix_idx++) {
  51. for (size_t ch = 0; ch < channels; ch++) {
  52. register float *mix = mixes[mix_idx].data[ch];
  53. register float *aud = source->audio_output_buf[mix_idx][ch];
  54. register float *end;
  55. mix += start_point;
  56. end = aud + total_floats;
  57. while (aud < end)
  58. *(mix++) += *(aud++);
  59. }
  60. }
  61. }
  62. static bool ignore_audio(obs_source_t *source, size_t channels, size_t sample_rate, uint64_t start_ts)
  63. {
  64. size_t num_floats = source->audio_input_buf[0].size / sizeof(float);
  65. const char *name = obs_source_get_name(source);
  66. if (!source->audio_ts && num_floats) {
  67. #if DEBUG_LAGGED_AUDIO == 1
  68. blog(LOG_DEBUG, "[src: %s] no timestamp, but audio available?", name);
  69. #endif
  70. for (size_t ch = 0; ch < channels; ch++)
  71. deque_pop_front(&source->audio_input_buf[ch], NULL, source->audio_input_buf[0].size);
  72. source->last_audio_input_buf_size = 0;
  73. return false;
  74. }
  75. if (num_floats) {
  76. /* round up the number of samples to drop */
  77. size_t drop = (size_t)util_mul_div64(start_ts - source->audio_ts - 1, sample_rate, 1000000000ULL) + 1;
  78. if (drop > num_floats)
  79. drop = num_floats;
  80. #if DEBUG_LAGGED_AUDIO == 1
  81. blog(LOG_DEBUG, "[src: %s] ignored %" PRIu64 "/%" PRIu64 " samples", name, (uint64_t)drop,
  82. (uint64_t)num_floats);
  83. #endif
  84. for (size_t ch = 0; ch < channels; ch++)
  85. deque_pop_front(&source->audio_input_buf[ch], NULL, drop * sizeof(float));
  86. source->last_audio_input_buf_size = 0;
  87. source->audio_ts += util_mul_div64(drop, 1000000000ULL, sample_rate);
  88. blog(LOG_DEBUG, "[src: %s] ts lag after ignoring: %" PRIu64, name, start_ts - source->audio_ts);
  89. /* rounding error, adjust */
  90. if (source->audio_ts == (start_ts - 1))
  91. source->audio_ts = start_ts;
  92. /* source is back in sync */
  93. if (source->audio_ts >= start_ts)
  94. return true;
  95. } else {
  96. #if DEBUG_LAGGED_AUDIO == 1
  97. blog(LOG_DEBUG, "[src: %s] no samples to ignore! ts = %" PRIu64, name, source->audio_ts);
  98. #endif
  99. }
  100. if (!source->audio_pending || num_floats) {
  101. blog(LOG_WARNING,
  102. "Source %s audio is lagging (over by %.02f ms) "
  103. "at max audio buffering. Restarting source audio.",
  104. name, (start_ts - source->audio_ts) / 1000000.);
  105. }
  106. source->audio_pending = true;
  107. source->audio_ts = 0;
  108. /* tell the timestamp adjustment code in source_output_audio_data to
  109. * reset everything, and hopefully fix the timestamps */
  110. source->timing_set = false;
  111. return false;
  112. }
  113. static bool discard_if_stopped(obs_source_t *source, size_t channels)
  114. {
  115. size_t last_size;
  116. size_t size;
  117. last_size = source->last_audio_input_buf_size;
  118. size = source->audio_input_buf[0].size;
  119. if (!size)
  120. return false;
  121. /* if perpetually pending data, it means the audio has stopped,
  122. * so clear the audio data */
  123. if (last_size == size) {
  124. if (!source->pending_stop) {
  125. source->pending_stop = true;
  126. #if DEBUG_AUDIO == 1
  127. blog(LOG_DEBUG, "doing pending stop trick: '%s'", source->context.name);
  128. #endif
  129. return false;
  130. }
  131. for (size_t ch = 0; ch < channels; ch++)
  132. deque_pop_front(&source->audio_input_buf[ch], NULL, source->audio_input_buf[ch].size);
  133. source->pending_stop = false;
  134. source->audio_ts = 0;
  135. source->last_audio_input_buf_size = 0;
  136. #if DEBUG_AUDIO == 1
  137. blog(LOG_DEBUG, "source audio data appears to have "
  138. "stopped, clearing");
  139. #endif
  140. return true;
  141. } else {
  142. source->last_audio_input_buf_size = size;
  143. return false;
  144. }
  145. }
  146. #define MAX_AUDIO_SIZE (AUDIO_OUTPUT_FRAMES * sizeof(float))
  147. static inline void discard_audio(struct obs_core_audio *audio, obs_source_t *source, size_t channels,
  148. size_t sample_rate, struct ts_info *ts)
  149. {
  150. size_t total_floats = AUDIO_OUTPUT_FRAMES;
  151. size_t size;
  152. /* debug assert only */
  153. UNUSED_PARAMETER(audio);
  154. #if DEBUG_AUDIO == 1
  155. bool is_audio_source = source->info.output_flags & OBS_SOURCE_AUDIO;
  156. #endif
  157. if (source->info.audio_render) {
  158. source->audio_ts = 0;
  159. return;
  160. }
  161. if (ts->end <= source->audio_ts) {
  162. #if DEBUG_AUDIO == 1
  163. blog(LOG_DEBUG,
  164. "can't discard, source "
  165. "timestamp (%" PRIu64 ") >= "
  166. "end timestamp (%" PRIu64 ")",
  167. source->audio_ts, ts->end);
  168. #endif
  169. return;
  170. }
  171. if (source->audio_ts < (ts->start - 1)) {
  172. if (source->audio_pending && source->audio_input_buf[0].size < MAX_AUDIO_SIZE &&
  173. discard_if_stopped(source, channels))
  174. return;
  175. #if DEBUG_AUDIO == 1
  176. if (is_audio_source) {
  177. blog(LOG_DEBUG,
  178. "can't discard, source "
  179. "timestamp (%" PRIu64 ") < "
  180. "start timestamp (%" PRIu64 ")",
  181. source->audio_ts, ts->start);
  182. }
  183. /* ignore_audio should have already run and marked this source
  184. * pending, unless we *just* added buffering */
  185. assert(audio->total_buffering_ticks < audio->max_buffering_ticks || source->audio_pending ||
  186. !source->audio_ts || audio->buffering_wait_ticks);
  187. #endif
  188. return;
  189. }
  190. if (source->audio_ts != ts->start && source->audio_ts != (ts->start - 1)) {
  191. size_t start_point = convert_time_to_frames(sample_rate, source->audio_ts - ts->start);
  192. if (start_point == AUDIO_OUTPUT_FRAMES) {
  193. #if DEBUG_AUDIO == 1
  194. if (is_audio_source)
  195. blog(LOG_DEBUG, "can't discard, start point is "
  196. "at audio frame count");
  197. #endif
  198. return;
  199. }
  200. total_floats -= start_point;
  201. }
  202. size = total_floats * sizeof(float);
  203. if (source->audio_input_buf[0].size < size) {
  204. if (discard_if_stopped(source, channels))
  205. return;
  206. #if DEBUG_AUDIO == 1
  207. if (is_audio_source)
  208. blog(LOG_DEBUG, "can't discard, data still pending");
  209. #endif
  210. source->audio_ts = ts->end;
  211. return;
  212. }
  213. for (size_t ch = 0; ch < channels; ch++)
  214. deque_pop_front(&source->audio_input_buf[ch], NULL, size);
  215. source->last_audio_input_buf_size = 0;
  216. #if DEBUG_AUDIO == 1
  217. if (is_audio_source)
  218. blog(LOG_DEBUG, "audio discarded, new ts: %" PRIu64, ts->end);
  219. #endif
  220. source->pending_stop = false;
  221. source->audio_ts = ts->end;
  222. }
  223. static inline bool audio_buffering_maxed(struct obs_core_audio *audio)
  224. {
  225. return audio->total_buffering_ticks == audio->max_buffering_ticks;
  226. }
  227. static void set_fixed_audio_buffering(struct obs_core_audio *audio, size_t sample_rate, struct ts_info *ts)
  228. {
  229. struct ts_info new_ts;
  230. size_t total_ms;
  231. int ticks;
  232. if (audio_buffering_maxed(audio))
  233. return;
  234. if (!audio->buffering_wait_ticks)
  235. audio->buffered_ts = ts->start;
  236. ticks = audio->max_buffering_ticks - audio->total_buffering_ticks;
  237. audio->total_buffering_ticks += ticks;
  238. total_ms = audio->total_buffering_ticks * AUDIO_OUTPUT_FRAMES * 1000 / sample_rate;
  239. blog(LOG_INFO,
  240. "Enabling fixed audio buffering, total "
  241. "audio buffering is now %d milliseconds",
  242. (int)total_ms);
  243. new_ts.start =
  244. audio->buffered_ts - audio_frames_to_ns(sample_rate, audio->buffering_wait_ticks * AUDIO_OUTPUT_FRAMES);
  245. while (ticks--) {
  246. const uint64_t cur_ticks = ++audio->buffering_wait_ticks;
  247. new_ts.end = new_ts.start;
  248. new_ts.start = audio->buffered_ts - audio_frames_to_ns(sample_rate, cur_ticks * AUDIO_OUTPUT_FRAMES);
  249. #if DEBUG_AUDIO == 1
  250. blog(LOG_DEBUG, "add buffered ts: %" PRIu64 "-%" PRIu64, new_ts.start, new_ts.end);
  251. #endif
  252. deque_push_front(&audio->buffered_timestamps, &new_ts, sizeof(new_ts));
  253. }
  254. *ts = new_ts;
  255. }
  256. static void add_audio_buffering(struct obs_core_audio *audio, size_t sample_rate, struct ts_info *ts, uint64_t min_ts,
  257. const char *buffering_name)
  258. {
  259. struct ts_info new_ts;
  260. uint64_t offset;
  261. uint64_t frames;
  262. size_t total_ms;
  263. size_t ms;
  264. int ticks;
  265. if (audio_buffering_maxed(audio))
  266. return;
  267. if (!audio->buffering_wait_ticks)
  268. audio->buffered_ts = ts->start;
  269. offset = ts->start - min_ts;
  270. frames = ns_to_audio_frames(sample_rate, offset);
  271. ticks = (int)((frames + AUDIO_OUTPUT_FRAMES - 1) / AUDIO_OUTPUT_FRAMES);
  272. audio->total_buffering_ticks += ticks;
  273. if (audio->total_buffering_ticks >= audio->max_buffering_ticks) {
  274. ticks -= audio->total_buffering_ticks - audio->max_buffering_ticks;
  275. audio->total_buffering_ticks = audio->max_buffering_ticks;
  276. blog(LOG_WARNING, "Max audio buffering reached!");
  277. }
  278. ms = ticks * AUDIO_OUTPUT_FRAMES * 1000 / sample_rate;
  279. total_ms = audio->total_buffering_ticks * AUDIO_OUTPUT_FRAMES * 1000 / sample_rate;
  280. blog(LOG_INFO,
  281. "adding %d milliseconds of audio buffering, total "
  282. "audio buffering is now %d milliseconds"
  283. " (source: %s)\n",
  284. (int)ms, (int)total_ms, buffering_name);
  285. #if DEBUG_AUDIO == 1
  286. blog(LOG_DEBUG,
  287. "min_ts (%" PRIu64 ") < start timestamp "
  288. "(%" PRIu64 ")",
  289. min_ts, ts->start);
  290. blog(LOG_DEBUG, "old buffered ts: %" PRIu64 "-%" PRIu64, ts->start, ts->end);
  291. #endif
  292. new_ts.start =
  293. audio->buffered_ts - audio_frames_to_ns(sample_rate, audio->buffering_wait_ticks * AUDIO_OUTPUT_FRAMES);
  294. while (ticks--) {
  295. const uint64_t cur_ticks = ++audio->buffering_wait_ticks;
  296. new_ts.end = new_ts.start;
  297. new_ts.start = audio->buffered_ts - audio_frames_to_ns(sample_rate, cur_ticks * AUDIO_OUTPUT_FRAMES);
  298. #if DEBUG_AUDIO == 1
  299. blog(LOG_DEBUG, "add buffered ts: %" PRIu64 "-%" PRIu64, new_ts.start, new_ts.end);
  300. #endif
  301. deque_push_front(&audio->buffered_timestamps, &new_ts, sizeof(new_ts));
  302. }
  303. *ts = new_ts;
  304. }
  305. static bool audio_buffer_insufficient(struct obs_source *source, size_t sample_rate, uint64_t min_ts)
  306. {
  307. size_t total_floats = AUDIO_OUTPUT_FRAMES;
  308. size_t size;
  309. if (source->info.audio_render || source->audio_pending || !source->audio_ts) {
  310. return false;
  311. }
  312. if (source->audio_ts != min_ts && source->audio_ts != (min_ts - 1)) {
  313. size_t start_point = convert_time_to_frames(sample_rate, source->audio_ts - min_ts);
  314. if (start_point >= AUDIO_OUTPUT_FRAMES)
  315. return false;
  316. total_floats -= start_point;
  317. }
  318. size = total_floats * sizeof(float);
  319. if (source->audio_input_buf[0].size < size) {
  320. source->audio_pending = true;
  321. return true;
  322. }
  323. return false;
  324. }
  325. static inline const char *find_min_ts(struct obs_core_data *data, uint64_t *min_ts)
  326. {
  327. obs_source_t *buffering_source = NULL;
  328. struct obs_source *source = data->first_audio_source;
  329. while (source) {
  330. if (!source->audio_pending && source->audio_ts && source->audio_ts < *min_ts) {
  331. *min_ts = source->audio_ts;
  332. buffering_source = source;
  333. }
  334. source = (struct obs_source *)source->next_audio_source;
  335. }
  336. return buffering_source ? obs_source_get_name(buffering_source) : NULL;
  337. }
  338. static inline bool mark_invalid_sources(struct obs_core_data *data, size_t sample_rate, uint64_t min_ts)
  339. {
  340. bool recalculate = false;
  341. struct obs_source *source = data->first_audio_source;
  342. while (source) {
  343. recalculate |= audio_buffer_insufficient(source, sample_rate, min_ts);
  344. source = (struct obs_source *)source->next_audio_source;
  345. }
  346. return recalculate;
  347. }
  348. static inline const char *calc_min_ts(struct obs_core_data *data, size_t sample_rate, uint64_t *min_ts)
  349. {
  350. const char *buffering_name = find_min_ts(data, min_ts);
  351. if (mark_invalid_sources(data, sample_rate, *min_ts))
  352. buffering_name = find_min_ts(data, min_ts);
  353. return buffering_name;
  354. }
  355. static inline void release_audio_sources(struct obs_core_audio *audio)
  356. {
  357. for (size_t i = 0; i < audio->render_order.num; i++)
  358. obs_source_release(audio->render_order.array[i]);
  359. }
  360. static inline void execute_audio_tasks(void)
  361. {
  362. struct obs_core_audio *audio = &obs->audio;
  363. bool tasks_remaining = true;
  364. while (tasks_remaining) {
  365. pthread_mutex_lock(&audio->task_mutex);
  366. if (audio->tasks.size) {
  367. struct obs_task_info info;
  368. deque_pop_front(&audio->tasks, &info, sizeof(info));
  369. info.task(info.param);
  370. }
  371. tasks_remaining = !!audio->tasks.size;
  372. pthread_mutex_unlock(&audio->task_mutex);
  373. }
  374. }
  375. bool audio_callback(void *param, uint64_t start_ts_in, uint64_t end_ts_in, uint64_t *out_ts, uint32_t mixers,
  376. struct audio_output_data *mixes)
  377. {
  378. struct obs_core_data *data = &obs->data;
  379. struct obs_core_audio *audio = &obs->audio;
  380. struct obs_source *source;
  381. size_t sample_rate = audio_output_get_sample_rate(audio->audio);
  382. size_t channels = audio_output_get_channels(audio->audio);
  383. struct ts_info ts = {start_ts_in, end_ts_in};
  384. size_t audio_size;
  385. uint64_t min_ts;
  386. da_resize(audio->render_order, 0);
  387. da_resize(audio->root_nodes, 0);
  388. deque_push_back(&audio->buffered_timestamps, &ts, sizeof(ts));
  389. deque_peek_front(&audio->buffered_timestamps, &ts, sizeof(ts));
  390. min_ts = ts.start;
  391. audio_size = AUDIO_OUTPUT_FRAMES * sizeof(float);
  392. #if DEBUG_AUDIO == 1
  393. blog(LOG_DEBUG, "ts %llu-%llu", ts.start, ts.end);
  394. #endif
  395. /* ------------------------------------------------ */
  396. /* build audio render order */
  397. pthread_mutex_lock(&obs->video.mixes_mutex);
  398. for (size_t j = 0; j < obs->video.mixes.num; j++) {
  399. struct obs_view *view = obs->video.mixes.array[j]->view;
  400. if (!view)
  401. continue;
  402. pthread_mutex_lock(&view->channels_mutex);
  403. /* NOTE: these are source channels, not audio channels */
  404. for (uint32_t i = 0; i < MAX_CHANNELS; i++) {
  405. obs_source_t *source = view->channels[i];
  406. if (!source)
  407. continue;
  408. if (!obs_source_active(source))
  409. continue;
  410. obs_source_enum_active_tree(source, push_audio_tree, audio);
  411. push_audio_tree(NULL, source, audio);
  412. if (obs->video.mixes.array[j] == obs->video.main_mix)
  413. da_push_back(audio->root_nodes, &source);
  414. }
  415. pthread_mutex_unlock(&view->channels_mutex);
  416. }
  417. pthread_mutex_unlock(&obs->video.mixes_mutex);
  418. pthread_mutex_lock(&data->audio_sources_mutex);
  419. source = data->first_audio_source;
  420. while (source) {
  421. push_audio_tree(NULL, source, audio);
  422. source = (struct obs_source *)source->next_audio_source;
  423. }
  424. pthread_mutex_unlock(&data->audio_sources_mutex);
  425. /* ------------------------------------------------ */
  426. /* render audio data */
  427. for (size_t i = 0; i < audio->render_order.num; i++) {
  428. obs_source_t *source = audio->render_order.array[i];
  429. obs_source_audio_render(source, mixers, channels, sample_rate, audio_size);
  430. /* if a source has gone backward in time and we can no
  431. * longer buffer, drop some or all of its audio */
  432. if (audio_buffering_maxed(audio) && source->audio_ts != 0 && source->audio_ts < ts.start) {
  433. if (source->info.audio_render) {
  434. blog(LOG_DEBUG,
  435. "render audio source %s timestamp has "
  436. "gone backwards",
  437. obs_source_get_name(source));
  438. /* just avoid further damage */
  439. source->audio_pending = true;
  440. #if DEBUG_AUDIO == 1
  441. /* this should really be fixed */
  442. assert(false);
  443. #endif
  444. } else {
  445. pthread_mutex_lock(&source->audio_buf_mutex);
  446. bool rerender = ignore_audio(source, channels, sample_rate, ts.start);
  447. pthread_mutex_unlock(&source->audio_buf_mutex);
  448. /* if we (potentially) recovered, re-render */
  449. if (rerender)
  450. obs_source_audio_render(source, mixers, channels, sample_rate, audio_size);
  451. }
  452. }
  453. }
  454. /* ------------------------------------------------ */
  455. /* get minimum audio timestamp */
  456. pthread_mutex_lock(&data->audio_sources_mutex);
  457. const char *buffering_name = calc_min_ts(data, sample_rate, &min_ts);
  458. pthread_mutex_unlock(&data->audio_sources_mutex);
  459. /* ------------------------------------------------ */
  460. /* if a source has gone backward in time, buffer */
  461. if (audio->fixed_buffer) {
  462. if (!audio_buffering_maxed(audio)) {
  463. set_fixed_audio_buffering(audio, sample_rate, &ts);
  464. }
  465. } else if (min_ts < ts.start) {
  466. add_audio_buffering(audio, sample_rate, &ts, min_ts, buffering_name);
  467. }
  468. /* ------------------------------------------------ */
  469. /* mix audio */
  470. if (!audio->buffering_wait_ticks) {
  471. for (size_t i = 0; i < audio->root_nodes.num; i++) {
  472. obs_source_t *source = audio->root_nodes.array[i];
  473. if (source->audio_pending)
  474. continue;
  475. pthread_mutex_lock(&source->audio_buf_mutex);
  476. if (source->audio_output_buf[0][0] && source->audio_ts)
  477. mix_audio(mixes, source, channels, sample_rate, &ts);
  478. pthread_mutex_unlock(&source->audio_buf_mutex);
  479. }
  480. }
  481. /* ------------------------------------------------ */
  482. /* discard audio */
  483. pthread_mutex_lock(&data->audio_sources_mutex);
  484. source = data->first_audio_source;
  485. while (source) {
  486. pthread_mutex_lock(&source->audio_buf_mutex);
  487. discard_audio(audio, source, channels, sample_rate, &ts);
  488. pthread_mutex_unlock(&source->audio_buf_mutex);
  489. source = (struct obs_source *)source->next_audio_source;
  490. }
  491. pthread_mutex_unlock(&data->audio_sources_mutex);
  492. /* ------------------------------------------------ */
  493. /* release audio sources */
  494. release_audio_sources(audio);
  495. deque_pop_front(&audio->buffered_timestamps, NULL, sizeof(ts));
  496. *out_ts = ts.start;
  497. if (audio->buffering_wait_ticks) {
  498. audio->buffering_wait_ticks--;
  499. return false;
  500. }
  501. execute_audio_tasks();
  502. UNUSED_PARAMETER(param);
  503. return true;
  504. }