mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 23:13:13 +02:00
testing dvb subtitles
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@126 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <sys/timeb.h>
|
||||
#include <time.h>
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include "Debug.hpp"
|
||||
@@ -29,13 +31,26 @@ FILE* Debug::set_file(char* file)
|
||||
return fp_;
|
||||
}
|
||||
|
||||
void Debug::print(int /*level*/, const char *fmt, ...)
|
||||
void Debug::print(int level, const char *fmt, ...)
|
||||
{
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
// if (level < level_) {
|
||||
vfprintf(fp_, fmt, argp);
|
||||
// }
|
||||
va_end(argp);
|
||||
struct timeb tp;
|
||||
char buf[1024];
|
||||
char tbuf[20];
|
||||
int len;
|
||||
struct tm tv;
|
||||
|
||||
if (level < level_) {
|
||||
ftime(&tp);
|
||||
localtime_r (&tp.time, &tv);
|
||||
strftime (tbuf, 14, "%H:%M:%S", &tv);
|
||||
len = sprintf(buf, "[ %s.%03d ] ", tbuf, tp.millitm);
|
||||
|
||||
va_start(argp, fmt);
|
||||
//vfprintf(fp_, fmt, argp);
|
||||
vsnprintf (&buf[len], 512, fmt, argp);
|
||||
va_end(argp);
|
||||
fprintf(fp_, "%s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ cDvbSubtitleConverter *dvbSubtitleConverter;
|
||||
int dvbsub_init() {
|
||||
int trc;
|
||||
|
||||
sub_debug.set_level(42);
|
||||
sub_debug.set_level(3);
|
||||
|
||||
reader_running = true;
|
||||
// reader-Thread starten
|
||||
@@ -149,7 +149,7 @@ int dvbsub_close()
|
||||
|
||||
static cDemux * dmx;
|
||||
|
||||
void* reader_thread(void */*arg*/)
|
||||
void* reader_thread(void * /*arg*/)
|
||||
{
|
||||
uint8_t tmp[16]; /* actually 6 should be enough */
|
||||
int count;
|
||||
@@ -243,7 +243,7 @@ void* reader_thread(void */*arg*/)
|
||||
}
|
||||
}
|
||||
if(!dvbsub_paused) {
|
||||
printf("[subtitles] adding packet, len %d\n", count);
|
||||
sub_debug.print(Debug::VERBOSE, "[subtitles] adding packet, len %d\n", count);
|
||||
/* Packet now in memory */
|
||||
packet_queue.push(buf);
|
||||
/* TODO: allocation exception */
|
||||
@@ -274,6 +274,7 @@ void* dvbsub_thread(void* /*arg*/)
|
||||
if (!dvbSubtitleConverter)
|
||||
dvbSubtitleConverter = new cDvbSubtitleConverter;
|
||||
|
||||
int timeout = 1000000;
|
||||
while(dvbsub_running) {
|
||||
uint8_t* packet;
|
||||
int64_t pts;
|
||||
@@ -282,10 +283,30 @@ void* dvbsub_thread(void* /*arg*/)
|
||||
int packlen;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
TIMEVAL_TO_TIMESPEC(&now, &restartWait);
|
||||
restartWait.tv_sec += 1;
|
||||
|
||||
int ret = 0;
|
||||
#if 1
|
||||
now.tv_usec += (timeout == 0) ? 1000000 : timeout; // add the timeout
|
||||
while (now.tv_usec >= 1000000) { // take care of an overflow
|
||||
now.tv_sec++;
|
||||
now.tv_usec -= 1000000;
|
||||
}
|
||||
restartWait.tv_sec = now.tv_sec; // seconds
|
||||
restartWait.tv_nsec = now.tv_usec * 1000; // nano seconds
|
||||
|
||||
pthread_mutex_lock( &packetMutex );
|
||||
ret = pthread_cond_timedwait( &packetCond, &packetMutex, &restartWait );
|
||||
pthread_mutex_unlock( &packetMutex );
|
||||
|
||||
timeout = dvbSubtitleConverter->Action();
|
||||
|
||||
if(packet_queue.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
|
||||
TIMEVAL_TO_TIMESPEC(&now, &restartWait);
|
||||
restartWait.tv_sec += 1;
|
||||
if(packet_queue.size() == 0) {
|
||||
pthread_mutex_lock( &packetMutex );
|
||||
ret = pthread_cond_timedwait( &packetCond, &packetMutex, &restartWait );
|
||||
@@ -300,7 +321,8 @@ void* dvbsub_thread(void* /*arg*/)
|
||||
{
|
||||
sub_debug.print(Debug::VERBOSE, "pthread_cond_timedwait fails with %s\n", strerror(errno));
|
||||
}
|
||||
sub_debug.print(Debug::VERBOSE, "\nPES: Wakeup, queue size %d\n", packet_queue.size());
|
||||
#endif
|
||||
sub_debug.print(Debug::VERBOSE, "PES: Wakeup, queue size %d\n\n", packet_queue.size());
|
||||
if(dvbsub_paused) {
|
||||
do {
|
||||
packet = packet_queue.pop();
|
||||
@@ -350,7 +372,7 @@ void* dvbsub_thread(void* /*arg*/)
|
||||
} else {
|
||||
sub_debug.print(Debug::INFO, "End_of_PES is missing\n");
|
||||
}
|
||||
dvbSubtitleConverter->Action();
|
||||
timeout = dvbSubtitleConverter->Action();
|
||||
|
||||
next_round:
|
||||
delete[] packet;
|
||||
|
@@ -20,6 +20,7 @@ extern "C" {
|
||||
#include <sys/mman.h>
|
||||
}
|
||||
#include "driver/framebuffer.h"
|
||||
#include "Debug.hpp"
|
||||
|
||||
#define FB "/dev/fb/0"
|
||||
extern int fb_fd;
|
||||
@@ -49,12 +50,21 @@ static bool DebugObjects = true;
|
||||
static bool DebugCluts = true;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define dbgconverter(a...) if (DebugConverter) fprintf(stderr, a)
|
||||
#define dbgsegments(a...) if (DebugSegments) fprintf(stderr, a)
|
||||
#define dbgpages(a...) if (DebugPages) fprintf(stderr, a)
|
||||
#define dbgregions(a...) if (DebugRegions) fprintf(stderr, a)
|
||||
#define dbgobjects(a...) if (DebugObjects) fprintf(stderr, a)
|
||||
#define dbgcluts(a...) if (DebugCluts) fprintf(stderr, a)
|
||||
#endif
|
||||
|
||||
#define dbgconverter(a...) if (DebugConverter) sub_debug.print(Debug::VERBOSE, a)
|
||||
#define dbgsegments(a...) if (DebugSegments) sub_debug.print(Debug::VERBOSE, a)
|
||||
#define dbgpages(a...) if (DebugPages) sub_debug.print(Debug::VERBOSE, a)
|
||||
#define dbgregions(a...) if (DebugRegions) sub_debug.print(Debug::VERBOSE, a)
|
||||
#define dbgobjects(a...) if (DebugObjects) sub_debug.print(Debug::VERBOSE, a)
|
||||
#define dbgcluts(a...) if (DebugCluts) sub_debug.print(Debug::VERBOSE, a)
|
||||
|
||||
int SubtitleFgTransparency = 0;
|
||||
int SubtitleBgTransparency = 0;
|
||||
@@ -673,10 +683,11 @@ static int max_x = 0, max_y = 0;
|
||||
|
||||
void cDvbSubtitleBitmaps::Clear()
|
||||
{
|
||||
dbgconverter("cDvbSubtitleBitmaps::Draw: clear x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
dbgconverter("cDvbSubtitleBitmaps::Clear: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
if(max_x && max_y) {
|
||||
CFrameBuffer::getInstance()->paintBackgroundBoxRel (min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
CFrameBuffer::getInstance()->paintBackgroundBoxRel (min_x, min_y-10, max_x-min_x, max_y-min_y+10);
|
||||
max_x = max_y = 0;
|
||||
min_x = min_y = 0xFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,7 +719,7 @@ void cDvbSubtitleBitmaps::Draw()
|
||||
int yoff = (yend - (576-bitmaps[i]->Y0()))*stride;
|
||||
int ys = yend - (576-bitmaps[i]->Y0());
|
||||
|
||||
dbgconverter("cDvbSubtitleBitmaps::Draw %d colors= %d at %d,%d (x=%d y=%d) size %dx%d\n",
|
||||
dbgconverter("cDvbSubtitleBitmaps::Draw num %d colors= %d at %d,%d (x=%d y=%d) size %dx%d\n",
|
||||
i, NumColors, bitmaps[i]->X0(), bitmaps[i]->Y0(), xoff, ys, bitmaps[i]->Width(), bitmaps[i]->Height());
|
||||
|
||||
for (int y2 = 0; y2 < bitmaps[i]->Height(); y2++) {
|
||||
@@ -787,9 +798,10 @@ void cDvbSubtitleConverter::Pause(bool pause)
|
||||
void cDvbSubtitleConverter::Clear(void)
|
||||
{
|
||||
if(max_x && max_y) {
|
||||
dbgconverter("cDvbSubtitleConverter::Draw: clear x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
CFrameBuffer::getInstance()->paintBackgroundBoxRel (min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
dbgconverter("cDvbSubtitleConverter::Clear: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
|
||||
CFrameBuffer::getInstance()->paintBackgroundBoxRel (min_x, min_y-10, max_x-min_x, max_y-min_y+10);
|
||||
max_x = max_y = 0;
|
||||
min_x = min_y = 0xFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,13 +908,13 @@ int cDvbSubtitleConverter::Convert(const uchar *Data, int Length, int64_t pts)
|
||||
|
||||
void dvbsub_get_stc(int64_t * STC);
|
||||
|
||||
void cDvbSubtitleConverter::Action(void)
|
||||
int cDvbSubtitleConverter::Action(void)
|
||||
{
|
||||
static cTimeMs Timeout(0xFFFF*1000);
|
||||
int WaitMs = 100;
|
||||
int WaitMs = 500;
|
||||
|
||||
if(!running)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
Lock();
|
||||
if (cDvbSubtitleBitmaps *sb = bitmaps->First()) {
|
||||
@@ -910,17 +922,18 @@ void cDvbSubtitleConverter::Action(void)
|
||||
dvbsub_get_stc(&STC);
|
||||
int64_t Delta = 0;
|
||||
|
||||
Delta = sb->Pts() - STC;
|
||||
Delta = LimitTo32Bit(sb->Pts()) - LimitTo32Bit(STC);
|
||||
Delta /= 90; // STC and PTS are in 1/90000s
|
||||
dbgconverter("cDvbSubtitleConverter::Action: PTS: %lld STC: %lld (%lld) timeout: %d\n", sb->Pts(), STC, Delta, sb->Timeout());
|
||||
|
||||
#if 0
|
||||
if(Delta > 1800) {
|
||||
Unlock();
|
||||
usleep((Delta-500)*1000);
|
||||
Lock();
|
||||
if(!running) {
|
||||
Unlock();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
#if 1 // debug
|
||||
dvbsub_get_stc(&STC);
|
||||
@@ -928,13 +941,13 @@ void cDvbSubtitleConverter::Action(void)
|
||||
dbgconverter("cDvbSubtitleConverter::Action: PTS: %lld STC: %lld (%lld) timeout: %d after sleep\n", sb->Pts(), STC, Delta/90, sb->Timeout());
|
||||
#endif
|
||||
}
|
||||
Delta = 0;
|
||||
#endif
|
||||
if (Delta <= MAXDELTA) {
|
||||
if (Delta <= 0) {
|
||||
dbgconverter("cDvbSubtitleConverter::Action: Got %d bitmaps, showing #%d\n", bitmaps->Count(), sb->Index() + 1);
|
||||
if (running) {
|
||||
sb->Draw();
|
||||
Timeout.Set(sb->Timeout() * 100);//max: was 1000 and timeout seems in 1/10 of sec ??
|
||||
Timeout.Set(sb->Timeout() * 1000);//max: was 1000 and timeout seems in 1/10 of sec ??
|
||||
}
|
||||
bitmaps->Del(sb, true);
|
||||
}
|
||||
@@ -946,12 +959,14 @@ void cDvbSubtitleConverter::Action(void)
|
||||
} else {
|
||||
//printf("cDvbSubtitleConverter::Action: timeout elapsed %lld\n", Timeout.Elapsed());
|
||||
if (Timeout.TimedOut()) {
|
||||
//printf("************************************ cDvbSubtitleConverter::Action: we timed out\n");
|
||||
Timeout.Set(0xFFFF*1000);
|
||||
dbgconverter("cDvbSubtitleConverter::Action: timeout, elapsed %lld\n", Timeout.Elapsed());
|
||||
Clear();
|
||||
Timeout.Set(0xFFFF*1000);
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
dbgconverter("cDvbSubtitleConverter::Action: finish, WaitMs %d\n", WaitMs);
|
||||
return WaitMs*1000;
|
||||
}
|
||||
|
||||
tColor cDvbSubtitleConverter::yuv2rgb(int Y, int Cb, int Cr)
|
||||
|
@@ -35,7 +35,7 @@ private:
|
||||
public:
|
||||
cDvbSubtitleConverter(void);
|
||||
virtual ~cDvbSubtitleConverter();
|
||||
void Action(void);
|
||||
int Action(void);
|
||||
void Reset(void);
|
||||
void Clear(void);
|
||||
void Pause(bool pause);
|
||||
|
Reference in New Issue
Block a user