void cluster_helper_c::render_after_adding_if_necessary(packet_cptr &packet) { // Render the cluster if it is full (according to my many criteria). auto timecode = get_timecode(); if ( ((packet->assigned_timecode - timecode) > g_max_ns_per_cluster) || (m->packets.size() > static_cast<size_t>(g_max_blocks_per_cluster)) || (get_cluster_content_size() > 1500000)) { render(); prepare_new_cluster(); } }
void cluster_helper_c::split(packet_cptr &packet) { render(); m->num_cue_elements = 0; bool create_new_file = m->current_split_point->m_create_new_file; bool previously_discarding = m->discarding; mxdebug_if(m->debug_splitting, boost::format("Splitting: splitpoint %1% reached before timecode %2%, create new? %3%.\n") % m->current_split_point->str() % format_timecode(packet->assigned_timecode) % create_new_file); finish_file(false, create_new_file, previously_discarding); if (m->current_split_point->m_use_once) { if ( m->current_split_point->m_discard && ( (split_point_c::parts == m->current_split_point->m_type) || (split_point_c::parts_frame_field == m->current_split_point->m_type)) && (m->split_points.end() == (m->current_split_point + 1))) { mxdebug_if(m->debug_splitting, boost::format("Splitting: Last part in 'parts:' splitting mode finished\n")); m->splitting_and_processed_fully = true; } m->discarding = m->current_split_point->m_discard; ++m->current_split_point; } if (create_new_file) { create_next_output_file(); if (g_no_linking) { m->previous_cluster_tc = -1; m->timecode_offset = g_video_packetizer ? m->max_video_timecode_rendered : packet->assigned_timecode; } m->bytes_in_file = 0; m->first_timecode_in_file = -1; m->max_timecode_in_file = -1; m->min_timecode_in_file.reset(); } m->first_timecode_in_part = -1; handle_discarded_duration(create_new_file, previously_discarding); prepare_new_cluster(); }
void cluster_helper_c::render_before_adding_if_necessary(packet_cptr &packet) { int64_t timecode = get_timecode(); int64_t timecode_delay = ( (packet->assigned_timecode > m->max_timecode_in_cluster) || (-1 == m->max_timecode_in_cluster)) ? packet->assigned_timecode : m->max_timecode_in_cluster; timecode_delay -= ( (-1 == m->min_timecode_in_cluster) || (packet->assigned_timecode < m->min_timecode_in_cluster)) ? packet->assigned_timecode : m->min_timecode_in_cluster; timecode_delay = (int64_t)(timecode_delay / g_timecode_scale); mxdebug_if(m->debug_packets, boost::format("cluster_helper_c::add_packet(): new packet { source %1%/%2% " "timecode: %3% duration: %4% bref: %5% fref: %6% assigned_timecode: %7% timecode_delay: %8% }\n") % packet->source->m_ti.m_id % packet->source->m_ti.m_fname % packet->timecode % packet->duration % packet->bref % packet->fref % packet->assigned_timecode % format_timecode(timecode_delay)); bool is_video_keyframe = (packet->source == g_video_packetizer) && packet->is_key_frame(); bool do_render = (std::numeric_limits<int16_t>::max() < timecode_delay) || (std::numeric_limits<int16_t>::min() > timecode_delay) || ( (std::max<int64_t>(0, m->min_timecode_in_cluster) > m->previous_cluster_tc) && (packet->assigned_timecode > m->min_timecode_in_cluster) && (!g_video_packetizer || !is_video_keyframe || m->first_video_keyframe_seen) && ( (packet->gap_following && !m->packets.empty()) || ((packet->assigned_timecode - timecode) > g_max_ns_per_cluster) || is_video_keyframe)); if (is_video_keyframe) m->first_video_keyframe_seen = true; mxdebug_if(m->debug_rendering, boost::format("render check cur_tc %9% min_tc_ic %1% prev_cl_tc %2% test %3% is_vid_and_key %4% tc_delay %5% gap_following_and_not_empty %6% cur_tc>min_tc_ic %8% first_video_key_seen %10% do_render %7%\n") % m->min_timecode_in_cluster % m->previous_cluster_tc % (std::max<int64_t>(0, m->min_timecode_in_cluster) > m->previous_cluster_tc) % is_video_keyframe % timecode_delay % (packet->gap_following && !m->packets.empty()) % do_render % (packet->assigned_timecode > m->min_timecode_in_cluster) % packet->assigned_timecode % m->first_video_keyframe_seen); if (!do_render) return; render(); prepare_new_cluster(); }
void cluster_helper_c::add_packet(packet_cptr packet) { if (!m->cluster) prepare_new_cluster(); packet->normalize_timecodes(); render_before_adding_if_necessary(packet); split_if_necessary(packet); m->packets.push_back(packet); m->cluster_content_size += packet->data->get_size(); if (packet->assigned_timecode > m->max_timecode_in_cluster) m->max_timecode_in_cluster = packet->assigned_timecode; if ((-1 == m->min_timecode_in_cluster) || (packet->assigned_timecode < m->min_timecode_in_cluster)) m->min_timecode_in_cluster = packet->assigned_timecode; render_after_adding_if_necessary(packet); if (g_video_packetizer == packet->source) ++m->frame_field_number; }
int main(int argc, char **argv) { char *analyze_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_upgrade")); /* Set default restrictive mask until new cluster permissions are read */ umask(PG_MODE_MASK_OWNER); parseCommandLine(argc, argv); get_restricted_token(os_info.progname); adjust_data_dir(&old_cluster); adjust_data_dir(&new_cluster); setup(argv[0], &live_check); output_check_banner(live_check); check_cluster_versions(); get_sock_dir(&old_cluster, live_check); get_sock_dir(&new_cluster, false); check_cluster_compatibility(live_check); /* Set mask based on PGDATA permissions */ if (!GetDataDirectoryCreatePerm(new_cluster.pgdata)) { pg_log(PG_FATAL, "could not read permissions of directory \"%s\": %s\n", new_cluster.pgdata, strerror(errno)); exit(1); } umask(pg_mode_mask); check_and_dump_old_cluster(live_check); /* -- NEW -- */ start_postmaster(&new_cluster, true); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\n" "Performing Upgrade\n" "------------------\n"); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_xact_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster, true); prepare_new_globals(); create_new_objects(); stop_postmaster(false); /* * Most failures happen in create_new_objects(), which has completed at * this point. We do this here because it is just before linking, which * will link the old and new cluster data files, preventing the old * cluster from being safely started once the new cluster is started. */ if (user_opts.transfer_mode == TRANSFER_MODE_LINK) disable_old_cluster(); transfer_all_new_tablespaces(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next OID for new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/pg_resetwal\" -o %u \"%s\"", new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); prep_status("Sync data directory to disk"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir, new_cluster.pgdata); check_ok(); create_script_for_cluster_analyze(&analyze_script_file_name); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings_and_set_wal_level(); pg_log(PG_REPORT, "\n" "Upgrade Complete\n" "----------------\n"); output_completion_banner(analyze_script_file_name, deletion_script_file_name); pg_free(analyze_script_file_name); pg_free(deletion_script_file_name); cleanup(); return 0; }
int main(int argc, char **argv) { char *sequence_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; parseCommandLine(argc, argv); output_check_banner(&live_check); setup(argv[0], live_check); check_cluster_versions(); check_cluster_compatibility(live_check); check_old_cluster(live_check, &sequence_script_file_name); /* -- NEW -- */ start_postmaster(&new_cluster); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\nPerforming Upgrade\n"); pg_log(PG_REPORT, "------------------\n"); disable_old_cluster(); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_clog_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster); prepare_new_databases(); create_new_objects(); stop_postmaster(false); transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next oid for new cluster"); exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -o %u \"%s\" > " DEVNULL SYSTEMQUOTE, new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings(sequence_script_file_name); pg_log(PG_REPORT, "\nUpgrade complete\n"); pg_log(PG_REPORT, "----------------\n"); output_completion_banner(deletion_script_file_name); pg_free(deletion_script_file_name); pg_free(sequence_script_file_name); cleanup(); return 0; }
int main(int argc, char **argv) { char *sequence_script_file_name = NULL; char *analyze_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; parseCommandLine(argc, argv); adjust_data_dir(&old_cluster); adjust_data_dir(&new_cluster); output_check_banner(&live_check); setup(argv[0], live_check); check_cluster_versions(); get_sock_dir(&old_cluster, live_check); get_sock_dir(&new_cluster, false); check_cluster_compatibility(live_check); check_and_dump_old_cluster(live_check, &sequence_script_file_name); /* -- NEW -- */ start_postmaster(&new_cluster); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\nPerforming Upgrade\n"); pg_log(PG_REPORT, "------------------\n"); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_clog_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster); prepare_new_databases(); create_new_objects(); stop_postmaster(false); /* * Most failures happen in create_new_objects(), which has completed at * this point. We do this here because it is just before linking, which * will link the old and new cluster data files, preventing the old * cluster from being safely started once the new cluster is started. */ if (user_opts.transfer_mode == TRANSFER_MODE_LINK) disable_old_cluster(); transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next OID for new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/pg_resetxlog\" -o %u \"%s\"", new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); prep_status("Sync data directory to disk"); exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir, new_cluster.pgdata); check_ok(); create_script_for_cluster_analyze(&analyze_script_file_name); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings(sequence_script_file_name); pg_log(PG_REPORT, "\nUpgrade Complete\n"); pg_log(PG_REPORT, "----------------\n"); output_completion_banner(analyze_script_file_name, deletion_script_file_name); pg_free(analyze_script_file_name); pg_free(deletion_script_file_name); pg_free(sequence_script_file_name); cleanup(); return 0; }