Exemple #1
0
/*load a piece of the file into piece */
int load_piece(bt_args_t *bt_args, bt_piece_t *piece_t){
	int fd = create_file_descriptor(bt_args->save_file);
	size_t len = bt_args->bt_info->piece_length;
	void * ptr = malloc(len);
	int load = load_data_from_file(ptr, len - piece_t->begin, piece_t->index*len+ piece_t->begin, fd, bt_args->save_file);
	memcpy(piece_t->piece, ptr, len);
	return load;
}
Exemple #2
0
void load_geom(int argc, char* argv[])
{
  assert(argc==3);
  const char* file_off = argv[1];
  const char* file_res = argv[2];

  // initialisation du maillage
  std::ifstream f(file_off, std::ifstream::in);
  if(!f){
      exit(0);
    }
  f >> m_mesh;
  m_mesh.compute_normals();

  // init of the ppal dir
  ppal_data.clear();
  load_data_from_file(ppal_data, file_res);

}
int main(){
    auto data_path = std::getenv("OBI_DATA");
    if(!data_path){
        std::cout << "OBI_DATA environment variable is not set!"  << std::endl;
        return 1;
    }

    rocksdb::DB* db = nullptr;
    rocksdb::Options options;
    options.create_if_missing = true;
    std::cout << "loading database" << std::endl;
    rocksdb::Status status = rocksdb::DB::Open(options, std::string(data_path) + std::string("/rocksdb-data"), &db);
    assert(status.ok());

    bool load_from_disk = false;
    if (load_from_disk){
        if (!load_data_from_file(db, std::string(data_path) + std::string("/data30GB.txt"))){
            return 1;
        }
    }

    std::size_t number_of_requests = 300 * 1000 *1000;

    std::cout << "next_key_max_all:" << std::endl;
    std::cout << "first  run warum up: " << std::endl
              << "seconds taken: " << run_test(db, &next_key_max_all, number_of_requests) << std::endl;
    std::cout << "second - real test:  " << std::endl
              << "seconds taken: " << run_test(db, &next_key_max_all, number_of_requests) << std::endl;
    std::cout << "third - real test:  " << std::endl
              << "seconds taken: " << run_test(db, &next_key_max_all, number_of_requests) << std::endl;


    //std::cout << std::endl << "next_key_max_2:" << std::endl;
    //std::cout << "first  run warum up: " << std::endl
    //          << "seconds taken: " << run_test(db, &next_key_max_1 ,300000000) << std::endl;
    //std::cout << "second - real test:  " << std::endl
    //          << "seconds taken: " << run_test(db, &next_key_max_1, 300000000) << std::endl;

    delete db;
    return 0;
}
Exemple #4
0
int wav_media_get_data(void* context, file_handle_t* handle, file_source_t* source, media_stats_t* stats, int piece, media_data_t* output_buffer, int output_buffer_size ){
	int start;
	int stop;
	int n_frames;

	track_data_t* tdata;
	track_data_t* vdata;
	media_data_t* mdata;
	char* ptr;
	int* size;
	int* offset;
	char* buf;

	char raw_wave_data[1152 * 2 * 2];
	char frame_data[1152 * 2 * 2];
	int n_out_frames;
	int n_out_bytes;
	int i;
	lame_global_flags* encopts = 0;
	int n_ch;
	int sample_rate;
	int encoding_sample_rate;
	int bit_per_sample;
	int data_offset;
	int type;
	int n_video_frames;
	char* video_logo_filename = get_logo_filename();
	int video_frame_size = 0;
	int r;

	int ef = 4;

	n_frames = get_frames_in_piece(stats, piece, 0, &start, &stop, 10);
	video_frame_size = parse_video_file(video_logo_filename, &n_video_frames);


	if ( !output_buffer || !output_buffer_size ){
		return (stats->track[0]->pts[stop] - stats->track[0]->pts[start] + 0.5) * stats->track[0]->bitrate / 8 +
				sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int) + (n_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int) + video_frame_size;
	}

	ptr = output_buffer;

	mdata = output_buffer;
	tdata = (media_data_t*)(ptr + sizeof(media_data_t));
	vdata = (media_data_t*)(ptr + sizeof(media_data_t) + sizeof(track_data_t));

	size   = (int*)(ptr + sizeof(media_data_t) + sizeof(track_data_t) * 2);
	offset = (int*)(ptr + sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int));

	mdata->n_tracks = 2;
	mdata->track_data[0] = tdata;
	mdata->track_data[1] = vdata;

	buf = (char*)(ptr + sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int) + (n_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int));

	tdata->buffer = buf;
	tdata->offset = offset;
	tdata->size   = size;

	n_out_bytes 	= 0;
	n_out_frames 	= 0;

	sample_rate 	= stats->track[0]->sample_rate;
	n_ch 			= stats->track[0]->n_ch;
	bit_per_sample 	= stats->track[0]->sample_size;
	data_offset		= stats->track[0]->data_start_offset;
	type			= stats->track[0]->type;


	encoding_sample_rate = get_close_rate(sample_rate);

#ifdef TWO_LAME


#else
//	encopts = lame_init();
//
//	r = lame_set_num_channels(encopts, n_ch);
//
//	/* sample rate */
//	r = lame_set_in_samplerate (encopts, encoding_sample_rate);
//	r = lame_set_out_samplerate(encopts, encoding_sample_rate);
//
//	/* algorithmic quality */
//	r = lame_set_quality(encopts, 8);
//
//	r = lame_set_mode(encopts, n_ch > 1 ? JOINT_STEREO : MONO);
//
//	/* rate control */
//	r = lame_set_padding_type(encopts, PAD_ALL);
//
//	r = lame_set_num_channels(encopts, n_ch);
////	lame_set_no_short_blocks(encopts, 1);
//
//	r = lame_set_VBR(encopts, vbr_off);
//
//	r = lame_set_brate(encopts, stats->track[0]->bitrate / 1000);
//
//	if (lame_init_params(encopts) == 0){
//		int frame_size = lame_get_framesize(encopts);
//
//		for(i = start; i < stop; ++i){
//			int n_samples = get_samples(handle, source, i * frame_size / (double)encoding_sample_rate, (i + 1) * frame_size / (double)encoding_sample_rate,
//										 raw_wave_data, sample_rate, n_ch, bit_per_sample, data_offset, type);
//
//			decode_wave(raw_wave_data, n_samples, frame_data, sample_rate, encoding_sample_rate, n_ch, bit_per_sample, type);
//
//			if (n_ch > 1){
//				n_out_bytes += lame_encode_buffer_interleaved(	encopts, (short*)(frame_data), frame_size, (unsigned char*)tdata->buffer + n_out_bytes, output_buffer_size - n_out_bytes );
//			}else{
//				n_out_bytes += lame_encode_buffer(	encopts, (short*)(frame_data), 0, frame_size, (unsigned char*)tdata->buffer + n_out_bytes, output_buffer_size - n_out_bytes );
//			}
//		}
//
//		n_out_bytes += lame_encode_flush(encopts,        tdata->buffer + n_out_bytes, output_buffer_size - n_out_bytes);
//
//		lame_close(encopts);
//	}
#endif

	tdata->first_frame  	= start;
	tdata->n_frames			= get_num_of_mp3_frames(tdata->buffer, n_out_bytes, encoding_sample_rate, stats->track[0]->bitrate, size, offset);
	tdata->buffer_size		= n_out_bytes;
	tdata->cc 				= 0;
	tdata->frames_written 	= 0;

	vdata->size 			= (char*)(ptr + sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int) + (n_frames + ef) * sizeof(int));
	vdata->offset 			= (char*)(ptr + sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int) + (n_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int));

	vdata->buffer 			= tdata->buffer + tdata->buffer_size;
	vdata->buffer_size 		= vdata->size[0] = load_data_from_file(vdata->buffer, video_frame_size, video_logo_filename);
	vdata->offset[0] 		= 0;
	vdata->cc 				= 0;
	vdata->frames_written 	= 0;
	vdata->first_frame 		= 0;
	vdata->n_frames 		= 1;

	return 	sizeof(media_data_t) + sizeof(track_data_t) * 2 + (n_frames + ef) * sizeof(int) + (n_frames + ef) * sizeof(int) +
			(n_video_frames + ef) * sizeof(int) + (n_video_frames + ef) * sizeof(int) + vdata->buffer_size + tdata->buffer_size;
}
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{
char filename[256];
mxArray *pa1;
mxArray **mat_elem;
double *matData;
const char *field_name[20] = {"name","data"};
int i,j,count;
HEADER_FRAME *first_header_frame;
DATA_FRAME *first_data_frame, *cur_data_frame;
NAME_LIST *first_sig_name, *cur_sig_name;
int num_sigs,num_samples;

first_data_frame = init_data_frame();
first_header_frame = init_header_frame();
first_sig_name = init_name_list();


if (nrhs != 1)
  mexErrMsgTxt("Error: missing filename. Usage:  x = loadsig_cppsim('filename')");
if (!mxIsChar(prhs[0]))
  mexErrMsgTxt("Error: filename must be a string");
if (nlhs != 1)
  mexErrMsgTxt("Error: missing output variable.  Usage:  x = loadsig_cppsim('filename')");

mxGetString(prhs[0],filename,255);


if (load_data_from_file(filename,first_header_frame,first_data_frame,
                        &num_sigs, &num_samples) == -1)
    mexErrMsgTxt("File not read");

extract_signal_names(first_header_frame,num_sigs,first_sig_name);


/* write into MATLAB structure */
plhs[0] = mxCreateStructMatrix(num_sigs,1,2,field_name);


/* copy signal name */
cur_sig_name = first_sig_name;
for (i = 0; i < num_sigs; i++)
    {
     pa1 = mxCreateString(cur_sig_name->name);
     mxSetField(plhs[0],i,field_name[0],pa1);
     cur_sig_name = cur_sig_name->next;  
    }

/* copy data */
if ((mat_elem = (mxArray **) mxCalloc(num_sigs,sizeof(mxArray *))) == NULL)   
    {   
     mexPrintf("error in loadsig_cppsim:  calloc call failed - \n");   
     mexPrintf("  not enough memory!!\n");   
     return;   
    }   
for (i = 0; i < num_sigs; i++)   
     mat_elem[i] = mxCreateDoubleMatrix(num_samples,1,mxREAL);

cur_data_frame = first_data_frame;

count = 0;
for (j = 0; j < num_samples; j++)
  {
   for (i = 0; i < num_sigs; i++)
      {
	if (count == cur_data_frame->length)
	  {
	    cur_data_frame = cur_data_frame->next;
	    if (cur_data_frame == NULL)
	      {
		mexPrintf("error: data frame too short!\n");
		return;
	      }
            count = 0;
	  }
        matData = mxGetPr(mat_elem[i]);
	if (cur_data_frame->data_type == 32)
           matData[j] = cur_data_frame->fbuf[count];
        else
           matData[j] = cur_data_frame->dbuf[count];
        count++;
      }
  }

for (i = 0; i < num_sigs; i++)
    mxSetField(plhs[0],i,field_name[1],mat_elem[i]);

free_header_frames(first_header_frame);
free_data_frames(first_data_frame);
free_name_list(first_sig_name);


return;
}