Skip to content

Commit

Permalink
Add CDDA demuxer
Browse files Browse the repository at this point in the history
OMXPlayer use DVDFactoryDemuxer for every media. With new CDDA demuxer RPi xbmc plays audio CDs.
  • Loading branch information
hubertmis committed May 4, 2013
1 parent 2b458e0 commit 6ee39a7
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 0 deletions.
2 changes: 2 additions & 0 deletions project/VS2010Express/XBMC.vcxproj
Expand Up @@ -397,6 +397,7 @@
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Audio\DVDAudioCodecPassthrough.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Video\CrystalHD.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxBXA.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxCDDA.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxPVRClient.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDInputStreams\DVDInputStreamBluray.cpp" />
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDInputStreams\DVDInputStreamPVRManager.cpp" />
Expand Down Expand Up @@ -1048,6 +1049,7 @@
<ClInclude Include="..\..\xbmc\cores\AudioEngine\Utils\AEWAVLoader.h" />
<ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Audio\DVDAudioCodecPassthrough.h" />
<ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxBXA.h" />
<ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxCDDA.h" />
<ClInclude Include="..\..\xbmc\cores\paplayer\PCMCodec.h" />
<ClInclude Include="..\..\xbmc\dialogs\GUIDialogKeyboardGeneric.h" />
<ClInclude Include="..\..\xbmc\DbUrl.h" />
Expand Down
6 changes: 6 additions & 0 deletions project/VS2010Express/XBMC.vcxproj.filters
Expand Up @@ -3030,6 +3030,9 @@
<ClCompile Include="..\..\xbmc\interfaces\json-rpc\FavouritesOperations.cpp">
<Filter>interfaces\json-rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxCDDA.cpp">
<Filter>cores\dvdplayer\DVDDemuxers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
Expand Down Expand Up @@ -5933,6 +5936,9 @@
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\FavouritesOperations.h">
<Filter>interfaces\json-rpc</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDDemuxers\DVDDemuxCDDA.h">
<Filter>cores\dvdplayer\DVDDemuxers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
Expand Down
180 changes: 180 additions & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxCDDA.cpp
@@ -0,0 +1,180 @@
/*
* Copyright (C) 2013 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, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "DVDInputStreams/DVDInputStream.h"
#include "DVDDemuxCDDA.h"
#include "DVDDemuxUtils.h"
#include "utils/log.h"
#include "../DVDClock.h"

// CDDA audio demuxer based on AirTunes audio Demuxer.

using namespace std;

class CDemuxStreamAudioCDDA
: public CDemuxStreamAudio
{
public:
void GetStreamInfo(string& strInfo)
{
strInfo = "pcm";
}
};

CDVDDemuxCDDA::CDVDDemuxCDDA() : CDVDDemux()
{
m_pInput = NULL;
m_stream = NULL;
m_bytes = 0;
}

CDVDDemuxCDDA::~CDVDDemuxCDDA()
{
Dispose();
}

bool CDVDDemuxCDDA::Open(CDVDInputStream* pInput)
{
Abort();

Dispose();

if(!pInput || !pInput->IsStreamType(DVDSTREAM_TYPE_FILE))
return false;

m_pInput = pInput;

m_stream = new CDemuxStreamAudioCDDA();

if(!m_stream)
return false;

m_stream->iSampleRate = 44100;
m_stream->iBitsPerSample = 16;
m_stream->iBitRate = 44100 * 2 * 16;
m_stream->iChannels = 2;
m_stream->type = STREAM_AUDIO;
m_stream->codec = CODEC_ID_PCM_S16LE;

return true;
}

void CDVDDemuxCDDA::Dispose()
{
delete m_stream;
m_stream = NULL;

m_pInput = NULL;
m_bytes = 0;
}

void CDVDDemuxCDDA::Reset()
{
CDVDInputStream* pInputStream = m_pInput;
Dispose();
Open(pInputStream);
}

void CDVDDemuxCDDA::Abort()
{
if(m_pInput)
return m_pInput->Abort();
}

void CDVDDemuxCDDA::Flush()
{
}

#define CDDA_READ_SIZE 4096
DemuxPacket* CDVDDemuxCDDA::Read()
{
if(!m_pInput)
return NULL;

DemuxPacket* pPacket = CDVDDemuxUtils::AllocateDemuxPacket(CDDA_READ_SIZE);

if (!pPacket)
{
if (m_pInput)
m_pInput->Close();
return NULL;
}

pPacket->iSize = m_pInput->Read(pPacket->pData, CDDA_READ_SIZE);
pPacket->iStreamId = 0;

if(pPacket->iSize < 1)
{
delete pPacket;
pPacket = NULL;
}
else
{
int n = m_stream->iBitRate>>3;
if (n > 0)
{
m_bytes += pPacket->iSize;
pPacket->dts = (double)m_bytes * DVD_TIME_BASE / n;
pPacket->pts = pPacket->dts;
}
else
{
pPacket->dts = DVD_NOPTS_VALUE;
pPacket->pts = DVD_NOPTS_VALUE;
}
}

return pPacket;
}

int CDVDDemuxCDDA::GetStreamLength()
{
int64_t num_track_bytes = m_pInput->GetLength();
int bytes_per_second = (m_stream->iBitRate>>3);
int64_t track_mseconds = num_track_bytes*1000 / bytes_per_second;
return (int)track_mseconds;
}

CDemuxStream* CDVDDemuxCDDA::GetStream(int iStreamId)
{
if(iStreamId != 0)
return NULL;

return m_stream;
}

int CDVDDemuxCDDA::GetNrOfStreams()
{
return (m_stream == NULL ? 0 : 1);
}

std::string CDVDDemuxCDDA::GetFileName()
{
if(m_pInput)
return m_pInput->GetFileName();
else
return "";
}

void CDVDDemuxCDDA::GetStreamCodecName(int iStreamId, CStdString &strName)
{
if (m_stream && iStreamId == 0)
strName = "pcm";
}
59 changes: 59 additions & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxCDDA.h
@@ -0,0 +1,59 @@
#pragma once
/*
* Copyright (C) 2013 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, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "DVDDemux.h"

#ifdef _WIN32
#define __attribute__(dummy_val)
#else
#include <config.h>
#endif

class CDemuxStreamAudioCDDA;

class CDVDDemuxCDDA : public CDVDDemux
{
public:

CDVDDemuxCDDA();
~CDVDDemuxCDDA();

bool Open(CDVDInputStream* pInput);
void Dispose();
void Reset();
void Abort();
void Flush();
DemuxPacket* Read();
bool SeekTime(int time, bool backwords = false, double* startpts = NULL) { return false; };
void SetSpeed(int iSpeed) {};
int GetStreamLength() ;
CDemuxStream* GetStream(int iStreamId);
int GetNrOfStreams();
std::string GetFileName();
virtual void GetStreamCodecName(int iStreamId, CStdString &strName);

protected:
friend class CDemuxStreamAudioCDDA;
CDVDInputStream* m_pInput;
int64_t m_bytes;

CDemuxStreamAudioCDDA *m_stream;
};
17 changes: 17 additions & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDFactoryDemuxer.cpp
Expand Up @@ -31,6 +31,7 @@
#include "DVDDemuxHTSP.h"
#endif
#include "DVDDemuxBXA.h"
#include "DVDDemuxCDDA.h"
#include "DVDDemuxPVRClient.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
Expand All @@ -54,6 +55,22 @@ CDVDDemux* CDVDFactoryDemuxer::CreateDemuxer(CDVDInputStream* pInputStream)
else
return NULL;
}

// Try to open CDDA demuxer
if (pInputStream->IsStreamType(DVDSTREAM_TYPE_FILE) && pInputStream->GetContent().compare("application/octet-stream") == 0)
{
std::string filename = pInputStream->GetFileName();
if (filename.substr(0, 7) == "cdda://")
{
CLog::Log(LOGDEBUG, "DVDFactoryDemuxer: Stream is probably CD audio. Creating CDDA demuxer.");

auto_ptr<CDVDDemuxCDDA> demuxer(new CDVDDemuxCDDA());
if (demuxer->Open(pInputStream))
{
return demuxer.release();
}
}
}

if (pInputStream->IsStreamType(DVDSTREAM_TYPE_HTTP))
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/Makefile.in
Expand Up @@ -2,6 +2,7 @@ INCLUDES+=-I@abs_top_srcdir@/xbmc/cores/dvdplayer

SRCS = DVDDemux.cpp
SRCS += DVDDemuxBXA.cpp
SRCS += DVDDemuxCDDA.cpp
SRCS += DVDDemuxFFmpeg.cpp
SRCS += DVDDemuxHTSP.cpp
SRCS += DVDDemuxPVRClient.cpp
Expand Down

0 comments on commit 6ee39a7

Please sign in to comment.