summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Reufer <thomas@reufer.ch>2015-08-27 21:48:10 +0200
committerThomas Reufer <thomas@reufer.ch>2015-08-27 21:48:10 +0200
commit02e18441f847a0b579d8aa97b6c94a77411fb79e (patch)
tree65ab7d310e21ec0d90788bff8d1fc993481ca28e
parent3620e2eebc6df1c86a6a5bb291f11ddf2b1caac8 (diff)
downloadvdr-plugin-amlhddevice-02e18441f847a0b579d8aa97b6c94a77411fb79e.tar.gz
vdr-plugin-amlhddevice-02e18441f847a0b579d8aa97b6c94a77411fb79e.tar.bz2
switched to TS mode and fixed A/V sync
-rw-r--r--HISTORY3
-rw-r--r--amldevice.c183
-rw-r--r--amldevice.h9
-rw-r--r--amlhddevice.c8
4 files changed, 60 insertions, 143 deletions
diff --git a/HISTORY b/HISTORY
index ae962ee..edc42cf 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,6 +1,9 @@
VDR Plugin 'amlhddevice' Revision History
-----------------------------------------
+- fixed:
+ - A/V sync
+
2015-08-23: Version 0.0.1
-------------------------
initial prototype
diff --git a/amldevice.c b/amldevice.c
index 3662f9a..7b698fc 100644
--- a/amldevice.c
+++ b/amldevice.c
@@ -10,7 +10,7 @@ extern "C" {
#include <codec.h>
}
-#include <vdr/libsi/si.h>
+#include <libsi/si.h>
#include "tools.h"
#include "amldevice.h"
@@ -26,7 +26,7 @@ public:
cAmlDecoder() :
m_initialized(false)
{
- memset(&m_param, 0, sizeof(codec_para_t));
+ Reset();
}
virtual ~cAmlDecoder()
@@ -35,7 +35,7 @@ public:
codec_close(&m_param);
}
- virtual void Reset(void)
+ virtual void Stop(void)
{
if (m_initialized)
codec_close(&m_param);
@@ -43,16 +43,20 @@ public:
m_initialized = false;
}
- virtual int Write(const uchar *data, int length, int64_t pts = INVALID_PTS)
+ virtual void Reset(void)
+ {
+ Stop();
+ memset(&m_param, 0, sizeof(codec_para_t));
+ m_param.stream_type = STREAM_TYPE_TS;
+ }
+
+ virtual int WriteTs(const uchar *data, int length)
{
if (!m_initialized)
return 0;
int ret = length;
- if (pts != INVALID_PTS)
- codec_checkin_pts(&m_param, pts);
-
while (length)
{
int written = codec_write(&m_param, (void *)data, length);
@@ -76,58 +80,20 @@ public:
return m_initialized;
}
-protected:
-
- bool ApplyConfig(void)
- {
- int ret = m_initialized ? codec_reset(&m_param) : codec_init(&m_param);
- m_initialized = ret == CODEC_ERROR_NONE;
- return m_initialized;
- }
-
- codec_para_t m_param;
- bool m_initialized;
-};
-
-/* ------------------------------------------------------------------------- */
-
-class cAmlAudioDecoder : public cAmlDecoder
-{
-public:
-
- enum eAudioCodec {
- eUnknown = 0,
- eMPEG,
- eAAC,
- eAC3,
- eEAC3,
- eDTS
- };
-
- static const char* Str(eAudioCodec codec) {
- return codec == eMPEG ? "MPEG" :
- codec == eAAC ? "AAC" :
- codec == eAC3 ? "AC3" :
- codec == eEAC3 ? "EAC3" :
- codec == eDTS ? "DTS" : "unknown";
- }
-
- cAmlAudioDecoder() :
- cAmlDecoder()
+ void SetAudioPid(int pid, int streamType)
{
- codec_audio_basic_init();
- }
+ if (!m_param.has_audio)
+ Stop();
- void SetCodec(eAudioCodec codec)
- {
m_param.has_audio = 1;
- m_param.stream_type = STREAM_TYPE_ES_AUDIO;
+ m_param.audio_pid = pid;
m_param.audio_type =
- codec == eMPEG ? AFORMAT_MPEG :
- codec == eAAC ? AFORMAT_AAC :
- codec == eAC3 ? AFORMAT_AC3 :
- codec == eEAC3 ? AFORMAT_EAC3 :
- codec == eDTS ? AFORMAT_DTS : 0;
+ streamType == 0x03 ? AFORMAT_MPEG :
+ streamType == 0x04 ? AFORMAT_MPEG :
+ streamType == SI::AC3DescriptorTag ? AFORMAT_AC3 :
+ streamType == SI::EnhancedAC3DescriptorTag ? AFORMAT_EAC3 :
+ streamType == 0x0f ? AFORMAT_AAC :
+ streamType == 0x11 ? AFORMAT_AAC : AFORMAT_UNKNOWN;
m_param.audio_channels = 0;
m_param.audio_samplerate = 0;
@@ -135,67 +101,43 @@ public:
m_param.audio_info.sample_rate = 0;
if (!ApplyConfig())
- ELOG("failed to set audio codec to %s!", Str(codec));
+ ELOG("failed to set audio codec!");
else
- DLOG("set audio codec to %s", Str(codec));
+ DLOG("set audio codec");
}
- static eAudioCodec MapStreamTypes(int type)
+ void SetVideoPid(int pid, int streamType)
{
- return type == 0x03 ? eMPEG :
- type == 0x04 ? eMPEG :
- type == SI::AC3DescriptorTag ? eAC3 :
- type == SI::EnhancedAC3DescriptorTag ? eEAC3 :
- type == 0x0f ? eAAC :
- type == 0x11 ? eAAC : eUnknown;
- }
-};
-
-/* ------------------------------------------------------------------------- */
+ if (!m_param.has_video)
+ Stop();
-class cAmlVideoDecoder : public cAmlDecoder
-{
-
-#define EXTERNAL_PTS (1)
-#define SYNC_OUTSIDE (2)
-
-public:
-
- enum eVideoCodec {
- eUnknown = 0,
- eMPEG12,
- eH264
- };
-
- static const char* Str(eVideoCodec codec) {
- return codec == eMPEG12 ? "MPEG1/2" :
- codec == eH264 ? "H264" : "unknown";
- }
-
- void SetCodec(eVideoCodec codec)
- {
m_param.has_video = 1;
- m_param.stream_type = STREAM_TYPE_ES_VIDEO;
+ m_param.video_pid = pid;
m_param.video_type =
- codec == eMPEG12 ? VFORMAT_MPEG12 :
- codec == eH264 ? VFORMAT_H264 : 0;
+ streamType == 0x01 ? VFORMAT_MPEG12 :
+ streamType == 0x02 ? VFORMAT_MPEG12 :
+ streamType == 0x1b ? VFORMAT_H264 : VFORMAT_UNKNOWN;
- m_param.am_sysinfo.format = VIDEO_DEC_FORMAT_UNKNOW;
- m_param.am_sysinfo.param = (void *)(EXTERNAL_PTS | SYNC_OUTSIDE);
- m_param.am_sysinfo.rate = 0;
+ m_param.am_sysinfo.format = m_param.video_type == VFORMAT_H264 ?
+ VIDEO_DEC_FORMAT_H264 : VIDEO_DEC_FORMAT_UNKNOW;
if (!ApplyConfig())
- ELOG("failed to set video codec to %s!", Str(codec));
+ ELOG("failed to set video codec!");
else
- DLOG("set video codec to %s", Str(codec));
+ DLOG("set video codec");
}
- static eVideoCodec MapStreamTypes(int type)
+protected:
+
+ bool ApplyConfig(void)
{
- return type == 0x01 ? eMPEG12 :
- type == 0x02 ? eMPEG12 :
- type == 0x1b ? eH264 : eUnknown;
+ int ret = m_initialized ? codec_reset(&m_param) : codec_init(&m_param);
+ m_initialized = ret == CODEC_ERROR_NONE;
+ return m_initialized;
}
+
+ codec_para_t m_param;
+ bool m_initialized;
};
/* ------------------------------------------------------------------------- */
@@ -203,8 +145,7 @@ public:
cAmlDevice::cAmlDevice(void (*onPrimaryDevice)(void)) :
cDevice(),
m_onPrimaryDevice(onPrimaryDevice),
- m_audioDecoder(new cAmlAudioDecoder()),
- m_videoDecoder(new cAmlVideoDecoder()),
+ m_decoder(new cAmlDecoder()),
m_audioPid(0),
m_videoPid(0)
{
@@ -214,8 +155,7 @@ cAmlDevice::~cAmlDevice()
{
DeInit();
- delete m_videoDecoder;
- delete m_audioDecoder;
+ delete m_decoder;
}
int cAmlDevice::Init(void)
@@ -243,6 +183,9 @@ void cAmlDevice::MakePrimaryDevice(bool On)
if (On && m_onPrimaryDevice)
m_onPrimaryDevice();
cDevice::MakePrimaryDevice(On);
+
+ cSysFs::Write("/sys/class/tsync/enable", 1);
+ codec_audio_basic_init();
}
void cAmlDevice::GetOsdSize(int &Width, int &Height, double &PixelAspect)
@@ -264,8 +207,8 @@ bool cAmlDevice::SetPlayMode(ePlayMode PlayMode)
switch (PlayMode)
{
case pmNone:
- m_audioDecoder->Reset();
- m_videoDecoder->Reset();
+ m_decoder->Reset();
+// cSysFs::Write("/sys/class/tsync/pts_pcrscr", "0x0");
m_audioPid = 0;
m_videoPid = 0;
break;
@@ -283,22 +226,6 @@ bool cAmlDevice::SetPlayMode(ePlayMode PlayMode)
return true;
}
-int cAmlDevice::PlayVideo(const uchar *Data, int Length)
-{
- return m_videoDecoder->Write(
- Data + PesPayloadOffset(Data),
- Length - PesPayloadOffset(Data),
- PesHasPts(Data) ? PesGetPts(Data) : INVALID_PTS);
-}
-
-int cAmlDevice::PlayAudio(const uchar *Data, int Length, uchar Id)
-{
- return m_audioDecoder->Write(
- Data + PesPayloadOffset(Data),
- Length - PesPayloadOffset(Data),
- PesHasPts(Data) ? PesGetPts(Data) : INVALID_PTS);
-}
-
int cAmlDevice::PlayTsVideo(const uchar *Data, int Length)
{
int pid = TsPid(Data);
@@ -307,12 +234,11 @@ int cAmlDevice::PlayTsVideo(const uchar *Data, int Length)
PatPmtParser();
if (pid == PatPmtParser()->Vpid())
{
- m_videoDecoder->SetCodec(cAmlVideoDecoder::MapStreamTypes(
- PatPmtParser()->Vtype()));
+ m_decoder->SetVideoPid(pid, PatPmtParser()->Vtype());
m_videoPid = pid;
}
}
- return cDevice::PlayTsVideo(Data, Length);
+ return m_decoder->WriteTs(Data, Length);
}
int cAmlDevice::PlayTsAudio(const uchar *Data, int Length)
@@ -334,10 +260,11 @@ int cAmlDevice::PlayTsAudio(const uchar *Data, int Length)
streamType = PatPmtParser()->Dtype(i);
break;
}
- m_audioDecoder->SetCodec(cAmlAudioDecoder::MapStreamTypes(streamType));
+
+ m_decoder->SetAudioPid(pid, streamType);
m_audioPid = pid;
}
- return cDevice::PlayTsAudio(Data, Length);
+ return m_decoder->WriteTs(Data, Length);
}
bool cAmlDevice::Poll(cPoller &Poller, int TimeoutMs)
diff --git a/amldevice.h b/amldevice.h
index 79506c9..35f38dc 100644
--- a/amldevice.h
+++ b/amldevice.h
@@ -11,8 +11,7 @@
#include "tools.h"
-class cAmlAudioDecoder;
-class cAmlVideoDecoder;
+class cAmlDecoder;
class cAmlDevice : cDevice
{
@@ -31,9 +30,6 @@ public:
virtual bool SetPlayMode(ePlayMode PlayMode);
- virtual int PlayVideo(const uchar *Data, int Length);
- virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
-
virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
virtual bool Flush(int TimeoutMs = 0);
@@ -50,8 +46,7 @@ private:
void (*m_onPrimaryDevice)(void);
- cAmlAudioDecoder *m_audioDecoder;
- cAmlVideoDecoder *m_videoDecoder;
+ cAmlDecoder *m_decoder;
int m_audioPid;
int m_videoPid;
diff --git a/amlhddevice.c b/amlhddevice.c
index cbc8a39..61ddc88 100644
--- a/amlhddevice.c
+++ b/amlhddevice.c
@@ -63,14 +63,6 @@ bool cPluginAmlHdDevice::Initialize(void)
cSysFs::Write("/sys/class/graphics/fb0/blank", 1);
cSysFs::Write("/sys/class/graphics/fb1/mode", "U:1280x720p-0\n");
cSysFs::Write("/sys/class/graphics/fb1/blank", 0);
-
- // 0: vmaster
- // 1: amaster
- // 2: pcrmaster
- cSysFs::Write("/sys/class/tsync/mode", 1);
-
- cSysFs::Write("/sys/class/tsync/enable", 1);
- cSysFs::Write("/sys/class/tsync/pts_pcrscr", "0x0");
}
return true;
}