MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / pulse_read_packet

Function pulse_read_packet

libavdevice/pulse_audio_dec.c:289–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
290{
291 PulseData *pd = s->priv_data;
292 int ret;
293 size_t read_length;
294 const void *read_data = NULL;
295 int64_t dts;
296 pa_usec_t latency;
297 int negative;
298 ptrdiff_t pos = 0;
299
300 pa_threaded_mainloop_lock(pd->mainloop);
301
302 CHECK_DEAD_GOTO(pd, ret, unlock_and_fail);
303
304 while (pos < pd->fragment_size) {
305 int r;
306
307 r = pa_stream_peek(pd->stream, &read_data, &read_length);
308 CHECK_SUCCESS_GOTO(ret, r == 0, unlock_and_fail);
309
310 if (read_length <= 0) {
311 pa_threaded_mainloop_wait(pd->mainloop);
312 CHECK_DEAD_GOTO(pd, ret, unlock_and_fail);
313 } else if (!read_data) {
314 /* There's a hole in the stream, skip it. We could generate
315 * silence, but that wouldn't work for compressed streams. */
316 r = pa_stream_drop(pd->stream);
317 CHECK_SUCCESS_GOTO(ret, r == 0, unlock_and_fail);
318 } else {
319 if (!pos) {
320 if (av_new_packet(pkt, pd->fragment_size) < 0) {
321 ret = AVERROR(ENOMEM);
322 goto unlock_and_fail;
323 }
324
325 dts = av_gettime();
326 pa_operation_unref(pa_stream_update_timing_info(pd->stream, NULL, NULL));
327
328 if (pa_stream_get_latency(pd->stream, &latency, &negative) >= 0) {
329 if (negative) {
330 dts += latency;
331 } else
332 dts -= latency;
333 } else {
334 av_log(s, AV_LOG_WARNING, "pa_stream_get_latency() failed\n");
335 }
336 }
337 if (pkt->size - pos < read_length) {
338 if (pos)
339 break;
340 pa_stream_drop(pd->stream);
341 /* Oversized fragment??? */
342 ret = AVERROR_EXTERNAL;
343 goto unlock_and_fail;
344 }
345 memcpy(pkt->data + pos, read_data, read_length);
346 pos += read_length;

Callers

nothing calls this directly

Calls 6

av_new_packetFunction · 0.85
av_gettimeFunction · 0.85
av_logFunction · 0.85
av_shrink_packetFunction · 0.85
ff_timefilter_updateFunction · 0.85
av_packet_unrefFunction · 0.85

Tested by

no test coverage detected