예제 #1
0
void test_read_int_and_uint() {
	char* buffer_ptr = NULL;
	size_t buffer_size = 0, pos = 0;
	FILE* f = open_memstream(&buffer_ptr, &buffer_size);
		ebml_element_uint(f, MKV_TimecodeScale, 0x0102030405060708);
		ebml_element_int(f, MKV_TimecodeScale, -1000000);
		ebml_element_int(f, MKV_TimecodeScale, 1000000);
	fclose(f);
	
	ebml_elem_t e = ebml_read_element(buffer_ptr, buffer_size, &pos);
	check(e.id == MKV_TimecodeScale);
	check_int(e.header_size, 3 + 1);
	
	uint64_t uvalue = ebml_read_uint(e.data_ptr, e.data_size);
	check_int(uvalue, 0x0102030405060708);
	
	e = ebml_read_element(buffer_ptr, buffer_size, &pos);
	check(e.id == MKV_TimecodeScale);
	
	int64_t ivalue = ebml_read_int(e.data_ptr, e.data_size);
	check_int(ivalue, -1000000);
	
	e = ebml_read_element(buffer_ptr, buffer_size, &pos);
	check(e.id == MKV_TimecodeScale);
	
	ivalue = ebml_read_int(e.data_ptr, e.data_size);
	check_int(ivalue, 1000000);
	
	free(buffer_ptr);
}
예제 #2
0
static int
demux_mkv_read_block(FILE *s, mkv_demuxer_t *mkv_d)
{
	uint64_t length, l;
	int il, tmp;
	uint64_t block_duration = 0,  block_length = 0;
	int64_t block_bref = 0, block_fref = 0;
	uint8_t *block = NULL;

	length = ebml_read_length (s, NULL);
	while (length > 0)
	{
		switch (ebml_read_id (s, &il))
		{
			case MATROSKA_ID_BLOCKDURATION:
				//puts("MATROSKA_ID_BLOCKDURATION");
				block_duration = ebml_read_uint (s, &l);
				if (block_duration == EBML_UINT_INVALID) {
					if(block)
						free(block);
					return 0;
				}
				block_duration *= mkv_d->tc_scale / 1000000.0;
				break;
			case MATROSKA_ID_BLOCK:
				//puts("MATROSKA_ID_BLOCK");
				block_length = ebml_read_length (s, &tmp);
				if(block)
					free(block);
				if (block_length > SIZE_MAX - AV_LZO_INPUT_PADDING) return 0;
				block = (uint8_t *)malloc (block_length + AV_LZO_INPUT_PADDING);
				if (!block)
				{
					return 0;
				}
				if (fread(block, 1, (size_t)block_length, s) != (size_t) block_length)
				{
					if(block)
						free(block);
					return 0;
				}
				l = tmp + block_length;
				break;
			case MATROSKA_ID_REFERENCEBLOCK:
				//puts("MATROSKA_ID_REFERENCEBLOCK");
				{
					int64_t num = ebml_read_int (s, &l);
					if (num == EBML_INT_INVALID) {
						if(block)
							free(block);
						return 0;
					}
					if (num <= 0)
						block_bref = num;
					else
						block_fref = num;
					break;
				}
			case EBML_ID_INVALID:
				//puts("EBML_ID_INVALID");
				if(block)
					free(block);
				return 0;
			default:
				ebml_read_skip (s, &l);
				break;
		}
		length -= l + il;

		if (block)
		{
			handle_block (mkv_d, block, block_length,
					block_duration, block_bref, block_fref, 0);
			free (block);
			block = NULL;
		}
	}
	return 0;
}