annotate libmpdemux/demux_mf.c @ 5610:fd196de4f1e9

cleanup. cosmetics only, no functional changes
author arpi
date Sat, 13 Apr 2002 22:16:15 +0000
parents ef8a43b74075
children 8a357300d0ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
1
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
2 #include <stdio.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
3 #include <stdlib.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
4 #include <unistd.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
5 #include <sys/types.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
6 #include <sys/stat.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
7 #include <unistd.h>
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
8
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
9 #include "config.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
10 #include "mp_msg.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
11 #include "help_mp.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
12
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
13 #include "stream.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
14 #include "demuxer.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
15 #include "stheader.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
16 #include "mf.h"
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
17
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
18 typedef struct
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
19 {
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
20 int nr_of_frames;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
21 int curr_frame;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
22 } demuxer_mf_t;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
23
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
24 void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags){
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
25 demuxer_mf_t * mf = (demuxer_mf_t *)demuxer->priv;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
26 sh_video_t * sh_video = demuxer->video->sh;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
27 int newpos = (flags & 1)?0:mf->curr_frame;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
28
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
29 if ( flags & 2 ) newpos+=rel_seek_secs*mf->nr_of_frames;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
30 else newpos+=rel_seek_secs * sh_video->fps;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
31 if ( newpos < 0 ) newpos=0;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
32 if( newpos > mf->nr_of_frames) newpos=mf->nr_of_frames;
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
33 mf->curr_frame=newpos;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
34 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
35
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
36 // return value:
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
37 // 0 = EOF or no stream found
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
38 // 1 = successfully read a packet
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
39 int demux_mf_fill_buffer(demuxer_t *demuxer){
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
40 mf_t * mf;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
41 demuxer_mf_t * dmf;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
42 struct stat fs;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
43 FILE * f;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
44
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
45 dmf=(demuxer_mf_t*)demuxer->priv;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
46 if ( dmf->curr_frame >= dmf->nr_of_frames ) return 0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
47 mf=(mf_t*)demuxer->stream->priv;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
48
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
49 stat( mf->names[dmf->curr_frame],&fs );
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
50 // printf( "[demux_mf] frame: %d (%s,%d)\n",dmf->curr_frame,mf->names[dmf->curr_frame],fs.st_size );
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
51
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
52 if ( !( f=fopen( mf->names[dmf->curr_frame],"r" ) ) ) return 0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
53 {
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
54 sh_video_t * sh_video = demuxer->video->sh;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
55 demux_packet_t * dp = new_demux_packet( fs.st_size );
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
56 if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
57 dp->pts=dmf->curr_frame / sh_video->fps;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
58 dp->pos=dmf->curr_frame;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
59 dp->flags=0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
60 // append packet to DS stream:
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
61 ds_add_packet( demuxer->video,dp );
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
62 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
63 fclose( f );
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
64
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
65 dmf->curr_frame++;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
66 return 1;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
67 }
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
68
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
69 demuxer_t* demux_open_mf(demuxer_t* demuxer){
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
70 sh_video_t *sh_video = NULL;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
71 mf_t *mf = NULL;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
72 demuxer_mf_t *dmf = NULL;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
73
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
74 mf=(mf_t*)demuxer->stream->priv;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
75 dmf=calloc( 1,sizeof( demuxer_mf_t ) );
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
76
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
77 // go back to the beginning
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
78 stream_reset(demuxer->stream);
4656
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
79 // stream_seek(demuxer->stream, 0);
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
80 demuxer->movi_start = 0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
81 demuxer->movi_end = mf->nr_of_files - 1;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
82 dmf->nr_of_frames= mf->nr_of_files;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
83 dmf->curr_frame=0;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
84
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
85 // create a new video stream header
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
86 sh_video = new_sh_video(demuxer, 0);
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
87 // make sure the demuxer knows about the new video stream header
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
88 // (even though new_sh_video() ought to take care of it)
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
89 demuxer->video->sh = sh_video;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
90
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
91 // make sure that the video demuxer stream header knows about its
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
92 // parent video demuxer stream (this is getting wacky), or else
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
93 // video_read_properties() will choke
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
94 sh_video->ds = demuxer->video;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
95
4656
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
96 if ( !strcasecmp( mf_type,"jpg" ) ||
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents: 4656
diff changeset
97 !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('I', 'J', 'P', 'G');
4656
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
98 else
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
99 if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' );
04880518728d add initial mPNG support
pontscho
parents: 4643
diff changeset
100 else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( dmf ); return NULL; }
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
101
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
102 sh_video->disp_w = mf_w;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
103 sh_video->disp_h = mf_h;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
104 sh_video->fps = mf_fps;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
105 sh_video->frametime = 1 / sh_video->fps;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
106
4556
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
107 // emulate BITMAPINFOHEADER:
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
108 sh_video->bih=malloc(sizeof(BITMAPINFOHEADER));
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
109 memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER));
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
110 sh_video->bih->biSize=40;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
111 sh_video->bih->biWidth = mf_w;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
112 sh_video->bih->biHeight = mf_h;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
113 sh_video->bih->biPlanes=1;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
114 sh_video->bih->biBitCount=24;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
115 sh_video->bih->biCompression=sh_video->format;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
116 sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3;
90a535d87e7b emulating BITMAPINFOHDR (for win32 codecs)
arpi
parents: 4550
diff changeset
117
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
118 /* disable seeking */
4565
be1562b2c2d0 finalize mfi support.
pontscho
parents: 4556
diff changeset
119 // demuxer->seekable = 0;
4550
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
120
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
121 demuxer->priv=(void*)dmf;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
122
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
123 return demuxer;
ff9f62e4bdd8 add mfi demuxer
pontscho
parents:
diff changeset
124 }