Skip to content

Commit

Permalink
firmware/lm32/encoder: fix fps limitation and add encoder fps command
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Jan 24, 2016
1 parent e1729c0 commit bdde570
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions firmware/lm32/ci.c
Expand Up @@ -71,6 +71,7 @@ static void help_encoder(void)
puts("encoder on - enable encoder");
puts("encoder off - disable encoder");
puts("encoder quality <quality> - select quality");
puts("encoder fps <fps> - configure target fps");
}
#endif

Expand Down Expand Up @@ -375,6 +376,11 @@ static void encoder_configure_quality(int quality)
encoder_set_quality(quality);
}

static void encoder_configure_fps(int fps)
{
printf("Setting encoder fps to %d\r\n", fps);
encoder_set_fps(fps);
}

static void encoder_off(void)
{
Expand Down Expand Up @@ -593,6 +599,8 @@ void ci_service(void)
encoder_off();
else if(strcmp(token, "quality") == 0)
encoder_configure_quality(atoi(get_token(&str)));
else if(strcmp(token, "fps") == 0)
encoder_configure_fps(atoi(get_token(&str)));
else
help_encoder();
}
Expand Down
20 changes: 17 additions & 3 deletions firmware/lm32/encoder.c
Expand Up @@ -160,21 +160,35 @@ int encoder_set_quality(int quality) {
return 1;
}

int encoder_set_fps(int fps) {
if(encoder_target_fps > 0 && encoder_target_fps <= 60) {
encoder_target_fps = fps;
return 0;
}
else {
encoder_target_fps = 30;
return 1;
}
}

void encoder_service(void) {

static int last_event;
static int last_fps_event;
static int frame_cnt;
static int can_start;

if(encoder_enabled) {
if(elapsed(&last_event, identifier_frequency_read()/30)) {
if (encoder_done() == 1) {
if(elapsed(&last_event, identifier_frequency_read()/encoder_target_fps)) {
can_start = 1;
}
if(can_start & encoder_done()) {
encoder_init(encoder_quality);
encoder_start(processor_h_active, processor_v_active);
encoder_reader_dma_length_write(processor_h_active*processor_v_active*2);
encoder_reader_dma_shoot_write(1);
frame_cnt++;
}
}
}
if(elapsed(&last_fps_event, identifier_frequency_read())) {
encoder_fps = frame_cnt;
Expand Down
2 changes: 2 additions & 0 deletions firmware/lm32/encoder.h
Expand Up @@ -23,6 +23,7 @@ const char chroma_rom_75[64];
const char chroma_rom_50[64];

char encoder_enabled;
int encoder_target_fps;
int encoder_fps;
int encoder_quality;

Expand All @@ -33,6 +34,7 @@ void encoder_start(short resx, short resy);
int encoder_done(void);
void encoder_enable(char enable);
int encoder_set_quality(int quality);
int encoder_set_fps(int fps);
void encoder_service(void);

#endif
1 change: 1 addition & 0 deletions firmware/lm32/processor.c
Expand Up @@ -371,6 +371,7 @@ void processor_init(void)
processor_encoder_source = VIDEO_IN_HDMI_IN0;
#ifdef ENCODER_BASE
encoder_enable(0);
encoder_target_fps = 30;
#endif
}

Expand Down

0 comments on commit bdde570

Please sign in to comment.