From 33dbdd2a13ae86bbe44a8339ac62f398554aab05 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 4 Mar 2014 17:34:41 +0100 Subject: [PATCH] Migrated SAGE RX/TX to new API --- Makefile.in | 1 + src/host.c | 4 +- src/host.h | 2 +- src/main.cpp | 19 +++----- src/video_rxtx.cpp | 43 ++---------------- src/video_rxtx.h | 8 ---- src/video_rxtx/sage.cpp | 96 +++++++++++++++++++++++++++++++++++++++++ src/video_rxtx/sage.h | 82 +++++++++++++++++++++++++++++++++++ 8 files changed, 190 insertions(+), 65 deletions(-) create mode 100644 src/video_rxtx/sage.cpp create mode 100644 src/video_rxtx/sage.h diff --git a/Makefile.in b/Makefile.in index d774afab9..4a0e42253 100644 --- a/Makefile.in +++ b/Makefile.in @@ -148,6 +148,7 @@ ULTRAGRID_OBJS = src/main.o \ src/video_rxtx.o \ src/video_rxtx/ihdtv.o \ src/video_rxtx/rtp.o \ + src/video_rxtx/sage.o \ src/video_rxtx/ultragrid_rtp.o \ REFLECTOR_OBJS = src/hd-rum-translator/hd-rum-decompress.o \ diff --git a/src/host.c b/src/host.c index 614a85e87..1526897cd 100644 --- a/src/host.c +++ b/src/host.c @@ -78,8 +78,8 @@ int initialize_video_capture(struct module *parent, } int initialize_video_display(const char *requested_display, - char *fmt, unsigned int flags, - struct display **out) + const char *fmt, unsigned int flags, + struct display **out) { display_type_t *dt; display_id_t id = 0; diff --git a/src/host.h b/src/host.h index 94b05c463..11d5b1508 100644 --- a/src/host.h +++ b/src/host.h @@ -108,7 +108,7 @@ struct vidcap; struct display; struct module; int initialize_video_display(const char *requested_display, - char *fmt, unsigned int flags, + const char *fmt, unsigned int flags, struct display **); int initialize_video_capture(struct module *parent, diff --git a/src/main.cpp b/src/main.cpp index 56fcb2a3d..84b7041aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,8 +80,9 @@ #include "video_display.h" #include "video_compress.h" #include "video_export.h" -#include "video_rxtx/ultragrid_rtp.h" #include "video_rxtx/ihdtv.h" +#include "video_rxtx/sage.h" +#include "video_rxtx/ultragrid_rtp.h" #include "audio/audio.h" #include "audio/audio_capture.h" #include "audio/codec.h" @@ -1000,19 +1001,9 @@ int main(int argc, char *argv[]) requested_mcast_if, requested_video_fec, requested_mtu, packet_rate, decoder_mode, postprocess, uv->display_device); } else { // SAGE -#if 0 - memset(&sage_rxtx, 0, sizeof(sage_rxtx)); - sage_receiver = uv->requested_receiver; - ret = initialize_video_display("sage", - sage_opts, 0, &sage_rxtx.sage_tx_device); - if(ret != 0) { - fprintf(stderr, "Unable to initialize SAGE TX.\n"); - exit_uv(EXIT_FAIL_NETWORK); - goto cleanup; - } - pthread_create(&sage_rxtx.thread_id, NULL, (void * (*)(void *)) display_run, - &sage_rxtx.sage_tx_device); -#endif + uv->video_rxtx = new sage_video_rxtx(&root_mod, video_exporter, + requested_compression, requested_receiver, sage_opts); + } if(rxtx_mode & MODE_RECEIVER) { diff --git a/src/video_rxtx.cpp b/src/video_rxtx.cpp index 92162c6f8..b99c752ca 100644 --- a/src/video_rxtx.cpp +++ b/src/video_rxtx.cpp @@ -68,23 +68,14 @@ #include "video_rxtx.h" #include "video_rxtx/ihdtv.h" #include "video_rxtx/rtp.h" +#include "video_rxtx/sage.h" #include "video_rxtx/ultragrid_rtp.h" using namespace std; -static void sage_rxtx_send(void *state, struct video_frame *tx_frame); -static void sage_rxtx_done(void *state); static void h264_rtp_send(void *state, struct video_frame *tx_frame); static void h264_rtp_done(void *state); -struct rx_tx sage_rxtx = { - SAGE, - "SAGE", - sage_rxtx_send, - sage_rxtx_done, - NULL -}; - struct rx_tx h264_rtp = { H264_STD, "H264 standard", @@ -139,41 +130,13 @@ const char *video_rxtx::get_name(enum rxtx_protocol proto) { return "UltraGrid RTP"; case IHDTV: return "iHDTV"; + case SAGE: + return "SAGE"; default: return NULL; } } -static void sage_rxtx_send(void *state, struct video_frame *tx_frame) -{ - struct sage_rxtx_state *data = (struct sage_rxtx_state *) state; - - if(!video_desc_eq(data->saved_vid_desc, - video_desc_from_frame(tx_frame))) { - display_reconfigure(data->sage_tx_device, - video_desc_from_frame(tx_frame)); - data->saved_vid_desc = video_desc_from_frame(tx_frame); - } - struct video_frame *frame = - display_get_frame(data->sage_tx_device); - memcpy(frame->tiles[0].data, tx_frame->tiles[0].data, - tx_frame->tiles[0].data_len); - display_put_frame(data->sage_tx_device, frame, PUTF_NONBLOCK); - - VIDEO_FRAME_DISPOSE(tx_frame); -} - -static void sage_rxtx_done(void *state) -{ - struct sage_rxtx_state *data = (struct sage_rxtx_state *) state; - - // poisoned pill to exit thread - display_put_frame(data->sage_tx_device, NULL, PUTF_NONBLOCK); - pthread_join(data->thread_id, NULL); - - display_done(data->sage_tx_device); -} - static void h264_rtp_send(void *state, struct video_frame *tx_frame) { struct h264_rtp_state *data = (struct h264_rtp_state *) state; diff --git a/src/video_rxtx.h b/src/video_rxtx.h index 8b6078e9d..8f3a03dc5 100644 --- a/src/video_rxtx.h +++ b/src/video_rxtx.h @@ -61,16 +61,8 @@ struct rx_tx { void *(*receiver_thread)(void *); }; -extern struct rx_tx ultragrid_rtp; -extern struct rx_tx sage_rxtx; extern struct rx_tx h264_rtp; -struct sage_rxtx_state { - struct video_desc saved_vid_desc; - struct display *sage_tx_device; - pthread_t thread_id; -}; - struct h264_rtp_state { int connections_count; struct rtp **network_devices; diff --git a/src/video_rxtx/sage.cpp b/src/video_rxtx/sage.cpp new file mode 100644 index 000000000..7dcbba6c2 --- /dev/null +++ b/src/video_rxtx/sage.cpp @@ -0,0 +1,96 @@ +/** + * @file video_rxtx/sage.cpp + * @author Martin Pulec + */ +/* + * Copyright (c) 2013-2014 CESNET z.s.p.o. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of CESNET nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "config_unix.h" +#include "config_win32.h" +#endif // HAVE_CONFIG_H + +#include + +#include "host.h" +#include "video_display.h" +#include "video_rxtx/sage.h" +#include "video.h" + +using namespace std; + +sage_video_rxtx::sage_video_rxtx(struct module *parent, struct video_export *video_exporter, + const char *requested_compression, + const char *requested_receiver, const char *sage_opts) : + video_rxtx(parent, video_exporter, requested_compression) +{ + sage_receiver = requested_receiver; + int ret = initialize_video_display("sage", + sage_opts, 0, &m_sage_tx_device); + if(ret != 0) { + throw string("Unable to initialize SAGE TX."); + } + pthread_create(&m_thread_id, NULL, (void * (*)(void *)) display_run, + &m_sage_tx_device); + memset(&m_saved_video_desc, 0, sizeof(m_saved_video_desc)); +} + +void sage_video_rxtx::send_frame(struct video_frame *tx_frame) +{ + if(!video_desc_eq(m_saved_video_desc, + video_desc_from_frame(tx_frame))) { + display_reconfigure(m_sage_tx_device, + video_desc_from_frame(tx_frame)); + m_saved_video_desc = video_desc_from_frame(tx_frame); + } + struct video_frame *frame = + display_get_frame(m_sage_tx_device); + memcpy(frame->tiles[0].data, tx_frame->tiles[0].data, + tx_frame->tiles[0].data_len); + display_put_frame(m_sage_tx_device, frame, PUTF_NONBLOCK); + + VIDEO_FRAME_DISPOSE(tx_frame); +} + +sage_video_rxtx::~sage_video_rxtx() +{ + // poisoned pill to exit thread + display_put_frame(m_sage_tx_device, NULL, PUTF_NONBLOCK); + pthread_join(m_thread_id, NULL); + + display_done(m_sage_tx_device); +} + + diff --git a/src/video_rxtx/sage.h b/src/video_rxtx/sage.h new file mode 100644 index 000000000..9b0cf34b1 --- /dev/null +++ b/src/video_rxtx/sage.h @@ -0,0 +1,82 @@ +/* + * FILE: video_rxtx/sage.h + * AUTHORS: Colin Perkins + * Ladan Gharai + * Martin Benes + * Lukas Hejtmanek + * Petr Holub + * Milos Liska + * Jiri Matela + * Dalibor Matura <255899@mail.muni.cz> + * Ian Wesley-Smith + * Martin Pulec + * + * Copyright (c) 2005-2014 CESNET z.s.p.o. + * Copyright (c) 2001-2004 University of Southern California + * Copyright (c) 2003-2004 University of Glasgow + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by the University of Southern + * California Information Sciences Institute. This product also includes + * software developed by CESNET z.s.p.o. + * + * 4. Neither the name of the University nor of the Institute may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef VIDEO_RXTX_SAGE_H_ +#define VIDEO_RXTX_SAGE_H_ + +#include "types.h" +#include "video_capture.h" +#include "video_display.h" +#include "video_rxtx.h" + +struct video_frame; +struct display; + +class sage_video_rxtx: public video_rxtx { +public: + sage_video_rxtx(struct module *parent, struct video_export *video_exporter, + const char *requested_compression, + const char *requested_receiver, const char *sage_opts); + ~sage_video_rxtx(); +private: + void send_frame(struct video_frame *); + void *(*get_receiver_thread())(void *arg) { + return NULL; + } + struct video_desc m_saved_video_desc; + struct display *m_sage_tx_device; + pthread_t m_thread_id; +}; + +#endif // VIDEO_RXTX_SAGE_H_ +