switch_mutex_t *mutex;
AVFormatContext *fc;
MediaStream *video_st;
- switch_timer_t *timer;
+ switch_timer_t *video_timer;
int in_callback;
switch_queue_t *video_queue;
switch_thread_t *video_thread;
switch_buffer_t *buf;
switch_buffer_t *audio_buffer;
switch_timer_t video_timer;
+ switch_timer_t audio_timer;
int offset;
int audio_start;
int aud_ready;
c->sample_rate = mst->sample_rate = mm->samplerate;
}
}
+ //FUCKER
+ mst->st->time_base.den = c->sample_rate;
+ mst->st->time_base.num = 1;
+ c->time_base.den = c->sample_rate;
+ c->time_base.num = 1;
break;
} else {
uint64_t delta_tmp;
- switch_core_timer_sync(context->eh.timer);
+ switch_core_timer_sync(context->eh.video_timer);
if (context->eh.record_timer_paused) {
continue;
context->eh.video_st->frame->pts += delta;
delta_tmp = delta;
- context->eh.record_timer_offset = context->eh.timer->samplecount - context->eh.video_st->frame->pts;
+ context->eh.record_timer_offset = context->eh.video_timer->samplecount - context->eh.video_st->frame->pts;
context->eh.record_timer_offset = context->eh.record_timer_offset > 0 ? context->eh.record_timer_offset : 0;
} else {
- delta_tmp = context->eh.timer->samplecount - last_ts;
+ delta_tmp = context->eh.video_timer->samplecount - last_ts;
}
if (delta_tmp != 0) {
delta_avg = (int)(double)(delta_sum / delta_i);
}
- context->eh.video_st->frame->pts = context->eh.timer->samplecount - context->eh.record_timer_offset;
+ context->eh.video_st->frame->pts = context->eh.video_timer->samplecount - context->eh.record_timer_offset;
} else {
- context->eh.video_st->frame->pts = (context->eh.timer->samplecount) + 1;
+ context->eh.video_st->frame->pts = (context->eh.video_timer->samplecount) + 1;
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Timer Activation Fail\n");
goto end;
}
- context.eh.timer = &timer;
+ context.eh.video_timer = &timer;
switch_queue_create(&context.eh.video_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
switch_core_session_set_video_read_callback(session, video_read_callback, (void *)&context.eh);
switch_core_timer_destroy(&context->video_timer);
}
+ if (context->audio_timer.interval) {
+ switch_core_timer_destroy(&context->audio_timer);
+ }
+
if (context->audio_buffer) {
switch_buffer_destroy(&context->audio_buffer);
}
continue;
}
- context->audio_st.tmp_frame->pts = context->audio_st.next_pts;
- context->audio_st.next_pts += context->audio_st.frame->nb_samples;
+ switch_core_timer_sync(&context->audio_timer);
+ context->audio_st.tmp_frame->pts = context->audio_timer.samplecount;
+ context->audio_st.next_pts = context->audio_st.tmp_frame->pts + context->audio_st.frame->nb_samples;
+
+ //context->audio_st.tmp_frame->pts = context->audio_st.next_pts;
+ //context->audio_st.next_pts += context->audio_st.frame->nb_samples;
ret = avcodec_encode_audio2(context->audio_st.st->codec, &pkt, context->audio_st.tmp_frame, &got_packet);
} else {
av_frame_make_writable(context->audio_st.frame);
switch_buffer_read(context->audio_buffer, context->audio_st.frame->data[0], bytes);
- context->audio_st.frame->pts = context->audio_st.next_pts;
- context->audio_st.next_pts += context->audio_st.frame->nb_samples;
+ switch_core_timer_sync(&context->audio_timer);
+ context->audio_st.frame->pts = context->audio_timer.samplecount;
+ context->audio_st.next_pts = context->audio_st.frame->pts + context->audio_st.frame->nb_samples;
+ //context->audio_st.frame->pts = context->audio_st.next_pts;
+ //context->audio_st.next_pts += context->audio_st.frame->nb_samples;
ret = avcodec_encode_audio2(context->audio_st.st->codec, &pkt, context->audio_st.frame, &got_packet);
}
switch_core_timer_destroy(&context->video_timer);
}
+ if (context->audio_timer.interval) {
+ switch_core_timer_destroy(&context->audio_timer);
+ }
+
switch_img_free(&context->last_img);
switch_buffer_destroy(&context->audio_buffer);
//switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_core_timer_init(&context->video_timer, "soft", 1, 90, context->pool);
- context->eh.timer = &context->video_timer;
+ switch_core_timer_init(&context->audio_timer, "soft", 1, handle->samplerate / 1000, context->pool);
+ context->eh.video_timer = &context->video_timer;
context->audio_st.frame->pts = 0;
context->audio_st.next_pts = 0;
switch_thread_create(&context->eh.video_thread, thd_attr, video_thread_run, context, handle->memory_pool);