summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c55
1 files changed, 4 insertions, 51 deletions
diff --git a/main.c b/main.c
index 7c0e5b5..ad3d1f0 100644
--- a/main.c
+++ b/main.c
@@ -22,11 +22,13 @@
*/
#define _GNU_SOURCE
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <png.h>
-#include <SDL.h>
#include "options.h"
#include "device.h"
+#include "live.h"
#include "utils.h"
void
@@ -73,55 +75,6 @@ run(struct device *device, struct options *options)
}
}
-void
-run_video(struct device *device, struct options *options)
-{
- if (SDL_Init(SDL_INIT_VIDEO))
- utils_fatal("unable to initialize SDL: %s", SDL_GetError());
- atexit(SDL_Quit);
- SDL_DisableScreenSaver();
- SDL_Window *window;
- SDL_Renderer *renderer;
- if (SDL_CreateWindowAndRenderer(options->width, options->height,
- SDL_WINDOW_RESIZABLE, &window, &renderer))
- utils_fatal("unable to create window: %s", SDL_GetError());
- SDL_SetWindowTitle(window, "Moticam");
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
- if (SDL_RenderSetLogicalSize(renderer, options->width, options->height))
- utils_fatal("can not set logical size: %s", SDL_GetError());
- SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA32,
- SDL_TEXTUREACCESS_STREAMING, options->width, options->height);
- if (!texture)
- utils_fatal("can not create texture: %s", SDL_GetError());
- bool exit = false;
- while (1) {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- if (event.type == SDL_QUIT)
- exit = true;
- if (event.type == SDL_KEYDOWN
- && (event.key.keysym.sym == SDLK_q
- || event.key.keysym.sym == SDLK_ESCAPE))
- exit = true;
- }
- if (exit)
- break;
- const uint32_t *pixels = device_read(device);
- if (pixels)
- {
- SDL_UpdateTexture(texture, NULL, pixels, options->width * 4);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
- SDL_RenderClear(renderer);
- SDL_RenderCopyEx(renderer, texture, NULL, NULL, 180.0, NULL,
- SDL_FLIP_NONE);
- SDL_RenderPresent(renderer);
- }
- }
- SDL_DestroyTexture(texture);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
-}
-
int
main(int argc, char **argv)
{
@@ -137,7 +90,7 @@ main(int argc, char **argv)
if (options.count)
run(device, &options);
else
- run_video(device, &options);
+ live_run(device, &options);
device_close(device);
libusb_exit(usb);
return EXIT_SUCCESS;