示例#1
0
文件: vp8.c 项目: taktod/ttLibC
/*
 * make frame object from vp8 binary data.
 * @param prev_frame    ref for prev analyzed vp8 frame.
 * @param data          vp8 data
 * @param data_size     vp8 data size
 * @param non_copy_mode true:hold pointer. false:copy data.
 * @param pts           pts for vp8 frame.
 * @param timebase      timebase for pts.
 * @return vp8 frame
 */
ttLibC_Vp8 *ttLibC_Vp8_getFrame(ttLibC_Vp8 *prev_frame, uint8_t *data, size_t data_size, bool non_copy_mode, uint64_t pts, uint32_t timebase) {
	if(data_size <= 0x0A) {
		ERR_PRINT("data size is too small for analyze.");
		return NULL;
	}
	bool isKey = ttLibC_Vp8_isKey(data, data_size);
	uint32_t width  = ttLibC_Vp8_getWidth(prev_frame, data, data_size);
	uint32_t height = ttLibC_Vp8_getHeight(prev_frame, data, data_size);
	if(width == 0 || height == 0) {
		return NULL;
	}
	return ttLibC_Vp8_make(prev_frame, isKey ? videoType_key : videoType_inner, width, height, data, data_size, non_copy_mode, pts, timebase);
}
示例#2
0
bool ttLibC_DynamicBuffer_markAsRead(ttLibC_DynamicBuffer *buffer, size_t read_size) {
	ttLibC_DynamicBuffer_ *buffer_ = (ttLibC_DynamicBuffer_ *)buffer;
	if(buffer_ == NULL) {
		return false;
	}
	if(buffer_->read_pos + read_size > buffer_->target_size) {
		ERR_PRINT("read_size is bigger than target_size, overflowed.");
		buffer_->inherit_super.error = ttLibC_updateError(Target_On_Util, Error_InvalidOperation);
		return false;
	}
	buffer_->read_pos += read_size;
	return true;
}
示例#3
0
bool NativeScriptInstance::refcount_decremented() {
	Variant::CallError err;
	Variant ret = call("_refcount_decremented", NULL, 0, err);
	if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) {
		ERR_PRINT("Failed to invoke _refcount_decremented - should not happen");
		return true; // assume we can destroy the object
	}
	if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
		// the method does not exist, default is true
		return true;
	}
	return ret;
}
bool StrUtilTest::DoReplace(const char* sTestData, const char* sTestResult, const char* sOldKey, const char* sNewKey)
{
	char sBuf[64] = {0};
	if (StringUtil::Replace(sTestData, sBuf, sizeof(sBuf), sOldKey, sNewKey) == false) {
		ERR_PRINT("Replace string failed!\n");
		return false;
	}
	DBG_PRINT("Replace result: %s\n", sBuf);
	if (strcmp(sTestResult, sBuf) != 0) {
		return false;
	}
	return true;
}
示例#5
0
const void *PoolAllocator::get(ID p_mem) const {

	if (!needs_locking) {

		const Entry *e=get_entry(p_mem);
		ERR_FAIL_COND_V(!e,NULL);
		return &pool[e->pos];

	}

	mt_lock();
	const Entry *e=get_entry(p_mem);

	if (!e) {

		mt_unlock();
		ERR_FAIL_COND_V(!e,NULL);
	}
	if (e->lock==0) {

		mt_unlock();
		ERR_PRINT( "e->lock == 0" );
		return NULL;
	}

	if (e->pos<0 || (int)e->pos>=pool_size) {

		mt_unlock();
		ERR_PRINT("e->pos<0 || e->pos>=pool_size");
		return NULL;
	}
	const void *ptr=&pool[e->pos];

	mt_unlock();

	return ptr;

}
示例#6
0
/*
 * make openal play device.
 * @param buffer_num number for queue buffers.
 */
ttLibC_AlDevice *ttLibC_AlDevice_make(uint32_t buffer_num) {
	ttLibC_AlDevice_ *device = ttLibC_malloc(sizeof(ttLibC_AlDevice_));
	if(device == NULL) {
		ERR_PRINT("failed to allocate memory for alDevice.");
		return NULL;
	}
	device->device = alcOpenDevice(NULL);
	if(device->device == NULL) {
		ERR_PRINT("failed to open ALCdevice.");
		ttLibC_free(device);
		return NULL;
	}
	device->context = alcCreateContext(device->device, NULL);
	if(device->context == NULL) {
		ERR_PRINT("failed to create ALCcontext.");
		alcCloseDevice(device->device);
		ttLibC_free(device);
		return NULL;
	}
	alcMakeContextCurrent(device->context);
	alGenSources(1, &device->source);

	device->inherit_super.buffer_num = buffer_num;
	device->buffers = ttLibC_malloc(sizeof(ALuint) * device->inherit_super.buffer_num);
	if(device->buffers == NULL) {
		ERR_PRINT("failed to allocate memory for buffers");
		alDeleteSources(1, &device->source);
		alcMakeContextCurrent(NULL);
		alcDestroyContext(device->context);
		alcCloseDevice(device->device);
		ttLibC_free(device);
		return NULL;
	}
	for(uint32_t i = 0;i < device->inherit_super.buffer_num;++ i) {
		device->buffers[i] = 0;
	}
	return (ttLibC_AlDevice *)device;
}
示例#7
0
Error StreamPeerWinsock::connect(const IP_Address& p_host, uint16_t p_port) {

	ERR_FAIL_COND_V( p_host.host == 0, ERR_INVALID_PARAMETER);

	if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
		ERR_PRINT("Socket creation failed!");
		disconnect();
		//perror("socket");
		return FAILED;
	};

	unsigned long par = 1;
	if (ioctlsocket(sockfd, FIONBIO, &par)) {
		perror("setting non-block mode");
		disconnect();
		return FAILED;
	};

	struct sockaddr_in their_addr;
	set_addr_in(their_addr, p_host, p_port);

	if (::connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == SOCKET_ERROR) {

		if (WSAGetLastError() != WSAEWOULDBLOCK) {
			ERR_PRINT("Connection to remote host failed!");
			disconnect();
			return FAILED;
		};
		status = STATUS_CONNECTING;
	} else {
		status = STATUS_CONNECTED;
	};

	peer_host = p_host;
	peer_port = p_port;

	return OK;
};
示例#8
0
bool NetworkUtil::GetInterfaceMAC(const char* sIfName, unsigned char* sMAC, unsigned int* uMACLen)
{
	struct ifreq ifr;
	int sockfd;
	int nRet;
	bool bRet;

	bRet = SocketUtil::Socket(AF_INET, SOCK_DGRAM, 0, &sockfd);
	if (bRet  == false) {
		ERR_PRINT("SocketUtil::Socket() error!\n");
		return false;
	}

	bzero(&ifr, sizeof(ifr));
	strncpy(ifr.ifr_name, sIfName, sizeof(ifr.ifr_name));

	nRet = ioctl(sockfd, SIOCGIFHWADDR, &ifr);
	if (nRet < 0) {
		nRet = errno;
		ERR_PRINT("%s\n",strerror(nRet));
		return false;
	}

	bRet = SocketUtil::Close(sockfd);
	if (bRet  == false) {
		ERR_PRINT("SocketUtil::Close() error!\n");
		return false;
	}

	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
		ERR_PRINT("Invalid family (%d)!\n", ifr.ifr_hwaddr.sa_family);
		return false;
	}

	memcpy(sMAC, &(ifr.ifr_hwaddr.sa_data), MAX_ADDR_LEN - 1);
	*uMACLen = MAX_ADDR_LEN - 1;
	return true;
}
示例#9
0
void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {

	packet_peer_stream->put_var(p_name);
	int len = 0;
	Error err = encode_variant(p_variable, NULL, len);
	if (err != OK)
		ERR_PRINT("Failed to encode variant");

	if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
		packet_peer_stream->put_var(Variant());
	} else {
		packet_peer_stream->put_var(p_variable);
	}
}
示例#10
0
文件: yuv420.c 项目: taktod/ttLibC
/*
 * close frame
 * @param frame
 */
void ttLibC_Yuv420_close(ttLibC_Yuv420 **frame) {
	ttLibC_Yuv420 *target = (*frame);
	if(target == NULL) {
		return;
	}
	if(target->inherit_super.inherit_super.type != frameType_yuv420) {
		ERR_PRINT("found non yuv420 frame in yuv420_close.");
	}
	if(!target->inherit_super.inherit_super.is_non_copy) {
		ttLibC_free(target->inherit_super.inherit_super.data);
	}
	ttLibC_free(target);
	*frame = NULL;
}
示例#11
0
文件: vp9.c 项目: taktod/ttLibC
/*
 * check if the vp9 binary is key frame.
 * @param data      vp9 data
 * @param data_size vp9 data size
 * @return true: key frame false:inter frame
 */
bool ttLibC_Vp9_isKey(void *data, size_t data_size) {
	ttLibC_ByteReader *reader = ttLibC_ByteReader_make(data, data_size, ByteUtilType_default);
	ttLibC_ByteReader_bit(reader, 2);
	ttLibC_ByteReader_bit(reader, 1);
	ttLibC_ByteReader_bit(reader, 1);
	uint32_t ref_flag = ttLibC_ByteReader_bit(reader, 1);
	if(ref_flag == 1) {
		ERR_PRINT("ref func is not implemented yet.");
		ttLibC_ByteReader_bit(reader, 3);
	}
	uint32_t key_frame_flag = ttLibC_ByteReader_bit(reader, 1);
	ttLibC_ByteReader_close(&reader);
	return (key_frame_flag == 0);
}
示例#12
0
void PoolAllocator::unlock(ID p_mem) {

	if (!needs_locking)
		return;
	mt_lock();
	Entry *e = get_entry(p_mem);
	if (e->lock == 0) {
		mt_unlock();
		ERR_PRINT("e->lock == 0");
		return;
	}
	e->lock--;
	mt_unlock();
}
示例#13
0
IP_Address IP_Unix::_resolve_hostname(const String& p_hostname) {

	struct hostent *he;
	if ((he=gethostbyname(p_hostname.utf8().get_data())) == NULL) {  // get the host info
		ERR_PRINT("gethostbyname failed!");
		return IP_Address();
	}
	IP_Address ip;

	ip.host= *((unsigned long*)he->h_addr);

	return ip;

}
示例#14
0
void AudioDriverCoreAudio::capture_finish() {
	if (input_unit) {
		lock();

		AURenderCallbackStruct callback;
		zeromem(&callback, sizeof(AURenderCallbackStruct));
		OSStatus result = AudioUnitSetProperty(input_unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(callback));
		if (result != noErr) {
			ERR_PRINT("AudioUnitSetProperty failed");
		}

		result = AudioUnitUninitialize(input_unit);
		if (result != noErr) {
			ERR_PRINT("AudioUnitUninitialize failed");
		}

#ifdef OSX_ENABLED
		AudioObjectPropertyAddress prop;
		prop.mSelector = kAudioHardwarePropertyDefaultInputDevice;
		prop.mScope = kAudioObjectPropertyScopeGlobal;
		prop.mElement = kAudioObjectPropertyElementMaster;

		result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &input_device_address_cb, this);
		if (result != noErr) {
			ERR_PRINT("AudioObjectRemovePropertyListener failed");
		}
#endif

		result = AudioComponentInstanceDispose(input_unit);
		if (result != noErr) {
			ERR_PRINT("AudioComponentInstanceDispose failed");
		}

		input_unit = NULL;
		unlock();
	}
}
示例#15
0
文件: video.c 项目: taktod/ttLibC
/*
 * close frame
 * @param frame
 */
void ttLibC_Video_close(ttLibC_Video **frame) {
	ttLibC_Video *target = *frame;
	if(target == NULL) {
		return;
	}
	switch(target->inherit_super.type) {
	case frameType_bgr:
		ttLibC_Bgr_close((ttLibC_Bgr **)frame);
		break;
	case frameType_flv1:
		ttLibC_Flv1_close((ttLibC_Flv1 **)frame);
		break;
	case frameType_h264:
		ttLibC_H264_close((ttLibC_H264 **)frame);
		break;
	case frameType_jpeg:
		ttLibC_Jpeg_close((ttLibC_Jpeg **)frame);
		break;
	case frameType_yuv420:
		ttLibC_Yuv420_close((ttLibC_Yuv420 **)frame);
		break;
	case frameType_vp6:
		ttLibC_Vp6_close((ttLibC_Vp6 **)frame);
		break;
	case frameType_vp8:
		ttLibC_Vp8_close((ttLibC_Vp8 **)frame);
		break;
	case frameType_vp9:
		ttLibC_Vp9_close((ttLibC_Vp9 **)frame);
		break;
	case frameType_wmv1:
		ttLibC_Wmv1_close((ttLibC_Wmv1 **)frame);
		break;
	case frameType_wmv2:
		ttLibC_Wmv2_close((ttLibC_Wmv2 **)frame);
		break;
	case frameType_theora:
		ttLibC_Theora_close((ttLibC_Theora **)frame);
		break;
	case frameType_h265:
		{
			ttLibC_Video_close_(frame);
		}
		break;
	default:
		ERR_PRINT("unknown type:%d", target->inherit_super.type);
		break;
	}
}
void TcpServerTest::Run()
{
	const char* sIP = NULL;
	unsigned int uPort = 8877;
	char sBuf[4096] = {0};
	unsigned int uBufSize = sizeof(sBuf);
	unsigned int uSigNo;
	TcpServer tcp(sIP, uPort);

	if (tcp.IsInitPass() == false) {
		ERR_PRINT("Initialize TCP server failed!\n");
		return;
	}

	while (true) {
		if (SigUtil::Wait(0, &uSigNo)) {
			if ((uSigNo == SIGINT) || (uSigNo == SIGTERM)) {
				ERR_PRINT("Signal %s received. Terminating.\n", SigUtil::GetSignalString(uSigNo));
				break;
			}
		}

		if (tcp.Wait(100)) {
			tcp.Accept();
		}

		if (tcp.WaitClient(0) == false) {
			continue;
		}
		if (tcp.Recv(sBuf, uBufSize) == false) {
			tcp.CloseClient();
			continue;
		}
		DBG_PRINT("Received data: %s\n", sBuf);
	}
}
示例#17
0
bool NetworkUtil::IPBinaryToText(int nAddressFamily, const void* stAddr, char* sIP)
{
	const char *pRet;
	int nRet;

	switch (nAddressFamily) {
	case AF_INET:
		pRet = inet_ntop(nAddressFamily, stAddr, sIP, INET_ADDRSTRLEN);
		break;
	case AF_INET6:
		pRet = inet_ntop(nAddressFamily, stAddr, sIP, INET6_ADDRSTRLEN);
		break;
	default:
		ERR_PRINT("Unknown address family (%d)!", nAddressFamily);
		return false;
	}

	if (pRet == NULL) {
		nRet = errno;
		ERR_PRINT("%s\n",strerror(nRet));
		return false;
	}
	return true;
}
示例#18
0
Variant Variant::call(const StringName& p_method,VARIANT_ARG_DECLARE) {
	VARIANT_ARGPTRS;
	int argc=0;
	for(int i=0;i<VARIANT_ARG_MAX;i++) {
		if (argptr[i]->get_type()==Variant::NIL)
			break;
		argc++;
	}

	CallError error;

	Variant ret = call(p_method,argptr,argc,error);

	switch(error.error) {

		case CallError::CALL_ERROR_INVALID_ARGUMENT: {

			String err = "Invalid type for argument #"+itos(error.argument)+", expected '"+Variant::get_type_name(error.expected)+"'.";
			ERR_PRINT(err.utf8().get_data());

		} break;
		case CallError::CALL_ERROR_INVALID_METHOD: {

			String err = "Invalid method '"+p_method+"' for type '"+Variant::get_type_name(type)+"'.";
			ERR_PRINT(err.utf8().get_data());
		} break;
		case CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {

			String err = "Too many arguments for method '"+p_method+"'";
			ERR_PRINT(err.utf8().get_data());
		} break;
		default: {}
	}

	return ret;
}
示例#19
0
Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) {

	if (native_handle == NULL) {
		ERR_PRINT("No valid library handle, can't get symbol from GDNative object");
		return ERR_CANT_OPEN;
	}

	Error result = OS::get_singleton()->get_dynamic_library_symbol_handle(
			native_handle,
			p_procedure_name,
			r_handle,
			true);

	return result;
}
示例#20
0
void PoolAllocator::free(ID p_mem) {

	mt_lock();
	Entry *e=get_entry(p_mem);
	if (!e) {
		mt_unlock();
		ERR_PRINT("!e");
		return;
	}
	if (e->lock) {
		mt_unlock();
		ERR_PRINT("e->lock");
		return;
	}

	EntryIndicesPos entry_indices_pos;

	bool index_found = find_entry_index(&entry_indices_pos,e);
	if (!index_found) {

		mt_unlock();
		ERR_FAIL_COND(!index_found);
	}



	for (int i=entry_indices_pos;i<(entry_count-1);i++) {

		entry_indices[ i ] = entry_indices[ i+1 ];
	}

	entry_count--;
	free_mem+=aligned(e->len);
	e->clear();
	mt_unlock();
}
示例#21
0
Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) const {

	if (!initialized) {
		ERR_PRINT("No valid library handle, can't get symbol from GDNative object");
		return ERR_CANT_OPEN;
	}

	Error result = OS::get_singleton()->get_dynamic_library_symbol_handle(
			native_handle,
			p_procedure_name,
			r_handle,
			p_optional);

	return result;
}
示例#22
0
SampleManagerMallocSW::~SampleManagerMallocSW() {

	// check for sample leakage
	List<RID> owned_list;
	sample_owner.get_owned_list(&owned_list);

	while (owned_list.size()) {

		Sample *s = sample_owner.get(owned_list.front()->get());
		String err = "Leaked sample of size: " + itos(s->length_bytes) + " description: " + s->description;
		ERR_PRINT(err.utf8().get_data());
		free(owned_list.front()->get());
		owned_list.pop_front();
	}
}
示例#23
0
文件: ip.cpp 项目: Bonfi96/godot
IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {

	ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE);

	resolver->mutex->lock();
	if (resolver->queue[p_id].status == IP::RESOLVER_STATUS_NONE) {
		ERR_PRINT("Condition status == IP::RESOLVER_STATUS_NONE");
		resolver->mutex->unlock();
		return IP::RESOLVER_STATUS_NONE;
	}
	IP::ResolverStatus res = resolver->queue[p_id].status;

	resolver->mutex->unlock();
	return res;
}
void ShaderTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) {

	_check_shader_mode();

	ShaderLanguage sl;
	String calltip;

	Error err = sl.complete(p_code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_types(), r_options, calltip);
	if (err != OK)
		ERR_PRINT("Shaderlang complete failed");

	if (calltip != "") {
		get_text_edit()->set_code_hint(calltip);
	}
}
示例#25
0
bool GDNative::terminate() {

	if (!initialized) {
		ERR_PRINT("No valid library handle, can't terminate GDNative object");
		return false;
	}

	if (library->should_load_once()) {
		Vector<Ref<GDNative> > *gdnatives = &(*GDNativeLibrary::loaded_libraries)[library->get_current_library_path()];
		if (gdnatives->size() > 1) {
			// there are other GDNative's still using this library, so we actually don't terminate
			gdnatives->erase(Ref<GDNative>(this));
			initialized = false;
			return true;
		} else if (gdnatives->size() == 1) {
			// we're the last one, terminate!
			gdnatives->clear();
			// wew this looks scary, but all it does is remove the entry completely
			GDNativeLibrary::loaded_libraries->erase(GDNativeLibrary::loaded_libraries->find(library->get_current_library_path()));
		}
	}

	void *library_terminate;
	Error error = get_symbol(library->get_symbol_prefix() + terminate_symbol, library_terminate);
	if (error || !library_terminate) {
		OS::get_singleton()->close_dynamic_library(native_handle);
		native_handle = NULL;
		initialized = false;
		return true;
	}

	godot_gdnative_terminate_fn library_terminate_pointer;
	library_terminate_pointer = (godot_gdnative_terminate_fn)library_terminate;

	godot_gdnative_terminate_options options;
	options.in_editor = Engine::get_singleton()->is_editor_hint();

	library_terminate_pointer(&options);

	initialized = false;

	// GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path);

	OS::get_singleton()->close_dynamic_library(native_handle);
	native_handle = NULL;

	return true;
}
示例#26
0
void ARVRServer::add_interface(const Ref<ARVRInterface> &p_interface) {
	ERR_FAIL_COND(p_interface.is_null());

	for (int i = 0; i < interfaces.size(); i++) {

		if (interfaces[i] == p_interface) {
			ERR_PRINT("Interface was already added");
			return;
		};
	};

	print_line("ARVR: Registered interface: " + p_interface->get_name());

	interfaces.push_back(p_interface);
	emit_signal("interface_added", p_interface->get_name());
};
示例#27
0
/*Create CdrStock*/
CdrStock* CdrStockCreate(ADTErr* _adterr)
{
    CdrStock* cdrStock = NULL;
    cdrStock = (CdrStock*)malloc(sizeof(CdrStock));
    if (! cdrStock)
    {
        if (NULL != _adterr)
        {
            *_adterr = ERR_ALLOCATION_FAILED;
        }
        ERR_PRINT("%s", "exited with NULL");
        return NULL;
    }
    cdrStock->m_protecQueue = QueueCreateProtecded(_adterr);
    return cdrStock;
}
示例#28
0
Error PoolAllocator::lock(ID p_mem) {

	if (!needs_locking)
		return OK;
	mt_lock();
	Entry *e = get_entry(p_mem);
	if (!e) {

		mt_unlock();
		ERR_PRINT("!e");
		return ERR_INVALID_PARAMETER;
	}
	e->lock++;
	mt_unlock();
	return OK;
}
示例#29
0
bool FileUtil::Read(void *pData, size_t uDataSize, size_t uNumElement, FILE *pFile, unsigned int *uReadSize)
{
	size_t uRet = fread(pData, uDataSize, uNumElement, pFile);
//	DBG_PRINT("Read size: %u\n", uRet);
	*uReadSize = uRet;
	if (uRet == 0) {
		int nRet = feof(pFile);
//		DBG_PRINT("feof() result: %d\n", nRet);
		if (nRet < 0) {
			nRet = errno;
			ERR_PRINT("fread() error: %s!\n", strerror(nRet));
			return false;
		}
	}
	return true;
}
示例#30
0
Error AudioDriverWASAPI::init() {

	Error err = init_device();
	if (err != OK) {
		ERR_PRINT("WASAPI: init_device error");
	}

	active = false;
	exit_thread = false;
	thread_exited = false;

	mutex = Mutex::create(true);
	thread = Thread::create(thread_func, this);

	return OK;
}