diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-10-16 02:08:40 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-10-16 04:15:09 +0200 |
commit | a7e0dbd83381377bd05a3fa988511d3713996370 (patch) | |
tree | 0e18f4c7b95aa4cf79d6646bca77ed5f03c65fb3 /src/capture/capture.c | |
parent | 93d46b976730bced7a70be1617a0171600167314 (diff) |
Refactor xcomposite into abstract capture api
Refactor c++ files into c files, more usable
Diffstat (limited to 'src/capture/capture.c')
-rw-r--r-- | src/capture/capture.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/capture/capture.c b/src/capture/capture.c index 9755d6a..699745a 100644 --- a/src/capture/capture.c +++ b/src/capture/capture.c @@ -1,17 +1,47 @@ #include "../../include/capture/capture.h" +#include <stdio.h> -int gsr_capture_start(gsr_capture *cap) { - return cap->start(cap); +int gsr_capture_start(gsr_capture *cap, AVCodecContext *video_codec_context) { + if(cap->started) + return -1; + + int res = cap->start(cap, video_codec_context); + if(res == 0) + cap->started = true; + + return res; } -void gsr_capture_stop(gsr_capture *cap) { - cap->stop(cap); +void gsr_capture_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) { + if(!cap->started) { + fprintf(stderr, "gsr error: gsp_capture_tick failed: the gsr capture has not been started\n"); + return; + } + + if(cap->tick) + cap->tick(cap, video_codec_context, frame); +} + +bool gsr_capture_should_stop(gsr_capture *cap, bool *err) { + if(!cap->started) { + fprintf(stderr, "gsr error: gsr_capture_should_stop failed: the gsr capture has not been started\n"); + return false; + } + + if(!cap->should_stop) + return false; + + return cap->should_stop(cap, err); } int gsr_capture_capture(gsr_capture *cap, AVFrame *frame) { + if(!cap->started) { + fprintf(stderr, "gsr error: gsr_capture_capture failed: the gsr capture has not been started\n"); + return -1; + } return cap->capture(cap, frame); } -void gsr_capture_destroy(gsr_capture *cap) { - cap->destroy(cap); +void gsr_capture_destroy(gsr_capture *cap, AVCodecContext *video_codec_context) { + cap->destroy(cap, video_codec_context); } |