use ff_thread_once
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | #include "config.h" |
| 22 | +#include "libavutil/thread.h" | |
| 22 | 23 | #include "avdevice.h" |
| 23 | 24 | |
| 24 | 25 | #define REGISTER_OUTDEV(X, x) \ |
| @@ -37,14 +38,8 @@ · 12 unmodified lines | ||
| 37 | 38 | |
| 38 | 39 | #define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x) |
| 39 | 40 | |
| 40 | −void avdevice_register_all(void) | |
| 41 | +static void register_all(void) | |
| 41 | 42 | { |
| 42 | − static int initialized; | |
| 43 | − | |
| 44 | − if (initialized) | |
| 45 | − return; | |
| 46 | − initialized = 1; | |
| 47 | − | |
| 48 | 43 | /* devices */ |
| 49 | 44 | REGISTER_INOUTDEV(ALSA, alsa); |
| 50 | 45 | REGISTER_INDEV (AVFOUNDATION, avfoundation); |
| @@ -76,3 +71,10 @@ void avdevice_register_all(void) · 25 unmodified lines | ||
| 76 | 71 | REGISTER_INDEV (LIBCDIO, libcdio); |
| 77 | 72 | REGISTER_INDEV (LIBDC1394, libdc1394); |
| 78 | 73 | } |
| 74 | + | |
| 75 | +void avdevice_register_all(void) | |
| 76 | +{ | |
| 77 | + AVOnce control = AV_ONCE_INIT; | |
| 78 | + | |
| 79 | + ff_thread_once(&control, register_all); | |
| 80 | +} | |
| @@ -67,7 +67,6 @@ const char *avdevice_license(void); · 66 unmodified lines | ||
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Initialize libavdevice and register all the input and output devices. |
| 70 | − * @warning This function is not thread safe. | |
| 71 | 70 | */ |
| 72 | 71 | void avdevice_register_all(void); |
| 73 | 72 | |