Mercurial > mplayer.hg
annotate libmpdemux/demux_mf.c @ 23035:e8afcfccf359
Always deallocate glyphs. Fixes a memory leak.
author | eugeni |
---|---|
date | Sat, 21 Apr 2007 10:56:28 +0000 |
parents | bbc011e59732 |
children | 87ca3bce504a |
rev | line source |
---|---|
4550 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <unistd.h> | |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <unistd.h> | |
8 | |
9 #include "config.h" | |
10 #include "mp_msg.h" | |
11 #include "help_mp.h" | |
12 | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22083
diff
changeset
|
13 #include "stream/stream.h" |
4550 | 14 #include "demuxer.h" |
15 #include "stheader.h" | |
16 #include "mf.h" | |
17 | |
17636 | 18 static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
7407 | 19 mf_t * mf = (mf_t *)demuxer->priv; |
4565 | 20 sh_video_t * sh_video = demuxer->video->sh; |
19180 | 21 int newpos = (flags & 1)?0:mf->curr_frame - 1; |
4565 | 22 |
19180 | 23 if ( flags & 2 ) newpos+=rel_seek_secs*(mf->nr_of_files - 1); |
4565 | 24 else newpos+=rel_seek_secs * sh_video->fps; |
25 if ( newpos < 0 ) newpos=0; | |
19180 | 26 if( newpos >= mf->nr_of_files) newpos=mf->nr_of_files - 1; |
4565 | 27 mf->curr_frame=newpos; |
4550 | 28 } |
29 | |
30 // return value: | |
31 // 0 = EOF or no stream found | |
32 // 1 = successfully read a packet | |
16175 | 33 static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){ |
4550 | 34 mf_t * mf; |
35 struct stat fs; | |
36 FILE * f; | |
37 | |
7407 | 38 mf=(mf_t*)demuxer->priv; |
39 if ( mf->curr_frame >= mf->nr_of_files ) return 0; | |
4550 | 40 |
7407 | 41 stat( mf->names[mf->curr_frame],&fs ); |
42 // printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size ); | |
4550 | 43 |
9992 | 44 #ifdef WIN32 |
45 if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0; | |
46 #else | |
7407 | 47 if ( !( f=fopen( mf->names[mf->curr_frame],"r" ) ) ) return 0; |
9992 | 48 #endif |
4550 | 49 { |
50 sh_video_t * sh_video = demuxer->video->sh; | |
51 demux_packet_t * dp = new_demux_packet( fs.st_size ); | |
4565 | 52 if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0; |
7407 | 53 dp->pts=mf->curr_frame / sh_video->fps; |
54 dp->pos=mf->curr_frame; | |
4550 | 55 dp->flags=0; |
56 // append packet to DS stream: | |
57 ds_add_packet( demuxer->video,dp ); | |
58 } | |
59 fclose( f ); | |
60 | |
7407 | 61 mf->curr_frame++; |
4550 | 62 return 1; |
63 } | |
64 | |
16175 | 65 static demuxer_t* demux_open_mf(demuxer_t* demuxer){ |
4550 | 66 sh_video_t *sh_video = NULL; |
67 mf_t *mf = NULL; | |
7407 | 68 |
69 if(!demuxer->stream->url) return NULL; | |
22083
59982606e602
mf demuxer only works with mf:// urls, so check for that.
reimar
parents:
19794
diff
changeset
|
70 if(strncmp(demuxer->stream->url, "mf://", 5)) return NULL; |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
71 |
17624
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
72 |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
73 mf=open_mf(demuxer->stream->url + 5); |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
74 if(!mf) return NULL; |
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
75 |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
76 if(!mf_type){ |
17624
7b30bef00830
allow autodetection of pictures type when using mf://@file.list syntax
iive
parents:
17569
diff
changeset
|
77 char* p=strrchr(mf->names[0],'.'); |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
78 if(!p){ |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
79 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! (try -mf type=xxx)\n" ); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
80 free( mf ); return NULL; |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
81 } |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
82 mf_type=strdup(p+1); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
83 mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! trying 'type=%s'...\n", mf_type); |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
84 } |
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
85 |
7407 | 86 mf->curr_frame=0; |
4550 | 87 |
88 demuxer->movi_start = 0; | |
89 demuxer->movi_end = mf->nr_of_files - 1; | |
90 | |
91 // create a new video stream header | |
92 sh_video = new_sh_video(demuxer, 0); | |
93 // make sure the demuxer knows about the new video stream header | |
94 // (even though new_sh_video() ought to take care of it) | |
95 demuxer->video->sh = sh_video; | |
96 | |
97 // make sure that the video demuxer stream header knows about its | |
98 // parent video demuxer stream (this is getting wacky), or else | |
99 // video_read_properties() will choke | |
100 sh_video->ds = demuxer->video; | |
9148
946b14a9e743
type autodetection (from filemask/filelist extension)
arpi
parents:
7407
diff
changeset
|
101 |
4656 | 102 if ( !strcasecmp( mf_type,"jpg" ) || |
5029 | 103 !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('I', 'J', 'P', 'G'); |
7362 | 104 else |
4656 | 105 if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' ); |
7362 | 106 else |
107 if ( !strcasecmp( mf_type,"tga" )) sh_video->format = mmioFOURCC('M', 'T', 'G', 'A' ); | |
22903 | 108 else |
109 if ( !strcasecmp( mf_type,"bmp" )) sh_video->format = mmioFOURCC('b', 'm', 'p', ' ' ); | |
9534
87e03d96a4cd
add support for sgi files to mencoder patch by (Todd Kirby <slapcat at pacbell dot net>)
michael
parents:
9148
diff
changeset
|
110 else |
87e03d96a4cd
add support for sgi files to mencoder patch by (Todd Kirby <slapcat at pacbell dot net>)
michael
parents:
9148
diff
changeset
|
111 if (!strcasecmp( mf_type,"sgi" )) sh_video->format = mmioFOURCC('S', 'G', 'I', '1'); |
87e03d96a4cd
add support for sgi files to mencoder patch by (Todd Kirby <slapcat at pacbell dot net>)
michael
parents:
9148
diff
changeset
|
112 else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknown input file type.\n" ); free( mf ); return NULL; } |
4550 | 113 |
114 sh_video->disp_w = mf_w; | |
115 sh_video->disp_h = mf_h; | |
116 sh_video->fps = mf_fps; | |
117 sh_video->frametime = 1 / sh_video->fps; | |
118 | |
4556 | 119 // emulate BITMAPINFOHEADER: |
120 sh_video->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
121 memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER)); | |
122 sh_video->bih->biSize=40; | |
123 sh_video->bih->biWidth = mf_w; | |
124 sh_video->bih->biHeight = mf_h; | |
125 sh_video->bih->biPlanes=1; | |
126 sh_video->bih->biBitCount=24; | |
127 sh_video->bih->biCompression=sh_video->format; | |
128 sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3; | |
129 | |
4550 | 130 /* disable seeking */ |
4565 | 131 // demuxer->seekable = 0; |
4550 | 132 |
7407 | 133 demuxer->priv=(void*)mf; |
4550 | 134 |
135 return demuxer; | |
136 } | |
5810 | 137 |
16175 | 138 static void demux_close_mf(demuxer_t* demuxer) { |
7407 | 139 mf_t *mf = demuxer->priv; |
5810 | 140 |
7407 | 141 if(!mf) |
5810 | 142 return; |
7407 | 143 free(mf); |
5810 | 144 } |
16175 | 145 |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
146 static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg) { |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
147 mf_t *mf = (mf_t *)demuxer->priv; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
148 sh_video_t *sh_video = demuxer->video->sh; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
149 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
150 switch(cmd) { |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
151 case DEMUXER_CTRL_GET_TIME_LENGTH: |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
152 *((double *)arg) = (double)mf->nr_of_files / sh_video->fps; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
153 return DEMUXER_CTRL_OK; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
154 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
155 case DEMUXER_CTRL_GET_PERCENT_POS: |
19794
0951c3e8864b
Avoid division by zero DEMUXER_CTRL_GET_PERCENT_POS with only one frame by just
reimar
parents:
19220
diff
changeset
|
156 if (mf->nr_of_files <= 1) |
0951c3e8864b
Avoid division by zero DEMUXER_CTRL_GET_PERCENT_POS with only one frame by just
reimar
parents:
19220
diff
changeset
|
157 return DEMUXER_CTRL_DONTKNOW; |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
158 *((int *)arg) = 100 * mf->curr_frame / (mf->nr_of_files - 1); |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
159 return DEMUXER_CTRL_OK; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
160 |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
161 default: |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
162 return DEMUXER_CTRL_NOTIMPL; |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
163 } |
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
164 } |
16175 | 165 |
166 demuxer_desc_t demuxer_desc_mf = { | |
167 "mf demuxer", | |
168 "mf", | |
169 "MF", | |
170 "?", | |
171 "multiframe?, pictures demuxer", | |
172 DEMUXER_TYPE_MF, | |
173 0, // no autodetect | |
174 NULL, | |
175 demux_mf_fill_buffer, | |
176 demux_open_mf, | |
177 demux_close_mf, | |
178 demux_seek_mf, | |
19220
fbd2391fcbb8
Implement DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS,
reimar
parents:
19180
diff
changeset
|
179 demux_control_mf |
16175 | 180 }; |