[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 1054, Mon Jun 9 13:55:56 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.5 2003-06-09 13:55:07 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 48  Line 53 
53          rc_2pass1_t * rc;          rc_2pass1_t * rc;
54    
55      /* check filename */      /* check filename */
56      if (param->filename == NULL || param->filename[0] == '\0')      if ((param->filename == NULL) ||
57                    (param->filename != NULL && param->filename[0] == '\0'))
58          return XVID_ERR_FAIL;          return XVID_ERR_FAIL;
59    
60      /* allocate context struct */      /* allocate context struct */
# Line 59  Line 65 
65      rc->stat_file = NULL;      rc->stat_file = NULL;
66    
67          /* Open the 1st pass file */          /* Open the 1st pass file */
68          if((rc->stat_file = fopen(param->filename, "w+")) == 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           */           */
101  #if 0          fprintf(rc->stat_file, "# XviD 2pass stat file (core version %d.%d.%d)\n",
102          fprintf(rc->stat_file, "# XviD 2pass stat file\n");                          XVID_VERSION_MAJOR(XVID_VERSION),
103      fprintf(rc->stat_file, "version %i.%i.%i\n",XVID_MAJOR(XVID_VERSION), XVID_MINOR(XVID_VERSION), XVID_PATCH(XVID_VERSION));                          XVID_VERSION_MINOR(XVID_VERSION),
104          fprintf(rc->stat_file, "start\n");                          XVID_VERSION_PATCH(XVID_VERSION));
105      fprintf(rc->stat_file, "type quantizer length kblocks mblocks ublocks\n");          fprintf(rc->stat_file, "# Please do not modify this file\n\n");
 #endif  
106    
107      rc->fq_error = 0;      rc->fq_error = 0;
108    
# 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                    if (fclose(rc->stat_file) == EOF) {
118          free(rc);                          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 95  Line 131 
131              rc->fq_error += (double)data->zone->increment / (double)data->zone->base;              rc->fq_error += (double)data->zone->increment / (double)data->zone->base;
132              data->quant = (int)rc->fq_error;              data->quant = (int)rc->fq_error;
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);
153  }  }
154    
155    
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 128  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  }  }
# Line 146  Line 197 
197      switch(opt)      switch(opt)
198      {      {
199      case XVID_PLG_INFO :      case XVID_PLG_INFO :
200            case XVID_PLG_FRAME :
201          return 0;          return 0;
202    
203      case XVID_PLG_CREATE :      case XVID_PLG_CREATE :

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

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