Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** \file
- * Bitrate
- */
- #include "dryos.h"
- #include "bmp.h"
- #include "tasks.h"
- #include "debug.h"
- #include "menu.h"
- #include "property.h"
- #include "config.h"
- #include "gui.h"
- #include "lens.h"
- #include "cache_hacks.h"
- //----------------begin qscale-----------------
- CONFIG_INT( "h264.qscale.plus16", qscale_plus16, 16-8 );
- CONFIG_INT( "h264.bitrate-mode", bitrate_mode, 1 ); // off, CBR, VBR
- CONFIG_INT( "h264.bitrate-factor", bitrate_factor, 20 );
- CONFIG_INT( "h264.iframe-factor", ifact, 10 );
- CONFIG_INT( "h264.pframe-factor", pfact, 10 );
- CONFIG_INT( "h264.d1frame-factor", d1fact, 10 );
- CONFIG_INT( "h264.d2frame-factor", d2fact, 10 );
- CONFIG_INT( "h264.gop0-factor", gop0fact, 10 );
- CONFIG_INT( "h264.gop1-factor", gop1fact, 10 );
- //CONFIG_INT( "h264.gop2-factor", gop2fact, 10 );
- CONFIG_INT( "h264.gop3-factor", gop3fact, 10 );
- CONFIG_INT( "h264.gop4-factor", gop4fact, 10 );
- CONFIG_INT( "h264.paverage", paverage, 0 );
- CONFIG_INT( "h264.paverage", pdebug, 0 );
- CONFIG_INT( "h264.dblockA", pdblock_A, 0 );
- CONFIG_INT( "h264.dblockB", pdblock_B, 0 );
- CONFIG_INT( "h264.goplng", goplength, 12 );
- CONFIG_INT( "h264.picqpc", p_picqpc, 0 );
- CONFIG_INT( "h264.qscale.slice", qscale_slice, 0 );
- CONFIG_INT( "time.indicator", time_indicator, 1); // 0 = off, 1 = current clip length, 2 = time remaining until filling the card, 3 = time remaining until 4GB
- CONFIG_INT( "bitrate.indicator", bitrate_indicator, 1);
- int video_mode[5];
- PROP_HANDLER(PROP_VIDEO_MODE)
- {
- memcpy(video_mode, buf, 20);
- }
- int hacked=0;
- //16 Slices
- int slice_array[] = { 0, 144, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86 };
- int time_indic_x = 720 - 160;
- int time_indic_y = 0;
- int time_indic_width = 160;
- int time_indic_height = 20;
- int time_indic_warning = 120;
- static int time_indic_font = FONT(FONT_MED, COLOR_RED, COLOR_BLACK );
- int measured_bitrate = 0; // mbps
- //~ int free_space_32k = 0;
- int movie_bytes_written_32k = 0;
- #define qscale (((int)qscale_plus16) - 16)
- //#define qscalemin (((int)qscale_plusMin) - 41)
- #define dblock_A (((int)pdblock_A) - 6)
- #define dblock_B (((int)pdblock_B) - 6)
- #define picqpc (((int)p_picqpc) - 7)
- #define BL_INSTR(pc,dest) \
- ( 0xEB000000 \
- | ((( ((uint32_t)dest) - ((uint32_t)pc) - 8 ) >> 2) & 0x00FFFFFF) \
- )
- int bitrate_dirty = 0;
- // don't call those outside vbr_fix / vbr_set
- void mvrFixQScale(uint16_t *); // only safe to call when not recording
- void mvrSetDefQScale(int16_t *); // when recording, only change qscale by 1 at a time
- // otherwise ther appears a nice error message which shows the shutter count [quote AlinS] :)
- //void mvrSetDeblockingFilter(int32_t *, int32_t *); //-6 to 6
- #ifndef CONFIG_50D
- void mvrSetDeblockingFilter(int32_t *);
- void JPCORE_DBFALPHA_DBFBETA(int8_t *, int8_t *);
- void mvrSetQscaleYC(int32_t *);
- void mvrSetLimitQScale(int32_t *);
- void AJ_JpcoreSliceqpdD_Qscale(int16_t *);
- uint32_t hijack_func = 0;
- uint32_t hijack_handler(uint32_t parm1, uint32_t parm2, uint32_t parm3, uint32_t parm4)
- {
- uint32_t (*callee)(uint32_t, uint32_t, uint32_t, uint32_t) = hijack_func;
- /* do stuff here */
- return callee(parm1, parm2, parm3, parm4);
- }
- void hijack_function(uint32_t address, uint32_t dest)
- {
- hijack_func = dest;
- cache_fake(address, BL_INSTR(address, &hijack_handler), TYPE_ICACHE);
- }
- #endif
- static struct mvr_config mvr_config_copy;
- void cbr_init()
- {
- memcpy(&mvr_config_copy, &mvr_config, sizeof(mvr_config_copy));
- }
- void vbr_fix(uint16_t param)
- {
- if (!lv) return;
- if (!is_movie_mode()) return;
- if (recording) return; // err70 if you do this while recording
- mvrFixQScale(¶m);
- }
- void big_gop(int param)
- {
- video_mode[3] = param; //Gop Length
- prop_request_change(PROP_VIDEO_MODE, video_mode, 20);
- // Edit this to play with Gop & Co.
- #ifndef CONFIG_50D
- #ifdef CONFIG_600D
- #define UNK_GOP_LOC 0xFF25516C
- #define GOP_MISMATCH_LOC 0xFF048054
- #elif defined CONFIG_1100D
- #define UNK_GOP_LOC 0xFF2478E8
- #define GOP_MISMATCH_LOC 0xFF047E4C
- #endif
- cache_fetch_line(UNK_GOP_LOC, TYPE_ICACHE);
- cache_fake(UNK_GOP_LOC , 0xE1A00000, TYPE_ICACHE);
- // Movie "Gop Mismatch"
- cache_fetch_line(GOP_MISMATCH_LOC, TYPE_ICACHE);
- cache_fake(GOP_MISMATCH_LOC , 0xE1A00000, TYPE_ICACHE);
- //hijack_function(0xFF25516C, 0xE1A00000);
- //hijack_function(0xFF254EC8, 0xeb0c4bde);
- #endif
- }
- void hack_slice()
- {
- #ifdef CONFIG_600D
- #define SLICE_HACK_LEN 3
- #define SLICE_HACK_LOC {0xFF1CA5EC, 0xFF1CA144, 0xFF1C94A4}
- #elif defined(CONFIG_1100D)
- #define SLICE_HACK_LEN 3
- #define SLICE_HACK_LOC {0xFF1B8F74, 0xFF1B9BE0, 0xFF1BA0BC}
- #endif
- uint32_t slice_hacks[SLICE_HACK_LEN] = SLICE_HACK_LOC;
- for(int i=0;i<SLICE_HACK_LEN;++i) {
- cache_fetch_line(slice_hacks[i], TYPE_ICACHE); // Nop Slice Setting
- cache_fake(slice_hacks[i] , 0xE1A00000, TYPE_ICACHE);
- }
- hacked=1;
- }
- void hack_deblock()
- {
- //Nop Deblocking filter setting so it respects ours.
- // str:_GopSize__IOptSize2__POptSize2_DBF_A_DBF_B+924
- // DefQScale__D1__D2__IOptSize__POptSize__Opt
- #ifdef CONFIG_600D
- #define DEBLOCK_HACK_LEN 2
- #define DEBLOCK_HACK_LOC {0xFF1CA664, 0xFF1CA144}
- #elif defined(CONFIG_1100D)
- #define DEBLOCK_HACK_LEN 2
- #define DEBLOCK_HACK_LOC {0xFF1BA134, 0xFF1B9C14}
- #endif
- uint32_t deblock_hacks[DEBLOCK_HACK_LEN] = DEBLOCK_HACK_LOC;
- for(int i=0;i<DEBLOCK_HACK_LEN;++i) {
- cache_fetch_line(deblock_hacks[i], TYPE_ICACHE);
- cache_fake(deblock_hacks[i] , 0xE1A00000, TYPE_ICACHE);
- }
- }
- void debugprints24p()
- {
- #ifdef CONFIG_600D
- if (video_mode[2] == 24)
- { int* xopt1 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 2 * MOV_OPT_STEP + 0;
- int* xopt2 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 2 * MOV_OPT_STEP + 1;
- int* xdopt1 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 2 * MOV_OPT_STEP + 2;
- int* xdopt2 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 2 * MOV_OPT_STEP + 3;
- int* xgopt0 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 2 * MOV_GOP_OPT_STEP + 0;
- int* xgopt1 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 2 * MOV_GOP_OPT_STEP + 1;
- int* xgopt2 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 2 * MOV_GOP_OPT_STEP + 2;
- int* xgopt3 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 2 * MOV_GOP_OPT_STEP + 3;
- int* xgopt4 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 2 * MOV_GOP_OPT_STEP + 4;
- bmp_printf(FONT_MED, 10,40, "I: %d P: %d D1: %d D2: %d", *xopt1, *xopt2, *xdopt1, *xdopt2);
- bmp_printf(FONT_MED, 10,80, "g0: %d g1: %d g2: %d g3: %d g4 %d", *xgopt0, *xgopt1, *xgopt2, *xgopt3, *xgopt4);
- }
- if (video_mode[2] == 30)
- {
- int* xopt1 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 0 * MOV_OPT_STEP + 0;
- int* xopt2 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 0 * MOV_OPT_STEP + 1;
- int* xdopt1 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 0 * MOV_OPT_STEP + 2;
- int* xdopt2 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + 0 * MOV_OPT_STEP + 3;
- int* xgopt0 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 0 * MOV_GOP_OPT_STEP + 0;
- int* xgopt1 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 0 * MOV_GOP_OPT_STEP + 1;
- int* xgopt2 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 0 * MOV_GOP_OPT_STEP + 2;
- int* xgopt3 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 0 * MOV_GOP_OPT_STEP + 3;
- int* xgopt4 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 0 * MOV_GOP_OPT_STEP + 4;
- bmp_printf(FONT_MED, 10,40, "I: %d P: %d D1: %d D2: %d", *xopt1, *xopt2, *xdopt1, *xdopt2);
- bmp_printf(FONT_MED, 10,80, "g0: %d g1: %d g2: %d g3: %d g4 %d", *xgopt0, *xgopt1, *xgopt2, *xgopt3, *xgopt4);
- }
- /*
- int* xalpha = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 586; //0x929;
- int* xbeta = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + 587; //0x92a;
- int* xgops = (int*) &(mvr_config.gop_size_d);
- int* xgopy = (int*) &(mvr_config.x124);
- int* xgopx = (int*) &(mvr_config.gop_zoneX);
- int* xgopz = (int*) &(mvr_config.gop_zoneZ);
- bmp_printf(FONT_SMALL, 10,40, "I: 0x%08X P: 0x%08X D1: %08X D2: %08X", xopt1, xopt2, xdopt1, xdopt2);
- bmp_printf(FONT_SMALL, 10,50, "g0: 0x%08X g1: 0x%08X g2: %08X g3: %08X g4 %08X", xgopt0, xgopt1, xgopt2, xgopt3, xgopt4);
- int* xspspps = (int*) (0xa083);
- int* xspspp2 = (int*) (0xa090);
- bmp_printf(FONT_MED, 10,180, "A083: %d A090: %d" , *xspspps, *xspspp2);
- //bmp_hexdump(FONT_SMALL, 0, 300, 0x6108, 32*10);
- // 786366719 2EDF00FF
- bmp_printf(FONT_MED, 10,40, "I: %d P: %d D1: %d D2: %d", *xopt1, *xopt2, *xdopt1, *xdopt2);
- bmp_printf(FONT_MED, 10,80, "g0: %d g1: %d g2: %d g3: %d g4 %d", *xgopt0, *xgopt1, *xgopt2, *xgopt3, *xgopt4);
- bmp_printf(FONT_MED, 10,120, "GP: %X v: %d U:%X v:%d" , xgops, *xgops, xgopy, *xgopy);
- bmp_printf(FONT_MED, 10,160, "GX: %X v: %d GZ:%X v:%d" , xgopx, *xgopx, xgopz, *xgopz);
- int* fooz=(int*)(0x5754);
- int* booz=(int*)(0x5750);
- int* dooz=(int*)(0xa083);
- int* fooz=(int*)(0x6138); //a
- int* booz=(int*)(0xFF5DF584); //a0
- int* dooz=(int*)(0xFF5DF588); //78
- uint16_t* fooz=(uint16_t*)(0x62A2); //a
- uint16_t* booz=(uint16_t*)(0x62A4); //a0
- */
- int8_t* theqscale = (int8_t*) (0x6ce0);
- int16_t* defqscale = (int16_t*) (0x629A);
- bmp_printf(FONT_MED, 10,120, "Slice: %d DefQ: %d, QS: %d H: %d", *theqscale, *defqscale, qscale_slice, hacked);
- /*
- int* xq1 = (int*) &(mvr_config.qscale_related_1);
- int* xq2 = (int*) &(mvr_config.qscale_related_2);
- int* xq3 = (int*) &(mvr_config.qscale_related_3);
- bmp_printf(FONT_MED, 10,160, "Q1: %d Q2: %d Q3: %d" , *xq1, *xq2, *xq3);
- //65521
- int* xqq1 = (int*) &(mvr_config.another_def_q_scale);
- int* xqq2 = (int*) &(mvr_config.IniQScale);
- int* xqq3 = (int*) &(mvr_config.actual_qscale_maybe);
- bmp_printf(FONT_MED, 10,200, "Def: %d INI: %d ACT: %d" , *xqq1, *xqq2, *xqq3);
- int* xqq1 = (int*) (0x63F0);
- int* xqq2 = (int*) (0x63EC);
- int* xqq3 = (int*) (0x63E8);
- int* xqq4 = (int*) (0x63E4);
- bmp_printf(FONT_MED, 10,200, "Def: %d INI: %d ACT: %d LS: %d" , *xqq1, *xqq2, *xqq3, *xqq4);
- //0xFF5DF64C
- 0x613C = arg0
- *0x6140 = (sp0->off_0x20)->off_0x8
- *0x614C = arg4
- *0x6158 = sp0->off_0x18
- *0x615C = sp0->off_0x20
- *0x6128 = (sp0->off_0x20)->off_0x4
- *0x6144 = arg3
- *0x6148 = arg4->off_0x8
- *0x6150 = arg4->off_0xC
- int* xqq1 = (int*) (0x613C);
- int* xqq2 = (int*) (0x614C);
- int* xqq3 = (int*) (0x6144);
- int* xqq4 = (int*) (0x615C);
- int* xqq5 = (int*) (0x6140);
- bmp_printf(FONT_MED, 10,200, "Def: %d INI: %d ACT: %d LS: %d ad: %d" , *xqq1, *xqq2, *xqq3, *xqq4, *xqq5);
- int* xsz1 = (int*) (0x5754);
- int* xsz2 = (int*) (0x5750);
- bmp_printf(FONT_MED, 10,240, "Size1: %d Size2: %d", *xsz1, *xsz2);
- */
- #endif
- }
- #ifdef CONFIG_600D
- /*
- void gop_set(int den, int gopxscale, int gopyscale, int gopzscale)
- {
- int* goptb3 = (int*) &(mvr_config.gop_zoneB);
- int* goptb4 = (int*) (int*) &(mvr_config_copy.gop_zoneB);
- (*goptb3) = (*goptb4) + 1;
- int* goptx3 = (int*) &(mvr_config.x124);
- int* goptx4 = (int*) (int*) &(mvr_config_copy.x124);
- (*goptx3) = (*goptx4) * gopxscale / den;
- int* gopty3 = (int*) &(mvr_config.gop_zoneY);
- int* gopty4 = (int*) (int*) &(mvr_config_copy.gop_zoneY);
- (*gopty3) = (*gopty4) * gopyscale / den;
- int* goptz3 = (int*) &(mvr_config.gop_zoneZ);
- int* goptz4 = (int*) (int*) &(mvr_config_copy.gop_zoneZ);
- (*goptz3) = (*goptz4) * gopzscale / den;
- }
- */
- #endif
- // may be dangerous if mvr_config and numbers are incorrect
- void opt_set(int num, int den, int iscale, int pscale, int d1scale, int d2scale, int gop0scale, int gop1scale, int gop3scale, int gop4scale)
- {
- int i, j;
- #if !defined(CONFIG_5D2) && !defined(CONFIG_500D)
- int avgI=0;
- int avgP=0;
- int avd1=0;
- int avd2=0;
- int agop0=0;
- int agop1=0;
- // int agop2=0;
- int agop3=0;
- int agop4=0;
- for ( int qq =0; qq < MOV_RES_AND_FPS_COMBINATIONS; qq++)
- { int* opt1 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + qq * MOV_OPT_STEP + 0;
- int* opt2 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + qq * MOV_OPT_STEP + 1;
- int* dopt1 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + qq * MOV_OPT_STEP + 2;
- int* dopt2 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + qq * MOV_OPT_STEP + 3;
- avd1 += (*dopt1) / (qq+1);
- avd2 += (*dopt2) / (qq+1);
- avgI += (*opt1) / (qq+1);
- avgP += (*opt2) / (qq+1);
- int* gopt0 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + qq * MOV_GOP_OPT_STEP + 0;
- int* gopt1 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + qq * MOV_GOP_OPT_STEP + 1;
- // int* gopt2 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + qq * MOV_GOP_OPT_STEP + 2;
- int* gopt3 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + qq * MOV_GOP_OPT_STEP + 3;
- int* gopt4 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + qq * MOV_GOP_OPT_STEP + 4;
- agop0+= (*gopt0) / (qq+1);
- agop1+= (*gopt1) / (qq+1);
- // agop2+= (*gopt2) / (qq+1);
- agop3+= (*gopt3) / (qq+1);
- agop4+= (*gopt4) / (qq+1);
- }
- #endif
- // 24P Defaults
- // I 62992200 (3c12F48) p 19594200 (12AFBD8)
- //d1 262144 = 40000 d2 262144
- //g0 3833856 (3A8000) g1 3309568 (328000) g2 2785284 (2A8004) g3 2260992 (228000) g4 17736704 (10EA400)
- //DSizes: 78643, 288358, 393216, 524288, 629145, 681574
- //G1-G2 = 80,000h
- //G2-G3 = 80,004h
- //Really High: 1.7, 1.7, 1.1 1.1 gop4 2.2 q-16
- //Stable BRS. 1,1, 2.5x2.5, 3x Many doesn't matter
- //Largest values: 1.9:1.0:1.5,1.5,2,2,1,2,2
- //100MBPS Crop 1250 , averaging P 1.7 vs 1.9
- for (i = 0; i < MOV_RES_AND_FPS_COMBINATIONS; i++) // 7 combinations of resolution / fps
- {
- #ifdef CONFIG_500D
- #define fullhd_30fps_opt_size_I fullhd_20fps_opt_size_I
- #define fullhd_30fps_gop_opt_0 fullhd_20fps_gop_opt_0
- #endif
- #ifdef CONFIG_5D2
- #define fullhd_30fps_opt_size_I v1920_30fps_opt_size_I
- #endif
- #if !defined(CONFIG_5D2) && !defined(CONFIG_500D)
- if (paverage == 1)
- {
- int* opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 0;
- (*opt) = avgI * iscale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 1;
- (*opt) = avgP * pscale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 2;
- (*opt) = avd1 * d1scale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 3;
- (*opt) = avd2 * d2scale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 0;
- (*opt) = agop0 * gop0scale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 1;
- (*opt) = agop1 * gop1scale / den;
- //opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 2;
- //(*opt) = agop2 * gop2scale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 3;
- (*opt) = agop3 * gop3scale / den;
- opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 4;
- (*opt) = agop4 * gop4scale / den;
- }
- else
- {
- int* opt3 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 0;
- int* opt4 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 0;
- (*opt3) = (*opt4) * iscale / den;
- int* opt5 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 1;
- int* opt6 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 1;
- (*opt5) = (*opt6) * pscale / den;
- ///Dopts
- int* dopt3 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 2;
- int* dopt4 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 2;
- (*dopt3) = (*dopt4) * d1scale / den;
- int* dopt5 = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 3;
- int* dopt6 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 3;
- (*dopt5) = (*dopt6) * d2scale / den;
- //gops
- int* gopt0 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 0;
- int* gopt1 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 0;
- (*gopt0) = (*gopt1) * gop0scale / den;
- int* gopt2 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 1;
- int* gopt3 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 1;
- (*gopt2) = (*gopt3) * gop1scale / den;
- int* gopt4 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 2;
- //int* gopt5 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 2;
- // (*gopt4) = (*gopt5) * gop2scale / den;
- //5570568 Gop 2 is calculated from P/I sizes.
- //7261685
- int* gopt6 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 3;
- int* gopt7 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 3;
- (*gopt6) = (*gopt7) * gop3scale / den;
- int* gopt8 = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 4;
- int* gopt9 = (int*) (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + 4;
- (*gopt8) = (*gopt9) * gop4scale / den;
- }
- #endif
- /*
- for (j = 0; j < MOV_OPT_NUM_PARAMS; j++)
- { int* opt0 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + j;
- if (*opt0 < 10000) { bmp_printf(FONT_LARGE, 0, 50, "opt_set: err %d %d %d ", i, j, *opt0); return; }
- avg += (*opt0) / (i+1) ;
- }
- int* opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP;
- (*opt) = avg * num / den;
- opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + 1;
- (*opt) = avg * num / den;
- for (j = 0; j < MOV_OPT_NUM_PARAMS; j++)
- { int* opt0 = (int*) &(mvr_config_copy.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + j;
- int* opt = (int*) &(mvr_config.fullhd_30fps_opt_size_I) + i * MOV_OPT_STEP + j;
- if (*opt0 < 10000) { bmp_printf(FONT_LARGE, 0, 50, "opt_set: err %d %d %d ", i, j, *opt0); return; }
- (*opt) = (*opt0) * num / den;
- }*
- for (j = 0; j < MOV_GOP_OPT_NUM_PARAMS; j++)
- {
- int* opt0 = (int*) &(mvr_config_copy.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + j;
- int* opt = (int*) &(mvr_config.fullhd_30fps_gop_opt_0) + i * MOV_GOP_OPT_STEP + j;
- if (*opt0 < 10000) { bmp_printf(FONT_LARGE, 0, 50, "gop_set: err %d %d %d ", i, j, *opt0); return; }
- (*opt) = (*opt0) * num / den;
- }*/
- }
- }
- void bitrate_set()
- {
- if (!lv) return;
- if (!is_movie_mode()) return;
- if (gui_menu_shown()) return;
- if (recording) return;
- #ifdef CONFIG_5D3
- //~ MEM(0x27880) = bitrate * 10000000;
- return;
- #endif
- if (bitrate_mode == 0)
- {
- if (!bitrate_dirty) return;
- vbr_fix(0);
- opt_set(1,1,1,1,1,1,1,1,1,1);
- }
- else if (bitrate_mode == 1) // CBR
- {
- if (bitrate_factor == 10 && !bitrate_dirty) return;
- vbr_fix(0);
- opt_set(bitrate_factor, 10, ifact, pfact, d1fact, d2fact, gop0fact, gop1fact, gop3fact, gop4fact);
- hack_deblock();
- if (qscale_slice != 0) { hack_slice(); }
- int8_t* xalpha = (int8_t*) (0x6ce1);
- int8_t* xbeta = (int8_t*) (0x6ce2);
- int8_t* xpicqpy = (int8_t*) (0x6ce3);
- int8_t* xpicqpc = (int8_t*) (0x6ce4);
- /*
- int16_t* sliceqpd = qscalemin;
- AJ_JpcoreSliceqpdD_Qscale(&sliceqpd);
- */
- int dbarg[2];
- dbarg[0] = dblock_A;
- dbarg[1] = dblock_B;
- int ycarg[2];
- ycarg[0] = -12;
- ycarg[1] = picqpc; //58 Highest value before Freezing@26 QPY
- #ifndef CONFIG_1100D
- mvrSetDeblockingFilter(&dbarg);
- mvrSetQscaleYC(&ycarg); // Set Qscale luma/chroma picQ
- #endif
- if (picqpc == 0) { *xpicqpy=20; /*highest value without frying.*/ }
- else { *xpicqpy=26; /*highest value without frying.*/ }
- /*
- int qlarg[2];
- qlarg[0] = 0;
- qlarg[1] = 6;
- mvrSetLimitQScale(&qlarg);
- */
- //uint16_t* xqscalem=(uint16_t*)(0x62A2);
- //*xqscalem=2;
- //int8_t* xalpha;
- //int8_t* xbeta;
- //*(int8_t*)0x6CE1 = xalpha;
- //*(int8_t*)0x6CE2 = xbeta;
- //int* xBitrate=(int*)(0x1E44);
- /*
- int8_t* theboss = (int8_t*) (0x6ce0);
- bmp_printf(FONT_MED, 10,20, "Py: %d PC: %d Addr %X", *xpicqpy, *xpicqpc, *theboss);
- //bmp_printf(FONT_MED, 10,20, "Py: %d PC: %d GopL %d BR: %d", *xpicqpy, *xpicqpc, video_mode[3], *xBitrate);
- //bmp_hexdump(FONT_SMALL, 0, 300, 0x6108, 32*10);
- //*xBitrate= 10417124;
- //9417124 Default
- /*
- bmp_printf(FONT_MED, 0, 300, "PROP_VIDEO_MODE: %d | %d | %d | %d", *fooz, *booz, video_mode[2], video_mode[3]);
- */
- big_gop(goplength);
- bmp_printf(FONT_MED, 10,20, "Py: %d PC: %d GopL %d", *xpicqpy, *xpicqpc, video_mode[3]);
- }
- else if (bitrate_mode == 2) // QScale
- {
- vbr_fix(1);
- // opt_set(1,1,1,1);
- opt_set(bitrate_factor, 10, ifact, pfact, d1fact, d2fact, gop0fact, gop1fact, gop3fact, gop4fact);
- hack_deblock();
- int16_t q = qscale;
- mvrSetDefQScale(&q);
- //int16_t* defqscale = (int16_t*) (0x629A);
- //*defqscale=-17;
- //int8_t* theqscale = (int8_t*) (0x6ce0);
- //*theqscale=70;
- //AJ_JpcoreSliceqpdD_Qscale(111);
- //EngDrvOut(0xC0F113C4, 0);
- /*int qlarg[2];
- qlarg[0] = 0;
- qlarg[1] = 6;
- mvrSetLimitQScale(&qlarg);
- */
- //uint16_t* xqscalem=(uint16_t*)(0x62A2);
- //*xqscalem=2;
- #ifndef CONFIG_1100D
- int dbarg[2];
- dbarg[0] = dblock_A;
- dbarg[1] = dblock_B;
- mvrSetDeblockingFilter(&dbarg);
- int ycarg[2];
- ycarg[0] = -12;
- ycarg[1] = picqpc; //58 Highest value before Freezing@26 QPY
- mvrSetQscaleYC(&ycarg); // Set Qscale luma/chroma picQ
- #endif
- int8_t* xpicqpy = (int8_t*) (0x6ce3);
- int8_t* xpicqpc = (int8_t*) (0x6ce4);
- if (picqpc == 0) { *xpicqpy=20; /*highest value without frying.*/ }
- else { *xpicqpy=26; /*highest value without frying.*/ }
- big_gop(goplength); //Sets Gop Length
- }
- bitrate_dirty = 1;
- }
- static void
- bitrate_print(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- int fnt = selected ? MENU_FONT_SEL : MENU_FONT;
- if (bitrate_mode == 0)
- {
- bmp_printf( fnt, x, y, "Bit Rate : FW default%s", bitrate_dirty ? "(reboot)" : "");
- menu_draw_icon(x, y, bitrate_dirty ? MNI_WARNING : MNI_OFF, 0);
- }
- else if (bitrate_mode == 1)
- {
- if (bitrate_factor > 10) fnt = FONT(fnt, bitrate_factor > 14 ? COLOR_RED : COLOR_YELLOW, FONT_BG(fnt));
- if (bitrate_factor < 7) fnt = FONT(fnt, bitrate_factor < 4 ? COLOR_RED : COLOR_YELLOW, FONT_BG(fnt));
- bmp_printf( fnt, x, y, "Bit Rate (CBR): %s%d.%dx%s", bitrate_factor>10 ? "up to " : "", bitrate_factor/10, bitrate_factor%10, bitrate_dirty || bitrate_factor != 10 ? "" : " (FW default)");
- menu_draw_icon(x, y, bitrate_dirty || bitrate_factor != 10 ? MNI_PERCENT : MNI_OFF, bitrate_factor * 100 / 30);
- }
- else if (bitrate_mode == 2)
- {
- fnt = FONT(fnt, COLOR_RED, FONT_BG(fnt));
- bmp_printf( fnt, x, y, "Bit Rate (VBR): QScale %d", qscale);
- menu_draw_icon(x, y, MNI_PERCENT, -(qscale-16) * 100 / 32);
- }
- }
- void bitrate_mvr_log(char* mvr_logfile_buffer)
- {
- if (bitrate_mode == 1)
- {
- MVR_LOG_APPEND (
- "Bit Rate (CBR) : %d.%dx", bitrate_factor/10, bitrate_factor%10
- );
- }
- else if (bitrate_mode == 2)
- {
- MVR_LOG_APPEND (
- "Bit Rate (VBR) : QScale %d", qscale
- );
- }
- }
- static void
- cbr_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "CBR factor : %d.%dx", bitrate_factor/10, bitrate_factor%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, bitrate_factor * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- gfact0_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Gop0 factor : %d.%dx", gop0fact/10, gop0fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, gop0fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- gfact1_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Gop1 factor : %d.%dx", gop1fact/10, gop1fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, gop1fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- /*
- gfact2_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Gop2 factor : %d.%dx", gop2fact/10, gop2fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, gop2fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- */
- gfact3_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Gop3 factor : %d.%dx", gop3fact/10, gop3fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, gop3fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- gfact4_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Gop4 factor : %d.%dx", gop4fact/10, gop4fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, gop4fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- ifact_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "I factor : %d.%dx", ifact/10, ifact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, ifact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- pfact_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "P factor : %d.%dx", pfact/10, pfact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, pfact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- d1fact_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "D1 factor : %d.%dx", d1fact/10, d1fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, d1fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- d2fact_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "D2 factor : %d.%dx", d2fact/10, d2fact%10);
- if (bitrate_mode == 1) menu_draw_icon(x, y, MNI_PERCENT, d2fact * 100 / 30);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "CBR mode inactive => CBR setting not used.");
- }
- static void
- qscale_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "Qscale factor : %d", qscale);
- if (bitrate_mode == 2) menu_draw_icon(x, y, MNI_PERCENT, -(qscale-16) * 100 / 32);
- else menu_draw_icon(x, y, MNI_WARNING, (intptr_t) "VBR mode inactive");
- }
- static void
- qscale_slice_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, "JP Slice : %d", slice_array[qscale_slice]);
- }
- static void
- goplength_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, " Gop : %d", goplength);
- }
- static void
- picqpc_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, " PicPC : %d", picqpc);
- }
- static void
- dblockA_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, " DblockA : %d", dblock_A);
- menu_draw_icon(x, y, MNI_PERCENT, -(dblock_A-6) * 100 / 12);
- }
- static void
- dblockB_display(
- void * priv,
- int x,
- int y,
- int selected
- )
- {
- bmp_printf( selected ? MENU_FONT_SEL : MENU_FONT, x, y, " DblockB : %d", dblock_B);
- menu_draw_icon(x, y, MNI_PERCENT, -(dblock_B-6) * 100 / 12);
- }
- static void
- bitrate_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- bitrate_factor = mod(bitrate_factor + delta - 1, 30) + 1;
- }
- static void
- i_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- ifact = mod(ifact + delta - 1, 30) + 1;
- }
- static void
- p_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- pfact = mod(pfact + delta - 1, 30) + 1;
- }
- static void
- d1_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- d1fact = mod(d1fact + delta - 1, 30) + 1;
- }
- static void
- d2_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- d2fact = mod(d2fact + delta - 1, 30) + 1;
- }
- static void
- gop0_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- gop0fact = mod(gop0fact + delta - 1, 30) + 1;
- }
- static void
- gop1_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- gop1fact = mod(gop1fact + delta - 1, 30) + 1;
- }
- /*
- static void
- gop2_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- gop2fact = mod(gop2fact + delta - 1, 30) + 1;
- }
- */
- static void
- gop3_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- gop3fact = mod(gop3fact + delta - 1, 30) + 1;
- }
- static void
- gop4_factor_toggle(void* priv, int delta)
- {
- if (recording) return;
- gop4fact = mod(gop4fact + delta - 1, 30) + 1;
- }
- static void
- goplength_toggle(void* priv, int delta)
- {
- if (recording) return;
- goplength = mod(goplength - delta, 120);
- }
- static void
- qscale_slice_toggle(void* priv, int delta)
- {
- if (recording) return;
- qscale_slice = mod(qscale_slice - delta, 47);
- }
- static void
- picqpc_toggle(void* priv, int delta)
- {
- if (recording) return;
- p_picqpc = mod(p_picqpc - delta, 8);
- }
- static void
- bitrate_dblockA_toggle(void* priv, int delta)
- {
- if (recording) return;
- pdblock_A = mod(pdblock_A - delta, 13);
- }
- static void
- bitrate_dblockB_toggle(void* priv, int delta)
- {
- if (recording) return;
- pdblock_B = mod(pdblock_B - delta, 13);
- }
- static void
- bitrate_qscale_toggle(void* priv, int delta)
- {
- if (recording) return;
- qscale_plus16 = mod(qscale_plus16 - delta, 33);
- }
- static void
- bitrate_toggle_mode(void* priv, int delta)
- {
- if (recording) return;
- menu_ternary_toggle(priv, delta);
- }
- static void
- bitrate_toggle(void* priv, int delta)
- {
- if (bitrate_mode == 1) bitrate_factor_toggle(priv, delta);
- else if (bitrate_mode == 2) bitrate_qscale_toggle(priv, delta);
- }
- int movie_elapsed_time_01s = 0; // seconds since starting the current movie * 10
- #ifdef CONFIG_5D3
- extern int cluster_size;
- extern int free_space_raw;
- #else
- PROP_INT(PROP_CLUSTER_SIZE, cluster_size);
- PROP_INT(PROP_FREE_SPACE, free_space_raw);
- #endif
- #define free_space_32k (free_space_raw * (cluster_size>>10) / (32768>>10))
- void free_space_show()
- {
- if (!get_global_draw()) return;
- if (gui_menu_shown()) return;
- if (recording && time_indicator) return;
- int fsg = free_space_32k >> 15;
- int fsgr = free_space_32k - (fsg << 15);
- int fsgf = (fsgr * 10) >> 15;
- bmp_printf(
- FONT(SHADOW_FONT(FONT_MED), COLOR_WHITE, COLOR_BLACK),
- time_indic_x + 160 - 6 * font_med.width,
- time_indic_y,
- "%d.%dGB",
- fsg,
- fsgf
- );
- }
- void fps_show()
- {
- if (!get_global_draw()) return;
- if (gui_menu_shown()) return;
- if (!is_movie_mode() || recording) return;
- //~ if (hdmi_code == 5) return; // workaround
- int screen_layout = get_screen_layout();
- if (screen_layout > SCREENLAYOUT_3_2_or_4_3) return;
- /* bmp_printf(
- SHADOW_FONT(FONT_MED),
- time_indic_x + 160 - (video_mode_resolution == 0 ? 7 : 6) * font_med.width,
- time_indic_y + font_med.height - 3,
- "%d%s%s",
- video_mode_fps,
- video_mode_crop ? "+" : "p",
- video_mode_resolution == 0 ? "1080" :
- video_mode_resolution == 1 ? "720" : "VGA"
- );*/
- int f = fps_get_current_x1000();
- bmp_printf(
- SHADOW_FONT(FONT_MED),
- time_indic_x + 160 - 6 * font_med.width,
- time_indic_y + font_med.height - 3,
- "%2d.%03d",
- f / 1000, f % 1000
- );
- }
- void free_space_show_photomode()
- {
- int fsg = free_space_32k >> 15;
- int fsgr = free_space_32k - (fsg << 15);
- int fsgf = (fsgr * 10) >> 15;
- int x = time_indic_x + 2 * font_med.width;
- int y = 452;
- bmp_printf(
- FONT(SHADOW_FONT(FONT_LARGE), COLOR_FG_NONLV, bmp_getpixel(x-10,y+10)),
- x, y,
- "%d.%dGB",
- fsg,
- fsgf
- );
- }
- void time_indicator_show()
- {
- if (!get_global_draw()) return;
- if (!recording)
- {
- free_space_show();
- return;
- }
- // time until filling the card
- // in "movie_elapsed_time_01s" seconds, the camera saved "movie_bytes_written_32k"x32kbytes, and there are left "free_space_32k"x32kbytes
- int time_cardfill = movie_elapsed_time_01s * free_space_32k / movie_bytes_written_32k / 10;
- // time until 4 GB
- int time_4gb = movie_elapsed_time_01s * (4 * 1024 * 1024 / 32 - movie_bytes_written_32k) / movie_bytes_written_32k / 10;
- //~ bmp_printf(FONT_MED, 0, 300, "%d %d %d %d ", movie_elapsed_time_01s, movie_elapsed_ticks, rec_time_card, rec_time_4gb);
- // what to display
- int dispvalue = time_indicator == 1 ? movie_elapsed_time_01s / 10:
- time_indicator == 2 ? time_cardfill :
- time_indicator == 3 ? MIN(time_4gb, time_cardfill)
- : 0;
- if (time_indicator)
- {
- bmp_printf(
- time_4gb < time_indic_warning ? time_indic_font : FONT(FONT_MED, COLOR_WHITE, TOPBAR_BGCOLOR),
- time_indic_x + 160 - 6 * font_med.width,
- time_indic_y,
- "%3d:%02d",
- dispvalue / 60,
- dispvalue % 60
- );
- }
- if (bitrate_indicator)
- {
- bmp_printf( FONT_SMALL,
- 680 - font_small.width * 5,
- 55,
- "A%3d ",
- movie_bytes_written_32k * 32 * 80 / 1024 / (movie_elapsed_time_01s));
- bmp_printf(FONT_SMALL,
- 680 - font_small.width * 5,
- 55 + font_small.height,
- "B%3d ",
- measured_bitrate*10
- );
- int fnts = FONT(FONT_SMALL, COLOR_WHITE, mvr_config.actual_qscale_maybe == -16 ? COLOR_RED : COLOR_BLACK);
- bmp_printf(fnts,
- 680,
- 55 + font_small.height,
- " Q%s%02d",
- mvr_config.actual_qscale_maybe < 0 ? "-" : "+",
- ABS(mvr_config.actual_qscale_maybe)
- );
- }
- //~ if (flicker_being_killed()) // this also kills recording dot
- //~ {
- //~ maru(os.x_max - 28, os.y0 + 12, COLOR_RED);
- //~ }
- }
- void measure_bitrate() // called once / second
- {
- static uint32_t prev_bytes_written = 0;
- uint32_t bytes_written = MVR_BYTES_WRITTEN;
- int bytes_delta = (((int)(bytes_written >> 1)) - ((int)(prev_bytes_written >> 1))) << 1;
- prev_bytes_written = bytes_written;
- movie_bytes_written_32k = bytes_written >> 15;
- measured_bitrate = (ABS(bytes_delta) / 1024) * 8 / 1024;
- }
- static void
- time_indicator_display( void * priv, int x, int y, int selected )
- {
- bmp_printf(
- selected ? MENU_FONT_SEL : MENU_FONT,
- x, y,
- "Time Indicator: %s",
- time_indicator == 1 ? "Elapsed" :
- time_indicator == 2 ? "Remain.Card" :
- time_indicator == 3 ? "Remain.4GB" : "OFF"
- );
- menu_draw_icon(x, y, MNI_BOOL_GDR(time_indicator));
- }
- /*static void
- bitrate_indicator_display( void * priv, int x, int y, int selected )
- {
- bmp_printf(
- selected ? MENU_FONT_SEL : MENU_FONT,
- x, y,
- "Bitrate Info : %s",
- bitrate_indicator ? "ON" : "OFF"
- );
- menu_draw_icon(x, y, MNI_BOOL_GDR(bitrate_indicator));
- }*/
- CONFIG_INT("buffer.warning.level", buffer_warning_level, 70);
- static void
- buffer_warning_level_display( void * priv, int x, int y, int selected )
- {
- bmp_printf(
- selected ? MENU_FONT_SEL : MENU_FONT,
- x, y,
- "BuffWarnLevel : %d%%",
- buffer_warning_level
- );
- menu_draw_icon(x, y, MNI_PERCENT, buffer_warning_level);
- }
- static void buffer_warning_level_toggle(void* priv, int step)
- {
- buffer_warning_level += step;
- if (buffer_warning_level > 100) buffer_warning_level = 30;
- if (buffer_warning_level < 30) buffer_warning_level = 100;
- }
- int warning = 0;
- int is_mvr_buffer_almost_full()
- {
- if (recording == 0) return 0;
- if (recording == 1) return 1;
- if (pdebug==1) { debugprints24p(); }
- //Lock Slice
- if ( (bitrate_mode == 1) && (qscale_slice !=0) )
- { int8_t* theqscale = (int8_t*) (0x6ce0);
- *theqscale=slice_array[qscale_slice];
- }
- if (MVR_BUFFER_USAGE > (int)buffer_warning_level) // Drop Slice if buffer
- { if ( (bitrate_mode == 1) && (qscale_slice >4) )
- qscale_slice -= 2;
- }
- if ( MVR_BUFFER_USAGE < ((int)buffer_warning_level-25) ) //Raise if BR getting low.
- { if ( (bitrate_mode == 1) && (qscale_slice < 45) && ((measured_bitrate*10)<75) && (measured_bitrate!=0) )
- qscale_slice++;
- }
- int ans = MVR_BUFFER_USAGE > (int)buffer_warning_level;
- if (ans) warning = 1;
- return warning;
- }
- void show_mvr_buffer_status()
- {
- int fnt = warning ? FONT(FONT_SMALL, COLOR_WHITE, COLOR_RED) : FONT(FONT_SMALL, COLOR_WHITE, COLOR_GREEN2);
- if (warning) warning--;
- if (recording && get_global_draw() && !gui_menu_shown()) bmp_printf(fnt, 680, 55, " %3d%%", MVR_BUFFER_USAGE);
- }
- static void load_h264_ini()
- {
- gui_stop_menu();
- call("IVAParamMode", CARD_DRIVE "ML/H264.ini");
- NotifyBox(2000, "%s", 0x4da10);
- }
- static void param_binary_toggle( void * priv, int delta )
- {
- unsigned * ptr = priv;
- *ptr = !*ptr;
- }
- static void
- param_display( void * priv, int x, int y, int selected )
- {
- unsigned fnt = selected ? MENU_FONT_SEL : MENU_FONT;
- bmp_printf(
- FONT(fnt, paverage ? COLOR_RED : FONT_FG(fnt), FONT_BG(fnt)),
- x, y,
- //23456789012
- "Averaging : %s",
- paverage ? "ON " : "OFF"
- );
- }
- pdebug_display( void * priv, int x, int y, int selected )
- {
- unsigned fnt = selected ? MENU_FONT_SEL : MENU_FONT;
- bmp_printf(
- FONT(fnt, pdebug ? COLOR_RED : FONT_FG(fnt), FONT_BG(fnt)),
- x, y,
- //23456789012
- "Debug : %s",
- pdebug ? "ON " : "OFF"
- );
- }
- static struct menu_entry mov_menus[] = {
- #ifdef CONFIG_5D3
- /* {
- .name = "Bit Rate ",
- .priv = &bitrate,
- .min = 1,
- .max = 20,
- .help = "H.264 bitrate. One unit = 10 mb/s."
- },*/
- {
- .name = "Load H264.ini ",
- //~ .priv = &bitrate,
- //~ .min = 1,
- //~ .max = 20,
- .select = load_h264_ini,
- .help = "Bitrate settings"
- },
- #else
- {
- .name = "Encoder Options",
- .select = menu_open_submenu,
- .help = "Extra Encoder Options",
- .children = (struct menu_entry[]) {
- #ifndef CONFIG_500D
- {
- .name = "P Factor",
- .priv = &pfact,
- .select = p_factor_toggle,
- .display = pfact_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "I Factor",
- .priv = &ifact,
- .select = i_factor_toggle,
- .display = ifact_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "D1 Factor",
- .priv = &d1fact,
- .select = d1_factor_toggle,
- .display = d1fact_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "D2 Factor",
- .priv = &d2fact,
- .select = d2_factor_toggle,
- .display = d2fact_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "Gop0 Factor",
- .priv = &gop0fact,
- .select = gop0_factor_toggle,
- .display = gfact0_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "Gop1 Factor",
- .priv = &gop1fact,
- .select = gop1_factor_toggle,
- .display = gfact1_display,
- .help = "1.0x = Canon default"
- },
- /* {
- .name = "Gop2 Factor",
- .priv = &gop2fact,
- .select = gop2_factor_toggle,
- .display = gfact2_display,
- .help = "1.0x = Canon default"
- },*/
- {
- .name = "Gop3 Factor",
- .priv = &gop3fact,
- .select = gop3_factor_toggle,
- .display = gfact3_display,
- .help = "1.0x = Canon default"
- },
- {
- .name = "Gop4 Factor",
- .priv = &gop4fact,
- .select = gop4_factor_toggle,
- .display = gfact4_display,
- .help = "1.0x = Canon default"
- },
- #ifndef CONFIG_50D
- {
- .name = "SliceLck",
- .priv = &qscale_slice,
- .select = qscale_slice_toggle,
- .display = qscale_slice_display,
- .help = "Lock slice in CBR for max quality. 0 = off (reboot required)"
- },
- #endif
- #endif
- MENU_EOL
- },
- },
- {
- .name = "Bit Rate",
- .priv = &bitrate_mode,
- .display = bitrate_print,
- .select = bitrate_toggle,
- .help = "Change H.264 bitrate. Be careful, recording may stop!",
- //.essential = 1,
- .edit_mode = EM_MANY_VALUES,
- .children = (struct menu_entry[]) {
- {
- .name = "Mode",
- .priv = &bitrate_mode,
- .max = 2,
- .select = bitrate_toggle_mode,
- .choices = (const char *[]) {"FW default", "CBR", "VBR (QScale)"},
- .help = "Firmware default / CBR (recommended) / VBR (very risky)"
- },
- /* {
- .name = "CBR factor",
- .priv = &bitrate_factor,
- .select = bitrate_factor_toggle,
- .display = cbr_display,
- .help = "1.0x = Canon default, 0.4x = 30minutes, 1.4x = fast card."
- },*/
- {
- .name = "QScale",
- .priv = &qscale_plus16,
- .select = bitrate_qscale_toggle,
- .display = qscale_display,
- .help = "Quality factor (-16 = best quality). Try not to use it!"
- },
- #ifndef CONFIG_50D
- {
- .name = "Deblocking A",
- .priv = &pdblock_A,
- .select = bitrate_dblockA_toggle,
- .display = dblockA_display,
- .help = "Deblocking Alpha"
- },
- {
- .name = "Deblocking B",
- .priv = &pdblock_B,
- .select = bitrate_dblockB_toggle,
- .display = dblockB_display,
- .help = "Deblocking Beta"
- },
- {
- .name = "PicQ PC",
- .priv = &p_picqpc,
- .select = picqpc_toggle,
- .display = picqpc_display,
- .help = "If set to 0, PicQPy is maximum supported."
- },
- #endif
- {
- .name = "Gop Length",
- .priv = &goplength,
- .select = goplength_toggle,
- .display = goplength_display,
- .help = "Gop Length"
- },
- /*
- {
- .name = "Qscale Max",
- .priv = &qscale_plusMax,
- .select = qscale_max_toggle,
- .display = qscale_max_display,
- .help = "Max Qscale"
- },
- */
- {
- .name = "Bitrate Info",
- .priv = &bitrate_indicator,
- .max = 1,
- .help = "A = average, B = instant bitrate, Q = instant QScale."
- },
- {
- .name = "BuffWarnLevel",
- .select = buffer_warning_level_toggle,
- .display = buffer_warning_level_display,
- .help = "ML will pause CPU-intensive graphics if buffer gets full."
- },
- {
- .name = "Debugging",
- .priv = &pdebug,
- .select = param_binary_toggle,
- .display = pdebug_display,
- .help = "See encoder values on screen 24p/30p",
- },
- {
- .name = "Averaging",
- .priv = &paverage,
- .select = param_binary_toggle,
- .display = param_display,
- .help = "Average Values for P/I",
- },
- MENU_EOL
- },
- },
- #endif
- #ifndef CONFIG_5D3
- {
- .name = "Time Indicator",
- .priv = &time_indicator,
- .select = menu_quaternary_toggle,
- .display = time_indicator_display,
- .help = "Time indicator during recording",
- //.essential = 1,
- //~ .edit_mode = EM_MANY_VALUES,
- },
- #endif
- };
- void bitrate_init()
- {
- menu_add( "Movie", mov_menus, COUNT(mov_menus) );
- }
- INIT_FUNC(__FILE__, bitrate_init);
- static void
- bitrate_task( void* unused )
- {
- cbr_init();
- TASK_LOOP
- {
- if (recording) msleep(100); // uses a bit of CPU, but it's precise
- else msleep(500); // relax
- // if (recording) wait_till_next_second(); // uses a bit of CPU, but it's precise
- // else msleep(1000); // relax
- if (recording)
- {
- // movie_elapsed_time_01s += 10;
- movie_elapsed_time_01s += 1;
- measure_bitrate();
- BMP_LOCK( show_mvr_buffer_status(); )
- }
- else
- {
- movie_elapsed_time_01s = 0;
- if (movie_elapsed_time_01s % 10 == 0)
- bitrate_set();
- }
- }
- }
- void movie_indicators_show()
- {
- if (recording)
- {
- BMP_LOCK( time_indicator_show(); )
- }
- else
- {
- BMP_LOCK(
- free_space_show();
- fps_show();
- )
- }
- }
- TASK_CREATE("bitrate_task", bitrate_task, 0, 0x1d, 0x1000 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement