#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <signal.h>
#include <unistd.h>
#include <assert.h>
#include <time.h>
#include <err.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <GL/glx.h>
#include <EGL/egl.h>
#include <alsa/asoundlib.h>
XXX
#define NUM_PBOS 2
static uint32_t FPS = 60;
static bool DROP_FRAMES = true;
static double SPEED_HACK = 1.0;
static bool FLIP_VIDEO = true;
static const char *FIFO_PATH = "/tmp/glcapture.fifo";
enum stream {
STREAM_VIDEO,
STREAM_AUDIO,
STREAM_LAST,
};
static const bool ENABLED_STREAMS[STREAM_LAST] = {
true,
true,
};
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define WARN(x, ...) do { warn("glcapture: "x, ##__VA_ARGS__); } while (0)
#define WARNX(x, ...) do { warnx("glcapture: "x, ##__VA_ARGS__); } while (0)
#define ERRX(x, y, ...) do { errx(x, "glcapture: "y, ##__VA_ARGS__); } while (0)
#define ERR(x, y, ...) do { err(x, "glcapture: "y, ##__VA_ARGS__); } while (0)
#define WARN_ONCE(x, ...) do { static bool o = false; if (!o) { WARNX(x, ##__VA_ARGS__); o = true; } } while (0)
static void swap_buffers(void);
static void alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, const char *caller);
static uint64_t get_fake_time_ns(void);
static __thread GLint LAST_FRAMEBUFFER_BLIT[8];
#include "hooks.h"
#include "glwrangle.h"
struct pbo {
uint64_t ts;
uint32_t width, height;
GLuint obj;
bool written;
};
struct gl {
struct pbo pbo[NUM_PBOS];
uint8_t active;
};
struct frame_info {
union {
struct {
uint32_t width, height, fps;
} video;
struct {
uint32_t rate;
uint8_t channels;
} audio;
};
const char *format;
uint64_t ts;
enum stream stream;
};
struct fifo {
struct {
struct frame_info info;
} stream[STREAM_LAST];
uint64_t base;
|