home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / mism.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  4.9 KB  |  198 lines

  1. /* 
  2.  *  mism.cpp 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - December 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24.  
  25. #include "RunState.h"
  26. #include "mism.h"
  27. extern TConfig   o;
  28. extern TRunState rs;
  29. extern HWND hMainWnd;
  30. extern void EnableMenu();
  31. extern void DisableMenu();
  32.  
  33. extern HINSTANCE hInst;
  34. extern char          program_directory[MAX_PATH];
  35.  
  36. typedef CArr<char> myString;
  37.  
  38. static CArr<HINSTANCE>    vhModule;
  39.  
  40. char *GetString(int x)
  41.   return GS(x); 
  42. }
  43.  
  44.  
  45. static HINSTANCE LoadMismModule( char *szTemp, LPFMMismInfo mismInfo )
  46. {
  47.   fmGetMismPtr          fmGetMism;
  48.   HINSTANCE hModule;
  49.  
  50.   if( hModule = LoadLibrary( szTemp ) )
  51.   { 
  52.     if( fmGetMism = (fmGetMismPtr)GetProcAddress( hModule, "fmGetMism" ) )
  53.     { 
  54.           fmGetMism( mismInfo );
  55.          
  56.           if( mismInfo->dwVersion != FM_MISM_VERSION ) {
  57.             FreeLibrary( hModule );
  58.             return NULL;
  59.           }
  60.           // Initialize Mism
  61.           FMMismStdParms params;
  62.           params.GetString = GetString;
  63.           params.hInst     = hInst;
  64.           params.hWnd      = hMainWnd;
  65.           params.lurkSize  = rs.conf.lurk_size;
  66.           mismInfo->Init( ¶ms );
  67.           return hModule;
  68.     }
  69.   }
  70.   return NULL;
  71. }
  72.  
  73.  
  74. bool StartMism()
  75. {
  76.   WIN32_FIND_DATA find_data;
  77.   char     directory[MAX_PATH];
  78.   myString strTemp;
  79.   // initialize strTemp
  80.   strTemp.SetArraySize( MAX_PATH );
  81.  
  82.   HINSTANCE hModule; 
  83.   HANDLE   search_handle;
  84.   int      i;
  85.   FMMismInfo mismInfo;
  86.  
  87.   
  88.   sprintf(directory, "%s\\*.mism.flask", program_directory );
  89.   
  90.   rs.AvalInputs.EmptyArray();
  91.  
  92.   vhModule.EmptyArray();
  93.  
  94.  
  95.   i=0;
  96.   search_handle = FindFirstFile(directory, &find_data);
  97.   if(search_handle==INVALID_HANDLE_VALUE){
  98.     rs.AvalInputs.EmptyArray();
  99.   }
  100.   else{
  101.     sprintf(strTemp.GetData(),"%s\\%s", program_directory, find_data.cFileName );
  102.     if( hModule = LoadMismModule( strTemp.GetData(), &mismInfo ) )
  103.     {
  104.       // Store module instance
  105.       vhModule.AddItem( &hModule );
  106.       // Store mism info
  107.       rs.AvalInputs.AddItem( &mismInfo );
  108.     }
  109.     while( FindNextFile(search_handle, &find_data ) ){
  110.       sprintf(strTemp.GetData(),"%s\\%s", program_directory, find_data.cFileName );
  111.     if( hModule = LoadMismModule( strTemp.GetData(), &mismInfo ) )
  112.     {
  113.       // Store module instance
  114.       vhModule.AddItem( &hModule );
  115.       // Store mism info
  116.       rs.AvalInputs.AddItem( &mismInfo );
  117.     }
  118.     }
  119.     FindClose(search_handle);
  120.   }
  121.   return rs.AvalInputs.GetCount() > 0;
  122. }
  123.  
  124. bool StopMism()
  125. {
  126.   // Deinitialize Misms
  127.   for(int i=0; i<rs.AvalInputs.GetCount(); i++)
  128.     rs.AvalInputs[i].DeInit();
  129.  
  130.   // Deinitialize Libraries
  131.   for(i=0; i<vhModule.GetCount(); i++)
  132.     FreeLibrary( vhModule[i] );
  133.  
  134.   return true;
  135. }
  136.  
  137. // Helper functions
  138. bool GetFirstVideoId( fmStreamIds *streamIds , fmStreamId *Id)
  139. {
  140.   for( int i=0; i<streamIds->idCount; i++ )
  141.   {
  142.     if(streamIds->vIds[i].streamId>= 0xE0 && streamIds->vIds[i].streamId <= 0xEF)
  143.     {
  144.       *Id = streamIds->vIds[i];
  145.       return true;
  146.     }
  147.   }
  148.   return false;
  149. }
  150.  
  151. bool GetFirstAudioId( fmStreamIds *streamIds, fmStreamId *Id, int *nIdx)
  152. {
  153.   for( int i=0; i<streamIds->idCount; i++ )
  154.   {
  155.     if(streamIds->vIds[i].streamId>= 0xC0 && streamIds->vIds[i].streamId <= 0xDF)
  156.     {
  157.       *Id = streamIds->vIds[i];
  158.       *nIdx  = i;
  159.       return true;
  160.     }
  161.     if(streamIds->vIds[i].streamId== 0xBD)
  162.     {
  163.       if( streamIds->vIds[i].subStreamId >= 0x80 && streamIds->vIds[i].subStreamId  <= 0x87 )
  164.       {
  165.         *Id = streamIds->vIds[i];
  166.         *nIdx  = i;
  167.         return true;
  168.       }
  169.     }
  170.   }
  171.   return false;
  172. }
  173.  
  174. bool GetFirstSubpicId( fmStreamIds *streamIds, fmStreamId *Id)
  175. {
  176.   for( int i=0; i<streamIds->idCount; i++ )
  177.   {
  178.     if(streamIds->vIds[i].streamId== 0xBD)
  179.     {
  180.       if( streamIds->vIds[i].subStreamId >= 0x20 && streamIds->vIds[i].subStreamId  <= 0x2F )
  181.       {
  182.         *Id = streamIds->vIds[i];
  183.         return true;
  184.       }
  185.     }
  186.   }
  187.   return false;
  188. }
  189.  
  190. bool MismIsAudioId(fmStreamId *Id)
  191. {
  192.   if(!Id)
  193.     return false;
  194.   return MismIsAudioTrack(Id->streamId, Id->subStreamId);
  195. }
  196.  
  197.