FS-7502: add simple video media bug implementation, should work with .fsv, be sure to set enable_file_write_buffering=false

Conflicts:
	src/include/switch_types.h
This commit is contained in:
Seven Du 2012-08-28 16:12:12 +08:00 committed by Michael Jerris
parent 67334bea27
commit 90b654e923
3 changed files with 63 additions and 1 deletions

View File

@ -483,7 +483,8 @@ typedef enum {
SWITCH_ABC_TYPE_READ_PING,
SWITCH_ABC_TYPE_TAP_NATIVE_READ,
SWITCH_ABC_TYPE_TAP_NATIVE_WRITE,
SWITCH_ABC_TYPE_CLOSE
SWITCH_ABC_TYPE_CLOSE,
SWITCH_ABC_TYPE_READ_VIDEO_PING
} switch_abc_type_t;
typedef struct {

View File

@ -111,6 +111,49 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
goto done;
}
if (session->bugs) {
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) {
continue;
}
if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) {
continue;
}
if (switch_test_flag(bp, SMBF_PRUNE)) {
prune++;
continue;
}
if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) {
switch_mutex_lock(bp->read_mutex);
bp->ping_frame = *frame;
if (bp->callback) {
if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_VIDEO_PING) == SWITCH_FALSE
|| (bp->stop_time && bp->stop_time <= switch_epoch_time_now(NULL))) {
ok = SWITCH_FALSE;
}
}
bp->ping_frame = NULL;;
switch_mutex_unlock(bp->read_mutex);
}
if (ok == SWITCH_FALSE) {
switch_set_flag(bp, SMBF_PRUNE);
prune++;
}
}
switch_thread_rwlock_unlock(session->bug_rwlock);
if (prune) {
switch_core_media_bug_prune(session);
}
}
done:
return status;

View File

@ -34,6 +34,7 @@
*/
#include <switch.h>
#include "private/switch_core_pvt.h"
#include <speex/speex_preprocess.h>
#include <speex/speex_echo.h>
@ -1478,6 +1479,23 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
}
}
break;
case SWITCH_ABC_TYPE_READ_VIDEO_PING:
if (rh->fh) {
switch_size_t len;
if (!bug->ping_frame) break;
len = bug->ping_frame->packetlen;
if (len && switch_core_file_write_video(rh->fh, bug->ping_frame->packet, &len) != SWITCH_STATUS_SUCCESS && rh->hangup_on_error) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error writing video to %s\n", rh->file);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
return SWITCH_FALSE;
}
}
break;
case SWITCH_ABC_TYPE_WRITE:
default:
break;