Skip to content

Commit

Permalink
Update Myth source base to work with new FFmpeg following 99b0c9d
Browse files Browse the repository at this point in the history
  • Loading branch information
jyavenard committed Dec 13, 2012
1 parent a0eddef commit 61167e5
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 246 deletions.
18 changes: 9 additions & 9 deletions mythtv/libs/libmyth/audio/audiooutputbase.cpp
Expand Up @@ -47,7 +47,7 @@ const char *AudioOutputBase::quality_string(int q)
AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
MThread("AudioOutputBase"),
// protected
channels(-1), codec(CODEC_ID_NONE),
channels(-1), codec(AV_CODEC_ID_NONE),
bytes_per_frame(0), output_bytes_per_frame(0),
format(FORMAT_NONE), output_format(FORMAT_NONE),
samplerate(-1), effdsp(0),
Expand Down Expand Up @@ -251,10 +251,10 @@ bool AudioOutputBase::CanPassthrough(int samplerate, int channels,

switch(codec)
{
case CODEC_ID_AC3:
case AV_CODEC_ID_AC3:
arg = FEATURE_AC3;
break;
case CODEC_ID_DTS:
case AV_CODEC_ID_DTS:
switch(profile)
{
case FF_PROFILE_DTS:
Expand All @@ -270,10 +270,10 @@ bool AudioOutputBase::CanPassthrough(int samplerate, int channels,
break;
}
break;
case CODEC_ID_EAC3:
case AV_CODEC_ID_EAC3:
arg = FEATURE_EAC3;
break;
case CODEC_ID_TRUEHD:
case AV_CODEC_ID_TRUEHD:
arg = FEATURE_TRUEHD;
break;
}
Expand Down Expand Up @@ -429,7 +429,7 @@ bool AudioOutputBase::CanUpmix(void)
bool AudioOutputBase::SetupPassthrough(int codec, int codec_profile,
int &samplerate_tmp, int &channels_tmp)
{
if (codec == CODEC_ID_DTS &&
if (codec == AV_CODEC_ID_DTS &&
!output_settingsdigital->canFeature(FEATURE_DTSHD))
{
// We do not support DTS-HD bitstream so force extraction of the
Expand All @@ -448,7 +448,7 @@ bool AudioOutputBase::SetupPassthrough(int codec, int codec_profile,
}

m_spdifenc = new SPDIFEncoder("spdif", codec);
if (m_spdifenc->Succeeded() && codec == CODEC_ID_DTS)
if (m_spdifenc->Succeeded() && codec == AV_CODEC_ID_DTS)
{
switch(codec_profile)
{
Expand Down Expand Up @@ -553,7 +553,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
/* Might we reencode a bitstream that's been decoded for timestretch?
If the device doesn't support the number of channels - see below */
if (output_settingsdigital->canFeature(FEATURE_AC3) &&
(settings.codec == CODEC_ID_AC3 || settings.codec == CODEC_ID_DTS))
(settings.codec == AV_CODEC_ID_AC3 || settings.codec == AV_CODEC_ID_DTS))
{
lreenc = true;
}
Expand Down Expand Up @@ -734,7 +734,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
.arg(samplerate).arg(configured_channels));

encoder = new AudioOutputDigitalEncoder();
if (!encoder->Init(CODEC_ID_AC3, 448000, samplerate,
if (!encoder->Init(AV_CODEC_ID_AC3, 448000, samplerate,
configured_channels))
{
Error("AC-3 encoder initialization failed");
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp
Expand Up @@ -154,7 +154,7 @@ bool AudioOutputDigitalEncoder::Init(
delete m_spdifenc;
}

m_spdifenc = new SPDIFEncoder("spdif", CODEC_ID_AC3);
m_spdifenc = new SPDIFEncoder("spdif", AV_CODEC_ID_AC3);
if (!m_spdifenc->Succeeded())
{
Dispose();
Expand Down Expand Up @@ -235,7 +235,7 @@ size_t AudioOutputDigitalEncoder::Encode(void *buf, int len, AudioFormat format)

if (!m_spdifenc)
{
m_spdifenc = new SPDIFEncoder("spdif", CODEC_ID_AC3);
m_spdifenc = new SPDIFEncoder("spdif", AV_CODEC_ID_AC3);
}
m_spdifenc->WriteFrame((uint8_t *)m_encodebuffer, outsize);
// Check if output buffer is big enough
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutputsettings.cpp
Expand Up @@ -449,14 +449,14 @@ QString AudioOutputSettings::GetPassthroughParams(int codec, int codec_profile,

switch (codec)
{
case CODEC_ID_AC3:
case AV_CODEC_ID_AC3:
log = "AC3";
break;
case CODEC_ID_EAC3:
case AV_CODEC_ID_EAC3:
samplerate = samplerate * 4;
log = "Dolby Digital Plus (E-AC3)";
break;
case CODEC_ID_DTS:
case AV_CODEC_ID_DTS:
switch(codec_profile)
{
case FF_PROFILE_DTS_ES:
Expand Down Expand Up @@ -487,7 +487,7 @@ QString AudioOutputSettings::GetPassthroughParams(int codec, int codec_profile,
break;
}
break;
case CODEC_ID_TRUEHD:
case AV_CODEC_ID_TRUEHD:
channels = 8;
log = "TrueHD";
switch(samplerate)
Expand Down
95 changes: 91 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutpututil.cpp
@@ -1,11 +1,18 @@
#include <math.h>

#include "mythconfig.h"
#include "audiooutpututil.h"
#include <sys/types.h>
#include <inttypes.h>
#include "bswap.h"

#include "mythconfig.h"
#include "mythlogging.h"
#include "audiooutpututil.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libswresample/swresample.h"
#include "pink.h"
}

#define LOC QString("AOUtil: ")

#if ARCH_X86
Expand Down Expand Up @@ -675,4 +682,84 @@ char *AudioOutputUtil::GeneratePinkFrames(char *frames, int channels,
}
return frames;
}


/**
* DecodeAudio
* Decode an audio packet, and compact it if data is planar
* Return negative error code if an error occurred during decoding
* or the number of bytes consumed from the input AVPacket
* data_size contains the size of decoded data copied into buffer
*/
int AudioOutputUtil::DecodeAudio(AVCodecContext *ctx,
uint8_t *buffer, int &data_size,
AVPacket *pkt)
{
AVFrame frame;
int got_frame = 0;
int ret, ret2;

data_size = 0;
avcodec_get_frame_defaults(&frame);
ret = avcodec_decode_audio4(ctx, &frame, &got_frame, pkt);
if (ret < 0 || !got_frame)
{
LOG(VB_AUDIO, LOG_ERR, LOC +
QString("audio decode error: %1 (%2)")
.arg(av_err2str(ret)).arg(got_frame));
return ret;
}

AVSampleFormat format = (AVSampleFormat)frame.format;
if (!av_sample_fmt_is_planar(format))
{
// data is already compacted... simply copy it
data_size = av_samples_get_buffer_size(NULL, ctx->channels,
frame.nb_samples,
format, 1);
memcpy(buffer, frame.extended_data[0], data_size);
return ret;
}

// Need to find a valid channels layout, as not all codecs provide one
int64_t channel_layout =
frame.channel_layout && frame.channels == av_get_channel_layout_nb_channels(frame.channel_layout) ?
frame.channel_layout : av_get_default_channel_layout(frame.channels);
SwrContext *swr = swr_alloc_set_opts(NULL,
channel_layout,
av_get_packed_sample_fmt(format),
frame.sample_rate,
channel_layout,
format,
frame.sample_rate,
0, NULL);
if (!swr)
{
LOG(VB_AUDIO, LOG_ERR, LOC + "error allocating resampler context");
return AVERROR(ENOMEM);
}
/* initialize the resampling context */
ret2 = swr_init(swr);
if (ret2 < 0)
{
LOG(VB_AUDIO, LOG_ERR, LOC +
QString("error initializing resampler context (%1)")
.arg(av_err2str(ret2)));
swr_free(&swr);
return ret2;
}

uint8_t *out[] = {buffer};
ret2 = swr_convert(swr, out, frame.nb_samples,
(const uint8_t **)frame.extended_data, frame.nb_samples);
swr_free(&swr);
if (ret2 < 0)
{
LOG(VB_AUDIO, LOG_ERR, LOC +
QString("error converting audio from planar format (%1)")
.arg(av_err2str(ret2)));
return ret2;
}
data_size = ret2 * frame.channels * av_get_bytes_per_sample(format);

return ret;
}
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/audio/audiooutpututil.h
Expand Up @@ -2,9 +2,6 @@
#define AUDIOOUTPUTUTIL_H_

#include "audiooutputsettings.h"
extern "C" {
#include "pink.h"
}

class MPUBLIC AudioOutputUtil
{
Expand All @@ -19,6 +16,9 @@ class MPUBLIC AudioOutputUtil
void *buffer, int bytes);
static char *GeneratePinkFrames(char *frames, int channels,
int channel, int count, int bits = 16);
static int DecodeAudio(AVCodecContext *ctx,
uint8_t *buffer, int &data_size,
AVPacket *pkt);
};

#endif
4 changes: 3 additions & 1 deletion mythtv/libs/libmyth/libmyth.pro
Expand Up @@ -87,20 +87,22 @@ LIBS += -L../libmythservicecontracts -lmythservicecontracts-$${LIBVERSION}
LIBS += -L../../external/FFmpeg/libavcodec -lmythavcodec
LIBS += -L../../external/FFmpeg/libavutil -lmythavutil
LIBS += -L../../external/FFmpeg/libavformat -lmythavformat
LIBS += -L../../external/FFmpeg/libswresample -lmythswresample

POST_TARGETDEPS += ../libmythsamplerate/libmythsamplerate-$${MYTH_LIB_EXT}
POST_TARGETDEPS += ../libmythsoundtouch/libmythsoundtouch-$${MYTH_LIB_EXT}
POST_TARGETDEPS += ../libmythfreesurround/libmythfreesurround-$${MYTH_LIB_EXT}
POST_TARGETDEPS += ../../external/FFmpeg/libavcodec/$$avLibName(avcodec)
POST_TARGETDEPS += ../../external/FFmpeg/libavutil/$$avLibName(avutil)
POST_TARGETDEPS += ../../external/FFmpeg/libswresample/$$avLibName(swresample)

# Install headers so that plugins can compile independently
inc.path = $${PREFIX}/include/mythtv/
inc.files = dialogbox.h mythcontext.h
inc.files += mythwidgets.h remotefile.h oldsettings.h volumecontrol.h
inc.files += settings.h uitypes.h mythdialogs.h
inc.files += audio/audiooutput.h audio/audiosettings.h
inc.files += audio/audiooutputsettings.h
inc.files += audio/audiooutputsettings.h audio/audiooutpututil.h
inc.files += audio/volumebase.h audio/eldutils.h
inc.files += inetcomms.h mythwizard.h schemawizard.h
inc.files += mythmediamonitor.h
Expand Down
24 changes: 10 additions & 14 deletions mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp
Expand Up @@ -9,6 +9,7 @@
#include "serverpool.h"

#include "audiooutput.h"
#include "audiooutpututil.h"

#include "mythraopdevice.h"
#include "mythraopconnection.h"
Expand Down Expand Up @@ -615,33 +616,28 @@ uint32_t MythRAOPConnection::decodeAudioPacket(uint8_t type,
tmp_pkt.size = len;

uint32_t frames_added = 0;
uint8_t *samples = (uint8_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE);
while (tmp_pkt.size > 0)
{
uint8_t *samples = (uint8_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE);
AVFrame frame;
int got_frame = 0;

int ret = avcodec_decode_audio4(ctx, &frame, &got_frame, &tmp_pkt);

int data_size;
int ret = AudioOutputUtil::DecodeAudio(ctx, samples,
data_size, &tmp_pkt);
if (ret < 0)
{
av_free(samples);
return -1;
}

if (got_frame)
if (data_size)
{
// ALAC codec isn't planar
int data_size = av_samples_get_buffer_size(NULL, ctx->channels,
frame.nb_samples,
ctx->sample_fmt, 1);
memcpy(samples, frame.extended_data[0], data_size);
int num_samples = data_size /
(ctx->channels * av_get_bytes_per_sample(ctx->sample_fmt));

frames_added += frame.nb_samples;
frames_added += num_samples;
AudioData block;
block.data = samples;
block.length = data_size;
block.frames = frame.nb_samples;
block.frames = num_samples;
dest->append(block);
}
tmp_pkt.data += ret;
Expand Down

0 comments on commit 61167e5

Please sign in to comment.