Changed constructor call convention of video_rxtx

This commit is contained in:
Martin Pulec
2014-07-22 16:16:43 +02:00
parent d4a046b4fb
commit b1b6d4bf68
13 changed files with 130 additions and 147 deletions

View File

@@ -963,39 +963,65 @@ int main(int argc, char *argv[])
}
try {
if (video_protocol == IHDTV) {
struct vidcap *capture_device = NULL;
struct display *display_device = NULL;
if (rxtx_mode & MODE_SENDER)
capture_device = uv->capture_device;
if (rxtx_mode & MODE_RECEIVER)
display_device = uv->display_device;
uv->state_video_rxtx = new ihdtv_video_rxtx(&root_mod, video_exporter,
requested_compression, capture_device,
display_device, requested_mtu,
argc, argv);
}else if (video_protocol == H264_STD) {
rtps_types_t avType;
if(strcmp("none", vidcap_params_get_driver(vidcap_params_head)) != 0 && (strcmp("none",audio_send) != 0)) avType = av; //AVStream
else if((strcmp("none",audio_send) != 0)) avType = audio; //AStream
else if(strcmp("none", vidcap_params_get_driver(vidcap_params_head))) avType = video; //VStream
else printf("[RTSP SERVER CHECK] no stream type... check capture devices input...\n");
map<string, param_u> params;
// common
params["parent"].ptr = &root_mod;
params["exporter"].ptr = video_exporter;
params["compression"].ptr = (void *) requested_compression;
// RTSP
params["rtsp_port"].i = rtsp_port;
params["audio_codec"].l = get_audio_codec(audio_codec);
params["audio_sammple_rate"].i = compressed_audio_sample_rate;
params["audio_bps"].i = 2;
// iHDTV
params["argc"].i = argc;
params["argv"].ptr = argv;
params["capture_device"].ptr = NULL;
params["display_device"].ptr = NULL;
if (rxtx_mode & MODE_SENDER)
params["capture_device"].ptr = uv->capture_device;
if (rxtx_mode & MODE_RECEIVER)
params["display_device"].ptr = uv->display_device;
//RTP
params["mtu"].i = requested_mtu;
params["receiver"].ptr = (void *) requested_receiver;
params["rx_port"].i = recv_port_number;
params["tx_port"].i = send_port_number;
params["use_ipv6"].b = ipv6;
params["mcast_if"].ptr = (void *) requested_mcast_if;
params["mtu"].i = requested_mtu;
params["fec"].ptr = (void *) requested_video_fec;
params["encryption"].ptr = (void *) requested_encryption;
params["packet_rate"].i = packet_rate;
// UltraGrid RTP
params["postprocess"].ptr = (void *) postprocess;
params["decoder_mode"].l = decoder_mode;
params["display_device"].ptr = uv->display_device;
// SAGE
params["sage_opts"].ptr = sage_opts;
if (video_protocol == IHDTV) {
uv->state_video_rxtx = new ihdtv_video_rxtx(params);
}else if (video_protocol == H264_STD) {
rtps_types_t avType;
if(strcmp("none", vidcap_params_get_driver(vidcap_params_head)) != 0 && (strcmp("none",audio_send) != 0)) avType = av; //AVStream
else if((strcmp("none",audio_send) != 0)) avType = audio; //AStream
else if(strcmp("none", vidcap_params_get_driver(vidcap_params_head))) avType = video; //VStream
else printf("[RTSP SERVER CHECK] no stream type... check capture devices input...\n");
params["avType"].l = avType;
uv->state_video_rxtx = new h264_rtp_video_rxtx(params);
uv->state_video_rxtx = new h264_rtp_video_rxtx(&root_mod, video_exporter,
requested_compression, requested_encryption,
requested_receiver, recv_port_number, send_port_number, audio_rx_port, audio_tx_port,
ipv6, requested_mcast_if, requested_video_fec, requested_mtu,
packet_rate, avType, get_audio_codec(audio_codec), compressed_audio_sample_rate, audio_capture_channels, 2 /*bps*/, rtsp_port);
} else if (video_protocol == ULTRAGRID_RTP) {
uv->state_video_rxtx = new ultragrid_rtp_video_rxtx(&root_mod, video_exporter,
requested_compression, requested_encryption,
requested_receiver, recv_port_number,
send_port_number, ipv6,
requested_mcast_if, requested_video_fec, requested_mtu,
packet_rate, decoder_mode, postprocess, uv->display_device);
uv->state_video_rxtx = new ultragrid_rtp_video_rxtx(params);
} else { // SAGE
uv->state_video_rxtx = new sage_video_rxtx(&root_mod, video_exporter,
requested_compression, requested_receiver, sage_opts);
uv->state_video_rxtx = new sage_video_rxtx(params);
}
if(rxtx_mode & MODE_RECEIVER) {

View File

@@ -73,22 +73,22 @@
using namespace std;
video_rxtx::video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression): m_paused(false), m_compression(NULL),
m_video_exporter(video_exporter) {
video_rxtx::video_rxtx(map<string, param_u> const &params): m_paused(false), m_compression(NULL),
m_video_exporter(static_cast<struct video_export *>(params.at("exporter").ptr)) {
module_init_default(&m_sender_mod);
m_sender_mod.cls = MODULE_CLASS_SENDER;
module_register(&m_sender_mod, parent);
module_register(&m_sender_mod, static_cast<struct module *>(params.at("parent").ptr));
module_init_default(&m_receiver_mod);
m_receiver_mod.cls = MODULE_CLASS_RECEIVER;
module_register(&m_receiver_mod, parent);
module_register(&m_receiver_mod, static_cast<struct module *>(params.at("parent").ptr));
m_compression = nullptr;
try {
int ret = compress_init(&m_sender_mod, requested_compression, &m_compression);
int ret = compress_init(&m_sender_mod, static_cast<const char *>(params.at("compression").ptr),
&m_compression);
if(ret != 0) {
if(ret < 0) {
throw string("Error initializing compression.");

View File

@@ -38,6 +38,9 @@
#ifndef VIDEO_RXTX_H_
#define VIDEO_RXTX_H_
#include <map>
#include <string>
#include "module.h"
struct display;
@@ -53,26 +56,23 @@ enum rxtx_protocol {
H264_STD
};
struct rx_tx {
enum rxtx_protocol protocol;
const char *name;
void (*send)(void *, struct video_frame *);
void (*done)(void *);
void *(*receiver_thread)(void *);
class video_rxtx;
union param_u {
void * ptr;
int i;
long l;
bool b;
};
extern struct rx_tx h264_rtp;
struct h264_rtp_state {
int connections_count;
struct rtp **network_devices;
struct tx *tx;
struct video_rxtx_info {
const char *name;
class video_rxtx *(*create)(std::map<std::string, param_u> const &params);
};
class video_rxtx {
public:
video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression);
video_rxtx(std::map<std::string, param_u> const &);
virtual ~video_rxtx();
void send(struct video_frame *);
static const char *get_name(enum rxtx_protocol);

View File

@@ -50,17 +50,16 @@
#include "video_rxtx/h264_rtp.h"
#include "video.h"
h264_rtp_video_rxtx::h264_rtp_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port, int a_rx_port, int a_tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec, int mtu,
long packet_rate, rtps_types_t avType, audio_codec_t audio_codec, int audio_sample_rate, int audio_channels, int audio_bps, int rtsp_port) :
rtp_video_rxtx(parent, video_exporter, requested_compression, requested_encryption,
receiver, rx_port, tx_port,
use_ipv6, mcast_if, requested_video_fec, mtu, packet_rate)
h264_rtp_video_rxtx::h264_rtp_video_rxtx(std::map<std::string, param_u> const &params) :
rtp_video_rxtx(params)
{
#ifdef HAVE_RTSP_SERVER
m_rtsp_server = init_rtsp_server(rtsp_port, parent, avType, audio_codec, audio_sample_rate, audio_channels, audio_bps, rx_port, a_rx_port);
m_rtsp_server = init_rtsp_server(params.at("rtsp_port").i,
static_cast<struct module *>(params.at("parent").ptr),
static_cast<rtps_types_t>(params.at("avType").l),
static_cast<audio_codec_t>(params.at("audio_codec").l),
params.at("audio_sample_rate").i, params.at("audio_channels").i,
params.at("audio_bps").i, params.at("rx_port").i, params.at("a_rx_port").i);
c_start_server(m_rtsp_server);
#endif
}

View File

@@ -48,11 +48,7 @@
class h264_rtp_video_rxtx : public rtp_video_rxtx {
public:
h264_rtp_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port, int a_rx_port, int a_tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec, int mtu,
long packet_rate, rtps_types_t avType, audio_codec_t audio_codec, int audio_sample_rate, int audio_channels, int audio_bps, int rtsp_port);
h264_rtp_video_rxtx(std::map<std::string, param_u> const &);
virtual ~h264_rtp_video_rxtx();
private:
virtual void send_frame(struct video_frame *);

View File

@@ -120,13 +120,12 @@ static void *ihdtv_sender_thread(void *arg)
}
#endif
ihdtv_video_rxtx::ihdtv_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression,
struct vidcap *capture_device, struct display *display_device,
int requested_mtu, int argc, char **argv) :
video_rxtx(parent, video_exporter, requested_compression)
ihdtv_video_rxtx::ihdtv_video_rxtx(map<string, param_u> const &params) :
video_rxtx(params)
{
#ifdef HAVE_IHDTV
int argc = params.at("argc").i;
char **argv = (char **) params.at("argv").ptr;
if ((argc != 0) && (argc != 1) && (argc != 2)) {
throw string("Wrong number of parameters");
}
@@ -134,29 +133,24 @@ ihdtv_video_rxtx::ihdtv_video_rxtx(struct module *parent, struct video_export *v
printf("Initializing ihdtv protocol\n");
// we cannot act as both together, because parameter parsing would have to be revamped
if (capture_device && display_device) {
if (params.at("capture_device").ptr && params.at("display_device").ptr) {
throw string
("Error: cannot act as both sender and receiver together in ihdtv mode");
}
m_display_device = display_device;
m_display_device = static_cast<struct display *>(params.at("display_device").ptr);
if (requested_mtu == 0) // mtu not specified on command line
{
requested_mtu = 8112; // not really a mtu, but a video-data payload per packet
}
if (display_device) {
if (m_display_device) {
if (ihdtv_init_rx_session
(&m_rx_connection, (argc == 0) ? NULL : argv[0],
(argc ==
0) ? NULL : ((argc == 1) ? argv[0] : argv[1]),
3000, 3001, requested_mtu) != 0) {
3000, 3001, params.at("mtu").i) != 0) {
throw string("Error initializing receiver session");
}
}
if (capture_device != 0) {
if (static_cast<struct display *>(params.at("capture_device").ptr) != 0) {
if (argc == 0) {
throw string("Error: specify the destination address");
}
@@ -164,19 +158,11 @@ ihdtv_video_rxtx::ihdtv_video_rxtx(struct module *parent, struct video_export *v
if (ihdtv_init_tx_session
(&m_tx_connection, argv[0],
(argc == 2) ? argv[1] : argv[0],
requested_mtu) != 0) {
params.at("mtu").i) != 0)
throw string("Error initializing sender session");
}
}
#else
UNUSED(parent);
UNUSED(video_exporter);
UNUSED(requested_compression);
UNUSED(capture_device);
UNUSED(display_device);
UNUSED(requested_mtu);
UNUSED(argc);
UNUSED(argv);
throw string("Support for iHDTV not compiled in");
#endif // HAVE_IHDTV
}

View File

@@ -67,10 +67,7 @@ struct display;
class ihdtv_video_rxtx: public video_rxtx {
public:
ihdtv_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression,
struct vidcap *capture_device, struct display *display_device,
int requested_mtu, int argc, char **argv);
ihdtv_video_rxtx(std::map<std::string, param_u> const &);
~ihdtv_video_rxtx();
private:
void send_frame(struct video_frame *);

View File

@@ -116,16 +116,10 @@ void rtp_video_rxtx::process_message(struct msg_sender *msg)
}
}
rtp_video_rxtx::rtp_video_rxtx(struct module *parent,
struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec,
int requested_mtu, long packet_rate) :
video_rxtx(parent, video_exporter, requested_compression),
m_fec_state(NULL)
rtp_video_rxtx::rtp_video_rxtx(map<string, param_u> const &params) :
video_rxtx(params), m_fec_state(NULL)
{
if(requested_mtu > RTP_MAX_MTU) {
if (params.at("mtu").i > RTP_MAX_MTU) {
ostringstream oss;
oss << "Requested MTU exceeds maximal value allowed by RTP library (" <<
RTP_MAX_PACKET_LEN << ").";
@@ -133,14 +127,14 @@ rtp_video_rxtx::rtp_video_rxtx(struct module *parent,
}
m_participants = pdb_init();
m_requested_receiver = receiver;
m_recv_port_number = rx_port;
m_send_port_number = tx_port;
m_ipv6 = use_ipv6;
m_requested_mcast_if = mcast_if;
m_requested_receiver = (const char *) params.at("receiver").ptr;
m_recv_port_number = params.at("rx_port").i;
m_send_port_number = params.at("tx_port").i;
m_ipv6 = params.at("use_ipv6").b;
m_requested_mcast_if = (const char *) params.at("mcast_if").ptr;
if ((m_network_devices = initialize_network(receiver, rx_port, tx_port,
m_participants, use_ipv6, mcast_if))
if ((m_network_devices = initialize_network(m_requested_receiver, m_recv_port_number, m_send_port_number,
m_participants, m_ipv6, m_requested_mcast_if))
== NULL) {
throw string("Unable to open network");
} else {
@@ -152,9 +146,10 @@ rtp_video_rxtx::rtp_video_rxtx(struct module *parent,
}
if ((m_tx = tx_init(&m_sender_mod,
requested_mtu, TX_MEDIA_VIDEO,
requested_video_fec,
requested_encryption, packet_rate)) == NULL) {
params.at("mtu").i, TX_MEDIA_VIDEO,
static_cast<const char *>(params.at("fec").ptr),
static_cast<const char *>(params.at("encryption").ptr),
params.at("packet_rate").i)) == NULL) {
throw string("Unable to initialize transmitter");
}

View File

@@ -56,11 +56,7 @@ struct fec;
class rtp_video_rxtx : public video_rxtx {
friend class video_rxtx;
public:
rtp_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec, int mtu,
long packet_rate);
rtp_video_rxtx(std::map<std::string, param_u> const &params);
virtual ~rtp_video_rxtx();
static struct rtp **initialize_network(const char *addrs, int recv_port_base,

View File

@@ -52,18 +52,16 @@
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_video_rxtx::sage_video_rxtx(map<string, param_u> const &params) :
video_rxtx(params)
{
ostringstream oss;
if (sage_opts) {
oss << sage_opts << ":";
if (params.at("sage_opts").ptr) {
oss << static_cast<const char *>(params.at("sage_opts").ptr) << ":";
}
oss << "fs=" << requested_receiver;
oss << "fs=" << static_cast<const char *>(params.at("receiver").ptr);
oss << ":tx"; // indicates that we are in tx mode
int ret = initialize_video_display("sage",
oss.str().c_str(), 0, &m_sage_tx_device);

View File

@@ -64,9 +64,7 @@ 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(std::map<std::string, param_u> const &);
~sage_video_rxtx();
private:
void send_frame(struct video_frame *);

View File

@@ -76,27 +76,22 @@
using namespace std;
ultragrid_rtp_video_rxtx::ultragrid_rtp_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec, int mtu,
long packet_rate, enum video_mode decoder_mode, const char *postprocess,
struct display *display_device) :
rtp_video_rxtx(parent, video_exporter, requested_compression, requested_encryption,
receiver, rx_port, tx_port,
use_ipv6, mcast_if, requested_video_fec, mtu, packet_rate)
ultragrid_rtp_video_rxtx::ultragrid_rtp_video_rxtx(const map<string, param_u> &params) :
rtp_video_rxtx(params)
{
if((postprocess && strstr(postprocess, "help") != NULL)) {
struct state_video_decoder *dec = video_decoder_init(NULL, VIDEO_NORMAL, postprocess, NULL, NULL);
if ((params.at("postprocess").ptr != NULL &&
strstr((const char *) params.at("postprocess").ptr, "help") != NULL)) {
struct state_video_decoder *dec = video_decoder_init(NULL, VIDEO_NORMAL,
(const char *) params.at("postprocess").ptr, NULL, NULL);
video_decoder_destroy(dec);
throw EXIT_SUCCESS;
}
gettimeofday(&m_start_time, NULL);
m_decoder_mode = decoder_mode;
m_postprocess = postprocess;
m_display_device = display_device;
m_requested_encryption = requested_encryption;
m_decoder_mode = (enum video_mode) params.at("decoder_mode").l;
m_postprocess = (const char *) params.at("postprocess").ptr;
m_display_device = (struct display *) params.at("display_device").ptr;
m_requested_encryption = (const char *) params.at("encryption").ptr;
m_async_sending = false;
}

View File

@@ -42,16 +42,13 @@
#include "video_rxtx/rtp.h"
#include <condition_variable>
#include <map>
#include <mutex>
#include <string>
class ultragrid_rtp_video_rxtx : public rtp_video_rxtx {
public:
ultragrid_rtp_video_rxtx(struct module *parent, struct video_export *video_exporter,
const char *requested_compression, const char *requested_encryption,
const char *receiver, int rx_port, int tx_port,
bool use_ipv6, const char *mcast_if, const char *requested_video_fec, int mtu,
long packet_rate, enum video_mode decoder_mode, const char *postprocess,
struct display *display_device);
ultragrid_rtp_video_rxtx(std::map<std::string, param_u> const &);
virtual ~ultragrid_rtp_video_rxtx();
virtual void join();
private: