Permalink
Browse files

Merge pull request #981 from cptspiff/cdripjobs

Refactor CD ripper code
  • Loading branch information...
2 parents cdd9c64 + a3d7289 commit 09bd1dfbe819dc59098779a0544dc6578d2cea86 Arne Morten Kvarving committed Jun 1, 2012
@@ -1392,7 +1392,7 @@
<ClCompile Include="..\..\xbmc\addons\Scraper.cpp" />
<ClCompile Include="..\..\xbmc\addons\ScreenSaver.cpp" />
<ClCompile Include="..\..\xbmc\addons\Visualisation.cpp" />
- <ClCompile Include="..\..\xbmc\cdrip\CDDAReader.cpp" />
+ <ClCompile Include="..\..\xbmc\cdrip\CDDARipJob.cpp" />
<ClCompile Include="..\..\xbmc\cdrip\CDDARipper.cpp" />
<ClCompile Include="..\..\xbmc\cdrip\Encoder.cpp" />
<ClCompile Include="..\..\xbmc\cdrip\EncoderFlac.cpp" />
@@ -2189,7 +2189,7 @@
<ClInclude Include="..\..\xbmc\addons\Scraper.h" />
<ClInclude Include="..\..\xbmc\addons\ScreenSaver.h" />
<ClInclude Include="..\..\xbmc\addons\Visualisation.h" />
- <ClInclude Include="..\..\xbmc\cdrip\CDDAReader.h" />
+ <ClInclude Include="..\..\xbmc\cdrip\CDDARipJob.h" />
<ClInclude Include="..\..\xbmc\cdrip\CDDARipper.h" />
<ClInclude Include="..\..\xbmc\cdrip\DllLameenc.h" />
<ClInclude Include="..\..\xbmc\cdrip\DllFlacEnc.h" />
@@ -849,10 +849,10 @@
<ClCompile Include="..\..\xbmc\music\Song.cpp">
<Filter>music</Filter>
</ClCompile>
- <ClCompile Include="..\..\xbmc\cdrip\CDDAReader.cpp">
+ <ClCompile Include="..\..\xbmc\cdrip\CDDARipper.cpp">
<Filter>cdrip</Filter>
</ClCompile>
- <ClCompile Include="..\..\xbmc\cdrip\CDDARipper.cpp">
+ <ClCompile Include="..\..\xbmc\cdrip\CDDARipJob.cpp">
<Filter>cdrip</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\cdrip\Encoder.cpp">
@@ -3342,7 +3342,7 @@
<ClInclude Include="..\..\xbmc\cdrip\EncoderWav.h">
<Filter>cdrip</Filter>
</ClInclude>
- <ClInclude Include="..\..\xbmc\cdrip\CDDAReader.h">
+ <ClInclude Include="..\..\xbmc\cdrip\CDDARipJob.h">
<Filter>cdrip</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\cdrip\CDDARipper.h">
View
@@ -76,8 +76,7 @@ void CAutorun::ExecuteAutorun(const CStdString& path, bool bypassSettings, bool
if (g_guiSettings.GetInt("audiocds.autoaction") == AUTOCD_RIP &&
pInfo->IsAudio(1) && !g_settings.GetCurrentProfile().musicLocked())
{
- CCDDARipper ripper;
- ripper.RipCD();
+ CCDDARipper::GetInstance().RipCD();
}
else
#endif
View
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "system.h"
-
-#ifdef HAS_CDDA_RIPPER
-
-#include "CDDAReader.h"
-#include <cdio/cdio.h>
-#include "utils/log.h"
-
-#define SECTOR_COUNT 52
-
-CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
-{
- m_sRipBuffer[0].pbtStream = NULL;
- m_sRipBuffer[1].pbtStream = NULL;
-
- m_iCurrentBuffer = 0;
-}
-
-CCDDAReader::~CCDDAReader()
-{
- m_bStop = true;
- StopThread();
-
- if (m_sRipBuffer[0].pbtStream) delete []m_sRipBuffer[0].pbtStream;
- if (m_sRipBuffer[1].pbtStream) delete []m_sRipBuffer[1].pbtStream;
-}
-
-bool CCDDAReader::Init(const char* strFileName)
-{
- // Open the Ripper session
- if (!m_fileCdda.Open(strFileName))
- return false;
-
- CLog::Log(LOGINFO, "%s, Sectors %"PRId64, strFileName, m_fileCdda.GetLength() / CDIO_CD_FRAMESIZE_RAW);
-
- // allocate 2 buffers
- // read around 128k per chunk. This makes the cd reading less noisy.
- m_sRipBuffer[0].pbtStream = new BYTE[CDIO_CD_FRAMESIZE_RAW * SECTOR_COUNT];
- m_sRipBuffer[1].pbtStream = new BYTE[CDIO_CD_FRAMESIZE_RAW * SECTOR_COUNT];
-
- Create(false, THREAD_MINSTACKSIZE);
-
- return true;
-}
-
-bool CCDDAReader::DeInit()
-{
- m_bStop = true;
- StopThread();
-
- m_iCurrentBuffer = 0;
-
- // free buffers
- if (m_sRipBuffer[0].pbtStream) delete []m_sRipBuffer[0].pbtStream;
- m_sRipBuffer[0].pbtStream = NULL;
- if (m_sRipBuffer[1].pbtStream) delete []m_sRipBuffer[1].pbtStream;
- m_sRipBuffer[1].pbtStream = NULL;
-
- // Close the Ripper session
- m_fileCdda.Close();
-
- return true;
-}
-
-int CCDDAReader::GetPercent()
-{
- return (int)((m_fileCdda.GetPosition()*100) / m_fileCdda.GetLength());
-}
-
-int CCDDAReader::GetTrackLength()
-{
- return (int)m_fileCdda.GetLength();
-}
-
-int CCDDAReader::ReadChunk()
-{
- // Read data
- DWORD dwBytesRead = m_fileCdda.Read(m_sRipBuffer[m_iCurrentBuffer].pbtStream, SECTOR_COUNT * CDIO_CD_FRAMESIZE_RAW);
- if (dwBytesRead == 0)
- {
- m_sRipBuffer[m_iCurrentBuffer].lBytesRead = 0;
- return CDDARIP_ERR;
- }
-
- m_sRipBuffer[m_iCurrentBuffer].lBytesRead = dwBytesRead;
-
- if (m_fileCdda.GetPosition() == m_fileCdda.GetLength()) return CDDARIP_DONE;
-
- return CDDARIP_OK;
-}
-
-void CCDDAReader::Process()
-{
- // fill first buffer
- m_iCurrentBuffer = 0;
-
- m_sRipBuffer[0].iRipError = ReadChunk();
- m_hDataReadyEvent.Set();
-
- while (!m_bStop)
- {
- // wait until someone called GetData()
- if (AbortableWait(m_hReadEvent) == WAIT_SIGNALED)
- {
- // event generated by m_hReadEvent, continue
- // switch buffer and start reading in this one
- m_iCurrentBuffer = m_iCurrentBuffer ? 0 : 1;
- m_sRipBuffer[m_iCurrentBuffer].iRipError = ReadChunk();
-
- m_hDataReadyEvent.Set();
- }
- }
-}
-
-int CCDDAReader::GetData(BYTE** stream, long& lBytes)
-{
- // wait until we are sure we have a buffer that is filled
- AbortableWait(m_hDataReadyEvent);
-
- int iError = m_sRipBuffer[m_iCurrentBuffer].iRipError;
- *stream = m_sRipBuffer[m_iCurrentBuffer].pbtStream;
- lBytes = m_sRipBuffer[m_iCurrentBuffer].lBytesRead;
-
- // got data buffer, signal thread so it can start filling the other buffer
- m_hReadEvent.Set();
- return iError;
-}
-
-#endif
View
@@ -1,70 +0,0 @@
-#ifndef _CCDDAREADER_H
-#define _CCDDAREADER_H
-
-/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#define CDDARIP_OK 0
-#define CDDARIP_ERR 1
-#define CDDARIP_DONE 2
-
-#include "threads/Thread.h"
-
-#include "FileItem.h"
-#include "filesystem/File.h"
-#include "threads/Event.h"
-
-struct RipBuffer
-{
- int iRipError;
- long lBytesRead;
- BYTE* pbtStream;
- HANDLE hEvent;
-};
-
-class CCDDAReader : public CThread
-{
-public:
- CCDDAReader();
- virtual ~CCDDAReader();
- int GetData(BYTE** stream, long& lBytes);
- bool Init(const char* strFileName);
- bool DeInit();
- int GetPercent();
- int GetTrackLength();
-protected:
- void Process();
- int ReadChunk();
-
- long m_lBufferSize;
-
- RipBuffer m_sRipBuffer[2]; // hold space for 2 buffers
- int m_iCurrentBuffer; // 0 or 1
-
- CEvent m_hReadEvent; // data is fetched
- CEvent m_hDataReadyEvent; // data is ready to be fetched
-
- bool m_iInitialized;
-
- XFILE::CFile m_fileCdda;
-};
-
-#endif // _CCDDAREADER_H
Oops, something went wrong.

0 comments on commit 09bd1df

Please sign in to comment.