diff options
Diffstat (limited to 'xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxBXA.cpp')
| -rw-r--r-- | xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxBXA.cpp | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxBXA.cpp b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxBXA.cpp new file mode 100644 index 0000000..9786983 --- /dev/null +++ b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxBXA.cpp | |||
| @@ -0,0 +1,193 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2012-2013 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 4 | * | ||
| 5 | * This Program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 8 | * any later version. | ||
| 9 | * | ||
| 10 | * This Program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with XBMC; see the file COPYING. If not, see | ||
| 17 | * <http://www.gnu.org/licenses/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "DVDInputStreams/DVDInputStream.h" | ||
| 22 | #include "DVDDemuxBXA.h" | ||
| 23 | #include "DVDDemuxUtils.h" | ||
| 24 | #include "utils/log.h" | ||
| 25 | #include "utils/StringUtils.h" | ||
| 26 | #include "../DVDClock.h" | ||
| 27 | |||
| 28 | // AirTunes audio Demuxer. | ||
| 29 | |||
| 30 | using namespace std; | ||
| 31 | |||
| 32 | class CDemuxStreamAudioBXA | ||
| 33 | : public CDemuxStreamAudio | ||
| 34 | { | ||
| 35 | CDVDDemuxBXA *m_parent; | ||
| 36 | string m_codec; | ||
| 37 | public: | ||
| 38 | CDemuxStreamAudioBXA(CDVDDemuxBXA *parent, const string& codec) | ||
| 39 | : m_parent(parent) | ||
| 40 | , m_codec(codec) | ||
| 41 | |||
| 42 | {} | ||
| 43 | void GetStreamInfo(string& strInfo) | ||
| 44 | { | ||
| 45 | strInfo = StringUtils::Format("%s", m_codec.c_str()); | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | |||
| 49 | CDVDDemuxBXA::CDVDDemuxBXA() : CDVDDemux() | ||
| 50 | { | ||
| 51 | m_pInput = NULL; | ||
| 52 | m_stream = NULL; | ||
| 53 | m_bytes = 0; | ||
| 54 | memset(&m_header, 0x0, sizeof(Demux_BXA_FmtHeader)); | ||
| 55 | } | ||
| 56 | |||
| 57 | CDVDDemuxBXA::~CDVDDemuxBXA() | ||
| 58 | { | ||
| 59 | Dispose(); | ||
| 60 | } | ||
| 61 | |||
| 62 | bool CDVDDemuxBXA::Open(CDVDInputStream* pInput) | ||
| 63 | { | ||
| 64 | Abort(); | ||
| 65 | |||
| 66 | Dispose(); | ||
| 67 | |||
| 68 | if(!pInput || !pInput->IsStreamType(DVDSTREAM_TYPE_FILE)) | ||
| 69 | return false; | ||
| 70 | |||
| 71 | if(pInput->Read((uint8_t *)&m_header, sizeof(Demux_BXA_FmtHeader)) < 1) | ||
| 72 | return false; | ||
| 73 | |||
| 74 | // file valid? | ||
| 75 | if (strncmp(m_header.fourcc, "BXA ", 4) != 0 || m_header.type != BXA_PACKET_TYPE_FMT_DEMUX) | ||
| 76 | { | ||
| 77 | pInput->Seek(0, SEEK_SET); | ||
| 78 | return false; | ||
| 79 | } | ||
| 80 | |||
| 81 | m_pInput = pInput; | ||
| 82 | |||
| 83 | m_stream = new CDemuxStreamAudioBXA(this, "BXA"); | ||
| 84 | |||
| 85 | if(!m_stream) | ||
| 86 | return false; | ||
| 87 | |||
| 88 | m_stream->iSampleRate = m_header.sampleRate; | ||
| 89 | m_stream->iBitsPerSample = m_header.bitsPerSample; | ||
| 90 | m_stream->iBitRate = m_header.sampleRate * m_header.channels * m_header.bitsPerSample; | ||
| 91 | m_stream->iChannels = m_header.channels; | ||
| 92 | m_stream->type = STREAM_AUDIO; | ||
| 93 | m_stream->codec = AV_CODEC_ID_PCM_S16LE; | ||
| 94 | |||
| 95 | return true; | ||
| 96 | } | ||
| 97 | |||
| 98 | void CDVDDemuxBXA::Dispose() | ||
| 99 | { | ||
| 100 | delete m_stream; | ||
| 101 | m_stream = NULL; | ||
| 102 | |||
| 103 | m_pInput = NULL; | ||
| 104 | m_bytes = 0; | ||
| 105 | |||
| 106 | memset(&m_header, 0x0, sizeof(Demux_BXA_FmtHeader)); | ||
| 107 | } | ||
| 108 | |||
| 109 | void CDVDDemuxBXA::Reset() | ||
| 110 | { | ||
| 111 | CDVDInputStream* pInputStream = m_pInput; | ||
| 112 | Dispose(); | ||
| 113 | Open(pInputStream); | ||
| 114 | } | ||
| 115 | |||
| 116 | void CDVDDemuxBXA::Abort() | ||
| 117 | { | ||
| 118 | if(m_pInput) | ||
| 119 | return m_pInput->Abort(); | ||
| 120 | } | ||
| 121 | |||
| 122 | void CDVDDemuxBXA::Flush() | ||
| 123 | { | ||
| 124 | } | ||
| 125 | |||
| 126 | #define BXA_READ_SIZE 4096 | ||
| 127 | DemuxPacket* CDVDDemuxBXA::Read() | ||
| 128 | { | ||
| 129 | if(!m_pInput) | ||
| 130 | return NULL; | ||
| 131 | |||
| 132 | DemuxPacket* pPacket = CDVDDemuxUtils::AllocateDemuxPacket(BXA_READ_SIZE); | ||
| 133 | |||
| 134 | if (!pPacket) | ||
| 135 | { | ||
| 136 | if (m_pInput) | ||
| 137 | m_pInput->Close(); | ||
| 138 | return NULL; | ||
| 139 | } | ||
| 140 | |||
| 141 | pPacket->iSize = m_pInput->Read(pPacket->pData, BXA_READ_SIZE); | ||
| 142 | pPacket->iStreamId = 0; | ||
| 143 | |||
| 144 | if(pPacket->iSize < 1) | ||
| 145 | { | ||
| 146 | delete pPacket; | ||
| 147 | pPacket = NULL; | ||
| 148 | } | ||
| 149 | else | ||
| 150 | { | ||
| 151 | int n = (m_header.channels * m_header.bitsPerSample * m_header.sampleRate)>>3; | ||
| 152 | if (n > 0) | ||
| 153 | { | ||
| 154 | m_bytes += pPacket->iSize; | ||
| 155 | pPacket->dts = (double)m_bytes * DVD_TIME_BASE / n; | ||
| 156 | pPacket->pts = pPacket->dts; | ||
| 157 | } | ||
| 158 | else | ||
| 159 | { | ||
| 160 | pPacket->dts = DVD_NOPTS_VALUE; | ||
| 161 | pPacket->pts = DVD_NOPTS_VALUE; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | return pPacket; | ||
| 166 | } | ||
| 167 | |||
| 168 | CDemuxStream* CDVDDemuxBXA::GetStream(int iStreamId) | ||
| 169 | { | ||
| 170 | if(iStreamId != 0) | ||
| 171 | return NULL; | ||
| 172 | |||
| 173 | return m_stream; | ||
| 174 | } | ||
| 175 | |||
| 176 | int CDVDDemuxBXA::GetNrOfStreams() | ||
| 177 | { | ||
| 178 | return (m_stream == NULL ? 0 : 1); | ||
| 179 | } | ||
| 180 | |||
| 181 | std::string CDVDDemuxBXA::GetFileName() | ||
| 182 | { | ||
| 183 | if(m_pInput) | ||
| 184 | return m_pInput->GetFileName(); | ||
| 185 | else | ||
| 186 | return ""; | ||
| 187 | } | ||
| 188 | |||
| 189 | void CDVDDemuxBXA::GetStreamCodecName(int iStreamId, std::string &strName) | ||
| 190 | { | ||
| 191 | if (m_stream && iStreamId == 0) | ||
| 192 | strName = "BXA"; | ||
| 193 | } | ||
