ExtendedRead.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "main.h"
  2. #include "CDPlay.h"
  3. #include "DAEPlay.h"
  4. #include "MCIPlay.h"
  5. #include "WindacPlay.h"
  6. #include "api__in_cdda.h"
  7. #include "workorder.h"
  8. #include "CDDB.h"
  9. //returns handle!=0 if successful, 0 if error
  10. //size will return the final nb of bytes written to the output, -1 if unknown
  11. //TODO> add output format stuff (srate, nch, bps)
  12. extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
  13. {
  14. s_last_error = NULL;
  15. C_CDPlay *wp = NULL;
  16. int ret = 1;
  17. wchar_t device = 0;
  18. int track = -1;
  19. if (!ParseName(fn, device, track))
  20. return 0;
  21. if (playStatus[device].IsRipping() || (g_cdplay && g_cdplay->IsPlaying(device)))
  22. {
  23. wchar_t title[32] = {0};
  24. MessageBoxW(NULL, WASABI_API_LNGSTRINGW(IDS_CD_CURRENTLY_IN_USE),
  25. WASABI_API_LNGSTRINGW_BUF(IDS_DRIVE_IN_USE,title,32),
  26. MB_ICONWARNING | MB_OK);
  27. return -1;
  28. }
  29. // Get a ICddbDisc object for MusicID
  30. #ifndef IGNORE_API_GRACENOTE
  31. ICddbDiscPtr pDisc = NULL;
  32. OpenMusicIDWorkOrder();
  33. if (workorder)
  34. {
  35. MCIDEVICEID submitDev = 0;
  36. if (!CDOpen(&submitDev, device, L"MusicID")) submitDev = 0;
  37. if (submitDev)
  38. {
  39. DINFO info;
  40. ret = GetDiscID(submitDev, &info);
  41. CDClose(&submitDev);
  42. if (ret == 0)
  43. {
  44. wchar_t szTOC[2048] = {0};
  45. if (Cddb_CalculateTOC(&info, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
  46. Cddb_GetDiscFromCache(szTOC, &pDisc);
  47. }
  48. }
  49. }
  50. if (config_rip_veritas)
  51. {
  52. VeritasPlay *vp = new VeritasPlay(true);
  53. wp = vp;
  54. ret = wp->open(device, track);
  55. if (ret)
  56. {
  57. delete(wp);
  58. wp = NULL;
  59. }
  60. else if (workorder && pDisc != 0) // see if MusicID is interested
  61. {
  62. void *handle = 0;
  63. workorder->GetSigHandle(&handle, pDisc, track);
  64. vp->submitHandle = handle;
  65. }
  66. }
  67. #endif
  68. if (ret)
  69. {
  70. DAEPlay *dae = new DAEPlay;
  71. if (dae)
  72. {
  73. wp = dae;
  74. ret = wp->open(device, track);
  75. if (ret)
  76. {
  77. delete(wp);
  78. wp = NULL;
  79. }
  80. }
  81. else
  82. {
  83. wp = NULL;
  84. }
  85. }
  86. if (ret)
  87. {
  88. wp = new WindacPlay;
  89. if (wp->open(device, track))
  90. {
  91. delete(wp);
  92. return 0;
  93. }
  94. }
  95. if (size && wp)
  96. {
  97. double s = (double)wp->getlength() / 1000;
  98. s *= (44100 * 4);
  99. *size = (int)s;
  100. }
  101. if (srate) *srate = 44100;
  102. if (nch) *nch = 2;
  103. if (bps) *bps = 16;
  104. playStatus[device].RippingStarted();
  105. return (intptr_t)wp;
  106. }
  107. //returns nb of bytes read. -1 if read error (like CD ejected). if (ret<len), EOF is assumed
  108. extern "C" __declspec(dllexport) int winampGetExtendedRead_getData(intptr_t handle, char *dest, int len, int *killswitch)
  109. {
  110. s_last_error = NULL;
  111. C_CDPlay *wp = (C_CDPlay*)handle;
  112. return (wp ? wp->read(dest, len, killswitch) : -1);
  113. }
  114. extern "C" __declspec(dllexport) void winampGetExtendedRead_close(intptr_t handle)
  115. {
  116. s_last_error = NULL;
  117. C_CDPlay *wp = (C_CDPlay*)handle;
  118. if (wp)
  119. {
  120. playStatus[wp->g_drive].RippingStopped();
  121. delete wp;
  122. wp = 0;
  123. }
  124. }
  125. // extended info writing (used by gen_ml to update the local CDDB database after a burn)
  126. extern "C" __declspec(dllexport) char * winampGetExtendedRead_lasterror()
  127. {
  128. char * retval = s_last_error;
  129. s_last_error = NULL;
  130. return retval;
  131. }