transcoder_imp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef _TRANSCODER_IMP_H_
  2. #define _TRANSCODER_IMP_H_
  3. #include <windows.h>
  4. #include <windowsx.h>
  5. #include "..\..\General\gen_ml/itemlist.h"
  6. #include "../winamp/wa_ipc.h"
  7. #include "..\..\General\gen_ml/ml.h"
  8. #include "DeviceView.h"
  9. #include "nu/AutoWide.h"
  10. #include "nu/AutoChar.h"
  11. #include "transcoder.h"
  12. #include "resource1.h"
  13. #include <wchar.h>
  14. #include <stdio.h>
  15. #include <vector>
  16. #define ENCODER_HIGHLY_PREFERRED 2
  17. #define ENCODER_PREFERRED 1
  18. #define ENCODER_NO_PREFERENCE 0
  19. #define ENCODER_NOT_PREFERRED -1
  20. #define ENCODER_DO_NOT_USE -2
  21. class EncodableFormat
  22. {
  23. public:
  24. unsigned int fourcc;
  25. wchar_t *desc;
  26. EncodableFormat(unsigned int fourcc,wchar_t *desc) :
  27. fourcc(fourcc)
  28. {
  29. this->desc = _wcsdup(desc);
  30. }
  31. ~EncodableFormat()
  32. {
  33. free(desc);
  34. }
  35. };
  36. typedef std::vector<EncodableFormat*> FormatList;
  37. class TranscoderImp : public Transcoder
  38. {
  39. protected:
  40. bool TranscoderDisabled;
  41. bool transrate;
  42. int transratethresh;
  43. bool translossless;
  44. wchar_t caption[100];
  45. wchar_t inifile[MAX_PATH];
  46. char inifileA[MAX_PATH];
  47. HINSTANCE hInst;
  48. HWND winampParent;
  49. HWND callbackhwnd;
  50. std::vector<unsigned int> outformats;
  51. FormatList formats;
  52. C_Config * config;
  53. convertFileStructW cfs;
  54. void (*callback)(void * callbackContext, wchar_t * status);
  55. void* callbackContext;
  56. bool convertDone;
  57. Device *device;
  58. void TranscodeProgress(int pc, bool done);
  59. bool StartTranscode(unsigned int destformat, wchar_t *inputFile, wchar_t *outputfile, bool test=false); // returns true if started ok.
  60. void EndTranscode();
  61. bool TestTranscode(wchar_t * file, unsigned int destformat);
  62. bool FormatAcceptable(wchar_t * format);
  63. bool FormatAcceptable(unsigned int format);
  64. int GetOutputFormat(wchar_t * file, int *bitrate=NULL);
  65. void AddEncodableFormat(const char *desc, unsigned int fourcc);
  66. void ReloadConfig();
  67. public:
  68. TranscoderImp(HWND winampParent, HINSTANCE hInst, C_Config * config, Device *device);
  69. virtual ~TranscoderImp();
  70. virtual void LoadConfigProfile(wchar_t *profile);
  71. virtual void AddAcceptableFormat(wchar_t *format);
  72. virtual void AddAcceptableFormat(unsigned int format);
  73. // done when file is added to transfer queue
  74. // returns:
  75. // -1 for can't transcode
  76. // output file size estimate if can transcode
  77. // if ext is supplied, it should be a buffer with space for 5 characters, and will be filled with
  78. // the output file type file extention, eg, L".mp3"
  79. virtual int CanTranscode(wchar_t *file, wchar_t *ext = NULL, int length = -1);
  80. virtual bool ShouldTranscode(wchar_t * file); // false if no transcoding needed
  81. virtual int TranscodeFile(wchar_t *inputFile, wchar_t *outputFile, int *killswitch, void (*callback)(void * callbackContext, wchar_t * status), void* callbackContext, wchar_t * caption=L"Transcoding %d%%");
  82. // done just before transfer OR in background after file is added to queue
  83. // extention is added to outputFile, allow 5 extra chars
  84. // callback, callbackcontext and killswitch should be similar to those passed by ml_pmp
  85. //virtual int TranscodeFileASync(wchar_t *inputFile, wchar_t *outputFile, int *killswitch, void (*callback)(void * callbackContext, wchar_t * status), void* callbackContext){return 0;};
  86. //asynchronous version of the above, details obvious
  87. virtual void GetTempFilePath(const wchar_t *ext, wchar_t *filename); // get a filename which can be used as a staging area. ext should be, i.e L".mp3"
  88. /* remember to call DestroyWindow on the return value when parent recieves the WM_DESTROY message.
  89. use like this:
  90. transcoderConfig = TranscoderImp::ConfigureTranscoder(hwndDlg,L"ml_pmp");
  91. RECT r;
  92. GetWindowRect(GetDlgItem(hwndDlg,IDC_PLACEHOLDER),&r);
  93. ScreenToClient(hwndDlg,(LPPOINT)&r);
  94. SetWindowPos(transcoderConfig,NULL,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  95. ShowWindow(transcoderConfig,SW_SHOWNA);
  96. where IDC_PLACEHOLDER is an invisible group box of size 259x176 (in dialog units)
  97. */
  98. static void* ConfigureTranscoder(wchar_t * configProfile, HWND winampParent, C_Config * config, Device *dev);
  99. static BOOL transcodeconfig_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  100. static void init();
  101. static void quit();
  102. friend LRESULT CALLBACK TranscodeMsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  103. };
  104. #endif //_TRANSCODER_IMP_H_