Update of /cvsroot/audacity/audacity-src/src In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv16096/src
Modified Files: FFmpeg.cpp FFmpeg.h Log Message: New mega-way to load FFmpeg libraries. Loads only avformat, then looks which modules got attached to process as a result to find paths to avcodec and avutil. Also recognizes statically-linked variants of avformat and loads only from it (untested!) Index: FFmpeg.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/FFmpeg.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- FFmpeg.cpp 4 Jun 2008 19:12:17 -0000 1.3 +++ FFmpeg.cpp 5 Jun 2008 15:48:45 -0000 1.4 @@ -34,13 +34,19 @@ FFmpegLibs::FFmpegLibs(bool showerr) { mLibsLoaded = false; - + mStatic = false; refcount = 1; + avformat = avcodec = avutil = NULL; } FFmpegLibs::~FFmpegLibs() { - + if (avformat) delete avformat; + if (!mStatic) + { + if (avcodec) delete avcodec; + if (avutil) delete avutil; + } }; bool FFmpegLibs::LoadLibs(wxWindow *parent, bool showerr) @@ -54,10 +60,8 @@ // Try loading using system search paths if (!ValidLibsLoaded()) { - mLibAVCodecPath = GetLibAVCodecName(); mLibAVFormatPath = GetLibAVFormatName(); - mLibAVUtilPath = GetLibAVUtilName(); - mLibsLoaded = InitLibs(mLibAVCodecPath, mLibAVFormatPath, mLibAVUtilPath,showerr); + mLibsLoaded = InitLibs(mLibAVFormatPath,showerr); } // Oh well, just give up @@ -73,38 +77,102 @@ return mLibsLoaded; } -bool FFmpegLibs::InitLibs(wxString libpath_codec, wxString libpath_format, wxString libpath_util, bool showerr) +bool FFmpegLibs::InitLibs(wxString libpath_format, bool showerr) { + //Initially we don't know where's the avcodec and avutl libs + wxString libpath_codec(wxT("")); + wxString libpath_util(wxT("")); bool gotError = false; + #if defined(__WXMSW__) + //On Windows force system to show error messages (as they are + //more informative than wxMessages). unsigned int erm = SetErrorMode(showerr ? 0 : SEM_FAILCRITICALERRORS); #endif - if (!avformat.IsLoaded() && !gotError) + avformat = new wxDynamicLibrary(); + if (!avformat->IsLoaded() && !gotError) { - gotError = !avformat.Load(libpath_format, wxDL_LAZY); + gotError = !avformat->Load(libpath_format, wxDL_LAZY); } - if (!avcodec.IsLoaded() && !gotError) + //avformat loaded successfully? + if (!gotError) { - gotError = !avcodec.Load(libpath_codec, wxDL_LAZY); + //Get the list of all loaded modules and it's length + wxDynamicLibraryDetailsArray loaded = avformat->ListLoaded(); + int loadsize = loaded.size(); + for (int i = 0; i < loadsize; i++) + { + _wxObjArraywxDynamicLibraryDetailsArray litem = loaded.Item(i); + //Get modules' path and base name + wxString libpath = litem.GetPath(); + wxString libname = litem.GetName(); + //Match name against a pattern to find avcodec and avutil +#if defined(__WXMSW__) + if (libname.Matches(wxT("*avcodec*.dll*"))) +#else + if (libname.Matches(wxT("*avcodec*.so*"))) +#endif + { + wxLogMessage(wxT("Found avcodec: %s"),libpath); + libpath_codec = libpath; + } +#if defined(__WXMSW__) + else if (libname.Matches(wxT("*avutil*.dll*"))) +#else + else if (libname.Matches(wxT("*avutil*.so*"))) +#endif + { + wxLogMessage(wxT("Found avutil: %s"),libpath); + libpath_util = libpath; + } + } + //avformat loaded all right. If it didn't linked two other + //libs to itself in process, then it's statically linked. + //"or" operator ensures that we won't count misnamed statically linked + //avformat library as dynamic one. + if ((libpath_codec.CompareTo(wxT("")) == 0) + || (libpath_util.CompareTo(wxT("")) == 0)) + { + mStatic = true; + } + else mStatic = false; } - if (!avutil.IsLoaded() && !gotError) + if (!mStatic) { - gotError = !avutil.Load(libpath_util, wxDL_LAZY); + //Load other two libs + avcodec = new wxDynamicLibrary(); + if (!avcodec->IsLoaded() && !gotError) + { + gotError = !avcodec->Load(libpath_codec, wxDL_LAZY); + } + avutil = new wxDynamicLibrary(); + if (!avutil->IsLoaded() && !gotError) + { + gotError = !avutil->Load(libpath_util, wxDL_LAZY); + } } if ( gotError ) { if ( showerr ) wxMessageBox(wxSysErrorMsg()); #if defined(__WXMSW__) + //On Windows - return error mode to normal SetErrorMode(erm); #endif return false; } + if (mStatic) + { + //If it's static library, load everything from it + avcodec = avformat; + avutil = avformat; + } + INITDYN(avformat,av_register_all); INITDYN(avformat,av_open_input_file); INITDYN(avformat,av_find_stream_info); @@ -142,9 +210,11 @@ INITDYN(avutil,av_log_default_callback); #if defined(__WXMSW__) + //Return error mode to normal SetErrorMode(erm); #endif + //FFmpeg initialization this->avcodec_init(); this->avcodec_register_all(); this->av_register_all(); @@ -153,9 +223,12 @@ void FFmpegLibs::FreeLibs() { - avcodec.Unload(); - avformat.Unload(); - avutil.Unload(); + if (avformat) avformat->Unload(); + if (!mStatic) + { + if (avcodec) avcodec->Unload(); + if (avutil) avutil->Unload(); + } return; } #endif //USE_FFMPEG Index: FFmpeg.h =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/FFmpeg.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- FFmpeg.h 4 Jun 2008 21:15:05 -0000 1.7 +++ FFmpeg.h 5 Jun 2008 15:48:45 -0000 1.8 @@ -29,7 +29,7 @@ #include <avformat.h> } -#define INITDYN(w,f) if ((*(void**)&this->f=(void*)w.GetSymbol(wxT(#f))) == NULL) return false +#define INITDYN(w,f) if ((*(void**)&this->f=(void*)w->GetSymbol(wxT(#f))) == NULL) return false class FFmpegLibs { @@ -75,42 +75,22 @@ bool ValidLibsLoaded(); /* initialize the library interface */ - bool InitLibs(wxString libpath_codec, wxString libpath_format, wxString libpath_util, bool showerr); + bool InitLibs(wxString libpath_codec, bool showerr); void FreeLibs(); /* note these values are for Windows only - Mac and Unix have their own * sections elsewhere */ //\todo { Section for Mac and *nix } #if defined(__WXMSW__) - wxString GetLibAVCodecName() - { - return wxT("avcodec.dll"); - } - wxString GetLibAVFormatName() { return wxT("avformat.dll"); } - - wxString GetLibAVUtilName() - { - return wxT("avutil.dll"); - } #else - wxString GetLibAVCodecName() - { - return wxT("libavcodec.so"); - } - wxString GetLibAVFormatName() { return wxT("libavformat.so"); } - - wxString GetLibAVUtilName() - { - return wxT("libavutil.so"); - } #endif //Ugly reference counting. I thought of using wxStuff for that, //but decided that wx reference counting is not useful, since @@ -119,14 +99,13 @@ private: - wxString mLibAVCodecPath; wxString mLibAVFormatPath; - wxString mLibAVUtilPath; - - wxDynamicLibrary avcodec; - wxDynamicLibrary avformat; - wxDynamicLibrary avutil; + + wxDynamicLibrary *avformat; + wxDynamicLibrary *avcodec; + wxDynamicLibrary *avutil; + bool mStatic; bool mLibsLoaded; }; #endif //USE_FFMPEG ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Audacity-cvs mailing list Audacity-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/audacity-cvs