Mercurial > mplayer.hg
annotate gui/mplayer/common.c @ 24933:4fc6e60dac36
Avoid short forms; has the added benefit of allowing compilation with gcc 2.95
which complains about 'unterminated string or character constant'.
author | diego |
---|---|
date | Sat, 03 Nov 2007 22:25:52 +0000 |
parents | 0b4098f8331a |
children |
rev | line source |
---|---|
23077 | 1 |
2 // main window | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <inttypes.h> | |
7 #include <sys/stat.h> | |
8 #include <unistd.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
23154
diff
changeset
|
9 #include <string.h> |
23077 | 10 |
11 #include "app.h" | |
12 #include "skin/font.h" | |
13 #include "skin/skin.h" | |
14 #include "wm/ws.h" | |
15 | |
16 #include "../config.h" | |
17 #include "../help_mp.h" | |
18 #include "../libvo/x11_common.h" | |
19 | |
20 #include "../stream/stream.h" | |
21 #include "../mixer.h" | |
22 #include "../libvo/sub.h" | |
23 | |
24 #include "../libmpdemux/demuxer.h" | |
25 #include "../libmpdemux/stheader.h" | |
26 #include "../codec-cfg.h" | |
23154
e564b9cd7290
Fix several implicit declarations of functions warnings.
diego
parents:
23077
diff
changeset
|
27 #include "../access_mpcontext.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
28 #include "../libavutil/avstring.h" |
23077 | 29 |
30 | |
31 #include "play.h" | |
32 #include "widgets.h" | |
33 | |
34 extern unsigned int GetTimerMS( void ); | |
35 | |
36 inline void TranslateFilename( int c,char * tmp,size_t tmplen ) | |
37 { | |
38 int i; | |
39 char * p; | |
40 | |
41 switch ( guiIntfStruct.StreamType ) | |
42 { | |
43 case STREAMTYPE_STREAM: | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
44 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen); |
23077 | 45 break; |
46 case STREAMTYPE_FILE: | |
47 if ( ( guiIntfStruct.Filename )&&( guiIntfStruct.Filename[0] ) ) | |
48 { | |
49 if ( (p = strrchr(guiIntfStruct.Filename, '/')) ) | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
50 av_strlcpy(tmp, p + 1, tmplen); |
23077 | 51 else |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
52 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen); |
23077 | 53 if ( tmp[strlen( tmp ) - 4] == '.' ) tmp[strlen( tmp ) - 4]=0; |
54 if ( tmp[strlen( tmp ) - 5] == '.' ) tmp[strlen( tmp ) - 5]=0; | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
55 } else av_strlcpy( tmp,MSGTR_NoFileLoaded,tmplen ); |
23077 | 56 break; |
57 #ifdef USE_DVDREAD | |
58 case STREAMTYPE_DVD: | |
59 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter ); | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
60 else av_strlcat( tmp,MSGTR_NoChapter,tmplen ); |
23077 | 61 break; |
62 #endif | |
63 #ifdef HAVE_VCD | |
64 case STREAMTYPE_VCD: | |
65 snprintf( tmp,tmplen,MSGTR_VCDTrack,guiIntfStruct.Track ); | |
66 break; | |
67 #endif | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
68 default: av_strlcpy( tmp,MSGTR_NoMediaOpened,tmplen ); |
23077 | 69 } |
70 if ( c ) | |
71 { | |
72 for ( i=0;i < (int)strlen( tmp );i++ ) | |
73 { | |
74 int t=0; | |
75 if ( c == 1 ) { if ( ( tmp[i] >= 'A' )&&( tmp[i] <= 'Z' ) ) t=32; } | |
76 if ( c == 2 ) { if ( ( tmp[i] >= 'a' )&&( tmp[i] <= 'z' ) ) t=-32; } | |
77 tmp[i]=(char)( tmp[i] + t ); | |
78 } | |
79 } | |
80 } | |
81 | |
82 /* Unsafe! Pass only null-terminated strings as (char *)str. */ | |
83 char * Translate( char * str ) | |
84 { | |
85 mixer_t *mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
86 static char trbuf[512]; | |
87 char tmp[512]; | |
88 int i,c; | |
89 int t; | |
90 int strsize = 0; | |
91 memset( trbuf,0,512 ); | |
92 memset( tmp,0,128 ); | |
93 strsize = strlen(str); | |
94 for ( c=0,i=0;i < strsize;i++ ) | |
95 { | |
96 if ( str[i] != '$' ) { trbuf[c++]=str[i]; trbuf[c]=0; } | |
97 else | |
98 { | |
99 switch ( str[++i] ) | |
100 { | |
101 case 't': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.Track ); | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
102 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 103 case 'o': TranslateFilename( 0,tmp,sizeof( tmp ) ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
104 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 105 case 'f': TranslateFilename( 1,tmp,sizeof( tmp ) ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
106 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 107 case 'F': TranslateFilename( 2,tmp,sizeof( tmp ) ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
108 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 109 case '6': t=guiIntfStruct.LengthInSec; goto calclengthhhmmss; |
110 case '1': t=guiIntfStruct.TimeSec; | |
111 calclengthhhmmss: | |
112 snprintf( tmp,sizeof( tmp ),"%02d:%02d:%02d",t/3600,t/60%60,t%60 ); | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
113 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); |
23077 | 114 break; |
115 case '7': t=guiIntfStruct.LengthInSec; goto calclengthmmmmss; | |
116 case '2': t=guiIntfStruct.TimeSec; | |
117 calclengthmmmmss: | |
118 snprintf( tmp,sizeof( tmp ),"%04d:%02d",t/60,t%60 ); | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
119 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); |
23077 | 120 break; |
121 case '3': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec / 3600 ); | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
122 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 123 case '4': snprintf( tmp,sizeof( tmp ),"%02d",( ( guiIntfStruct.TimeSec / 60 ) % 60 ) ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
124 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 125 case '5': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec % 60 ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
126 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
127 case '8': snprintf( tmp,sizeof( tmp ),"%01d:%02d:%02d",guiIntfStruct.TimeSec / 3600,( guiIntfStruct.TimeSec / 60 ) % 60,guiIntfStruct.TimeSec % 60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 128 case 'v': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Volume ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
129 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 130 case 'V': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Volume ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
131 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 132 case 'b': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Balance ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
133 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 134 case 'B': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Balance ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
135 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 136 case 'd': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.FrameDrop ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
137 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 138 case 'x': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieWidth ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
139 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 140 case 'y': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieHeight ); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
141 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
23077 | 142 case 'C': snprintf( tmp,sizeof( tmp ),"%s", guiIntfStruct.sh_video? ((sh_video_t *)guiIntfStruct.sh_video)->codec->name : ""); |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
143 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
144 case 's': if ( guiIntfStruct.Playing == 0 ) av_strlcat( trbuf,"s",sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
145 case 'l': if ( guiIntfStruct.Playing == 1 ) av_strlcat( trbuf,"p",sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
146 case 'e': if ( guiIntfStruct.Playing == 2 ) av_strlcat( trbuf,"e",sizeof( trbuf ) ); break; |
23077 | 147 case 'a': |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
148 if ( mixer->muted ) { av_strlcat( trbuf,"n",sizeof( trbuf ) ); break; } |
23077 | 149 switch ( guiIntfStruct.AudioType ) |
150 { | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
151 case 0: av_strlcat( trbuf,"n",sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
152 case 1: av_strlcat( trbuf,"m",sizeof( trbuf ) ); break; |
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
153 case 2: av_strlcat( trbuf,"t",sizeof( trbuf ) ); break; |
23077 | 154 } |
155 break; | |
156 case 'T': | |
157 switch ( guiIntfStruct.StreamType ) | |
158 { | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
159 case STREAMTYPE_FILE: av_strlcat( trbuf,"f",sizeof( trbuf ) ); break; |
23077 | 160 #ifdef HAVE_VCD |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
161 case STREAMTYPE_VCD: av_strlcat( trbuf,"v",sizeof( trbuf ) ); break; |
23077 | 162 #endif |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
163 case STREAMTYPE_STREAM: av_strlcat( trbuf,"u",sizeof( trbuf ) ); break; |
23077 | 164 #ifdef USE_DVDREAD |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
165 case STREAMTYPE_DVD: av_strlcat( trbuf,"d",sizeof( trbuf ) ); break; |
23077 | 166 #endif |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
167 default: av_strlcat( trbuf," ",sizeof( trbuf ) ); break; |
23077 | 168 } |
169 break; | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23374
diff
changeset
|
170 case '$': av_strlcat( trbuf,"$",sizeof( trbuf ) ); break; |
23077 | 171 default: continue; |
172 } | |
173 c=strlen( trbuf ); | |
174 } | |
175 } | |
176 return trbuf; | |
177 } | |
178 | |
179 static char * image_buffer = NULL; | |
180 static int image_width = 0; | |
181 | |
182 void PutImage( txSample * bf,int x,int y,int max,int ofs ) | |
183 { | |
184 int i=0,ix,iy; | |
185 uint32_t * buf = NULL; | |
186 uint32_t * drw = NULL; | |
187 register uint32_t tmp; | |
24236 | 188 /* register uint32_t yc; */ |
23077 | 189 |
190 if ( ( !bf )||( bf->Image == NULL ) ) return; | |
191 | |
192 i=( bf->Width * ( bf->Height / max ) ) * ofs; | |
193 buf=(uint32_t *)image_buffer; | |
194 drw=(uint32_t *)bf->Image; | |
195 | |
196 #if 1 | |
197 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) | |
198 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
199 { | |
200 tmp=drw[i++]; | |
201 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; | |
202 } | |
203 #else | |
204 yc=y * image_width; | |
205 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) | |
206 { | |
207 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
208 { | |
209 tmp=drw[i++]; | |
210 if ( tmp != 0x00ff00ff ) buf[yc + ix]=tmp; | |
211 } | |
212 yc+=image_width; | |
213 } | |
214 #endif | |
215 } | |
216 | |
217 void SimplePotmeterPutImage( txSample * bf,int x,int y,float frac ) | |
218 { | |
219 int i=0,w,r,ix,iy; | |
220 uint32_t * buf = NULL; | |
221 uint32_t * drw = NULL; | |
222 register uint32_t tmp; | |
223 | |
224 if ( ( !bf )||( bf->Image == NULL ) ) return; | |
225 | |
226 buf=(uint32_t *)image_buffer; | |
227 drw=(uint32_t *)bf->Image; | |
228 w=bf->Width*frac; | |
229 r=bf->Width-w; | |
230 for ( iy=y;iy < (int)(y+bf->Height);iy++ ) | |
231 { | |
232 for ( ix=x;ix < (int)(x+w);ix++ ) | |
233 { | |
234 tmp=drw[i++]; | |
235 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; | |
236 } | |
237 i+=r; | |
238 } | |
239 } | |
240 | |
241 void Render( wsTWindow * window,wItem * Items,int nrItems,char * db,int size ) | |
242 { | |
243 wItem * item; | |
244 txSample * image = NULL; | |
245 int i; | |
246 | |
247 image_buffer=db; | |
248 image_width=window->Width; | |
249 | |
250 for( i=0;i < nrItems + 1;i++ ) | |
251 { | |
252 item=&Items[i]; | |
253 switch( item->type ) | |
254 { | |
255 case itButton: | |
256 PutImage( &item->Bitmap,item->x,item->y,3,item->pressed ); | |
257 break; | |
258 case itPotmeter: | |
259 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); | |
260 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); | |
261 break; | |
262 case itHPotmeter: | |
263 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); | |
264 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); | |
265 PutImage( &item->Mask,item->x + (int)( ( item->width - item->psx ) * item->value / 100.0f ),item->y,3,item->pressed ); | |
266 break; | |
267 case itVPotmeter: | |
268 PutImage( &item->Bitmap, | |
269 item->x,item->y, | |
270 item->phases, | |
271 item->phases * ( 1. - item->value / 100.0f ) ); | |
272 PutImage( &item->Mask, | |
273 item->x,item->y + (int)( ( item->height - item->psy ) * ( 1. - item->value / 100.0f ) ), | |
274 3,item->pressed ); | |
275 break; | |
276 case itSLabel: | |
277 image=fntRender( item,0,"%s",item->label ); | |
278 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
279 case itDLabel: | |
280 { | |
281 char * t = Translate( item->label ); | |
282 int l = fntTextWidth( item->fontid,t ); | |
283 l=(l?l:item->width); | |
284 image=fntRender( item,l-(GetTimerMS() / 20)%l,"%s",t ); | |
285 } | |
286 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
287 break; | |
288 } | |
289 } | |
290 wsConvert( window,db,size ); | |
291 } |