Mercurial > mplayer.hg
annotate libmpcodecs/dec_video.c @ 6832:54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
author | arpi |
---|---|
date | Sun, 28 Jul 2002 21:30:09 +0000 |
parents | 6ad5d182153c |
children | 66427e850216 |
rev | line source |
---|---|
2775 | 1 |
2 #include "config.h" | |
1294 | 3 |
4 #include <stdio.h> | |
2775 | 5 #ifdef HAVE_MALLOC_H |
6 #include <malloc.h> | |
7 #endif | |
1294 | 8 #include <stdlib.h> |
1430 | 9 #include <unistd.h> |
1294 | 10 |
1567 | 11 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1949
diff
changeset
|
12 #include "help_mp.h" |
1294 | 13 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1309
diff
changeset
|
14 #include "linux/timer.h" |
1496 | 15 #include "linux/shmem.h" |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1309
diff
changeset
|
16 |
2563 | 17 extern int verbose; // defined in mplayer.c |
18 | |
1294 | 19 #include "stream.h" |
20 #include "demuxer.h" | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
21 #include "parse_es.h" |
1294 | 22 |
23 #include "codec-cfg.h" | |
24 | |
25 #include "libvo/video_out.h" | |
26 | |
4188 | 27 #include "stheader.h" |
4902
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
28 #include "vd.h" |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
5328
diff
changeset
|
29 #include "vf.h" |
4188 | 30 |
2563 | 31 #include "dec_video.h" |
32 | |
33 // =================================================================== | |
34 | |
35 extern double video_time_usage; | |
36 extern double vout_time_usage; | |
4388 | 37 extern vo_vaa_t vo_vaa; |
2563 | 38 |
2184 | 39 #include "postproc/postprocess.h" |
40 | |
3144 | 41 #include "cpudetect.h" |
42 | |
2563 | 43 int divx_quality=0; |
1294 | 44 |
5180 | 45 vd_functions_t* mpvdec=NULL; |
4902
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
46 |
1429 | 47 int get_video_quality_max(sh_video_t *sh_video){ |
5519 | 48 vf_instance_t* vf=sh_video->vfilter; |
49 if(vf){ | |
50 int ret=vf->control(vf,VFCTRL_QUERY_MAX_PP_LEVEL,NULL); | |
51 if(ret>0){ | |
52 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Using external postprocessing filter, max q = %d\n",ret); | |
53 return ret; | |
54 } | |
55 } | |
4957 | 56 if(mpvdec){ |
4967 | 57 int ret=mpvdec->control(sh_video,VDCTRL_QUERY_MAX_PP_LEVEL,NULL); |
5519 | 58 if(ret>0){ |
59 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Using codec's postprocessing, max q = %d\n",ret); | |
60 return ret; | |
61 } | |
4957 | 62 } |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
5984
diff
changeset
|
63 // mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Sorry, postprocessing is not available\n"); |
5519 | 64 return 0; |
1429 | 65 } |
66 | |
67 void set_video_quality(sh_video_t *sh_video,int quality){ | |
5519 | 68 vf_instance_t* vf=sh_video->vfilter; |
69 if(vf){ | |
70 int ret=vf->control(vf,VFCTRL_SET_PP_LEVEL, (void*)(&quality)); | |
71 if(ret==CONTROL_TRUE) return; // success | |
72 } | |
4957 | 73 if(mpvdec) |
74 mpvdec->control(sh_video,VDCTRL_SET_PP_LEVEL, (void*)(&quality)); | |
1429 | 75 } |
76 | |
4395 | 77 int set_video_colors(sh_video_t *sh_video,char *item,int value) |
78 { | |
6780 | 79 vf_instance_t* vf=sh_video->vfilter; |
6832
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
80 vf_equalizer_t data; |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
81 |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
82 data.item = item; |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
83 data.value = value; |
6786 | 84 |
85 mp_dbg(MSGT_DECVIDEO,MSGL_V,"set video colors %s=%d \n", item, value); | |
6785 | 86 if (vf) |
87 { | |
6832
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
88 int ret = vf->control(vf, VFCTRL_SET_EQUALIZER, &data); |
6785 | 89 if (ret == CONTROL_TRUE) |
90 return(1); | |
91 } | |
6780 | 92 /* try software control */ |
6800 | 93 if(mpvdec) |
94 if( mpvdec->control(sh_video,VDCTRL_SET_EQUALIZER, item, (int *)value) | |
95 == CONTROL_OK) return 1; | |
96 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Video attribute '%s' isn't supported by selected vo & vd! \n",item); | |
6780 | 97 return 0; |
98 } | |
99 | |
100 int get_video_colors(sh_video_t *sh_video,char *item,int *value) | |
101 { | |
102 vf_instance_t* vf=sh_video->vfilter; | |
6832
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
103 vf_equalizer_t data; |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
104 |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
105 data.item = item; |
6786 | 106 |
107 mp_dbg(MSGT_DECVIDEO,MSGL_V,"get video colors %s \n", item); | |
108 if (vf) | |
109 { | |
6832
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
110 int ret = vf->control(vf, VFCTRL_GET_EQUALIZER, &data); |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
111 if (ret == CONTROL_TRUE){ |
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
112 *value = data.value; |
6786 | 113 return(1); |
6832
54578e5a8050
... removed from vf's control(), sing struct for equalizer. based on patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
6800
diff
changeset
|
114 } |
6786 | 115 } |
6780 | 116 /* try software control */ |
117 if(mpvdec) return mpvdec->control(sh_video,VDCTRL_GET_EQUALIZER, item, value); | |
1429 | 118 return 0; |
119 } | |
1294 | 120 |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
2044
diff
changeset
|
121 void uninit_video(sh_video_t *sh_video){ |
1654 | 122 if(!sh_video->inited) return; |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1949
diff
changeset
|
123 mp_msg(MSGT_DECVIDEO,MSGL_V,"uninit video: %d \n",sh_video->codec->driver); |
4902
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
124 mpvdec->uninit(sh_video); |
5737 | 125 vf_uninit_filter_chain(sh_video->vfilter); |
1654 | 126 sh_video->inited=0; |
127 } | |
128 | |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
129 int init_video(sh_video_t *sh_video,char* codecname,int vfm,int status){ |
6230
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
130 unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0; |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
131 sh_video->codec=NULL; |
5925
3f17793b2cea
setting vf_inited flag, some printf->mp_msg, some MSGL_FATAL->MSGL_WARN
arpi
parents:
5871
diff
changeset
|
132 sh_video->vf_inited=0; |
6230
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
133 |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
134 while(1){ |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
135 int i; |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
136 // restore original fourcc: |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
137 if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc; |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
138 if(!(sh_video->codec=find_codec(sh_video->format, |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
139 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, |
936aa617e829
restore original bih->biCompression if codec init failed
arpi
parents:
6138
diff
changeset
|
140 sh_video->codec,0) )) break; |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
141 // ok we found one codec |
5328
014ddf03476d
check and set codec selection - impossible to do it at find_codec
arpi
parents:
5266
diff
changeset
|
142 if(sh_video->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
143 if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
144 if(vfm>=0 && sh_video->codec->driver!=vfm) continue; // vfm doesn't match |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
145 if(sh_video->codec->status<status) continue; // too unstable |
5328
014ddf03476d
check and set codec selection - impossible to do it at find_codec
arpi
parents:
5266
diff
changeset
|
146 sh_video->codec->flags|=CODECS_FLAG_SELECTED; // tagging it |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
147 // ok, it matches all rules, let's find the driver! |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
148 for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
149 if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
150 mpvdec=mpcodecs_vd_drivers[i]; |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
151 if(!mpvdec){ // driver not available (==compiled in) |
5925
3f17793b2cea
setting vf_inited flag, some printf->mp_msg, some MSGL_FATAL->MSGL_WARN
arpi
parents:
5871
diff
changeset
|
152 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Requested video codec family [%s] (vfm=%d) not available (enable it at compile time!)\n", |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
153 sh_video->codec->name, sh_video->codec->driver); |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
154 continue; |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
155 } |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
156 // it's available, let's try to init! |
6566 | 157 if(sh_video->codec->flags & CODECS_FLAG_ALIGN16){ |
158 // align width/height to n*16 | |
159 // FIXME: save orig w/h, and restore if codec init failed! | |
160 if(sh_video->bih){ | |
161 sh_video->disp_w=sh_video->bih->biWidth=(sh_video->bih->biWidth+15)&(~15); | |
162 sh_video->disp_h=sh_video->bih->biHeight=(sh_video->bih->biHeight+15)&(~15); | |
163 } else { | |
164 sh_video->disp_w=(sh_video->disp_w+15)&(~15); | |
165 sh_video->disp_h=(sh_video->disp_h+15)&(~15); | |
166 } | |
167 } | |
168 // init() | |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
5984
diff
changeset
|
169 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Opening video decoder: [%s] %s\n",mpvdec->info->short_name,mpvdec->info->name); |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
170 if(!mpvdec->init(sh_video)){ |
5925
3f17793b2cea
setting vf_inited flag, some printf->mp_msg, some MSGL_FATAL->MSGL_WARN
arpi
parents:
5871
diff
changeset
|
171 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VDecoder init failed :(\n"); |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
172 continue; // try next... |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
173 } |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
174 // Yeah! We got it! |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
175 sh_video->inited=1; |
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
176 return 1; |
4902
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
177 } |
5171
7145d6aba6cd
init_video() changed - now it handles codec selection
arpi
parents:
5155
diff
changeset
|
178 return 0; |
1294 | 179 } |
180 | |
5224 | 181 extern int vo_directrendering; |
4515 | 182 |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
5328
diff
changeset
|
183 int decode_video(sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
5328
diff
changeset
|
184 vf_instance_t* vf=sh_video->vfilter; |
4898 | 185 mp_image_t *mpi=NULL; |
1360 | 186 unsigned int t=GetTimer(); |
187 unsigned int t2; | |
4834 | 188 double tt; |
1360 | 189 |
5266
413e450da31c
try to uncomment this line - very funny effect (skipping I frames)
arpi
parents:
5224
diff
changeset
|
190 //if(!(sh_video->ds->flags&1) || sh_video->ds->pack_no<5) |
4902
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
191 mpi=mpvdec->decode(sh_video, start, in_size, drop_frame); |
7c4edfe929c8
implemented basic wrapper functions to new libmpcodecs api
arpi
parents:
4901
diff
changeset
|
192 |
1294 | 193 //------------------------ frame decoded. -------------------- |
194 | |
3160 | 195 #ifdef ARCH_X86 |
6780 | 196 // some codecs are broken, and doesn't restore MMX state :( |
1367 | 197 // it happens usually with broken/damaged files. |
3144 | 198 if(gCpuCaps.has3DNow){ |
199 __asm __volatile ("femms\n\t":::"memory"); | |
200 } | |
201 else if(gCpuCaps.hasMMX){ | |
202 __asm __volatile ("emms\n\t":::"memory"); | |
203 } | |
3160 | 204 #endif |
1367 | 205 |
4834 | 206 t2=GetTimer();t=t2-t; |
207 tt = t*0.000001f; | |
208 video_time_usage+=tt; | |
4898 | 209 |
5643 | 210 if(!mpi || drop_frame) return 0; // error / skipped frame |
5040 | 211 |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
5328
diff
changeset
|
212 //vo_draw_image(video_out,mpi); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
5328
diff
changeset
|
213 vf->put_image(vf,mpi); |
5643 | 214 vf->control(vf,VFCTRL_DRAW_OSD,NULL); |
4898 | 215 |
4834 | 216 t2=GetTimer()-t2; |
217 tt=t2*0.000001f; | |
218 vout_time_usage+=tt; | |
1360 | 219 |
5984 | 220 return 1; |
1294 | 221 } |