endfor:
+ for(;;) {
+ AVPacket pkt = { 0 };
+ int got_packet = 0;
+ int ret = 0;
+
+ av_init_packet(&pkt);
+
+ ret = avcodec_encode_video2(eh->video_st->st->codec, &pkt, eh->video_st->frame, &got_packet);
+
+ if (ret < 0) {
+ break;
+ } else if (got_packet) {
+ switch_mutex_lock(eh->mutex);
+ ret = write_frame(eh->fc, &eh->video_st->st->codec->time_base, eh->video_st->st, &pkt);
+ switch_mutex_unlock(eh->mutex);
+ av_free_packet(&pkt);
+ if (ret < 0) break;
+ }
+ }
+
while(switch_queue_trypop(eh->video_queue, &pop) == SWITCH_STATUS_SUCCESS) {
if (!pop) break;
img = (switch_image_t *) pop;
pkt.data = NULL;
pkt.size = 0;
- if ((error = av_read_frame(context->fc, &pkt)) < 0) {
+ if (context->video_st.st && (error = av_read_frame(context->fc, &pkt)) < 0) {
if (error == AVERROR_EOF) {
eof = 1;
/* just make sure*/
//inuse = switch_buffer_inuse(context->audio_buffer);
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "inuse: %d samples: %d bytes: %d\n", inuse, context->audio_st.frame->nb_samples, bytes);
+ if (context->closed) {
+ inuse = switch_buffer_inuse(context->audio_buffer);
+ if (inuse < bytes) {
+ char buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
+ switch_buffer_write(context->audio_buffer, buf, bytes - inuse);
+ }
+ }
+
while ((inuse = switch_buffer_inuse(context->audio_buffer)) >= bytes) {
AVPacket pkt = { 0 };
context->eh.finalize = 1;
if (context->eh.video_queue) {
-
-
- if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
- switch_rgb_color_t bgcolor;
- int x;
-
- switch_color_set_rgb(&bgcolor, "#000000");
- x = (int)handle->mm.fps * 1;
-
- if (x <= 0) x = 100;
-
- while(handle->mm.vw && x-- > 0) {
- switch_image_t *blank_img = NULL;
- if ((blank_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, handle->mm.vw, handle->mm.vh, 1))) {
- switch_img_fill(blank_img, 0, 0, blank_img->d_w, blank_img->d_h, &bgcolor);
- switch_queue_push(context->eh.video_queue, blank_img);
- }
- }
-
- }
switch_queue_push(context->eh.video_queue, NULL);
}
- if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
- av_file_write(handle, NULL, NULL);
- }
-
if (context->eh.video_thread) {
switch_thread_join(&status, context->eh.video_thread);
}
+ if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
+ av_file_write(handle, NULL, NULL);
+ }
+
if (context->file_read_thread_running && context->file_read_thread) {
context->file_read_thread_running = 0;
switch_thread_join(&status, context->file_read_thread);
switch_core_session_receive_message(session, &msg);
}
+SWITCH_STANDARD_APP(video_set_decode_function)
+{
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ char *txt = (char *) data;
+ int on = 0, wait = 0;
+
+ if (txt) {
+ on = !strcasecmp(txt, "on");
+ wait = !strcasecmp(txt, "wait");
+ }
+
+ if (data && (on || wait)) {
+ switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ);
+ if (wait) {
+ switch_core_session_wait_for_video_input_params(session, 10000);
+ }
+ } else {
+ switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ);
+ }
+}
+
SWITCH_STANDARD_APP(video_refresh_function)
{
switch_core_session_message_t msg = { 0 };
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "video_refresh", "Send video refresh.", "Send video refresh.", video_refresh_function, "",
SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "video_decode", "Set video decode.", "Set video decode.", video_set_decode_function, "[[on|wait]|off]",
+ SAF_NONE);
SWITCH_ADD_APP(app_interface, "send_info", "Send info", "Send info", send_info_function, "<info>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "jitterbuffer", "Send session jitterbuffer", "Send a jitterbuffer message to a session.",
jitterbuffer_function, "<jitterbuffer_data>", SAF_SUPPORT_NOMEDIA);
switch_frame_t *read_frame;
switch_status_t status;
+ if (switch_channel_test_flag(session->channel, CF_VIDEO_READY) && smh->vid_params.width && smh->vid_params.height) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
- break;
- }
-
- if (switch_channel_test_flag(session->channel, CF_VIDEO_READY) && smh->vid_params.width && smh->vid_params.height && smh->vid_params.fps) {
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_FALSE;
}
timeout_ms -= (read_impl.microseconds_per_packet / 1000);