From 34b378ee754f5811b1f1cb30ca55a17dd26bb9cd Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 12 Sep 2017 18:28:41 +0200 Subject: video test passed --- code/core/core.c | 1 + code/core/rbuf_recv.c | 10 ++++------ code/test/vid/Makefile | 12 ++++++------ code/test/vid/client.c | 26 ++++++++++++++------------ code/test/vid/enc.c | 1 + 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/code/core/core.c b/code/core/core.c index ab4041f..fafda4f 100644 --- a/code/core/core.c +++ b/code/core/core.c @@ -1349,6 +1349,7 @@ int ecp_msg_defrag(ECPFragIter *iter, ecp_seq_t seq, unsigned char *msg_in, size } else { if (iter->seq + frag_cnt != seq) { iter->seq = seq - frag_cnt; + iter->frag_cnt = 0; return ECP_ERR_ITER; } if (iter->frag_cnt != frag_cnt) return ECP_ERR_ITER; diff --git a/code/core/rbuf_recv.c b/code/core/rbuf_recv.c index 2217bfc..b3b48dc 100644 --- a/code/core/rbuf_recv.c +++ b/code/core/rbuf_recv.c @@ -149,22 +149,20 @@ static int ack_send(ECPConnection *conn) { static int ack_shift(ECPRBRecv *buf) { int do_ack = 0; + int in_rbuf = 0; int idx; int i; if ((buf->flags & ECP_RBUF_FLAG_RELIABLE) && ((buf->ack_map & ACK_MASK_FIRST) == 0)) return 0; - idx = ecp_rbuf_msg_idx(&buf->rbuf, buf->seq_ack); - if (idx < 0) return idx; - while (ECP_SEQ_LT(buf->seq_ack, buf->rbuf.seq_max)) { - idx = ECP_RBUF_IDX_MASK(idx + 1, buf->rbuf.msg_size); buf->seq_ack++; + in_rbuf = ECP_SEQ_LT(buf->seq_ack, buf->rbuf.seq_start) ? 1 : buf->rbuf.msg[ECP_RBUF_IDX_MASK(buf->rbuf.msg_start + buf->seq_ack - buf->rbuf.seq_start, buf->rbuf.msg_size)].flags & ECP_RBUF_FLAG_IN_RBUF; - if ((buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) && (buf->ack_map == ECP_ACK_FULL)) continue; + if (in_rbuf && (buf->ack_map == ECP_ACK_FULL)) continue; buf->ack_map = buf->ack_map << 1; - if (buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) { + if (in_rbuf & ECP_RBUF_FLAG_IN_RBUF) { buf->ack_map |= 1; } else if (!do_ack && ECP_SEQ_LTE(buf->seq_ack, buf->rbuf.seq_max - 2 * buf->hole_max)) { do_ack = 1; diff --git a/code/test/vid/Makefile b/code/test/vid/Makefile index 3f78157..9ef247e 100644 --- a/code/test/vid/Makefile +++ b/code/test/vid/Makefile @@ -1,7 +1,7 @@ -# LIBVPX_HOME=/home/majstor/libvpx -LIBVPX_HOME=/Users/majstor/src/libvpx -CFLAGS=-D_V4L2_KERNEL_ -I/usr/src/linux-headers-$(uname -r) -I$(LIBVPX_HOME) -I../../core -I../../vconn -I../../util -LDFLAGS=-L$(LIBVPX_HOME) +LIBVPX_HOME=/home/majstor/libvpx +# LIBVPX_HOME=/Users/majstor/src/libvpx +CFLAGS=-D_V4L2_KERNEL_ -I/usr/src/linux-headers-$(uname -r) -I$(LIBVPX_HOME) -I/opt/local/include/SDL2 -I../../core -I../../vconn -I../../util +LDFLAGS=-L$(LIBVPX_HOME) -L/opt/local/lib dep=../../core/libecpcore.a ../../core/crypto/libecpcr.a ../../core/htable/libecpht.a ../../core/posix/libecptr.a ../../core/posix/libecptm.a ../../vconn/libecpvconn.a ../../util/libecputil.a ../init.o all: client cap @@ -12,8 +12,8 @@ all: client cap cap: cap.o enc.o tools.o server.o $(CC) -o $@ $< enc.o tools.o server.o -lvpx -lm -pthread $(dep) $(LDFLAGS) -client: client.o tools.o - $(CC) -o $@ $< tools.o -lvpx -lm -pthread $(dep) $(LDFLAGS) +client: client.o display.o tools.o + $(CC) -o $@ $< display.o tools.o -lvpx -lSDL2 -lm -pthread $(dep) $(LDFLAGS) clean: rm -f *.o diff --git a/code/test/vid/client.c b/code/test/vid/client.c index 858d2ad..2c32c51 100644 --- a/code/test/vid/client.c +++ b/code/test/vid/client.c @@ -9,6 +9,7 @@ #include "vpx/vpx_decoder.h" #include "vpx/vp8cx.h" #include "tools.h" +#include "display.h" #define CTYPE_TEST 0 #define MTYPE_MSG 8 @@ -23,7 +24,6 @@ ECPConnHandler handler_c; ECPNode node; ECPConnection conn; -FILE *outfile; vpx_codec_ctx_t codec; ECPRBRecv rbuf_recv; @@ -31,17 +31,18 @@ ECPRBMessage rbuf_r_msg[RBUF_MSG_SIZE]; ECPFragIter frag_iter; unsigned char frag_buffer[FRAG_BUF_SIZE]; +SDLCanvas sdl_canvas; + ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *f, ssize_t sz) { vpx_codec_iter_t iter = NULL; vpx_image_t *img = NULL; - if (vpx_codec_decode(&codec, f, (unsigned int)sz, NULL, 0)) - die_codec(&codec, "Failed to decode frame."); + + if (vpx_codec_decode(&codec, f, (unsigned int)sz, NULL, 0)) die_codec(&codec, "Failed to decode frame."); while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { - if (!vpx_img_write_f(img, outfile)) { - die_codec(NULL, "Failed to write image."); - } + if (!vpx_img_write(img, sdl_canvas.yuvBuffer, sdl_canvas.yPlaneSz + 2 * sdl_canvas.uvPlaneSz)) die_codec(NULL, "Failed to write image."); } + sdl_display_frame(&sdl_canvas); return sz; } @@ -88,12 +89,8 @@ int main(int argc, char *argv[]) { rbuf_recv.frag_iter = &frag_iter; } - if (!rv) rv = ecp_conn_open(&conn, &node); - fprintf(stderr, "ecp_conn_open RV:%d\n", rv); - const char *codec_arg = "vp9"; const VpxInterface *decoder = get_vpx_decoder_by_name(codec_arg); - outfile = stdout; if (!decoder) die_codec(NULL, "Unknown input codec."); fprintf(stderr, "Using %s\n", vpx_codec_iface_name(decoder->codec_interface())); @@ -101,7 +98,12 @@ int main(int argc, char *argv[]) { if (vpx_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0)) die_codec(&codec, "Failed to initialize decoder."); - while (1) sleep(1); - + sdl_open(&sdl_canvas, 640, 480); + + if (!rv) rv = ecp_conn_open(&conn, &node); + fprintf(stderr, "ecp_conn_open RV:%d\n", rv); + + sdl_loop(); + sdl_close(&sdl_canvas); if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec"); } \ No newline at end of file diff --git a/code/test/vid/enc.c b/code/test/vid/enc.c index 9aebf5f..34d0be8 100644 --- a/code/test/vid/enc.c +++ b/code/test/vid/enc.c @@ -148,6 +148,7 @@ void vpx_open(const char *codec_arg, int width, int height, int fps, int bitrate cfg.g_timebase.den = fps; cfg.rc_target_bitrate = bitrate; cfg.g_error_resilient = err_resilient; + cfg.g_lag_in_frames = 0; cfg.rc_end_usage = VPX_CBR; if (vpx_codec_enc_init(codec, encoder->codec_interface(), &cfg, 0)) -- cgit v1.2.3