NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
| /* | |
| * V4L2 video capture example | |
| * | |
| * This program can be used and distributed without restrictions. | |
| * | |
| * This program is provided with the V4L2 API | |
| * see http://linuxtv.org/docs.php for more information | |
| */ | |
| #include <stdio.h> |
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
| /* | |
| * use -lpthread when build. | |
| */ | |
| #include <semaphore.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <sys/mman.h> | |
| #include <sys/types.h> |
| // fileResponseWriter wraps an http.ResponseWriter and a File | |
| // passing it to an http.Handler's ServeHTTP | |
| // will write to both the file and the response. | |
| type fileResponseWriter struct { | |
| file io.Writer | |
| resp http.ResponseWriter | |
| multi io.Writer | |
| } |