| 204 | } |
| 205 | |
| 206 | int COMXAudioCodecOMX::GetData(BYTE** dst, double &dts, double &pts) |
| 207 | { |
| 208 | if (!m_bGotFrame) |
| 209 | return 0; |
| 210 | int inLineSize, outLineSize; |
| 211 | /* input audio is aligned */ |
| 212 | int inputSize = m_dllAvUtil.av_samples_get_buffer_size(&inLineSize, m_pCodecContext->channels, m_pFrame1->nb_samples, m_pCodecContext->sample_fmt, 0); |
| 213 | /* output audio will be packed */ |
| 214 | int outputSize = m_dllAvUtil.av_samples_get_buffer_size(&outLineSize, m_pCodecContext->channels, m_pFrame1->nb_samples, m_desiredSampleFormat, 1); |
| 215 | |
| 216 | if (!m_bNoConcatenate && m_iBufferOutputUsed && (int)m_frameSize != outputSize) |
| 217 | { |
| 218 | CLog::Log(LOGERROR, "COMXAudioCodecOMX::GetData Unexpected change of size (%d->%d)", m_frameSize, outputSize); |
| 219 | m_bNoConcatenate = true; |
| 220 | } |
| 221 | |
| 222 | // if this buffer won't fit then flush out what we have |
| 223 | int desired_size = AUDIO_DECODE_OUTPUT_BUFFER * (m_pCodecContext->channels * GetBitsPerSample()) >> (rounded_up_channels_shift[m_pCodecContext->channels] + 4); |
| 224 | if (m_iBufferOutputUsed && (m_iBufferOutputUsed + outputSize > desired_size || m_bNoConcatenate)) |
| 225 | { |
| 226 | int ret = m_iBufferOutputUsed; |
| 227 | m_iBufferOutputUsed = 0; |
| 228 | m_bNoConcatenate = false; |
| 229 | dts = m_dts; |
| 230 | pts = m_pts; |
| 231 | *dst = m_pBufferOutput; |
| 232 | return ret; |
| 233 | } |
| 234 | m_frameSize = outputSize; |
| 235 | |
| 236 | if (m_iBufferOutputAlloced < m_iBufferOutputUsed + outputSize) |
| 237 | { |
| 238 | m_pBufferOutput = (BYTE*)m_dllAvUtil.av_realloc(m_pBufferOutput, m_iBufferOutputUsed + outputSize + FF_INPUT_BUFFER_PADDING_SIZE); |
| 239 | m_iBufferOutputAlloced = m_iBufferOutputUsed + outputSize; |
| 240 | } |
| 241 | |
| 242 | /* need to convert format */ |
| 243 | if(m_pCodecContext->sample_fmt != m_desiredSampleFormat) |
| 244 | { |
| 245 | if(m_pConvert && (m_pCodecContext->sample_fmt != m_iSampleFormat || m_channels != m_pCodecContext->channels)) |
| 246 | { |
| 247 | m_dllSwResample.swr_free(&m_pConvert); |
| 248 | m_channels = m_pCodecContext->channels; |
| 249 | } |
| 250 | |
| 251 | if(!m_pConvert) |
| 252 | { |
| 253 | m_iSampleFormat = m_pCodecContext->sample_fmt; |
| 254 | m_pConvert = m_dllSwResample.swr_alloc_set_opts(NULL, |
| 255 | m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), |
| 256 | m_desiredSampleFormat, m_pCodecContext->sample_rate, |
| 257 | m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), |
| 258 | m_pCodecContext->sample_fmt, m_pCodecContext->sample_rate, |
| 259 | 0, NULL); |
| 260 | |
| 261 | if(!m_pConvert || m_dllSwResample.swr_init(m_pConvert) < 0) |
| 262 | { |
| 263 | CLog::Log(LOGERROR, "COMXAudioCodecOMX::Decode - Unable to initialise convert format %d to %d", m_pCodecContext->sample_fmt, m_desiredSampleFormat); |
no test coverage detected