Mercurial > mplayer.hg
annotate libvo/vo_odivx.c @ 4713:ad8b41562877
use mem2agpcpy_pic()
author | michael |
---|---|
date | Fri, 15 Feb 2002 01:00:26 +0000 |
parents | c35d7ce151b3 |
children | 32e1f5042f65 |
rev | line source |
---|---|
1 | 1 /* |
2 * OpenDivX AVI file writer | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 | |
9 #include "config.h" | |
10 #include "video_out.h" | |
11 #include "video_out_internal.h" | |
12 | |
13 LIBVO_EXTERN(odivx) | |
14 | |
15 #include <sys/ioctl.h> | |
16 #include <unistd.h> | |
17 #include <fcntl.h> | |
18 #include <sys/mman.h> | |
19 | |
20 #include "../encore/encore.h" | |
21 | |
354 | 22 #include "fastmemcpy.h" |
350 | 23 |
1 | 24 static vo_info_t vo_info = |
25 { | |
26 "OpenDivX AVI File writer", | |
27 "odivx", | |
28 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
29 "" | |
30 }; | |
31 | |
32 static uint8_t *image=NULL; | |
33 static int image_width=0; | |
34 static int image_height=0; | |
35 static unsigned int image_format=0; | |
36 static char *buffer=NULL; | |
37 static int frameno=0; | |
38 | |
39 extern char* encode_name; | |
40 extern char* encode_index_name; | |
41 | |
42 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num) | |
43 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
44 { | |
45 uint8_t *s; | |
46 uint8_t *d; | |
47 int i; | |
48 int dstride=image_width; | |
49 | |
50 // copy Y | |
51 d=image+dstride*y+x; | |
52 s=src[0]; | |
53 for(i=0;i<h;i++){ | |
54 memcpy(d,s,w); | |
55 s+=stride[0]; | |
56 d+=dstride; | |
57 } | |
58 | |
59 w/=2;h/=2;x/=2;y/=2; dstride/=2; | |
60 | |
61 // copy U | |
62 d=image+image_width*image_height + dstride*y+x; | |
63 s=src[1]; | |
64 for(i=0;i<h;i++){ | |
65 memcpy(d,s,w); | |
66 s+=stride[1]; | |
67 d+=dstride; | |
68 } | |
69 | |
70 // copy V | |
71 d=image+image_width*image_height +image_width*image_height/4 + dstride*y+x; | |
72 s=src[2]; | |
73 for(i=0;i<h;i++){ | |
74 memcpy(d,s,w); | |
75 s+=stride[2]; | |
76 d+=dstride; | |
77 } | |
78 | |
79 return 0; | |
80 } | |
81 | |
82 static uint32_t | |
83 draw_frame(uint8_t *src[]) | |
84 { | |
85 uint8_t *d=image; | |
86 | |
87 switch(image_format){ | |
88 case IMGFMT_YV12: | |
89 // copy Y | |
90 memcpy(d,src[0],image_width*image_height); | |
91 // copy U | |
92 d+=image_width*image_height; | |
93 memcpy(d,src[1],image_width*image_height/4); | |
94 // copy V | |
95 d+=image_width*image_height/4; | |
96 memcpy(d,src[2],image_width*image_height/4); | |
97 break; | |
80 | 98 case IMGFMT_YUY2: { |
99 uint8_t *dY=image; | |
100 uint8_t *dU=image+image_width*image_height; | |
101 uint8_t *dV=dU+image_width*image_height/4; | |
102 uint8_t *s=src[0]; | |
103 int y; | |
104 for(y=0;y<image_height;y+=2){ | |
105 uint8_t *e=s+image_width*2; | |
106 while(s<e){ | |
107 *dY++=s[0]; | |
108 *dU++=s[1]; | |
109 *dY++=s[2]; | |
110 *dV++=s[3]; | |
111 s+=4; | |
112 } | |
113 e=s+image_width*2; | |
114 while(s<e){ | |
115 *dY++=s[0]; | |
116 *dY++=s[2]; | |
117 s+=4; | |
118 } | |
119 } | |
120 | |
121 // case IMGFMT_BGR|24: | |
122 // memcpy(d,src[0],image_width*image_height*2); | |
1 | 123 break; |
124 } | |
80 | 125 } |
1 | 126 |
127 return 0; | |
128 } | |
129 | |
130 typedef unsigned int DWORD; | |
131 | |
132 typedef struct | |
133 { | |
134 DWORD ckid; | |
135 DWORD dwFlags; | |
136 DWORD dwChunkOffset; // Position of chunk | |
137 DWORD dwChunkLength; // Length of chunk | |
138 } AVIINDEXENTRY; | |
139 | |
1502 | 140 static void draw_osd(void) |
141 { | |
142 } | |
143 | |
1 | 144 static void |
145 flip_page(void) | |
146 { | |
147 | |
148 // we are rady to encode this frame | |
149 ENC_FRAME enc_frame; | |
150 ENC_RESULT enc_result; | |
151 | |
152 if(++frameno<10) return; | |
153 | |
80 | 154 enc_frame.image=image; |
1 | 155 enc_frame.bitstream=buffer; |
156 enc_frame.length=0; | |
157 encore(0x123,0,&enc_frame,&enc_result); | |
158 | |
612 | 159 printf("coded length: %ld \n",enc_frame.length); |
1 | 160 |
161 if(encode_name){ | |
162 AVIINDEXENTRY i; | |
163 FILE *file; | |
164 i.ckid=('c'<<24)|('d'<<16)|('0'<<8)|'0'; // "00dc" | |
165 i.dwFlags=enc_result.isKeyFrame?0x10:0; | |
166 i.dwChunkLength=enc_frame.length; | |
167 // Write AVI chunk: | |
168 if((file=fopen(encode_name,"ab"))){ | |
169 unsigned char zerobyte=0; | |
170 i.dwChunkOffset=ftell(file); | |
171 fwrite(&i.ckid,4,1,file); | |
172 fwrite(&enc_frame.length,4,1,file); | |
173 fwrite(buffer,enc_frame.length,1,file); | |
174 if(enc_frame.length&1) fwrite(&zerobyte,1,1,file); // padding | |
175 fclose(file); | |
176 } | |
177 // Write AVI index: | |
178 if(encode_index_name && (file=fopen(encode_index_name,"ab"))){ | |
179 fwrite(&i,sizeof(i),1,file); | |
180 fclose(file); | |
181 } | |
182 } | |
183 | |
184 | |
185 } | |
186 | |
187 static uint32_t | |
188 query_format(uint32_t format) | |
189 { | |
190 switch(format){ | |
191 case IMGFMT_YV12: | |
80 | 192 case IMGFMT_YUY2: |
193 // case IMGFMT_BGR|24: | |
1 | 194 return 1; |
195 } | |
196 return 0; | |
197 } | |
198 | |
199 extern int encode_bitrate; | |
200 | |
201 static uint32_t | |
4433 | 202 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info) |
1 | 203 { |
204 uint32_t frame_size; | |
205 ENC_PARAM enc_param; | |
206 | |
207 // file = fopen("encoded.odvx","wb"); | |
208 // if(!file) return -1; | |
209 | |
210 switch(format){ | |
211 case IMGFMT_YV12: | |
212 frame_size=width*height+width*height/2; | |
80 | 213 // enc_param.flip=2; // 0=RGB 1=flippedRGB 2=planarYUV format |
1 | 214 break; |
80 | 215 case IMGFMT_YUY2: |
216 // case IMGFMT_BGR|24: | |
217 // enc_param.flip=0; // 0=RGB 1=flippedRGB 2=planarYUV format | |
218 // frame_size=width*height*2; | |
219 frame_size=width*height+width*height/2; | |
1 | 220 break; |
221 default: return -1; // invalid format | |
222 } | |
223 | |
224 enc_param.x_dim=width; | |
225 enc_param.y_dim=height; | |
226 | |
227 image_width=width; | |
228 image_height=height; | |
229 image_format=format; | |
230 image=malloc(frame_size); | |
231 | |
232 //clear the buffer | |
233 memset(image,0x80,frame_size); | |
234 | |
235 // buffer for encoded video data: | |
236 buffer=malloc(0x100000); | |
237 if(!buffer) return -1; | |
238 | |
239 // encoding parameters: | |
240 enc_param.framerate=25.0; | |
241 enc_param.bitrate=encode_bitrate?encode_bitrate:780000; | |
242 enc_param.rc_period=300; | |
243 enc_param.max_quantizer=15; | |
244 enc_param.min_quantizer=1; | |
245 enc_param.search_range=128; | |
246 | |
247 // init codec: | |
248 encore(0x123,ENC_OPT_INIT,&enc_param,NULL); | |
249 | |
250 return 0; | |
251 } | |
252 | |
253 static const vo_info_t* | |
254 get_info(void) | |
255 { | |
256 return &vo_info; | |
257 } | |
258 | |
259 static void | |
260 uninit(void) | |
261 { | |
262 } | |
263 | |
31 | 264 static void check_events(void) |
265 { | |
266 } | |
267 | |
4352 | 268 static uint32_t preinit(const char *arg) |
269 { | |
270 return 0; | |
271 } | |
31 | 272 |
4596 | 273 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 274 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
275 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
276 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
277 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
278 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
279 return VO_NOTIMPL; |
4352 | 280 } |