61#include <Carbon/Carbon.h>
63#define MAX_DISPLAY_COUNT 10
64#define MOD_NAME "[screen cap mac] "
73 printf(
"Screen capture\n");
75 printf(
"\t-t screen[:fps=<fps>][:codec=<c>][:display=<d>]\n");
76 printf(
"\t\t<fps> - preferred grabbing fps (otherwise unlimited)\n");
77 printf(
"\t\t <c> - requested codec to capture (RGB /default/ or RGBA)\n");
78 printf(
"\t\t <d> - display ID or \"primary\" or \"secondary\"\n");
79 printf(
"\n\nAvailable displays:\n");
83 CGGetOnlineDisplayList(
sizeof screens /
sizeof screens[0], screens, &
count);
85 for (
unsigned int i = 0; i <
count; ++i) {
87 strcpy(
flags, CGDisplayIsMain(screens[i]) ?
"primary" :
"secondary");
88 if (CGDisplayIsBuiltin(screens[i])) {
91 printf(
"\tID %u) %s\n", screens[i],
flags);
109 CGImageRef image = CGDisplayCreateImage(s->
display);
129 snprintf((*available_cards)[0].
name,
sizeof (*available_cards)[0].
name,
"Screen capture");
131 int framerates[] = {24, 30, 60};
133 snprintf((*available_cards)[0].modes[0].
name,
sizeof (*available_cards)[0].
name,
135 snprintf((*available_cards)[0].modes[0].
id,
sizeof (*available_cards)[0].modes[0].
id,
138 for(
unsigned i = 0; i <
sizeof(framerates) /
sizeof(framerates[0]); i++){
139 snprintf((*available_cards)[0].modes[i + 1].
name,
sizeof (*available_cards)[0].
name,
140 "%d fps", framerates[i]);
141 snprintf((*available_cards)[0].modes[i + 1].
id,
sizeof (*available_cards)[0].modes[0].
id,
142 "{\"fps\":\"%d\"}", framerates[i]);
150 printf(
"vidcap_screen_init\n");
158 printf(
"Unable to allocate screen capture state\n");
164 gettimeofday(&s->
t0, NULL);
171 s->
display = CGMainDisplayID();
180 char *save_ptr = NULL;
182 while ((
item = strtok_r(
fmt,
":", &save_ptr)) != NULL) {
183 if (strncasecmp(
item,
"fps=", strlen(
"fps=")) == 0) {
185 }
else if (strncasecmp(
item,
"codec=", strlen(
"codec=")) == 0) {
187 }
else if (strncasecmp(
item,
"display=", strlen(
"display=")) == 0) {
190 if (strcasecmp(
display,
"secondary") == 0) {
193 CGGetOnlineDisplayList(
sizeof screens /
sizeof screens[0], screens, &
count);
195 for (; i <
count; ++i) {
196 if (!CGDisplayIsMain(screens[i])) {
206 }
if (strcasecmp(
display,
"primary") != 0) {
262 CGImageRef image = CGDisplayCreateImage(s->
display);
263 CFDataRef
data = CGDataProviderCopyData(CGImageGetDataProvider(image));
264 const unsigned char *
pixels = CFDataGetBytePtr(
data);
268 unsigned char *dst = (
unsigned char *)
tile->
data;
269 const unsigned char *src = (
const unsigned char *)
pixels;
270 for (
unsigned int y = 0; y <
tile->
height; ++y) {
271 s->
decode(dst, src, dst_linesize, 16, 8, 0);
279 struct timeval cur_time;
280 gettimeofday(&cur_time, NULL);
282 gettimeofday(&cur_time, NULL);
286 gettimeofday(&s->t, NULL);
289 float fps = s->
frames / seconds;
struct video_frame * frame
const char unsigned int flags
struct audio_frame ** audio
int void(** deleter)(void *))
int vc_get_linesize(unsigned int width, codec_t codec)
codec_t get_codec_from_name(const char *name)
This file contains definition of some common audio types.
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_INFO
normal reporting
#define LOG_LEVEL_ERROR
general errors
#define VIDCAP_INIT_NOERR
state not initialized, other action performed (typically help)
#define VIDCAP_INIT_OK
initialization successful
#define VIDCAP_NO_GENERIC_FPS_INDICATOR
#define VIDEO_CAPTURE_ABI_VERSION
#define VIDCAP_INIT_FAIL
error ocured
#define VIDCAP_INIT_AUDIO_NOT_SUPPORTED
card does not support audio
@ LIBRARY_CLASS_VIDEO_CAPTURE
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
decoder_func_t vc_copylineRGBA
decoder_func_t * decoder_t
decoder_func_t vc_copylineBGRAtoRGB
static void vidcap_screen_osx_probe(struct device_info **available_cards, int *count, void(**deleter)(void *))
static void vidcap_screen_osx_done(void *state)
static bool initialize(struct vidcap_screen_osx_state *s)
static int vidcap_screen_osx_init(struct vidcap_params *params, void **state)
static struct video_frame * vidcap_screen_osx_grab(void *state, struct audio_frame **audio)
static const struct video_capture_info vidcap_screen_osx_info
#define MAX_DISPLAY_COUNT
static void show_help(void)
struct used to comunicate with audio capture/playback device
This struct represents initialized video display state.
Struct tile is an area of video_frame.
char * data
Raw tile data. Pointer must be at least 4B aligned.
CGDirectDisplayID display
decoder_t decode
decoder, must accept BGRA (different shift)
enum interlacing_t interlacing
unsigned int width
width of every tile (!)
unsigned int height
height of every tile (!)
Struct video_frame represents a video frame and contains video description.
uint32_t tv_diff_usec(struct timeval curr_time, struct timeval prev_time)
double tv_diff(struct timeval curr_time, struct timeval prev_time)
@ PROGRESSIVE
progressive frame
@ RGB
RGB 8-bit (packed into 24-bit word)
@ RGBA
RGBA 8-bit, big-endian.
This is an umbrella header for video functions.
const char * vidcap_params_get_fmt(const struct vidcap_params *params)
unsigned int vidcap_params_get_flags(const struct vidcap_params *params)
#define VIDCAP_FLAG_AUDIO_ANY
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].
void video_frame_pool_destroy(void *state)
void * video_frame_pool_init(struct video_desc desc, int len)
struct video_frame * video_frame_pool_get_disposable_frame(void *state)