Mercurial > mplayer.hg
annotate libmpdemux/demux_rawvideo.c @ 17450:ac1ecfe54dcf
synced with 1.1208
author | gpoirier |
---|---|
date | Sat, 21 Jan 2006 19:39:12 +0000 |
parents | fde45c312c31 |
children | b849a99cdc3c |
rev | line source |
---|---|
9065 | 1 |
2 #include "config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <unistd.h> | |
7 #include <string.h> | |
8 | |
17012 | 9 #include "m_option.h" |
9065 | 10 |
11 #include "stream.h" | |
12 #include "demuxer.h" | |
13 #include "stheader.h" | |
14 | |
17012 | 15 #include "libmpcodecs/img_format.h" |
9065 | 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 | 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 | |
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[] = { |
9065 | 26 // size: |
27 { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL }, | |
28 { "h", &height, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL }, | |
29 { "sqcif", &size_id, CONF_TYPE_FLAG,0,0,1, NULL }, | |
30 { "qcif", &size_id, CONF_TYPE_FLAG,0,0,2, NULL }, | |
31 { "cif", &size_id, CONF_TYPE_FLAG,0,0,3, NULL }, | |
32 { "4cif", &size_id, CONF_TYPE_FLAG,0,0,4, NULL }, | |
33 { "pal", &size_id, CONF_TYPE_FLAG,0,0,5, NULL }, | |
34 { "ntsc", &size_id, CONF_TYPE_FLAG,0,0,6, NULL }, | |
9068 | 35 { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL }, |
36 { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL }, | |
9065 | 37 // format: |
10599 | 38 { "format", &format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL }, |
39 // below options are obsolete | |
14166 | 40 { "i420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL }, |
9065 | 41 { "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
|
42 { "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
|
43 { "hm12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_HM12, NULL }, |
9065 | 44 { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL }, |
9068 | 45 { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL }, |
9065 | 46 { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL }, |
47 // misc: | |
48 { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL }, | |
49 { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL }, | |
50 | |
51 {NULL, NULL, 0, 0, 0, 0, NULL} | |
52 }; | |
53 | |
54 | |
16175 | 55 static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { |
9065 | 56 sh_video_t* sh_video; |
57 | |
58 switch(size_id){ | |
59 case 1: width=128; height=96; break; | |
60 case 2: width=176; height=144; break; | |
61 case 3: width=352; height=288; break; | |
62 case 4: width=704; height=576; break; | |
63 case 5: width=720; height=576; break; | |
64 case 6: width=720; height=480; break; | |
9068 | 65 case 7: width=1408;height=1152;break; |
66 case 8: width=352; height=240; break; | |
9065 | 67 } |
68 if(!width || !height){ | |
69 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: width or height not specified!\n"); | |
70 return 0; | |
71 } | |
9068 | 72 |
9065 | 73 if(!imgsize) |
74 switch(format){ | |
75 case IMGFMT_I420: | |
76 case IMGFMT_IYUV: | |
10305
3e40b8f879c8
HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents:
9708
diff
changeset
|
77 case IMGFMT_NV12: |
3e40b8f879c8
HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents:
9708
diff
changeset
|
78 case IMGFMT_HM12: |
9065 | 79 case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break; |
80 case IMGFMT_YUY2: imgsize=width*height*2;break; | |
9068 | 81 case IMGFMT_UYVY: imgsize=width*height*2;break; |
9065 | 82 case IMGFMT_Y8: imgsize=width*height;break; |
83 default: | |
17219 | 84 if (IMGFMT_IS_RGB(format)) |
85 imgsize = width * height * ((IMGFMT_RGB_DEPTH(format) + 7) >> 3); | |
86 else if (IMGFMT_IS_BGR(format)) | |
87 imgsize = width * height * ((IMGFMT_BGR_DEPTH(format) + 7) >> 3); | |
88 else { | |
9065 | 89 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n"); |
90 return 0; | |
17219 | 91 } |
9065 | 92 } |
93 | |
94 sh_video = new_sh_video(demuxer,0); | |
95 sh_video->format=format; | |
96 sh_video->fps=fps; | |
97 sh_video->frametime=1.0/fps; | |
98 sh_video->disp_w=width; | |
99 sh_video->disp_h=height; | |
100 sh_video->i_bps=fps*imgsize; | |
101 | |
102 demuxer->movi_start = demuxer->stream->start_pos; | |
103 demuxer->movi_end = demuxer->stream->end_pos; | |
104 | |
105 demuxer->video->sh = sh_video; | |
106 sh_video->ds = demuxer->video; | |
107 | |
16175 | 108 return demuxer; |
9065 | 109 } |
110 | |
16175 | 111 static 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
|
112 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
|
113 off_t pos; |
9065 | 114 if(demuxer->stream->eof) return 0; |
115 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
|
116 pos = stream_tell(demuxer->stream); |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
117 ds_read_packet(ds,demuxer->stream,imgsize,(pos/imgsize)*sh->frametime,pos,0x10); |
9065 | 118 return 1; |
119 } | |
120 | |
16175 | 121 static void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
9065 | 122 stream_t* s = demuxer->stream; |
123 sh_video_t* sh_video = demuxer->video->sh; | |
124 off_t pos; | |
125 | |
126 pos = (flags & 1) ? demuxer->movi_start : stream_tell(s); | |
127 if(flags & 2) | |
128 pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
129 else | |
130 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
|
131 if(pos < 0) pos = 0; |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
132 if(demuxer->movi_end && pos > demuxer->movi_end) pos = (demuxer->movi_end-imgsize); |
9065 | 133 pos/=imgsize; |
134 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
|
135 //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
|
136 demuxer->video->pts = pos * sh_video->frametime; |
9065 | 137 // printf("demux_rawvideo: streamtell=%d\n",(int)stream_tell(demuxer->stream)); |
138 } | |
16175 | 139 |
140 | |
141 demuxer_desc_t demuxer_desc_rawvideo = { | |
142 "Raw video demuxer", | |
143 "rawvideo", | |
144 "rawvideo", | |
145 "?", | |
146 "", | |
147 DEMUXER_TYPE_RAWVIDEO, | |
148 0, // no autodetect | |
149 NULL, | |
150 demux_rawvideo_fill_buffer, | |
151 demux_rawvideo_open, | |
152 NULL, | |
153 demux_rawvideo_seek, | |
154 NULL | |
155 }; |