Exemplo n.º 1
0
int insert (b_tree** root ,  i_primario* element){	//k is the insertion_key

	int j;
	b_tree* aux = (*root);

	
	if(aux->i_counter == (ORDEM-1)){
		// NÓ ESTÁ CHEIO

			//Criação de um novo nó pai
		b_tree* parent;
		btree_create(&parent);

			//Definição das informações do novo nó pai
		parent->leaf 		= 0;
		parent->branches[0] = aux;
		(*root) 			= parent;

		splitting(root, 0, &aux);

		
		insert_nonfull(&parent, element);
		
		return FUNCTION_OK;
	}else{
		// NÓ NÃO ESTÁ CHEIO
		insert_nonfull(&aux, element);

	}
	return FUNCTION_OK;
}
Exemplo n.º 2
0
int insert_nonfull(b_tree** root, i_primario* k){

	int i = (*root)->i_counter;

	if ((*root)->leaf == 1){	//CASO LEAF FUNCIONA, CHECAR CASO NÃO-LEAF
		while ( i >= 0 ){
			if ((*root)->index[i] != NULL){
				
				if ( key_compare((*root)->index[i]->key, k->key) == 1){
					(*root)->index[i+1] = (*root)->index[i];					
				}else{
					break;					
				}
			}

			i--;
		}
		i++;
		
		(*root)->index[i] = k;
		(*root)->i_counter++;

		return FUNCTION_OK;



	}else{

		//printf("not leaf => i_counter: %d // ", (*root)->i_counter);
			

		for(i = (*root)->i_counter - 1; i >= 0; i--){
				if((*root)->index[i] != NULL){
					if (key_compare((*root)->index[i]->key, k->key) == 2){
					//i++;
					break;
				}
			}
		}
		i++;


		if((*root)->branches[i]->i_counter == (ORDEM-1)){
			splitting(root, i, &((*root)->branches[i]) );
			insert_nonfull(root, k);

		}else{
			insert_nonfull(&((*root)->branches[i]) , k);
			

		}
	}
	return FUNCTION_OK;
}
Exemplo n.º 3
0
void
cluster_helper_c::split_if_necessary(packet_cptr &packet) {
    if (   !splitting()
            || (m->split_points.end() == m->current_split_point)
            || (g_file_num > g_split_max_num_files)
            || !packet->is_key_frame()
            || (   (packet->source->get_track_type() != track_video)
                   && g_video_packetizer))
        return;

    bool split_now = false;

    // Maybe we want to start a new file now.
    if (split_point_c::size == m->current_split_point->m_type) {
        int64_t additional_size = 0;

        if (!m->packets.empty())
            // Cluster + Cluster timecode: roughly 21 bytes. Add all frame sizes & their overheaders, too.
            additional_size = 21 + boost::accumulate(m->packets, 0, [](size_t size, const packet_cptr &p) {
            return size + p->data->get_size() + (p->is_key_frame() ? 10 : p->is_p_frame() ? 13 : 16);
        });

        additional_size += 18 * m->num_cue_elements;

        mxdebug_if(m->debug_splitting,
                   boost::format("cluster_helper split decision: header_overhead: %1%, additional_size: %2%, bytes_in_file: %3%, sum: %4%\n")
                   % m->header_overhead % additional_size % m->bytes_in_file % (m->header_overhead + additional_size + m->bytes_in_file));
        if ((m->header_overhead + additional_size + m->bytes_in_file) >= m->current_split_point->m_point)
            split_now = true;

    } else if (   (split_point_c::duration == m->current_split_point->m_type)
                  && (0 <= m->first_timecode_in_file)
                  && (packet->assigned_timecode - m->first_timecode_in_file) >= m->current_split_point->m_point)
        split_now = true;

    else if (   (   (split_point_c::timecode == m->current_split_point->m_type)
                    || (split_point_c::parts    == m->current_split_point->m_type))
                && (packet->assigned_timecode >= m->current_split_point->m_point))
        split_now = true;

    else if (   (   (split_point_c::frame_field       == m->current_split_point->m_type)
                    || (split_point_c::parts_frame_field == m->current_split_point->m_type))
                && (m->frame_field_number >= m->current_split_point->m_point))
        split_now = true;

    if (!split_now)
        return;

    split(packet);
}
Exemplo n.º 4
0
void applyRules(struct grid * Grid){
	struct grid g;
	do{
		g=copy(*Grid);
		fill_grid_boarder_line_by_spaces(Grid);
		fill_grid_boarder_column_by_spaces(Grid);
		fill_grid_by_spaces(Grid);
		joining(Grid);
	
		splitting(Grid);
	
	
		simple_box(Grid);
		fill_grid_by_spaces(Grid);
	}
	while(!areEquals(g,*Grid));	
}
Exemplo n.º 5
0
bool
cluster_helper_c::split_mode_produces_many_files()
  const {
  if (!splitting())
    return false;

  if (   (split_point_c::parts             != m->split_points.front().m_type)
      && (split_point_c::parts_frame_field != m->split_points.front().m_type))
    return true;

  bool first = true;
  for (auto &split_point : m->split_points)
    if (!split_point.m_discard && split_point.m_create_new_file) {
      if (!first)
        return true;
      first = false;
    }

  return false;
}
Exemplo n.º 6
0
int
cluster_helper_c::render() {
  std::vector<render_groups_cptr> render_groups;
  KaxCues cues;
  cues.SetGlobalTimecodeScale(g_timecode_scale);

  bool use_simpleblock    = !hack_engaged(ENGAGE_NO_SIMPLE_BLOCKS);

  LacingType lacing_type  = hack_engaged(ENGAGE_LACING_XIPH) ? LACING_XIPH : hack_engaged(ENGAGE_LACING_EBML) ? LACING_EBML : LACING_AUTO;

  int64_t min_cl_timecode = std::numeric_limits<int64_t>::max();
  int64_t max_cl_timecode = 0;

  int elements_in_cluster = 0;
  bool added_to_cues      = false;

  // Splitpoint stuff
  if ((-1 == m->header_overhead) && splitting())
    m->header_overhead = m->out->getFilePointer() + g_tags_size;

  // Make sure that we don't have negative/wrapped around timecodes in the output file.
  // Can happend when we're splitting; so adjust timecode_offset accordingly.
  m->timecode_offset       = boost::accumulate(m->packets, m->timecode_offset, [](int64_t a, const packet_cptr &p) { return std::min(a, p->assigned_timecode); });
  int64_t timecode_offset = m->timecode_offset + get_discarded_duration();

  for (auto &pack : m->packets) {
    generic_packetizer_c *source = pack->source;
    bool has_codec_state         = !!pack->codec_state;

    if (g_video_packetizer == source)
      m->max_video_timecode_rendered = std::max(pack->assigned_timecode + pack->get_duration(), m->max_video_timecode_rendered);

    if (discarding()) {
      if (-1 == m->first_discarded_timecode)
        m->first_discarded_timecode = pack->assigned_timecode;
      m->last_discarded_timecode_and_duration = std::max(m->last_discarded_timecode_and_duration, pack->assigned_timecode + pack->get_duration());
      continue;
    }

    if (source->contains_gap())
      m->cluster->SetSilentTrackUsed();

    render_groups_c *render_group = nullptr;
    for (auto &rg : render_groups)
      if (rg->m_source == source) {
        render_group = rg.get();
        break;
      }

    if (!render_group) {
      render_groups.push_back(render_groups_cptr(new render_groups_c(source)));
      render_group = render_groups.back().get();
    }

    min_cl_timecode                        = std::min(pack->assigned_timecode, min_cl_timecode);
    max_cl_timecode                        = std::max(pack->assigned_timecode, max_cl_timecode);

    DataBuffer *data_buffer                = new DataBuffer((binary *)pack->data->get_buffer(), pack->data->get_size());

    KaxTrackEntry &track_entry             = static_cast<KaxTrackEntry &>(*source->get_track_entry());

    kax_block_blob_c *previous_block_group = !render_group->m_groups.empty() ? render_group->m_groups.back().get() : nullptr;
    kax_block_blob_c *new_block_group      = previous_block_group;

    if (!pack->is_key_frame() || has_codec_state || pack->has_discard_padding())
      render_group->m_more_data = false;

    if (!render_group->m_more_data) {
      set_duration(render_group);
      render_group->m_durations.clear();
      render_group->m_duration_mandatory = false;

      BlockBlobType this_block_blob_type
        = !use_simpleblock                         ? BLOCK_BLOB_NO_SIMPLE
        : must_duration_be_set(render_group, pack) ? BLOCK_BLOB_NO_SIMPLE
        : !pack->data_adds.empty()                 ? BLOCK_BLOB_NO_SIMPLE
        : has_codec_state                          ? BLOCK_BLOB_NO_SIMPLE
        : pack->has_discard_padding()              ? BLOCK_BLOB_NO_SIMPLE
        :                                            BLOCK_BLOB_ALWAYS_SIMPLE;

      render_group->m_groups.push_back(kax_block_blob_cptr(new kax_block_blob_c(this_block_blob_type)));
      new_block_group = render_group->m_groups.back().get();
      m->cluster->AddBlockBlob(new_block_group);
      new_block_group->SetParent(*m->cluster);

      added_to_cues = false;
    }

    // Now put the packet into the cluster.
    render_group->m_more_data = new_block_group->add_frame_auto(track_entry, pack->assigned_timecode - timecode_offset, *data_buffer, lacing_type,
                                                                pack->has_bref() ? pack->bref - timecode_offset : -1,
                                                                pack->has_fref() ? pack->fref - timecode_offset : -1);

    if (has_codec_state) {
      KaxBlockGroup &bgroup = (KaxBlockGroup &)*new_block_group;
      KaxCodecState *cstate = new KaxCodecState;
      bgroup.PushElement(*cstate);
      cstate->CopyBuffer(pack->codec_state->get_buffer(), pack->codec_state->get_size());
    }

    if (-1 == m->first_timecode_in_file)
      m->first_timecode_in_file = pack->assigned_timecode;
    if (-1 == m->first_timecode_in_part)
      m->first_timecode_in_part = pack->assigned_timecode;

    m->min_timecode_in_file      = std::min(timecode_c::ns(pack->assigned_timecode),        m->min_timecode_in_file.value_or_max());
    m->max_timecode_in_file      = std::max(pack->assigned_timecode,                        m->max_timecode_in_file);
    m->max_timecode_and_duration = std::max(pack->assigned_timecode + pack->get_duration(), m->max_timecode_and_duration);

    if (!pack->is_key_frame() || !track_entry.LacingEnabled())
      render_group->m_more_data = false;

    render_group->m_durations.push_back(pack->get_unmodified_duration());
    render_group->m_duration_mandatory |= pack->duration_mandatory;

    cues_c::get().set_duration_for_id_timecode(source->get_track_num(), pack->assigned_timecode - timecode_offset, pack->get_duration());

    if (new_block_group) {
      // Set the reference priority if it was wanted.
      if ((0 < pack->ref_priority) && new_block_group->replace_simple_by_group())
        GetChild<KaxReferencePriority>(*new_block_group).SetValue(pack->ref_priority);

      // Handle BlockAdditions if needed
      if (!pack->data_adds.empty() && new_block_group->ReplaceSimpleByGroup()) {
        KaxBlockAdditions &additions = AddEmptyChild<KaxBlockAdditions>(*new_block_group);

        size_t data_add_idx;
        for (data_add_idx = 0; pack->data_adds.size() > data_add_idx; ++data_add_idx) {
          auto &block_more = AddEmptyChild<KaxBlockMore>(additions);
          GetChild<KaxBlockAddID     >(block_more).SetValue(data_add_idx + 1);
          GetChild<KaxBlockAdditional>(block_more).CopyBuffer((binary *)pack->data_adds[data_add_idx]->get_buffer(), pack->data_adds[data_add_idx]->get_size());
        }
      }

      if (pack->has_discard_padding())
        GetChild<KaxDiscardPadding>(*new_block_group).SetValue(pack->discard_padding.to_ns());
    }

    elements_in_cluster++;

    if (!new_block_group)
      new_block_group = previous_block_group;

    else if (g_write_cues && (!added_to_cues || has_codec_state)) {
      added_to_cues = add_to_cues_maybe(pack);
      if (added_to_cues)
        cues.AddBlockBlob(*new_block_group);
    }

    pack->group = new_block_group;

    m->track_statistics[ source->get_uid() ].process(*pack);
  }

  if (!discarding()) {
    if (0 < elements_in_cluster) {
      for (auto &rg : render_groups)
        set_duration(rg.get());

      m->cluster->SetPreviousTimecode(min_cl_timecode - timecode_offset - 1, (int64_t)g_timecode_scale);
      m->cluster->set_min_timecode(min_cl_timecode - timecode_offset);
      m->cluster->set_max_timecode(max_cl_timecode - timecode_offset);

      m->cluster->Render(*m->out, cues);
      m->bytes_in_file += m->cluster->ElementSize();

      if (g_kax_sh_cues)
        g_kax_sh_cues->IndexThis(*m->cluster, *g_kax_segment);

      m->previous_cluster_tc = m->cluster->GlobalTimecode();

      cues_c::get().postprocess_cues(cues, *m->cluster);

    } else
      m->previous_cluster_tc = -1;
  }

  m->min_timecode_in_cluster = -1;
  m->max_timecode_in_cluster = -1;

  m->cluster->delete_non_blocks();

  return 1;
}
Exemplo n.º 7
0
bool
cluster_helper_c::discarding()
  const {
  return splitting() && m->discarding;
}