@@ -79,14 +79,7 @@ static opus_uint32 char_to_int(unsigned char ch[4])
79
79
| ((opus_uint32 )ch [2 ]<< 8 ) | (opus_uint32 )ch [3 ];
80
80
}
81
81
82
- static void check_encoder_option (int decode_only , const char * opt )
83
- {
84
- if (decode_only )
85
- {
86
- fprintf (stderr , "option %s is only for encoding\n" , opt );
87
- exit (EXIT_FAILURE );
88
- }
89
- }
82
+ #define check_encoder_option (decode_only , opt ) do {if (decode_only) {fprintf(stderr, "option %s is only for encoding\n", opt); goto failure;}} while(0)
90
83
91
84
static const int silk8_test [][4 ] = {
92
85
{MODE_SILK_ONLY , OPUS_BANDWIDTH_NARROWBAND , 960 * 3 , 1 },
@@ -218,15 +211,16 @@ int main(int argc, char *argv[])
218
211
{
219
212
int err ;
220
213
char * inFile , * outFile ;
221
- FILE * fin , * fout ;
214
+ FILE * fin = NULL ;
215
+ FILE * fout = NULL ;
222
216
OpusEncoder * enc = NULL ;
223
217
OpusDecoder * dec = NULL ;
224
218
int args ;
225
219
int len [2 ];
226
220
int frame_size , channels ;
227
221
opus_int32 bitrate_bps = 0 ;
228
- unsigned char * data [2 ];
229
- unsigned char * fbytes ;
222
+ unsigned char * data [2 ] = { NULL , NULL } ;
223
+ unsigned char * fbytes = NULL ;
230
224
opus_int32 sampling_rate ;
231
225
int use_vbr ;
232
226
int max_payload_bytes ;
@@ -240,7 +234,8 @@ int main(int argc, char *argv[])
240
234
int k ;
241
235
opus_int32 skip = 0 ;
242
236
int stop = 0 ;
243
- short * in , * out ;
237
+ short * in = NULL ;
238
+ short * out = NULL ;
244
239
int application = OPUS_APPLICATION_AUDIO ;
245
240
double bits = 0.0 , bits_max = 0.0 , bits_act = 0.0 , bits2 = 0.0 , nrg ;
246
241
double tot_samples = 0 ;
@@ -268,11 +263,12 @@ int main(int argc, char *argv[])
268
263
int remaining = 0 ;
269
264
int variable_duration = OPUS_FRAMESIZE_ARG ;
270
265
int delayed_decision = 0 ;
266
+ int ret = EXIT_FAILURE ;
271
267
272
268
if (argc < 5 )
273
269
{
274
270
print_usage ( argv );
275
- return EXIT_FAILURE ;
271
+ goto failure ;
276
272
}
277
273
278
274
tot_in = tot_out = 0 ;
@@ -291,7 +287,7 @@ int main(int argc, char *argv[])
291
287
if (!decode_only && argc < 7 )
292
288
{
293
289
print_usage ( argv );
294
- return EXIT_FAILURE ;
290
+ goto failure ;
295
291
}
296
292
297
293
if (!decode_only )
@@ -303,7 +299,7 @@ int main(int argc, char *argv[])
303
299
else if (strcmp (argv [args ], "audio" )!= 0 ) {
304
300
fprintf (stderr , "unknown application: %s\n" , argv [args ]);
305
301
print_usage (argv );
306
- return EXIT_FAILURE ;
302
+ goto failure ;
307
303
}
308
304
args ++ ;
309
305
}
@@ -316,7 +312,7 @@ int main(int argc, char *argv[])
316
312
{
317
313
fprintf (stderr , "Supported sampling rates are 8000, 12000, "
318
314
"16000, 24000 and 48000.\n" );
319
- return EXIT_FAILURE ;
315
+ goto failure ;
320
316
}
321
317
frame_size = sampling_rate /50 ;
322
318
@@ -326,7 +322,7 @@ int main(int argc, char *argv[])
326
322
if (channels < 1 || channels > 2 )
327
323
{
328
324
fprintf (stderr , "Opus_demo supports only 1 or 2 channels.\n" );
329
- return EXIT_FAILURE ;
325
+ goto failure ;
330
326
}
331
327
332
328
if (!decode_only )
@@ -366,7 +362,7 @@ int main(int argc, char *argv[])
366
362
fprintf (stderr , "Unknown bandwidth %s. "
367
363
"Supported are NB, MB, WB, SWB, FB.\n" ,
368
364
argv [ args + 1 ]);
369
- return EXIT_FAILURE ;
365
+ goto failure ;
370
366
}
371
367
args += 2 ;
372
368
} else if ( strcmp ( argv [ args ], "-framesize" ) == 0 ) {
@@ -393,7 +389,7 @@ int main(int argc, char *argv[])
393
389
fprintf (stderr , "Unsupported frame size: %s ms. "
394
390
"Supported are 2.5, 5, 10, 20, 40, 60, 80, 100, 120.\n" ,
395
391
argv [ args + 1 ]);
396
- return EXIT_FAILURE ;
392
+ goto failure ;
397
393
}
398
394
args += 2 ;
399
395
} else if ( strcmp ( argv [ args ], "-max_payload" ) == 0 ) {
@@ -480,7 +476,7 @@ int main(int argc, char *argv[])
480
476
} else {
481
477
printf ( "Error: unrecognized setting: %s\n\n" , argv [ args ] );
482
478
print_usage ( argv );
483
- return EXIT_FAILURE ;
479
+ goto failure ;
484
480
}
485
481
}
486
482
@@ -491,15 +487,15 @@ int main(int argc, char *argv[])
491
487
{
492
488
fprintf (stderr , "max_payload_bytes must be between 0 and %d\n" ,
493
489
MAX_PACKET );
494
- return EXIT_FAILURE ;
490
+ goto failure ;
495
491
}
496
492
497
493
inFile = argv [argc - 2 ];
498
494
fin = fopen (inFile , "rb" );
499
495
if (!fin )
500
496
{
501
497
fprintf (stderr , "Could not open input file %s\n" , argv [argc - 2 ]);
502
- return EXIT_FAILURE ;
498
+ goto failure ;
503
499
}
504
500
if (mode_list )
505
501
{
@@ -517,8 +513,7 @@ int main(int argc, char *argv[])
517
513
if (!fout )
518
514
{
519
515
fprintf (stderr , "Could not open output file %s\n" , argv [argc - 1 ]);
520
- fclose (fin );
521
- return EXIT_FAILURE ;
516
+ goto failure ;
522
517
}
523
518
524
519
if (!decode_only )
@@ -527,9 +522,7 @@ int main(int argc, char *argv[])
527
522
if (err != OPUS_OK )
528
523
{
529
524
fprintf (stderr , "Cannot create encoder: %s\n" , opus_strerror (err ));
530
- fclose (fin );
531
- fclose (fout );
532
- return EXIT_FAILURE ;
525
+ goto failure ;
533
526
}
534
527
opus_encoder_ctl (enc , OPUS_SET_BITRATE (bitrate_bps ));
535
528
opus_encoder_ctl (enc , OPUS_SET_BANDWIDTH (bandwidth ));
@@ -551,9 +544,7 @@ int main(int argc, char *argv[])
551
544
if (err != OPUS_OK )
552
545
{
553
546
fprintf (stderr , "Cannot create decoder: %s\n" , opus_strerror (err ));
554
- fclose (fin );
555
- fclose (fout );
556
- return EXIT_FAILURE ;
547
+ goto failure ;
557
548
}
558
549
}
559
550
@@ -729,9 +720,7 @@ int main(int argc, char *argv[])
729
720
if (len [toggle ] < 0 )
730
721
{
731
722
fprintf (stderr , "opus_encode() returned %d\n" , len [toggle ]);
732
- fclose (fin );
733
- fclose (fout );
734
- return EXIT_FAILURE ;
723
+ goto failure ;
735
724
}
736
725
curr_mode_count += frame_size ;
737
726
if (curr_mode_count > mode_switch_time && curr_mode < nb_modes_in_list - 1 )
@@ -748,7 +737,7 @@ int main(int argc, char *argv[])
748
737
if ((err = opus_packet_pad (data [toggle ], len [toggle ], new_len )) != OPUS_OK )
749
738
{
750
739
fprintf (stderr , "padding failed: %s\n" , opus_strerror (err ));
751
- return EXIT_FAILURE ;
740
+ goto failure ;
752
741
}
753
742
len [toggle ] = new_len ;
754
743
}
@@ -759,16 +748,16 @@ int main(int argc, char *argv[])
759
748
int_to_char (len [toggle ], int_field );
760
749
if (fwrite (int_field , 1 , 4 , fout ) != 4 ) {
761
750
fprintf (stderr , "Error writing.\n" );
762
- return EXIT_FAILURE ;
751
+ goto failure ;
763
752
}
764
753
int_to_char (enc_final_range [toggle ], int_field );
765
754
if (fwrite (int_field , 1 , 4 , fout ) != 4 ) {
766
755
fprintf (stderr , "Error writing.\n" );
767
- return EXIT_FAILURE ;
756
+ goto failure ;
768
757
}
769
758
if (fwrite (data [toggle ], 1 , len [toggle ], fout ) != (unsigned )len [toggle ]) {
770
759
fprintf (stderr , "Error writing.\n" );
771
- return EXIT_FAILURE ;
760
+ goto failure ;
772
761
}
773
762
tot_samples += nb_encoded ;
774
763
} else {
@@ -811,7 +800,7 @@ int main(int argc, char *argv[])
811
800
}
812
801
if (fwrite (fbytes , sizeof (short )* channels , output_samples - skip , fout ) != (unsigned )(output_samples - skip )){
813
802
fprintf (stderr , "Error writing.\n" );
814
- return EXIT_FAILURE ;
803
+ goto failure ;
815
804
}
816
805
tot_out += output_samples - skip ;
817
806
}
@@ -837,9 +826,7 @@ int main(int argc, char *argv[])
837
826
(long )count ,
838
827
(unsigned long )enc_final_range [toggle ^use_inbandfec ],
839
828
(unsigned long )dec_final_range );
840
- fclose (fin );
841
- fclose (fout );
842
- return EXIT_FAILURE ;
829
+ goto failure ;
843
830
}
844
831
845
832
lost_prev = lost ;
@@ -888,15 +875,18 @@ int main(int argc, char *argv[])
888
875
fprintf (stderr , "bitrate statistics are undefined\n" );
889
876
}
890
877
silk_TimerSave ("opus_timing.txt" );
878
+ ret = EXIT_SUCCESS ;
879
+ failure :
891
880
opus_encoder_destroy (enc );
892
881
opus_decoder_destroy (dec );
893
882
free (data [0 ]);
894
- if (use_inbandfec )
895
- free (data [1 ]);
896
- fclose (fin );
897
- fclose (fout );
883
+ free (data [1 ]);
884
+ if (fin )
885
+ fclose (fin );
886
+ if (fout )
887
+ fclose (fout );
898
888
free (in );
899
889
free (out );
900
890
free (fbytes );
901
- return EXIT_SUCCESS ;
891
+ return ret ;
902
892
}
0 commit comments