Video display: pass parent module pointer

This commit is contained in:
Martin Pulec
2014-11-03 17:03:04 +01:00
parent 4c68a1b137
commit 2bd86bddf6
32 changed files with 80 additions and 48 deletions

View File

@@ -390,6 +390,9 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message)
} else if(strcasecmp(message, "bye") == 0) {
ret = CONTROL_CLOSE_HANDLE;
resp = new_response(RESPONSE_OK, NULL);
} else if(strcmp(message, "dump-tree") == 0) {
dump_tree(s->root_module, 0);
resp = new_response(RESPONSE_OK, NULL);
} else { // assume message in format "path message"
struct msg_universal *msg = (struct msg_universal *)
new_message(sizeof(struct msg_universal));

View File

@@ -178,7 +178,7 @@ void *hd_rum_decompress_init(struct module *parent)
char cfg[128] = "";
snprintf(cfg, sizeof cfg, "pipe:%p", s);
assert (initialize_video_display("proxy", cfg, 0, &s->display) == 0);
assert (initialize_video_display(parent, "proxy", cfg, 0, &s->display) == 0);
map<string, param_u> params;

View File

@@ -889,7 +889,7 @@ int main(int argc, char *argv[])
// Display initialization should be prior to modules that may use graphic card (eg. GLSL) in order
// to initalize shared resource (X display) first
ret =
initialize_video_display(requested_display, display_cfg, display_flags, &uv->display_device);
initialize_video_display(&root_mod, requested_display, display_cfg, display_flags, &uv->display_device);
if (ret < 0) {
printf("Unable to open display device: %s\n",
requested_display);

View File

@@ -127,7 +127,7 @@ void module_done(struct module *module_data)
simple_linked_list_destroy(tmp.msg_queue_childs);
}
const char *module_class_name_pairs[] = {
static const char *module_class_name_pairs[] = {
[MODULE_CLASS_ROOT] = "root",
[MODULE_CLASS_PORT] = "port",
[MODULE_CLASS_COMPRESS] = "compress",
@@ -139,6 +139,7 @@ const char *module_class_name_pairs[] = {
[MODULE_CLASS_CONTROL] = "control",
[MODULE_CLASS_CAPTURE] = "capture",
[MODULE_CLASS_FILTER] = "filter",
[MODULE_CLASS_DISPLAY] = "display",
};
const char *module_class_name(enum module_class cls)
@@ -185,7 +186,9 @@ static struct module *find_child(struct module *node, const char *node_name, int
{
for(void *it = simple_linked_list_it_init(node->childs); it != NULL; ) {
struct module *child = (struct module *) simple_linked_list_it_next(&it);
if(strcasecmp(module_class_name(child->cls), node_name) == 0) {
const char *child_name = module_class_name(child->cls);
assert(child_name != NULL);
if(strcasecmp(child_name, node_name) == 0) {
if(index-- == 0) {
return child;
}

View File

@@ -74,6 +74,7 @@ enum module_class {
MODULE_CLASS_CONTROL,
MODULE_CLASS_CAPTURE,
MODULE_CLASS_FILTER,
MODULE_CLASS_DISPLAY,
};
struct module;

View File

@@ -57,6 +57,7 @@
#include "config_unix.h"
#include "config_win32.h"
#include "debug.h"
#include "module.h"
#include "perf.h"
#include "video_display.h"
@@ -78,8 +79,11 @@
#define DISPLAY_MAGIC 0x01ba7ef1
static int display_init(struct module *parent, display_id_t id, const char *fmt, unsigned int flags, struct display **state);
/// @brief This struct represents initialized video display state.
struct display {
struct module mod;
uint32_t magic; ///< state of the created video capture driver
int index; ///< index to @ref display_device_table
void *state; ///< For debugging. Conatins @ref DISPLAY_MAGIC
@@ -98,7 +102,7 @@ typedef struct {
const char *library_name; ///< @copydoc decoder_table_t::library_name
display_type_t *(*func_probe) (void);
const char *func_probe_str;
void *(*func_init) (const char *fmt, unsigned int flags);
void *(*func_init) (struct module *parent, const char *fmt, unsigned int flags);
const char *func_init_str;
void (*func_run) (void *state);
const char *func_run_str;
@@ -354,8 +358,7 @@ static int display_fill_symbols(display_table_t *device)
device->func_probe = (display_type_t *(*) (void))
dlsym(handle, device->func_probe_str);
device->func_init = (void *(*) (const char *, unsigned int))
dlsym(handle, device->func_init_str);
device->func_init = dlsym(handle, device->func_init_str);
device->func_run = (void (*) (void *))
dlsym(handle, device->func_run_str);
device->func_done = (void (*) (void *))
@@ -403,9 +406,8 @@ void list_video_display_devices()
display_free_devices();
}
int initialize_video_display(const char *requested_display,
const char *fmt, unsigned int flags,
struct display **out)
int initialize_video_display(struct module *parent, const char *requested_display,
const char *fmt, unsigned int flags, struct display **out)
{
display_type_t *dt;
display_id_t id = 0;
@@ -439,7 +441,7 @@ int initialize_video_display(const char *requested_display,
}
display_free_devices();
return display_init(id, fmt, flags, out);
return display_init(parent, id, fmt, flags, out);
}
/**
@@ -526,24 +528,34 @@ display_id_t display_get_null_device_id(void)
* @retval -1 if failed
* @retval 1 if successfully shown help (no state returned)
*/
int display_init(display_id_t id, const char *fmt, unsigned int flags, struct display **state)
static int display_init(struct module *parent, display_id_t id, const char *fmt,
unsigned int flags, struct display **state)
{
unsigned int i;
for (i = 0; i < DISPLAY_DEVICE_TABLE_SIZE; i++) {
if (display_device_table[i].id == id) {
struct display *d =
(struct display *)malloc(sizeof(struct display));
(struct display *) calloc(1, sizeof(struct display));
d->magic = DISPLAY_MAGIC;
d->state = display_device_table[i].func_init(fmt, flags);
module_init_default(&d->mod);
d->mod.cls = MODULE_CLASS_DISPLAY;
module_register(&d->mod, parent);
d->state = display_device_table[i].func_init(&d->mod, fmt, flags);
d->index = i;
if (d->state == NULL) {
debug_msg("Unable to start display 0x%08lx\n",
id);
free(d);
module_done(&d->mod);
return -1;
} else if (d->state == &display_init_noerr) {
free(d);
module_done(&d->mod);
return 1;
}
*state = d;
@@ -562,6 +574,7 @@ void display_done(struct display *d)
{
assert(d->magic == DISPLAY_MAGIC);
display_device_table[d->index].func_done(d->state);
module_done(&d->mod);
free(d);
}

View File

@@ -76,6 +76,7 @@ extern "C" {
/** @} */
struct audio_frame;
struct module;
/*
* Interface to probing the valid display types.
@@ -120,14 +121,14 @@ display_id_t display_get_null_device_id(void);
*
*/
struct display;
struct module;
extern int display_init_noerr;
void list_video_display_devices(void);
int initialize_video_display(const char *requested_display,
const char *fmt, unsigned int flags,
int initialize_video_display(struct module *parent,
const char *requested_display, const char *fmt, unsigned int flags,
struct display **out);
int display_init(display_id_t id, const char *fmt, unsigned int flags, struct display **state);
void display_run(struct display *d);
void display_done(struct display *d);
struct video_frame *display_get_frame(struct display *d);

View File

@@ -99,8 +99,9 @@ void display_aggregate_run(void *state)
}
}
void *display_aggregate_init(const char *fmt, unsigned int flags)
void *display_aggregate_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct display_aggregate_state *s;
char *save_ptr = NULL;
char *item;
@@ -108,7 +109,6 @@ void *display_aggregate_init(const char *fmt, unsigned int flags)
char *tmp;
int i;
if(!fmt || strcmp(fmt, "help") == 0) {
show_help();
return &display_init_noerr;
@@ -146,7 +146,7 @@ void *display_aggregate_init(const char *fmt, unsigned int flags)
}
int ret = initialize_video_display(device,
device_cfg, dev_flags, &s->devices[i]);
device_cfg, dev_flags, &s->devices[i], parent);
if(ret != 0) {
fprintf(stderr, "[aggregate] Unable to initialize device %d (%s:%s).\n", i, device, device_cfg);
free(config);

View File

@@ -48,11 +48,12 @@
#define DISPLAY_AGGREGATE_ID 0xbbcaa321
struct audio_frame;
struct module;
struct video_desc;
struct video_frame;
display_type_t *display_aggregate_probe(void);
void *display_aggregate_init(const char *fmt, unsigned int flags);
void *display_aggregate_init(struct module *parent, const char *fmt, unsigned int flags);
void display_aggregate_run(void *state);
void display_aggregate_done(void *state);
struct video_frame *display_aggregate_getf(void *state);

View File

@@ -837,10 +837,10 @@ static void show_help(void)
}
}
void *display_bluefish444_init(const char *fmt, unsigned int flags)
void *display_bluefish444_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
int deviceId = 1;
if(fmt){
if(strcmp(fmt, "help") == 0) {
show_help();

View File

@@ -43,6 +43,7 @@
#define DISPLAY_BLUEFISH444_ID 0x52f45430
struct audio_frame;
struct module;
struct video_desc;
struct video_frame;
@@ -51,7 +52,7 @@ extern "C" {
#endif
display_type_t *display_bluefish444_probe(void);
void *display_bluefish444_init(const char *fmt, unsigned int flags);
void *display_bluefish444_init(struct module *parent, const char *fmt, unsigned int flags);
void display_bluefish444_run(void *state);
void display_bluefish444_done(void *state);
struct video_frame *display_bluefish444_getf(void *state);

View File

@@ -691,8 +691,9 @@ static int blackmagic_api_version_check(STRING *current_version)
}
void *display_decklink_init(const char *fmt, unsigned int flags)
void *display_decklink_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct state_decklink *s;
IDeckLinkIterator* deckLinkIterator;
HRESULT result;
@@ -704,7 +705,6 @@ void *display_decklink_init(const char *fmt, unsigned int flags)
BMDVideo3DPackingFormat HDMI3DPacking = (BMDVideo3DPackingFormat) 0;
int audio_consumer_levels = -1;
#ifdef WIN32
// Initialize COM on this thread
result = CoInitialize(NULL);

View File

@@ -50,7 +50,7 @@ extern "C" {
#endif
display_type_t *display_decklink_probe(void);
void *display_decklink_init(const char *fmt, unsigned int flags);
void *display_decklink_init(struct module *parent, const char *fmt, unsigned int flags);
void display_decklink_run(void *state);
void display_decklink_done(void *state);
struct video_frame *display_decklink_getf(void *state);

View File

@@ -334,12 +334,13 @@ error:
}
void *display_deltacast_init(const char *fmt, unsigned int flags)
void *display_deltacast_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct state_deltacast *s;
ULONG Result,DllVersion,NbBoards,ChnType;
ULONG BrdId = 0;
s = (struct state_deltacast *)calloc(1, sizeof(struct state_deltacast));
s->magic = DELTACAST_MAGIC;

View File

@@ -64,7 +64,7 @@ extern const struct deltacast_frame_mode_t deltacast_frame_modes[];
extern const int deltacast_frame_modes_count;
display_type_t *display_deltacast_probe(void);
void *display_deltacast_init(const char *fmt, unsigned int flags);
void *display_deltacast_init(struct module *parent, const char *fmt, unsigned int flags);
void display_deltacast_run(void *state);
void display_deltacast_done(void *state);
struct video_frame *display_deltacast_getf(void *state);

View File

@@ -649,8 +649,9 @@ int display_dvs_reconfigure(void *state,
}
void *display_dvs_init(const char *cfg, unsigned int flags)
void *display_dvs_init(struct module *parent, const char *cfg, unsigned int flags)
{
UNUSED(parent);
struct state_hdsp *s;
int i;
char *name = strdup("");

View File

@@ -58,7 +58,7 @@ extern const hdsp_mode_table_t hdsp_mode_table[];
display_type_t *display_dvs_probe(void);
void *display_dvs_init(const char *fmt, unsigned int flags);
void *display_dvs_init(struct module *parent, const char *fmt, unsigned int flags);
void display_dvs_run(void *state);
void display_dvs_done(void *state);
struct video_frame *display_dvs_getf(void *state);

View File

@@ -279,8 +279,9 @@ static void gl_load_splashscreen(struct state_gl *s)
display_gl_putf(s, frame, PUTF_BLOCKING);
}
void * display_gl_init(const char *fmt, unsigned int flags) {
void * display_gl_init(struct module *parent, const char *fmt, unsigned int flags) {
UNUSED(flags);
UNUSED(parent);
struct state_gl *s = new state_gl;
/* GLUT callbacks take only some arguments so we need static variable */

View File

@@ -57,7 +57,7 @@ extern "C" {
#endif
display_type_t *display_gl_probe(void);
void *display_gl_init(const char *fmt, unsigned int flags);
void *display_gl_init(struct module *parent, const char *fmt, unsigned int flags);
void display_gl_run(void *state);
void display_gl_done(void *state);
struct video_frame *display_gl_getf(void *state);

View File

@@ -57,10 +57,11 @@ struct state_null {
uint32_t magic;
};
void *display_null_init(const char *fmt, unsigned int flags)
void *display_null_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(fmt);
UNUSED(flags);
UNUSED(parent);
struct state_null *s;
s = (struct state_null *)calloc(1, sizeof(struct state_null));

View File

@@ -50,7 +50,7 @@ struct video_desc;
struct video_frame;
display_type_t *display_null_probe(void);
void *display_null_init(const char *fmt, unsigned int flags);
void *display_null_init(struct module *parent, const char *fmt, unsigned int flags);
void display_null_run(void *state);
void display_null_done(void *state);
struct video_frame *display_null_getf(void *state);

View File

@@ -52,9 +52,10 @@ struct state_pipe {
struct video_desc desc;
};
void *display_pipe_init(const char *fmt, unsigned int flags)
void *display_pipe_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(flags);
UNUSED(parent);
frame_recv_delegate *delegate;
if (!fmt || strlen(fmt) == 0 || strcmp(fmt, "help") == 0) {

View File

@@ -46,7 +46,7 @@ extern "C" {
#endif
display_type_t *display_pipe_probe(void);
void *display_pipe_init(const char *fmt, unsigned int flags);
void *display_pipe_init(struct module *parent, const char *fmt, unsigned int flags);
void display_pipe_run(void *state);
void display_pipe_done(void *state);
struct video_frame *display_pipe_getf(void *state);

View File

@@ -79,8 +79,9 @@ struct state_proxy {
condition_variable cv;
};
void *display_proxy_init(const char *fmt, unsigned int flags)
void *display_proxy_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct state_proxy *s;
char *fmt_copy = NULL;
const char *requested_display = "gl";
@@ -97,7 +98,7 @@ void *display_proxy_init(const char *fmt, unsigned int flags)
cfg = delim + 1;
}
}
assert (initialize_video_display(requested_display, cfg, flags, &s->real_display) == 0);
assert (initialize_video_display(parent, requested_display, cfg, flags, &s->real_display) == 0);
free(fmt_copy);
pthread_create(&s->thread_id, NULL, (void *(*)(void *)) display_run,

View File

@@ -46,7 +46,7 @@ extern "C" {
#endif
display_type_t *display_proxy_probe(void);
void *display_proxy_init(const char *fmt, unsigned int flags);
void *display_proxy_init(struct module *parent, const char *fmt, unsigned int flags);
void display_proxy_run(void *state);
void display_proxy_done(void *state);
struct video_frame *display_proxy_getf(void *state);

View File

@@ -597,8 +597,9 @@ static void show_help(int full)
print_modes(full);
}
void *display_quicktime_init(const char *fmt, unsigned int flags)
void *display_quicktime_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct state_quicktime *s;
int ret;
int i;

View File

@@ -64,7 +64,7 @@ typedef struct {
extern const quicktime_mode_t quicktime_modes[];
display_type_t *display_quicktime_probe(void);
void *display_quicktime_init(const char *fmt, unsigned int flags);
void *display_quicktime_init(struct module *parent, const char *fmt, unsigned int flags);
void display_quicktime_run(void *state);
void display_quicktime_done(void *state);
struct video_frame *display_quicktime_getf(void *state);

View File

@@ -166,10 +166,11 @@ void display_sage_run(void *arg)
}
}
void *display_sage_init(const char *fmt, unsigned int flags)
void *display_sage_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(fmt);
UNUSED(flags);
UNUSED(parent);
struct state_sage *s;
s = (struct state_sage *) calloc(1, sizeof(struct state_sage));

View File

@@ -57,7 +57,7 @@ struct video_desc;
struct video_frame;
display_type_t *display_sage_probe(void);
void *display_sage_init(const char *fmt, unsigned int flags);
void *display_sage_init(struct module *parent, const char *fmt, unsigned int flags);
void display_sage_run(void *state);
void display_sage_done(void *state);
struct video_frame *display_sage_getf(void *state);

View File

@@ -420,8 +420,9 @@ static int display_sdl_reconfigure_real(void *state, struct video_desc desc)
return TRUE;
}
void *display_sdl_init(const char *fmt, unsigned int flags)
void *display_sdl_init(struct module *parent, const char *fmt, unsigned int flags)
{
UNUSED(parent);
struct state_sdl *s = new state_sdl;
int ret;
const SDL_VideoInfo *video_info;

View File

@@ -57,7 +57,7 @@ extern "C" {
#endif
display_type_t * display_sdl_probe (void);
void * display_sdl_init (const char *fmt, unsigned int flags);
void * display_sdl_init (struct module *parent, const char *fmt, unsigned int flags);
void display_sdl_run (void *state);
void display_sdl_done (void *state);
struct video_frame * display_sdl_getf (void *state);

View File

@@ -63,7 +63,7 @@ sage_video_rxtx::sage_video_rxtx(map<string, param_u> const &params) :
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",
int ret = initialize_video_display(&m_sender_mod, "sage",
oss.str().c_str(), 0, &m_sage_tx_device);
if(ret != 0) {
throw string("Unable to initialize SAGE TX.");