annotate libmpdemux/demux_rawvideo.c @ 11441:fef5c880a61c

seek in realmedia files
author luran
date Wed, 12 Nov 2003 10:27:16 +0000
parents 822b1fa6db25
children c7822e66c36f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
1
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
2 #include "config.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
3
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
4 #include <stdlib.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
5 #include <stdio.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
6 #include <unistd.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
7 #include <string.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
8
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
9 #include "../m_option.h"
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
10
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
11 #include "stream.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
12 #include "demuxer.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
13 #include "stheader.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
14
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
15 #include "../libmpcodecs/img_format.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
16
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
17 extern int demuxer_type;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
18 static int format = IMGFMT_I420;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
19 static int size_id = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
20 static int width = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
21 static int height = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
22 static float fps = 25;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
23 static int imgsize=0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
24
10594
57bdcdb061d7 Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents: 10305
diff changeset
25 m_option_t demux_rawvideo_opts[] = {
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
26 { "on", &demuxer_type, CONF_TYPE_FLAG, 0,0, DEMUXER_TYPE_RAWVIDEO, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
27 // size:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
28 { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
29 { "h", &height, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
30 { "sqcif", &size_id, CONF_TYPE_FLAG,0,0,1, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
31 { "qcif", &size_id, CONF_TYPE_FLAG,0,0,2, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
32 { "cif", &size_id, CONF_TYPE_FLAG,0,0,3, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
33 { "4cif", &size_id, CONF_TYPE_FLAG,0,0,4, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
34 { "pal", &size_id, CONF_TYPE_FLAG,0,0,5, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
35 { "ntsc", &size_id, CONF_TYPE_FLAG,0,0,6, NULL },
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
36 { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL },
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
37 { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
38 // format:
10599
822b1fa6db25 using CONF_TYPE_IMGFMT
alex
parents: 10594
diff changeset
39 { "format", &format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL },
822b1fa6db25 using CONF_TYPE_IMGFMT
alex
parents: 10594
diff changeset
40 // below options are obsolete
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
41 { "y420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
42 { "yv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YV12, NULL },
10305
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
43 { "nv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_NV12, NULL },
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
44 { "hm12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_HM12, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
45 { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL },
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
46 { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
47 { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
48 // misc:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
49 { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
50 { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
51
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
52 {NULL, NULL, 0, 0, 0, 0, NULL}
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
53 };
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
54
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
55
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
56 int demux_rawvideo_open(demuxer_t* demuxer) {
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
57 sh_video_t* sh_video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
58
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
59 switch(size_id){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
60 case 1: width=128; height=96; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
61 case 2: width=176; height=144; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
62 case 3: width=352; height=288; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
63 case 4: width=704; height=576; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
64 case 5: width=720; height=576; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
65 case 6: width=720; height=480; break;
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
66 case 7: width=1408;height=1152;break;
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
67 case 8: width=352; height=240; break;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
68 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
69 if(!width || !height){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
70 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: width or height not specified!\n");
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
71 return 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
72 }
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
73
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
74 if(!imgsize)
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
75 switch(format){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
76 case IMGFMT_I420:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
77 case IMGFMT_IYUV:
10305
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
78 case IMGFMT_NV12:
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
79 case IMGFMT_HM12:
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
80 case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
81 case IMGFMT_YUY2: imgsize=width*height*2;break;
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
82 case IMGFMT_UYVY: imgsize=width*height*2;break;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
83 case IMGFMT_Y8: imgsize=width*height;break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
84 default:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
85 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n");
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
86 return 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
87 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
88
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
89 sh_video = new_sh_video(demuxer,0);
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
90 sh_video->format=format;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
91 sh_video->fps=fps;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
92 sh_video->frametime=1.0/fps;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
93 sh_video->disp_w=width;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
94 sh_video->disp_h=height;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
95 sh_video->i_bps=fps*imgsize;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
96
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
97 demuxer->movi_start = demuxer->stream->start_pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
98 demuxer->movi_end = demuxer->stream->end_pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
99
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
100 demuxer->video->sh = sh_video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
101 sh_video->ds = demuxer->video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
102
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
103 return 1;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
104 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
105
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
106 int demux_rawvideo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
107 sh_video_t* sh = demuxer->video->sh;
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
108 off_t pos;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
109 if(demuxer->stream->eof) return 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
110 if(ds!=demuxer->video) return 0;
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
111 pos = stream_tell(demuxer->stream);
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
112 ds_read_packet(ds,demuxer->stream,imgsize,(pos/imgsize)*sh->frametime,pos,0x10);
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
113 return 1;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
114 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
115
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
116 void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
117 stream_t* s = demuxer->stream;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
118 sh_video_t* sh_video = demuxer->video->sh;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
119 off_t pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
120
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
121 pos = (flags & 1) ? demuxer->movi_start : stream_tell(s);
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
122 if(flags & 2)
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
123 pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
124 else
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
125 pos += (rel_seek_secs*sh_video->i_bps);
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
126 if(pos < 0) pos = 0;
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
127 if(demuxer->movi_end && pos > demuxer->movi_end) pos = (demuxer->movi_end-imgsize);
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
128 pos/=imgsize;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
129 stream_seek(s,pos*imgsize);
9708
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
130 //sh_video->timer=pos * sh_video->frametime;
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
131 demuxer->video->pts = pos * sh_video->frametime;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
132 // printf("demux_rawvideo: streamtell=%d\n",(int)stream_tell(demuxer->stream));
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
133 }