예제 #1
0
size_t NetSocketPosix::_set_addr_storage(struct sockaddr_storage *p_addr, const IP_Address &p_ip, uint16_t p_port, IP::Type p_ip_type) {

	memset(p_addr, 0, sizeof(struct sockaddr_storage));
	if (p_ip_type == IP::TYPE_IPV6 || p_ip_type == IP::TYPE_ANY) { // IPv6 socket

		// IPv6 only socket with IPv4 address
		ERR_FAIL_COND_V(!p_ip.is_wildcard() && p_ip_type == IP::TYPE_IPV6 && p_ip.is_ipv4(), 0);

		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
		addr6->sin6_family = AF_INET6;
		addr6->sin6_port = htons(p_port);
		if (p_ip.is_valid()) {
			copymem(&addr6->sin6_addr.s6_addr, p_ip.get_ipv6(), 16);
		} else {
			addr6->sin6_addr = in6addr_any;
		}
		return sizeof(sockaddr_in6);
	} else { // IPv4 socket

		// IPv4 socket with IPv6 address
		ERR_FAIL_COND_V(!p_ip.is_wildcard() && !p_ip.is_ipv4(), 0);

		struct sockaddr_in *addr4 = (struct sockaddr_in *)p_addr;
		addr4->sin_family = AF_INET;
		addr4->sin_port = htons(p_port); // short, network byte order

		if (p_ip.is_valid()) {
			copymem(&addr4->sin_addr.s_addr, p_ip.get_ipv4(), 4);
		} else {
			addr4->sin_addr.s_addr = INADDR_ANY;
		}

		return sizeof(sockaddr_in);
	}
}
예제 #2
0
파일: main.c 프로젝트: gitprotest/console
int main()
{
    //Initial setup
    vbDisplayOn();

    //Copy tileset and tilemap into memory
    copymem((void*)CharSeg0, (void*)CHADJUSTMENT, 256*16);
    copymem((void*)BGMap(0), (void*)BGADJUSTMENT, 450*16);

    //Setup worlds
    //(This uses structs to access world data, the old method using functions is commented out)
    WA[31].head = (WRLD_LON|WRLD_OVR);
    WA[31].w = 384;
    WA[31].h = 224;
    //vbSetWorld(31, (WRLD_LON|WRLD_OVR), 0, 0, 0, 0, 0, 0, 384, 224);
    
    WA[30].head = (WRLD_RON|WRLD_OVR);
    WA[30].my = 224;
    WA[30].w = 384;
    WA[30].h = 224;
    //vbSetWorld(30, (WRLD_RON|WRLD_OVR), 0, 0, 0, 0, 0, 224, 384, 224);

    WA[29].head = WRLD_END;
    //vbSetWorld(29, WRLD_END, 0, 0, 0, 0, 0, 0, 0, 0);

    //Set brightness registers
    vbDisplayShow();

    //Main loop (Empty because we're done but don't want to reach the end)
    for (;;);

    return 0;
}
예제 #3
0
PLUGINFUNCTIONEND

PLUGINFUNCTION(Store)
{
    TempStack *tmp;
    int size = ((INST_R9+1)*g_stringsize);    

    char *command, *cmd = command = system_popstring();
    while (*cmd != 0)
    {
        switch (*(cmd++))
        {
        case 's':
        case 'S':
            // Store the whole variables range
            tmp = (TempStack*) GlobalAlloc(GPTR, sizeof(TempStack)+size);
            tmp->Next = tempstack;
            tempstack = tmp;

            // Fill with data
            copymem(tempstack->Data, g_variables, size);
            break;
        case 'l':
        case 'L':
            if (tempstack == NULL) break;

            // Fill with data
            copymem(g_variables, tempstack->Data, size);

            // Restore stack
            tmp = tempstack->Next;
            GlobalFree((HANDLE) tempstack);
            tempstack = tmp;
            break;
        case 'P':
            *cmd += 10;
        case 'p':
            GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-'0')));
            break;
        case 'R':
            *cmd += 10;
        case 'r':
            GlobalFree((HANDLE) system_setuservariable(*(cmd++)-'0', system_popstring()));
            break;
        }
    }

    GlobalFree((HANDLE) command);
}
size_t NetworkedMultiplayerENet::enet_compress(void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit) {

	NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet*)(context);

	if (size_t(enet->src_compressor_mem.size())<inLimit) {
		enet->src_compressor_mem.resize( inLimit );
	}

	int total = inLimit;
	int ofs=0;
	while(total) {
		for(size_t i=0;i<inBufferCount;i++) {
			int to_copy = MIN(total,int(inBuffers[i].dataLength));
			copymem(&enet->src_compressor_mem[ofs],inBuffers[i].data,to_copy);
			ofs+=to_copy;
			total-=to_copy;
		}
	}

	Compression::Mode mode;

	switch(enet->compression_mode) {
		case COMPRESS_FASTLZ: {
			mode=Compression::MODE_FASTLZ;
		} break;
		case COMPRESS_ZLIB: {
			mode=Compression::MODE_DEFLATE;
		} break;
		default: { ERR_FAIL_V(0); }
	}

	int req_size = Compression::get_max_compressed_buffer_size(ofs,mode);
	if (enet->dst_compressor_mem.size()<req_size) {
		enet->dst_compressor_mem.resize(req_size);
	}
	int ret=Compression::compress(enet->dst_compressor_mem.ptr(),enet->src_compressor_mem.ptr(),ofs,mode);

	if (ret<0)
		return 0;


	if (ret>int(outLimit))
		return 0; //do not bother

	copymem(outData,enet->dst_compressor_mem.ptr(),ret);

	return ret;
}
int VideoStreamTheoraplayer::get_pending_frame_count() const {

	if (!clip)
		return 0;

	if (!frame.empty())
		return 1;

	TheoraVideoFrame* f = clip->getNextFrame();
	if (!f)
		return 0;

	float w=clip->getWidth(),h=clip->getHeight();
    int imgsize = w * h * f->mBpp;

	int size = f->getStride() * f->getHeight() * f->mBpp;
	DVector<uint8_t> data;
	data.resize(imgsize);
	DVector<uint8_t>::Write wr = data.write();
    uint8_t* ptr = wr.ptr();
    copymem(ptr, f->getBuffer(), imgsize);
    /*
    for (int i=0; i<h; i++) {
        int dstofs = i * w * f->mBpp;
        int srcofs = i * f->getStride() * f->mBpp;
        copymem(ptr + dstofs, f->getBuffer() + dstofs, w * f->mBpp);
    };
     */
	frame = Image();
	frame.create(w, h, 0, f->mBpp == 3 ? Image::FORMAT_RGB : Image::FORMAT_RGBA, data);

	clip->popFrame();

	return 1;
};
예제 #6
0
PLUGINFUNCTIONEND

PLUGINFUNCTIONSHORT(Copy)
{
    int size = 0;
    HANDLE source, dest;
    char *str;
    // Get the string
    if ((str = system_popstring()) == NULL) return;

    // Check for size option
    if (str[0] == '/')
    {
        size = (int) myatoi64(str+1);
        dest = (HANDLE) popint64();
    }
    else dest = (HANDLE) myatoi64(str);
    source = (HANDLE) popint64();

    // Ok, check the size
    if (size == 0) size = (int) GlobalSize(source);
    // and the destinantion
    if ((int) dest == 0) 
    {
        dest = GlobalAlloc((GPTR), size);
        system_pushint((int) dest);
    }

    // COPY!
    copymem(dest, source, size);

    GlobalFree(str);
}
예제 #7
0
void load_warning_scr()
{

	copymem((void *)0x78000, (void*)font_pc, 8192);	
	/* Clear out any leftover characters from previous BG. */
	setmem((void*)BGMap(0), 0, 0x2000);
	
	WA[31].head = WRLD_ON;
	WA[31].gx    = 0;
	WA[31].gp    = 0; //No parallax for now.
	WA[31].gy    = CENTER_Y(5)*8;
	WA[31].mx = 0;
	WA[31].mp = 0;
	WA[31].my = 0;
	WA[31].w = 384;
	WA[31].h = (5*8 - 1);
	WA[31].ovr = 0;
	WA[31].param = 0;
	
	WA[30].head = WRLD_END;
	
	print_message(msg_warn[0], 0, CENTER_X(27), 0, 0);
	print_message(msg_warn[1], 0, CENTER_X(23), 2, 0);
	print_message(msg_warn[2], 0, CENTER_X(16), 4, 0);
	
	
}
예제 #8
0
void GetURLHandler::AppendDataBytes(const char* buffer, int32_t num_bytes) {
  if (num_bytes <= 0)
    return;
  // Make sure we don't get a buffer overrun.
  num_bytes = std::min(READ_BUFFER_SIZE, num_bytes);
  int ofs = data.size();
  data.resize(ofs + num_bytes);
  copymem(&data[ofs], buffer, num_bytes);
}
예제 #9
0
static void _write_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length) {

	PoolVector<uint8_t> &v = *(PoolVector<uint8_t> *)png_get_io_ptr(png_ptr);
	int vs = v.size();

	v.resize(vs + p_length);
	PoolVector<uint8_t>::Write w = v.write();
	copymem(&w[vs], data, p_length);
}
예제 #10
0
static void _write_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {

	DVector<uint8_t> &v = *(DVector<uint8_t>*)png_get_io_ptr(png_ptr);
	int vs = v.size();

	v.resize(vs+p_length);
	DVector<uint8_t>::Write w = v.write();
	copymem(&w[vs],data,p_length);
	//print_line("png write: "+itos(p_length));
}
예제 #11
0
void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) {

	int left = length - pos;
	int write = MIN(p_length, left);
	if (write < p_length) {
		WARN_PRINT("Writing less data than requested");
	};

	copymem(&data[pos], p_src, write);
	pos += p_length;
};
예제 #12
0
Error PackedDataContainer::pack(const Variant &p_data) {

	Vector<uint8_t> tmpdata;
	Map<String, uint32_t> string_cache;
	_pack(p_data, tmpdata, string_cache);
	datalen = tmpdata.size();
	data.resize(tmpdata.size());
	PoolVector<uint8_t>::Write w = data.write();
	copymem(w.ptr(), tmpdata.ptr(), tmpdata.size());

	return OK;
}
예제 #13
0
파일: mlpc2.c 프로젝트: kieranhogan13/C
int main() {
	int i;
	char s1[]="abcdefghijklmnopqrstuvwxyz";
	char s2[30];
	char *s3;
	char *s4;
	s3=(char *)malloc(10000);
	s4=(char *)malloc(10000);
	for(i=0;i<100000;i++)	
		copymem(s3,s4,10000);
	return(0);

}
예제 #14
0
파일: main.c 프로젝트: dbrooke/wsrdr
//! Set up device and execute command(s).
//
int main(int argc, char** argv) {
    // read in program arguments
    read_arguments(argc, argv);

#ifdef _DEBUG
    // DEBUG: list the options
    dump_options();
#endif // _DEBUG

    // help over-rides all. For options variable see cmdline.h
    if (options.showHelp) {
        printHelp();
        exit(0);
    }

    // open the device or its imposter (file), see dfile.h
    if (options.inputFromFile == 1) {
        dopen(cmdFilename);
    }
    else {
        dopen(":usb:");
    }

    // dump header can be executed with other commands
    if (options.dumpHeader == 1) {
        printHeader();
    }

    // now dispatch for processing
    if (options.dumpMemory == 1) {
        // hexdump device memory
        dumpmemory(memoryDumpStart, memoryDumpEnd, DumpWidth);
    }
    else if (options.writeMemoryToFile == 1) {
        // copy device memory to a file
        copymem(cmdFilename);
    }
    else if (options.printRecordsSince == 1) {
        // list records since given date & time
        listRecordsSince(dateSince);
    }
    else if (options.printRecords == 1) {
        // list specified records (0 = current, n = oldest)
        if (options.untilFirstRecord == 1) {
            endRecordNumber = getRecordsStored();
        }
        listRecords(startRecordNumber, endRecordNumber);
    }

    dclose();
}
예제 #15
0
void load_ipdfoc_scr()
{
	/* Load focus screen tiles into memory. */
	/* copymem((void *)0x78000, (void*)cgx_sample, 8192*2);
	copymem((void*)BGMap(0), (void*)scr_ipd_foc, 4096*2); */
	copymem((void *)0x78000, (void*)char_cfoc, 8192*2);
	copymem((void*)BGMap(0), (void*)bg_vblogo_r, 4096*2);
	copymem((void*)BGMap(1), (void*)bg_vblogo_l, 4096*2);
	
	/* Reload the worlds to point to the appropriate.
	Screen. */
	WA[31].head = WRLD_RON;
	WA[31].gx = 0;
	WA[31].gp = 0;
	WA[31].gy = 0;
	WA[31].mx = 0;
	WA[31].mp = 0;
	WA[31].my = 0;
	WA[31].w = 383;
	WA[31].h = 223;
	WA[31].ovr = 0;
	WA[31].param = 0;
	
	WA[30].head = WRLD_LON + 1;
	WA[30].gx    = 0;
	WA[30].gp    = 0; //No parallax for now.
	WA[30].gy    = 0;
	WA[30].mx = 0;
	WA[30].mp = 0;
	WA[30].my = 0;
	WA[30].w = 383;
	WA[30].h = 223;
	WA[30].ovr = 0;
	WA[30].param = 0;
	
	WA[29].head = WRLD_END;
	
}
예제 #16
0
int AudioStreamMPC::_read_file(void *p_dst,int p_bytes) {

	if (f)
		return f->get_buffer((uint8_t*)p_dst,p_bytes);

	DVector<uint8_t>::Read r = data.read();
	if (p_bytes+data_ofs > streamlen) {
		p_bytes=streamlen-data_ofs;
	}

	copymem(p_dst,&r[data_ofs],p_bytes);
	//print_line("read file: "+itos(p_bytes));
	data_ofs+=p_bytes;
	return p_bytes;
}
예제 #17
0
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {

	if (p_bytes <= 0)
		return OK;

	if (pointer + p_bytes > data.size()) {
		data.resize(pointer + p_bytes);
	}

	DVector<uint8_t>::Write w = data.write();
	copymem(&w[pointer], p_data, p_bytes);

	pointer += p_bytes;
	return OK;
}
예제 #18
0
파일: export.cpp 프로젝트: 9cat/godot
void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& icon) {


	Ref<ImageTexture> it = memnew( ImageTexture );
	int size=512;

	Vector<uint8_t> data;

	data.resize(8);
	data[0]='i';
	data[1]='c';
	data[2]='n';
	data[3]='s';

	const char *name[]={"ic09","ic08","ic07","icp6","icp5","icp4"};
	int index=0;

	while(size>=16) {

		Image copy = p_icon;
		copy.convert(Image::FORMAT_RGBA);
		copy.resize(size,size);
		it->create_from_image(copy);
		String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/icon.png";
		ResourceSaver::save(path,it);

		FileAccess *f = FileAccess::open(path,FileAccess::READ);
		ERR_FAIL_COND(!f);

		int ofs = data.size();
		uint32_t len = f->get_len();
		data.resize(data.size()+len+8);
		f->get_buffer(&data[ofs+8],len);
		memdelete(f);
		len+=8;
		len=BSWAP32(len);
		copymem(&data[ofs],name[index],4);
		encode_uint32(len,&data[ofs+4]);
		index++;
		size/=2;
	}

	uint32_t total_len = data.size();
	total_len = BSWAP32(total_len);
	encode_uint32(total_len,&data[4]);

	icon=data;
}
예제 #19
0
int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const {

	ERR_FAIL_COND_V(!data, -1);

	int left = length - pos;
	int read = MIN(p_length, left);

	if (read < p_length) {
		WARN_PRINT("Reading less data than requested");
	};

	copymem(p_dst, &data[pos], read);
	pos += p_length;

	return read;
};
예제 #20
0
파일: export.cpp 프로젝트: nakoff/godot
void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {

	Ref<ImageTexture> it = memnew(ImageTexture);
	int size = 512;

	Vector<uint8_t> data;

	data.resize(8);
	data[0] = 'i';
	data[1] = 'c';
	data[2] = 'n';
	data[3] = 's';

	const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
	int index = 0;

	while (size >= 16) {

		Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
		copy->convert(Image::FORMAT_RGBA8);
		copy->resize(size, size);
		it->create_from_image(copy);
		String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
		ResourceSaver::save(path, it);

		FileAccess *f = FileAccess::open(path, FileAccess::READ);
		ERR_FAIL_COND(!f);

		int ofs = data.size();
		uint32_t len = f->get_len();
		data.resize(data.size() + len + 8);
		f->get_buffer(&data[ofs + 8], len);
		memdelete(f);
		len += 8;
		len = BSWAP32(len);
		copymem(&data[ofs], name[index], 4);
		encode_uint32(len, &data[ofs + 4]);
		index++;
		size /= 2;
	}

	uint32_t total_len = data.size();
	total_len = BSWAP32(total_len);
	encode_uint32(total_len, &data[4]);

	p_data = data;
}
예제 #21
0
Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {

	if (pointer + p_bytes > data.size()) {
		r_received = data.size() - pointer;
		if (r_received <= 0) {
			r_received = 0;
			return OK; //you got 0
		}
	} else {
		r_received = p_bytes;
	}

	DVector<uint8_t>::Read r = data.read();
	copymem(p_buffer, r.ptr() + pointer, r_received);

	pointer += r_received;
	// FIXME: return what? OK or ERR_*
}
예제 #22
0
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode) {

	switch(p_mode) {
		case MODE_FASTLZ: {

			if (p_src_size<16) {
				uint8_t src[16];
				zeromem(&src[p_src_size],16-p_src_size);
				copymem(src,p_src,p_src_size);
				return fastlz_compress(src,16,p_dst);
			} else {
				return fastlz_compress(p_src,p_src_size,p_dst);
			}

		} break;
		case MODE_DEFLATE: {

			z_stream strm;
			strm.zalloc = zipio_alloc;
			strm.zfree = zipio_free;
			strm.opaque = Z_NULL;
			int err = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
			if (err!=Z_OK)
			    return -1;

			strm.avail_in=p_src_size;
			int aout = deflateBound(&strm,p_src_size);;
			/*if (aout>p_src_size) {
				deflateEnd(&strm);
				return -1;
			}*/
			strm.avail_out=aout;
			strm.next_in=(Bytef*)p_src;
			strm.next_out=p_dst;
			deflate(&strm,Z_FINISH);
			aout = aout - strm.avail_out;
			deflateEnd(&strm);
			return aout;

		} break;
	}

	ERR_FAIL_V(-1);
}
예제 #23
0
void *memcpy(void *dest, const void *src, size_t n)
{
   if (n > 3) {
     if (!((long)dest & 1)) {
       if (!((long)src & 1)) {
          copymem_aligned(src, dest, n);
          return dest;
       }
     } else if ((long)src & 1) {
       *((char *)dest)++ = *((const char *)src)++;
       copymem_aligned(src, dest, n - 1);
       return (char *)dest - 1;
     }
   }

   copymem(src, dest, n);

   return dest;
}
예제 #24
0
파일: marshalls.cpp 프로젝트: jejung/godot
static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {

	CharString utf8 = p_string.utf8();

	if (buf) {
		encode_uint32(utf8.length(), buf);
		buf += 4;
		copymem(buf, utf8.get_data(), utf8.length());
		buf += utf8.length();
	}

	r_len += 4 + utf8.length();
	while (r_len % 4) {
		r_len++; //pad
		if (buf) {
			buf++;
		}
	}
}
예제 #25
0
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode){

	switch(p_mode) {
		case MODE_FASTLZ: {

			int ret_size=0;

			if (p_dst_max_size<16) {
				uint8_t dst[16];
				ret_size = fastlz_decompress(p_src,p_src_size,dst,16);
				copymem(p_dst,dst,p_dst_max_size);
			} else {
				ret_size = fastlz_decompress(p_src,p_src_size,p_dst,p_dst_max_size);
			}
			return ret_size;
		} break;
		case MODE_DEFLATE: {

			z_stream strm;
			strm.zalloc = zipio_alloc;
			strm.zfree = zipio_free;
			strm.opaque = Z_NULL;
			strm.avail_in= 0;
			strm.next_in=Z_NULL;
			int err = inflateInit(&strm);
			ERR_FAIL_COND_V(err!=Z_OK,-1);

			strm.avail_in=p_src_size;
			strm.avail_out=p_dst_max_size;
			strm.next_in=(Bytef*)p_src;
			strm.next_out=p_dst;

			err = inflate(&strm,Z_FINISH);
			int total = strm.total_out;
			inflateEnd(&strm);
			ERR_FAIL_COND_V(err!=Z_STREAM_END,-1);
			return total;
		} break;
	}

	ERR_FAIL_V(-1);
}
void VideoStreamTheoraplayer::pop_frame(Ref<ImageTexture> p_tex) {

	if (!clip)
		return;

	TheoraVideoFrame* f = clip->getNextFrame();
	if (!f) {
		return;
	};

	float w=clip->getWidth(),h=clip->getHeight();
	int imgsize = w * h * f->mBpp;

	int size = f->getStride() * f->getHeight() * f->mBpp;
	data.resize(imgsize);
	{
		DVector<uint8_t>::Write wr = data.write();
		uint8_t* ptr = wr.ptr();
		copymem(ptr, f->getBuffer(), imgsize);
	}
    /*
    for (int i=0; i<h; i++) {
        int dstofs = i * w * f->mBpp;
        int srcofs = i * f->getStride() * f->mBpp;
        copymem(ptr + dstofs, f->getBuffer() + dstofs, w * f->mBpp);
    };
     */
	Image frame = Image();
	frame.create(w, h, 0, f->mBpp == 3 ? Image::FORMAT_RGB : Image::FORMAT_RGBA, data);

	clip->popFrame();

	if (p_tex->get_width() == 0) {
		p_tex->create(frame.get_width(),frame.get_height(),frame.get_format(),Texture::FLAG_VIDEO_SURFACE|Texture::FLAG_FILTER);
		p_tex->set_data(frame);
	} else {

		p_tex->set_data(frame);
	};
};
예제 #27
0
static PoolVector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quality) {

	ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), PoolVector<uint8_t>());

	Ref<Image> img = p_image->duplicate();
	if (img->detect_alpha())
		img->convert(Image::FORMAT_RGBA8);
	else
		img->convert(Image::FORMAT_RGB8);

	Size2 s(img->get_width(), img->get_height());
	PoolVector<uint8_t> data = img->get_data();
	PoolVector<uint8_t>::Read r = data.read();

	uint8_t *dst_buff = NULL;
	size_t dst_size = 0;
	if (img->get_format() == Image::FORMAT_RGB8) {

		dst_size = WebPEncodeRGB(r.ptr(), s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
	} else {
		dst_size = WebPEncodeRGBA(r.ptr(), s.width, s.height, 4 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
	}

	ERR_FAIL_COND_V(dst_size == 0, PoolVector<uint8_t>());
	PoolVector<uint8_t> dst;
	dst.resize(4 + dst_size);
	PoolVector<uint8_t>::Write w = dst.write();
	w[0] = 'W';
	w[1] = 'E';
	w[2] = 'B';
	w[3] = 'P';
	copymem(&w[4], dst_buff, dst_size);
	free(dst_buff);
	w = PoolVector<uint8_t>::Write();
	return dst;
}
예제 #28
0
void VideoStreamPlaybackTheora::set_file(const String &p_file) {

	ERR_FAIL_COND(playing);
	ogg_packet op;
	th_setup_info *ts = NULL;

	file_name = p_file;
	if (file) {
		memdelete(file);
	}
	file = FileAccess::open(p_file, FileAccess::READ);
	ERR_FAIL_COND(!file);

#ifdef THEORA_USE_THREAD_STREAMING
	thread_exit = false;
	thread_eof = false;
	//pre-fill buffer
	int to_read = ring_buffer.space_left();
	int read = file->get_buffer(read_buffer.ptr(), to_read);
	ring_buffer.write(read_buffer.ptr(), read);

	thread = Thread::create(_streaming_thread, this);

#endif

	ogg_sync_init(&oy);

	/* init supporting Vorbis structures needed in header parsing */
	vorbis_info_init(&vi);
	vorbis_comment_init(&vc);

	/* init supporting Theora structures needed in header parsing */
	th_comment_init(&tc);
	th_info_init(&ti);

	theora_eos = false;
	vorbis_eos = false;

	/* Ogg file open; parse the headers */
	/* Only interested in Vorbis/Theora streams */
	int stateflag = 0;

	int audio_track_skip = audio_track;

	while (!stateflag) {
		int ret = buffer_data();
		if (ret == 0) break;
		while (ogg_sync_pageout(&oy, &og) > 0) {
			ogg_stream_state test;

			/* is this a mandated initial header? If not, stop parsing */
			if (!ogg_page_bos(&og)) {
				/* don't leak the page; get it into the appropriate stream */
				queue_page(&og);
				stateflag = 1;
				break;
			}

			ogg_stream_init(&test, ogg_page_serialno(&og));
			ogg_stream_pagein(&test, &og);
			ogg_stream_packetout(&test, &op);

			/* identify the codec: try theora */
			if (!theora_p && th_decode_headerin(&ti, &tc, &ts, &op) >= 0) {
				/* it is theora */
				copymem(&to, &test, sizeof(test));
				theora_p = 1;
			} else if (!vorbis_p && vorbis_synthesis_headerin(&vi, &vc, &op) >= 0) {

				/* it is vorbis */
				if (audio_track_skip) {
					vorbis_info_clear(&vi);
					vorbis_comment_clear(&vc);
					ogg_stream_clear(&test);
					vorbis_info_init(&vi);
					vorbis_comment_init(&vc);

					audio_track_skip--;
				} else {
					copymem(&vo, &test, sizeof(test));
					vorbis_p = 1;
				}
			} else {
				/* whatever it is, we don't care about it */
				ogg_stream_clear(&test);
			}
		}
		/* fall through to non-bos page parsing */
	}

	/* we're expecting more header packets. */
	while ((theora_p && theora_p < 3) || (vorbis_p && vorbis_p < 3)) {
		int ret;

		/* look for further theora headers */
		while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout(&to, &op))) {
			if (ret < 0) {
				fprintf(stderr, "Error parsing Theora stream headers; "
								"corrupt stream?\n");
				clear();
				return;
			}
			if (!th_decode_headerin(&ti, &tc, &ts, &op)) {
				fprintf(stderr, "Error parsing Theora stream headers; "
								"corrupt stream?\n");
				clear();
				return;
			}
			theora_p++;
		}

		/* look for more vorbis header packets */
		while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(&vo, &op))) {
			if (ret < 0) {
				fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n");
				clear();
				return;
			}
			ret = vorbis_synthesis_headerin(&vi, &vc, &op);
			if (ret) {
				fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n");
				clear();
				return;
			}
			vorbis_p++;
			if (vorbis_p == 3) break;
		}

		/* The header pages/packets will arrive before anything else we
		care about, or the stream is not obeying spec */

		if (ogg_sync_pageout(&oy, &og) > 0) {
			queue_page(&og); /* demux into the appropriate stream */
		} else {
			int ret = buffer_data(); /* someone needs more data */
			if (ret == 0) {
				fprintf(stderr, "End of file while searching for codec headers.\n");
				clear();
				return;
			}
		}
	}

	/* and now we have it all.  initialize decoders */
	if (theora_p) {
		td = th_decode_alloc(&ti, ts);
		printf("Ogg logical stream %lx is Theora %dx%d %.02f fps",
				to.serialno, ti.pic_width, ti.pic_height,
				(double)ti.fps_numerator / ti.fps_denominator);
		px_fmt = ti.pixel_fmt;
		switch (ti.pixel_fmt) {
			case TH_PF_420: printf(" 4:2:0 video\n"); break;
			case TH_PF_422: printf(" 4:2:2 video\n"); break;
			case TH_PF_444: printf(" 4:4:4 video\n"); break;
			case TH_PF_RSVD:
			default:
				printf(" video\n  (UNKNOWN Chroma sampling!)\n");
				break;
		}
		if (ti.pic_width != ti.frame_width || ti.pic_height != ti.frame_height)
			printf("  Frame content is %dx%d with offset (%d,%d).\n",
					ti.frame_width, ti.frame_height, ti.pic_x, ti.pic_y);
		th_decode_ctl(td, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max,
				sizeof(pp_level_max));
		pp_level = 0;
		th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, sizeof(pp_level));
		pp_inc = 0;

		int w;
		int h;
		w = (ti.pic_x + ti.frame_width + 1 & ~1) - (ti.pic_x & ~1);
		h = (ti.pic_y + ti.frame_height + 1 & ~1) - (ti.pic_y & ~1);
		size.x = w;
		size.y = h;

		texture->create(w, h, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE);

	} else {
		/* tear down the partial theora setup */
		th_info_clear(&ti);
		th_comment_clear(&tc);
	}

	th_setup_free(ts);

	if (vorbis_p) {
		vorbis_synthesis_init(&vd, &vi);
		vorbis_block_init(&vd, &vb);
		fprintf(stderr, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.\n",
				vo.serialno, vi.channels, vi.rate);
		//_setup(vi.channels, vi.rate);

	} else {
		/* tear down the partial vorbis setup */
		vorbis_info_clear(&vi);
		vorbis_comment_clear(&vc);
	}

	playing = false;
	buffering = true;
	time = 0;
	audio_frames_wrote = 0;
};
예제 #29
0
파일: Plugin.c 프로젝트: kichik/nsis-1
HANDLE GlobalCopy(HANDLE Old)
{
    size_t size = GlobalSize(Old);
    return copymem(GlobalAlloc(GPTR, size), Old, size);
}
예제 #30
0
파일: http_client.cpp 프로젝트: Ace17/godot
ByteArray HTTPClient::read_response_body_chunk() {

	ERR_FAIL_COND_V( status !=STATUS_BODY, ByteArray() );

	Error err=OK;

	if (chunked) {

		while(true) {

			if (chunk_left==0) {
				//reading len
				uint8_t b;
				int rec=0;
				err = connection->get_partial_data(&b,1,rec);

				if (rec==0)
					break;

				chunk.push_back(b);

				if (chunk.size()>32) {
					ERR_PRINT("HTTP Invalid chunk hex len");
					status=STATUS_CONNECTION_ERROR;
					return ByteArray();
				}

				if (chunk.size()>2 && chunk[chunk.size()-2]=='\r' && chunk[chunk.size()-1]=='\n') {

					int len=0;
					for(int i=0;i<chunk.size()-2;i++) {
						char c = chunk[i];
						int v=0;
						if (c>='0' && c<='9')
							v=c-'0';
						else if (c>='a' && c<='f')
							v=c-'a'+10;
						else if (c>='A' && c<='F')
							v=c-'A'+10;
						else {
							ERR_PRINT("HTTP Chunk len not in hex!!");
							status=STATUS_CONNECTION_ERROR;
							return ByteArray();
						}
						len<<=4;
						len|=v;
						if (len>(1<<24)) {
							ERR_PRINT("HTTP Chunk too big!! >16mb");
							status=STATUS_CONNECTION_ERROR;
							return ByteArray();
						}

					}

					if (len==0) {
						//end!
						status=STATUS_CONNECTED;
						chunk.clear();
						return ByteArray();
					}

					chunk_left=len+2;
					chunk.resize(chunk_left);

				}
			} else {

				int rec=0;
				err = connection->get_partial_data(&chunk[chunk.size()-chunk_left],chunk_left,rec);
				if (rec==0) {
					break;
				}
				chunk_left-=rec;

				if (chunk_left==0) {

					if (chunk[chunk.size()-2]!='\r' || chunk[chunk.size()-1]!='\n') {
						ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)");
						status=STATUS_CONNECTION_ERROR;
						return ByteArray();
					}

					ByteArray ret;
					ret.resize(chunk.size()-2);
					{
						ByteArray::Write w = ret.write();
						copymem(w.ptr(),chunk.ptr(),chunk.size()-2);
					}
					chunk.clear();

					return ret;

				}

				break;
			}
		}

	} else {
		ByteArray ret;
		ret.resize(MAX(body_left,tmp_read.size()));
		ByteArray::Write w = ret.write();
		int _offset = 0;
		while (body_left > 0) {
			ByteArray::Write r = tmp_read.write();
			int rec=0;
			err = connection->get_partial_data(r.ptr(),MIN(body_left,tmp_read.size()),rec);
			if (rec>0) {
				copymem(w.ptr()+_offset,r.ptr(),rec);
				body_left-=rec;
				_offset += rec;
			}
		}
		if (body_left==0) {
			status=STATUS_CONNECTED;
		}
		return ret;

	}


	if (err!=OK) {
		close();
		if (err==ERR_FILE_EOF) {

			status=STATUS_DISCONNECTED; //server disconnected
		} else {

			status=STATUS_CONNECTION_ERROR;
		}
	} else if (body_left==0 && !chunked) {

		status=STATUS_CONNECTED;
	}

	return ByteArray();
}