[svn] / branches / dev-api-4 / xvidcore / src / plugins / plugin_2pass1.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/plugins/plugin_2pass1.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1216, Wed Nov 19 15:42:38 2003 UTC revision 1286, Sat Dec 20 15:30:03 2003 UTC
# Line 22  Line 22 
22   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
23   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24   *   *
25   * $Id: plugin_2pass1.c,v 1.1.2.9 2003-11-19 15:42:38 syskin Exp $   * $Id: plugin_2pass1.c,v 1.1.2.12 2003-12-20 15:30:03 edgomez Exp $
26   *   *
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"
# Line 63  Line 65 
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           */           */
# Line 81  Line 110 
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    
# Line 94  Line 128 
128              rc->fq_error += (double)data->zone->increment / (double)data->zone->base;              rc->fq_error += (double)data->zone->increment / (double)data->zone->base;
129              data->quant = (int)rc->fq_error;              data->quant = (int)rc->fq_error;
130              rc->fq_error -= data->quant;              rc->fq_error -= data->quant;
   
131          }else {          }else {
132              data->quant = 2;              data->quant = 2;
133          }          }
134      }      }
135      return 0;           return(0);
136  }  }
137    
138    
139  static int rc_2pass1_after(rc_2pass1_t * rc, xvid_plg_data_t * data)  static int rc_2pass1_after(rc_2pass1_t * rc, xvid_plg_data_t * data)
140  {  {
141          char type;          char type;
142            xvid_enc_stats_t *stats = &data->stats;
143    
144          /* Frame type in ascii I/P/B */          /* Frame type in ascii I/P/B */
145          switch(data->type) {          switch(stats->type) {
146          case XVID_TYPE_IVOP:          case XVID_TYPE_IVOP:
147                  type = 'i';                  type = 'i';
148                  break;                  break;
# Line 127  Line 161 
161    
162          /* write the resulting statistics */          /* write the resulting statistics */
163    
164          fprintf(rc->stat_file, "%c %d %d %d %d %d\n",          fprintf(rc->stat_file, "%c %d %d %d %d %d %d\n",
165          type,          type,
166                  data->quant,                          stats->quant,
167                  data->kblks,                          stats->kblks,
168          data->mblks,                          stats->mblks,
169          data->ublks,                          stats->ublks,
170          data->length);                          stats->length,
171                            stats->hlength);
172    
173          return(0);          return(0);
174  }  }

Legend:
Removed from v.1216  
changed lines
  Added in v.1286

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4