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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1014 - (view) (download)

1 : suxen_drol 938 /******************************************************************************
2 :     *
3 :     * XviD Bit Rate Controller Library
4 :     * - VBR 2 pass bitrate controler implementation -
5 :     *
6 :     * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
7 :     *
8 :     * The curve treatment algorithm is the one implemented by Foxer <email?> and
9 :     * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
10 :     *
11 :     * This program is free software; you can redistribute it and/or modify
12 :     * it under the terms of the GNU General Public License as published by
13 :     * the Free Software Foundation; either version 2 of the License, or
14 :     * (at your option) any later version.
15 :     *
16 :     * This program is distributed in the hope that it will be useful,
17 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 :     * GNU General Public License for more details.
20 :     *
21 :     * You should have received a copy of the GNU General Public License
22 :     * along with this program; if not, write to the Free Software
23 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 :     *
25 : suxen_drol 1014 * $Id: plugin_2pass1.c,v 1.1.2.3 2003-05-12 12:33:16 suxen_drol Exp $
26 : suxen_drol 938 *
27 :     *****************************************************************************/
28 :    
29 :     #include <stdio.h>
30 :    
31 :     #include "../xvid.h"
32 :     #include "../image/image.h"
33 :    
34 :    
35 :     /* context struct */
36 :     typedef struct
37 :     {
38 :     FILE * stat_file;
39 : suxen_drol 1014
40 :     double fq_error;
41 : suxen_drol 938 } rc_2pass1_t;
42 :    
43 :    
44 :    
45 :     static int rc_2pass1_create(xvid_plg_create_t * create, rc_2pass1_t ** handle)
46 :     {
47 :     xvid_plugin_2pass1_t * param = (xvid_plugin_2pass1_t *)create->param;
48 :     rc_2pass1_t * rc;
49 :    
50 :     /* check filename */
51 :     if (param->filename == NULL || param->filename[0] == '\0')
52 :     return XVID_ERR_FAIL;
53 :    
54 :     /* allocate context struct */
55 :     if((rc = malloc(sizeof(rc_2pass1_t))) == NULL)
56 :     return(XVID_ERR_MEMORY);
57 :    
58 :     /* Initialize safe defaults for 2pass 1 */
59 :     rc->stat_file = NULL;
60 :    
61 :     /* Open the 1st pass file */
62 :     if((rc->stat_file = fopen(param->filename, "w+")) == NULL)
63 :     return(XVID_ERR_FAIL);
64 :    
65 : suxen_drol 1014 {
66 :     int i;
67 :     printf("---\n");
68 :     for (i=0;i<create->num_zones;i++) {
69 :     printf("[%i] %i\n", create->zones[i].frame, create->zones[i].increment);
70 :     }
71 :     printf("---\n");
72 :     }
73 :    
74 : suxen_drol 938 /*
75 :     * The File Header
76 :     */
77 :     /* fprintf(rc->stat_file, "# XviD 2pass stat file\n");
78 :     fprintf(rc->stat_file, "version %i.%i.%i\n",XVID_MAJOR(XVID_VERSION), XVID_MINOR(XVID_VERSION), XVID_PATCH(XVID_VERSION));
79 :     fprintf(rc->stat_file, "start\n");
80 :     fprintf(rc->stat_file, "type quantizer length kblocks mblocks ublocks\n"); */
81 : suxen_drol 1014
82 :     rc->fq_error = 0;
83 : suxen_drol 938
84 :     *handle = rc;
85 :     return(0);
86 :     }
87 :    
88 :    
89 :     static int rc_2pass1_destroy(rc_2pass1_t * rc, xvid_plg_destroy_t * destroy)
90 :     {
91 :     fclose(rc->stat_file);
92 :    
93 :     free(rc);
94 :     return(0);
95 :     }
96 :    
97 :    
98 :     static int rc_2pass1_before(rc_2pass1_t * rc, xvid_plg_data_t * data)
99 :     {
100 : suxen_drol 1014 if (data->quant <= 0) {
101 :     if (data->zone && data->zone->mode == XVID_ZONE_QUANT) {
102 :     rc->fq_error += (double)data->zone->increment / (double)data->zone->base;
103 :     data->quant = (int)rc->fq_error;
104 :     rc->fq_error -= data->quant;
105 :    
106 :     }else {
107 :     data->quant = 2;
108 :     }
109 :     }
110 : suxen_drol 938 return 0;
111 :     }
112 :    
113 :    
114 :     static int rc_2pass1_after(rc_2pass1_t * rc, xvid_plg_data_t * data)
115 :     {
116 :     char type;
117 :    
118 :     /* Frame type in ascii I/P/B */
119 :     switch(data->type) {
120 :     case XVID_TYPE_IVOP:
121 :     type = 'i';
122 :     break;
123 :     case XVID_TYPE_PVOP:
124 :     type = 'p';
125 :     break;
126 :     case XVID_TYPE_BVOP:
127 :     type = 'b';
128 :     break;
129 :     case XVID_TYPE_SVOP:
130 :     type = 's';
131 :     break;
132 :     default: /* Should not go here */
133 :     return(XVID_ERR_FAIL);
134 :     }
135 :    
136 :     /* write the resulting statistics */
137 :    
138 :     fprintf(rc->stat_file, "%c %d %d %d %d %d\n",
139 :     type,
140 :     data->quant,
141 :     data->kblks,
142 :     data->mblks,
143 : suxen_drol 977 data->ublks,
144 :     data->length);
145 : suxen_drol 938
146 :     return(0);
147 :     }
148 :    
149 :    
150 :    
151 :     int xvid_plugin_2pass1(void * handle, int opt, void * param1, void * param2)
152 :     {
153 :     switch(opt)
154 :     {
155 :     case XVID_PLG_INFO :
156 :     return 0;
157 :    
158 :     case XVID_PLG_CREATE :
159 :     return rc_2pass1_create((xvid_plg_create_t*)param1, param2);
160 :    
161 :     case XVID_PLG_DESTROY :
162 :     return rc_2pass1_destroy((rc_2pass1_t*)handle, (xvid_plg_destroy_t*)param1);
163 :    
164 :     case XVID_PLG_BEFORE :
165 :     return rc_2pass1_before((rc_2pass1_t*)handle, (xvid_plg_data_t*)param1);
166 :    
167 :     case XVID_PLG_AFTER :
168 :     return rc_2pass1_after((rc_2pass1_t*)handle, (xvid_plg_data_t*)param1);
169 :     }
170 :    
171 :     return XVID_ERR_FAIL;
172 :     }

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