Mercurial > mplayer.hg
comparison libvo/vo_jpeg.c @ 13316:0d17bef9894d
* Changed malloc and strncpy to strdup. Less code.
* More error checking. If malloc or strdup fails, print message and exit.
* Free malloc'd memory when uninit is called.
* Moved default of jpeg_outdir to preinit, so it is always malloc'd and can
easily be freed at uninit.
author | ivo |
---|---|
date | Sat, 11 Sep 2004 19:59:31 +0000 |
parents | 47dd02fb02df |
children | 42d52a9f72a4 |
comparison
equal
deleted
inserted
replaced
13315:ff9c9b130ace | 13316:0d17bef9894d |
---|---|
70 int jpeg_baseline = 1; | 70 int jpeg_baseline = 1; |
71 int jpeg_progressive_mode = 0; | 71 int jpeg_progressive_mode = 0; |
72 int jpeg_optimize = 100; | 72 int jpeg_optimize = 100; |
73 int jpeg_smooth = 0; | 73 int jpeg_smooth = 0; |
74 int jpeg_quality = 75; | 74 int jpeg_quality = 75; |
75 char *jpeg_outdir = "."; | 75 char *jpeg_outdir = NULL; |
76 char *jpeg_subdirs = NULL; | 76 char *jpeg_subdirs = NULL; |
77 int jpeg_maxfiles = 1000; | 77 int jpeg_maxfiles = 1000; |
78 | 78 |
79 static int framenum = 0; | 79 static int framenum = 0; |
80 | 80 |
278 | 278 |
279 /* ------------------------------------------------------------------------- */ | 279 /* ------------------------------------------------------------------------- */ |
280 | 280 |
281 static void uninit(void) | 281 static void uninit(void) |
282 { | 282 { |
283 if (jpeg_subdirs) { | |
284 free(jpeg_subdirs); | |
285 jpeg_subdirs = NULL; | |
286 } | |
287 if (jpeg_outdir) { | |
288 free(jpeg_outdir); | |
289 jpeg_outdir = NULL; | |
290 } | |
283 } | 291 } |
284 | 292 |
285 /* ------------------------------------------------------------------------- */ | 293 /* ------------------------------------------------------------------------- */ |
286 | 294 |
287 static void check_events(void) | 295 static void check_events(void) |
288 { | 296 { |
289 } | 297 } |
290 | 298 |
291 /* ------------------------------------------------------------------------- */ | 299 /* ------------------------------------------------------------------------- */ |
292 | 300 |
301 /** \brief Memory allocation failed. | |
302 * | |
303 * This function can be called if memory allocations failed. It prints a | |
304 * message and exits the player. | |
305 * | |
306 * \return none It never returns. | |
307 */ | |
308 | |
309 void jpeg_malloc_failed(void) { | |
310 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
311 MSGTR_MemAllocFailed); | |
312 exit_player(MSGTR_Exit_error); | |
313 } | |
314 | |
315 /* ------------------------------------------------------------------------- */ | |
316 | |
293 static uint32_t preinit(const char *arg) | 317 static uint32_t preinit(const char *arg) |
294 { | 318 { |
295 char *buf; /* buf is used to store parsed string values */ | 319 char *buf; /* buf is used to store parsed string values */ |
296 int length; /* length is used when calculating the length of buf */ | |
297 int value; /* storage for parsed integer values */ | 320 int value; /* storage for parsed integer values */ |
298 | 321 |
299 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | 322 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, |
300 MSGTR_VO_ParsingSuboptions); | 323 MSGTR_VO_ParsingSuboptions); |
301 | 324 |
401 arg++; /* log10(0) fails */ | 424 arg++; /* log10(0) fails */ |
402 } | 425 } |
403 } else if (!strncmp(arg, "outdir=", 7)) { | 426 } else if (!strncmp(arg, "outdir=", 7)) { |
404 arg += 7; | 427 arg += 7; |
405 buf = malloc(strlen(arg)+1); /* maximum length possible */ | 428 buf = malloc(strlen(arg)+1); /* maximum length possible */ |
406 if (!buf) { | 429 if (!buf) jpeg_malloc_failed(); /* print msg and exit */ |
407 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
408 MSGTR_MemAllocFailed); | |
409 exit_player(MSGTR_Exit_error); | |
410 } | |
411 if (sscanf(arg, "%[^:]", buf) == 1) { | 430 if (sscanf(arg, "%[^:]", buf) == 1) { |
412 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", | 431 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", |
413 info.short_name, "outdir", buf); | 432 info.short_name, "outdir", buf); |
414 length = strlen(buf); | 433 arg += strlen(buf); |
415 arg += length; | 434 jpeg_outdir = strdup(buf); |
416 jpeg_outdir = malloc(length+1); | 435 if (!jpeg_outdir) jpeg_malloc_failed(); |
417 strncpy(jpeg_outdir, buf, length+1); | |
418 free(buf); | 436 free(buf); |
419 } else { | 437 } else { |
420 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | 438 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", |
421 info.short_name, "outdir", | 439 info.short_name, "outdir", |
422 MSGTR_VO_NoValueSpecified); | 440 MSGTR_VO_NoValueSpecified); |
423 exit_player(MSGTR_Exit_error); | 441 exit_player(MSGTR_Exit_error); |
424 } | 442 } |
425 } else if (!strncmp(arg, "subdirs=", 8)) { | 443 } else if (!strncmp(arg, "subdirs=", 8)) { |
426 arg += 8; | 444 arg += 8; |
427 buf = malloc(strlen(arg)+1); /* maximum length possible */ | 445 buf = malloc(strlen(arg)+1); /* maximum length possible */ |
428 if (!buf) { | 446 if (!buf) jpeg_malloc_failed(); |
429 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
430 MSGTR_MemAllocFailed); | |
431 exit_player(MSGTR_Exit_error); | |
432 } | |
433 if (sscanf(arg, "%[^:]", buf) == 1) { | 447 if (sscanf(arg, "%[^:]", buf) == 1) { |
434 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", | 448 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", |
435 info.short_name, "subdirs", buf); | 449 info.short_name, "subdirs", buf); |
436 length = strlen(buf); | 450 arg += strlen(buf); |
437 arg += length; | 451 jpeg_subdirs = strdup(buf); |
438 jpeg_subdirs = malloc(length+1); | 452 if (!jpeg_subdirs) jpeg_malloc_failed(); |
439 strncpy(jpeg_subdirs, buf, length+1); | |
440 free(buf); | 453 free(buf); |
441 } else { | 454 } else { |
442 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | 455 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", |
443 info.short_name, "subdirs", | 456 info.short_name, "subdirs", |
444 MSGTR_VO_NoValueSpecified); | 457 MSGTR_VO_NoValueSpecified); |
475 exit_player(MSGTR_Exit_error); | 488 exit_player(MSGTR_Exit_error); |
476 } | 489 } |
477 } /* end while */ | 490 } /* end while */ |
478 } /* endif */ | 491 } /* endif */ |
479 | 492 |
493 /* If jpeg_outdir is not set by an option, resort to default of "." */ | |
494 if (!jpeg_outdir) { | |
495 jpeg_outdir = strdup("."); | |
496 } | |
497 | |
480 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | 498 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, |
481 MSGTR_VO_SuboptionsParsedOK); | 499 MSGTR_VO_SuboptionsParsedOK); |
482 return 0; | 500 return 0; |
483 } | 501 } |
484 | 502 |