switch_frame_t *read_frame;
uint32_t width = 0, height = 0, size;
switch_byte_t *yuv;
- uint32_t last_video_ts;
+ switch_time_t last_video_ts = 0;
int argc;
char *argv[3] = { 0 };
char *mydata = switch_core_session_strdup(session, data);
uint32_t encoded_data_len = 1500;
uint32_t encoded_rate = 0;
switch_frame_t *frame = &vid_frame;
- uint32_t now;
+ switch_time_t now = switch_micro_time_now() / 1000;
char ts_str[33];
+ int delta;
codec->enc_picture.width = width;
codec->enc_picture.height = height;
decoded_data_len = width * height * 3 / 2;
+ delta = now - last_video_ts;
- now = switch_micro_time_now() / 1000;
-
- if (!last_video_ts) {
+ if (delta > 0) {
+ frame->timestamp += delta * 90;
last_video_ts = now;
- frame->timestamp = last_video_ts;
- } else {
- int delta = now - last_video_ts;
- if (delta > 0) {
- frame->timestamp += delta * 90;
- last_video_ts = now;
- }
}
sprintf(ts_str, "%u", (uint32_t)frame->timestamp);
switch_core_codec_encode(codec, NULL, yuv, decoded_data_len, 0, vid_frame.data, &encoded_data_len, &encoded_rate, &flag);
while(encoded_data_len) {
- // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "encoded: %s [%d] flag=%d ts=%u\n", codec->implementation->iananame, encoded_data_len, flag, context->last_video_ts);
+ // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "encoded: %s [%d] flag=%d ts=%u\n", codec->implementation->iananame, encoded_data_len, flag, last_video_ts);
frame->datalen = encoded_data_len;
frame->packetlen = frame->datalen + 12;
uint8_t video_packet[1500 + 12];
void *raw_yuyv_data;
void *raw_i420_data;
- uint32_t last_video_ts;
+ switch_time_t last_video_ts;
switch_payload_t pt;
uint32_t seq;
int width;
int height;
int force_width;
int force_height;
- int new_frame; // next frame is a new frame(new timestamp)
};
typedef struct vlc_video_context vlc_video_context_t;
uint32_t flag = 0;
uint32_t encoded_data_len = 1500;
uint32_t encoded_rate = 0;
+ switch_time_t now = (switch_time_t)(switch_micro_time_now() / 1000);
switch_codec_t *codec = switch_core_session_get_video_write_codec(context->session);
+ int delta;
switch_assert(id == NULL); /* picture identifier, not needed here */
switch_assert(codec);
+ if (now - context->last_video_ts < 60) goto end;
+
yuyv_to_i420(*p_pixels, context->raw_i420_data, context->width, context->height);
codec->enc_picture.width = context->width;
codec->enc_picture.height = context->height;
decoded_data_len = context->width * context->height * 3 / 2;
+ delta = now - context->last_video_ts;
+
+ if (delta > 0) {
+ frame->timestamp += delta * 90;
+ context->last_video_ts = now;
+ }
+
switch_core_codec_encode(codec, NULL, context->raw_i420_data, decoded_data_len, 0, frame->data, &encoded_data_len, &encoded_rate, &flag);
while(encoded_data_len) {
frame->datalen = encoded_data_len;
frame->packetlen = frame->datalen + 12;
frame->m = flag & SFF_MARKER ? 1 : 0;
- // frame->timestamp = context->ts;
- // if (frame->m) context->ts += 90000 / FPS;
- if (!context->last_video_ts) {
- context->last_video_ts = switch_micro_time_now() / 1000;
- frame->timestamp = context->last_video_ts;
- }
-
- if (context->new_frame) {
- int delta = switch_micro_time_now() / 1000 - context->last_video_ts;
- frame->timestamp += delta * 90;
- context->last_video_ts = switch_micro_time_now() / 1000;
- context->new_frame = 0;
- }
-
- if (frame->m) { // next frame is a new frame
- context->new_frame = 1;
- }
if (1) {
/* set correct mark and ts */
switch_core_codec_encode(codec, NULL, NULL, 0, 0, frame->data, &encoded_data_len, &encoded_rate, &flag);
}
+end:
switch_mutex_unlock(context->video_mutex);
}
uint32_t encoded_rate = 0;
switch_codec_t *codec = switch_core_session_get_video_write_codec(context->session);
switch_frame_t *frame = context->vid_frame;
+ switch_time_t now = (switch_time_t)(switch_micro_time_now() / 1000);
+ int delta;
switch_assert(id == NULL); /* picture identifier, not needed here */
switch_assert(codec);
frame->packet = context->video_packet;
frame->data = context->video_packet + 12;
+ delta = now - context->last_video_ts;
+
+ if (delta > 0) {
+ frame->timestamp += delta * 90;
+ context->last_video_ts = now;
+ }
switch_core_codec_encode(codec, NULL, context->raw_i420_data, decoded_data_len, 0, frame->data, &encoded_data_len, &encoded_rate, &flag);
frame->datalen = encoded_data_len;
frame->packetlen = frame->datalen + 12;
frame->m = flag & SFF_MARKER ? 1 : 0;
- if (!context->last_video_ts) {
- context->last_video_ts = switch_micro_time_now() / 1000;
- frame->timestamp = context->last_video_ts;
- }
-
- if (context->new_frame) {
- int delta = switch_micro_time_now() / 1000 - context->last_video_ts;
- frame->timestamp += delta * 90;
- context->last_video_ts = switch_micro_time_now() / 1000;
- context->new_frame = 0;
- }
-
- if (frame->m) { // next frame is a new frame
- context->new_frame = 1;
- }
if (1) {
/* set correct mark and ts */
fail:
- return SWITCH_STATUS_FALSE;
+ return status;
}
static switch_status_t channel_on_init(switch_core_session_t *session)