Skip to content

Commit

Permalink
Make SPDIF encoder use weak linking so libmyth doesn't require libavf…
Browse files Browse the repository at this point in the history
…ormat/ libavcodec and libavutil. If they aren't present, spdif encoder will cleanly fail
  • Loading branch information
jyavenard committed Dec 14, 2010
1 parent d8810c8 commit 53e428e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions mythtv/libs/libmyth/audiooutputdigitalencoder.cpp
Expand Up @@ -93,7 +93,14 @@ bool AudioOutputDigitalEncoder::Init(
{
delete m_spdifenc;
}

m_spdifenc = new SPDIFEncoder("spdif", av_context);
if (!m_spdifenc->Succeeded())
{
Dispose();
delete m_spdifenc;
return false;
}

bytes_per_sample = av_context->channels * sizeof(short);
one_frame_bytes = bytes_per_sample * av_context->frame_size;
Expand Down
22 changes: 21 additions & 1 deletion mythtv/libs/libmyth/spdifencoder.cpp
Expand Up @@ -24,6 +24,26 @@ SPDIFEncoder::SPDIFEncoder(QString muxer, AVCodecContext *ctx)
AVOutputFormat *fmt =
av_guess_format(dev_ba.constData(), NULL, NULL);

if (!(av_guess_format && avformat_alloc_context &&
av_new_stream && av_write_header && av_write_frame &&
av_write_trailer && av_set_parameters))
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavformat");
return;
}

if (!avcodec_close)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavcodec");
return;
}

if (!(av_freep && av_alloc_put_byte))
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavutil");
return;
}

if (!fmt)
{
VERBOSE(VB_AUDIO, LOC_ERR + "av_guess_format");
Expand Down Expand Up @@ -186,6 +206,6 @@ void SPDIFEncoder::Destroy()
{
av_freep(&m_oc->pb);
}
av_free(m_oc);
av_freep(&m_oc);
}
}
12 changes: 12 additions & 0 deletions mythtv/libs/libmyth/spdifencoder.h
Expand Up @@ -11,6 +11,17 @@ extern "C" {
#include "libavcodec/audioconvert.h"
}

#pragma weak av_guess_format
#pragma weak avformat_alloc_context
#pragma weak av_new_stream
#pragma weak av_write_header
#pragma weak av_write_frame
#pragma weak av_write_trailer
#pragma weak avcodec_close
#pragma weak av_freep
#pragma weak av_set_parameters
#pragma weak av_alloc_put_byte

class MPUBLIC SPDIFEncoder
{

Expand All @@ -20,6 +31,7 @@ class MPUBLIC SPDIFEncoder
void WriteFrame(unsigned char *data, int size);
int GetData(unsigned char *buffer, int &dest_size);
void Reset();
bool Succeeded() { return m_complete; };

private:
static int funcIO(void *opaque, unsigned char *buf, int size);
Expand Down
7 changes: 7 additions & 0 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -4023,7 +4023,14 @@ bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt,
if (!m_spdifenc)
{
m_spdifenc = new SPDIFEncoder("spdif", ctx);
if (!m_spdifenc->Succeeded())
{
avcodeclock->unlock();
delete m_spdifenc;
return false;
}
}

m_spdifenc->WriteFrame(tmp_pkt.data, tmp_pkt.size);
data_size = tmp_pkt.size;
ret = m_spdifenc->GetData((unsigned char *)audioSamples, data_size);
Expand Down

0 comments on commit 53e428e

Please sign in to comment.