2002-06-08 20:47:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef USE_REALCODECS
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
|
|
|
#include "vd_internal.h"
|
|
|
|
|
|
|
|
static vd_info_t info = {
|
2002-06-13 00:14:28 +00:00
|
|
|
"RealVideo decoder",
|
2002-08-30 20:06:22 +00:00
|
|
|
"realvid",
|
2002-08-24 22:40:01 +00:00
|
|
|
"Florian Schneider & A'rpi",
|
2002-06-08 20:47:54 +00:00
|
|
|
"using original closed source codecs for Linux",
|
|
|
|
"binary real video codecs"
|
|
|
|
};
|
|
|
|
|
2002-08-30 20:06:22 +00:00
|
|
|
LIBVD_EXTERN(realvid)
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
|
2002-10-13 21:26:00 +00:00
|
|
|
static unsigned long (*rvyuv_custom_message)(unsigned long*,void*);
|
|
|
|
static unsigned long (*rvyuv_free)(void*);
|
|
|
|
static unsigned long (*rvyuv_hive_message)(unsigned long,unsigned long);
|
|
|
|
static unsigned long (*rvyuv_init)(void*, void*); // initdata,context
|
|
|
|
static unsigned long (*rvyuv_transform)(char*, char*,unsigned long*,unsigned long*,void*);
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2002-10-13 21:26:00 +00:00
|
|
|
static void *rv_handle=NULL;
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
void *__builtin_vec_new(unsigned long size) {
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __builtin_vec_delete(void *mem) {
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __pure_virtual(void) {
|
2002-06-09 19:53:13 +00:00
|
|
|
printf("FATAL: __pure_virtual() called!\n");
|
|
|
|
// exit(1);
|
2002-06-08 20:47:54 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 00:14:28 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
2002-06-09 19:53:13 +00:00
|
|
|
void ___brk_addr(void) {exit(0);}
|
2002-06-13 00:14:28 +00:00
|
|
|
char **__environ={NULL};
|
2002-06-09 19:53:13 +00:00
|
|
|
#undef stderr
|
2002-06-13 00:14:28 +00:00
|
|
|
FILE *stderr=NULL;
|
2002-06-09 19:53:13 +00:00
|
|
|
#endif
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
// to set/get/query special features/parameters
|
|
|
|
static int control(sh_video_t *sh,int cmd,void* arg,...){
|
|
|
|
// switch(cmd){
|
|
|
|
// case VDCTRL_QUERY_MAX_PP_LEVEL:
|
|
|
|
// return 9;
|
|
|
|
// case VDCTRL_SET_PP_LEVEL:
|
|
|
|
// vfw_set_postproc(sh,10*(*((int*)arg)));
|
|
|
|
// return CONTROL_OK;
|
|
|
|
// }
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exits program when failure */
|
2002-10-13 21:26:00 +00:00
|
|
|
static int load_syms_linux(char *path) {
|
2002-06-08 20:47:54 +00:00
|
|
|
void *handle;
|
|
|
|
|
2002-06-09 19:53:13 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO, "opening shared obj '%s'\n", path);
|
2002-06-08 20:47:54 +00:00
|
|
|
rv_handle = dlopen (path, RTLD_LAZY);
|
|
|
|
handle=rv_handle;
|
|
|
|
if (!handle) {
|
2002-06-09 19:53:13 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error: %s\n",dlerror());
|
2002-06-08 20:47:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rvyuv_custom_message = dlsym(handle, "RV20toYUV420CustomMessage");
|
|
|
|
rvyuv_free = dlsym(handle, "RV20toYUV420Free");
|
|
|
|
rvyuv_hive_message = dlsym(handle, "RV20toYUV420HiveMessage");
|
|
|
|
rvyuv_init = dlsym(handle, "RV20toYUV420Init");
|
|
|
|
rvyuv_transform = dlsym(handle, "RV20toYUV420Transform");
|
2002-06-09 19:53:13 +00:00
|
|
|
|
|
|
|
if(rvyuv_custom_message &&
|
|
|
|
rvyuv_free &&
|
|
|
|
rvyuv_hive_message &&
|
|
|
|
rvyuv_init &&
|
|
|
|
rvyuv_transform) return 1;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n");
|
|
|
|
return 0;
|
2002-06-08 20:47:54 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 08:13:08 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
2002-08-28 22:45:48 +00:00
|
|
|
|
|
|
|
#include "../loader/ldt_keeper.h"
|
|
|
|
void* LoadLibraryA(char* name);
|
|
|
|
void* GetProcAddress(void* handle,char* func);
|
|
|
|
|
2002-10-13 21:26:00 +00:00
|
|
|
static int load_syms_windows(char *path) {
|
2002-06-09 18:20:27 +00:00
|
|
|
void *handle;
|
|
|
|
Setup_LDT_Keeper();
|
|
|
|
rv_handle = handle = LoadLibraryA(path);
|
2002-06-09 19:53:13 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"win32 real codec handle=%p \n",handle);
|
2002-06-09 18:20:27 +00:00
|
|
|
|
|
|
|
rvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage");
|
|
|
|
rvyuv_free = GetProcAddress(handle, "RV20toYUV420Free");
|
|
|
|
rvyuv_hive_message = GetProcAddress(handle, "RV20toYUV420HiveMessage");
|
|
|
|
rvyuv_init = GetProcAddress(handle, "RV20toYUV420Init");
|
|
|
|
rvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform");
|
|
|
|
|
|
|
|
if(rvyuv_custom_message &&
|
|
|
|
rvyuv_free &&
|
|
|
|
rvyuv_hive_message &&
|
|
|
|
rvyuv_init &&
|
|
|
|
rvyuv_transform) return 1;
|
|
|
|
return 0; // error
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-08 20:47:54 +00:00
|
|
|
/* we need exact positions */
|
|
|
|
struct rv_init_t {
|
|
|
|
short unk1;
|
|
|
|
short w;
|
|
|
|
short h;
|
|
|
|
short unk3;
|
|
|
|
int unk2;
|
2002-06-09 01:08:33 +00:00
|
|
|
int subformat;
|
2002-06-08 20:47:54 +00:00
|
|
|
int unk5;
|
|
|
|
int format;
|
|
|
|
} rv_init_t;
|
|
|
|
|
|
|
|
// init driver
|
|
|
|
static int init(sh_video_t *sh){
|
|
|
|
//unsigned int out_fmt;
|
|
|
|
char path[4096];
|
|
|
|
int result;
|
2002-06-09 01:08:33 +00:00
|
|
|
// we export codec id and sub-id from demuxer in bitmapinfohdr:
|
|
|
|
unsigned int* extrahdr=(unsigned int*)(sh->bih+1);
|
2002-06-08 20:47:54 +00:00
|
|
|
struct rv_init_t init_data={
|
2002-06-09 01:08:33 +00:00
|
|
|
11, sh->disp_w, sh->disp_h,0,0,extrahdr[0],
|
|
|
|
1,extrahdr[1]}; // rv30
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",extrahdr[1],extrahdr[0]);
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2002-06-13 00:14:28 +00:00
|
|
|
sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);
|
2002-06-24 08:13:08 +00:00
|
|
|
|
|
|
|
/* first try to load linux dlls, if failed and we're supporting win32 dlls,
|
|
|
|
then try to load the windows ones */
|
|
|
|
if(!load_syms_linux(path))
|
2002-06-24 08:13:31 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
2002-06-24 08:13:08 +00:00
|
|
|
if (!load_syms_windows(path))
|
|
|
|
#endif
|
|
|
|
{
|
2002-06-08 20:47:54 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
|
2002-06-13 00:14:28 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_HINT,"You need to copy the contents from the RealPlayer codecs directory\n");
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_HINT,"into " REALCODEC_PATH "/ !\n");
|
2002-06-08 20:47:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// only I420 supported
|
|
|
|
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
|
|
|
|
// init codec:
|
|
|
|
sh->context=NULL;
|
|
|
|
result=(*rvyuv_init)(&init_data, &sh->context);
|
|
|
|
if (result){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't open RealVideo codec, error code: 0x%X \n",result);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-09 01:08:33 +00:00
|
|
|
// setup rv30 codec (codec sub-type and image dimensions):
|
2002-08-24 23:06:38 +00:00
|
|
|
if(extrahdr[1]>=0x20200002){
|
2002-07-17 23:28:37 +00:00
|
|
|
unsigned long cmsg24[4]={sh->disp_w,sh->disp_h,sh->disp_w,sh->disp_h};
|
2002-09-29 19:19:31 +00:00
|
|
|
unsigned long cmsg_data[3]={0x24,1+((extrahdr[0]>>16)&7),(unsigned long) &cmsg24};
|
2002-06-09 01:08:33 +00:00
|
|
|
(*rvyuv_custom_message)(cmsg_data,sh->context);
|
|
|
|
}
|
2002-06-08 20:47:54 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: RealVideo codec init OK!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// uninit driver
|
|
|
|
static void uninit(sh_video_t *sh){
|
2002-10-13 21:26:00 +00:00
|
|
|
if(rvyuv_free) rvyuv_free(sh->context);
|
2002-06-09 01:08:33 +00:00
|
|
|
if(rv_handle) dlclose(rv_handle);
|
|
|
|
rv_handle=NULL;
|
2002-06-08 20:47:54 +00:00
|
|
|
}
|
|
|
|
|
2002-08-24 22:40:01 +00:00
|
|
|
// copypaste from demux_real.c - it should match to get it working!
|
|
|
|
typedef struct dp_hdr_s {
|
|
|
|
uint32_t chunks; // number of chunks
|
|
|
|
uint32_t timestamp; // timestamp from packet header
|
|
|
|
uint32_t len; // length of actual data
|
|
|
|
uint32_t chunktab; // offset to chunk offset array
|
|
|
|
} dp_hdr_t;
|
|
|
|
|
2002-06-08 20:47:54 +00:00
|
|
|
// decode a frame
|
|
|
|
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|
|
|
mp_image_t* mpi;
|
2002-07-17 23:28:37 +00:00
|
|
|
unsigned long result;
|
2002-08-24 22:40:01 +00:00
|
|
|
dp_hdr_t* dp_hdr=(dp_hdr_t*)data;
|
|
|
|
unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t);
|
|
|
|
uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab);
|
|
|
|
|
2002-07-17 23:28:37 +00:00
|
|
|
unsigned long transform_out[5];
|
|
|
|
unsigned long transform_in[6]={
|
2002-08-24 22:40:01 +00:00
|
|
|
dp_hdr->len, // length of the packet (sub-packets appended)
|
2002-06-08 20:47:54 +00:00
|
|
|
0, // unknown, seems to be unused
|
2002-08-24 22:40:01 +00:00
|
|
|
dp_hdr->chunks, // number of sub-packets - 1
|
2002-09-29 19:19:31 +00:00
|
|
|
(unsigned long) extra, // table of sub-packet offsets
|
2002-06-08 20:47:54 +00:00
|
|
|
0, // unknown, seems to be unused
|
2002-08-24 22:40:01 +00:00
|
|
|
dp_hdr->timestamp,// timestamp (the integer value from the stream)
|
2002-06-08 20:47:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop
|
|
|
|
|
|
|
|
mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,
|
|
|
|
sh->disp_w, sh->disp_h);
|
|
|
|
if(!mpi) return NULL;
|
|
|
|
|
2002-08-24 22:40:01 +00:00
|
|
|
result=(*rvyuv_transform)(dp_data, mpi->planes[0], transform_in,
|
2002-06-08 20:47:54 +00:00
|
|
|
transform_out, sh->context);
|
|
|
|
|
|
|
|
return (result?NULL:mpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|