示例#1
0
static int
hook_d9(const char *hook_type, const char *hook_method) {
	HMODULE hMod;
	// GetCreateDeviceAddress
	//ga_error("Start to hook Direct3DCreate9 ...");
	//
	if((hMod = GetModuleHandle("d3d9.dll")) == NULL) {
		if((hMod = LoadLibrary("d3d9.dll")) == NULL) {
			ga_error("Load d3d9.dll failed.\n");
			return -1;
		}
	}
	// Direct3DCreate9()
	pD3d = (TDirect3DCreate9)
		GetProcAddress(hMod, "Direct3DCreate9");
	if(pD3d == NULL) {
		ga_error("GetProcAddress(Direct3DCreate9) failed.\n");
		return -1;
	}
	//
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourAttach(&(PVOID&)pD3d, hook_d3d);
	DetourTransactionCommit();
	//
	return 0;
}
示例#2
0
static int
vencoder_start(void *arg) {
	int iid;
	char *pipefmt = (char*) arg;
#define	MAXPARAMLEN	64
	static char pipename[VIDEO_SOURCE_CHANNEL_MAX][MAXPARAMLEN];
#ifdef SAVEFILE
	if(fout == NULL) {
		fout = fopen(SAVEFILE, "wb");
	}
#endif
	if(vencoder_started != 0)
		return 0;
	vencoder_started = 1;
	for(iid = 0; iid < video_source_channels(); iid++) {
		snprintf(pipename[iid], MAXPARAMLEN, pipefmt, iid);
		if(pthread_create(&vencoder_tid[iid], NULL, vencoder_threadproc, pipename[iid]) != 0) {
			vencoder_started = 0;
			ga_error("video encoder: create thread failed.\n");
			return -1;
		}
	}
	ga_error("video encdoer: all started (%d)\n", iid);
	return 0;
}
示例#3
0
LRESULT CALLBACK
hook_proc(int nCode, WPARAM wParam, LPARAM lParam) {
	char hook_type[64];
	pthread_t ga_server_thread;

	if(module_checked || app_hooked)
		return CallNextHookEx(gHook, nCode, wParam, lParam);

	if(hook_app() < 0)
		return CallNextHookEx(gHook, nCode, wParam, lParam);
	
	// identified the executable: initialize once

	if(do_hook(hook_type, sizeof(hook_type)) < 0) {
		ga_error("hook_proc: hook failed.\n");
		return CallNextHookEx(gHook, nCode, wParam, lParam);
	}
	
	// SDL: override controller
	if(strcasecmp(hook_type, "sdl") == 0) {
		sdl12_mapinit();
		ctrl_server_setreplay(sdl_hook_replay_callback);
		no_default_controller = 1;
		ga_error("hook_proc: sdl - use native replayer.\n");
	}
	// start hook server
	if(pthread_create(&ga_server_thread, NULL, ga_server, NULL) != 0) {
		ga_error("cannot create GA server thread\n");
		return CallNextHookEx(gHook, nCode, wParam, lParam);
	}
	pthread_detach(ga_server_thread);
	
	return CallNextHookEx(gHook, nCode, wParam, lParam);
}
示例#4
0
int
hook_app() {
	char *appexe;
	char module_name[1024];
	int pid = GetCurrentProcessId();

	module_checked = 1;

	if(GetModuleFileName(NULL, module_name, sizeof(module_name)) == 0) {
		ga_error("GetModuleFileName failed: %s\n", GetLastError());
		return -1;
	}

	if((appexe = getenv("GA_APPEXE")) == NULL) {
		ga_error("[%d] No GA_APPEXE provided.\n", pid);
		return -1;
	}

	if(strstr(module_name, appexe) == NULL) {
		ga_error("will not hook: %s\n", module_name);
		return -1;
	}

	app_hooked = 1;

	ga_error("hooked app module: [%d] %s\n", pid, module_name);

	return 0;
}
示例#5
0
MODULE MODULE_EXPORT int
install_hook(const char *ga_root, const char *config, const char *app_exe)
{
	char s_drive[_MAX_DRIVE], s_dir[_MAX_DIR], s_fname[_MAX_FNAME];
	
	if(ga_root == NULL || config == NULL) {
		ga_error("[install_hook] no ga-root nor configuration were specified.\n");
		return -1;
	}
	
	_splitpath(app_exe, s_drive, s_dir, s_fname, NULL);
#if 0
	if(strncpy(g_appexe, s_fname, sizeof(g_appexe)) < 0)
		return -1;
	if(strncpy(g_root, ga_root, sizeof(g_root)) < 0)
		return -1;
	if(strncpy(g_confpath, config, sizeof(g_confpath)) < 0)
		return -1;
#endif
	_putenv_s("GA_APPEXE", s_fname);
	_putenv_s("GA_ROOT", ga_root);
	_putenv_s("GA_CONFIG", config);
	
	if((gHook = SetWindowsHookEx(WH_CBT, hook_proc, hInst, 0)) == NULL) {
		ga_error("SetWindowsHookEx filaed (0x%08x)\n", GetLastError());
		return -1;
	}

	ga_error("[install_hook] success.\n");
	
	return 0;
}
示例#6
0
MODULE MODULE_EXPORT BOOL APIENTRY
DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved) {
	char module_name[1024];
	static int initialized = 0;

	if(initialized == 0) {
		srand(time(NULL));
		hookid = rand() & 0x0ffff;
		initialized = 1;
	}

	if(GetModuleFileName(NULL, module_name, sizeof(module_name)) <= 0)
		module_name[0] = '\0';

	switch(fdwReason) {
	case DLL_PROCESS_ATTACH:
		hInst = hModule;
		ga_error("[ga-hook-%04x] attached to %s\n", hookid, module_name);
		break;
	case DLL_PROCESS_DETACH:
		ga_error("[ga-hook-%04x] detached from %s\n", hookid, module_name);
		break;
	}

	return TRUE;
}
示例#7
0
Integer util_gnxtval_(Integer *val) {

    if(*val > 0) {
       if(!initialized) ga_error("nxtval: not yet initialized", 0L);
       return (Integer) NGA_Read_inc(g_T, &subscript, 1);
    }
    else if(*val==0) {
       int n = 1;
       initialized=1;

       /* create task array */
       g_T = NGA_Create(C_LONG, 1, &n,"Atomic Task", NULL);
       
       /* Initialize the task array */
       if(GA_Nodeid()==0) {
	  int lo=0, hi=0;
	  NGA_Put (g_T, &lo, &hi, &initval, &hi);
	  initval=0;
       }
              GA_Sync();
       return 0;
    }
    else if (*val < 0) { GA_Destroy(g_T); initialized=0; initval=0; return 0;}
    
    ga_error("nxtval: invalid value passed", 0L);
    return -1;
}
示例#8
0
int
ga_crop_window(struct gaRect *rect, struct gaRect **prect) {
	char display[16], wndname[1024];
	char *pdisplay, *pname;
	Display *d = NULL;
	int dw, dh, screen = 0;
	Window w = 0;
	//
	if(rect == NULL || prect == NULL)
		return -1;
	//
	if((pdisplay = ga_conf_readv("display", display, sizeof(display))) == NULL) {
		*prect = NULL;
		return 0;
	}
	if((pname = ga_conf_readv("find-window-name", wndname, sizeof(wndname))) == NULL) {
		*prect = NULL;
		return 0;
	}
	//
	if((d = XOpenDisplay(pdisplay)) == NULL) {
		ga_error("ga_crop_window: cannot open display %s\n", display);
		return -1;
	}
	screen = XDefaultScreen(d);
	dw = DisplayWidth(d, screen);
	dh = DisplayHeight(d, screen);
	if((w = FindWindowX(d, RootWindow(d, screen), pname)) == 0) {
		ga_error("FindWindowX failed for %s/%s\n", pdisplay, pname);
		XCloseDisplay(d);
		return -1;
	}
	if(GetClientRectX(d, screen, w, rect) < 0) {
		ga_error("GetClientRectX failed for %s/%s\n", pdisplay, pname);
		XCloseDisplay(d);
		return -1;
	}
	XRaiseWindow(d, w);
	XSetInputFocus(d, w, RevertToNone, CurrentTime);
	XCloseDisplay(d);
	// size check: multiples of 2?
	if((rect->right - rect->left + 1) % 2 != 0)
		rect->left--;
	if((rect->bottom - rect->top + 1) % 2 != 0)
		rect->top--;
	// window is all visible?
	if(rect->left < 0 || rect->top < 0 || rect->right >= dw || rect->bottom >= dh) {
		ga_error("Invalid window: (%d,%d)-(%d,%d) w=%d h=%d (screen dimension = %dx%d).\n",
			rect->left, rect->top, rect->right, rect->bottom,
			rect->right - rect->left + 1,
			rect->bottom - rect->top + 1,
			dw, dh);
		return -1;
	}
	//
	*prect = rect;
	return 1;
}
int nw_inp_from_string(Integer rtdb, const char *input)
{
    char filename[30];
    FILE *file;
#if defined(USE_FCD) || defined(CRAY_T3E) || defined(WIN32)
    _fcd fstring;
#else
    char fstring[255];
#endif
    int status;
    const char base[] = "temp";
    const char ending[] = ".nw";
    int number ;

// This is bad, not 100% sure to be unique, since could be subgroup
    if (ga_pgroup_get_world_() != ga_pgroup_get_default_()) {
       number = (int) util_sgroup_mygroup_() ;
    } else {
       number = 0 ;
    }
    sprintf(filename, "%s%d%s", base,number,ending);
    if (ga_nodeid_() == 0) {
      if (!(file = fopen(filename,"w"))) {
        ga_error("nw_inp_from_string: failed to open temp.nw\n",0);
      }
      if (fwrite(input, 1, strlen(input), file) != strlen(input)) {
        ga_error("nw_inp_from_string: failed to write to temp.nw\n",0);
      }
      if (fwrite("\n", 1, 1, file) != 1) {
        ga_error("nw_inp_from_string: failed to write to temp.nw\n",0);
      }
      (void) fclose(file);
    }

#if defined(CRAY_T3E)
      fstring = _cptofcd(filename, strlen(filename));
      status = nw_inp_from_file_(&rtdb, fstring);
#elif defined(WIN32)
    fstring.string = filename;
    fstring.len = strlen(filename);
    status = nw_inp_from_file_(&rtdb, fstring);
#elif defined(USE_FCD)
#error Do something about _fcd
#else
    status = nw_inp_from_file_(&rtdb, filename, strlen(filename));
#endif


    if (ga_nodeid_() == 0) (void) unlink(filename);

    return status;
}
示例#10
0
void
ga_xwin_imageinfo(XImage *image) {
	ga_error("ga-imageinfo: %dx%dx%d xoffset=%d format=%d byte-order=%d\n",
			image->width, image->height, image->depth,
			image->xoffset, image->format, image->byte_order);
	ga_error("ga-imageinfo: --> bitmap-unit=%d bitmap-bit-order=%d bitmap-pad=%d\n",
			image->bitmap_unit, image->bitmap_bit_order, image->bitmap_pad);
	ga_error("ga-imageinfo: --> bytes-per-line=%d bits-per-pixel=%d\n",
			image->bytes_per_line, image->bits_per_pixel);
	ga_error("ga-imageinfo: --> mask red=0x%08lx green=0x%08lx blue=0x%08lx\n",
			image->red_mask, image->green_mask, image->blue_mask);
	return;
}
示例#11
0
static int
rtsp_read_binary(RTSPContext *ctx, char *buf, size_t count) {
	int reqlength;
	if(ctx->rbuftail - ctx->rbufhead < 4)
		goto readmore;
again:
	reqlength = (unsigned char) ctx->rbuffer[ctx->rbufhead+2];
	reqlength <<= 8;
	reqlength += (unsigned char) ctx->rbuffer[ctx->rbufhead+3];
	// data is ready
	if(4+reqlength <= ctx->rbuftail - ctx->rbufhead) {
		bcopy(ctx->rbuffer + ctx->rbufhead, buf, 4+reqlength);
		ctx->rbufhead += (4+reqlength);
		if(ctx->rbufhead == ctx->rbuftail)
			ctx->rbufhead = ctx->rbuftail = 0;
		return 4+reqlength;
	}
	// second trail?
	if(ctx->rbuftail - ctx->rbufhead == ctx->rbufsize) {
		ga_error("Buffer full: Extremely long binary data encountered?\n");
		return -1;
	}
readmore:
	bcopy(ctx->rbuffer + ctx->rbufhead, ctx->rbuffer, ctx->rbuftail - ctx->rbufhead);
	ctx->rbuftail = ctx->rbuftail - ctx->rbufhead;
	ctx->rbufhead = 0;
	//
	if(rtsp_read_internal(ctx) < 0)
		return -1;
	goto again;
	// unreachable, but to meet compiler's requirement
	return -1;
}
示例#12
0
static int
vencoder_deinit(void *arg) {
	int iid;
	for(iid = 0; iid < video_source_channels(); iid++) {
		if(_sps[iid] != NULL)
			free(_sps[iid]);
		if(_pps[iid] != NULL)
			free(_pps[iid]);
#ifdef STANDALONE_SDP
		if(vencoder_sdp[iid] != NULL)
			ga_avcodec_close(vencoder_sdp[iid]);
#endif
		if(vencoder[iid] != NULL)
			ga_avcodec_close(vencoder[iid]);
#ifdef STANDALONE_SDP
		vencoder_sdp[iid] = NULL;
#endif
		vencoder[iid] = NULL;
	}
	bzero(_sps, sizeof(_sps));
	bzero(_pps, sizeof(_pps));
	bzero(_spslen, sizeof(_spslen));
	bzero(_ppslen, sizeof(_ppslen));
	vencoder_initialized = 0;
	ga_error("video encoder: deinitialized.\n");
	return 0;
}
示例#13
0
int
rtp_open_ports(RTSPContext *ctx, int streamid) {
	if(streamid < 0)
		return -1;
	if(streamid+1 > ctx->streamCount) {
		ctx->streamCount = streamid+1;
	}
	streamid *= 2;
	// initialized?
	if(ctx->rtpSocket[streamid] != 0)
		return 0;
	//
	if((ctx->rtpSocket[streamid] = rtp_open_internal(&ctx->rtpLocalPort[streamid])) < 0)
		return -1;
	if((ctx->rtpSocket[streamid+1] = rtp_open_internal(&ctx->rtpLocalPort[streamid+1])) < 0) {
		close(ctx->rtpSocket[streamid]);
		return -1;
	}
	ga_error("RTP: port opened for stream %d, min=%d (fd=%d), max=%d (fd=%d)\n",
		streamid/2,
		(unsigned int) ctx->rtpLocalPort[streamid],
		(int) ctx->rtpSocket[streamid],
		(unsigned int) ctx->rtpLocalPort[streamid+1],
		(int) ctx->rtpSocket[streamid+1]);
	return 0;
}
示例#14
0
int
qos_add_source(const char *prefix, RTPSource *rtpsrc) {
	if(n_qrec >= Q_MAX) {
		ga_error("qos-measurement: too many channels (limit=%d).\n", Q_MAX);
		return -1;
	}
	if(rtpsrc == NULL) {
		ga_error("qos-measurement: invalid RTPSource object.\n");
		return -1;
	}
	snprintf(qrec[n_qrec].prefix, QOS_PREFIX_LEN, "%s", prefix);
	qrec[n_qrec].rtpsrc = rtpsrc;
	ga_error("qos-measurement: source #%d added, prefix=%d\n", n_qrec, prefix);
	n_qrec++;
	return 0;
}
示例#15
0
struct gaRect *
ga_fillrect(struct gaRect *rect, int left, int top, int right, int bottom) {
	if(rect == NULL)
		return NULL;
#define SWAP(a,b)	do { int tmp = a; a = b; b = tmp; } while(0);
	if(left > right)
		SWAP(left, right);
	if(top > bottom)
		SWAP(top, bottom);
#undef	SWAP
	rect->left = left;
	rect->top = top;
	rect->right = right;
	rect->bottom = bottom;
	//
	rect->width = rect->right - rect->left + 1;
	rect->height = rect->bottom - rect->top + 1;
	rect->linesize = rect->width * RGBA_SIZE;
	rect->size = rect->width * rect->height * RGBA_SIZE;
	//
	if(rect->width <= 0 || rect->height <= 0) {
		ga_error("# invalid rect size (%dx%d)\n", rect->width, rect->height);
		return NULL;
	}
	//
	return rect;
}
示例#16
0
static void
rtsp_cmd_play(RTSPContext *ctx, const char *url, RTSPMessageHeader *h) {
	char path[4096];
	//
	av_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path, sizeof(path), url);
	if(strncmp(path, rtspconf->object, strlen(rtspconf->object)) != 0) {
		rtsp_reply_error(ctx, RTSP_STATUS_SESSION);
		return;
	}
	if(strcmp(ctx->session_id, h->session_id) != 0) {
		rtsp_reply_error(ctx, RTSP_STATUS_SESSION);
		return;
	}
	//
	if(ctx->state != SERVER_STATE_READY
	&& ctx->state != SERVER_STATE_PAUSE) {
		rtsp_reply_error(ctx, RTSP_STATUS_STATE);
		return;
	}
	// 2014-05-20: support only shared-encoder model
	if(ff_server_register_client(ctx) < 0) {
		ga_error("cannot register encoder client.\n");
		rtsp_reply_error(ctx, RTSP_STATUS_INTERNAL);
		return;
	}
	//
	ctx->state = SERVER_STATE_PLAYING;
	rtsp_reply_header(ctx, RTSP_STATUS_OK);
	rtsp_printf(ctx, "Session: %s\r\n", ctx->session_id);
	rtsp_printf(ctx, "\r\n");
	return;
}
示例#17
0
static void
rtsp_cmd_play(RTSPContext *ctx, const char *url, RTSPMessageHeader *h) {
	char path[4096];
	//
	av_url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path, sizeof(path), url);
	if(strncmp(path, rtspconf->object, strlen(rtspconf->object)) != 0) {
		rtsp_reply_error(ctx, RTSP_STATUS_SESSION);
		return;
	}
	if(strcmp(ctx->session_id, h->session_id) != 0) {
		rtsp_reply_error(ctx, RTSP_STATUS_SESSION);
		return;
	}
	//
	if(ctx->state != SERVER_STATE_READY
	&& ctx->state != SERVER_STATE_PAUSE) {
		rtsp_reply_error(ctx, RTSP_STATUS_STATE);
		return;
	}
	// create threads
#ifndef SHARE_ENCODER
	if(pthread_create(&ctx->vthread, NULL, vencoder_thread, ctx) != 0) {
		ga_error("cannot create video thread\n");
		rtsp_reply_error(ctx, RTSP_STATUS_INTERNAL);
		return;
	}
#ifdef ENABLE_AUDIO
	if(pthread_create(&ctx->athread, NULL, aencoder_thread, ctx) != 0) {
		ga_error("cannot create audio thread\n");
		rtsp_reply_error(ctx, RTSP_STATUS_INTERNAL);
		return;
	}
#endif	/* ENABLE_AUDIO */
#else
	if(encoder_register_client(ctx) < 0) {
		ga_error("cannot register encoder client.\n");
		rtsp_reply_error(ctx, RTSP_STATUS_INTERNAL);
		return;
	}
#endif	/* SHARE_ENCODER */
	//
	ctx->state = SERVER_STATE_PLAYING;
	rtsp_reply_header(ctx, RTSP_STATUS_OK);
	rtsp_printf(ctx, "Session: %s\r\n", ctx->session_id);
	rtsp_printf(ctx, "\r\n");
	return;
}
示例#18
0
MODULE MODULE_EXPORT int
install_hook(const char *ga_root, const char *config, const char *app_exe)
{
	if(ga_root == NULL || config == NULL) {
		ga_error("[install_hook] no ga-root nor configuration were specified.\n");
		return -1;
	}
	
	if((gHook = SetWindowsHookEx(WH_CBT, hook_proc, hInst, 0)) == NULL) {
		ga_error("SetWindowsHookEx filaed (0x%08x)\n", GetLastError());
		return -1;
	}

	ga_error("[install_hook] success.\n");
	
	return 0;
}
示例#19
0
int
qos_init(UsageEnvironment *ue) {
	env = ue;
	n_qrec = 0;
	bzero(qrec, sizeof(qrec));
	ga_error("qos-measurement: initialized.\n");
	return 0;
}
示例#20
0
snd_pcm_sframes_t
XcapAlsaReadiQueue::readi(snd_pcm_t *handle, unsigned char *samples, int chunksize, int queue) {
	unsigned char *qdata;
	snd_pcm_sframes_t ret = 0;
	// not initialized or error
	if(n == 0 || this->chunksize != chunksize)
		return -1;
	if(samples == NULL)
		return 0;
	// no more queue
	if(queue==0) {
		// queue is empty
		if(datapool.size() == 0)
			return snd_pcm_readi(handle, samples, chunksize);
		// queue is not empty, dequeue
		qdata = datapool.front();
		ret = *((snd_pcm_sframes_t*) qdata);
		bcopy(qdata+sizeof(snd_pcm_sframes_t), samples, this->chunkbyte);
		datapool.pop_front();
		freepool.push_front(qdata);
	}
	// read and queue
	if(freepool.size() == 0) {
		ga_error("AlsaReadiQueue: no more queue, dropping eldest\n");
		qdata = datapool.front();
		datapool.pop_front();
	} else {
		qdata = freepool.front();
		freepool.pop_front();
	}
	*((snd_pcm_sframes_t*) qdata) = snd_pcm_readi(handle,
						qdata+sizeof(snd_pcm_sframes_t),
						chunksize);
	if(*((snd_pcm_sframes_t*) qdata) < 0) {
		freepool.push_front(qdata);
		if(ret > 0 && *((snd_pcm_sframes_t*) qdata) == -EAGAIN) {
			ga_error("DEBUG: snd_pcm_wait in queue->readi (qsize=%d)\n", datapool.size());
			snd_pcm_wait(handle, 1000);
			return ret;
		}
		return *((snd_pcm_sframes_t*) qdata);
	}
	datapool.push_back(qdata);
	//
	return ret;
}
static enum AVSampleFormat
CA2SWR_format(WAVEFORMATEX *w) {
	WAVEFORMATEXTENSIBLE *wex = (WAVEFORMATEXTENSIBLE*) w;
	switch(w->wFormatTag) {
	case WAVE_FORMAT_PCM:
pcm:
		if(w->wBitsPerSample == 8)
			return AV_SAMPLE_FMT_U8;
		if(w->wBitsPerSample == 16)
			return AV_SAMPLE_FMT_S16;
		if(w->wBitsPerSample == 32)
			return AV_SAMPLE_FMT_S32;
		break;
	case WAVE_FORMAT_IEEE_FLOAT:
ieee_float:
		if(w->wBitsPerSample == 32)
			return AV_SAMPLE_FMT_FLT;
		if(w->wBitsPerSample == 64)
			return AV_SAMPLE_FMT_DBL;
		break;
	case WAVE_FORMAT_EXTENSIBLE:
		if(wex->SubFormat == KSDATAFORMAT_SUBTYPE_PCM)
			goto pcm;
		if(wex->SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
			goto ieee_float;
		ga_error("CA2SWR: format %08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX is not supported.\n",
			wex->SubFormat.Data1,
			wex->SubFormat.Data2,
			wex->SubFormat.Data3,
			wex->SubFormat.Data4[0],
			wex->SubFormat.Data4[1],
			wex->SubFormat.Data4[2],
			wex->SubFormat.Data4[3],
			wex->SubFormat.Data4[4],
			wex->SubFormat.Data4[5],
			wex->SubFormat.Data4[6],
			wex->SubFormat.Data4[7]);
		exit(-1);
		break;
	default:
		ga_error("CA2SWR: format %x is not supported.\n", w->wFormatTag);
		exit(-1);
	}
	return AV_SAMPLE_FMT_NONE;
}
int
hook_coreaudio() {
	HMODULE hMod;
	if((hMod = LoadLibrary("ole32.dll")) == NULL) {
		ga_error("Load ole32.dll failed.\n");
		return -1;
	}
	if(old_CoCreateInstance != NULL)
		return 0;
	old_CoCreateInstance =
		(t_CoCreateInstance) GetProcAddress(hMod, "CoCreateInstance");
	if(old_CoCreateInstance == NULL) {
		ga_error("GetProcAddress(CoCreateInstance) failed.\n");
		return -1;
	}
	CA_DO_HOOK(CoCreateInstance);
	return 0;
}
示例#23
0
MODULE MODULE_EXPORT int
uninstall_hook() {
	if(gHook != NULL) {
		UnhookWindowsHookEx(gHook);
		gHook = NULL;
		ga_error("[uninstall_hook] success.\n");
	}
	return 0;
}
static int
live_server_start(void *arg) {
    pthread_cancel_init();
    if(pthread_create(&server_tid, NULL, liveserver_main, NULL) != 0) {
        ga_error("start live-server failed.\n");
        return -1;
    }
    return 0;
}
示例#25
0
static void Error(char *string, int integer)
{
/*
  (void) fflush(stdout);
  (void) fprintf(stderr,"\n\nError was called.\n");
  (void) fprintf(stderr,string);
  (void) fprintf(stderr," %d (%#x).\n",integer,integer);
  exit(1); */
  ga_error(string, (long) integer);
}
示例#26
0
static int
vencoder_reconfigure(int iid, ga_ioctl_reconfigure_t *reconf) {
	if(vencoder_initialized == 0) {
		ga_error("video encoder: reconfigure failed - not initialized?\n");
		return GA_IOCTL_ERR_NOTINITIALIZED;
	}
	if(reconf->bitrateKbps > 0
	|| reconf->framerate_n > 0) {
		unsigned int framerate = 0;
		if(reconf->framerate_n > 0 && reconf->framerate_d > 0) {
			framerate = (((reconf->framerate_d-1) & 0x0ffff)<<16) | (reconf->framerate_n & 0x0ffff);
		}
		if(vpu_encoder_reconfigure(&vpu[reconf->id], reconf->bitrateKbps, framerate) < 0) {
			ga_error("video encoder: reconfigure failed.\n");
			return -1;
		}
	}
	return 0;
}
static int64_t
CA2SWR_chlayout(int channels) {
	if(channels == 1)
		return AV_CH_LAYOUT_MONO;
	if(channels == 2)
		return AV_CH_LAYOUT_STEREO;
	ga_error("CA2SWR: channel layout (%d) is not supported.\n", channels);
	exit(-1);
	return -1;
}
示例#28
0
static int
vencoder_init(void *arg) {
	int iid;
	char *pipefmt = (char*) arg;
	struct RTSPConf *rtspconf = rtspconf_global();
	//
	if(rtspconf == NULL) {
		ga_error("video encoder: no configuration found\n");
		return -1;
	}
	if(vencoder_initialized != 0)
		return 0;
	//
	for(iid = 0; iid < video_source_channels(); iid++) {
		char pipename[64];
		int outputW, outputH;
		pipeline *pipe;
		//
		_sps[iid] = _pps[iid] = NULL;
		_spslen[iid] = _ppslen[iid] = 0;
		snprintf(pipename, sizeof(pipename), pipefmt, iid);
		outputW = video_source_out_width(iid);
		outputH = video_source_out_height(iid);
		if((pipe = pipeline::lookup(pipename)) == NULL) {
			ga_error("video encoder: pipe %s is not found\n", pipename);
			goto init_failed;
		}
		ga_error("video encoder: video source #%d from '%s' (%dx%d).\n",
			iid, pipe->name(), outputW, outputH, iid);
		//
		if(vpu_encoder_init(&vpu[iid], outputW, outputH, rtspconf->video_fps, 1,
				ga_conf_mapreadint("video-specific", "b") / 1000,
				ga_conf_mapreadint("video-specific", "g")) < 0)
			goto init_failed;
	}
	vencoder_initialized = 1;
	ga_error("video encoder: initialized (%d channels).\n", iid);
	return 0;
init_failed:
	vencoder_deinit(NULL);
	return -1;
}
示例#29
0
void *
asource_threadproc(void *arg) {
	int r;
	unsigned char *fbuffer;
	//
	if(asource_init(NULL) < 0) {
		exit(-1);
	}
	if((fbuffer = (unsigned char*) malloc(audioparam.chunk_bytes)) == NULL) {
		ga_error("Audio source: malloc failed (%d bytes) - %s\n",
			audioparam.chunk_bytes, strerror(errno));
		exit(-1);
	}
	//
	ga_error("Audio source thread started: tid=%ld\n", ga_gettid());
	//
	while(true) {
#ifdef WIN32
		r = ga_wasapi_read(&audioparam, fbuffer, audioparam.chunk_size);
		if(r < 0) {
			ga_error("Audio source: WASAPI read failed.\n");
			break;
		}
#else
		r = snd_pcm_readi(audioparam.handle, fbuffer, audioparam.chunk_size);
		if(r == -EAGAIN) {
			snd_pcm_wait(audioparam.handle, 1000);
			continue;
		} else if(r < 0) {
			ga_error("Audio source: ALSA read failed - %s\n",
				snd_strerror(r));
			break;
		}
#endif
		audio_source_buffer_fill(fbuffer, r);
	}
	//
	ga_error("audio capture thread terminated.\n");
	//
	return NULL;
}
示例#30
0
static int
hook_dxgi(const char *hook_type, const char *hook_method) {
	HMODULE hMod;
	//
	if((hMod = GetModuleHandle("dxgi.dll")) == NULL) {
		ga_error("Load dxgi.dll failed.\n");
		return -1;
	}
	//
	pCreateDXGIFactory = (TCreateDXGIFactory) GetProcAddress(hMod, "CreateDXGIFactory");
	if (pCreateDXGIFactory == NULL) {
		ga_error("GetProcAddress(CreateDXGIFactory) failed.\n");
		return -1;
	}
	//
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourAttach(&(PVOID&)pCreateDXGIFactory, hook_CreateDXGIFactory);
	DetourTransactionCommit();
	return 0;
}