mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-31 07:34:19 +00:00
indent pass 2
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
9bbcabbbdd
commit
f930eaeec7
101 files changed
+31644
-31458
No files matched your search
@@ -61,35 +61,35 @@ static void *SWITCH_THREAD_FUNC record_video_thread(switch_thread_t *thread, voi
|
||||
switch_status_t status;
|
||||
switch_frame_t *read_frame;
|
||||
int bytes;
|
||||
|
||||
eh->up = 1;
|
||||
while(switch_channel_ready(channel)) {
|
||||
|
||||
eh->up = 1;
|
||||
while (switch_channel_ready(channel)) {
|
||||
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
|
||||
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (switch_test_flag(read_frame, SFF_CNG)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bytes = read_frame->packetlen |VID_BIT;
|
||||
|
||||
bytes = read_frame->packetlen | VID_BIT;
|
||||
|
||||
switch_mutex_lock(eh->mutex);
|
||||
|
||||
if (write(eh->fd, &bytes, sizeof(bytes)) != (int)sizeof(bytes)) {
|
||||
|
||||
if (write(eh->fd, &bytes, sizeof(bytes)) != (int) sizeof(bytes)) {
|
||||
switch_mutex_unlock(eh->mutex);
|
||||
break;
|
||||
}
|
||||
|
||||
if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int)read_frame->packetlen) {
|
||||
if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int) read_frame->packetlen) {
|
||||
switch_mutex_unlock(eh->mutex);
|
||||
break;
|
||||
}
|
||||
|
||||
switch_mutex_unlock(eh->mutex);
|
||||
|
||||
|
||||
switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
}
|
||||
eh->up = 0;
|
||||
@@ -101,24 +101,24 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
switch_status_t status;
|
||||
switch_frame_t *read_frame;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
struct record_helper eh = {0};
|
||||
struct record_helper eh = { 0 };
|
||||
switch_thread_t *thread;
|
||||
switch_threadattr_t *thd_attr = NULL;
|
||||
int fd;
|
||||
switch_mutex_t *mutex = NULL;
|
||||
switch_codec_t codec, *read_codec, *vid_codec;
|
||||
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
if ((fd = open((char *)data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
|
||||
|
||||
if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
read_codec = switch_core_session_get_read_codec(session);
|
||||
|
||||
|
||||
if (switch_core_codec_init(&codec,
|
||||
"L16",
|
||||
NULL,
|
||||
@@ -131,14 +131,14 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
switch_core_session_set_read_codec(session, &codec);
|
||||
|
||||
|
||||
if (switch_channel_test_flag(channel, CF_VIDEO)) {
|
||||
struct file_header h;
|
||||
memset(&h, 0, sizeof(h));
|
||||
vid_codec = switch_core_session_get_video_read_codec(session);
|
||||
|
||||
|
||||
h.version = VERSION;
|
||||
h.created = switch_timestamp_now();
|
||||
switch_set_string(h.video_codec_name, vid_codec->implementation->iananame);
|
||||
@@ -147,11 +147,11 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
}
|
||||
h.audio_rate = read_codec->implementation->samples_per_second;
|
||||
h.audio_ptime = read_codec->implementation->microseconds_per_frame / 1000;
|
||||
|
||||
|
||||
if (write(fd, &h, sizeof(h)) != sizeof(h)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||
eh.mutex = mutex;
|
||||
eh.fd = fd;
|
||||
@@ -161,12 +161,12 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||
switch_thread_create(&thread, thd_attr, record_video_thread, &eh, switch_core_session_get_pool(session));
|
||||
}
|
||||
|
||||
|
||||
while(switch_channel_ready(channel)) {
|
||||
|
||||
|
||||
while (switch_channel_ready(channel)) {
|
||||
|
||||
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
|
||||
|
||||
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
||||
break;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
break;
|
||||
}
|
||||
|
||||
if (write(fd, read_frame->data, read_frame->datalen) != (int)read_frame->datalen) {
|
||||
if (write(fd, read_frame->data, read_frame->datalen) != (int) read_frame->datalen) {
|
||||
if (mutex) {
|
||||
switch_mutex_unlock(mutex);
|
||||
}
|
||||
@@ -198,42 +198,44 @@ SWITCH_STANDARD_APP(record_fsv_function)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
end:
|
||||
|
||||
end:
|
||||
|
||||
if (eh.up) {
|
||||
while(eh.up) {
|
||||
while (eh.up) {
|
||||
switch_yield(1000);
|
||||
}
|
||||
}
|
||||
|
||||
switch_core_session_set_read_codec(session, read_codec);
|
||||
switch_core_codec_destroy(&codec);
|
||||
|
||||
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(play_fsv_function)
|
||||
{
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_frame_t write_frame = {0}, vid_frame = {0};
|
||||
switch_frame_t write_frame = { 0 }, vid_frame = {
|
||||
0};
|
||||
int fd = -1;
|
||||
int bytes;
|
||||
switch_codec_t *read_codec = NULL, codec = {0}, vid_codec = {0}, *read_vid_codec;
|
||||
switch_codec_t *read_codec = NULL, codec = { 0 }, vid_codec = {
|
||||
0}, *read_vid_codec;
|
||||
unsigned char *aud_buffer;
|
||||
unsigned char *vid_buffer;
|
||||
struct file_header h;
|
||||
uint32_t ts = 0, last = 0;
|
||||
switch_timer_t timer = {0};
|
||||
uint32_t ts = 0, last = 0;
|
||||
switch_timer_t timer = { 0 };
|
||||
switch_payload_t pt = 0;
|
||||
|
||||
aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
|
||||
vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
|
||||
|
||||
if ((fd = open((char *)data, O_RDONLY)) < 0) {
|
||||
|
||||
if ((fd = open((char *) data, O_RDONLY)) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (read(fd, &h, sizeof(h)) != sizeof(h)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error reading file header\n");
|
||||
goto end;
|
||||
@@ -246,7 +248,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
|
||||
switch_channel_set_variable(channel, "sip_force_video_fmtp", h.video_fmtp);
|
||||
switch_channel_answer(channel);
|
||||
|
||||
|
||||
if ((read_vid_codec = switch_core_session_get_video_read_codec(session))) {
|
||||
pt = read_vid_codec->agreed_pt;
|
||||
}
|
||||
@@ -254,16 +256,16 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
write_frame.codec = &codec;
|
||||
write_frame.data = aud_buffer;
|
||||
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
||||
|
||||
|
||||
vid_frame.codec = &vid_codec;
|
||||
vid_frame.packet = vid_buffer;
|
||||
vid_frame.data = vid_buffer + 12;
|
||||
vid_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE - 12;
|
||||
switch_set_flag((&vid_frame), SFF_RAW_RTP);
|
||||
|
||||
|
||||
read_codec = switch_core_session_get_read_codec(session);
|
||||
|
||||
if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000,
|
||||
if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000,
|
||||
read_codec->implementation->samples_per_frame, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "timer Activation Fail\n");
|
||||
goto end;
|
||||
@@ -281,7 +283,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_codec_init(&vid_codec,
|
||||
h.video_codec_name,
|
||||
NULL,
|
||||
@@ -296,20 +298,20 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
}
|
||||
switch_core_session_set_read_codec(session, &codec);
|
||||
|
||||
while(switch_channel_ready(channel)) {
|
||||
while (switch_channel_ready(channel)) {
|
||||
|
||||
if (read(fd, &bytes, sizeof(bytes)) != sizeof(bytes)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (bytes & VID_BIT) {
|
||||
switch_rtp_hdr_t *hdr = vid_frame.packet;
|
||||
bytes &= ~VID_BIT;
|
||||
|
||||
if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t)bytes) {
|
||||
if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t) bytes) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
ts = ntohl(hdr->ts);
|
||||
if (pt) {
|
||||
hdr->pt = pt;
|
||||
@@ -322,7 +324,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
}
|
||||
last = ts;
|
||||
} else {
|
||||
if (bytes > (int)write_frame.buflen) {
|
||||
if (bytes > (int) write_frame.buflen) {
|
||||
bytes = write_frame.buflen;
|
||||
}
|
||||
if ((write_frame.datalen = read(fd, write_frame.data, bytes)) <= 0) {
|
||||
@@ -333,9 +335,9 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
|
||||
end:
|
||||
|
||||
if (timer.interval) {
|
||||
switch_core_timer_destroy(&timer);
|
||||
}
|
||||
@@ -343,15 +345,15 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
||||
if (read_codec) {
|
||||
switch_core_session_set_read_codec(session, read_codec);
|
||||
}
|
||||
|
||||
|
||||
if (codec.implementation) {
|
||||
switch_core_codec_destroy(&codec);
|
||||
}
|
||||
|
||||
|
||||
if (vid_codec.implementation) {
|
||||
switch_core_codec_destroy(&vid_codec);
|
||||
}
|
||||
|
||||
|
||||
if (fd > -1) {
|
||||
close(fd);
|
||||
}
|
||||
@@ -362,7 +364,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fsv_load)
|
||||
switch_application_interface_t *app_interface;
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
SWITCH_ADD_APP(app_interface, "play_fsv", "play an fsv file", "play an fsv file", play_fsv_function, "<file>", SAF_NONE);
|
||||
SWITCH_ADD_APP(app_interface, "record_fsv", "record an fsv file", "record an fsv file", record_fsv_function, "<file>", SAF_NONE);
|
||||
|
||||
Reference in new issue
Block a user