📄 pthread_enc.c
字号:
*/ mpeg_encode_parmeter(ii, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);#endif#if 1/* for special recording mode */ if(psp->gp.video_form == NTSC) { if(psp->gp.resolution == CIF) { switch(ii) { case 0: /* ch1 : left & top */ h_offset = 0; v_offset = 0; break; case 1: /* ch2 : right & top */ h_offset = 22; v_offset = 0; break; case 2: /* ch3 : left & bottom */ h_offset = 0; v_offset = 120; break; case 3: /* ch4 : right & bottom */ h_offset = 22; v_offset = 120; break; } } }else { if(psp->gp.resolution == CIF) { switch(ii) { case 0: /* ch1 : left & top */ h_offset = 0; v_offset = 0; break; case 1: /* ch2 : right & top */ h_offset = 22; v_offset = 0; break; case 2: /* ch3 : left & bottom */ h_offset = 0; v_offset = 144; break; case 3: /* ch4 : right & bottom */ h_offset = 22; v_offset = 144; break; } } }#endif /* ch_id : channel ID * h_offset : horizontal offset (16-pel unit), default is 0 * v_offset : vertical offset (2-line unit), default is 0 * h_mbsize : horizontal MB size (16-pel unit), default is 45 * v_mbsize : vertical MB size (16-line unit), default is 30 */ encode_region_info(ii, h_offset, v_offset, h_mbsize, v_mbsize); /* ch_id : channel ID * input_frame_number : the number of input frames * 1 ~ 255, default is 1 * rec_frame_number : the number of frames to be recorded out of input frames * 0 ~ number of input frame, default is 1 */#if 1 if(psp->gp.resolution == D1) { recoding_frame_rate_control(ii, 1, 1); } else { if(psp->enc_ch[ii].flag_conti_rec || psp->enc_ch[ii].motion.flag || psp->enc_ch[ii].sensor.flag_in || psp->enc_ch[ii].schedule.flag) { if(psm->mode == NTSC) recoding_frame_rate_control(ii, framerate_d0_list[psp->enc_ch[ii].frame_rate], framerate_d1_list[psp->enc_ch[ii].frame_rate]); else recoding_frame_rate_control(ii, pal_framerate_d0_list[psp->enc_ch[ii].frame_rate], pal_framerate_d1_list[psp->enc_ch[ii].frame_rate]); } else recoding_frame_rate_control(ii, framerate_d0_list[psp->enc_ch[ii].frame_rate], 0); }#else//org recoding_frame_rate_control(ii, framerate_d0_list[psp->enc_ch[ii].frame_rate], framerate_d1_list[psp->enc_ch[ii].frame_rate]);#endif /* whitefe-20040824@add: fix encoding size bug */ m_MSG("\n\t!!! ENCODING SIZE [%d][%d]", h_mbsize, v_mbsize); usleep(10000); /* ch_id : channel ID * mode : rate control mode * '0' fixed Q * '1' Picture level rate control * '2' MB level rate control * default is '0' */ // pentamicro 2006.01.11 if(psp->enc_attr.encoding_type == 0) /* only JPEG encoding */ rate_control_mode(ii, 0); // JPEG only else rate_control_mode(ii, 1); // CBR only /* ch_id : channel ID * bit_rate : average Kbit rate per frame (1000-bit unit), default is 100 */ if(psp->gp.resolution == D1) cbr_q = (UNS32)((float)(d1_cbr_val_list[psp->enc_ch[ii].cbr_q] / fps_val * 100.0)); else cbr_q = (UNS32)((float)(cif_cbr_val_list[psp->enc_ch[ii].cbr_q] / fps_val * 100.0)); rate_control_parm_CBR(ii, cbr_q); /* ch_id : channel ID * qscale_code : Q value for fixed Q or JPEG image quality * JPEG : 1 ~ 100(%) * other standard : 1 ~ 31(Q) * default is 5 */// pentamicro 2006.01.11 if(psp->enc_attr.encoding_type == 0) /* only JPEG encoding */ set_qscale_code(ii, (UNS16)jpeg_q_val_list[psp->enc_ch[ii].cbr_q]); /* ch_id : channel ID * closed_gop : closed GOP * '0' open GOP, '1' closed GOP, '2' closed GOP type 2, default is '1' * gop_nm : GOP_NM (N/M, > 0), default is 5 * gop_m : GOP_M (M, > 0), default is 3 */ gop_structure(ii, 2, 5, 3);#ifdef __TRANS_THR__ #if 1//xchannel modify gop_str_nm[ii]= 5;#else//org gop_str_nm[ii]= psp->enc_ch[ii].gop_nm;#endif m_MSG ("[CH-%d : %d gop_str_nm]\n", ii, gop_str_nm[ii]);#endif /* mode : '0' normal record, '1' not record, default is '0' */ motionless_record_mode(ii, 0); /* ch_id : channel ID * motion sensitivity : 0 ~ 4 */ motion_sensitivity(ii, psp->enc_ch[ii].motion.sensitivity); /* ch_id : channel ID * motion area : 0 ~ 17 */ motion_area(ii, psp->enc_ch[ii].motion.area); }// pentamicro 2006.01.11 for(ii=0; ii < MAX_CH_NUM; ii++) encode_standard(ii, psp->enc_attr.encoding_type); m_MSG("\nEncoding Type = %d\n", psp->enc_attr.encoding_type); watermark_enable(psp->enc_attr.wm.flag_wm); m_MSG("Watermark Status = %s\n", psp->enc_attr.wm.flag_wm ? "Enable": "Disable"); if(psp->enc_attr.wm.flag_wm) { watermark_strength(psp->enc_attr.wm.strength); for(ii=0; ii < 16;ii++) watermark_key(psp->enc_attr.wm.key); m_MSG("Watermark Strength = %d\n", psp->enc_attr.wm.strength); m_MSG("Watermark Key = %d\n", psp->enc_attr.wm.key); } return SUCCESS;} void motion_sensitivity(UNS16 ch_id, UNS16 level){ UNS16 ii; UNS16 sensitivity; UNS16 pel_diff_threshold; UNS16 diff_pel_count_threshold; UNS16 motion_mb_count_threshold; UNS16 motionless_frame_count_threshold; /* MD Sensitivity Setting */ switch(level) { case 0: sensitivity = 1; pel_diff_threshold = 8; diff_pel_count_threshold = 4; motion_mb_count_threshold = 1; motionless_frame_count_threshold = 10; break; case 1: sensitivity = 2; pel_diff_threshold = 12; diff_pel_count_threshold = 12; motion_mb_count_threshold = 1; motionless_frame_count_threshold = 10; break; case 2: sensitivity = 3; pel_diff_threshold = 16; diff_pel_count_threshold = 20; motion_mb_count_threshold = 2; motionless_frame_count_threshold = 10; break; case 3: sensitivity = 4; pel_diff_threshold = 20; diff_pel_count_threshold = 28; motion_mb_count_threshold = 3; motionless_frame_count_threshold = 10; break; case 4: sensitivity = 5; pel_diff_threshold = 24; diff_pel_count_threshold = 36; motion_mb_count_threshold = 4; motionless_frame_count_threshold = 10; break; } /* ch_id : channel ID * sensitivity : sensitivity '0'(more sensitive) ~ '7'(less sensitive), default is '2' * pel_diff_threshold : pixel difference threshold, '0' ~ '63', default is 32 * diff_pel_count_threshold : different pixel count threshold * '0' ~ '127', default is '32' * motion_mb_count_threshold : motion MB count threshold * '0' ~ '255', default is '5' * motionless_frame_count_threshold : motion-less frame count threshold * '0' ~ '255', default is '5' */ motion_detection_parameter(ch_id, sensitivity, pel_diff_threshold, diff_pel_count_threshold, motion_mb_count_threshold, motionless_frame_count_threshold); }void motion_area(UNS16 ch_id, UNS32 *area){ UNS16 ii; UNS16 byte; UNS16 temp; UNS16 bitmap[54]; for (ii = 0; ii < AT2041_MB_TABLE; ii++) { for (byte = 0; byte < 3; byte++) { temp = (area[ii] >> (byte*8)) & 0xff; bitmap[ii * 3 + byte] = (((temp>>0 )&1)<<7)|(((temp>>1 )&1)<<6)| (((temp>>2 )&1)<<5)|(((temp>>3 )&1)<<4)| (((temp>>4 )&1)<<3)|(((temp>>5 )&1)<<2)| (((temp>>6 )&1)<<1)|(((temp>>7 )&1)<<0); } } /* ch_id : channel ID * bitmap : 1 bit is assigned to 2x2MBs and 3 bytes are assigned to 2 slices. * The MS bit of the first byte is aligned to the left-top 2x2MBs of the input video */ motion_detection_area_bitmap(ch_id, bitmap); }/* make_rectable * * input int *ch : frame_rate of ch[0] - ch[3], 0 - 30 range * int field_flag : 1 if field mode, 0 if frame mode * int max_frame : the maximum number of frames (30/60/120 or 25/50/100) * output int *rectable : recoding frame table (the length is same as max_frame) */void make_rectable(S32 *ch, S32 field_flag, S32 max_frame){ double sum, rch[4], pch[4], dtemp, mapped_time; int ii, jj, kk, bch[4], itemp, mapped_num; int rectable[120]; int index_table[60]; /* initialize rectable */ for (ii=0; ii<max_frame; ii++) rectable[ii] = 0x0c; // dummy channel /* 1st, framerate down if (sum of ch[] > max_frame) */ for (ii=0; ii < MAX_CH_NUM; ii++) rch[ii] = (double)ch[ii]; sum = rch[0] + rch[1] + rch[2] + rch[3]; if ((int)sum > max_frame) { for (ii=0; ii<MAX_CH_NUM; ii++) rch[ii] = (rch[ii] * max_frame) / sum; } /* 2nd, get picture period */ for (ii=0; ii<MAX_CH_NUM; ii++) if (rch[ii]==0.0) pch[ii] = (double)9999.0; // dummy channel else pch[ii] = (double)max_frame / rch[ii]; /* 3rd, sort by big channel ( ascending sort ) */ for (ii=0; ii<MAX_CH_NUM; ii++) bch[ii] = ii; for (kk=3; kk>0; kk--) { for (ii=0; ii<kk; ii++) { if (pch[ii] > pch[ii+1]) { dtemp = pch[ii]; pch[ii] = pch[ii+1]; pch[ii+1] = dtemp; itemp = bch[ii]; bch[ii] = bch[ii+1]; bch[ii+1] = itemp; } } } /* 4th, allocation to table */ for (ii=0; ii<MAX_CH_NUM; ii++) { if (pch[ii] == 9999.0) continue; mapped_num = 0; for (jj=0; jj<max_frame; jj++) if (rectable[jj] == 0x0c) break; for (kk=jj; kk<max_frame; kk++) { mapped_time = pch[ii] * (double)mapped_num; if (rectable[kk]==0x0c && (kk-jj)>=mapped_time) { rectable[kk] = (bch[ii]*2) + 1; mapped_num++; } if (field_flag) kk++; } }#if 0/* not use ( for 401x Quad table ) */ /* make index table */ for(ii=0; ii<(max_frame+1)/2; ii++) index_table[ii]=((rectable[ii*2]<<4) + (rectable[ii*2+1]&0xf)); #endif /* TW2834 switch mode setting */ /* set the queue size */ tw2834_write_reg(TW2834_PAGE1, 0x57, max_frame - 1); for(ii=0; ii < max_frame; ii++) { /* set record channel index */ tw2834_write_reg(TW2834_PAGE1, 0x59, rectable[ii]>>1); /* update index */ tw2834_write_reg(TW2834_PAGE1, 0x5a, 0x80 | ii); } return;}void get_time(time_t *time_a, struct tm *time_b, OPTION mode) { time(time_a); if (mode == MODE_1) { memcpy(time_b, localtime(time_a), sizeof(struct tm)); }} RETURN create_rec_file(ENC_OBJECT *peo){ S8 cur_date[16]; S8 cur_time[10]; S32 min_rest; S32 sec_rest; time_t cur_time_t; struct tm cur_tm; S8 v_mode[2] = "n"; S8 resolution[2] = "C"; S8 multi_ch[2] = "m"; S16 ii; S16 count = 0; UNS8 tmp_str[32]; peo->psp = gp_setup_param; /* NTSC/PAL */ if (peo->psp->gp.video_form == NTSC) { strcpy(v_mode, "n"); } else { strcpy(v_mode, "p"); } /* D1/CIF */ if (peo->psp->gp.resolution == D1) { strcpy(resolution, "D"); } else if (peo->psp->gp.resolution == CIF) { strcpy(resolution, "C"); } /* single/multi-channel */ for (ii = 0; ii < MAX_CH_NUM; ii++) { #if 1//xchannel add /* when the continue on/off */ if(peo->psp->enc_ch[ii].flag_conti_rec) if (peo->psp->enc_ch[ii].frame_rate != 0) count++; /* when the motion on/off */ if(peo->psp->enc_ch[ii].motion.flag) count++; /* when the sensor on/off */ if(peo->psp->enc_ch[ii].sensor.flag_in) count++; /* when the schedule on/off */ if(peo->psp->enc_ch[ii].schedule.flag) count++;#endif } if (count > 1) { strcpy(multi_ch, "m"); } else { strcpy(multi_ch, "s"); } memset(peo->fname_ps, 0x00, sizeof(peo->fname_ps)); /* dir info get current free space disk */ GET_DIR_NAME(&tmp_str, gv_cur_disk_id); strcpy(peo->dname_ps, tmp_str); /* time_t format -> tm format */ get_time(&cur_time_t, &cur_tm, MODE_1); sprintf(cur_date,"%04d%02d%02d", cur_tm.tm_year+1900, cur_tm.tm_mon + 1, cur_tm.tm_mday); sprintf(cur_time,"%02d%02d%02d", cur_tm.tm_hour, cur_tm.tm_min, cur_tm.tm_sec); sprintf(peo->fname_ps,"%s%s_%s_%s%s%s.ps", peo->dname_ps, cur_date, cur_time, v_mode, resolution, multi_ch); m_DEBUG("Filename : %s\n", peo->fname_ps); /* open video file */ if ( !(peo->p_fd_ps = fopen(peo->fname_ps, "wb")) ) { m_ERROR("pthread_enc.c:error In function 'fopen'\n"); return FAILURE; } /* update db info */ strcpy(peo->db_nrec.start_time, cur_time); /* calculate play time */ min_rest = cur_tm.tm_min%(g_rec_time_list[peo->psp->sys.disk.slice_time]); sec_rest = cur_tm.tm_sec + min_rest*60; peo->time_end = cur_time_t + ((g_rec_time_list[peo->psp->sys.disk.slice_time])*60 - sec_rest); return SUCCESS; }RETURN insert_program_header(SETUP_PARAM *psp){ S32 ii; S32 ret; UNS8 h_mbsize; UNS8 v_mbsize; UNS8 *hdr; CHINFO video_ch_info[16]; CHINFO audio_ch_info[16]; hdr = (UNS8 *) malloc(512 * sizeof(char)); /* initialize stream_type for all 16 channels */ if (psp->gp.video_form == PAL) { if (psp->gp.resolution == D1) { h_mbsize = 45; v_mbsize = 36; } else if (psp->gp.resolution == CIF) { h_mbsize = 22; v_mbsize = 18; } } else if (psp->gp.video_form == NTSC) { if (psp->gp.resolution == D1) { h_mbsize = 45;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -