mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 00:00:44 +00:00
FS-7501: more factoring on vid buffer
This commit is contained in:
parent
0e991e7d0f
commit
0d626bc715
@ -513,6 +513,7 @@ SWITCH_DECLARE(char *) get_addr6(char *buf, switch_size_t len, struct sockaddr_i
|
|||||||
|
|
||||||
SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa);
|
SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa);
|
||||||
SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2);
|
SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2);
|
||||||
|
SWITCH_DECLARE(int) switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief get the port number of an ip address
|
\brief get the port number of an ip address
|
||||||
|
@ -517,6 +517,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
|
|||||||
(!frame->m) && (!context->last_received_complete_picture)) {
|
(!frame->m) && (!context->last_received_complete_picture)) {
|
||||||
// possible packet loss
|
// possible packet loss
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Packet Loss, skip previous received frame (to avoid crash?)\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Packet Loss, skip previous received frame (to avoid crash?)\n");
|
||||||
|
usleep(500000);abort();
|
||||||
switch_goto_status(SWITCH_STATUS_RESTART, end);
|
switch_goto_status(SWITCH_STATUS_RESTART, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +564,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
|
|||||||
frame->img = (switch_image_t *) vpx_codec_get_frame(decoder, &iter);
|
frame->img = (switch_image_t *) vpx_codec_get_frame(decoder, &iter);
|
||||||
|
|
||||||
if (!(frame->img) || corrupted) {
|
if (!(frame->img) || corrupted) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "VPX invalid packet\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "VPX invalid packet image: %d corrupted: %d\n", !!frame->img, corrupted);
|
||||||
switch_goto_status(SWITCH_STATUS_RESTART, end);
|
switch_goto_status(SWITCH_STATUS_RESTART, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9831,10 +9831,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
|
|||||||
loops++;
|
loops++;
|
||||||
|
|
||||||
if (switch_channel_down_nosig(session->channel)) {
|
if (switch_channel_down_nosig(session->channel)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING DOWN\n");
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_channel_test_flag(session->channel, CF_VIDEO_PAUSE)) {
|
if (switch_channel_test_flag(session->channel, CF_VIDEO_PAUSE)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING VID PAUSED\n");
|
||||||
*frame = &runtime.dummy_cng_frame;
|
*frame = &runtime.dummy_cng_frame;
|
||||||
switch_yield(20000);
|
switch_yield(20000);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
@ -9853,14 +9855,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
|
|||||||
if (status == SWITCH_STATUS_INUSE) {
|
if (status == SWITCH_STATUS_INUSE) {
|
||||||
*frame = &runtime.dummy_cng_frame;
|
*frame = &runtime.dummy_cng_frame;
|
||||||
switch_yield(20000);
|
switch_yield(20000);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING DUMMY\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING BAD STATUS %d\n", status);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(*frame)) {
|
if (!(*frame)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING NO FRAME\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9882,6 +9887,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
|
|||||||
|
|
||||||
|
|
||||||
if (switch_test_flag(*frame, SFF_CNG)) {
|
if (switch_test_flag(*frame, SFF_CNG)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FUCKING CNG\n");
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -5107,6 +5107,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
|
|||||||
rtp_session->recv_msg.header.pt = jb_frame->pt;
|
rtp_session->recv_msg.header.pt = jb_frame->pt;
|
||||||
rtp_session->recv_msg.header.seq = htons(jb_frame->seq);
|
rtp_session->recv_msg.header.seq = htons(jb_frame->seq);
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
switch_cp_addr(rtp_session->from_addr, rtp_session->remote_addr);
|
||||||
if (!xcheck_jitter) {
|
if (!xcheck_jitter) {
|
||||||
check_jitter(rtp_session);
|
check_jitter(rtp_session);
|
||||||
xcheck_jitter = *bytes;
|
xcheck_jitter = *bytes;
|
||||||
@ -5121,18 +5122,22 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
|
|||||||
switch(vstatus) {
|
switch(vstatus) {
|
||||||
case SWITCH_STATUS_RESTART:
|
case SWITCH_STATUS_RESTART:
|
||||||
switch_core_session_request_video_refresh(rtp_session->session);
|
switch_core_session_request_video_refresh(rtp_session->session);
|
||||||
|
*bytes = 0;
|
||||||
break;
|
break;
|
||||||
case SWITCH_STATUS_MORE_DATA:
|
case SWITCH_STATUS_MORE_DATA:
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
*bytes = 0;
|
*bytes = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
case SWITCH_STATUS_SUCCESS:
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
switch_cp_addr(rtp_session->from_addr, rtp_session->remote_addr);
|
||||||
if (!xcheck_jitter) {
|
if (!xcheck_jitter) {
|
||||||
check_jitter(rtp_session);
|
check_jitter(rtp_session);
|
||||||
xcheck_jitter = *bytes;
|
xcheck_jitter = *bytes;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1976,6 +1976,55 @@ SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *s
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(int) switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *s1;
|
||||||
|
struct sockaddr_in *s2;
|
||||||
|
|
||||||
|
struct sockaddr_in6 *s16;
|
||||||
|
struct sockaddr_in6 *s26;
|
||||||
|
|
||||||
|
struct sockaddr *ss1;
|
||||||
|
struct sockaddr *ss2;
|
||||||
|
|
||||||
|
if (!(sa1 && sa2))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
s1 = (struct sockaddr_in *) &sa1->sa;
|
||||||
|
s2 = (struct sockaddr_in *) &sa2->sa;
|
||||||
|
|
||||||
|
s16 = (struct sockaddr_in6 *) &sa1->sa;
|
||||||
|
s26 = (struct sockaddr_in6 *) &sa2->sa;
|
||||||
|
|
||||||
|
ss1 = (struct sockaddr *) &sa1->sa;
|
||||||
|
ss2 = (struct sockaddr *) &sa2->sa;
|
||||||
|
|
||||||
|
if (ss1->sa_family != ss2->sa_family)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ss1->sa_family) {
|
||||||
|
case AF_INET:
|
||||||
|
s1->sin_addr.s_addr = s2->sin_addr.s_addr;
|
||||||
|
s1->sin_port = s2->sin_port;
|
||||||
|
return 1;
|
||||||
|
case AF_INET6:
|
||||||
|
if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
s16->sin6_port = s26->sin6_port;
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
*((int32_t *) s16->sin6_addr.s6_addr + i) = *((int32_t *) s26->sin6_addr.s6_addr + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(char *) get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
|
SWITCH_DECLARE(char *) get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
|
||||||
{
|
{
|
||||||
switch_assert(buf);
|
switch_assert(buf);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <switch_vidderbuffer.h>
|
#include <switch_vidderbuffer.h>
|
||||||
|
|
||||||
|
#define MAX_MISSING_SEQ 20
|
||||||
#define vb_debug(_vb, _level, _format, ...) if (_vb->debug_level >= _level) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ALERT, "VB:%p level:%d line:%d ->" _format, (void *) _vb, _level, __LINE__, __VA_ARGS__)
|
#define vb_debug(_vb, _level, _format, ...) if (_vb->debug_level >= _level) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ALERT, "VB:%p level:%d line:%d ->" _format, (void *) _vb, _level, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
typedef struct switch_vb_node_s {
|
typedef struct switch_vb_node_s {
|
||||||
@ -45,8 +46,10 @@ typedef struct switch_vb_frame_s {
|
|||||||
struct switch_vb_s *parent;
|
struct switch_vb_s *parent;
|
||||||
struct switch_vb_node_s *node_list;
|
struct switch_vb_node_s *node_list;
|
||||||
uint32_t ts;
|
uint32_t ts;
|
||||||
|
uint32_t visible_nodes;
|
||||||
uint8_t visible;
|
uint8_t visible;
|
||||||
uint8_t complete;
|
uint8_t complete;
|
||||||
|
uint8_t mark;
|
||||||
struct switch_vb_frame_s *next;
|
struct switch_vb_frame_s *next;
|
||||||
uint16_t min_seq;
|
uint16_t min_seq;
|
||||||
uint16_t max_seq;
|
uint16_t max_seq;
|
||||||
@ -55,8 +58,11 @@ typedef struct switch_vb_frame_s {
|
|||||||
struct switch_vb_s {
|
struct switch_vb_s {
|
||||||
struct switch_vb_frame_s *frame_list;
|
struct switch_vb_frame_s *frame_list;
|
||||||
struct switch_vb_frame_s *cur_read_frame;
|
struct switch_vb_frame_s *cur_read_frame;
|
||||||
|
struct switch_vb_frame_s *cur_write_frame;
|
||||||
uint32_t last_read_ts;
|
uint32_t last_read_ts;
|
||||||
uint32_t last_read_seq;
|
uint32_t last_read_seq;
|
||||||
|
uint32_t last_wrote_ts;
|
||||||
|
uint32_t last_wrote_seq;
|
||||||
uint16_t target_seq;
|
uint16_t target_seq;
|
||||||
uint16_t seq_out;
|
uint16_t seq_out;
|
||||||
uint32_t visible_frames;
|
uint32_t visible_frames;
|
||||||
@ -96,7 +102,8 @@ static inline switch_vb_node_t *new_node(switch_vb_frame_t *frame)
|
|||||||
switch_assert(np);
|
switch_assert(np);
|
||||||
|
|
||||||
np->visible = 1;
|
np->visible = 1;
|
||||||
|
np->parent->visible_nodes++;
|
||||||
|
|
||||||
return np;
|
return np;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,18 +124,29 @@ static inline void add_node(switch_vb_frame_t *frame, switch_rtp_packet_t *packe
|
|||||||
frame->max_seq = packet->header.seq;
|
frame->max_seq = packet->header.seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
vb_debug(frame->parent, (packet->header.m ? 1 : 2), "PUT packet ts:%u seq:%u %s\n",
|
vb_debug(frame->parent, (packet->header.m ? 1 : 2), "PUT packet last_ts:%u ts:%u seq:%u %s\n",
|
||||||
ntohl(node->packet.header.ts), ntohs(node->packet.header.seq), packet->header.m ? "FINAL" : "PARTIAL");
|
ntohl(frame->parent->last_wrote_ts), ntohl(node->packet.header.ts), ntohs(node->packet.header.seq), packet->header.m ? "FINAL" : "PARTIAL");
|
||||||
|
|
||||||
|
|
||||||
if (packet->header.m) {
|
if (packet->header.m) {
|
||||||
|
frame->mark = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((frame->parent->last_wrote_ts && frame->parent->last_wrote_ts != node->packet.header.ts)) {
|
||||||
frame->complete = 1;
|
frame->complete = 1;
|
||||||
frame->parent->complete_frames++;
|
frame->parent->complete_frames++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frame->parent->last_wrote_ts = packet->header.ts;
|
||||||
|
frame->parent->last_wrote_seq = packet->header.seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void hide_node(switch_vb_node_t *node)
|
static inline void hide_node(switch_vb_node_t *node)
|
||||||
{
|
{
|
||||||
node->visible = 0;
|
if (node->visible) {
|
||||||
|
node->visible = 0;
|
||||||
|
node->parent->visible_nodes--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void hide_nodes(switch_vb_frame_t *frame)
|
static inline void hide_nodes(switch_vb_frame_t *frame)
|
||||||
@ -144,30 +162,45 @@ static inline void hide_frame(switch_vb_frame_t *frame)
|
|||||||
{
|
{
|
||||||
vb_debug(frame->parent, 2, "Hide frame ts: %u\n", ntohl(frame->ts));
|
vb_debug(frame->parent, 2, "Hide frame ts: %u\n", ntohl(frame->ts));
|
||||||
|
|
||||||
frame->visible = 0;
|
if (frame->visible) {
|
||||||
frame->min_seq = frame->max_seq = 0;
|
frame->visible = 0;
|
||||||
frame->parent->visible_frames--;
|
frame->parent->visible_frames--;
|
||||||
|
}
|
||||||
|
|
||||||
if (frame->complete) {
|
if (frame->complete) {
|
||||||
frame->parent->complete_frames--;
|
frame->parent->complete_frames--;
|
||||||
frame->complete = 0;
|
frame->complete = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frame->min_seq = frame->max_seq = 0;
|
||||||
|
|
||||||
hide_nodes(frame);
|
hide_nodes(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline switch_vb_frame_t *new_frame(switch_vb_t *vb, switch_rtp_packet_t *packet)
|
static inline switch_vb_frame_t *new_frame(switch_vb_t *vb, switch_rtp_packet_t *packet)
|
||||||
{
|
{
|
||||||
switch_vb_frame_t *fp, *last = NULL;
|
switch_vb_frame_t *fp = NULL, *last = NULL;
|
||||||
int new = 1;
|
int new = 1;
|
||||||
|
|
||||||
for (fp = vb->frame_list; fp; fp = fp->next) {
|
if (vb->cur_write_frame) {
|
||||||
if (fp->ts == packet->header.ts) {
|
if (!vb->cur_write_frame->visible) {
|
||||||
if (fp->complete || !fp->visible) {
|
vb->cur_write_frame = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else if (vb->cur_write_frame->ts == packet->header.ts) {
|
||||||
new = 0;
|
fp = vb->cur_write_frame;
|
||||||
break;
|
new = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fp) {
|
||||||
|
for (fp = vb->frame_list; fp; fp = fp->next) {
|
||||||
|
if (fp->ts == packet->header.ts) {
|
||||||
|
if (!fp->visible) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
new = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,8 +234,11 @@ static inline switch_vb_frame_t *new_frame(switch_vb_t *vb, switch_rtp_packet_t
|
|||||||
fp->complete = 0;
|
fp->complete = 0;
|
||||||
fp->ts = packet->header.ts;
|
fp->ts = packet->header.ts;
|
||||||
fp->min_seq = fp->max_seq = 0;
|
fp->min_seq = fp->max_seq = 0;
|
||||||
|
fp->mark = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vb->cur_write_frame = fp;
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -212,7 +248,12 @@ static inline int frame_contains_seq(switch_vb_frame_t *frame, uint16_t target_s
|
|||||||
int16_t seq = ntohs(target_seq);
|
int16_t seq = ntohs(target_seq);
|
||||||
|
|
||||||
if (frame->min_seq && frame->max_seq && seq >= ntohs(frame->min_seq) && seq <= ntohs(frame->max_seq)) {
|
if (frame->min_seq && frame->max_seq && seq >= ntohs(frame->min_seq) && seq <= ntohs(frame->max_seq)) {
|
||||||
return 1;
|
switch_vb_node_t *np;
|
||||||
|
|
||||||
|
for (np = frame->node_list; np; np = np->next) {
|
||||||
|
if (!np->visible) continue;
|
||||||
|
if (ntohs(np->packet.header.seq) == seq) return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -261,36 +302,85 @@ static inline int check_frame(switch_vb_frame_t *frame, switch_bool_t seq_check)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void increment_seq(switch_vb_t *vb)
|
||||||
|
{
|
||||||
|
vb->target_seq = htons((ntohs(vb->target_seq) + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void set_read_seq(switch_vb_t *vb, uint16_t seq)
|
||||||
|
{
|
||||||
|
vb->last_read_seq = seq;
|
||||||
|
vb->target_seq = htons((ntohs(vb->last_read_seq) + 1));
|
||||||
|
}
|
||||||
|
|
||||||
static inline switch_status_t next_frame(switch_vb_t *vb)
|
static inline switch_status_t next_frame(switch_vb_t *vb)
|
||||||
{
|
{
|
||||||
switch_vb_frame_t *fp = NULL, *oldest = NULL, *frame_containing_seq = NULL;
|
switch_vb_frame_t *fp = NULL, *oldest = NULL, *frame_containing_seq = NULL;
|
||||||
|
|
||||||
vb->cur_read_frame = NULL;
|
if ((fp = vb->cur_read_frame)) {
|
||||||
|
if (fp->visible_nodes == 0) {
|
||||||
for (fp = vb->frame_list; fp; fp = fp->next) {
|
hide_frame(fp);
|
||||||
|
vb->cur_read_frame = NULL;
|
||||||
if (!fp->visible || !fp->complete) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vb->target_seq) {
|
|
||||||
if (frame_contains_seq(fp, vb->target_seq)) {
|
if ((fp = vb->cur_read_frame)) {
|
||||||
vb_debug(fp->parent, 2, "FOUND FRAME CONTAINING SEQ %d\n", ntohs(vb->target_seq));
|
int ok = 1;
|
||||||
frame_containing_seq = fp;
|
|
||||||
break;
|
if (!fp->visible || !fp->complete || fp->visible_nodes == 0) {
|
||||||
|
ok = 0;
|
||||||
|
} else {
|
||||||
|
if (vb->target_seq) {
|
||||||
|
if (frame_contains_seq(fp, vb->target_seq)) {
|
||||||
|
vb_debug(vb, 2, "FOUND CUR FRAME %u CONTAINING SEQ %d\n", ntohl(fp->ts), ntohs(vb->target_seq));
|
||||||
|
frame_containing_seq = fp;
|
||||||
|
goto end;
|
||||||
|
} else {
|
||||||
|
ok = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!check_frame(fp, SWITCH_FALSE)) {
|
if (!ok) {
|
||||||
return SWITCH_STATUS_RESTART;
|
vb_debug(vb, 2, "DONE WITH CUR FRAME %u v: %d c: %d\n", ntohl(fp->ts), fp->visible, fp->complete);
|
||||||
}
|
vb->cur_read_frame = NULL;
|
||||||
|
|
||||||
if ((!oldest || htonl(oldest->ts) > htonl(fp->ts))) {
|
|
||||||
oldest = fp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
for (fp = vb->frame_list; fp; fp = fp->next) {
|
||||||
|
|
||||||
|
if (!fp->visible || !fp->complete) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vb->target_seq) {
|
||||||
|
if (frame_contains_seq(fp, vb->target_seq)) {
|
||||||
|
vb_debug(vb, 2, "FOUND FRAME %u CONTAINING SEQ %d\n", ntohl(fp->ts), ntohs(vb->target_seq));
|
||||||
|
frame_containing_seq = fp;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!oldest || htonl(oldest->ts) > htonl(fp->ts))) {
|
||||||
|
oldest = fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!frame_containing_seq && vb->target_seq) {
|
||||||
|
if (ntohs(vb->target_seq) - ntohs(vb->last_read_seq) > MAX_MISSING_SEQ) {
|
||||||
|
vb_debug(vb, 1, "FOUND NO FRAMES CONTAINING SEQ %d. Too many failures....\n", ntohs(vb->target_seq));
|
||||||
|
switch_vb_reset(vb, SWITCH_FALSE);
|
||||||
|
} else {
|
||||||
|
vb_debug(vb, 2, "FOUND NO FRAMES CONTAINING SEQ %d. Try next one\n", ntohs(vb->target_seq));
|
||||||
|
increment_seq(vb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!frame_containing_seq && vb->target_seq);
|
||||||
|
|
||||||
|
end:
|
||||||
|
|
||||||
if (frame_containing_seq) {
|
if (frame_containing_seq) {
|
||||||
vb->cur_read_frame = frame_containing_seq;
|
vb->cur_read_frame = frame_containing_seq;
|
||||||
@ -305,12 +395,6 @@ static inline switch_status_t next_frame(switch_vb_t *vb)
|
|||||||
return SWITCH_STATUS_NOTFOUND;
|
return SWITCH_STATUS_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_read_seq(switch_vb_t *vb, uint16_t seq)
|
|
||||||
{
|
|
||||||
vb->last_read_seq = seq;
|
|
||||||
vb->target_seq = htons((ntohs(vb->last_read_seq) + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline switch_vb_node_t *frame_find_next_seq(switch_vb_frame_t *frame)
|
static inline switch_vb_node_t *frame_find_next_seq(switch_vb_frame_t *frame)
|
||||||
{
|
{
|
||||||
switch_vb_node_t *np;
|
switch_vb_node_t *np;
|
||||||
@ -349,19 +433,31 @@ static inline switch_vb_node_t *frame_find_lowest_seq(switch_vb_frame_t *frame)
|
|||||||
return lowest;
|
return lowest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline switch_vb_node_t *next_frame_packet(switch_vb_t *vb)
|
static inline switch_status_t next_frame_packet(switch_vb_t *vb, switch_vb_node_t **nodep)
|
||||||
{
|
{
|
||||||
switch_vb_node_t *node;
|
switch_vb_node_t *node;
|
||||||
|
switch_status_t status;
|
||||||
|
|
||||||
if (vb->last_read_seq) {
|
if ((status = next_frame(vb) != SWITCH_STATUS_SUCCESS)) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vb->target_seq) {
|
||||||
vb_debug(vb, 2, "Search for next packet %u cur ts: %u\n", htons(vb->target_seq), htonl(vb->cur_read_frame->ts));
|
vb_debug(vb, 2, "Search for next packet %u cur ts: %u\n", htons(vb->target_seq), htonl(vb->cur_read_frame->ts));
|
||||||
node = frame_find_next_seq(vb->cur_read_frame);
|
node = frame_find_next_seq(vb->cur_read_frame);
|
||||||
} else {
|
} else {
|
||||||
vb_debug(vb, 2, "Find lowest seq frame ts: %u\n", ntohl(vb->cur_read_frame->ts));
|
|
||||||
node = frame_find_lowest_seq(vb->cur_read_frame);
|
node = frame_find_lowest_seq(vb->cur_read_frame);
|
||||||
|
vb_debug(vb, 2, "Find lowest seq frame ts: %u seq: %u\n", ntohl(vb->cur_read_frame->ts), ntohs(node->packet.header.seq));
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
*nodep = node;
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_NOTFOUND;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_nodes(switch_vb_frame_t *frame)
|
static inline void free_nodes(switch_vb_frame_t *frame)
|
||||||
@ -418,8 +514,10 @@ SWITCH_DECLARE(void) switch_vb_debug_level(switch_vb_t *vb, uint8_t level)
|
|||||||
|
|
||||||
SWITCH_DECLARE(void) switch_vb_reset(switch_vb_t *vb, switch_bool_t flush)
|
SWITCH_DECLARE(void) switch_vb_reset(switch_vb_t *vb, switch_bool_t flush)
|
||||||
{
|
{
|
||||||
|
vb_debug(vb, 2, "RESET BUFFER flush: %d\n", (int)flush);
|
||||||
|
|
||||||
|
|
||||||
if (vb->cur_read_frame) {
|
if (vb->cur_read_frame) {
|
||||||
hide_frame(vb->cur_read_frame);
|
|
||||||
vb->cur_read_frame = NULL;
|
vb->cur_read_frame = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,7 +567,7 @@ SWITCH_DECLARE(switch_status_t) switch_vb_put_packet(switch_vb_t *vb, switch_rtp
|
|||||||
{
|
{
|
||||||
switch_vb_frame_t *frame;
|
switch_vb_frame_t *frame;
|
||||||
|
|
||||||
#ifndef VB_PLOSS
|
#ifdef VB_PLOSS
|
||||||
int r = (rand() % 100000) + 1;
|
int r = (rand() % 100000) + 1;
|
||||||
if (r <= 20) {
|
if (r <= 20) {
|
||||||
vb_debug(vb, 1, "Simulate dropped packet ......... ts: %u seq: %u\n", ntohl(packet->header.ts), ntohs(packet->header.seq));
|
vb_debug(vb, 1, "Simulate dropped packet ......... ts: %u seq: %u\n", ntohl(packet->header.ts), ntohs(packet->header.seq));
|
||||||
@ -488,37 +586,28 @@ SWITCH_DECLARE(switch_status_t) switch_vb_put_packet(switch_vb_t *vb, switch_rtp
|
|||||||
SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp_packet_t *packet, switch_size_t *len)
|
SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp_packet_t *packet, switch_size_t *len)
|
||||||
{
|
{
|
||||||
switch_vb_node_t *node = NULL;
|
switch_vb_node_t *node = NULL;
|
||||||
int fail = 0;
|
switch_status_t status;
|
||||||
|
|
||||||
if (vb->complete_frames < vb->frame_len) {
|
if (vb->complete_frames < vb->frame_len) {
|
||||||
vb_debug(vb, 2, "BUFFERING %u/%u\n", vb->complete_frames , vb->frame_len);
|
vb_debug(vb, 2, "BUFFERING %u/%u\n", vb->complete_frames , vb->frame_len);
|
||||||
return SWITCH_STATUS_MORE_DATA;
|
return SWITCH_STATUS_MORE_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
if ((status = next_frame_packet(vb, &node)) == SWITCH_STATUS_SUCCESS) {
|
||||||
if (vb->cur_read_frame) {
|
vb_debug(vb, 2, "Found next frame cur ts: %u seq: %u\n", htonl(vb->cur_read_frame->ts), htons(node->packet.header.seq));
|
||||||
if (!(node = next_frame_packet(vb))) {
|
} else {
|
||||||
vb_debug(vb, 2, "Cannot find next packet %u cur ts: %u\n", htons(vb->target_seq), htonl(vb->cur_read_frame->ts));
|
switch_vb_reset(vb, SWITCH_FALSE);
|
||||||
switch_vb_reset(vb, SWITCH_FALSE);
|
|
||||||
fail++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch_status_t status = next_frame(vb);
|
|
||||||
|
|
||||||
switch(status) {
|
|
||||||
case SWITCH_STATUS_RESTART:
|
|
||||||
vb_debug(vb, 2, "%s", "Error encountered ask for new keyframe\n");
|
|
||||||
return SWITCH_STATUS_RESTART;
|
|
||||||
case SWITCH_STATUS_NOTFOUND:
|
|
||||||
vb_debug(vb, 2, "%s", "No frames found wait for more\n");
|
|
||||||
return SWITCH_STATUS_MORE_DATA;
|
|
||||||
default:
|
|
||||||
vb_debug(vb, 2, "Found next frame cur ts: %u\n", htonl(vb->cur_read_frame->ts));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (!node && fail < 2);
|
switch(status) {
|
||||||
|
case SWITCH_STATUS_RESTART:
|
||||||
|
vb_debug(vb, 2, "%s", "Error encountered ask for new keyframe\n");
|
||||||
|
return SWITCH_STATUS_RESTART;
|
||||||
|
case SWITCH_STATUS_NOTFOUND:
|
||||||
|
default:
|
||||||
|
vb_debug(vb, 2, "%s", "No frames found wait for more\n");
|
||||||
|
return SWITCH_STATUS_MORE_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
*packet = node->packet;
|
*packet = node->packet;
|
||||||
@ -533,22 +622,14 @@ SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
packet->header.ts = htonl(vb->timer.samplecount);
|
vb_debug(vb, 1, "GET packet ts:%u seq:%u~%u m:%d\n", ntohl(packet->header.ts), ntohs(packet->header.seq), vb->seq_out, packet->header.m);
|
||||||
|
|
||||||
vb_debug(vb, 1, "GET packet ts:%u seq:%u~%u\n", ntohl(packet->header.ts), ntohs(packet->header.seq), vb->seq_out);
|
|
||||||
|
|
||||||
if (vb->timer.timer_interface) {
|
if (vb->timer.timer_interface) {
|
||||||
packet->header.seq = htons(vb->seq_out++);
|
packet->header.seq = htons(vb->seq_out++);
|
||||||
|
packet->header.ts = htonl(vb->timer.samplecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vb->cur_read_frame && node->packet.header.m) {
|
|
||||||
hide_frame(vb->cur_read_frame);
|
|
||||||
vb->cur_read_frame = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
} else if (fail) {
|
|
||||||
return SWITCH_STATUS_NOTFOUND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_MORE_DATA;
|
return SWITCH_STATUS_MORE_DATA;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user