2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-06-08 20:47:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
2002-06-08 20:47:54 +00:00
|
|
|
#include <dlfcn.h>
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
#include "mp_msg.h"
|
2010-07-10 22:24:31 +00:00
|
|
|
#include "ffmpeg_files/intreadwrite.h"
|
2010-03-23 17:52:46 +00:00
|
|
|
#include "path.h"
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
#include "vd_internal.h"
|
2007-03-15 08:29:24 +00:00
|
|
|
#include "loader/wine/windef.h"
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2008-04-24 05:43:56 +00:00
|
|
|
static const vd_info_t info = {
|
2002-06-13 00:14:28 +00:00
|
|
|
"RealVideo decoder",
|
2002-08-30 20:06:22 +00:00
|
|
|
"realvid",
|
2004-06-24 09:19:15 +00:00
|
|
|
"Alex Beregszaszi",
|
|
|
|
"Florian Schneider, Arpad Gereoffy, Alex Beregszaszi, Donnie Smith",
|
2002-06-08 20:47:54 +00:00
|
|
|
"binary real video codecs"
|
|
|
|
};
|
|
|
|
|
2002-08-30 20:06:22 +00:00
|
|
|
LIBVD_EXTERN(realvid)
|
2002-06-08 20:47:54 +00:00
|
|
|
|
|
|
|
|
2002-12-22 16:21:02 +00:00
|
|
|
/*
|
|
|
|
* Structures for data packets. These used to be tables of unsigned ints, but
|
|
|
|
* that does not work on 64 bit platforms (e.g. Alpha). The entries that are
|
|
|
|
* pointers get truncated. Pointers on 64 bit platforms are 8 byte longs.
|
|
|
|
* So we have to use structures so the compiler will assign the proper space
|
|
|
|
* for the pointer.
|
|
|
|
*/
|
|
|
|
typedef struct cmsg_data_s {
|
|
|
|
uint32_t data1;
|
|
|
|
uint32_t data2;
|
|
|
|
uint32_t* dimensions;
|
|
|
|
} cmsg_data_t;
|
|
|
|
|
|
|
|
typedef struct transform_in_s {
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t unknown1;
|
|
|
|
uint32_t chunks;
|
|
|
|
uint32_t* extra;
|
|
|
|
uint32_t unknown2;
|
|
|
|
uint32_t timestamp;
|
|
|
|
} transform_in_t;
|
|
|
|
|
|
|
|
static unsigned long (*rvyuv_custom_message)(cmsg_data_t* ,void*);
|
2002-10-13 21:26:00 +00:00
|
|
|
static unsigned long (*rvyuv_free)(void*);
|
|
|
|
static unsigned long (*rvyuv_init)(void*, void*); // initdata,context
|
2002-12-22 16:21:02 +00:00
|
|
|
static unsigned long (*rvyuv_transform)(char*, char*,transform_in_t*,unsigned int*,void*);
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
static unsigned long WINAPI (*wrvyuv_custom_message)(cmsg_data_t* ,void*);
|
|
|
|
static unsigned long WINAPI (*wrvyuv_free)(void*);
|
|
|
|
static unsigned long WINAPI (*wrvyuv_init)(void*, void*); // initdata,context
|
|
|
|
static unsigned long WINAPI (*wrvyuv_transform)(char*, char*,transform_in_t*,unsigned int*,void*);
|
|
|
|
#endif
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2002-10-13 21:26:00 +00:00
|
|
|
static void *rv_handle=NULL;
|
2008-02-14 14:23:55 +00:00
|
|
|
static int initialized=0;
|
2006-12-10 16:52:58 +00:00
|
|
|
static uint8_t *buffer = NULL;
|
2006-12-10 18:59:28 +00:00
|
|
|
static int bufsz = 0;
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
static int dll_type = 0; /* 0 = unix dlopen, 1 = win32 dll */
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
2005-05-25 08:48:32 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
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 */
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
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;
|
|
|
|
|
2006-03-03 22:38:46 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V, "opening shared obj '%s'\n", path);
|
2003-02-10 15:02:05 +00:00
|
|
|
handle = dlopen (path, RTLD_LAZY);
|
2002-06-08 20:47:54 +00:00
|
|
|
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_init = dlsym(handle, "RV20toYUV420Init");
|
|
|
|
rvyuv_transform = dlsym(handle, "RV20toYUV420Transform");
|
2002-06-09 19:53:13 +00:00
|
|
|
|
2004-11-03 02:50:01 +00:00
|
|
|
if(rvyuv_custom_message &&
|
|
|
|
rvyuv_free &&
|
|
|
|
rvyuv_init &&
|
|
|
|
rvyuv_transform)
|
|
|
|
{
|
|
|
|
rv_handle = handle;
|
|
|
|
return 1;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-11-03 02:50:01 +00:00
|
|
|
rvyuv_custom_message = dlsym(handle, "RV40toYUV420CustomMessage");
|
|
|
|
rvyuv_free = dlsym(handle, "RV40toYUV420Free");
|
|
|
|
rvyuv_init = dlsym(handle, "RV40toYUV420Init");
|
|
|
|
rvyuv_transform = dlsym(handle, "RV40toYUV420Transform");
|
|
|
|
|
2002-06-09 19:53:13 +00:00
|
|
|
if(rvyuv_custom_message &&
|
|
|
|
rvyuv_free &&
|
|
|
|
rvyuv_init &&
|
2003-02-10 15:02:05 +00:00
|
|
|
rvyuv_transform)
|
|
|
|
{
|
|
|
|
rv_handle = handle;
|
|
|
|
return 1;
|
|
|
|
}
|
2002-06-09 19:53:13 +00:00
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n");
|
2003-02-10 15:02:05 +00:00
|
|
|
dlclose(handle);
|
2002-06-09 19:53:13 +00:00
|
|
|
return 0;
|
2002-06-08 20:47:54 +00:00
|
|
|
}
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-08-28 22:45:48 +00:00
|
|
|
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "loader/ldt_keeper.h"
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2002-12-22 18:10:45 +00:00
|
|
|
void* WINAPI LoadLibraryA(char* name);
|
|
|
|
void* WINAPI GetProcAddress(void* handle,char* func);
|
|
|
|
int WINAPI FreeLibrary(void *handle);
|
2002-08-28 22:45:48 +00:00
|
|
|
|
2007-08-20 16:17:13 +00:00
|
|
|
#ifndef WIN32_LOADER
|
|
|
|
void * WINAPI GetModuleHandleA(char *);
|
|
|
|
static int patch_dll(uint8_t *patchpos, const uint8_t *oldcode,
|
|
|
|
const uint8_t *newcode, int codesize) {
|
|
|
|
void *handle = GetModuleHandleA("kernel32");
|
|
|
|
int WINAPI (*VirtProt)(void *, unsigned, int, int *);
|
|
|
|
int res = 0;
|
|
|
|
int prot, tmp;
|
|
|
|
VirtProt = GetProcAddress(handle, "VirtualProtect");
|
|
|
|
// change permissions to PAGE_WRITECOPY
|
|
|
|
if (!VirtProt ||
|
|
|
|
!VirtProt(patchpos, codesize, 0x08, &prot)) {
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_WARN, "VirtualProtect failed at %p\n", patchpos);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (memcmp(patchpos, oldcode, codesize) == 0) {
|
|
|
|
memcpy(patchpos, newcode, codesize);
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
VirtProt(patchpos, codesize, prot, &tmp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
2002-12-22 18:10:45 +00:00
|
|
|
|
2006-03-03 22:38:46 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V, "opening win32 dll '%s'\n", path);
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2002-06-09 18:20:27 +00:00
|
|
|
Setup_LDT_Keeper();
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2003-02-10 15:02:05 +00:00
|
|
|
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-12-22 18:10:45 +00:00
|
|
|
if (!handle) {
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error loading dll\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wrvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage");
|
|
|
|
wrvyuv_free = GetProcAddress(handle, "RV20toYUV420Free");
|
|
|
|
wrvyuv_init = GetProcAddress(handle, "RV20toYUV420Init");
|
|
|
|
wrvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform");
|
2003-02-10 15:02:05 +00:00
|
|
|
|
2002-12-22 18:10:45 +00:00
|
|
|
if(wrvyuv_custom_message &&
|
|
|
|
wrvyuv_free &&
|
|
|
|
wrvyuv_init &&
|
2003-02-10 15:02:05 +00:00
|
|
|
wrvyuv_transform)
|
|
|
|
{
|
|
|
|
dll_type = 1;
|
|
|
|
rv_handle = handle;
|
2007-08-20 16:17:13 +00:00
|
|
|
#ifndef WIN32_LOADER
|
|
|
|
{
|
2008-04-12 18:35:11 +00:00
|
|
|
if (strstr(path, "drv43260.dll")) {
|
2008-04-12 18:23:26 +00:00
|
|
|
int patched;
|
2007-08-20 16:17:13 +00:00
|
|
|
// patch away multithreaded decoding, it causes crashes
|
|
|
|
static const uint8_t oldcode[13] = {
|
|
|
|
0x83, 0xbb, 0xf8, 0x05, 0x00, 0x00, 0x01,
|
|
|
|
0x0f, 0x86, 0xd0, 0x00, 0x00, 0x00 };
|
|
|
|
static const uint8_t newcode[13] = {
|
|
|
|
0x31, 0xc0,
|
|
|
|
0x89, 0x83, 0xf8, 0x05, 0x00, 0x00,
|
|
|
|
0xe9, 0xd0, 0x00, 0x00, 0x00 };
|
2008-04-12 18:31:08 +00:00
|
|
|
patched = patch_dll(
|
|
|
|
(char*)wrvyuv_transform + 0x634132fa - 0x634114d0,
|
|
|
|
oldcode, newcode, sizeof(oldcode));
|
2008-04-12 18:24:25 +00:00
|
|
|
if (!patched)
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Could not patch Real codec, this might crash on multi-CPU systems\n");
|
2008-04-12 18:23:26 +00:00
|
|
|
}
|
2007-08-20 16:17:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-02-10 15:02:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-04-12 18:19:51 +00:00
|
|
|
|
|
|
|
wrvyuv_custom_message = GetProcAddress(handle, "RV40toYUV420CustomMessage");
|
|
|
|
wrvyuv_free = GetProcAddress(handle, "RV40toYUV420Free");
|
|
|
|
wrvyuv_init = GetProcAddress(handle, "RV40toYUV420Init");
|
|
|
|
wrvyuv_transform = GetProcAddress(handle, "RV40toYUV420Transform");
|
|
|
|
if(wrvyuv_custom_message &&
|
|
|
|
wrvyuv_free &&
|
|
|
|
wrvyuv_init &&
|
2008-04-13 02:35:30 +00:00
|
|
|
wrvyuv_transform) {
|
|
|
|
dll_type = 1;
|
|
|
|
rv_handle = handle;
|
2008-04-12 18:19:51 +00:00
|
|
|
return 1;
|
2008-04-13 02:35:30 +00:00
|
|
|
}
|
2008-04-12 18:19:51 +00:00
|
|
|
|
2002-12-22 18:10:45 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error resolving symbols! (version incompatibility?)\n");
|
2003-02-10 15:02:05 +00:00
|
|
|
FreeLibrary(handle);
|
2002-06-09 18:20:27 +00:00
|
|
|
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;
|
2003-05-12 16:02:34 +00:00
|
|
|
char *path;
|
2002-06-08 20:47:54 +00:00
|
|
|
int result;
|
2002-06-09 01:08:33 +00:00
|
|
|
// we export codec id and sub-id from demuxer in bitmapinfohdr:
|
2006-11-14 22:40:35 +00:00
|
|
|
unsigned char* extrahdr=(unsigned char*)(sh->bih+1);
|
2010-09-12 11:44:42 +00:00
|
|
|
unsigned int extrahdr_size = sh->bih->biSize - sizeof(*sh->bih);
|
2006-11-14 22:40:35 +00:00
|
|
|
struct rv_init_t init_data;
|
2002-06-09 01:08:33 +00:00
|
|
|
|
2006-11-14 22:40:35 +00:00
|
|
|
if(extrahdr_size < 8) {
|
2010-09-12 11:44:42 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"realvideo: extradata too small (%u)\n", extrahdr_size);
|
2006-11-14 22:40:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-10 22:24:31 +00:00
|
|
|
init_data = (struct rv_init_t){11, sh->disp_w, sh->disp_h, 0, 0, AV_RB32(extrahdr), 1, AV_RB32(extrahdr + 4)}; // rv30
|
2006-11-14 22:40:35 +00:00
|
|
|
|
2010-07-10 22:24:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",init_data.format,init_data.subformat);
|
2002-06-08 20:47:54 +00:00
|
|
|
|
2010-03-23 19:40:37 +00:00
|
|
|
path = malloc(strlen(codec_path) + strlen(sh->codec->dll) + 2);
|
2003-05-12 16:02:34 +00:00
|
|
|
if (!path) return 0;
|
2010-03-23 19:40:37 +00:00
|
|
|
sprintf(path, "%s/%s", codec_path, 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 */
|
2009-07-06 23:26:13 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
2003-05-11 17:58:03 +00:00
|
|
|
if(strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
|
|
|
|
#endif
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2003-07-19 22:05:16 +00:00
|
|
|
if (!load_syms_windows(sh->codec->dll))
|
2002-06-24 08:13:08 +00:00
|
|
|
#endif
|
|
|
|
{
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"ERROR: Could not open required DirectShow codec %s.\n",sh->codec->dll);
|
2003-02-10 15:02:05 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Read the RealVideo section of the DOCS!\n");
|
2003-05-12 16:02:34 +00:00
|
|
|
free(path);
|
2002-06-08 20:47:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-12 16:02:34 +00:00
|
|
|
free(path);
|
2002-06-08 20:47:54 +00:00
|
|
|
// only I420 supported
|
2003-03-09 17:19:41 +00:00
|
|
|
// if((sh->format!=0x30335652) && !mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
|
2002-06-08 20:47:54 +00:00
|
|
|
// init codec:
|
|
|
|
sh->context=NULL;
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
if (dll_type == 1)
|
|
|
|
result=(*wrvyuv_init)(&init_data, &sh->context);
|
|
|
|
else
|
|
|
|
#endif
|
2002-06-08 20:47:54 +00:00
|
|
|
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):
|
2010-07-10 22:24:31 +00:00
|
|
|
if((sh->format<=0x30335652) && AV_RB32(extrahdr + 4)>=0x20200002){
|
2006-11-14 22:40:35 +00:00
|
|
|
int i, cmsg_cnt;
|
|
|
|
uint32_t cmsg24[16]={sh->disp_w,sh->disp_h};
|
|
|
|
cmsg_data_t cmsg_data={0x24,1+(extrahdr[1]&7), &cmsg24[0]};
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo: using cmsg24 with %u elements.\n",extrahdr[1]&7);
|
|
|
|
cmsg_cnt = (extrahdr[1]&7)*2;
|
|
|
|
if (extrahdr_size-8 < cmsg_cnt) {
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"realvideo: not enough extradata (%u) to make %u cmsg24 elements.\n",extrahdr_size-8,extrahdr[1]&7);
|
|
|
|
cmsg_cnt = extrahdr_size-8;
|
|
|
|
}
|
|
|
|
for (i = 0; i < cmsg_cnt; i++)
|
|
|
|
cmsg24[2+i] = extrahdr[8+i]*4;
|
|
|
|
if (extrahdr_size-8 > cmsg_cnt)
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"realvideo: %u bytes of unknown extradata remaining.\n",extrahdr_size-8-cmsg_cnt);
|
2002-12-22 18:10:45 +00:00
|
|
|
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
if (dll_type == 1)
|
|
|
|
(*wrvyuv_custom_message)(&cmsg_data,sh->context);
|
|
|
|
else
|
|
|
|
#endif
|
2002-12-22 16:21:02 +00:00
|
|
|
(*rvyuv_custom_message)(&cmsg_data,sh->context);
|
2002-06-09 01:08:33 +00:00
|
|
|
}
|
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){
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
if (dll_type == 1)
|
|
|
|
{
|
|
|
|
if (wrvyuv_free) wrvyuv_free(sh->context);
|
|
|
|
} else
|
|
|
|
#endif
|
2002-10-13 21:26:00 +00:00
|
|
|
if(rvyuv_free) rvyuv_free(sh->context);
|
2002-12-22 18:10:45 +00:00
|
|
|
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
if (dll_type == 1)
|
|
|
|
{
|
|
|
|
if (rv_handle) FreeLibrary(rv_handle);
|
|
|
|
} else
|
|
|
|
#endif
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
2002-06-09 01:08:33 +00:00
|
|
|
if(rv_handle) dlclose(rv_handle);
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2002-06-09 01:08:33 +00:00
|
|
|
rv_handle=NULL;
|
2008-02-14 14:23:55 +00:00
|
|
|
initialized = 0;
|
2010-11-14 09:12:34 +00:00
|
|
|
free(buffer);
|
2006-12-10 16:52:58 +00:00
|
|
|
buffer = NULL;
|
2006-12-10 18:59:28 +00:00
|
|
|
bufsz = 0;
|
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;
|
2009-02-09 22:00:57 +00:00
|
|
|
uint8_t *buf = data;
|
|
|
|
int chunks = *buf++;
|
|
|
|
int extra_size = 8*(chunks+1);
|
|
|
|
uint32_t data_size = len-1-extra_size;
|
|
|
|
unsigned char* dp_data=buf+extra_size;
|
|
|
|
uint32_t* extra=(uint32_t*)buf;
|
|
|
|
int i;
|
2002-08-24 22:40:01 +00:00
|
|
|
|
2002-12-22 16:21:02 +00:00
|
|
|
unsigned int transform_out[5];
|
|
|
|
transform_in_t transform_in={
|
2009-02-09 22:00:57 +00:00
|
|
|
data_size, // length of the packet (sub-packets appended)
|
2002-06-08 20:47:54 +00:00
|
|
|
0, // unknown, seems to be unused
|
2009-02-09 22:00:57 +00:00
|
|
|
chunks, // number of sub-packets - 1
|
2002-12-22 16:21:02 +00:00
|
|
|
extra, // table of sub-packet offsets
|
2002-06-08 20:47:54 +00:00
|
|
|
0, // unknown, seems to be unused
|
2008-01-06 13:49:07 +00:00
|
|
|
0, // timestamp (should be unneded)
|
2002-06-08 20:47:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop
|
|
|
|
|
2006-12-10 18:59:28 +00:00
|
|
|
if (bufsz < sh->disp_w*sh->disp_h*3/2) {
|
2010-11-14 09:12:34 +00:00
|
|
|
free(buffer);
|
2006-12-10 18:59:28 +00:00
|
|
|
bufsz = sh->disp_w*sh->disp_h*3/2;
|
|
|
|
buffer=malloc(bufsz);
|
2003-03-09 17:19:41 +00:00
|
|
|
if (!buffer) return 0;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-02-09 22:00:57 +00:00
|
|
|
for (i=0; i<2*(chunks+1); i++)
|
|
|
|
extra[i] = le2me_32(extra[i]);
|
|
|
|
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2002-12-22 18:10:45 +00:00
|
|
|
if (dll_type == 1)
|
2003-03-09 17:19:41 +00:00
|
|
|
result=(*wrvyuv_transform)(dp_data, buffer, &transform_in,
|
2002-12-22 18:10:45 +00:00
|
|
|
transform_out, sh->context);
|
|
|
|
else
|
|
|
|
#endif
|
2003-03-09 17:19:41 +00:00
|
|
|
result=(*rvyuv_transform)(dp_data, buffer, &transform_in,
|
2002-06-08 20:47:54 +00:00
|
|
|
transform_out, sh->context);
|
|
|
|
|
2008-02-14 14:23:55 +00:00
|
|
|
if(!initialized){ // rv30 width/height now known
|
2003-03-09 17:19:41 +00:00
|
|
|
sh->aspect=(float)sh->disp_w/(float)sh->disp_h;
|
|
|
|
sh->disp_w=transform_out[3];
|
|
|
|
sh->disp_h=transform_out[4];
|
|
|
|
if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
|
2008-02-14 14:23:55 +00:00
|
|
|
initialized=1;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2006-12-10 16:52:58 +00:00
|
|
|
mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,
|
|
|
|
sh->disp_w, sh->disp_h);
|
|
|
|
if(!mpi) return NULL;
|
|
|
|
mpi->planes[0] = buffer;
|
|
|
|
mpi->stride[0] = sh->disp_w;
|
|
|
|
mpi->planes[1] = buffer + sh->disp_w*sh->disp_h;
|
|
|
|
mpi->stride[1] = sh->disp_w / 2;
|
|
|
|
mpi->planes[2] = buffer + sh->disp_w*sh->disp_h*5/4;
|
|
|
|
mpi->stride[2] = sh->disp_w / 2;
|
|
|
|
|
|
|
|
if(transform_out[0] &&
|
|
|
|
(sh->disp_w != transform_out[3] || sh->disp_h != transform_out[4]))
|
2008-02-14 14:23:55 +00:00
|
|
|
initialized = 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2008-05-16 00:23:02 +00:00
|
|
|
return result ? NULL : mpi;
|
2002-06-08 20:47:54 +00:00
|
|
|
}
|