Merge branch 'master' into pu/mp

Origin commit data
------------------
Branch: ni/coolstream
Commit: 4b8cf23d70
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2017-10-16 (Mon, 16 Oct 2017)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
Jacek Jendrzej
2017-10-16 13:17:17 +02:00
20 changed files with 360 additions and 423 deletions

View File

@@ -50,7 +50,7 @@ static void clear_queue();
int dvbsub_init() {
int trc;
sub_debug.set_level(2);
sub_debug.set_level(3);
reader_running = true;
dvbsub_stopped = 1;
@@ -103,11 +103,7 @@ int dvbsub_start(int pid)
pid_change_req = 1;
}
}
#if 0
printf("[dvb-sub] ***************************************** start, stopped %d pid %x\n", dvbsub_stopped, dvbsub_pid);
while(!dvbsub_stopped)
usleep(10);
#endif
if(dvbsub_pid > 0) {
dvbsub_stopped = 0;
dvbsub_paused = false;
@@ -248,11 +244,8 @@ static void* reader_thread(void * /*arg*/)
set_threadname("dvbsub:reader");
dmx = new cDemux(0);
#if HAVE_TRIPLEDRAGON
dmx->Open(DMX_PES_CHANNEL, NULL, 16*1024);
#else
dmx->Open(DMX_PES_CHANNEL, NULL, 64*1024);
#endif
while (reader_running) {
if(dvbsub_stopped /*dvbsub_paused*/) {
sub_debug.print(Debug::VERBOSE, "%s stopped\n", __FUNCTION__);
@@ -310,17 +303,6 @@ static void* reader_thread(void * /*arg*/)
count += len;
}
}
#if 0
for(int i = 6; i < packlen - 4; i++) {
if(!memcmp(&buf[i], "\x00\x00\x01\xbd", 4)) {
int plen = getbits(&buf[i], 4*8, 16) + 6;
sub_debug.print(Debug::VERBOSE, "[subtitles] ******************* PES header at %d ?! *******************\n", i);
sub_debug.print(Debug::VERBOSE, "[subtitles] start code: %02x%02x%02x%02x len %d\n", buf[i+0], buf[i+1], buf[i+2], buf[i+3], plen);
free(buf);
continue;
}
}
#endif
if(!dvbsub_stopped /*!dvbsub_paused*/) {
sub_debug.print(Debug::VERBOSE, "[subtitles] *** new packet, len %d buf 0x%x pts-stc diff %lld ***\n", count, buf, get_pts_stc_delta(get_pts(buf)));
@@ -400,11 +382,6 @@ static void* dvbsub_thread(void* /*arg*/)
dataoffset = packet[8] + 8 + 1;
if (packet[dataoffset] != 0x20) {
sub_debug.print(Debug::VERBOSE, "Not a dvb subtitle packet, discard it (len %d)\n", packlen);
#if 0
for(int i = 0; i < packlen; i++)
printf("%02X ", packet[i]);
printf("\n");
#endif
goto next_round;
}

View File

@@ -32,12 +32,10 @@ extern "C" {
#endif
// Set these to 'true' for debug output:
static bool DebugConverter = false;
static bool DebugConverter = true;
#define dbgconverter(a...) if (DebugConverter) sub_debug.print(Debug::VERBOSE, a)
// --- cDvbSubtitleBitmaps ---------------------------------------------------
class cDvbSubtitleBitmaps : public cListObject
{
private:
@@ -61,7 +59,7 @@ cDvbSubtitleBitmaps::cDvbSubtitleBitmaps(int64_t pPts)
cDvbSubtitleBitmaps::~cDvbSubtitleBitmaps()
{
// dbgconverter("cDvbSubtitleBitmaps::delete: PTS: %lld rects %d\n", pts, Count());
dbgconverter("cDvbSubtitleBitmaps::delete: PTS: %lld rects %d\n", pts, Count());
int i;
if(sub.rects) {
@@ -87,16 +85,7 @@ fb_pixel_t * simple_resize32(uint8_t * orgin, uint32_t * colors, int nb_colors,
fb_pixel_t *cr,*l;
int i,j,k,ip;
#ifndef HAVE_SPARK_HARDWARE
cr = (fb_pixel_t *) malloc(dx*dy*sizeof(fb_pixel_t));
if(cr == NULL) {
printf("Error: malloc\n");
return NULL;
}
#else
cr = CFrameBuffer::getInstance()->getBackBufferPointer();
#endif
l = cr;
for(j = 0; j < dy; j++, l += dx)
@@ -115,27 +104,8 @@ fb_pixel_t * simple_resize32(uint8_t * orgin, uint32_t * colors, int nb_colors,
void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
{
int i;
#ifndef HAVE_SPARK_HARDWARE
int stride = CFrameBuffer::getInstance()->getScreenWidth(true);
#if 0
int wd = CFrameBuffer::getInstance()->getScreenWidth();
int xstart = CFrameBuffer::getInstance()->getScreenX();
int yend = CFrameBuffer::getInstance()->getScreenY() + CFrameBuffer::getInstance()->getScreenHeight();
int ystart = CFrameBuffer::getInstance()->getScreenY();
#endif
uint32_t *sublfb = CFrameBuffer::getInstance()->getFrameBufferPointer();
#endif
// dbgconverter("cDvbSubtitleBitmaps::Draw: %d bitmaps, x= %d, width= %d yend=%d stride %d\n", Count(), xstart, wd, yend, stride);
int sw = CFrameBuffer::getInstance()->getScreenWidth(true);
int sh = CFrameBuffer::getInstance()->getScreenHeight(true);
#if 0
double xc = (double) CFrameBuffer::getInstance()->getScreenWidth(true)/(double) 720;
double yc = (double) CFrameBuffer::getInstance()->getScreenHeight(true)/(double) 576;
xc = yc; //FIXME should we scale also to full width ?
int xf = int(xc * (double) 720);
#endif
for (i = 0; i < Count(); i++) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0)
@@ -147,28 +117,20 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
int height = sub.rects[i]->h;
int xoff, yoff;
#if 0
int nw = int(width == 1280 ? ((double) width / xc) : ((double) width * xc));
int nh = int((double) height * yc);
int xdiff = (wd > xf) ? ((wd - xf) / 2) : 0;
xoff = int(sub.rects[i]->x*xc + xstart + xdiff);
if(sub.rects[i]->y < 576/2) {
yoff = int(ystart + sub.rects[i]->y*yc);
} else {
yoff = int(yend - ((width == 1280 ? 704:576) - (double) (sub.rects[i]->y + height))*yc - nh);
if(yoff < ystart)
yoff = ystart;
int h2 = 576;
switch (width)
{
case 1280: h2 = 720; break;
case 1920: h2 = 1080; break;
}
#endif
int h2 = (width == 1280) ? 720 : 576;
xoff = sub.rects[i]->x * sw / width;
yoff = sub.rects[i]->y * sh / h2;
int nw = width * sw / width;
int nh = height * sh / h2;
// dbgconverter("cDvbSubtitleBitmaps::Draw: #%d at %d,%d size %dx%d colors %d (x=%d y=%d w=%d h=%d) \n", i+1,
// sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h, sub.rects[i]->nb_colors, xoff, yoff, nw, nh);
dbgconverter("cDvbSubtitleBitmaps::Draw: #%d at %d,%d size %dx%d colors %d (x=%d y=%d w=%d h=%d) \n", i+1,
sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h, sub.rects[i]->nb_colors, xoff, yoff, nw, nh);
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0)
fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->pict.data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh);
@@ -176,18 +138,7 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh);
#endif
#ifdef HAVE_SPARK_HARDWARE
// CFrameBuffer::getInstance()->waitForIdle();
CFrameBuffer::getInstance()->blit2FB(newdata, nw, nh, xoff, yoff, 0, 0);
#else
fb_pixel_t * ptr = newdata;
for (int y2 = 0; y2 < nh; y2++) {
int y = (yoff + y2) * stride;
for (int x2 = 0; x2 < nw; x2++)
*(sublfb + xoff + x2 + y) = *ptr++;
}
free(newdata);
#endif
if(min_x > xoff)
min_x = xoff;
@@ -199,13 +150,12 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
max_y = yoff + nh;
}
// if(Count())
// dbgconverter("cDvbSubtitleBitmaps::Draw: finish, min/max screen: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
// dbgconverter("\n");
if(Count())
dbgconverter("cDvbSubtitleBitmaps::Draw: finish, min/max screen: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
dbgconverter("\n");
}
static int screen_w, screen_h, screen_x, screen_y;
// --- cDvbSubtitleConverter -------------------------------------------------
cDvbSubtitleConverter::cDvbSubtitleConverter(void)
{
@@ -254,12 +204,12 @@ cDvbSubtitleConverter::~cDvbSubtitleConverter()
void cDvbSubtitleConverter::Lock(void)
{
pthread_mutex_lock(&mutex);
pthread_mutex_lock(&mutex);
}
void cDvbSubtitleConverter::Unlock(void)
{
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(&mutex);
}
void cDvbSubtitleConverter::Pause(bool pause)
@@ -272,24 +222,21 @@ void cDvbSubtitleConverter::Pause(bool pause)
Clear();
running = false;
Unlock();
//Reset();
} else {
//Reset();
running = true;
}
}
void cDvbSubtitleConverter::Clear(void)
{
// dbgconverter("cDvbSubtitleConverter::Clear: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
if(running && (max_x-min_x > 0) && (max_y-min_y > 0)) {
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, max_x-min_x, max_y-min_y);
/* reset area to clear */
min_x = screen_w;
min_y = screen_h;
max_x = screen_x;
max_y = screen_h;
//CFrameBuffer::getInstance()->paintBackground();
max_y = screen_y;
}
}
@@ -322,18 +269,17 @@ int cDvbSubtitleConverter::Convert(const uchar *Data, int Length, int64_t pts)
avpkt.data = (uint8_t*) Data;
avpkt.size = Length;
// dbgconverter("cDvbSubtitleConverter::Convert: sub %x pkt %x pts %lld\n", sub, &avpkt, pts);
//avctx->sub_id = (anc_page << 16) | comp_page; //FIXME not patched ffmpeg needs this !
dbgconverter("cDvbSubtitleConverter::Convert: sub %x pkt %x pts %lld\n", sub, &avpkt, pts);
avcodec_decode_subtitle2(avctx, sub, &got_subtitle, &avpkt);
// dbgconverter("cDvbSubtitleConverter::Convert: pts %lld subs ? %s, %d bitmaps\n", pts, got_subtitle? "yes" : "no", sub->num_rects);
dbgconverter("cDvbSubtitleConverter::Convert: pts %lld subs ? %s, %d bitmaps\n", pts, got_subtitle? "yes" : "no", sub->num_rects);
if(got_subtitle) {
if(DebugConverter) {
unsigned int i;
for(i = 0; i < sub->num_rects; i++) {
// dbgconverter("cDvbSubtitleConverter::Convert: #%d at %d,%d size %d x %d colors %d\n", i+1,
// sub->rects[i]->x, sub->rects[i]->y, sub->rects[i]->w, sub->rects[i]->h, sub->rects[i]->nb_colors);
dbgconverter("cDvbSubtitleConverter::Convert: #%d at %d,%d size %d x %d colors %d\n", i+1,
sub->rects[i]->x, sub->rects[i]->y, sub->rects[i]->w, sub->rects[i]->h, sub->rects[i]->nb_colors);
}
}
bitmaps->Add(Bitmaps);
@@ -354,10 +300,7 @@ void dvbsub_get_stc(int64_t * STC);
int cDvbSubtitleConverter::Action(void)
{
int WaitMs = WAITMS;
#if 0
retry:
bool shown = false;
#endif
if (!running)
return 0;
@@ -374,12 +317,12 @@ int cDvbSubtitleConverter::Action(void)
Delta = LimitTo32Bit(sb->Pts()) - LimitTo32Bit(STC);
Delta /= 90; // STC and PTS are in 1/90000s
// dbgconverter("cDvbSubtitleConverter::Action: PTS: %016llx STC: %016llx (%lld) timeout: %d\n", sb->Pts(), STC, Delta, sb->Timeout());
dbgconverter("cDvbSubtitleConverter::Action: PTS: %016llx STC: %016llx (%lld) timeout: %d\n", sb->Pts(), STC, Delta, sb->Timeout());
if (Delta <= MAXDELTA) {
if (Delta <= SHOW_DELTA) {
dbgconverter("cDvbSubtitleConverter::Action: PTS: %012llx STC: %012llx (%lld) timeout: %d bmp %d/%d\n", sb->Pts(), STC, Delta, sb->Timeout(), bitmaps->Count(), sb->Index() + 1);
// dbgconverter("cDvbSubtitleConverter::Action: Got %d bitmaps, showing #%d\n", bitmaps->Count(), sb->Index() + 1);
dbgconverter("cDvbSubtitleConverter::Action: PTS: %012llx STC: %012llx (%lld) timeout: %d bmp %d/%d\n", sb->Pts(), STC, Delta, sb->Timeout(), bitmaps->Count(), sb->Index() + 1);
dbgconverter("cDvbSubtitleConverter::Action: Got %d bitmaps, showing #%d\n", bitmaps->Count(), sb->Index() + 1);
if (running) {
Clear();
sb->Draw(min_x, min_y, max_x, max_y);
@@ -388,7 +331,6 @@ dbgconverter("cDvbSubtitleConverter::Action: PTS: %012llx STC: %012llx (%lld) ti
if(sb->Count())
WaitMs = MIN_DISPLAY_TIME;
bitmaps->Del(sb, true);
// shown = true;
}
else if (Delta < WaitMs)
WaitMs = int((Delta > SHOW_DELTA) ? Delta - SHOW_DELTA : Delta);
@@ -406,10 +348,6 @@ dbgconverter("cDvbSubtitleConverter::Action: PTS: %012llx STC: %012llx (%lld) ti
}
}
Unlock();
#if 0
if (shown)
goto retry;
#endif
if(WaitMs != WAITMS)
dbgconverter("cDvbSubtitleConverter::Action: finish, WaitMs %d\n", WaitMs);