Mercurial > mplayer.hg
comparison libmpcodecs/dec_video.c @ 31171:fe3b2b2a085f
cosmetics: K&R coding style
author | diego |
---|---|
date | Thu, 27 May 2010 09:54:37 +0000 |
parents | 3774cf3c7df3 |
children | cc6ee3017097 |
comparison
equal
deleted
inserted
replaced
31170:c720f2bd4765 | 31171:fe3b2b2a085f |
---|---|
51 extern double video_time_usage; | 51 extern double video_time_usage; |
52 extern double vout_time_usage; | 52 extern double vout_time_usage; |
53 | 53 |
54 #include "cpudetect.h" | 54 #include "cpudetect.h" |
55 | 55 |
56 int field_dominance=-1; | 56 int field_dominance = -1; |
57 | 57 |
58 int divx_quality=0; | 58 int divx_quality = 0; |
59 | 59 |
60 const vd_functions_t* mpvdec=NULL; | 60 const vd_functions_t *mpvdec = NULL; |
61 | 61 |
62 int get_video_quality_max(sh_video_t *sh_video){ | 62 int get_video_quality_max(sh_video_t *sh_video) |
63 vf_instance_t* vf=sh_video->vfilter; | 63 { |
64 if(vf){ | 64 vf_instance_t *vf = sh_video->vfilter; |
65 int ret=vf->control(vf,VFCTRL_QUERY_MAX_PP_LEVEL,NULL); | 65 if (vf) { |
66 if(ret>0){ | 66 int ret = vf->control(vf, VFCTRL_QUERY_MAX_PP_LEVEL, NULL); |
67 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_UsingExternalPP,ret); | 67 if (ret > 0) { |
68 return ret; | 68 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_UsingExternalPP, ret); |
69 } | 69 return ret; |
70 } | 70 } |
71 if(mpvdec){ | 71 } |
72 int ret=mpvdec->control(sh_video,VDCTRL_QUERY_MAX_PP_LEVEL,NULL); | 72 if (mpvdec) { |
73 if(ret>0){ | 73 int ret = mpvdec->control(sh_video, VDCTRL_QUERY_MAX_PP_LEVEL, NULL); |
74 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_UsingCodecPP,ret); | 74 if (ret > 0) { |
75 return ret; | 75 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_UsingCodecPP, ret); |
76 } | 76 return ret; |
77 } | 77 } |
78 } | |
78 // mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Sorry, postprocessing is not available\n"); | 79 // mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Sorry, postprocessing is not available\n"); |
79 return 0; | 80 return 0; |
80 } | 81 } |
81 | 82 |
82 void set_video_quality(sh_video_t *sh_video,int quality){ | 83 void set_video_quality(sh_video_t *sh_video, int quality) |
83 vf_instance_t* vf=sh_video->vfilter; | 84 { |
84 if(vf){ | 85 vf_instance_t *vf = sh_video->vfilter; |
85 int ret=vf->control(vf,VFCTRL_SET_PP_LEVEL, (void*)(&quality)); | 86 if (vf) { |
86 if(ret==CONTROL_TRUE) return; // success | 87 int ret = vf->control(vf, VFCTRL_SET_PP_LEVEL, (void *) (&quality)); |
87 } | 88 if (ret == CONTROL_TRUE) |
88 if(mpvdec) | 89 return; // success |
89 mpvdec->control(sh_video,VDCTRL_SET_PP_LEVEL, (void*)(&quality)); | 90 } |
90 } | 91 if (mpvdec) |
91 | 92 mpvdec->control(sh_video, VDCTRL_SET_PP_LEVEL, (void *) (&quality)); |
92 int set_video_colors(sh_video_t *sh_video,const char *item,int value) | 93 } |
93 { | 94 |
94 vf_instance_t* vf=sh_video->vfilter; | 95 int set_video_colors(sh_video_t *sh_video, const char *item, int value) |
96 { | |
97 vf_instance_t *vf = sh_video->vfilter; | |
95 vf_equalizer_t data; | 98 vf_equalizer_t data; |
96 | 99 |
97 data.item = item; | 100 data.item = item; |
98 data.value = value; | 101 data.value = value; |
99 | 102 |
100 mp_dbg(MSGT_DECVIDEO,MSGL_V,"set video colors %s=%d \n", item, value); | 103 mp_dbg(MSGT_DECVIDEO, MSGL_V, "set video colors %s=%d \n", item, value); |
101 if (vf) | 104 if (vf) { |
102 { | 105 int ret = vf->control(vf, VFCTRL_SET_EQUALIZER, &data); |
103 int ret = vf->control(vf, VFCTRL_SET_EQUALIZER, &data); | 106 if (ret == CONTROL_TRUE) |
104 if (ret == CONTROL_TRUE) | 107 return 1; |
105 return 1; | |
106 } | 108 } |
107 /* try software control */ | 109 /* try software control */ |
108 if(mpvdec) | 110 if (mpvdec) |
109 if( mpvdec->control(sh_video,VDCTRL_SET_EQUALIZER, item, (int *)value) | 111 if (mpvdec->control |
110 == CONTROL_OK) return 1; | 112 (sh_video, VDCTRL_SET_EQUALIZER, item, (int *) value) |
111 mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_VideoAttributeNotSupportedByVO_VD,item); | 113 == CONTROL_OK) |
114 return 1; | |
115 mp_msg(MSGT_DECVIDEO, MSGL_V, MSGTR_VideoAttributeNotSupportedByVO_VD, | |
116 item); | |
112 return 0; | 117 return 0; |
113 } | 118 } |
114 | 119 |
115 int get_video_colors(sh_video_t *sh_video,const char *item,int *value) | 120 int get_video_colors(sh_video_t *sh_video, const char *item, int *value) |
116 { | 121 { |
117 vf_instance_t* vf=sh_video->vfilter; | 122 vf_instance_t *vf = sh_video->vfilter; |
118 vf_equalizer_t data; | 123 vf_equalizer_t data; |
119 | 124 |
120 data.item = item; | 125 data.item = item; |
121 | 126 |
122 mp_dbg(MSGT_DECVIDEO,MSGL_V,"get video colors %s \n", item); | 127 mp_dbg(MSGT_DECVIDEO, MSGL_V, "get video colors %s \n", item); |
123 if (vf) | 128 if (vf) { |
124 { | |
125 int ret = vf->control(vf, VFCTRL_GET_EQUALIZER, &data); | 129 int ret = vf->control(vf, VFCTRL_GET_EQUALIZER, &data); |
126 if (ret == CONTROL_TRUE){ | 130 if (ret == CONTROL_TRUE) { |
127 *value = data.value; | 131 *value = data.value; |
128 return 1; | 132 return 1; |
129 } | 133 } |
130 } | 134 } |
131 /* try software control */ | 135 /* try software control */ |
132 if(mpvdec) return mpvdec->control(sh_video,VDCTRL_GET_EQUALIZER, item, value); | 136 if (mpvdec) |
137 return mpvdec->control(sh_video, VDCTRL_GET_EQUALIZER, item, value); | |
133 return 0; | 138 return 0; |
134 } | 139 } |
135 | 140 |
136 int set_rectangle(sh_video_t *sh_video,int param,int value) | 141 int set_rectangle(sh_video_t *sh_video, int param, int value) |
137 { | 142 { |
138 vf_instance_t* vf=sh_video->vfilter; | 143 vf_instance_t *vf = sh_video->vfilter; |
139 int data[] = {param, value}; | 144 int data[] = { param, value }; |
140 | 145 |
141 mp_dbg(MSGT_DECVIDEO,MSGL_V,"set rectangle \n"); | 146 mp_dbg(MSGT_DECVIDEO, MSGL_V, "set rectangle \n"); |
142 if (vf) | 147 if (vf) { |
143 { | |
144 int ret = vf->control(vf, VFCTRL_CHANGE_RECTANGLE, data); | 148 int ret = vf->control(vf, VFCTRL_CHANGE_RECTANGLE, data); |
145 if (ret) | 149 if (ret) |
146 return 1; | 150 return 1; |
147 } | 151 } |
148 return 0; | 152 return 0; |
149 } | 153 } |
150 | 154 |
151 void resync_video_stream(sh_video_t *sh_video) | 155 void resync_video_stream(sh_video_t *sh_video) |
152 { | 156 { |
153 sh_video->timer = 0; | 157 sh_video->timer = 0; |
154 sh_video->next_frame_time = 0; | 158 sh_video->next_frame_time = 0; |
155 sh_video->num_buffered_pts = 0; | 159 sh_video->num_buffered_pts = 0; |
156 sh_video->last_pts = MP_NOPTS_VALUE; | 160 sh_video->last_pts = MP_NOPTS_VALUE; |
157 if(mpvdec) mpvdec->control(sh_video, VDCTRL_RESYNC_STREAM, NULL); | 161 if (mpvdec) |
162 mpvdec->control(sh_video, VDCTRL_RESYNC_STREAM, NULL); | |
158 } | 163 } |
159 | 164 |
160 int get_current_video_decoder_lag(sh_video_t *sh_video) | 165 int get_current_video_decoder_lag(sh_video_t *sh_video) |
161 { | 166 { |
162 int ret; | 167 int ret; |
163 | 168 |
164 if (!mpvdec) | 169 if (!mpvdec) |
165 return -1; | 170 return -1; |
166 ret = mpvdec->control(sh_video, VDCTRL_QUERY_UNSEEN_FRAMES, NULL); | 171 ret = mpvdec->control(sh_video, VDCTRL_QUERY_UNSEEN_FRAMES, NULL); |
167 if (ret >= 10) | 172 if (ret >= 10) |
168 return ret-10; | 173 return ret - 10; |
169 return -1; | 174 return -1; |
170 } | 175 } |
171 | 176 |
172 void uninit_video(sh_video_t *sh_video){ | 177 void uninit_video(sh_video_t *sh_video) |
173 if(!sh_video->initialized) return; | 178 { |
174 mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_UninitVideoStr,sh_video->codec->drv); | 179 if (!sh_video->initialized) |
180 return; | |
181 mp_msg(MSGT_DECVIDEO, MSGL_V, MSGTR_UninitVideoStr, sh_video->codec->drv); | |
175 mpvdec->uninit(sh_video); | 182 mpvdec->uninit(sh_video); |
176 #ifdef CONFIG_DYNAMIC_PLUGINS | 183 #ifdef CONFIG_DYNAMIC_PLUGINS |
177 if (sh_video->dec_handle) | 184 if (sh_video->dec_handle) |
178 dlclose(sh_video->dec_handle); | 185 dlclose(sh_video->dec_handle); |
179 #endif | 186 #endif |
180 vf_uninit_filter_chain(sh_video->vfilter); | 187 vf_uninit_filter_chain(sh_video->vfilter); |
181 sh_video->initialized=0; | 188 sh_video->initialized = 0; |
182 } | 189 } |
183 | 190 |
184 void vfm_help(void){ | 191 void vfm_help(void) |
192 { | |
185 int i; | 193 int i; |
186 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_AvailableVideoFm); | 194 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_AvailableVideoFm); |
187 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_DRIVERS\n"); | 195 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_DRIVERS\n"); |
188 mp_msg(MSGT_DECVIDEO,MSGL_INFO," vfm: info: (comment)\n"); | 196 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " vfm: info: (comment)\n"); |
189 for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) | 197 for (i = 0; mpcodecs_vd_drivers[i] != NULL; i++) |
190 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"%8s %s (%s)\n", | 198 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "%8s %s (%s)\n", |
191 mpcodecs_vd_drivers[i]->info->short_name, | 199 mpcodecs_vd_drivers[i]->info->short_name, |
192 mpcodecs_vd_drivers[i]->info->name, | 200 mpcodecs_vd_drivers[i]->info->name, |
193 mpcodecs_vd_drivers[i]->info->comment); | 201 mpcodecs_vd_drivers[i]->info->comment); |
194 } | 202 } |
195 | 203 |
196 static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status, | 204 static int init_video(sh_video_t *sh_video, char *codecname, char *vfm, |
197 stringset_t *selected){ | 205 int status, stringset_t *selected) |
206 { | |
198 int force = 0; | 207 int force = 0; |
199 unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0; | 208 unsigned int orig_fourcc = |
200 sh_video->codec=NULL; | 209 sh_video->bih ? sh_video->bih->biCompression : 0; |
201 sh_video->vf_initialized=0; | 210 sh_video->codec = NULL; |
211 sh_video->vf_initialized = 0; | |
202 if (codecname && codecname[0] == '+') { | 212 if (codecname && codecname[0] == '+') { |
203 codecname = &codecname[1]; | 213 codecname = &codecname[1]; |
204 force = 1; | 214 force = 1; |
205 } | 215 } |
206 | 216 |
207 while(1){ | 217 while (1) { |
208 int i; | 218 int i; |
209 int orig_w, orig_h; | 219 int orig_w, orig_h; |
210 // restore original fourcc: | 220 // restore original fourcc: |
211 if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc; | 221 if (sh_video->bih) |
212 if(!(sh_video->codec=find_video_codec(sh_video->format, | 222 sh_video->bih->biCompression = orig_fourcc; |
213 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, | 223 if (! |
214 sh_video->codec,force) )) break; | 224 (sh_video->codec = |
215 // ok we found one codec | 225 find_video_codec(sh_video->format, |
216 if(stringset_test(selected, sh_video->codec->name)) continue; // already tried & failed | 226 sh_video-> |
217 if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc | 227 bih ? ((unsigned int *) &sh_video->bih-> |
218 if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match | 228 biCompression) : NULL, sh_video->codec, |
219 if(!force && sh_video->codec->status<status) continue; // too unstable | 229 force))) |
220 stringset_add(selected, sh_video->codec->name); // tagging it | 230 break; |
221 // ok, it matches all rules, let's find the driver! | 231 // ok we found one codec |
222 for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) | 232 if (stringset_test(selected, sh_video->codec->name)) |
223 // if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; | 233 continue; // already tried & failed |
224 if(!strcmp(mpcodecs_vd_drivers[i]->info->short_name,sh_video->codec->drv)) break; | 234 if (codecname && strcmp(sh_video->codec->name, codecname)) |
225 mpvdec=mpcodecs_vd_drivers[i]; | 235 continue; // -vc |
236 if (vfm && strcmp(sh_video->codec->drv, vfm)) | |
237 continue; // vfm doesn't match | |
238 if (!force && sh_video->codec->status < status) | |
239 continue; // too unstable | |
240 stringset_add(selected, sh_video->codec->name); // tagging it | |
241 // ok, it matches all rules, let's find the driver! | |
242 for (i = 0; mpcodecs_vd_drivers[i] != NULL; i++) | |
243 // if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; | |
244 if (!strcmp | |
245 (mpcodecs_vd_drivers[i]->info->short_name, | |
246 sh_video->codec->drv)) | |
247 break; | |
248 mpvdec = mpcodecs_vd_drivers[i]; | |
226 #ifdef CONFIG_DYNAMIC_PLUGINS | 249 #ifdef CONFIG_DYNAMIC_PLUGINS |
227 if (!mpvdec) | 250 if (!mpvdec) { |
228 { | 251 /* try to open shared decoder plugin */ |
229 /* try to open shared decoder plugin */ | 252 int buf_len; |
230 int buf_len; | 253 char *buf; |
231 char *buf; | 254 vd_functions_t *funcs_sym; |
232 vd_functions_t *funcs_sym; | 255 vd_info_t *info_sym; |
233 vd_info_t *info_sym; | 256 |
234 | 257 buf_len = |
235 buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_video->codec->drv)+16; | 258 strlen(MPLAYER_LIBDIR) + strlen(sh_video->codec->drv) + 16; |
236 buf = malloc(buf_len); | 259 buf = malloc(buf_len); |
237 if (!buf) | 260 if (!buf) |
238 break; | 261 break; |
239 snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, sh_video->codec->drv); | 262 snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, |
240 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf); | 263 sh_video->codec->drv); |
241 sh_video->dec_handle = dlopen(buf, RTLD_LAZY); | 264 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, |
242 if (!sh_video->dec_handle) | 265 "Trying to open external plugin: %s\n", buf); |
243 break; | 266 sh_video->dec_handle = dlopen(buf, RTLD_LAZY); |
244 snprintf(buf, buf_len, "mpcodecs_vd_%s", sh_video->codec->drv); | 267 if (!sh_video->dec_handle) |
245 funcs_sym = dlsym(sh_video->dec_handle, buf); | 268 break; |
246 if (!funcs_sym || !funcs_sym->info || !funcs_sym->init || | 269 snprintf(buf, buf_len, "mpcodecs_vd_%s", sh_video->codec->drv); |
247 !funcs_sym->uninit || !funcs_sym->control || !funcs_sym->decode) | 270 funcs_sym = dlsym(sh_video->dec_handle, buf); |
248 break; | 271 if (!funcs_sym || !funcs_sym->info || !funcs_sym->init |
249 info_sym = funcs_sym->info; | 272 || !funcs_sym->uninit || !funcs_sym->control |
250 if (strcmp(info_sym->short_name, sh_video->codec->drv)) | 273 || !funcs_sym->decode) |
251 break; | 274 break; |
252 free(buf); | 275 info_sym = funcs_sym->info; |
253 mpvdec = funcs_sym; | 276 if (strcmp(info_sym->short_name, sh_video->codec->drv)) |
254 mp_msg(MSGT_DECVIDEO, MSGL_V, "Using external decoder plugin (%s/mplayer/vd_%s.so)!\n", | 277 break; |
255 MPLAYER_LIBDIR, sh_video->codec->drv); | 278 free(buf); |
256 } | 279 mpvdec = funcs_sym; |
257 #endif | 280 mp_msg(MSGT_DECVIDEO, MSGL_V, |
258 if(!mpvdec){ // driver not available (==compiled in) | 281 "Using external decoder plugin (%s/mplayer/vd_%s.so)!\n", |
259 mp_msg(MSGT_DECVIDEO,MSGL_WARN,MSGTR_VideoCodecFamilyNotAvailableStr, | 282 MPLAYER_LIBDIR, sh_video->codec->drv); |
260 sh_video->codec->name, sh_video->codec->drv); | 283 } |
261 continue; | 284 #endif |
262 } | 285 if (!mpvdec) { // driver not available (==compiled in) |
263 orig_w = sh_video->bih ? sh_video->bih->biWidth : sh_video->disp_w; | 286 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
264 orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h; | 287 MSGTR_VideoCodecFamilyNotAvailableStr, |
265 sh_video->disp_w = orig_w; | 288 sh_video->codec->name, sh_video->codec->drv); |
266 sh_video->disp_h = orig_h; | 289 continue; |
267 // it's available, let's try to init! | 290 } |
268 if(sh_video->codec->flags & CODECS_FLAG_ALIGN16){ | 291 orig_w = sh_video->bih ? sh_video->bih->biWidth : sh_video->disp_w; |
269 // align width/height to n*16 | 292 orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h; |
270 sh_video->disp_w=(sh_video->disp_w+15)&(~15); | 293 sh_video->disp_w = orig_w; |
271 sh_video->disp_h=(sh_video->disp_h+15)&(~15); | 294 sh_video->disp_h = orig_h; |
272 } | 295 // it's available, let's try to init! |
273 if (sh_video->bih) { | 296 if (sh_video->codec->flags & CODECS_FLAG_ALIGN16) { |
274 sh_video->bih->biWidth = sh_video->disp_w; | 297 // align width/height to n*16 |
275 sh_video->bih->biHeight = sh_video->disp_h; | 298 sh_video->disp_w = (sh_video->disp_w + 15) & (~15); |
276 } | 299 sh_video->disp_h = (sh_video->disp_h + 15) & (~15); |
277 // init() | 300 } |
278 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_OpeningVideoDecoder,mpvdec->info->short_name,mpvdec->info->name); | 301 if (sh_video->bih) { |
279 // clear vf init error, it is no longer relevant | 302 sh_video->bih->biWidth = sh_video->disp_w; |
280 if (sh_video->vf_initialized < 0) | 303 sh_video->bih->biHeight = sh_video->disp_h; |
281 sh_video->vf_initialized = 0; | 304 } |
282 if(!mpvdec->init(sh_video)){ | 305 // init() |
283 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_VDecoderInitFailed); | 306 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_OpeningVideoDecoder, |
284 sh_video->disp_w=orig_w; | 307 mpvdec->info->short_name, mpvdec->info->name); |
285 sh_video->disp_h=orig_h; | 308 // clear vf init error, it is no longer relevant |
286 if (sh_video->bih) { | 309 if (sh_video->vf_initialized < 0) |
287 sh_video->bih->biWidth = sh_video->disp_w; | 310 sh_video->vf_initialized = 0; |
288 sh_video->bih->biHeight = sh_video->disp_h; | 311 if (!mpvdec->init(sh_video)) { |
289 } | 312 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_VDecoderInitFailed); |
290 continue; // try next... | 313 sh_video->disp_w = orig_w; |
291 } | 314 sh_video->disp_h = orig_h; |
292 // Yeah! We got it! | 315 if (sh_video->bih) { |
293 sh_video->initialized=1; | 316 sh_video->bih->biWidth = sh_video->disp_w; |
294 return 1; | 317 sh_video->bih->biHeight = sh_video->disp_h; |
318 } | |
319 continue; // try next... | |
320 } | |
321 // Yeah! We got it! | |
322 sh_video->initialized = 1; | |
323 return 1; | |
295 } | 324 } |
296 return 0; | 325 return 0; |
297 } | 326 } |
298 | 327 |
299 int init_best_video_codec(sh_video_t *sh_video,char** video_codec_list,char** video_fm_list){ | 328 int init_best_video_codec(sh_video_t *sh_video, char **video_codec_list, |
300 char* vc_l_default[2]={"",(char*)NULL}; | 329 char **video_fm_list) |
301 stringset_t selected; | 330 { |
302 // hack: | 331 char *vc_l_default[2] = { "", (char *) NULL }; |
303 if(!video_codec_list) video_codec_list=vc_l_default; | 332 stringset_t selected; |
304 // Go through the codec.conf and find the best codec... | 333 // hack: |
305 sh_video->initialized=0; | 334 if (!video_codec_list) |
306 stringset_init(&selected); | 335 video_codec_list = vc_l_default; |
307 while(!sh_video->initialized && *video_codec_list){ | 336 // Go through the codec.conf and find the best codec... |
308 char* video_codec=*(video_codec_list++); | 337 sh_video->initialized = 0; |
309 if(video_codec[0]){ | 338 stringset_init(&selected); |
310 if(video_codec[0]=='-'){ | 339 while (!sh_video->initialized && *video_codec_list) { |
311 // disable this codec: | 340 char *video_codec = *(video_codec_list++); |
312 stringset_add(&selected, video_codec+1); | 341 if (video_codec[0]) { |
313 } else { | 342 if (video_codec[0] == '-') { |
314 // forced codec by name: | 343 // disable this codec: |
315 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_ForcedVideoCodec,video_codec); | 344 stringset_add(&selected, video_codec + 1); |
316 init_video(sh_video,video_codec,NULL,-1, &selected); | 345 } else { |
317 } | 346 // forced codec by name: |
318 } else { | 347 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_ForcedVideoCodec, |
319 int status; | 348 video_codec); |
320 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. | 349 init_video(sh_video, video_codec, NULL, -1, &selected); |
321 if(video_fm_list){ | 350 } |
322 char** fmlist=video_fm_list; | 351 } else { |
323 // try first the preferred codec families: | 352 int status; |
324 while(!sh_video->initialized && *fmlist){ | 353 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. |
325 char* video_fm=*(fmlist++); | 354 if (video_fm_list) { |
326 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_TryForceVideoFmtStr,video_fm); | 355 char **fmlist = video_fm_list; |
327 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | 356 // try first the preferred codec families: |
328 if(init_video(sh_video,NULL,video_fm,status, &selected)) break; | 357 while (!sh_video->initialized && *fmlist) { |
329 } | 358 char *video_fm = *(fmlist++); |
330 } | 359 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_TryForceVideoFmtStr, |
331 if(!sh_video->initialized) | 360 video_fm); |
332 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | 361 for (status = CODECS_STATUS__MAX; |
333 if(init_video(sh_video,NULL,NULL,status, &selected)) break; | 362 status >= CODECS_STATUS__MIN; --status) |
334 } | 363 if (init_video |
335 } | 364 (sh_video, NULL, video_fm, status, &selected)) |
336 stringset_free(&selected); | 365 break; |
337 | 366 } |
338 if(!sh_video->initialized){ | 367 } |
339 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); | 368 if (!sh_video->initialized) |
340 return 0; // failed | 369 for (status = CODECS_STATUS__MAX; status >= CODECS_STATUS__MIN; |
341 } | 370 --status) |
342 | 371 if (init_video(sh_video, NULL, NULL, status, &selected)) |
343 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_SelectedVideoCodec, | 372 break; |
344 sh_video->codec->name,sh_video->codec->drv,sh_video->codec->info); | 373 } |
345 return 1; // success | 374 } |
375 stringset_free(&selected); | |
376 | |
377 if (!sh_video->initialized) { | |
378 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantFindVideoCodec, | |
379 sh_video->format); | |
380 return 0; // failed | |
381 } | |
382 | |
383 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_SelectedVideoCodec, | |
384 sh_video->codec->name, sh_video->codec->drv, sh_video->codec->info); | |
385 return 1; // success | |
346 } | 386 } |
347 | 387 |
348 void *decode_video(sh_video_t *sh_video, unsigned char *start, int in_size, | 388 void *decode_video(sh_video_t *sh_video, unsigned char *start, int in_size, |
349 int drop_frame, double pts) | 389 int drop_frame, double pts) |
350 { | 390 { |
351 mp_image_t *mpi = NULL; | 391 mp_image_t *mpi = NULL; |
352 unsigned int t = GetTimer(); | 392 unsigned int t = GetTimer(); |
353 unsigned int t2; | 393 unsigned int t2; |
354 double tt; | 394 double tt; |
355 | 395 |
356 if (correct_pts && pts != MP_NOPTS_VALUE) { | 396 if (correct_pts && pts != MP_NOPTS_VALUE) { |
357 int delay = get_current_video_decoder_lag(sh_video); | 397 int delay = get_current_video_decoder_lag(sh_video); |
358 if (delay >= 0) { | 398 if (delay >= 0) { |
359 if (delay > sh_video->num_buffered_pts) | 399 if (delay > sh_video->num_buffered_pts) |
360 #if 0 | 400 #if 0 |
361 // this is disabled because vd_ffmpeg reports the same lag | 401 // this is disabled because vd_ffmpeg reports the same lag |
362 // after seek even when there are no buffered frames, | 402 // after seek even when there are no buffered frames, |
363 // leading to incorrect error messages | 403 // leading to incorrect error messages |
364 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Not enough buffered pts\n"); | 404 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Not enough buffered pts\n"); |
365 #else | 405 #else |
366 ; | 406 ; |
367 #endif | 407 #endif |
368 else | 408 else |
369 sh_video->num_buffered_pts = delay; | 409 sh_video->num_buffered_pts = delay; |
370 } | 410 } |
371 if (sh_video->num_buffered_pts == | 411 if (sh_video->num_buffered_pts == |
372 sizeof(sh_video->buffered_pts)/sizeof(double)) | 412 sizeof(sh_video->buffered_pts) / sizeof(double)) |
373 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Too many buffered pts\n"); | 413 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Too many buffered pts\n"); |
374 else { | 414 else { |
375 int i, j; | 415 int i, j; |
376 for (i = 0; i < sh_video->num_buffered_pts; i++) | 416 for (i = 0; i < sh_video->num_buffered_pts; i++) |
377 if (sh_video->buffered_pts[i] < pts) | 417 if (sh_video->buffered_pts[i] < pts) |
378 break; | 418 break; |
379 for (j = sh_video->num_buffered_pts; j > i; j--) | 419 for (j = sh_video->num_buffered_pts; j > i; j--) |
380 sh_video->buffered_pts[j] = sh_video->buffered_pts[j-1]; | 420 sh_video->buffered_pts[j] = sh_video->buffered_pts[j - 1]; |
381 sh_video->buffered_pts[i] = pts; | 421 sh_video->buffered_pts[i] = pts; |
382 sh_video->num_buffered_pts++; | 422 sh_video->num_buffered_pts++; |
383 } | 423 } |
384 } | 424 } |
385 | 425 |
386 mpi = mpvdec->decode(sh_video, start, in_size, drop_frame); | 426 mpi = mpvdec->decode(sh_video, start, in_size, drop_frame); |
387 | 427 |
388 //------------------------ frame decoded. -------------------- | 428 //------------------------ frame decoded. -------------------- |
389 | 429 |
390 #if HAVE_MMX | 430 #if HAVE_MMX |
391 // some codecs are broken, and doesn't restore MMX state :( | 431 // some codecs are broken, and doesn't restore MMX state :( |
392 // it happens usually with broken/damaged files. | 432 // it happens usually with broken/damaged files. |
393 if (gCpuCaps.has3DNow) { | 433 if (gCpuCaps.has3DNow) { |
394 __asm__ volatile ("femms\n\t":::"memory"); | 434 __asm__ volatile ("femms\n\t":::"memory"); |
395 } | 435 } else if (gCpuCaps.hasMMX) { |
396 else if (gCpuCaps.hasMMX) { | 436 __asm__ volatile ("emms\n\t":::"memory"); |
397 __asm__ volatile ("emms\n\t":::"memory"); | 437 } |
398 } | 438 #endif |
399 #endif | 439 |
400 | 440 t2 = GetTimer(); |
401 t2 = GetTimer(); t = t2-t; | 441 t = t2 - t; |
402 tt = t*0.000001f; | 442 tt = t * 0.000001f; |
403 video_time_usage += tt; | 443 video_time_usage += tt; |
404 | 444 |
405 if (!mpi || drop_frame) | 445 if (!mpi || drop_frame) |
406 return NULL; // error / skipped frame | 446 return NULL; // error / skipped frame |
407 | 447 |
408 if (field_dominance == 0) | 448 if (field_dominance == 0) |
409 mpi->fields |= MP_IMGFIELD_TOP_FIRST; | 449 mpi->fields |= MP_IMGFIELD_TOP_FIRST; |
410 else if (field_dominance == 1) | 450 else if (field_dominance == 1) |
411 mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; | 451 mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; |
412 | 452 |
413 if (correct_pts) { | 453 if (correct_pts) { |
414 if (sh_video->num_buffered_pts) { | 454 if (sh_video->num_buffered_pts) { |
415 sh_video->num_buffered_pts--; | 455 sh_video->num_buffered_pts--; |
416 sh_video->pts = sh_video->buffered_pts[sh_video->num_buffered_pts]; | 456 sh_video->pts = sh_video->buffered_pts[sh_video->num_buffered_pts]; |
417 } | 457 } else { |
418 else { | 458 mp_msg(MSGT_CPLAYER, MSGL_ERR, |
419 mp_msg(MSGT_CPLAYER, MSGL_ERR, "No pts value from demuxer to " | 459 "No pts value from demuxer to " "use for frame!\n"); |
420 "use for frame!\n"); | 460 sh_video->pts = MP_NOPTS_VALUE; |
421 sh_video->pts = MP_NOPTS_VALUE; | 461 } |
422 } | |
423 } | 462 } |
424 return mpi; | 463 return mpi; |
425 } | 464 } |
426 | 465 |
427 int filter_video(sh_video_t *sh_video, void *frame, double pts) | 466 int filter_video(sh_video_t *sh_video, void *frame, double pts) |
430 unsigned int t2 = GetTimer(); | 469 unsigned int t2 = GetTimer(); |
431 vf_instance_t *vf = sh_video->vfilter; | 470 vf_instance_t *vf = sh_video->vfilter; |
432 // apply video filters and call the leaf vo/ve | 471 // apply video filters and call the leaf vo/ve |
433 int ret = vf->put_image(vf, mpi, pts); | 472 int ret = vf->put_image(vf, mpi, pts); |
434 if (ret > 0) { | 473 if (ret > 0) { |
435 // draw EOSD first so it ends up below the OSD. | 474 // draw EOSD first so it ends up below the OSD. |
436 // Note that changing this is will not work right with vf_ass and the | 475 // Note that changing this is will not work right with vf_ass and the |
437 // vos currently always draw the EOSD first in paused mode. | 476 // vos currently always draw the EOSD first in paused mode. |
438 #ifdef CONFIG_ASS | 477 #ifdef CONFIG_ASS |
439 vf->control(vf, VFCTRL_DRAW_EOSD, NULL); | 478 vf->control(vf, VFCTRL_DRAW_EOSD, NULL); |
440 #endif | 479 #endif |
441 vf->control(vf, VFCTRL_DRAW_OSD, NULL); | 480 vf->control(vf, VFCTRL_DRAW_OSD, NULL); |
442 } | 481 } |
443 | 482 |
444 t2 = GetTimer()-t2; | 483 t2 = GetTimer() - t2; |
445 vout_time_usage += t2*0.000001; | 484 vout_time_usage += t2 * 0.000001; |
446 | 485 |
447 return ret; | 486 return ret; |
448 } | 487 } |