9065
|
1
|
|
2 #include "config.h"
|
|
3
|
|
4 #include <stdlib.h>
|
|
5 #include <stdio.h>
|
|
6 #include <unistd.h>
|
|
7 #include <string.h>
|
|
8
|
|
9 #include "../cfgparser.h"
|
|
10
|
|
11 #include "stream.h"
|
|
12 #include "demuxer.h"
|
|
13 #include "stheader.h"
|
|
14
|
|
15 #include "../libmpcodecs/img_format.h"
|
|
16
|
|
17 int use_rawvideo = 0;
|
|
18 static int format = IMGFMT_I420;
|
|
19 static int size_id = 0;
|
|
20 static int width = 0;
|
|
21 static int height = 0;
|
|
22 static float fps = 25;
|
|
23 static int imgsize=0;
|
|
24
|
|
25 config_t demux_rawvideo_opts[] = {
|
|
26 { "on", &use_rawvideo, CONF_TYPE_FLAG, 0,0, 1, NULL },
|
|
27 // size:
|
|
28 { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
|
|
29 { "h", &height, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
|
|
30 { "sqcif", &size_id, CONF_TYPE_FLAG,0,0,1, NULL },
|
|
31 { "qcif", &size_id, CONF_TYPE_FLAG,0,0,2, NULL },
|
|
32 { "cif", &size_id, CONF_TYPE_FLAG,0,0,3, NULL },
|
|
33 { "4cif", &size_id, CONF_TYPE_FLAG,0,0,4, NULL },
|
|
34 { "pal", &size_id, CONF_TYPE_FLAG,0,0,5, NULL },
|
|
35 { "ntsc", &size_id, CONF_TYPE_FLAG,0,0,6, NULL },
|
9068
|
36 { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL },
|
|
37 { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL },
|
9065
|
38 // format:
|
|
39 { "format", &format, CONF_TYPE_INT, 0, 0 , 0, NULL },
|
|
40 { "y420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL },
|
|
41 { "yv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YV12, NULL },
|
|
42 { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL },
|
9068
|
43 { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL },
|
9065
|
44 { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL },
|
|
45 // misc:
|
|
46 { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL },
|
|
47 { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL },
|
|
48
|
|
49 {NULL, NULL, 0, 0, 0, 0, NULL}
|
|
50 };
|
|
51
|
|
52
|
|
53 int demux_rawvideo_open(demuxer_t* demuxer) {
|
|
54 sh_video_t* sh_video;
|
|
55
|
|
56 switch(size_id){
|
|
57 case 1: width=128; height=96; break;
|
|
58 case 2: width=176; height=144; break;
|
|
59 case 3: width=352; height=288; break;
|
|
60 case 4: width=704; height=576; break;
|
|
61 case 5: width=720; height=576; break;
|
|
62 case 6: width=720; height=480; break;
|
9068
|
63 case 7: width=1408;height=1152;break;
|
|
64 case 8: width=352; height=240; break;
|
9065
|
65 }
|
|
66 if(!width || !height){
|
|
67 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: width or height not specified!\n");
|
|
68 return 0;
|
|
69 }
|
9068
|
70
|
9065
|
71 if(!imgsize)
|
|
72 switch(format){
|
|
73 case IMGFMT_I420:
|
|
74 case IMGFMT_IYUV:
|
|
75 case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break;
|
|
76 case IMGFMT_YUY2: imgsize=width*height*2;break;
|
9068
|
77 case IMGFMT_UYVY: imgsize=width*height*2;break;
|
9065
|
78 case IMGFMT_Y8: imgsize=width*height;break;
|
|
79 default:
|
|
80 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n");
|
|
81 return 0;
|
|
82 }
|
|
83
|
|
84 sh_video = new_sh_video(demuxer,0);
|
|
85 sh_video->format=format;
|
|
86 sh_video->fps=fps;
|
|
87 sh_video->frametime=1.0/fps;
|
|
88 sh_video->disp_w=width;
|
|
89 sh_video->disp_h=height;
|
|
90 sh_video->i_bps=fps*imgsize;
|
|
91
|
|
92 demuxer->movi_start = demuxer->stream->start_pos;
|
|
93 demuxer->movi_end = demuxer->stream->end_pos;
|
|
94
|
|
95 demuxer->video->sh = sh_video;
|
|
96 sh_video->ds = demuxer->video;
|
|
97
|
|
98 return 1;
|
|
99 }
|
|
100
|
|
101 int demux_rawvideo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
|
|
102
|
|
103 if(demuxer->stream->eof) return 0;
|
|
104 if(ds!=demuxer->video) return 0;
|
|
105
|
|
106 ds_read_packet(ds,demuxer->stream,imgsize,0,stream_tell(demuxer->stream),0x10);
|
|
107
|
|
108 return 1;
|
|
109 }
|
|
110
|
|
111 void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
|
|
112 stream_t* s = demuxer->stream;
|
|
113 sh_video_t* sh_video = demuxer->video->sh;
|
|
114 off_t pos;
|
|
115
|
|
116 pos = (flags & 1) ? demuxer->movi_start : stream_tell(s);
|
|
117 if(flags & 2)
|
|
118 pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
|
|
119 else
|
|
120 pos += (rel_seek_secs*sh_video->i_bps);
|
|
121
|
|
122 pos/=imgsize;
|
|
123 stream_seek(s,pos*imgsize);
|
|
124 sh_video->timer=pos * sh_video->frametime;
|
|
125 // printf("demux_rawvideo: streamtell=%d\n",(int)stream_tell(demuxer->stream));
|
|
126 }
|