realvideo.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:17k
源码类别:
midi
开发平台:
Unix_Linux
- /*****************************************************************************
- * realvideo.c: a realvideo decoder that uses the real's dll
- *****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
- * Copyright (C) 2008 Wang Bo
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
- /*****************************************************************************
- * Preamble
- *****************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include <vlc_common.h>
- #include <vlc_plugin.h>
- #include <vlc_vout.h>
- #include <vlc_codec.h>
- #ifdef LOADER
- /* Need the w32dll loader from mplayer */
- # include <wine/winerror.h>
- # include <ldt_keeper.h>
- # include <wine/windef.h>
- void *WINAPI LoadLibraryA( char *name );
- void *WINAPI GetProcAddress( void *handle, char *func );
- int WINAPI FreeLibrary( void *handle );
- #endif
- #ifndef WINAPI
- # define WINAPI
- #endif
- #if defined(HAVE_DL_DLOPEN)
- # if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
- # include <dlfcn.h>
- # endif
- # if defined(HAVE_SYS_DL_H)
- # include <sys/dl.h>
- # endif
- #endif
- 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;
- // 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;
- /* we need exact positions */
- struct rv_init_t
- {
- short unk1;
- short w;
- short h;
- short unk3;
- int unk2;
- unsigned int * subformat;
- int unk5;
- unsigned int * format;
- } rv_init_t;
- struct decoder_sys_t
- {
- /* library */
- #ifdef LOADER
- ldt_fs_t *ldt_fs;
- #endif
- void *handle;
- void *rv_handle;
- int inited;
- char *plane;
- };
- int dll_type = 1;
- static unsigned long (*rvyuv_custom_message)(cmsg_data_t* ,void*);
- static unsigned long (*rvyuv_free)(void*);
- static unsigned long (*rvyuv_init)(void*, void*); // initdata,context
- static unsigned long (*rvyuv_transform)(char*, char*,transform_in_t*,unsigned int*,void*);
- #ifdef WIN32
- 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
- /*****************************************************************************
- * Module descriptor
- *****************************************************************************/
- static int Open ( vlc_object_t * );
- static void Close( vlc_object_t * );
- //static int OpenPacketizer( vlc_object_t * );
- static picture_t *DecodeVideo( decoder_t *, block_t ** );
- vlc_module_begin ()
- set_description( N_("RealVideo library decoder") )
- set_capability( "decoder", 10 )
- set_category( CAT_INPUT )
- set_subcategory( SUBCAT_INPUT_VCODEC )
- set_callbacks( Open, Close )
- vlc_module_end ()
- /*****************************************************************************
- * Local prototypes
- *****************************************************************************/
- #ifdef WIN32
- static void * load_syms(decoder_t *p_dec, const char *path)
- {
- void *handle;
- msg_Dbg( p_dec, "opening win32 dll '%s'", path);
- #ifdef LOADER
- Setup_LDT_Keeper();
- #endif
- handle = LoadLibraryA(path);
- msg_Dbg( p_dec, "win32 real codec handle=%p",handle);
- if (!handle)
- {
- msg_Err( p_dec, "Error loading dll");
- return NULL;
- }
- wrvyuv_custom_message = GetProcAddress(handle, "RV20toYUV420CustomMessage");
- wrvyuv_free = GetProcAddress(handle, "RV20toYUV420Free");
- wrvyuv_init = GetProcAddress(handle, "RV20toYUV420Init");
- wrvyuv_transform = GetProcAddress(handle, "RV20toYUV420Transform");
- if (wrvyuv_custom_message && wrvyuv_free && wrvyuv_init && wrvyuv_transform)
- {
- dll_type = 1;
- return handle;
- }
- msg_Err( p_dec, "Error resolving symbols! (version incompatibility?)");
- FreeLibrary(handle);
- return NULL; // error
- }
- #else
- static void * load_syms_linux(decoder_t *p_dec, const char *path)
- {
- void *handle;
- msg_Dbg( p_dec, "opening shared obj '%s'", path);
- handle = dlopen (path, RTLD_LAZY);
- if (!handle)
- {
- msg_Err( p_dec,"Error: %s",dlerror());
- return NULL;
- }
- rvyuv_custom_message = dlsym(handle, "RV20toYUV420CustomMessage");
- rvyuv_free = dlsym(handle, "RV20toYUV420Free");
- rvyuv_init = dlsym(handle, "RV20toYUV420Init");
- rvyuv_transform = dlsym(handle, "RV20toYUV420Transform");
- if(rvyuv_custom_message && rvyuv_free && rvyuv_init && rvyuv_transform)
- {
- dll_type = 0;
- return handle;
- }
- msg_Err( p_dec,"Error resolving symbols! (version incompatibility?)");
- dlclose(handle);
- return 0;
- }
- #endif
- static vlc_mutex_t rm_mutex = VLC_STATIC_MUTEX;
- static int InitVideo(decoder_t *p_dec)
- {
- int result;
- struct rv_init_t init_data;
- char fcc[4];
- char *g_decode_path;
- int i_vide = p_dec->fmt_in.i_extra;
- unsigned int *p_vide = p_dec->fmt_in.p_extra;
- decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
- memset(p_sys,0,sizeof( decoder_sys_t ) );
- if( i_vide < 8 )
- {
- msg_Err( p_dec, "missing extra info" );
- free( p_sys );
- return VLC_EGENERIC;
- }
- if (p_sys->plane) free(p_sys->plane);
- p_sys->plane = malloc (p_dec->fmt_in.video.i_width*p_dec->fmt_in.video.i_height*3/2 + 1024 );
- if (NULL == p_sys->plane)
- {
- msg_Err( p_dec, "cannot alloc plane buffer" );
- free( p_sys );
- return VLC_EGENERIC;
- }
- p_dec->p_sys = p_sys;
- p_dec->pf_decode_video = DecodeVideo;
- memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
- init_data.unk1 = 11;
- init_data.w = p_dec->fmt_in.video.i_width ;
- init_data.h = p_dec->fmt_in.video.i_height ;
- init_data.unk3 = 0;
- init_data.unk2 = 0;
- init_data.subformat = (unsigned int*)p_vide[0];
- init_data.unk5 = 1;
- init_data.format = (unsigned int*)p_vide[1];
- /* first try to load linux dlls, if failed and we're supporting win32 dlls,
- then try to load the windows ones */
- bool b_so_opened = false;
- #ifdef WIN32
- g_decode_path="plugins\drv43260.dll";
- if( (p_sys->rv_handle = load_syms(p_dec, g_decode_path)) )
- b_so_opened = true;
- #else
- static const char psz_paths[] =
- {
- "/usr/lib/win32 "
- "/usr/lib/codecs "
- "/usr/local/RealPlayer8/Codecs "
- "/usr/RealPlayer8/Codecs "
- "/usr/lib/RealPlayer8/Codecs "
- "/opt/RealPlayer8/Codecs "
- "/usr/lib/RealPlayer9/users/Real/Codecs "
- "/usr/lib/RealPlayer10/codecs "
- "/usr/lib/RealPlayer10GOLD/codecs "
- "/usr/lib/helix/player/codecs "
- "/usr/lib64/RealPlayer8/Codecs "
- "/usr/lib64/RealPlayer9/users/Real/Codecs "
- "/usr/lib64/RealPlayer10/codecs "
- "/usr/lib64/RealPlayer10GOLD/codecs "
- "/usr/local/lib/codecs "
- "