annotate libmpdemux/demux_rawvideo.c @ 31311:9ce59b78dbfd

Remove mp_msg related GUI hacks.
author reimar
date Sun, 13 Jun 2010 11:17:26 +0000
parents d643e4643313
children a93891202051
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
2 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
5 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
7 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
12 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
14 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26378
diff changeset
17 */
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
18
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
19 #include "config.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
20
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
21 #include <stdlib.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
22 #include <stdio.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
23 #include <unistd.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
24 #include <string.h>
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
25
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16598
diff changeset
26 #include "m_option.h"
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
27
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 17636
diff changeset
28 #include "stream/stream.h"
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
29 #include "demuxer.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
30 #include "stheader.h"
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
31
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16598
diff changeset
32 #include "libmpcodecs/img_format.h"
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
33
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
34 static int format = IMGFMT_I420;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
35 static int size_id = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
36 static int width = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
37 static int height = 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
38 static float fps = 25;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
39 static int imgsize=0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
40
25241
bb7c65f2a289 Make m_option_t arrays referenced by cfg-common.h const
reimar
parents: 25193
diff changeset
41 const m_option_t demux_rawvideo_opts[] = {
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
42 // size:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
43 { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
44 { "h", &height, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
45 { "sqcif", &size_id, CONF_TYPE_FLAG,0,0,1, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
46 { "qcif", &size_id, CONF_TYPE_FLAG,0,0,2, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
47 { "cif", &size_id, CONF_TYPE_FLAG,0,0,3, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
48 { "4cif", &size_id, CONF_TYPE_FLAG,0,0,4, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
49 { "pal", &size_id, CONF_TYPE_FLAG,0,0,5, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
50 { "ntsc", &size_id, CONF_TYPE_FLAG,0,0,6, NULL },
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
51 { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL },
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
52 { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
53 // format:
10599
822b1fa6db25 using CONF_TYPE_IMGFMT
alex
parents: 10594
diff changeset
54 { "format", &format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL },
822b1fa6db25 using CONF_TYPE_IMGFMT
alex
parents: 10594
diff changeset
55 // below options are obsolete
14166
c7822e66c36f y420 vs i420 typo
diego
parents: 10599
diff changeset
56 { "i420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
57 { "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
58 { "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
59 { "hm12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_HM12, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
60 { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL },
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
61 { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL },
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
62 { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
63 // misc:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
64 { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
65 { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL },
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
66
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
67 {NULL, NULL, 0, 0, 0, 0, NULL}
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
68 };
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
69
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
70
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
71 static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) {
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
72 sh_video_t* sh_video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
73
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
74 switch(size_id){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
75 case 1: width=128; height=96; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
76 case 2: width=176; height=144; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
77 case 3: width=352; height=288; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
78 case 4: width=704; height=576; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
79 case 5: width=720; height=576; break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
80 case 6: width=720; height=480; break;
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
81 case 7: width=1408;height=1152;break;
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
82 case 8: width=352; height=240; break;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
83 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
84 if(!width || !height){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
85 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: width or height not specified!\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 }
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
88
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
89 if(!imgsize)
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
90 switch(format){
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
91 case IMGFMT_I420:
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
92 case IMGFMT_IYUV:
10305
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
93 case IMGFMT_NV12:
3e40b8f879c8 HM12 & NV12 "decoder" (specially interleaved YUV formats, used by Hauppauge's PVR cards)
arpi
parents: 9708
diff changeset
94 case IMGFMT_HM12:
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
95 case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break;
25193
55783f005bf3 simplify
michael
parents: 24740
diff changeset
96 case IMGFMT_YUY2:
9068
8f1659a47aa4 16cif,sif,uyvy
michael
parents: 9065
diff changeset
97 case IMGFMT_UYVY: imgsize=width*height*2;break;
24740
caae775a1619 support Y800 in raw video
diego
parents: 22605
diff changeset
98 case IMGFMT_Y800:
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
99 case IMGFMT_Y8: imgsize=width*height;break;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
100 default:
17219
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
101 if (IMGFMT_IS_RGB(format))
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
102 imgsize = width * height * ((IMGFMT_RGB_DEPTH(format) + 7) >> 3);
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
103 else if (IMGFMT_IS_BGR(format))
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
104 imgsize = width * height * ((IMGFMT_BGR_DEPTH(format) + 7) >> 3);
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
105 else {
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
106 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
107 return 0;
17219
fde45c312c31 calculate framesize for raw RGB and BGR.
reimar
parents: 17012
diff changeset
108 }
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
109 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
110
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
111 sh_video = new_sh_video(demuxer,0);
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
112 sh_video->format=format;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
113 sh_video->fps=fps;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
114 sh_video->frametime=1.0/fps;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
115 sh_video->disp_w=width;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
116 sh_video->disp_h=height;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
117 sh_video->i_bps=fps*imgsize;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
118
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
119 demuxer->movi_start = demuxer->stream->start_pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
120 demuxer->movi_end = demuxer->stream->end_pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
121
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
122 demuxer->video->sh = sh_video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
123 sh_video->ds = demuxer->video;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
124
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
125 return demuxer;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
126 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
127
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
128 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
129 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
130 off_t pos;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
131 if(demuxer->stream->eof) return 0;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
132 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
133 pos = stream_tell(demuxer->stream);
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
134 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
135 return 1;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
136 }
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
137
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17219
diff changeset
138 static void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
139 stream_t* s = demuxer->stream;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
140 sh_video_t* sh_video = demuxer->video->sh;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
141 off_t pos;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
142
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
143 pos = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
144 if(flags & SEEK_FACTOR)
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
145 pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
146 else
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
147 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
148 if(pos < 0) pos = 0;
a37708f0b574 on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents: 9068
diff changeset
149 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
150 pos/=imgsize;
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
151 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
152 //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
153 demuxer->video->pts = pos * sh_video->frametime;
9065
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
154 // printf("demux_rawvideo: streamtell=%d\n",(int)stream_tell(demuxer->stream));
59805b2d220a raw video demuxer, requested by Michael
arpi
parents:
diff changeset
155 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
156
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
157
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25241
diff changeset
158 const demuxer_desc_t demuxer_desc_rawvideo = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
159 "Raw video demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
160 "rawvideo",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
161 "rawvideo",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
162 "?",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
163 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
164 DEMUXER_TYPE_RAWVIDEO,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
165 0, // no autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
166 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
167 demux_rawvideo_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
168 demux_rawvideo_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
169 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
170 demux_rawvideo_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
171 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 14166
diff changeset
172 };