93 return bug->video_ping_frame;
98 return bug->write_replace_frame_in;
103 bug->write_replace_frame_out = frame;
108 return bug->read_replace_frame_in;
113 return bug->native_read_frame;
118 return bug->native_write_frame;
123 bug->read_replace_frame_out = frame;
128 bug->read_demux_frame = frame;
133 return bug->user_data;
139 bug->record_pre_buffer_count = 0;
141 if (bug->raw_read_buffer) {
147 if (bug->raw_write_buffer) {
153 bug->record_frame_size = 0;
154 bug->record_pre_buffer_count = 0;
178 bug->record_pre_buffer_max = framecount;
193 switch_size_t do_read = 0, do_write = 0, has_read = 0, has_write = 0, fill_read = 0, fill_write = 0;
199 if (frame->buflen < bytes) {
207 "%s Buffer Error (raw_read_buffer=%p, raw_write_buffer=%p, read=%s, write=%s)\n",
209 (
void *)bug->raw_read_buffer, (
void *)bug->raw_write_buffer,
233 if (bug->record_frame_size && bug->record_pre_buffer_max && (do_read || do_write) && bug->record_pre_buffer_count < bug->record_pre_buffer_max) {
234 bug->record_pre_buffer_count++;
242 bug->record_frame_size = frame_size;
245 if (bug->record_frame_size && do_write > do_read && do_write > (bug->record_frame_size * 2)) {
254 if ((has_read && !do_read)) {
258 if ((has_write && !do_write)) {
263 if (bug->record_frame_size) {
264 if ((do_read && do_read < bug->record_frame_size) || (do_write && do_write < bug->record_frame_size)) {
268 if (do_read && do_read > bug->record_frame_size) {
269 do_read = bug->record_frame_size;
272 if (do_write && do_write > bug->record_frame_size) {
273 do_write = bug->record_frame_size;
277 if ((fill_read && fill_write) || (fill && (fill_read || fill_write))) {
291 frame->datalen = (uint32_t)
switch_buffer_read(bug->raw_read_buffer, frame->data, do_read);
292 if (frame->datalen != do_read) {
299 }
else if (fill_read) {
300 frame->datalen = (uint32_t)bytes;
301 memset(frame->data, 255, frame->datalen);
308 if (datalen != do_write) {
315 }
else if (fill_write) {
317 memset(bug->data, 255, datalen);
321 dp = (int16_t *) bug->data;
322 fp = (int16_t *) frame->data;
323 rlen = frame->datalen / 2;
325 blen = (uint32_t)(bytes / 2);
328 int16_t *left, *right;
329 size_t left_len, right_len;
341 for (x = 0; x < blen; x++) {
343 *(tp++) = *(left + x);
348 *(tp++) = *(right + x);
353 memcpy(frame->data, bug->tmp, bytes * 2);
355 for (x = 0; x < blen; x++) {
356 int32_t w = 0, r = 0, z = 0;
359 r = (int32_t) * (fp + x);
363 w = (int32_t) * (dp + x);
375 *(fp + x) = (int16_t) z;
379 frame->datalen = (uint32_t)bytes;
396 if (
zstr(name))
goto end;
398 if (!strcasecmp(name,
"dual-crop")) {
402 if (!strcasecmp(name,
"lower-right-large")) {
413 bug->spy_fmt = spy_fmt;
424 for (i = 0; i < 2; i++) {
425 if (!bug->spy_video_queue[i]) {
430 spy_q = bug->spy_video_queue[rw];
444 if (bug->spy_img[rw]) {
446 switch (bug->spy_fmt) {
453 float aspect169 = (float)1920 / 1080;
456 if ((
float)w/h == aspect169) {
457 if ((
float)bug->spy_img[rw]->d_w / bug->spy_img[rw]->d_h == aspect169) {
458 spy_tmp =
switch_img_copy_rect(bug->spy_img[rw], bug->spy_img[rw]->d_w / 4, 0, bug->spy_img[rw]->d_w / 2, bug->spy_img[rw]->d_h);
464 if ((
float)bug->spy_img[rw]->d_w / bug->spy_img[rw]->d_h == aspect169) {
465 spy_tmp =
switch_img_copy_rect(bug->spy_img[rw], bug->spy_img[rw]->d_w / 6, 0, bug->spy_img[rw]->d_w / 4, bug->spy_img[rw]->d_h);
467 spy_tmp =
switch_img_copy_rect(bug->spy_img[rw], bug->spy_img[rw]->d_w / 4, 0, bug->spy_img[rw]->d_w / 2, bug->spy_img[rw]->d_h);
496 float scaler = 0.125f;
503 spyw = (int) (
float)w * scaler;
504 spyh = (int) (
float)h * scaler;
506 if (bug->spy_img[rw]->d_w != spyw || bug->spy_img[rw]->d_h != spyh) {
511 bug->spy_img[rw] = tmp_img;
537 frame.
data = buf + 12;
539 frame.
buflen = buflen - 12;
556 int w = 0, h = 0, ok = 1;
582 if (other_img->d_w != w || other_img->d_h != h) {
593 if (!IMG || IMG->
d_h != h || IMG->
d_w != w) {
606 frame.
img = other_q ? IMG : img;
651 if (bug->spy_video_queue[rw] && frame->img) {
665 #define MAX_BUG_BUFFER 1024 * 512
667 const
char *function,
670 void *user_data, time_t stop_time,
677 int tap_only = 1, punt = 0;
681 if (!
zstr(
function)) {
684 for (bp = session->bugs; bp; bp = bp->
next) {
717 for (bp = session->bugs; bp; bp = bp->
next) {
729 for (bp = session->bugs; bp; bp = bp->
next) {
830 bug->
next = session->bugs;
833 for(bp = session->bugs; bp; bp = bp->
next) {
867 for (bp = session->bugs; bp; bp = bp->
next) {
880 char *list[100] = { 0 };
881 int stop_times[100] = { 0 };
884 if (orig_session->bugs) {
890 const char *new_stereo = orig_stereo;
897 for (bp = orig_session->bugs; bp; bp = bp->
next) {
898 if (!strcmp(bp->
function,
"session_record")) {
909 for(i = 0; i < x; i++) {
932 bp = orig_session->bugs;
937 if (cur->callback == callback) {
939 last->next = cur->next;
941 orig_session->bugs = cur->next;
948 user_data_dup_func(new_session, cur->user_data),
949 cur->stop_time, cur->flags, &new_bug);
972 if (orig_session->bugs) {
974 for (bp = orig_session->bugs; bp; bp = bp->
next) {
975 if (!strcmp(bp->
function,
function)) {
999 if (orig_session->bugs) {
1001 for (bp = orig_session->bugs; bp; bp = bp->
next) {
1017 if (orig_session->bugs) {
1019 for (bp = orig_session->bugs; bp; bp = bp->
next) {
1055 if (orig_session->bugs) {
1057 for (bp = orig_session->bugs; bp; bp = bp->
next) {
1073 stream->write_function(stream,
"<media-bugs>\n");
1075 if (session->bugs) {
1077 for (bp = session->bugs; bp; bp = bp->
next) {
1079 stream->write_function(stream,
1081 " <function>%s</function>\n"
1082 " <target>%s</target>\n"
1083 " <thread-locked>%d</thread-locked>\n"
1091 stream->write_function(stream,
"</media-bugs>\n");
1101 if (session->bugs) {
1103 for (bp = session->bugs; bp; bp = bp->
next) {
1111 if (!
zstr(
function) && strcmp(bp->
function,
function)) {
1125 session->bugs = bp->
next;
1166 for (i = 0; i < 2; i++) {
1210 if (session->bugs) {
1211 for (bp = session->bugs; bp; bp = bp->
next) {
1214 last->next = bp->
next;
1216 session->bugs = bp->
next;
1229 if (session->bugs) {
1230 for(bp2 = session->bugs; bp2; bp2 = bp2->next) {
1262 if (session->bugs) {
1263 for (bp = session->bugs; bp; bp = bp->
next) {
1266 last->next = bp->
next;
1268 session->bugs = bp->
next;
1301 if (session->bugs) {
1311 session->bugs = cur->
next;
struct apr_queue_t switch_queue_t
switch_frame_t * switch_core_media_bug_get_video_ping_frame(switch_media_bug_t *bug)
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
unsigned int switch_queue_size(switch_queue_t *queue)
void switch_channel_set_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
#define SWITCH_BUFFER_START_FRAMES
#define SWITCH_CHANNEL_SESSION_LOG(x)
void switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
patch a small img to a big IMG at position x,y
switch_thread_rwlock_t * bug_rwlock
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_size_t switch_buffer_read(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen)
Read data from a switch_buffer_t up to the ammount of datalen if it is available. Remove read data fr...
void(* switch_media_bug_exec_cb_t)(switch_media_bug_t *bug, void *user_data)
void switch_img_free(switch_image_t **img)
Close an image descriptor.
switch_status_t switch_buffer_create_dynamic(_Out_ switch_buffer_t **buffer, _In_ switch_size_t blocksize, _In_ switch_size_t start_len, _In_ switch_size_t max_len)
Allocate a new dynamic switch_buffer.
switch_status_t switch_ivr_stop_record_session(switch_core_session_t *session, const char *file)
Stop Recording a session.
switch_frame_t * switch_core_media_bug_get_native_read_frame(switch_media_bug_t *bug)
#define SWITCH_RECOMMENDED_BUFFER_SIZE
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
uint32_t decoded_bytes_per_packet
switch_memory_pool_t * pool
void switch_core_media_bug_inuse(switch_media_bug_t *bug, switch_size_t *readp, switch_size_t *writep)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
switch_status_t switch_core_media_bug_set_pre_buffer_framecount(switch_media_bug_t *bug, uint32_t framecount)
void switch_media_bug_set_spy_fmt(switch_media_bug_t *bug, switch_vid_spy_fmt_t spy_fmt)
#define SWITCH_RTP_MAX_BUF_LEN
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
uint32_t switch_core_media_bug_count(switch_core_session_t *orig_session, const char *function)
#define switch_channel_media_ready(_channel)
void switch_core_media_bug_pause(switch_core_session_t *session)
Pause a media bug on the session.
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
#define switch_core_session_get_name(_s)
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
switch_bool_t(* switch_media_bug_callback_t)(switch_media_bug_t *, void *, switch_abc_type_t)
switch_status_t switch_core_media_bug_transfer_recordings(switch_core_session_t *orig_session, switch_core_session_t *new_session)
switch_status_t switch_core_media_bug_patch_spy_frame(switch_media_bug_t *bug, switch_image_t *img, switch_rw_t rw)
static switch_thread_t * thread
switch_status_t switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
void switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP)
switch_image_t * switch_img_alloc(switch_image_t *img, switch_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
#define SWITCH_MUTEX_NESTED
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_core_media_bug_pop(switch_core_session_t *orig_session, const char *function, switch_media_bug_t **pop)
switch_size_t switch_buffer_toss(_In_ switch_buffer_t *buffer, _In_ switch_size_t datalen)
Remove data from the buffer.
switch_status_t switch_core_media_bug_transfer_callback(switch_core_session_t *orig_session, switch_core_session_t *new_session, switch_media_bug_callback_t callback, void *(*user_data_dup_func)(switch_core_session_t *, void *))
switch_byte_t switch_byte_t * buf
uint32_t switch_core_media_bug_prune(switch_core_session_t *session)
switch_channel_t * channel
#define SWITCH_CORE_QUEUE_LEN
switch_frame_flag_t flags
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
uint32_t actual_samples_per_second
switch_status_t switch_core_media_bug_push_spy_frame(switch_media_bug_t *bug, switch_frame_t *frame, switch_rw_t rw)
#define switch_channel_get_variable(_c, _v)
#define SWITCH_THREAD_STACKSIZE
switch_status_t switch_core_media_bug_remove_callback(switch_core_session_t *session, switch_media_bug_callback_t callback)
Remove media bug callback.
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
switch_status_t switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit)
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
void switch_buffer_zero(_In_ switch_buffer_t *buffer)
Remove all data from the buffer.
An abstraction of a data frame.
switch_image_t * switch_img_copy_rect(switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
Copy part of an image to a new image.
switch_vid_spy_fmt_t switch_media_bug_parse_spy_fmt(const char *name)
switch_byte_t switch_byte_t uint32_t buflen
switch_status_t switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height)
switch_status_t switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *color_str)
Set RGB color with a string.
uint8_t number_of_channels
switch_status_t
Common return values.
uint32_t switch_core_media_bug_patch_video(switch_core_session_t *orig_session, switch_frame_t *frame)
void switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color)
Fill image with color.
switch_status_t switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh)
Record a session to disk.
struct apr_thread_t switch_thread_t
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
void switch_core_media_bug_resume(switch_core_session_t *session)
Resume a media bug on the session.
#define switch_channel_set_flag(_c, _f)
#define SWITCH_IMG_FMT_I420
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_channel_clear_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
A table of settings and callbacks that define a paticular implementation of a codec.
#define switch_normalize_to_16bit(n)
uint32_t switch_media_bug_flag_t
switch_frame_t * switch_core_media_bug_get_native_write_frame(switch_media_bug_t *bug)
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
switch_thread_id_t switch_thread_self(void)
switch_status_t switch_core_media_bug_exec_all(switch_core_session_t *orig_session, const char *function, switch_media_bug_exec_cb_t cb, void *user_data)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_channel_set_variable(_channel, _var, _val)
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
#define SWITCH_BUFFER_BLOCK_FRAMES
switch_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.