Ejemplo n.º 1
0
	// translate
	//  basis -> old -> new -> target
	// to
	//  basis -> merge -> target
	void translate_chunks (DeltaSet* ds_old, DeltaSet* ds_new) {
		command_count = 0;
		chunks = NULL;
		delta_chunk t_chunk, out_chunk;
		size_t relative, len;

		for (int i = 0; i < ds_new->command_count; i++) {
			t_chunk = ds_new->chunks[i];
			switch (t_chunk.c_type) {
			case RS_KIND_LITERAL:
				out_chunk = t_chunk;

				trace("[%i LITERAL id(%i) %i %i] -> ", (int) out_chunk.start, out_chunk.sf_id, (int) out_chunk.sf_pos, (int) out_chunk.len);
				trace("%i LITERAL id(%i) %i %i\n", (int) out_chunk.start, out_chunk.sf_id, (int) out_chunk.sf_pos, (int) out_chunk.len);

				add_chunk(out_chunk);
				break;
			case RS_KIND_END:
				out_chunk = t_chunk;

				trace("%i END\n", (int) out_chunk.start);

				add_chunk(out_chunk);
				return;
				break;
			case RS_KIND_COPY:
				relative = 0;
				len = t_chunk.len;

				trace("[%i COPY %i %i] ->", (int) t_chunk.start, (int) t_chunk.sf_pos, (int) len);

				while (len > 0) {
					trace(" <%i", (int) (t_chunk.sf_pos + relative) );

					out_chunk = ds_old->find_chunk(t_chunk.sf_pos + relative, len);
					out_chunk.start = t_chunk.start + relative; // actual translation
					add_chunk(out_chunk);
					len -= out_chunk.len;
					relative += out_chunk.len;
#ifdef DEBUG
					switch (out_chunk.c_type) {
					case RS_KIND_LITERAL: trace(" %i LITERAL id(%i) %i %i\n", (int) out_chunk.start, out_chunk.sf_id, (int) out_chunk.sf_pos, (int) out_chunk.len); break;
					case RS_KIND_COPY: trace(" %i COPY %i %i\n", (int) out_chunk.start, (int) out_chunk.sf_pos, (int) out_chunk.len); break;
					case RS_KIND_END: trace(" %i END\n", (int) out_chunk.start); return; break;
					}
#endif
				}
				break;
			}
		}
	};
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////////
//响应chunk的ping包
void MasterServer::on_chunk_ping(SocketHandle socket_handle, Protocol *protocol)
{
	SFSProtocolFamily* protocol_family = (SFSProtocolFamily*)get_protocol_family();
	ProtocolChunkPingResp *protocol_chunkping_resp = (ProtocolChunkPingResp *)protocol_family->create_protocol(PROTOCOL_CHUNK_PING_RESP);
	assert(protocol_chunkping_resp);

	ProtocolChunkPing *protocol_chunkping = (ProtocolChunkPing *)protocol;
	ChunkInfo &chunk_info = protocol_chunkping->get_chunk_info();
	SLOG_INFO("receive chunk_ping protocol.fd=%d, chunk_id=%s, chunk_addr=%s, chunk_port=%d, disk_space=%lld, disk_used=%lld."
				,socket_handle
				,chunk_info.id.c_str()
				,chunk_info.ip.c_str()
				,chunk_info.port
				,chunk_info.disk_space
				,chunk_info.disk_used);

	if(chunk_info.id == "" || chunk_info.ip == "")
	{
		SLOG_ERROR("chunk id or ip is empty.");
		protocol_chunkping_resp->get_result() = false;
	}
	else
	{
		add_chunk(chunk_info);
		protocol_chunkping_resp->get_result() = true;
	}

	if(!send_protocol(socket_handle, protocol_chunkping_resp))
	{
		protocol_family->destroy_protocol(protocol_chunkping_resp);
		SLOG_ERROR("send protocol_chunkping_resp failed.fd=%d, chunk_id=%s.", socket_handle, chunk_info.id.c_str());
	}
}
Ejemplo n.º 3
0
    void string_builder::add(const char* s,int len)
    {
        if(!s)
            return;
        if(len==-1)
            len=strlen(s);
        if(!len)
            return;

        while(len>0)
        {
            int n=end?(chunk::max_size-end->size):0;

            if(n<=0)
            {
                if(add_chunk())
                    return;
                n=chunk::max_size;
            }

            int m=len>n?n:len;
            memcpy(end->ptr+end->size,s,m);
            end->size+=m;
            len-=m;
            s+=m;
        }
    }
Ejemplo n.º 4
0
// TODO: triple-check what happens when a writing fails in the
// middle of a serialization op.
static int sdb_bss_ram_writer( unsigned const char *data,  int length, sdb_table_t *tbl) {
  struct sdb_ram_storage_t *ram =& tbl->storage.ram;
  int written_in_chunk = tbl->nwrittenbytes % SDB_CHUNK_SIZE;
  int left_in_chunk = SDB_CHUNK_SIZE - written_in_chunk;
  if( length >= SDB_DATA_SIZE_LIMIT) {
      return SDB_ETOOBIG;
  } else if( left_in_chunk > length) { /* fits in current chunk. */
    int r, needed_size =  next_pow2( written_in_chunk + length);
    if( ram->last_chunk_size!=0 && ram->last_chunk_size<needed_size) {
        r = set_last_chunk_size( tbl, needed_size);
        if( r) return r;
    }
    memcpy( ram->last_chunk->data + written_in_chunk, data, length);
  } else { /* write across two chunks. */
    int r;
    struct sdb_chunk_t *chunk1, *chunk2;
    if( ram->last_chunk_size != 0) {
        r = set_last_chunk_size( tbl, SDB_CHUNK_SIZE); // 1st chunk to max size
        if( r) return r;
    }
    chunk1 = ram->last_chunk;
    r = add_chunk( ram, length - left_in_chunk);
    if( r) return SDB_EMEM;
    chunk2 = ram->last_chunk;
    memcpy( chunk1->data + written_in_chunk, data, left_in_chunk);
    memcpy( chunk2->data, data + left_in_chunk, length - left_in_chunk);
  }
  tbl->nwrittenbytes += length;
  return length;
}
Ejemplo n.º 5
0
int get_index_time_tivo(tystream_holder_t * tystream, gop_index_t * gop_index) {

	/* Iteration */
	int i;


	/* The chunk we read */
	chunk_t * chunk = NULL;

	/* The chunk linked list */
	chunk_t * chunks = NULL;

	/* vstream */
	vstream_t * vstream;

	int chunks_to_read;


	chunks_to_read = 2;

	/* Find out how many chunks we need to read
	if pes and i frame is in the same chunk then two chunks if not three chunks
	*/


	vstream = new_vstream();
	/* Lets fake it and do a read buffer */
	vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE);
	vstream->size = sizeof(uint8_t) * CHUNK_SIZE ;
	vstream->current_pos = vstream->start_stream;
	vstream->end_stream = vstream->start_stream + vstream->size;
	tystream->vstream = vstream;

	for(i=0; i < chunks_to_read; i++) {

		vstream->current_pos = vstream->start_stream;
		vstream->eof=0;
		read_a_chunk(infile, gop_index->chunk_number_i_frame_pes + i + tystream->start_chunk, vstream->start_stream);
		chunk_in_buf = gop_index->chunk_number_i_frame_pes + i + tystream->start_chunk;

		chunk = read_chunk(tystream, gop_index->chunk_number_i_frame_pes + i, 1);

		if(chunk) {
			chunks = add_chunk(tystream, chunk, chunks);
		} else {
			chunks_to_read++;
		}
	}

	free_vstream(vstream);
	tystream->vstream=NULL;

	gop_index->time_of_iframe = get_time_Y_video(gop_index->i_frame_pes_rec_nr, chunks, tystream);

	free_junk_chunks(chunks);

	return(1);
}
Ejemplo n.º 6
0
/*
 * finds what chunks the data points to, adds them to the chunk_list, 
 * and returns the length of the current chunk
 */
int get_chunks(ubyte *data, ubyte *new_data, chunk *list, int *no)
{
	short n;
	ubyte *p = data;

	while (INTEL_SHORT(w(p)) != OP_EOF) {
		switch (INTEL_SHORT(w(p))) {
		case OP_DEFPOINTS:
			n = INTEL_SHORT(w(p+2));
			p += n*sizeof(struct vms_vector) + 4;
			break;
		case OP_DEFP_START:
			n = INTEL_SHORT(w(p+2));
			p += n*sizeof(struct vms_vector) + 8;
			break;
		case OP_FLATPOLY:
			n = INTEL_SHORT(w(p+2));
			p += 30 + ((n&~1)+1)*2;
			break;
		case OP_TMAPPOLY:
			n = INTEL_SHORT(w(p+2));
			p += 30 + ((n&~1)+1)*2 + n*12;
			break;
		case OP_SORTNORM:
			add_chunk(p, p - data + new_data, 28, list, no);
			add_chunk(p, p - data + new_data, 30, list, no);
			p += 32;
			break;
		case OP_RODBM:
			p+=36;
			break;
		case OP_SUBCALL:
			add_chunk(p, p - data + new_data, 16, list, no);
			p+=20;
			break;
		case OP_GLOW:
			p += 4;
			break;
		default:
			Error("invalid polygon model\n");
		}
	}
	return p + 2 - data;
}
Ejemplo n.º 7
0
	// read delta file
	void read_commands (FILE* fi, int file_id) {
		unsigned char buf[4];
		command_count = 0;
		chunks = NULL;
		size_t fo_pos = 0;
		delta_chunk t_chunk;
		size_t parm1, parm2;

		fread(&buf, 4, 1, fi); // header

		while ( fread(&buf, 1, 1, fi) > 0 ) {
			cmd = buf[0];

			rs_prototab_ent cmd_data = rs_prototab[cmd];

			t_chunk.c_type = cmd_data.kind;
			t_chunk.start = fo_pos;
			t_chunk.len = 0;
			t_chunk.sf_id = 0;
			t_chunk.sf_pos = 0;

			switch (cmd_data.kind) {
			case RS_KIND_LITERAL:
				parm1 = read_parm(fi, cmd_data.len_1);

				trace("%i LITERAL %i | ", (int) fo_pos, (int) parm1);

				t_chunk.len = parm1;
				t_chunk.sf_id = file_id;
				t_chunk.sf_pos = ftell(fi);
				fseek(fi, parm1, SEEK_CUR);
				fo_pos += t_chunk.len;
				break;
			case RS_KIND_COPY:
				parm1 = read_parm(fi, cmd_data.len_1);
				parm2 = read_parm(fi, cmd_data.len_2);

				trace("%i COPY %i %i | ", (int) fo_pos, (int) parm1, (int) parm2);

				t_chunk.sf_pos = parm1;
				t_chunk.len = parm2;
				fo_pos += t_chunk.len;
				break;
			case RS_KIND_END:
				trace("%i END", (int) fo_pos);
				break;
			default: // unknown
				fprintf(stderr, "ERROR: unknown command %i\n", cmd);
				throw new int;
			}
			
			add_chunk(t_chunk);
		}
	};
Ejemplo n.º 8
0
                /**
                 * Add a null terminated string to the store. This will
                 * automatically get more memory if we are out.
                 * Returns a pointer to the copy of the string we have
                 * allocated.
                 */
                const char* add(const char* string) {
                    size_t len = std::strlen(string) + 1;

                    assert(len <= m_chunk_size);

                    size_t chunk_len = m_chunks.back().size();
                    if (chunk_len + len > m_chunks.back().capacity()) {
                        add_chunk();
                        chunk_len = 0;
                    }

                    m_chunks.back().append(string);
                    m_chunks.back().append(1, '\0');

                    return m_chunks.back().c_str() + chunk_len;
                }
Ejemplo n.º 9
0
Archivo: key.c Proyecto: RAttab/ilka
static void
reserve(struct ilka_key *key, size_t size)
{
    if (key->size >= size) return;

    size_t diff = size - key->size;
    size_t pos = size % ILKA_KEY_CHUNK_SIZE;
    size_t avail = ILKA_KEY_CHUNK_SIZE - pos;

    while (diff > avail) {
        add_chunk(key->last);
        key->last = key->last->next;

        diff -= avail;
        avail = ILKA_KEY_CHUNK_SIZE;
    }
}
Ejemplo n.º 10
0
  char *alloc(size_t size) {
    if ((size_t)(m_chunk_end - m_unused_p) < size) {
      while ((++m_chunk_iter) != m_chunks.end()) {
        if (m_chunk_iter->size() >= size) {
          m_unused_p = m_chunk_iter->begin() + size;
          m_chunk_end = m_chunk_iter->end();
          return m_chunk_iter->begin();
        }
      }

      add_chunk(size);
    }

    char *p = m_unused_p;
    m_unused_p += size;
    return p;
  }
void process_dir( const char* c ) {
  //printf("Processing %s\n", c) ;
  DIR* d = opendir( c ) ;

  struct dirent* e;
  while (  (e=readdir(d)) ) {
    // skip dot, dot-dot
    if ( !strcmp(e->d_name,"." ) ) continue;
    if ( !strcmp(e->d_name,".." ) ) continue;
    // skip player info
    if ( !strcmp(e->d_name,"level.dat" ) ) continue;
    // only directories and .dat files

    if ( e->d_type == DT_DIR ) {
        int len = strlen(c) + 1 + strlen(e->d_name) + 1 ;
        char *f = (char*)malloc(sizeof(char)*len);
        strcpy(f,c);
        strcat(f,"/");
        strcat(f,e->d_name);
        process_dir(f);
        free(f);
        continue;
    }

    if ( !strstr(e->d_name+strlen(e->d_name)-4, ".dat" )) continue ;

    // ok, we have a file to process
    char* fname = (char*)malloc(sizeof(char)*(strlen(c)+strlen(e->d_name)+2));
    strcpy(fname,c) ; strcat(fname,"/") ; strcat(fname,e->d_name);
    Named_Tag* n = process_file(fname);
    first_file = 0 ;

    //print_named_tag( n ) ;
    //printf("\n");
    //printf("%s: %i %i\n", fname, current_x, current_z) ;

    add_chunk( current_x, current_z, current_chunk ) ;

    free(fname);
    NT_dispose(n);
    //printf("%s\n", e->d_name ) ;
  }

        closedir(d);
}
Ejemplo n.º 12
0
  void CodeManager::add_resource(CodeResource* cr) {
    utilities::thread::Mutex::LockGuard guard(mutex_);

    total_allocated_ += cr->size();
    bytes_used_ += cr->size();

    for(;;) {
      while(current_index_ < chunk_size_) {
        if(current_chunk_->resources[current_index_] == 0) {
          current_chunk_->resources[current_index_] = cr;
          return;
        }

        current_index_++;
      }

      // Move on to the next one or add a new one
      current_index_ = 0;
      current_chunk_ = current_chunk_->next;
      if(!current_chunk_) add_chunk();
    }
  }
void
GIFFManager::add_chunk(GUTF8String name, const TArray<char> & data)
      // name is fully qualified name of the chunk TO BE INSERTED.
      //      it may contain brackets at the end to set the position
      // All the required chunks will be created
{
  DEBUG_MSG("GIFFManager::add_chunk(): adding plain chunk with name='" << name << "'\n");
  DEBUG_MAKE_INDENT(3);

  GUTF8String chunk_name;
  const int lastdot=name.rsearch('.');
  if(lastdot < 0)
  {
    chunk_name=name;
    name=name.substr(0,lastdot);
  }else
  {
    chunk_name=name.substr(lastdot+1,(unsigned int)-1);
  }

  int pos=-1;
  const int obracket=chunk_name.search('[');
  if (obracket >= 0)
  {
    const int cbracket=chunk_name.search(']',obracket+1);
    if (cbracket < 0)
      G_THROW( ERR_MSG("GIFFManager.unmatched") );
    if (name.length() > (unsigned int)(cbracket+1))
      G_THROW( ERR_MSG("GIFFManager.garbage") );
//    pos=atoi((const char *)chunk_name.substr(obracket+1,cbracket-obracket-1));
    pos = chunk_name.substr(obracket+1,cbracket-obracket-1).toInt();
    chunk_name=chunk_name.substr(0,obracket);
  }
  DEBUG_MSG("Creating new chunk with name " << chunk_name << "\n");
  GP<GIFFChunk> chunk;
  chunk=GIFFChunk::create(chunk_name, data);
  add_chunk(name, chunk, pos);
}
Ejemplo n.º 14
0
  void CodeManager::add_resource(CodeResource* cr, bool* collect_now) {
    utilities::thread::Mutex::LockGuard guard(mutex_);

    for(;;) {
      while(current_index_ < chunk_size_) {
        if(current_chunk_->resources[current_index_] == 0) {
          current_chunk_->resources[current_index_] = cr;
          return;
        }

        current_index_++;
      }

      // Move on to the next one or add a new one
      current_index_ = 0;
      current_chunk_ = current_chunk_->next;
      if(!current_chunk_) {
        add_chunk();
        *collect_now = true;
        diagnostics_.collections_++;
      }
    }
  }
Ejemplo n.º 15
0
// Read the actual values of the passed lookup offset and add them to
// the list of chunks to skip as nessasary. Returns false on error.
int add_skip_chunks(struct ccx_demuxer *ctx, struct wtv_chunked_buffer *cb, uint32_t offset, uint32_t flag)
{

	uint64_t start = ctx->past;
	buffered_seek(ctx, (int)((offset*WTV_CHUNK_SIZE) - start));
	uint64_t seek_back=0-((offset*WTV_CHUNK_SIZE)-start);

	uint32_t value;
	buffered_read(ctx, (unsigned char*)&value, 4);
	if(result!=4)
		return 0;
	seek_back-=4;
	while(value!=0)
	{
		dbg_print(CCX_DMT_PARSE, "value: %llx\n", get_meta_chunk_start(value));
		buffered_read(ctx, (unsigned char*)&value, 4);
		if(result!=4)
			return 0;
		add_chunk(cb, get_meta_chunk_start(value));
		seek_back-=4;
	}
	buffered_seek(ctx, (int)seek_back);
	return 1;
}
Ejemplo n.º 16
0
	Board::Board() : Board(ChunkGenerator(0.15, 0.03))
	{
        add_chunk({0, 0}, chunkGenerator.generate());
	};
Ejemplo n.º 17
0
 vm_heap() : m_chunk_iter(m_chunks.end()) {
   add_chunk(1);
 }
Ejemplo n.º 18
0
/**
* \fn int main(int argc, char *argv[])
* \brief Fonction principale.
*
*
* La fonction principale récupère les arguments et le fichier de configuration,
* initialise la vue, le modèle, puis éxécute la boucle de calcul.
* Une fois cette boucle terminée, elle libère la mémoire et finalise l'éxécution.
*
*
*/
int main(int argc, char *argv[])
{
	config_t *conf = parse_args(argc, argv);

	int error = 0;
	error_t *error_cell = NULL;

	if(conf == NULL)
	{
		return 1;
	}

	view_t *view = init_view(conf);

	model_t *model = init_model(conf);

	double delta_time = 0;
	event_t event;

	init_event(&event);

	vect_t chunk_pos;
	init_vect(&chunk_pos, 0.4, 0.4, 0.4);
	add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);


	while(!event.exit_wanted)
	{
		delta_time = temporize(conf);
		get_event(&event, view);

		if(event.click_callback != NULL)
			(*(event.click_callback))(model);

		error = update_model(model, &event, delta_time);

		if(error)
		{
			printf("ERREUR DETECTEE !\n");
			error_cell = get_error_list();
			int error_count = 0;

			while(error_cell != NULL)
			{
				printf("%s\n", error_cell->comment);
				error_cell = error_cell->next;
				error_count++;
				if(error_count >= 10)
				{
					printf("Appuyez sur ENTREE pour voir la suite, q puis ENTREE pour quitter.\n");
					if(getchar() == 'q')
						return 1;
					error_count = 0;
				}
			}
			return 1;
		}

		update_view(view, model, &event);
	}

	close_conf(conf);
	close_view(view);
	close_model(model);

	return 0;
}
Ejemplo n.º 19
0
 explicit StringStore(size_t chunk_size) :
     m_chunk_size(chunk_size),
     m_chunks() {
     add_chunk();
 }
Ejemplo n.º 20
0
int open_file_tydemux(tystream_holder_t * tystream, char *filename) {

	chunknumber_t probe_hz;
	chunknumber_t chunk_lnr;
	chunknumber_t int_chunk_nr;
	vstream_t * vstream;
	chunk_t * chunk;


	if(infile) {
		printf("Error input file allready open\n");
		return(0);
	}
	//printf("%s:\n", filename);

	infile = open_input(filename, 0);
	if (infile == -1) {
		totalchunks= -1;		/* Total chunks */
		infile = 0;			/* FD of input file */
		chunk_in_buf = -1;

		printf("Error opening file\n");
		return(0);

	}


	tystream->tivo_probe = 1;

	probe_hz = totalchunks/10;

	tystream->tivo_probe = 1;
	tystream->tivo_version = V_2X;

	for(chunk_lnr=1, int_chunk_nr=0 ;  chunk_lnr < totalchunks; chunk_lnr = chunk_lnr + probe_hz, int_chunk_nr++ ){


		vstream = new_vstream();
		/* Lets fake it and do a read buffer */
		vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE);
		vstream->size = sizeof(uint8_t) * CHUNK_SIZE ;
		vstream->current_pos = vstream->start_stream;
		vstream->end_stream = vstream->start_stream + vstream->size;

		read_a_chunk(infile, chunk_lnr, vstream->start_stream);

		tystream->vstream = vstream;

		chunk = read_chunk(tystream, (int)chunk_lnr, 1);
		chunk_in_buf = chunk_lnr;

		if(chunk != NULL) {
			tystream->chunks = add_chunk(tystream, chunk, tystream->chunks);
		}

		free_vstream(vstream);
		tystream->vstream=NULL;

	}



	if(!tivo_probe_tystream(tystream)) {
		totalchunks= -1;		/* Total chunks */
		infile = 0;			/* FD of input file */
		chunk_in_buf = -1;
		return(0);
	}

	get_start_chunk_tivo(tystream);

	tystream->tivo_probe = 0;

	/* We assume that the first chunk to be used is chunk 0 */
	read_a_chunk(infile, (int)tystream->start_chunk, buf);
  	chunk_in_buf = (int)tystream->start_chunk;
  	return(1);
}
Ejemplo n.º 21
0
static int probe_audio_tick_size(tystream_holder_t * tystream) {

	/* Iteration */
	int i;

	/* Chunks */
	chunk_t * chunks;
	chunk_t * right_audio_chunk;

	/* Counting variables */
	int nr_size;
	int nr_time;
	int nr_audio_pes;

	/* Total timediff and size */
	ticks_t total_time;
	ticks_t time_diff;
	ticks_t audio_median_tick_diff;
	int total_size;
	int med_size;

	/* Markers */
	int gotit;


	/* Init */
	chunks = tystream->chunks;
	right_audio_chunk=NULL;
	nr_size = 0;
	nr_time = 0;
	nr_audio_pes = 0;
	total_time = 0;
	gotit = 0;
	total_size = 0;

	//printf("Audio Tick size\n");

	while(chunks) {
		gotit = 0;
		for(i=0; i < chunks->nr_records; i++){
			if(chunks->record_header[i].type == tystream->right_audio) {
				/* okay so lets save  it - in junk_chunks */
				//printf("Audio Tick size copy %i\n", i);
				right_audio_chunk = copy_chunk(chunks);
				//printf("Audio Tick size copy finished %i\n", i);
				if(right_audio_chunk) {
					tystream->junk_chunks = add_chunk(tystream, right_audio_chunk, tystream->junk_chunks);
				}
				gotit = 1;
			} else if (chunks->record_header[i].type == tystream->wrong_audio) {
				gotit = 1;
			}

			if(gotit) {
				break;
			}
		}
		chunks = chunks->next;
	}


	if( tystream->junk_chunks == NULL) {
		/* Abort */
		LOG_ERROR("ABORTING \n");
		return(0);
	}

	right_audio_chunk = tystream->junk_chunks;

	//printf("Audio Tick size - 1\n");

	/* Okay so get the total size - two stage to remove unwanted values FIXME*/
	while(right_audio_chunk) {
		for(i=0; i < right_audio_chunk->nr_records; i++) {
			switch(right_audio_chunk->record_header[i].type){
				case 0x2c0:
				case 0x4c0:
				case 0x3c0:
				case 0x9c0:
					if(right_audio_chunk->record_header[i].size > 300 &&  right_audio_chunk->record_header[i].size < 2000) {
						nr_size++;
						total_size = total_size + right_audio_chunk->record_header[i].size;
						LOG_DEVDIAG1("Size is %i\n",right_audio_chunk->record_header[i].size );
						LOG_DEVDIAG1("Total Size is %i\n", total_size);
						
					}
					break;
			}
		}
		right_audio_chunk = right_audio_chunk->next;
	}

	if(!nr_size) {
		LOG_ERROR("Major error div by zero\n");
		return(0);
	}

	med_size = total_size / nr_size;

	//printf("Audio Tick size - 2\n");

	nr_size = 0;
	total_size = 0;
	right_audio_chunk = tystream->junk_chunks;

	while(right_audio_chunk) {
		for(i=0; i < right_audio_chunk->nr_records; i++) {
			switch(right_audio_chunk->record_header[i].type){
				case 0x2c0:
				case 0x4c0:
				case 0x3c0:
				case 0x9c0:
					if((int)right_audio_chunk->record_header[i].size > (med_size - 200) &&
					   (int)right_audio_chunk->record_header[i].size < (med_size + 200)) {
						nr_size++;
						total_size = total_size + right_audio_chunk->record_header[i].size;
						LOG_DEVDIAG1("Size is %i\n",right_audio_chunk->record_header[i].size );
						LOG_DEVDIAG1("Total Size is %i\n", total_size);
					}
					break;
			}
		}
		right_audio_chunk = right_audio_chunk->next;
	}

	if(!nr_size) {
		LOG_ERROR("Major error div by zero\n");
	}

	//printf("Audio Tick size - 3 \n");

	med_size = total_size / nr_size;

	tystream->med_size = med_size;

	/* This is the typical sizes of TIVO mpeg/ac3 audio
	 * Hence we want to control if we have a typical one
	 * if we don't we give a waring and tell the user to
	 * save the tystream. FIXME WE SHOULD EXIT
	 */
	if(med_size > 1532 && med_size < 1572) {
		tystream->std_audio_size = 1552;
		tystream->audio_frame_size = 1536;
		tystream->audio_type = DTIVO_AC3;
	} else if ( med_size > 840 && med_size < 910) {
		tystream->std_audio_size = 880;
		tystream->audio_frame_size = 864;
		tystream->audio_type = SA_MPEG;
	} else if ( med_size > 760 && med_size < 800) {
		tystream->std_audio_size = 780;
		tystream->audio_frame_size = 768;
		tystream->audio_type = DTIVO_MPEG_1;
	} else if ( med_size > 568 && med_size < 608) {
		tystream->std_audio_size = 588;
		tystream->audio_frame_size = 576;
		tystream->audio_type = DTIVO_MPEG_2;
	} else if ( med_size > 460 && med_size < 500) {
		tystream->std_audio_size = 492;
		tystream->audio_frame_size = 480;
		tystream->audio_type = DTIVO_MPEG_3;
	} else if ( med_size > 328 && med_size < 368) {
		/* This one is a bit of guess work FIXME */
		tystream->std_audio_size = 348;
		tystream->audio_frame_size = 336;
		tystream->audio_type = DTIVO_MPEG_4;
		LOG_ERROR("probe_audio_tick_size: PLEASE SEND A REPORT - SAVE THE TYSTREAM\n");
	} else {
		tystream->std_audio_size = 0;
		tystream->audio_frame_size = 0;
		tystream->audio_type = AUDIO_TYPE_UNKNOW;
		LOG_WARNING("probe_audio_tick_size: Warning: can't determine std audio size PLEASE SEND A REPORT - SAVE THE TYSTREAM\n");
	}

	/* Now we collect the median tickdiff of the audio stream */

	right_audio_chunk = tystream->junk_chunks;

	while(right_audio_chunk) {
		nr_audio_pes = get_nr_audio_pes(tystream, right_audio_chunk);
		for(i=0; i < nr_audio_pes - 2; i++) {
			time_diff = get_time_X(i + 1, right_audio_chunk, AUDIO, tystream)
				- get_time_X(i, right_audio_chunk, AUDIO, tystream);
			if(time_diff > 1000 && time_diff < 4000) {
				total_time = total_time + time_diff;
				nr_time++;
			}
		}
		right_audio_chunk = right_audio_chunk->next;
	}


	//printf("Out of Audio Tick\n");
	audio_median_tick_diff = total_time / nr_time;
	
	if(audio_median_tick_diff < 3245 && audio_median_tick_diff > 3235) {
		tystream->audio_median_tick_diff = 3240;
	} else if (audio_median_tick_diff < 2165 && audio_median_tick_diff > 2155) {
		tystream->audio_median_tick_diff = 2160;
	} else if (audio_median_tick_diff < 2885 && audio_median_tick_diff > 2875) {
		tystream->audio_median_tick_diff = 2880;
	} else {
		LOG_WARNING1("probe_audio_tick_size: Warning: can't determine audio_median_tick_diff "I64FORMAT"PLEASE SEND A REPORT - SAVE THE TYSTREAM\n", audio_median_tick_diff);
		return(0);
	}

	return(1);

}
Ejemplo n.º 22
0
int get_image_chunk_tivo(gop_index_t * gop_index,module_t * module)
{

	/* Iteration */
	int i;


	/* The chunk we read */
	chunk_t * chunk = NULL;

	/* The chunk linked list */
	chunk_t * chunks = NULL;

	/* vstream */
	vstream_t * vstream;

	int chunks_to_read;
	int result;


	chunks_to_read = 2;

	/* Find out how many chunks we need to read
	if pes and i frame is in the same chunk then two chunks if not three chunks
	*/


	vstream = new_vstream();
	/* Lets fake it and do a read buffer */
	vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE);
	vstream->size = sizeof(uint8_t) * CHUNK_SIZE ;
	vstream->current_pos = vstream->start_stream;
	vstream->end_stream = vstream->start_stream + vstream->size;
	tystream->vstream = vstream;

	for(i=0; i < chunks_to_read; i++) {

		vstream->current_pos = vstream->start_stream;
		vstream->eof=0;
		read_a_chunk(infile, gop_index->chunk_number_i_frame + i + tystream->start_chunk, vstream->start_stream);

		chunk = read_chunk(tystream, gop_index->chunk_number_i_frame_pes + i, 1);

		if(chunk) {
			chunks = add_chunk(tystream, chunk, chunks);
		} else {
			chunks_to_read++;
		}
	}

	free_vstream(vstream);
	tystream->vstream=NULL;



	result = get_video(gop_index->i_frame_rec_nr, module, chunks, MPEG_I, tystream);

	if(!result) {
		LOG_ERROR2("parse_chunk_video: ERROR - i-frame - chunk %lld , record %i\n", \
			chunks->chunk_number,gop_index->i_frame_rec_nr );
		free_junk_chunks(chunks);
		return(0);
	}

	//write(2,data_collector_module.data_buffer,data_collector_module.buffer_size);

	free_junk_chunks(chunks);

	return(1);

}
Ejemplo n.º 23
0
int std_probe_tystream(tystream_holder_t * tystream) {

	/* Iteration */
	off64_t j;

	/* File size */
	off64_t in_file_size;

	/* Chunks */
	chunknumber_t local_nr_chunks;
	chunknumber_t probe_hz;
	chunknumber_t chunk_lnr;
	chunknumber_t int_chunk_nr;


	chunk_t * chunk;

	LOG_USERDIAG("Probing TyStream .....\n");

	chunk = NULL;


	if(tystream->vstream) {
		in_file_size=tystream->vstream->size;
	} else {
		in_file_size=tystream->in_file_size;
	}

	/* Calculate the probe rate */
	local_nr_chunks = (chunknumber_t)(in_file_size/CHUNK_SIZE);
	probe_hz = local_nr_chunks/10;

	for(j=0, chunk_lnr=1,int_chunk_nr=0 ;  j < in_file_size; j = (j + CHUNK_SIZE*probe_hz), chunk_lnr = chunk_lnr + probe_hz, int_chunk_nr++ ){

		chunk = read_chunk(tystream, chunk_lnr, 2048);
		if(chunk != NULL) {
			tystream->chunks = add_chunk(tystream, chunk, tystream->chunks);
			//printf("Chunk %i has %i records\n",int_chunk_nr,chunk->nr_records);
		} else {
			//printf("Chunk was null\n");
		}
	}



	if(tystream->chunks == NULL) {
		LOG_ERROR("Big ERROR - NO CHUNKS\n");
		clear_tystream_audio_probe(tystream, 0);
		return(0);
	}

	if(!probe_tystream_S2(tystream)) {
		LOG_ERROR("Big ERROR - CAN'T DETECT S1/S2\n");
		clear_tystream_audio_probe(tystream, 0);
		return(0);
	}


	if(!probe_tystream_frame_rate(tystream)){
		LOG_ERROR("Big ERROR - CAN'T DETECT FRAME RATE\n");
		clear_tystream_audio_probe(tystream, 0);
		return(0);
	}

	if(!probe_tystream_audio(tystream)) {
		LOG_ERROR("Big ERROR - CAN'T DETECT AUDIO TYPE\n");
		clear_tystream_audio_probe(tystream, 0);
		return(0);
	}

	if(!probe_audio_tick_size(tystream)) {
		LOG_ERROR("Big ERROR - CAN'T DETECT AUDIO SIZE\n");
		clear_tystream_audio_probe(tystream, 1);
		return(0);
	}

	clear_tystream_audio_probe(tystream, 1);
	return(1);


}
Ejemplo n.º 24
0
int get_first_seq_tivo(gop_index_t * gop_index, module_t * module) {

	/* Iteration */
	int i;

	/* vstream */
	vstream_t * vstream;

	/* The chunk we read */
	chunk_t * chunk = NULL;

	/* The chunk linked list */
	chunk_t * chunks = NULL;

	int chunks_to_read;
	int result;


	vstream = new_vstream();
	/* Lets fake it and do a read buffer */
	vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE);
	vstream->size = sizeof(uint8_t) * CHUNK_SIZE ;
	vstream->current_pos = vstream->start_stream;
	vstream->end_stream = vstream->start_stream + vstream->size;
	tystream->vstream = vstream;



	chunks_to_read = 2;


	for(i=0; i < chunks_to_read; i++) {

		vstream->current_pos = vstream->start_stream;
		vstream->eof=0;
		read_a_chunk(infile, gop_index->chunk_number_seq + i + tystream->start_chunk, vstream->start_stream);
		chunk = read_chunk(tystream, gop_index->chunk_number_seq + i + tystream->start_chunk, 1);

		if(chunk) {
			chunks = add_chunk(tystream, chunk, chunks);
		} else {
			chunks_to_read++;
		}
	}

	free_vstream(vstream);
	tystream->vstream=NULL;


	LOG_DEVDIAG("getting seq\n");
	result = get_video(gop_index->seq_rec_nr, module, chunks, MPEG_SEQ, tystream);


	if(!result) {
		LOG_ERROR2("parse_chunk_video: ERROR - seq-frame - chunk %lld , record %i\n", \
			chunks->chunk_number, gop_index->seq_rec_nr);
		free_junk_chunks(chunks);
		return(get_first_seq(tystream,gop_index->next,module));
		return(0);
	}
	LOG_DEVDIAG("setting seq\n");
	set_seq_low_delay(tystream, module);
	free_junk_chunks(chunks);
	LOG_DEVDIAG("getting seq done\n");
	return(1);


}
Ejemplo n.º 25
0
static void
test_run (void)
{
  FlowMuxDeserializer *deserializer;
  FlowUserAdapter *adapter;
  FlowPad *input_pad;
  FlowPacket *packet;
  GQueue *expected_chunks;
  guint32 chunk_size;
  guchar *buffer;
  int i, len;
  Chunk *chunk;
  FlowPacketQueue *input_packet_queue;
  guint current_channel_id;
  
  deserializer = flow_mux_deserializer_new ();

  adapter = flow_user_adapter_new ();
  flow_pad_connect (FLOW_PAD (flow_simplex_element_get_output_pad (
                                      FLOW_SIMPLEX_ELEMENT (deserializer))),
                    FLOW_PAD (flow_simplex_element_get_input_pad (
                                      FLOW_SIMPLEX_ELEMENT (adapter))));
  input_pad = FLOW_PAD (flow_simplex_element_get_input_pad (FLOW_SIMPLEX_ELEMENT(deserializer)));
  
  buffer = g_malloc (BUFFER_SIZE);
  memset (buffer, 0xaa, BUFFER_SIZE);

  chunk_size = 0;
  expected_chunks = g_queue_new ();
  for (i = 0; i < ITERATIONS; i++)
  {
    FlowPacket *header;
    guint hdr_size;
    
    current_channel_id = g_random_int_range (0, N_CHANNELS);
    len = g_random_int_range (1, MAX_CHUNK_SIZE);
    hdr_size = flow_mux_deserializer_get_header_size (deserializer);
    flow_mux_deserializer_unparse_header (deserializer, buffer, current_channel_id, len);
    header = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, hdr_size);
    flow_pad_push (input_pad, header);
    add_chunk (expected_chunks, current_channel_id, len);

    while (len > 0)
    {
      guint n = g_random_int_range (1, BUFFER_SIZE);
      if (n > len)
        n = len;
      flow_pad_push (input_pad, flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, n));
      len -= n;
    }
  }
  
  flow_pad_push (input_pad, flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, FLOW_STREAM_END));

  input_packet_queue = flow_user_adapter_get_input_queue (adapter);

  while ((chunk = g_queue_pop_head (expected_chunks)) != NULL)
  {
    guint32 size;
    gpointer data;

    while ((packet = flow_packet_queue_pop_packet (input_packet_queue)) == NULL)
      flow_user_adapter_wait_for_input (adapter);

    data = flow_packet_get_data (packet);
    if (packet->format != FLOW_PACKET_FORMAT_OBJECT
        || !FLOW_IS_MUX_EVENT (data))
      test_end (TEST_RESULT_FAILED, "expected mux event packet");

    if (flow_mux_event_get_channel_id (FLOW_MUX_EVENT (data)) != chunk->channel_id)
      test_end (TEST_RESULT_FAILED, "unexpected channel id in mux event packet");

    flow_packet_unref (packet);
    
    size = 0;
    while (TRUE)
    {
      while (!flow_packet_queue_peek_packet (input_packet_queue, &packet, NULL))
        flow_user_adapter_wait_for_input (adapter);
      if (packet->format != FLOW_PACKET_FORMAT_BUFFER)
        break;
      size += packet->size;
      flow_packet_queue_drop_packet (input_packet_queue);
    } 

    if (size != chunk->size)
      test_end (TEST_RESULT_FAILED, "chunk differs in size");
    
    g_free (chunk);
  }
  g_queue_free (expected_chunks);
  g_free (buffer);
}