SWITCH_DECLARE(switch_status_t) switch_core_session_start_video_thread(switch_core_session_t *session);
SWITCH_DECLARE(int) switch_core_media_check_video_function(switch_core_session_t *session);
SWITCH_DECLARE(void) switch_core_session_video_reinit(switch_core_session_t *session);
+SWITCH_DECLARE(switch_status_t) switch_core_media_read_lock_unlock(switch_core_session_t *session, switch_media_type_t type, switch_bool_t lock);
+
+#define switch_core_media_read_lock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_TRUE)
+#define switch_core_media_read_unlock(_s, _t) switch_core_media_read_lock_unlock(_s, _t, SWITCH_FALSE)
+
SWITCH_END_EXTERN_C
#endif
int want_refresh = 0;
int yield = 0;
switch_core_session_t *session;
- char buf[65536];
+ //char buf[65536];
conference_member_t *floor_holder = NULL;
+ int locked = 0;
conference->video_running = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Video thread started for conference %s\n", conference->name);
while (conference->video_running == 1 && globals.running && !switch_test_flag(conference, CFLAG_DESTRUCT)) {
+ locked = 0;
+ session = NULL;
+
if (yield) {
switch_yield(yield);
yield = 0;
if ((status = switch_core_session_read_lock(session)) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(conference->mutex);
- if (!switch_channel_ready(switch_core_session_get_channel(session))) {
- status = SWITCH_STATUS_FALSE;
+ if ((switch_core_media_read_lock(session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_STATUS_SUCCESS)) {
+ locked = 1;
+ if (!switch_channel_ready(switch_core_session_get_channel(session))) {
+ status = SWITCH_STATUS_FALSE;
+ } else {
+ status = switch_core_session_read_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
+ }
} else {
- status = switch_core_session_read_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
+ status = SWITCH_STATUS_FALSE;
}
switch_mutex_lock(conference->mutex);
switch_core_session_rwunlock(session);
goto do_continue;
}
- memcpy(buf, vid_frame->packet, vid_frame->packetlen);
+ //memcpy(buf, vid_frame->packet, vid_frame->packetlen);
switch_mutex_unlock(conference->mutex);
switch_mutex_lock(conference->mutex);
}
if (isession && switch_channel_test_flag(ichannel, CF_VIDEO)) {
- memcpy(vid_frame->packet, buf, vid_frame->packetlen);
+ //memcpy(vid_frame->packet, buf, vid_frame->packetlen);
switch_core_session_write_video_frame(imember->session, vid_frame, SWITCH_IO_FLAG_NONE, 0);
}
}
do_continue:
+
+ if (session && locked) {
+ switch_core_media_read_unlock(session, SWITCH_MEDIA_TYPE_VIDEO);
+ locked = 0;
+ }
+
switch_mutex_unlock(conference->mutex);
}
uint8_t decoder_init;
switch_buffer_t *vpx_packet_buffer;
int got_key_frame;
+ int key_count;
switch_size_t last_received_timestamp;
switch_bool_t last_received_complete_picture;
int need_key_frame;
if (is_keyframe && !context->got_key_frame) {
context->got_key_frame = 1;
+ context->key_count = 0;
}
}
len = switch_buffer_inuse(context->vpx_packet_buffer);
- if (frame->m && (status != SWITCH_STATUS_SUCCESS || !len)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WTF????? %d %ld\n", status, len);
- }
+ //if (frame->m && (status != SWITCH_STATUS_SUCCESS || !len)) {
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WTF????? %d %ld\n", status, len);
+ //}
if (status == SWITCH_STATUS_SUCCESS && frame->m && len) {
end:
- if (status == SWITCH_STATUS_NOTFOUND) {
- switch_buffer_zero(context->vpx_packet_buffer);
- switch_set_flag(frame, SFF_WAIT_KEY_FRAME);
- }
-
if (status == SWITCH_STATUS_RESTART) {
context->got_key_frame = 0;
switch_buffer_zero(context->vpx_packet_buffer);
}
if (!context->got_key_frame) {
- switch_set_flag(frame, SFF_WAIT_KEY_FRAME);
+ if (!(context->key_count++ % 20)) {
+ switch_set_flag(frame, SFF_WAIT_KEY_FRAME);
+ }
}
+
return status;
}
}
+//?
+SWITCH_DECLARE(switch_status_t) switch_core_media_read_lock_unlock(switch_core_session_t *session, switch_media_type_t type, switch_bool_t lock)
+{
+ switch_rtp_engine_t *engine;
+ switch_media_handle_t *smh;
+
+ switch_assert(session);
+
+ if (!(smh = session->media_handle)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if (!smh->media_flags[SCMF_RUNNING]) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ engine = &smh->engines[type];
+
+ if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ switch_assert(engine->rtp_session != NULL);
+
+
+ if (!switch_channel_up_nosig(session->channel) || !switch_rtp_ready(engine->rtp_session) || switch_channel_test_flag(session->channel, CF_NOT_READY)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if (lock) {
+ if (engine->read_mutex[type] && switch_mutex_trylock(engine->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
+ /* return CNG, another thread is already reading */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n",
+ switch_channel_get_name(session->channel), type2str(type));
+ return SWITCH_STATUS_INUSE;
+ }
+ } else {
+ switch_mutex_unlock(engine->read_mutex[type]);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
//?
SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session_t *session, switch_frame_t **frame,
switch_io_flag_t flags, int stream_id, switch_media_type_t type)
write_frame = *frame;
frame = &write_frame;
+ frame->img = img;
if (!switch_test_flag(frame, SFF_USE_VIDEO_TIMESTAMP)) {