1 /*****************************************************************************
2 * lib.c : libv4l2 run-time
3 *****************************************************************************
4 * Copyright (C) 2012 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 #include <sys/ioctl.h>
30 #include <vlc_common.h>
34 static int fd_open (int fd
, int flags
)
40 static void *v4l2_handle
= NULL
;
42 static int (*v4l2_fd_open_cb
)(int, int) = fd_open
;
43 //int (*v4l2_open) (const char *, int, ...) = open;
44 //int (*v4l2_dup) (const char *, int, ...) = dup;
45 int (*v4l2_close
) (int) = close
;
46 int (*v4l2_ioctl
) (int, unsigned long int, ...) = ioctl
;
47 ssize_t (*v4l2_read
) (int, void *, size_t) = read
;
48 //ssize_t (*v4l2_write) (int, const void *, size_t) = write;
49 void * (*v4l2_mmap
) (void *, size_t, int, int, int, int64_t) = mmap
;
50 int (*v4l2_munmap
) (void *, size_t) = munmap
;
52 static void v4l2_lib_load (void)
56 h
= dlopen ("libmediaclient.so", RTLD_LAZY
| RTLD_LOCAL
| RTLD_NOLOAD
);
58 h
= dlopen ("libv4l2.so.0", RTLD_LAZY
| RTLD_LOCAL
);
62 void *sym
= dlsym(h
, "v4l2_fd_open");
64 v4l2_fd_open_cb
= sym
;
67 sym = dlsym (h, "v4l2_"#name); \
68 if (sym != NULL) v4l2_##name = sym
70 /*SYM(open); SYM(dup);*/ SYM(close
); SYM(ioctl
);
71 SYM(read
); /*SYM(write);*/ SYM(mmap
); SYM(munmap
);
76 __attribute__((destructor
))
77 static void v4l2_lib_unload (void)
79 if (v4l2_handle
!= NULL
)
80 dlclose (v4l2_handle
);
83 int v4l2_fd_open(int fd
, int flags
)
85 static pthread_once_t once
= PTHREAD_ONCE_INIT
;
87 pthread_once(&once
, v4l2_lib_load
);
88 return v4l2_fd_open_cb(fd
, flags
);