Skip to content

Commit c1511f4

Browse files
authored
End of program fixed
The program close properly after the end of all files replace buffer length by FL2K_BUF_LEN
1 parent 482d744 commit c1511f4

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/fl2k_file.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ int read_sample_file(void *inpt_color)
455455
audio_frame = ((88200/30) * 2);
456456
}
457457

458-
unsigned long buf_size = (1310720 + (is16 * 1310720));
458+
unsigned long buf_size = (FL2K_BUF_LEN + (is16 * FL2K_BUF_LEN));
459459

460460
if(istbc == 1)//compute buf size
461461
{
@@ -464,7 +464,7 @@ int read_sample_file(void *inpt_color)
464464

465465
buf_size += sample_skip;
466466

467-
unsigned char *tmp_buf = malloc(1310720);
467+
unsigned char *tmp_buf = malloc(FL2K_BUF_LEN);
468468
unsigned char *audio_buf = malloc(audio_frame);
469469
char *audio_buf_signed = (void *)audio_buf;
470470
unsigned char *calc = malloc(buf_size);
@@ -540,7 +540,7 @@ int read_sample_file(void *inpt_color)
540540
//write audio file to stdout only if its not a terminal
541541
if(isatty(STDOUT_FILENO) == 0 && is_sync_a)
542542
{
543-
//write(stdout, tmp_buf, 1310720);
543+
//write(stdout, tmp_buf, FL2K_BUF_LEN);
544544
fread(audio_buf_signed,audio_frame,1,streamA);
545545
//write(stdout, audio_buf_signed, audio_frame);
546546
fwrite(audio_buf, audio_frame,1,stdout);
@@ -716,10 +716,10 @@ int read_sample_file(void *inpt_color)
716716
*line_sample_cnt += (1 + is16);
717717
}
718718

719-
memcpy(buffer, tmp_buf, 1310720);
719+
memcpy(buffer, tmp_buf, FL2K_BUF_LEN);
720720
if(isatty(STDOUT_FILENO) == 0 && use_pipe)
721721
{
722-
fwrite(tmp_buf, 1310720,1,stdout);
722+
fwrite(tmp_buf, FL2K_BUF_LEN,1,stdout);
723723
fflush(stdout);
724724
}
725725

@@ -761,7 +761,7 @@ void fl2k_callback(fl2k_data_info_t *data_info)
761761
//set sign (signed = 1 , unsigned = 0)
762762
data_info->sampletype_signed = sample_type;
763763

764-
//send the bufer with a size of 1310720
764+
//send the bufer with a size of (1280 * 1024) = 1310720
765765
if(red == 1)
766766
{
767767
data_info->r_buf = txbuf_r;
@@ -886,6 +886,14 @@ void fl2k_callback(fl2k_data_info_t *data_info)
886886
}
887887
}
888888

889+
if((red == 0 || feof(file_r)) && (green == 0 || feof(file_g)) && (blue == 0 || feof(file_b)))
890+
{
891+
fprintf(stderr, "End of the process\n");
892+
fl2k_stop_tx(dev);
893+
do_exit = 1;
894+
return 0;
895+
}
896+
889897
/*if(!(green == 1 && feof(file_g)) || !(green == 1 && feof(file_g)) && !(green == 1 && feof(file_g)))
890898
{
891899
@@ -940,7 +948,7 @@ int main(int argc, char **argv)
940948
char *filename2_b = NULL;
941949
char *filename_audio = NULL;
942950

943-
//pipe_buf = malloc(1310720);
951+
//pipe_buf = malloc(FL2K_BUF_LEN);
944952

945953
/*if (pipe_buf == NULL)
946954
{
@@ -949,7 +957,7 @@ int main(int argc, char **argv)
949957
return -1;
950958
}*/
951959

952-
//setvbuf(stdout,pipe_buf,_IOLBF,1310720);
960+
//setvbuf(stdout,pipe_buf,_IOLBF,FL2K_BUF_LEN);
953961

954962
int option_index = 0;
955963
static struct option long_options[] = {

0 commit comments

Comments
 (0)