UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
aggregate.c File Reference

Aggregate video capture driver. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "debug.h"
#include "lib_common.h"
#include "tv.h"
#include "types.h"
#include "video_capture.h"
#include "video_capture_params.h"
#include "video_frame.h"
Include dependency graph for aggregate.c:

Go to the source code of this file.

Classes

struct  vidcap_aggregate_state
 

Functions

 REGISTER_MODULE (aggregate, &vidcap_aggregate_info, LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION)
 
static void show_help (void)
 
static void vidcap_aggregate_done (void *state)
 
static struct video_frame * vidcap_aggregate_grab (void *state, struct audio_frame **audio)
 
static int vidcap_aggregate_init (struct vidcap_params *params, void **state)
 
static void vidcap_aggregate_probe (struct device_info **cards, int *count, void(**deleter)(void *))
 

Variables

static const struct video_capture_info vidcap_aggregate_info
 

Detailed Description

Aggregate video capture driver.

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file aggregate.c.

Function Documentation

◆ REGISTER_MODULE()

REGISTER_MODULE ( aggregate ,
& vidcap_aggregate_info,
LIBRARY_CLASS_VIDEO_CAPTURE ,
VIDEO_CAPTURE_ABI_VERSION  )

◆ show_help()

static void show_help ( void )
static

Definition at line 60 of file aggregate.c.

61{
62 printf("Aggregate capture\n");
63 printf("Usage\n");
64 printf("\t-t aggregate -t <dev1_config> -t <dev2_config> ....]\n");
65 printf("\t\twhere devn_config is a complete configuration string of device involved in an aggregate device\n");
66
67}

Referenced by display_aggregate_init(), and vidcap_aggregate_init().

◆ vidcap_aggregate_done()

static void vidcap_aggregate_done ( void * state)
static

Definition at line 162 of file aggregate.c.

163{
165
166 assert(s != NULL);
167
168 if (s != NULL) {
169 int i;
170 for (i = 0; i < s->devices_cnt; ++i) {
171 vidcap_done(s->devices[i]);
172 }
173 }
174
175 vf_free(s->frame);
176 free(s);
177}
void ** state
void vf_free(struct video_frame *buf)
Frees video_frame structure.
void vidcap_done(struct vidcap *state)
Destroys vidap state.
struct video_frame * frame
Definition aggregate.c:74
struct vidcap ** devices
Definition aggregate.c:70

References vidcap_aggregate_state::devices, vidcap_aggregate_state::devices_cnt, vidcap_aggregate_state::frame, state, vf_free(), and vidcap_done().

Here is the call graph for this function:

◆ vidcap_aggregate_grab()

static struct video_frame * vidcap_aggregate_grab ( void * state,
struct audio_frame ** audio )
static

Definition at line 180 of file aggregate.c.

181{
183 struct audio_frame *audio_frame = NULL;
184 struct video_frame *frame = NULL;
185
186 for (int i = 0; i < s->devices_cnt; ++i) {
188 }
189
190 *audio = NULL;
191
192 for (int i = 0; i < s->devices_cnt; ++i) {
193 frame = NULL;
194 while(!frame) {
196 }
197 if (i == 0) {
200 s->frame->fps = frame->fps;
201 }
202 if (s->audio_source_index == -1 && audio_frame != NULL) {
203 fprintf(stderr, "[aggregate] Locking device #%d as an audio source.\n",
204 i);
205 s->audio_source_index = i;
206 }
207 if (s->audio_source_index == i) {
209 }
210 if (frame->color_spec != s->frame->color_spec ||
211 frame->fps != s->frame->fps ||
213 fprintf(stderr, "[aggregate] Different format detected: ");
214 if(frame->color_spec != s->frame->color_spec)
215 fprintf(stderr, "codec");
217 fprintf(stderr, "interlacing");
218 if(frame->fps != s->frame->fps)
219 fprintf(stderr, "FPS (%.2f and %.2f)", frame->fps, s->frame->fps);
220 fprintf(stderr, "\n");
221
222 return NULL;
223 }
228 s->captured_frames[i] = frame;
229 }
230 s->frames++;
231 gettimeofday(&s->t, NULL);
232 double seconds = tv_diff(s->t, s->t0);
233 if (seconds >= 5) {
234 float fps = s->frames / seconds;
235 log_msg(LOG_LEVEL_INFO, "[aggregate cap.] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps);
236 s->t0 = s->t;
237 s->frames = 0;
238 }
239
240 return s->frame;
241}
struct video_frame * frame
struct audio_frame ** audio
struct audio_frame audio_frame
struct used to comunicate with audio capture/playback device
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
struct video_frame * vidcap_grab(struct vidcap *state, struct audio_frame **audio)
Grabs video frame. This function may block for a short period if waiting for incoming frame....
struct used to comunicate with audio capture/playback device
Definition types.h:99
unsigned int width
Definition types.h:280
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
unsigned int height
Definition types.h:281
struct timeval t t0
Definition aggregate.c:76
struct video_frame ** captured_frames
Definition aggregate.c:73
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
enum interlacing_t interlacing
Definition types.h:307
double fps
Definition types.h:308
codec_t color_spec
Definition types.h:306
double tv_diff(struct timeval curr_time, struct timeval prev_time)
Definition tv.c:97
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76

References audio, vidcap_aggregate_state::audio_source_index, vidcap_aggregate_state::captured_frames, video_frame::color_spec, tile::data, tile::data_len, vidcap_aggregate_state::devices, vidcap_aggregate_state::devices_cnt, video_frame::fps, frame, vidcap_aggregate_state::frame, vidcap_aggregate_state::frames, tile::height, video_frame::interlacing, LOG_LEVEL_INFO, log_msg(), state, vidcap_aggregate_state::t0, tv_diff(), vf_get_tile(), vidcap_grab(), VIDEO_FRAME_DISPOSE, and tile::width.

Here is the call graph for this function:

◆ vidcap_aggregate_init()

static int vidcap_aggregate_init ( struct vidcap_params * params,
void ** state )
static

Definition at line 90 of file aggregate.c.

91{
92 struct vidcap_aggregate_state *s;
93
94 printf("vidcap_aggregate_init\n");
95
96
97 s = (struct vidcap_aggregate_state *) calloc(1, sizeof(struct vidcap_aggregate_state));
98 if(s == NULL) {
99 printf("Unable to allocate aggregate capture state\n");
100 return VIDCAP_INIT_FAIL;
101 }
102
103 s->audio_source_index = -1;
104 s->frames = 0;
105 gettimeofday(&s->t0, NULL);
106
107 if(vidcap_params_get_fmt(params) && strcmp(vidcap_params_get_fmt(params), "") != 0) {
108 show_help();
109 free(s);
110 return VIDCAP_INIT_NOERR;
111 }
112
113
114 s->devices_cnt = 0;
115 struct vidcap_params *tmp = params;
116 while((tmp = vidcap_params_get_next(tmp))) {
117 if (vidcap_params_get_driver(tmp) != NULL)
118 s->devices_cnt++;
119 else
120 break;
121 }
122
123 s->devices = calloc(s->devices_cnt, sizeof(struct vidcap *));
124 tmp = params;
125 for (int i = 0; i < s->devices_cnt; ++i) {
126 tmp = vidcap_params_get_next(tmp);
127
130 }
131
133 if(ret != 0) {
134 fprintf(stderr, "[aggregate] Unable to initialize device %d (%s:%s).\n",
137 goto error;
138 }
139 }
140
141 s->captured_frames = calloc(s->devices_cnt, sizeof(struct video_frame *));
142
143 s->frame = vf_alloc(s->devices_cnt);
144
145 *state = s;
146 return VIDCAP_INIT_OK;
147
148error:
149 if(s->devices) {
150 int i;
151 for (i = 0u; i < s->devices_cnt; ++i) {
152 if(s->devices[i]) {
153 vidcap_done(s->devices[i]);
154 }
155 }
156 }
157 free(s);
158 return VIDCAP_INIT_FAIL;
159}
struct video_frame * vf_alloc(int count)
Allocates blank video frame.
#define VIDCAP_INIT_NOERR
state not initialized, other action performed (typically help)
#define VIDCAP_INIT_OK
initialization successful
int initialize_video_capture(struct module *parent, struct vidcap_params *param, struct vidcap **state)
Initializes video capture.
#define VIDCAP_INIT_FAIL
error ocured
static struct @19 params[100]
This struct represents video capture state.
static void show_help(void)
Definition aggregate.c:60
struct module * vidcap_params_get_parent(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_get_next(const struct vidcap_params *curr)
const char * vidcap_params_get_driver(const struct vidcap_params *params)
void vidcap_params_set_flags(struct vidcap_params *params, unsigned int flags)
const char * vidcap_params_get_fmt(const struct vidcap_params *params)
unsigned int vidcap_params_get_flags(const struct vidcap_params *params)

References vidcap_aggregate_state::audio_source_index, vidcap_aggregate_state::captured_frames, vidcap_aggregate_state::devices, vidcap_aggregate_state::devices_cnt, vidcap_aggregate_state::frame, vidcap_aggregate_state::frames, initialize_video_capture(), params, show_help(), state, vidcap_aggregate_state::t0, vf_alloc(), vidcap_done(), VIDCAP_INIT_FAIL, VIDCAP_INIT_NOERR, VIDCAP_INIT_OK, vidcap_params_get_driver(), vidcap_params_get_flags(), vidcap_params_get_fmt(), vidcap_params_get_next(), vidcap_params_get_parent(), and vidcap_params_set_flags().

Here is the call graph for this function:

◆ vidcap_aggregate_probe()

static void vidcap_aggregate_probe ( struct device_info ** cards,
int * count,
void(** deleter )(void *) )
static

Definition at line 82 of file aggregate.c.

83{
84 *cards = NULL;
85 *count = 0;
86 *deleter = free;
87}
int void(** deleter)(void *))
int count
Definition hd-rum.c:44

References count, and deleter.

Variable Documentation

◆ vidcap_aggregate_info

const struct video_capture_info vidcap_aggregate_info
static
Initial value:
= {
}
#define VIDCAP_NO_GENERIC_FPS_INDICATOR
static void vidcap_aggregate_done(void *state)
Definition aggregate.c:162
static struct video_frame * vidcap_aggregate_grab(void *state, struct audio_frame **audio)
Definition aggregate.c:180
static void vidcap_aggregate_probe(struct device_info **cards, int *count, void(**deleter)(void *))
Definition aggregate.c:82
static int vidcap_aggregate_init(struct vidcap_params *params, void **state)
Definition aggregate.c:90

Definition at line 243 of file aggregate.c.