forked from opdenkamp/xbmc
/
DVDAudioCodecPassthrough.cpp
159 lines (131 loc) · 4.04 KB
/
DVDAudioCodecPassthrough.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (C) 2010-2013 Team XBMC
* http://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 "DVDAudioCodecPassthrough.h"
#include "DVDCodecs/DVDCodecs.h"
#include "DVDStreamInfo.h"
#include "cores/AudioEngine/Utils/AEUtil.h"
#include "settings/Settings.h"
#include "utils/log.h"
#include "cores/AudioEngine/AEFactory.h"
CDVDAudioCodecPassthrough::CDVDAudioCodecPassthrough(void) :
m_buffer (NULL),
m_bufferSize(0)
{
}
CDVDAudioCodecPassthrough::~CDVDAudioCodecPassthrough(void)
{
Dispose();
}
bool CDVDAudioCodecPassthrough::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
bool bSupportsAC3Out = CAEFactory::SupportsRaw(AE_FMT_AC3);
bool bSupportsEAC3Out = CAEFactory::SupportsRaw(AE_FMT_EAC3);
bool bSupportsDTSOut = CAEFactory::SupportsRaw(AE_FMT_DTS);
bool bSupportsTrueHDOut = CAEFactory::SupportsRaw(AE_FMT_TRUEHD);
bool bSupportsDTSHDOut = CAEFactory::SupportsRaw(AE_FMT_DTSHD);
/* only get the dts core from the parser if we don't support dtsHD */
m_info.SetCoreOnly(!bSupportsDTSHDOut);
m_bufferSize = 0;
/* 32kHz E-AC-3 passthrough requires 128kHz IEC 60958 stream
* which HDMI does not support, and IEC 61937 does not mention
* reduced sample rate support, so support only 44.1 and 48 */
if ((hints.codec == AV_CODEC_ID_AC3 && bSupportsAC3Out) ||
(hints.codec == AV_CODEC_ID_EAC3 && bSupportsEAC3Out && (hints.samplerate == 44100 || hints.samplerate == 48000)) ||
(hints.codec == AV_CODEC_ID_DTS && bSupportsDTSOut) ||
(hints.codec == AV_CODEC_ID_TRUEHD && bSupportsTrueHDOut))
{
return true;
}
return false;
}
int CDVDAudioCodecPassthrough::GetSampleRate()
{
return m_info.GetOutputRate();
}
int CDVDAudioCodecPassthrough::GetEncodedSampleRate()
{
return m_info.GetSampleRate();
}
enum AEDataFormat CDVDAudioCodecPassthrough::GetDataFormat()
{
switch(m_info.GetDataType())
{
case CAEStreamInfo::STREAM_TYPE_AC3:
return AE_FMT_AC3;
case CAEStreamInfo::STREAM_TYPE_DTS_512:
case CAEStreamInfo::STREAM_TYPE_DTS_1024:
case CAEStreamInfo::STREAM_TYPE_DTS_2048:
case CAEStreamInfo::STREAM_TYPE_DTSHD_CORE:
return AE_FMT_DTS;
case CAEStreamInfo::STREAM_TYPE_EAC3:
return AE_FMT_EAC3;
case CAEStreamInfo::STREAM_TYPE_TRUEHD:
return AE_FMT_TRUEHD;
case CAEStreamInfo::STREAM_TYPE_DTSHD:
return AE_FMT_DTSHD;
default:
return AE_FMT_INVALID; //Unknown stream type
}
}
int CDVDAudioCodecPassthrough::GetChannels()
{
return m_info.GetOutputChannels();
}
int CDVDAudioCodecPassthrough::GetEncodedChannels()
{
return m_info.GetChannels();
}
CAEChannelInfo CDVDAudioCodecPassthrough::GetChannelMap()
{
return m_info.GetChannelMap();
}
void CDVDAudioCodecPassthrough::Dispose()
{
if (m_buffer)
{
delete[] m_buffer;
m_buffer = NULL;
}
m_bufferSize = 0;
}
int CDVDAudioCodecPassthrough::Decode(uint8_t* pData, int iSize)
{
if (iSize <= 0) return 0;
unsigned int size = m_bufferSize;
unsigned int used = m_info.AddData(pData, iSize, &m_buffer, &size);
m_bufferSize = std::max(m_bufferSize, size);
/* if we have a frame */
if (size)
m_packer.Pack(m_info, m_buffer, size);
return used;
}
int CDVDAudioCodecPassthrough::GetData(uint8_t** dst)
{
int size = m_packer.GetSize();
*dst = m_packer.GetBuffer();
return size;
}
void CDVDAudioCodecPassthrough::Reset()
{
}
int CDVDAudioCodecPassthrough::GetBufferSize()
{
return (int)m_info.GetBufferSize();
}