[MPlayer-cygwin] compile mplayer as a single

李鑫 jackyxinli at gmail.com
Wed Jul 28 06:36:22 CEST 2010


I reference the project in_mplayer(http://sourceforge.net/projects/inmplayer),
which can compile mplayer as a single dll under mingw compile environment.
and i follow it's instructions, but failed. so, i write my own Makefile,
it's content listed below.

Makefile_dll
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DIRS = input libaf libao2 libass libdvdcss libdvdnav libdvdnav/vm
libdvdread4 libfaad2 libmpcodecs libmpdemux libmpeg2 libvo loader loader/dmo
loader/dshow mp3lib osdep stream stream/freesdp stream/librtsp
stream/realrtsp tremor vidix
ALL_OBJS = $(foreach DIR, $(DIRS), $(wildcard $(DIR)/*.o))

OBJS_MPLAYER = $(wildcard *.o)

INNER_LIBS = libavformat/libavformat.a libavcodec/libavcodec.a
libavutil/libavutil.a libpostproc/libpostproc.a libswscale/libswscale.a
/usr/lib/live/liveMedia/libliveMedia.a
/usr/lib/live/groupsock/libgroupsock.a
/usr/lib/live/UsageEnvironment/libUsageEnvironment.a
/usr/lib/live/BasicUsageEnvironment/libBasicUsageEnvironment.a

LIBS = -lwinmm -ffast-math -lws2_32 -liconv -lpng -lz -ljpeg -lungif
-lcdio_cdda -lcdio -lcdio_paranoia -lwinmm -L/mingw/lib -lfreetype -lz
-lfontconfig -lexpat -lfreetype -lz -liconv -lfribidi -lenca -lz -lbz2
-llzo2 -lmad -lspeex -Lc:/mingw/lib -ltheora -logg   -la52 -ldca -lmpcdec
-ladvapi32 -lole32  -lstdc++ -lopencore-amrnb -lopencore-amrwb -lxvidcore
-lm -lole32 -luuid    -L/mingw/lib  -lm  -lgdi32 -lcaca -lz -lSDL -lopengl32
-lgdi32 -lwinmm -lgdi32 -lfaac

mplayer.dll : $(OBJS_MPLAYER:mencoder.o=) $(ALL_OBJS) mplayer_dll.o
 dllwrap --output-lib=libmplayer.a --dllname=$@ --driver-name=gcc
$(OBJS_MPLAYER:mencoder.o=) $(ALL_OBJS) mplayer_dll.o $(INNER_LIBS) $(LIBS)
 cc -c -I. -Ic:/mingw/include/freetype2/freetype/ test_static.c
 cc -o test_static.exe $(OBJS_MPLAYER:mencoder.o=) $(ALL_OBJS) test_static.o
$(INNER_LIBS) $(LIBS)

test_static.exe : $(OBJS_MPLAYER:mencoder.o=) $(ALL_OBJS) test_static.o
 cc -o $@ $(OBJS_MPLAYER:mencoder.o=) $(ALL_OBJS) test_static.o
$(INNER_LIBS) $(LIBS)

mplayer_dll.o : mplayer_dll.c
 cc -c -I. mplayer_dll.c

test_static.o : test_static.c
 cc -c -I. test_static.c
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

create a new file named "mplayer_dll.c", content listed below:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdarg.h>
#include <windows.h>
#include "cpudetect.h"
#include "version.h"

extern int parse_codec_cfg(char *cfgfile);
extern void * open_stream(char* filename,char** options,int* file_format);
extern void * demux_open(void *stream,int file_format,int aid,int vid,int
sid,char* filename);
extern int init_best_audio_codec(void *sh_audio,char**
audio_codec_list,char** audio_fm_list);
extern int init_best_video_codec(void *sh_video,char**
video_codec_list,char** video_fm_list);
extern void *init_best_video_out(char** vo_list);
extern int video_read_properties(void *sh_video);
extern int demux_info_print(void *demuxer);
extern int video_read_frame(void * sh_video,float* frame_time_ptr,unsigned
char** start,int force_fps);
extern int decode_video(void *sh_video,unsigned char *start,int in_size,int
drop_frame);
extern int decode_audio(void *sh_audio,unsigned char *buf,int minlen,int
maxlen);
extern void* vf_open_filter(void* next, char *name, char **args);
extern void* append_filters(void* last);
unsigned long demuxer_get_time_length(void *demuxer);
extern void uninit_audio(void *sh_audio);
extern void uninit_video(void *sh_video);
extern void free_demuxer(void *demuxer);
extern int demux_seek(void *demuxer,float rel_seek_secs,int flags);
extern void free_stream(void *s);
extern int divx_quality;
extern char* dvd_device;
extern int dvd_chapter, dvd_last_chapter, dvd_angle;
extern int stream_enable_cache(void *stream,int size,int min,int prefill);
__declspec(dllexport) void exp_init()
{
  GetCpuCaps(&gCpuCaps);
}
__declspec(dllexport) int exp_parse_codec_cfg(char *cfgfile)
{
    return parse_codec_cfg(cfgfile);
}
__declspec(dllexport) void* exp_open_stream(char* filename,char**
options,int* file_format)
{
    return open_stream(filename,options,file_format);
}
__declspec(dllexport) void* exp_demux_open(void *stream,int file_format,int
aid,int vid,int sid,char* filename)
{
    return demux_open(stream,file_format,aid,vid,sid,filename);
}
__declspec(dllexport) int exp_init_best_audio_codec(void *sh_audio,char**
audio_codec_list,char** audio_fm_list)
{
    return init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list);
}
__declspec(dllexport) int exp_init_best_video_codec(void *sh_video,char**
video_codec_list,char** video_fm_list)
{
    return init_best_video_codec(sh_video,video_codec_list,video_fm_list);
}
__declspec(dllexport) void *exp_init_best_video_out(char** vo_list)
{
    return init_best_video_out(vo_list);
}
__declspec(dllexport) int exp_video_read_properties(void *sh_video)
{
    return video_read_properties(sh_video);
}
__declspec(dllexport) int exp_demux_info_print(void *demuxer)
{
    return demux_info_print(demuxer);
}
__declspec(dllexport) int exp_video_read_frame(void * sh_video,float*
frame_time_ptr,unsigned char** start,int force_fps)
{
    return video_read_frame(sh_video,frame_time_ptr,start,force_fps);
}
__declspec(dllexport) int exp_decode_video(void *sh_video,unsigned char
*start,int in_size,int drop_frame)
{
    return decode_video(sh_video,start,in_size,drop_frame);
}
__declspec(dllexport) int exp_decode_audio(void *sh_audio,unsigned char
*buf,int minlen,int maxlen)
{
    return decode_audio(sh_audio,buf,minlen,maxlen);
}
__declspec(dllexport) void *exp_vf_open_filter(void* next, char *name, char
**args)
{
    return vf_open_filter(next,name,args);
}
__declspec(dllexport) void *exp_append_filters(void* last)
{
    return append_filters(last);
}
__declspec(dllexport) unsigned long exp_demuxer_get_time_length(void*
demuxer)
{
    return demuxer_get_time_length(demuxer);
}
__declspec(dllexport) void exp_uninit_audio(void* sh_audio)
{
    uninit_audio(sh_audio);
}
__declspec(dllexport) void exp_uninit_video(void* sh_video)
{
    uninit_video(sh_video);
}
__declspec(dllexport) void exp_free_demuxer(void* d)
{
    free_demuxer(d);
}
__declspec(dllexport) int exp_demux_seek(void *demuxer,float
rel_seek_secs,int flags)
{
    return demux_seek(demuxer,rel_seek_secs,flags);
}
__declspec(dllexport) void exp_free_stream(void* s)
{
    free_stream(s);
}
__declspec(dllexport) void exp_set_pp(int q) //0...6   0=disabled  6=max
{
    divx_quality=q;
}
__declspec(dllexport) void exp_set_dvd_device(char *dvd)
{
    static char dev[MAX_PATH];
    strcpy(dev,dvd);
    dvd_device=dev;
}
__declspec(dllexport) void exp_set_dvd_chapter(int chapter, int
last_chapter, int angle)
{
    dvd_chapter=chapter;
    dvd_last_chapter=last_chapter;
    dvd_angle=angle;
}
__declspec(dllexport) int exp_stream_enable_cache(void *stream,int size,int
min,int prefill)
{
    return stream_enable_cache(stream,size,min,prefill);
}
__declspec(dllexport) char *exp_get_version()
{
    return VERSION;
}
__declspec(dllexport) char * exp_get_dbgtext()
{
    return "";
}
__declspec(dllexport) void exp_reset_dbgtext()
{
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

i modified file "mplayer.h", and "#define DISABLE_MAIN" at end of file, and
save it.

i do those commands in mingw/msys environment
$./configure --disable-debug --disable-mencoder --disable-sdl
--disable-pthreads --enable-w32threads
$make
$make -f Makefile_dll

then i got a single dll file, i wrote test code like below:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
int main(int argc, char* argv[])
{
 stream_t* stream = NULL;
 demuxer_t* demuxer = NULL;
 char* filename = "d:\\Music\\01.mp3";
 int file_format = 0;
 sh_audio_t *sh_audio = NULL;
 sh_video_t *sh_video = NULL;
 demux_stream_t *d_audio = NULL;
 demux_stream_t *d_video = NULL;

 HMODULE hModule = LoadLibrary("mplayer.dll");
 if(hModule)
 {
  typedef void* (*open_stream)(char* filename,char** options,int*
file_format);
  typedef void* (*demux_open)(void *stream,int file_format,int aid,int
vid,int sid,char* filename);
  open_stream _open_stream = (open_stream)GetProcAddress(hModule,
"exp_open_stream");
  demux_open _demux_open = (demux_open)GetProcAddress(hModule,
"exp_demux_open");
  printf("%p %p\n", _open_stream, _demux_open);
  stream = (stream_t*)_open_stream(filename, 0, &file_format);
  demuxer = (demuxer_t*)_demux_open(stream, file_format, -1, -1, -1,
filename);
  d_audio=demuxer->audio;
  d_video=demuxer->video;
  if(d_audio)
   sh_audio=d_audio->sh;
  printf("stream=%p, demuxer=%p, d_audio=%p, d_video=%p, sh_audio=%p\n",
   stream, demuxer, d_audio, d_video, sh_audio);

  FreeLibrary(hModule);
 }
 return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

when i run test code, the result displaied is not right, d_audio always is
NULL, but use gdb debug mplayer.exe, which is not NULL. is someone could
help me?
and i attached Makefile what i created in a attachment.

best regards,
jacky_zz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer_dll.zip
Type: application/zip
Size: 4235 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-cygwin/attachments/20100728/4e4ab632/attachment.zip>


More information about the MPlayer-cygwin mailing list