Skip to content

Commit 3bfe198

Browse files
committed
vcap/v4l2: updates
- use generic FPS indicator - decrease verbosity of some messages
1 parent 54cff74 commit 3bfe198

1 file changed

Lines changed: 9 additions & 29 deletions

File tree

src/video_capture/v4l2.c

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@
5454
#include <errno.h>
5555
#include <fcntl.h>
5656
#include <inttypes.h>
57+
#include <linux/videodev2.h> // for v4l2_format
5758
#include <pthread.h>
58-
#include <stdbool.h> // for bool, false, true
5959
#include <stdio.h>
6060
#include <stdlib.h>
6161
#include <string.h>
6262
#include <sys/ioctl.h>
6363
#include <sys/mman.h>
64-
#include <sys/time.h> // for gettimeofday, timeval
6564
#include <unistd.h>
6665

6766
enum {
@@ -70,9 +69,9 @@ enum {
7069
};
7170
#define MOD_NAME "[V4L cap.] "
7271

72+
#include "compat/c23.h" // IWYU pragma: keep
7373
#include "debug.h"
7474
#include "lib_common.h"
75-
#include "tv.h"
7675
#include "types.h" // for device_info, video_desc, tile, vid...
7776
#include "utils/color_out.h"
7877
#include "utils/list.h"
@@ -104,9 +103,6 @@ struct vidcap_v4l2_state {
104103
struct v4l2_format src_fmt; ///< captured format
105104
struct v4l2_format dst_fmt; ///< converted format if v4lconvert is used
106105

107-
struct timeval t0;
108-
int frames;
109-
110106
int buffer_count;
111107

112108
struct simple_linked_list *buffers_to_enqueue;
@@ -591,7 +587,7 @@ static int vidcap_v4l2_init(const struct vidcap_params *params, void **state)
591587
{
592588
struct parsed_opts opts = { .buffer_count = DEFAULT_BUF_COUNT };
593589

594-
printf("vidcap_v4l2_init\n");
590+
MSG(VERBOSE, "vidcap_v4l2_init\n");
595591

596592
if (vidcap_params_get_flags(params) & VIDCAP_FLAG_AUDIO_ANY) {
597593
return VIDCAP_INIT_AUDIO_NOT_SUPPORTED;
@@ -777,10 +773,7 @@ static int vidcap_v4l2_init(const struct vidcap_params *params, void **state)
777773
goto error;
778774
};
779775

780-
gettimeofday(&s->t0, NULL);
781-
s->frames = 0;
782-
783-
MSG(NOTICE, "Capturing %dx%d @%.2f%s %s from %s\n", s->desc.width,
776+
MSG(INFO, "Capturing %dx%d @%.2f%s %s from %s\n", s->desc.width,
784777
s->desc.height, s->desc.fps,
785778
get_interlacing_suffix(s->desc.interlacing),
786779
get_codec_name(s->desc.color_spec), opts.dev_name);
@@ -890,28 +883,15 @@ static struct video_frame * vidcap_v4l2_grab(void *state, struct audio_frame **a
890883
out->callbacks.dispose_udata = frame_data;
891884
}
892885

893-
s->frames++;
894-
895-
struct timeval t;
896-
gettimeofday(&t, NULL);
897-
double seconds = tv_diff(t, s->t0);
898-
if (seconds >= 5) {
899-
float fps = s->frames / seconds;
900-
log_msg(LOG_LEVEL_INFO, "[V4L2 capture] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps);
901-
s->t0 = t;
902-
s->frames = 0;
903-
}
904-
905-
906886
return out;
907887
}
908888

909889
static const struct video_capture_info vidcap_v4l2_info = {
910-
vidcap_v4l2_probe,
911-
vidcap_v4l2_init,
912-
vidcap_v4l2_done,
913-
vidcap_v4l2_grab,
914-
VIDCAP_NO_GENERIC_FPS_INDICATOR,
890+
.probe = vidcap_v4l2_probe,
891+
.init = vidcap_v4l2_init,
892+
.done = vidcap_v4l2_done,
893+
.grab = vidcap_v4l2_grab,
894+
.generic_fps_indicator_prefix = MOD_NAME,
915895
};
916896

917897
REGISTER_MODULE(v4l2, &vidcap_v4l2_info, LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION);

0 commit comments

Comments
 (0)