generic-pc: clean up cAudio header, separate private stuff

This commit is contained in:
Stefan Seyfried
2013-11-01 21:52:05 +01:00
parent 50b1d46af1
commit 0bfaccd2ee
4 changed files with 120 additions and 72 deletions

View File

@@ -23,54 +23,50 @@
#include <cstdlib>
#include "audio_lib.h"
#include "audio_priv.h"
#include "dmx_lib.h"
#include "lt_debug.h"
#define lt_debug(args...) _lt_debug(HAL_DEBUG_AUDIO, this, args)
#define lt_info(args...) _lt_info(HAL_DEBUG_AUDIO, this, args)
#include <OpenThreads/Thread>
extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/opt.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#include <ao/ao.h>
}
/* ffmpeg buf 2k */
#define INBUF_SIZE 0x0800
/* my own buf 16k */
#define DMX_BUF_SZ 0x4000
cAudio * audioDecoder = NULL;
ADec *adec = NULL;
extern cDemux *audioDemux;
static uint8_t *dmxbuf = NULL;
static int bufpos;
extern bool HAL_nodec;
static cAudio *gThiz = NULL;
static ao_device *adevice = NULL;
static ao_sample_format sformat;
static AVCodecContext *c= NULL;
cAudio::cAudio(void *, void *, void *)
{
adec = new ADec();
}
cAudio::~cAudio(void)
{
delete adec;
}
ADec::ADec(void)
{
adevice = NULL;
dmxbuf = NULL;
bufpos = 0;
c = NULL;
thread_started = false;
if (!HAL_nodec)
dmxbuf = (uint8_t *)malloc(DMX_BUF_SZ);
bufpos = 0;
curr_pts = 0;
gThiz = this;
ao_initialize();
}
cAudio::~cAudio(void)
ADec::~ADec(void)
{
closeDevice();
free(dmxbuf);
if (adevice)
ao_close(adevice);
@@ -78,19 +74,19 @@ cAudio::~cAudio(void)
ao_shutdown();
}
void cAudio::openDevice(void)
int cAudio::mute(void)
{
lt_debug("%s\n", __func__);
return SetMute(true);
}
void cAudio::closeDevice(void)
int cAudio::unmute(void)
{
lt_debug("%s\n", __func__);
return SetMute(false);
}
int cAudio::do_mute(bool enable, bool remember)
int cAudio::SetMute(bool enable)
{
lt_debug("%s(%d, %d)\n", __func__, enable, remember);
lt_debug("%s(%d)\n", __func__, enable);
return 0;
}
@@ -101,21 +97,31 @@ int cAudio::setVolume(unsigned int left, unsigned int right)
}
int cAudio::Start(void)
{
return adec->Start();
}
int cAudio::Stop(void)
{
return adec->Stop();
}
int ADec::Start(void)
{
lt_debug("%s >\n", __func__);
if (! HAL_nodec)
OpenThreads::Thread::start();
start();
lt_debug("%s <\n", __func__);
return 0;
}
int cAudio::Stop(void)
int ADec::Stop(void)
{
lt_debug("%s >\n", __func__);
if (thread_started)
{
thread_started = false;
OpenThreads::Thread::join();
join();
}
lt_debug("%s <\n", __func__);
return 0;
@@ -142,6 +148,11 @@ int cAudio::setChannel(int /*channel*/)
};
int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le)
{
return adec->PrepareClipPlay(ch, srate, bits, le);
}
int ADec::PrepareClipPlay(int ch, int srate, int bits, int le)
{
lt_debug("%s ch %d srate %d bits %d le %d adevice %p\n", __func__, ch, srate, bits, le, adevice);;
int driver;
@@ -168,6 +179,11 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le)
};
int cAudio::WriteClip(unsigned char *buffer, int size)
{
return adec->WriteClip(buffer, size);
}
int ADec::WriteClip(unsigned char *buffer, int size)
{
lt_debug("cAudio::%s buf 0x%p size %d\n", __func__, buffer, size);
if (!adevice) {
@@ -195,6 +211,11 @@ int cAudio::StopClip()
};
void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode)
{
adec->getAudioInfo(type, layer, freq, bitrate, mode);
}
void ADec::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode)
{
type = 0;
layer = 0; /* not used */
@@ -269,17 +290,12 @@ void cAudio::EnableAnalogOut(bool enable)
lt_debug("%s %d\n", __func__, enable);
};
void cAudio::setBypassMode(bool disable)
{
lt_debug("%s %d\n", __func__, disable);
}
static int _my_read(void *, uint8_t *buf, int buf_size)
{
return gThiz->my_read(buf, buf_size);
return adec->my_read(buf, buf_size);
}
int cAudio::my_read(uint8_t *buf, int buf_size)
int ADec::my_read(uint8_t *buf, int buf_size)
{
int tmp = 0;
if (audioDecoder && bufpos < DMX_BUF_SZ - 4096) {
@@ -306,7 +322,7 @@ int cAudio::my_read(uint8_t *buf, int buf_size)
return tmp;
}
void cAudio::run()
void ADec::run()
{
lt_info("====================== start decoder thread ================================\n");
/* libavcodec & friends */

View File

@@ -4,7 +4,6 @@
#define _AUDIO_LIB_H_
#include <stdint.h>
#include <OpenThreads/Thread>
#include <cs_types.h>
typedef enum
@@ -38,46 +37,23 @@ typedef enum
AUDIO_FMT_ADVANCED = AUDIO_FMT_MLP
} AUDIO_FORMAT;
class cAudio : public OpenThreads::Thread
class cAudio
{
friend class cPlayback;
private:
int fd;
bool Muted;
int clipfd; /* for pcm playback */
int mixer_fd; /* if we are using the OSS mixer */
int mixer_num; /* oss mixer to use, if any */
AUDIO_FORMAT StreamType;
AUDIO_SYNC_MODE SyncMode;
bool started;
bool thread_started;
int volume;
int64_t curr_pts;
void openDevice(void);
void closeDevice(void);
int do_mute(bool enable, bool remember);
void setBypassMode(bool disable);
void run();
public:
/* construct & destruct */
cAudio(void *, void *, void *);
~cAudio(void);
int64_t getPts() { return curr_pts; }
void *GetHandle() { return NULL; };
/* shut up */
int mute(bool remember = true) { return do_mute(true, remember); };
int unmute(bool remember = true) { return do_mute(false, remember); };
int mute(void);
int unmute(void);
int SetMute(bool enable);
/* volume, min = 0, max = 255 */
int setVolume(unsigned int left, unsigned int right);
int getVolume(void) { return volume;}
bool getMuteStatus(void) { return Muted; };
bool getMuteStatus(void) { return muted; };
/* start and stop audio */
int Start(void);
@@ -98,7 +74,10 @@ class cAudio : public OpenThreads::Thread
void SetSpdifDD(bool enable);
void ScheduleMute(bool On);
void EnableAnalogOut(bool enable);
int my_read(uint8_t *buf, int buf_size);
private:
bool muted;
int volume;
void *pdata;
};
#endif

53
generic-pc/audio_priv.h Normal file
View File

@@ -0,0 +1,53 @@
/*
* (C) 2010-2013 Stefan Seyfried
*
* 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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* private stuff for the audio decoder, only used inside libstb-hal
*/
#include <OpenThreads/Thread>
extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/opt.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#include <ao/ao.h>
}
class ADec : public OpenThreads::Thread
{
public:
ADec();
~ADec();
int Start();
int Stop();
int PrepareClipPlay(int ch, int srate, int bits, int le);
int WriteClip(unsigned char *buffer, int size);
void getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode);
int my_read(uint8_t *buf, int buf_size);
int64_t getPts() { return curr_pts; };
private:
bool thread_started;
int64_t curr_pts;
void run();
ao_device *adevice;
ao_sample_format sformat;
uint8_t *dmxbuf;
int bufpos;
AVCodecContext *c;
};

View File

@@ -39,7 +39,7 @@
#include <linux/input.h>
#include "glfb_priv.h"
#include "video_priv.h"
#include "audio_lib.h"
#include "audio_priv.h"
#include "lt_debug.h"
@@ -50,7 +50,7 @@
extern VDec *vdec;
extern cAudio *audioDecoder;
extern ADec *adec;
/* the private class that does stuff only needed inside libstb-hal.
* is used e.g. by cVideo... */
@@ -596,8 +596,8 @@ void GLFbPC::bltDisplayBuffer()
* better this than nothing... :-) */
int64_t apts = 0;
int64_t vpts = buf->pts();
if (audioDecoder)
apts = audioDecoder->getPts();
if (adec)
apts = adec->getPts();
if (apts != last_apts) {
int rate, dummy1, dummy2;
if (apts < vpts)