comparison libmpcodecs/vd_realvid.c @ 7172:33c38a0c20e8

renamed to match driver family name
author arpi
date Fri, 30 Aug 2002 19:49:37 +0000
parents libmpcodecs/vd_real.c@1e47c2e7aa8e
children 7672615cc811
comparison
equal deleted inserted replaced
7171:772f853f32a1 7172:33c38a0c20e8
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "config.h"
5 #ifdef USE_REALCODECS
6
7 #include <dlfcn.h>
8
9 #include "mp_msg.h"
10 #include "help_mp.h"
11
12 #include "vd_internal.h"
13
14 static vd_info_t info = {
15 "RealVideo decoder",
16 "real",
17 VFM_REAL,
18 "Florian Schneider & A'rpi",
19 "using original closed source codecs for Linux",
20 "binary real video codecs"
21 };
22
23 LIBVD_EXTERN(real)
24
25
26 unsigned long (*rvyuv_custom_message)(unsigned long,unsigned long);
27 unsigned long (*rvyuv_free)(unsigned long);
28 unsigned long (*rvyuv_hive_message)(unsigned long,unsigned long);
29 unsigned long (*rvyuv_init)(unsigned long,unsigned long);
30 unsigned long (*rvyuv_transform)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long);
31
32 void *rv_handle=NULL;
33
34 void *__builtin_vec_new(unsigned long size) {
35 return malloc(size);
36 }
37
38 void __builtin_vec_delete(void *mem) {
39 free(mem);
40 }
41
42 void __pure_virtual(void) {
43 printf("FATAL: __pure_virtual() called!\n");
44 // exit(1);
45 }
46
47 #if defined(__FreeBSD__) || defined(__NetBSD__)
48 void ___brk_addr(void) {exit(0);}
49 char **__environ={NULL};
50 #undef stderr
51 FILE *stderr=NULL;
52 #endif
53
54 // to set/get/query special features/parameters
55 static int control(sh_video_t *sh,int cmd,void* arg,...){
56 // switch(cmd){
57 // case VDCTRL_QUERY_MAX_PP_LEVEL:
58 // return 9;
59 // case VDCTRL_SET_PP_LEVEL:
60 // vfw_set_postproc(sh,10*(*((int*)arg)));
61 // return CONTROL_OK;
62 // }
63 return CONTROL_UNKNOWN;
64 }
65
66 /* exits program when failure */
67 int load_syms_linux(char *path) {
68 void *handle;
69 char *error;
70
71 mp_msg(MSGT_DECVIDEO,MSGL_INFO, "opening shared obj '%s'\n", path);
72 rv_handle = dlopen (path, RTLD_LAZY);
73 handle=rv_handle;
74 if (!handle) {
75 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error: %s\n",dlerror());
76 return 0;
77 }
78
79 rvyuv_custom_message = dlsym(handle, "RV20toYUV420CustomMessage");
80 rvyuv_free = dlsym(handle, "RV20toYUV420Free");
81 rvyuv_hive_message = dlsym(handle, "RV20toYUV420HiveMessage");
82 rvyuv_init = dlsym(handle, "RV20toYUV420Init");
83 rvyuv_transform = dlsym(handle, "RV20toYUV420Transform");
84
85 if(rvyuv_custom_message &&
86 rvyuv_free &&
87 rvyuv_hive_message &&
88 rvyuv_init &&
89 rvyuv_transform) return 1;
90
91 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n");
92 return 0;
93 }
94
95 #ifdef USE_WIN32DLL
96
97 #include "../loader/ldt_keeper.h"
98 void* LoadLibraryA(char* name);
99 void* GetProcAddress(void* handle,char* func);
100
101 int load_syms_windows(char *path) {
102 void *handle;
103 Setup_LDT_Keeper();
104 rv_handle = handle = LoadLibraryA(path);
105 mp_msg(MSGT_DECVIDEO,MSGL_V,"win32 real codec handle=%p \n",handle);
106
107 rvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage");
108 rvyuv_free = GetProcAddress(handle, "RV20toYUV420Free");
109 rvyuv_hive_message = GetProcAddress(handle, "RV20toYUV420HiveMessage");
110 rvyuv_init = GetProcAddress(handle, "RV20toYUV420Init");
111 rvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform");
112
113 if(rvyuv_custom_message &&
114 rvyuv_free &&
115 rvyuv_hive_message &&
116 rvyuv_init &&
117 rvyuv_transform) return 1;
118 return 0; // error
119 }
120 #endif
121
122 /* we need exact positions */
123 struct rv_init_t {
124 short unk1;
125 short w;
126 short h;
127 short unk3;
128 int unk2;
129 int subformat;
130 int unk5;
131 int format;
132 } rv_init_t;
133
134 // init driver
135 static int init(sh_video_t *sh){
136 //unsigned int out_fmt;
137 char path[4096];
138 int result;
139 // we export codec id and sub-id from demuxer in bitmapinfohdr:
140 unsigned int* extrahdr=(unsigned int*)(sh->bih+1);
141 struct rv_init_t init_data={
142 11, sh->disp_w, sh->disp_h,0,0,extrahdr[0],
143 1,extrahdr[1]}; // rv30
144
145 mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",extrahdr[1],extrahdr[0]);
146
147 sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);
148
149 /* first try to load linux dlls, if failed and we're supporting win32 dlls,
150 then try to load the windows ones */
151 if(!load_syms_linux(path))
152 #ifdef USE_WIN32DLL
153 if (!load_syms_windows(path))
154 #endif
155 {
156 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
157 mp_msg(MSGT_DECVIDEO,MSGL_HINT,"You need to copy the contents from the RealPlayer codecs directory\n");
158 mp_msg(MSGT_DECVIDEO,MSGL_HINT,"into " REALCODEC_PATH "/ !\n");
159 return 0;
160 }
161 // only I420 supported
162 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
163 // init codec:
164 sh->context=NULL;
165 result=(*rvyuv_init)(&init_data, &sh->context);
166 if (result){
167 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't open RealVideo codec, error code: 0x%X \n",result);
168 return 0;
169 }
170 // setup rv30 codec (codec sub-type and image dimensions):
171 if(extrahdr[1]>=0x20200002){
172 unsigned long cmsg24[4]={sh->disp_w,sh->disp_h,sh->disp_w,sh->disp_h};
173 unsigned long cmsg_data[3]={0x24,1+((extrahdr[0]>>16)&7),&cmsg24};
174 (*rvyuv_custom_message)(cmsg_data,sh->context);
175 }
176 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: RealVideo codec init OK!\n");
177 return 1;
178 }
179
180 // uninit driver
181 static void uninit(sh_video_t *sh){
182 if(rv_handle) dlclose(rv_handle);
183 rv_handle=NULL;
184 }
185
186 // copypaste from demux_real.c - it should match to get it working!
187 typedef struct dp_hdr_s {
188 uint32_t chunks; // number of chunks
189 uint32_t timestamp; // timestamp from packet header
190 uint32_t len; // length of actual data
191 uint32_t chunktab; // offset to chunk offset array
192 } dp_hdr_t;
193
194 // decode a frame
195 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
196 mp_image_t* mpi;
197 unsigned long result;
198 dp_hdr_t* dp_hdr=(dp_hdr_t*)data;
199 unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t);
200 uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab);
201
202 unsigned long transform_out[5];
203 unsigned long transform_in[6]={
204 dp_hdr->len, // length of the packet (sub-packets appended)
205 0, // unknown, seems to be unused
206 dp_hdr->chunks, // number of sub-packets - 1
207 extra, // table of sub-packet offsets
208 0, // unknown, seems to be unused
209 dp_hdr->timestamp,// timestamp (the integer value from the stream)
210 };
211
212 if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop
213
214 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,
215 sh->disp_w, sh->disp_h);
216 if(!mpi) return NULL;
217
218 result=(*rvyuv_transform)(dp_data, mpi->planes[0], transform_in,
219 transform_out, sh->context);
220
221 return (result?NULL:mpi);
222 }
223
224 #endif