27 |
*****************************************************************************/ |
*****************************************************************************/ |
28 |
|
|
29 |
#include <stdio.h> |
#include <stdio.h> |
30 |
|
#include <errno.h> /* errno var (or function with recent libc) */ |
31 |
|
#include <string.h> /* strerror() */ |
32 |
|
|
33 |
#include "../xvid.h" |
#include "../xvid.h" |
34 |
#include "../image/image.h" |
#include "../image/image.h" |
65 |
if((rc->stat_file = fopen(param->filename, "w+b")) == NULL) |
if((rc->stat_file = fopen(param->filename, "w+b")) == NULL) |
66 |
return(XVID_ERR_FAIL); |
return(XVID_ERR_FAIL); |
67 |
|
|
68 |
|
/* I swear xvidcore isn't buggy, but when using mencoder+xvid4 i observe |
69 |
|
* this weird bug. |
70 |
|
* |
71 |
|
* Symptoms: The stats file grows until it's fclosed, but at this moment |
72 |
|
* a large part of the file is filled by 0x00 bytes w/o any |
73 |
|
* reasonable cause. The stats file is then completly unusable |
74 |
|
* |
75 |
|
* So far, i think i found "the why": |
76 |
|
* - take a MPEG stream containing 2 sequences (concatenate 2 MPEG files |
77 |
|
* together) |
78 |
|
* - Encode this MPEG file |
79 |
|
* |
80 |
|
* It should trigger the bug |
81 |
|
* |
82 |
|
* I think this is caused by some kind of race condition on mencoder module |
83 |
|
* start/stop. |
84 |
|
* - mencoder encodes the first sequence |
85 |
|
* + xvid4 module opens xvid-twopass.stats and writes stats in it. |
86 |
|
* - mencoder detects the second sequence and initialize a second |
87 |
|
* module and stops the old encoder |
88 |
|
* + new xvid4 module opens a new xvid-twopass.stats, old xvid4 |
89 |
|
* module closes it |
90 |
|
* |
91 |
|
* This is IT, got a racing condition. |
92 |
|
* Unbuffered IO, may help ... */ |
93 |
|
setbuf(rc->stat_file, NULL); |
94 |
|
|
95 |
/* |
/* |
96 |
* The File Header |
* The File Header |
97 |
*/ |
*/ |
110 |
|
|
111 |
static int rc_2pass1_destroy(rc_2pass1_t * rc, xvid_plg_destroy_t * destroy) |
static int rc_2pass1_destroy(rc_2pass1_t * rc, xvid_plg_destroy_t * destroy) |
112 |
{ |
{ |
113 |
fclose(rc->stat_file); |
if (rc->stat_file) { |
114 |
free(rc); |
if (fclose(rc->stat_file) == EOF) { |
115 |
|
DPRINTF(XVID_DEBUG_RC, "Error closing stats file (%s)", strerror(errno)); |
116 |
|
} |
117 |
|
} |
118 |
|
rc->stat_file = NULL; /* Just a paranoid reset */ |
119 |
|
free(rc); /* as the container structure is freed anyway */ |
120 |
return(0); |
return(0); |
121 |
} |
} |
122 |
|
|