From 25c89d453df5781b8863476ef6652bb5f5765602 Mon Sep 17 00:00:00 2001 From: Piotr Binkowski Date: Mon, 23 Dec 2019 15:01:42 +0100 Subject: [PATCH] firmware/eth_stream: add double buffering --- firmware/eth_stream.c | 13 ++++++++++--- firmware/eth_stream.h | 4 +++- firmware/processor.c | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/firmware/eth_stream.c b/firmware/eth_stream.c index 548e62ec9..3d8267d36 100644 --- a/firmware/eth_stream.c +++ b/firmware/eth_stream.c @@ -13,6 +13,8 @@ static int eth_stream_in_pos; static int eth_stream_out_pos; static int eth_stream_out_state; +int eth_stream_in_fb_index; + static unsigned int eth_stream_out_next_fb; static unsigned int eth_stream_out_size; @@ -42,6 +44,8 @@ void eth_stream_init(void) (tcp_socket_event_callback_t) eth_stream_out_event_cb); tcp_socket_listen(ð_stream_socket_out, ETH_STREAM_PORT_OUT); + eth_stream_in_fb_index = 0; + printf("Ethernet streamer listening on ports %d(in) %d(out)\n", ETH_STREAM_PORT_IN, ETH_STREAM_PORT_OUT); #endif } @@ -54,6 +58,8 @@ int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t e eth_stream_in_pos = 0; break; case TCP_SOCKET_CLOSED: + eth_stream_in_fb_index = (eth_stream_in_fb_index + 1) % 4; + break; case TCP_SOCKET_TIMEDOUT: case TCP_SOCKET_ABORTED: default: @@ -64,14 +70,15 @@ int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t e int eth_stream_in_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, int rxlen) { - uint8_t *fb_base = (uint8_t*)fb_ptrdiff_to_main_ram(FRAMEBUFFER_BASE_ETH_IN); + char idx = (eth_stream_in_fb_index + 1) % 4; + uint8_t *fb_base = (uint8_t*)fb_ptrdiff_to_main_ram(eth_stream_in_framebuffer_base(idx)); memcpy(fb_base + eth_stream_in_pos, rxbuf, rxlen); eth_stream_in_pos += rxlen; return 0; } -unsigned int eth_stream_in_framebuffer_base(void) { - return FRAMEBUFFER_BASE_ETH_IN; +unsigned int eth_stream_in_framebuffer_base(char n) { + return FRAMEBUFFER_BASE_ETH_IN + n * FRAMEBUFFER_SIZE; } int eth_stream_out_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event) diff --git a/firmware/eth_stream.h b/firmware/eth_stream.h index c42584c03..0fbc2c06f 100644 --- a/firmware/eth_stream.h +++ b/firmware/eth_stream.h @@ -22,6 +22,8 @@ enum { ETH_STREAM_OUT_STATE_CLOSE, }; +extern int eth_stream_in_fb_index; + void eth_stream_init(void); int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event); @@ -30,7 +32,7 @@ int eth_stream_in_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, in int eth_stream_out_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event); int eth_stream_out_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, int rxlen); -unsigned int eth_stream_in_framebuffer_base(void); +unsigned int eth_stream_in_framebuffer_base(char n); void eth_stream_out_service(void); void eth_stream_out_base_write(unsigned int value); diff --git a/firmware/processor.c b/firmware/processor.c index 55ace6627..c8f281113 100644 --- a/firmware/processor.c +++ b/firmware/processor.c @@ -745,7 +745,7 @@ void processor_update(void) hdmi_out0_core_initiator_base_write(pattern_framebuffer_base()); if(processor_hdmi_out0_source == VIDEO_IN_ETH) - hdmi_out0_core_initiator_base_write(eth_stream_in_framebuffer_base()); + hdmi_out0_core_initiator_base_write(eth_stream_in_framebuffer_base(eth_stream_in_fb_index)); #endif #ifdef CSR_HDMI_OUT1_BASE