mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 12:40:17 +00:00
Merge pull request #336 in FS/freeswitch from ~BRADLEYJOKINEN/freeswitch:FS-7799 to master
* commit '31ade5f9680ddbb25f6b18ebf879ce537b9f5a6e': FS-7799 Add API command uuid_write_png to mod_png
This commit is contained in:
commit
569c75c17d
@ -36,8 +36,11 @@
|
|||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
switch_loadable_module_interface_t *MODULE_INTERFACE;
|
||||||
|
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_png_load);
|
SWITCH_MODULE_LOAD_FUNCTION(mod_png_load);
|
||||||
SWITCH_MODULE_DEFINITION(mod_png, mod_png_load, NULL, NULL);
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_png_shutdown);
|
||||||
|
SWITCH_MODULE_DEFINITION(mod_png, mod_png_load, mod_png_shutdown, NULL);
|
||||||
|
|
||||||
struct png_file_context {
|
struct png_file_context {
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
@ -201,17 +204,106 @@ static switch_status_t png_file_read_video(switch_file_handle_t *handle, switch_
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static switch_bool_t write_png_bug_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
|
||||||
|
{
|
||||||
|
switch_core_session_t *session = switch_core_media_bug_get_session(bug);
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
char *path = (char *) user_data;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SWITCH_ABC_TYPE_INIT:
|
||||||
|
{
|
||||||
|
switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SWITCH_ABC_TYPE_CLOSE:
|
||||||
|
{
|
||||||
|
switch_thread_rwlock_unlock(MODULE_INTERFACE->rwlock);
|
||||||
|
switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SWITCH_ABC_TYPE_READ_VIDEO_PING:
|
||||||
|
{
|
||||||
|
switch_frame_t *frame = switch_core_media_bug_get_video_ping_frame(bug);
|
||||||
|
if (!frame || !frame->img) break;
|
||||||
|
switch_img_write_png(frame->img, path);
|
||||||
|
return SWITCH_FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_STANDARD_API(uuid_write_png_function)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
char *argv[2] = { 0 };
|
||||||
|
char *mydata = NULL;
|
||||||
|
char *uuid;
|
||||||
|
char *path;
|
||||||
|
switch_media_bug_t *bug;
|
||||||
|
switch_media_bug_flag_t flags = SMBF_READ_VIDEO_PING;
|
||||||
|
switch_core_session_t *session_;
|
||||||
|
|
||||||
|
if (!zstr(cmd) && (mydata = strdup(cmd))) {
|
||||||
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
stream->write_function(stream, "-USAGE: <uuid> <path> \n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid = argv[0];
|
||||||
|
if (!(session_ = switch_core_session_locate(uuid))) {
|
||||||
|
stream->write_function(stream, "-ERR Could not locate session.\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!switch_channel_test_flag(switch_core_session_get_channel(session_), CF_VIDEO)) {
|
||||||
|
stream->write_function(stream, "-ERR Session does not have video.\n");
|
||||||
|
switch_core_session_rwunlock(session_);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!switch_is_file_path(argv[1])) {
|
||||||
|
const char *prefix = SWITCH_GLOBAL_dirs.images_dir;
|
||||||
|
path = switch_core_session_sprintf(session_, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, argv[1]);
|
||||||
|
} else {
|
||||||
|
path = switch_core_session_strdup(session_, argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_thread_rwlock_rdlock(MODULE_INTERFACE->rwlock);
|
||||||
|
|
||||||
|
if (switch_core_media_bug_add(session_, NULL, NULL, write_png_bug_callback, path, 0, flags, &bug) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
stream->write_function(stream, "-ERR Could not attach bug.\n");
|
||||||
|
switch_thread_rwlock_unlock(MODULE_INTERFACE->rwlock);
|
||||||
|
} else {
|
||||||
|
stream->write_function(stream, "+OK\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_core_session_rwunlock(session_);
|
||||||
|
|
||||||
|
end:
|
||||||
|
switch_safe_free(mydata);
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static char *supported_formats[2] = { 0 };
|
static char *supported_formats[2] = { 0 };
|
||||||
|
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_png_load)
|
SWITCH_MODULE_LOAD_FUNCTION(mod_png_load)
|
||||||
{
|
{
|
||||||
|
switch_api_interface_t *api_interface;
|
||||||
switch_file_interface_t *file_interface;
|
switch_file_interface_t *file_interface;
|
||||||
|
|
||||||
supported_formats[0] = (char *)"png";
|
supported_formats[0] = (char *)"png";
|
||||||
|
|
||||||
/* connect my internal structure to the blank pointer passed to me */
|
/* 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);
|
||||||
|
MODULE_INTERFACE = *module_interface;
|
||||||
|
|
||||||
file_interface = (switch_file_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
|
file_interface = (switch_file_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
|
||||||
file_interface->interface_name = modname;
|
file_interface->interface_name = modname;
|
||||||
@ -221,10 +313,17 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_png_load)
|
|||||||
file_interface->file_read = png_file_read;
|
file_interface->file_read = png_file_read;
|
||||||
file_interface->file_read_video = png_file_read_video;
|
file_interface->file_read_video = png_file_read_video;
|
||||||
|
|
||||||
|
SWITCH_ADD_API(api_interface, "uuid_write_png", "grab an image from a call",uuid_write_png_function, "");
|
||||||
|
|
||||||
/* indicate that the module should continue to be loaded */
|
/* indicate that the module should continue to be loaded */
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_png_shutdown)
|
||||||
|
{
|
||||||
|
return SWITCH_STATUS_UNLOAD;
|
||||||
|
}
|
||||||
|
|
||||||
/* For Emacs:
|
/* For Emacs:
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* mode:c
|
* mode:c
|
||||||
|
Loading…
x
Reference in New Issue
Block a user