mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-30 08:51:11 +02:00
all: clean up cAudio header, separate private stuff
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/dvb/audio.h>
|
||||
#include "audio_lib.h"
|
||||
#include "audio_hal.h"
|
||||
#include "audio_priv.h"
|
||||
#include "lt_debug.h"
|
||||
|
||||
#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0"
|
||||
@@ -16,6 +17,7 @@
|
||||
#include <linux/soundcard.h>
|
||||
|
||||
cAudio * audioDecoder = NULL;
|
||||
ADec *adec = NULL;
|
||||
|
||||
static int proc_put(const char *path, const char *value, const int len)
|
||||
{
|
||||
@@ -32,32 +34,41 @@ static int proc_put(const char *path, const char *value, const int len)
|
||||
|
||||
cAudio::cAudio(void *, void *, void *)
|
||||
{
|
||||
fd = -1;
|
||||
clipfd = -1;
|
||||
mixer_fd = -1;
|
||||
openDevice();
|
||||
Muted = false;
|
||||
adec = new ADec();
|
||||
}
|
||||
|
||||
cAudio::~cAudio(void)
|
||||
{
|
||||
delete adec;
|
||||
}
|
||||
|
||||
ADec::ADec(void)
|
||||
{
|
||||
fd = -1;
|
||||
clipfd = -1;
|
||||
mixer_fd = -1;
|
||||
openDevice();
|
||||
muted = false;
|
||||
}
|
||||
|
||||
ADec::~ADec(void)
|
||||
{
|
||||
closeDevice();
|
||||
}
|
||||
|
||||
void cAudio::openDevice(void)
|
||||
void ADec::openDevice(void)
|
||||
{
|
||||
if (fd < 0)
|
||||
{
|
||||
if ((fd = open(AUDIO_DEVICE, O_RDWR)) < 0)
|
||||
if ((fd = open(AUDIO_DEVICE, O_RDWR|O_CLOEXEC)) < 0)
|
||||
lt_info("openDevice: open failed (%m)\n");
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
do_mute(true, false);
|
||||
//SetMute(true);
|
||||
}
|
||||
else
|
||||
lt_info("openDevice: already open (fd = %d)\n", fd);
|
||||
}
|
||||
|
||||
void cAudio::closeDevice(void)
|
||||
void ADec::closeDevice(void)
|
||||
{
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
@@ -70,15 +81,30 @@ void cAudio::closeDevice(void)
|
||||
mixer_fd = -1;
|
||||
}
|
||||
|
||||
int cAudio::do_mute(bool enable, bool remember)
|
||||
int cAudio::mute(void)
|
||||
{
|
||||
lt_debug("%s(%d, %d)\n", __FUNCTION__, enable, remember);
|
||||
return SetMute(true);
|
||||
}
|
||||
|
||||
int cAudio::unmute(void)
|
||||
{
|
||||
return SetMute(false);
|
||||
}
|
||||
|
||||
int cAudio::SetMute(bool enable)
|
||||
{
|
||||
return adec->SetMute(enable);
|
||||
}
|
||||
|
||||
int ADec::SetMute(bool enable, bool remember)
|
||||
{
|
||||
lt_debug("%s(%d)\n", __func__, enable);
|
||||
char str[4];
|
||||
|
||||
if (remember)
|
||||
Muted = enable;
|
||||
muted = enable;
|
||||
|
||||
sprintf(str, "%d", Muted);
|
||||
sprintf(str, "%d", muted);
|
||||
proc_put("/proc/stb/audio/j1_mute", str, strlen(str));
|
||||
|
||||
if (!enable)
|
||||
@@ -102,8 +128,12 @@ int map_volume(const int volume)
|
||||
return vol;
|
||||
}
|
||||
|
||||
|
||||
int cAudio::setVolume(unsigned int left, unsigned int right)
|
||||
{
|
||||
return adec->setVolume(left, right);
|
||||
}
|
||||
|
||||
int ADec::setVolume(unsigned int left, unsigned int right)
|
||||
{
|
||||
lt_debug("%s(%d, %d)\n", __func__, left, right);
|
||||
|
||||
@@ -112,7 +142,7 @@ int cAudio::setVolume(unsigned int left, unsigned int right)
|
||||
if (clipfd != -1 && mixer_fd != -1) {
|
||||
int tmp = 0;
|
||||
/* not sure if left / right is correct here, but it is always the same anyways ;-) */
|
||||
if (! Muted)
|
||||
if (! muted)
|
||||
tmp = left << 8 | right;
|
||||
int ret = ioctl(mixer_fd, MIXER_WRITE(mixer_num), &tmp);
|
||||
if (ret == -1)
|
||||
@@ -134,14 +164,12 @@ int cAudio::setVolume(unsigned int left, unsigned int right)
|
||||
|
||||
int cAudio::Start(void)
|
||||
{
|
||||
int ret;
|
||||
ret = ioctl(fd, AUDIO_PLAY);
|
||||
return ret;
|
||||
return adec->Start();
|
||||
}
|
||||
|
||||
int cAudio::Stop(void)
|
||||
{
|
||||
return ioctl(fd, AUDIO_STOP);
|
||||
return adec->Stop();
|
||||
}
|
||||
|
||||
bool cAudio::Pause(bool /*Pcm*/)
|
||||
@@ -150,6 +178,21 @@ bool cAudio::Pause(bool /*Pcm*/)
|
||||
};
|
||||
|
||||
void cAudio::SetSyncMode(AVSYNC_TYPE Mode)
|
||||
{
|
||||
adec->SetSyncMode(Mode);
|
||||
}
|
||||
|
||||
int ADec::Start(void)
|
||||
{
|
||||
return ioctl(fd, AUDIO_PLAY);
|
||||
}
|
||||
|
||||
int ADec::Stop(void)
|
||||
{
|
||||
return ioctl(fd, AUDIO_STOP);
|
||||
}
|
||||
|
||||
void ADec::SetSyncMode(AVSYNC_TYPE Mode)
|
||||
{
|
||||
lt_debug("%s %d\n", __func__, Mode);
|
||||
ioctl(fd, AUDIO_SET_AV_SYNC, Mode);
|
||||
@@ -165,6 +208,11 @@ void cAudio::SetSyncMode(AVSYNC_TYPE Mode)
|
||||
#define AUDIO_ENCODING_LPCM 2
|
||||
#define AUDIO_ENCODING_LPCMA 11
|
||||
void cAudio::SetStreamType(AUDIO_FORMAT type)
|
||||
{
|
||||
adec->SetStreamType(type);
|
||||
}
|
||||
|
||||
void ADec::SetStreamType(AUDIO_FORMAT type)
|
||||
{
|
||||
int bypass = AUDIO_STREAMTYPE_MPEG;
|
||||
bool update_volume = (StreamType != type);
|
||||
@@ -199,6 +247,11 @@ int cAudio::setChannel(int channel)
|
||||
};
|
||||
|
||||
int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
|
||||
{
|
||||
return adec->PrepareClipPlay(ch, srate, bits, little_endian);
|
||||
}
|
||||
|
||||
int ADec::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
|
||||
{
|
||||
int fmt;
|
||||
unsigned int devmask, stereo, usable;
|
||||
@@ -297,6 +350,11 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
|
||||
};
|
||||
|
||||
int cAudio::WriteClip(unsigned char *buffer, int size)
|
||||
{
|
||||
return adec->WriteClip(buffer, size);
|
||||
}
|
||||
|
||||
int ADec::WriteClip(unsigned char *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
// lt_debug("cAudio::%s\n", __FUNCTION__);
|
||||
@@ -311,6 +369,11 @@ int cAudio::WriteClip(unsigned char *buffer, int size)
|
||||
};
|
||||
|
||||
int cAudio::StopClip()
|
||||
{
|
||||
return adec->StopClip();
|
||||
}
|
||||
|
||||
int ADec::StopClip()
|
||||
{
|
||||
lt_debug("%s\n", __FUNCTION__);
|
||||
if (clipfd <= 0) {
|
||||
@@ -390,7 +453,7 @@ void cAudio::SetHdmiDD(bool enable)
|
||||
void cAudio::SetSpdifDD(bool enable)
|
||||
{
|
||||
lt_debug("%s %d\n", __func__, enable);
|
||||
setBypassMode(!enable);
|
||||
adec->setBypassMode(!enable);
|
||||
};
|
||||
|
||||
void cAudio::ScheduleMute(bool On)
|
||||
@@ -405,7 +468,7 @@ void cAudio::EnableAnalogOut(bool enable)
|
||||
|
||||
#define AUDIO_BYPASS_ON 0
|
||||
#define AUDIO_BYPASS_OFF 1
|
||||
void cAudio::setBypassMode(bool disable)
|
||||
void ADec::setBypassMode(bool disable)
|
||||
{
|
||||
const char *opt[] = { "passthrough", "downmix" };
|
||||
lt_debug("%s %d\n", __func__, disable);
|
||||
|
@@ -1,97 +0,0 @@
|
||||
/* public header file */
|
||||
|
||||
#ifndef _AUDIO_TD_H_
|
||||
#define _AUDIO_TD_H_
|
||||
#include <cs_types.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_SYNC_WITH_PTS,
|
||||
AUDIO_NO_SYNC,
|
||||
AUDIO_SYNC_AUDIO_MASTER
|
||||
} AUDIO_SYNC_MODE;
|
||||
|
||||
typedef enum {
|
||||
HDMI_ENCODED_OFF,
|
||||
HDMI_ENCODED_AUTO,
|
||||
HDMI_ENCODED_FORCED
|
||||
} HDMI_ENCODED_MODE;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_FMT_AUTO = 0,
|
||||
AUDIO_FMT_MPEG,
|
||||
AUDIO_FMT_MP3,
|
||||
AUDIO_FMT_DOLBY_DIGITAL,
|
||||
AUDIO_FMT_BASIC = AUDIO_FMT_DOLBY_DIGITAL,
|
||||
AUDIO_FMT_AAC,
|
||||
AUDIO_FMT_AAC_PLUS,
|
||||
AUDIO_FMT_DD_PLUS,
|
||||
AUDIO_FMT_DTS,
|
||||
AUDIO_FMT_AVS,
|
||||
AUDIO_FMT_MLP,
|
||||
AUDIO_FMT_WMA,
|
||||
AUDIO_FMT_MPG1, // TD only. For Movieplayer / cPlayback
|
||||
AUDIO_FMT_ADVANCED = AUDIO_FMT_MLP
|
||||
} AUDIO_FORMAT;
|
||||
|
||||
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;
|
||||
|
||||
int volume;
|
||||
|
||||
void openDevice(void);
|
||||
void closeDevice(void);
|
||||
|
||||
int do_mute(bool enable, bool remember);
|
||||
void setBypassMode(bool disable);
|
||||
public:
|
||||
/* construct & destruct */
|
||||
cAudio(void *, void *, void *);
|
||||
~cAudio(void);
|
||||
|
||||
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); };
|
||||
|
||||
/* volume, min = 0, max = 255 */
|
||||
int setVolume(unsigned int left, unsigned int right);
|
||||
int getVolume(void) { return volume;}
|
||||
bool getMuteStatus(void) { return Muted; };
|
||||
|
||||
/* start and stop audio */
|
||||
int Start(void);
|
||||
int Stop(void);
|
||||
bool Pause(bool Pcm = true);
|
||||
void SetStreamType(AUDIO_FORMAT type);
|
||||
void SetSyncMode(AVSYNC_TYPE Mode);
|
||||
|
||||
/* select channels */
|
||||
int setChannel(int channel);
|
||||
int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian);
|
||||
int WriteClip(unsigned char * buffer, int size);
|
||||
int StopClip();
|
||||
void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode);
|
||||
void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level);
|
||||
bool IsHdmiDDSupported() { return true; };
|
||||
void SetHdmiDD(bool enable);
|
||||
void SetSpdifDD(bool enable);
|
||||
void ScheduleMute(bool On);
|
||||
void EnableAnalogOut(bool enable);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
62
libspark/audio_priv.h
Normal file
62
libspark/audio_priv.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* (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 audio stuff, to be used inside libstb-hal only
|
||||
*/
|
||||
|
||||
#ifndef __audio_priv__
|
||||
#define __audio_priv__
|
||||
|
||||
#include <audio_hal.h>
|
||||
class ADec
|
||||
{
|
||||
public:
|
||||
/* construct & destruct */
|
||||
ADec(void);
|
||||
~ADec(void);
|
||||
|
||||
int SetMute(bool enable, bool remember = true);
|
||||
|
||||
/* volume, min = 0, max = 255 */
|
||||
int setVolume(unsigned int left, unsigned int right);
|
||||
|
||||
/* start and stop audio */
|
||||
int Start(void);
|
||||
int Stop(void);
|
||||
void SetStreamType(AUDIO_FORMAT type);
|
||||
void SetSyncMode(AVSYNC_TYPE Mode);
|
||||
|
||||
/* select channels */
|
||||
int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian);
|
||||
int WriteClip(unsigned char * buffer, int size);
|
||||
int StopClip();
|
||||
void setBypassMode(bool disable);
|
||||
void openDevice();
|
||||
void closeDevice();
|
||||
|
||||
/* variables */
|
||||
int fd;
|
||||
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;
|
||||
bool started;
|
||||
int volume;
|
||||
bool muted;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -10,7 +10,7 @@
|
||||
#include <cstring>
|
||||
#include "playback_lib.h"
|
||||
#include "dmx_hal.h"
|
||||
#include "audio_lib.h"
|
||||
#include "audio_hal.h"
|
||||
#include "video_lib.h"
|
||||
#include "lt_debug.h"
|
||||
#define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_PLAYBACK, this, args)
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <audio_lib.h>
|
||||
#include <audio_priv.h>
|
||||
#include <video_priv.h>
|
||||
|
||||
#include <common.h>
|
||||
@@ -16,7 +16,7 @@ extern ManagerHandler_t ManagerHandler;
|
||||
|
||||
static Context_t *player;
|
||||
|
||||
extern cAudio *audioDecoder;
|
||||
extern ADec *adec;
|
||||
extern cVideo *videoDecoder;
|
||||
static bool decoders_closed = false;
|
||||
|
||||
@@ -37,7 +37,7 @@ bool cPlayback::Open(playmode_t PlayMode)
|
||||
|
||||
if (PlayMode != PLAYMODE_TS)
|
||||
{
|
||||
audioDecoder->closeDevice();
|
||||
adec->closeDevice();
|
||||
videoDecoder->vdec->closeDevice();
|
||||
decoders_closed = true;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void cPlayback::Close(void)
|
||||
Stop();
|
||||
if (decoders_closed)
|
||||
{
|
||||
audioDecoder->openDevice();
|
||||
adec->openDevice();
|
||||
videoDecoder->vdec->openDevice();
|
||||
decoders_closed = false;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ bool cPlayback::Start(char *filename, unsigned short vpid, int vtype, unsigned s
|
||||
{
|
||||
ret = true;
|
||||
videoDecoder->vdec->Stop(false);
|
||||
audioDecoder->Stop();
|
||||
adec->Stop();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -253,7 +253,7 @@ bool cPlayback::SetSpeed(int speed)
|
||||
|
||||
if (! decoders_closed)
|
||||
{
|
||||
audioDecoder->closeDevice();
|
||||
adec->closeDevice();
|
||||
videoDecoder->vdec->closeDevice();
|
||||
decoders_closed = true;
|
||||
usleep(500000);
|
||||
|
Reference in New Issue
Block a user