Fixed video packet assembling.

Video should look better now.
This commit is contained in:
irungentoo 2014-12-12 17:47:57 -05:00
parent 36851e7b38
commit 12f396fcc2
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -637,7 +637,10 @@ void queue_message(RTPSession *session, RTPMessage *msg)
if (packet_size < VIDEOFRAME_HEADER_SIZE)
goto end;
if (packet[0] > cs->frameid_in || (msg->header->timestamp > cs->last_timestamp)) { /* New frame */
uint8_t diff = packet[0] - cs->frameid_in;
if (diff != 0) {
if (diff < 225) { /* New frame */
/* Flush last frames' data and get ready for this frame */
Payload *p = malloc(sizeof(Payload) + cs->frame_size);
@ -666,18 +669,31 @@ void queue_message(RTPSession *session, RTPMessage *msg)
memset(cs->frame_buf, 0, cs->frame_size);
cs->frame_size = 0;
} else if (packet[0] < cs->frameid_in) { /* Old frame; drop */
} else { /* Old frame; drop */
LOGGER_DEBUG("Old packet: %u", packet[0]);
goto end;
}
}
uint8_t piece_number = packet[1];
uint32_t length_before_piece = ((piece_number - 1) * cs->video_frame_piece_size);
uint32_t framebuf_new_length = length_before_piece + (packet_size - VIDEOFRAME_HEADER_SIZE);
if (framebuf_new_length > cs->max_video_frame_size) {
goto end;
}
/* Otherwise it's part of the frame so just process */
/* LOGGER_DEBUG("Video Packet: %u %u", packet[0], packet[1]); */
memcpy(cs->frame_buf + cs->frame_size,
memcpy(cs->frame_buf + length_before_piece,
packet + VIDEOFRAME_HEADER_SIZE,
packet_size - VIDEOFRAME_HEADER_SIZE);
cs->frame_size += packet_size - VIDEOFRAME_HEADER_SIZE;
if (framebuf_new_length > cs->frame_size) {
cs->frame_size = framebuf_new_length;
}
end:
rtp_free_msg(NULL, msg);