annotate libvo/Attic/SHIT/video_out_odivx.c.OLD @ 68:001286db4e90

IRQ handler disabled, vcount-based vsync
author arpi_esp
date Sat, 10 Mar 2001 02:27:50 +0000
parents 3b5f5d1c5041
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * OpenDivX AVI file writer
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include "video_out.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include "video_out_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 LIBVO_EXTERN(odivx)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <sys/mman.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include "../encore/encore.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 static vo_info_t vo_info =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 "OpenDivX AVI File writer",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 "odivx",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 "Arpad Gereoffy <arpi@esp-team.scene.hu>",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 ""
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 static uint8_t *image=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 static int image_width=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 static int image_height=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 static char *buffer=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 static int frameno=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 extern char* encode_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 extern char* encode_index_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 draw_slice(uint8_t *src[], uint32_t slice_num)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 uint8_t *d;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 // copy Y
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 d=image;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 memcpy(d+(slice_num<<4)*image_width,src[0],image_width*16);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 // copy U
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 d+=image_width*image_height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 memcpy(d+(slice_num<<2)*image_width,src[1],image_width*4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 // copy V
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 d+=image_width*image_height/4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 memcpy(d+(slice_num<<2)*image_width,src[2],image_width*4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 draw_frame(uint8_t *src[])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 uint8_t *d;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 // copy Y
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 d=image;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 memcpy(d,src[0],image_width*image_height);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 // copy U
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 d+=image_width*image_height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 memcpy(d,src[1],image_width*image_height/4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 // copy V
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 d+=image_width*image_height/4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 memcpy(d,src[2],image_width*image_height/4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 typedef unsigned int DWORD;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 typedef struct
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 DWORD ckid;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 DWORD dwFlags;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 DWORD dwChunkOffset; // Position of chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 DWORD dwChunkLength; // Length of chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 } AVIINDEXENTRY;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 static void
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 flip_page(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 // we are rady to encode this frame
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 ENC_FRAME enc_frame;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 ENC_RESULT enc_result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 if(++frameno<10) return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 enc_frame.bmp=image;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 enc_frame.bitstream=buffer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 enc_frame.length=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 encore(0x123,0,&enc_frame,&enc_result);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 printf("coded length: %d \n",enc_frame.length);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 if(encode_name){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 AVIINDEXENTRY i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 FILE *file;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 i.ckid=('c'<<24)|('d'<<16)|('0'<<8)|'0'; // "00dc"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 i.dwFlags=enc_result.isKeyFrame?0x10:0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 i.dwChunkLength=enc_frame.length;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 // Write AVI chunk:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 if((file=fopen(encode_name,"ab"))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 unsigned char zerobyte=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 i.dwChunkOffset=ftell(file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 fwrite(&i.ckid,4,1,file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 fwrite(&enc_frame.length,4,1,file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 fwrite(buffer,enc_frame.length,1,file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 if(enc_frame.length&1) fwrite(&zerobyte,1,1,file); // padding
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 fclose(file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 // Write AVI index:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 if(encode_index_name && (file=fopen(encode_index_name,"ab"))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 fwrite(&i,sizeof(i),1,file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 fclose(file);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 query_format(uint32_t format)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 switch(format){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 case IMGFMT_YV12:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 // case IMGFMT_YUY2:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 // case IMGFMT_RGB|24:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 // case IMGFMT_BGR|24:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 uint32_t frame_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 ENC_PARAM enc_param;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 buffer=malloc(0x100000);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 if(!buffer) return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 // file = fopen("encoded.odvx","wb");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 // if(!file) return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 frame_size=width*height+width*height/2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 image_width=width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 image_height=height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 image=malloc(frame_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 //clear the buffer
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 memset(image,0x80,frame_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 // encoding parameters:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 enc_param.framerate=25.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 enc_param.bitrate=400000; //780000;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 enc_param.rc_period=300;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 enc_param.max_quantizer=15;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 enc_param.min_quantizer=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 enc_param.search_range=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 // init codec:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 enc_param.x_dim=width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 enc_param.y_dim=height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 enc_param.flip=2; // 0=RGB 1=flippedRGB 2=planarYUV format
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 encore(0x123,ENC_OPT_INIT,&enc_param,NULL);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 static const vo_info_t*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 get_info(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 return &vo_info;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183