|
|
|
|
@ -34,6 +34,8 @@ struct stream_media_cursor {
|
|
|
|
|
int initialized; |
|
|
|
|
unsigned tracks; |
|
|
|
|
int64_t start_us; |
|
|
|
|
int audio_started; |
|
|
|
|
int64_t audio_blocked_pts; |
|
|
|
|
uint8_t *scratch[2], *frame; |
|
|
|
|
size_t scratch_capacity, frame_capacity; |
|
|
|
|
uint64_t scratch_seq[2]; |
|
|
|
|
@ -258,6 +260,7 @@ void stream_media_cursor_destroy(struct stream_media_cursor *c) {
|
|
|
|
|
void stream_media_cursor_reset(struct stream_media_cursor *c) { |
|
|
|
|
if (!c) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "media cursor reset: null cursor"); return; } |
|
|
|
|
c->initialized = 0; c->video_revision = 0; c->pending_used = 0; |
|
|
|
|
c->audio_started = 0; c->audio_blocked_pts = -1; |
|
|
|
|
c->pending = (struct stream_media_video){0}; c->pending_format = (struct stream_media_format){0}; |
|
|
|
|
c->scratch_valid[0] = c->scratch_valid[1] = 0; |
|
|
|
|
c->video = (struct cursor_track){0}; c->audio = (struct cursor_track){0}; |
|
|
|
|
@ -431,10 +434,22 @@ int stream_media_cursor_read(struct stream_media_cursor *c, int64_t position, in
|
|
|
|
|
result = cursor_block(c, c->audio.seq, &audio); |
|
|
|
|
if (result != STREAM_OK) return result; |
|
|
|
|
struct stream_media_audio a = audio.audio[c->audio.entry++]; |
|
|
|
|
if (!c->audio_started) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "media cursor first audio source=%llx seq=%llu pts=%llu start=%lld lead_us=%lld", |
|
|
|
|
(unsigned long long)c->store->descriptor.source_node_id, (unsigned long long)c->audio.seq, |
|
|
|
|
(unsigned long long)a.pts_us, (long long)c->start_us, (long long)((int64_t)a.pts_us - c->start_us)); |
|
|
|
|
c->audio_started = 1; |
|
|
|
|
} |
|
|
|
|
memcpy(c->opus, a.data, a.length); a.data = c->opus; |
|
|
|
|
*packet = (struct stream_media_packet){.kind = STREAM_MEDIA_READ_AUDIO, .format = audio.format, .audio = a}; |
|
|
|
|
return STREAM_OK; |
|
|
|
|
} |
|
|
|
|
if (video_allowed) return cursor_video(c, packet); |
|
|
|
|
if (ar == STREAM_OK && audio_ahead >= 0 && audio_pts > audio_limit && c->audio_blocked_pts != audio_pts) { |
|
|
|
|
c->audio_blocked_pts = audio_pts; |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_STREAM, "media cursor audio waits source=%llx seq=%llu pts=%lld position=%lld limit=%lld first=%d video_requested=%d", |
|
|
|
|
(unsigned long long)c->store->descriptor.source_node_id, (unsigned long long)c->audio.seq, |
|
|
|
|
(long long)audio_pts, (long long)position, (long long)audio_limit, !c->audio_started, want_video); |
|
|
|
|
} |
|
|
|
|
return ar == STREAM_MORE || vr == STREAM_MORE ? STREAM_MORE : STREAM_WAIT; |
|
|
|
|
} |
|
|
|
|
|