|
|
|
|
@ -24,7 +24,7 @@ struct media_record {
|
|
|
|
|
}; |
|
|
|
|
struct media_queue { struct media_record *head, *tail; size_t bytes; unsigned count; }; |
|
|
|
|
struct android_media_session { |
|
|
|
|
uint64_t id, group, source, next_frame, last_pts[2], drain_until; |
|
|
|
|
uint64_t id, group, source, epoch, next_frame, last_pts[2], drain_until; |
|
|
|
|
struct STREAM_HANDLE *handle; |
|
|
|
|
struct stream_media_receiver *receiver; |
|
|
|
|
struct stream_media_format format; |
|
|
|
|
@ -110,7 +110,8 @@ static void media_event(struct UTUN_INSTANCE *inst, const struct stream_event *e
|
|
|
|
|
(void)arg; |
|
|
|
|
pthread_mutex_lock(&media_lock); |
|
|
|
|
if (inst == media_inst && viewer.handle && event->descriptor.group_id == viewer.group |
|
|
|
|
&& event->descriptor.source_node_id == viewer.source) { |
|
|
|
|
&& event->descriptor.source_node_id == viewer.source && event->descriptor.source_epoch == viewer.epoch |
|
|
|
|
&& !viewer.stopping && (event->type != STREAM_EVENT_CLOSED || !stream_handle_active(viewer.handle))) { |
|
|
|
|
if (event->type == STREAM_EVENT_DATA) { |
|
|
|
|
int result = stream_media_receiver_feed(viewer.receiver, event->data, event->length); |
|
|
|
|
if (result != STREAM_OK || viewer.rx_overflow) { |
|
|
|
|
@ -182,10 +183,16 @@ static void media_process(void *arg) {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) { |
|
|
|
|
struct android_media_session *s = sessions[i]; |
|
|
|
|
if (s->opening) { |
|
|
|
|
if (s->stopping) { media_close(s, 5); continue; } |
|
|
|
|
s->opening = 0; |
|
|
|
|
int result = s->source ? stream_subscribe_open(media_inst, s->group, s->source, &s->handle) |
|
|
|
|
: stream_publish_open(media_inst, s->group, NULL, &s->handle); |
|
|
|
|
if (result == STREAM_OK && s->source) result = stream_media_receiver_create(&s->receiver, media_frame, s); |
|
|
|
|
struct stream_info info; |
|
|
|
|
if (result == STREAM_OK) { |
|
|
|
|
result = stream_get_info(s->handle, &info); |
|
|
|
|
if (result == STREAM_OK) s->epoch = info.descriptor.source_epoch; |
|
|
|
|
} |
|
|
|
|
if (result != STREAM_OK) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "Android stream open failed id=%llu group=%llx source=%llx result=%d", |
|
|
|
|
(unsigned long long)s->id, (unsigned long long)s->group, (unsigned long long)s->source, result); |
|
|
|
|
|