[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 1267, Wed Dec 17 15:16:16 2003 UTC revision 1287, Sat Dec 20 15:38:13 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.10 2003-12-17 15:16:16 edgomez Exp $   * $Id: plugin_2pass1.c,v 1.1.2.13 2003-12-20 15:38:13 syskin 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"
35    
36    
37    #define FAST1PASS
38    
39    
40  /* context struct */  /* context struct */
41  typedef struct  typedef struct
42  {  {
# Line 63  Line 68 
68          if((rc->stat_file = fopen(param->filename, "w+b")) == NULL)          if((rc->stat_file = fopen(param->filename, "w+b")) == NULL)
69                  return(XVID_ERR_FAIL);                  return(XVID_ERR_FAIL);
70    
71            /* I swear xvidcore isn't buggy, but when using mencoder+xvid4 i observe
72             * this weird bug.
73             *
74             * Symptoms: The stats file grows until it's fclosed, but at this moment
75             *           a large part of the file is filled by 0x00 bytes w/o any
76             *           reasonable cause. The stats file is then completly unusable
77             *
78             * So far, i think i found "the why":
79             *  - take a MPEG stream containing 2 sequences (concatenate 2 MPEG files
80             *    together)
81             *  - Encode this MPEG file
82             *
83             * It should trigger the bug
84             *
85             * I think this is caused by some kind of race condition on mencoder module
86             * start/stop.
87             *  - mencoder encodes the first sequence
88             *    + xvid4 module opens xvid-twopass.stats and writes stats in it.
89             *  - mencoder detects the second sequence and initialize a second
90             *    module and stops the old encoder
91             *    + new xvid4 module opens a new xvid-twopass.stats, old xvid4
92             *      module closes it
93             *
94             * This is IT, got a racing condition.
95             * Unbuffered IO, may help ... */
96            setbuf(rc->stat_file, NULL);
97    
98          /*          /*
99           * The File Header           * The File Header
100           */           */
# Line 81  Line 113 
113    
114  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)
115  {  {
116          fclose(rc->stat_file);          if (rc->stat_file) {
117          free(rc);                  if (fclose(rc->stat_file) == EOF) {
118                            DPRINTF(XVID_DEBUG_RC, "Error closing stats file (%s)", strerror(errno));
119                    }
120            }
121            rc->stat_file = NULL; /* Just a paranoid reset */
122            free(rc); /* as the container structure is freed anyway */
123          return(0);          return(0);
124  }  }
125    
# Line 96  Line 133 
133                          rc->fq_error -= data->quant;                          rc->fq_error -= data->quant;
134                  } else {                  } else {
135                          data->quant = 2;                          data->quant = 2;
136    
137    #ifdef FAST1PASS
138    
139                            data->motion_flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP + XVID_ME_USESQUARES16
140                                                                            + XVID_ME_ADVANCEDDIAMOND16 + XVID_ME_EXTSEARCH16);
141    
142                            data->motion_flags |= XVID_ME_FAST_MODEINTERPOLATE + XVID_ME_SKIP_DELTASEARCH
143                                                                            + XVID_ME_FASTREFINE16 + XVID_ME_BFRAME_EARLYSTOP;
144    
145                            data->vop_flags &= ~(XVID_VOP_MODEDECISION_RD + XVID_VOP_FAST_MODEDECISION_RD
146                                                                    + XVID_VOP_TRELLISQUANT + XVID_VOP_INTER4V + XVID_VOP_HQACPRED);
147    
148                            data->vol_flags &= ~XVID_VOL_GMC;
149    #endif
150                  }                  }
151          }          }
152           return(0);           return(0);
# Line 105  Line 156 
156  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)
157  {  {
158          char type;          char type;
159            xvid_enc_stats_t *stats = &data->stats;
160    
161          /* Frame type in ascii I/P/B */          /* Frame type in ascii I/P/B */
162          switch(data->type) {          switch(stats->type) {
163          case XVID_TYPE_IVOP:          case XVID_TYPE_IVOP:
164                  type = 'i';                  type = 'i';
165                  break;                  break;
# Line 126  Line 178 
178    
179          /* write the resulting statistics */          /* write the resulting statistics */
180    
181          fprintf(rc->stat_file, "%c %d %d %d %d %d\n",          fprintf(rc->stat_file, "%c %d %d %d %d %d %d\n",
182          type,          type,
183                  data->quant,                          stats->quant,
184                  data->kblks,                          stats->kblks,
185          data->mblks,                          stats->mblks,
186          data->ublks,                          stats->ublks,
187          data->length);                          stats->length,
188                            stats->hlength);
189    
190          return(0);          return(0);
191  }  }

Legend:
Removed from v.1267  
changed lines
  Added in v.1287

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