Skip to content

Commit

Permalink
[eDVBSubtitleParser]
Browse files Browse the repository at this point in the history
* add processBuffer

Thanks to @DimitarCC
  • Loading branch information
jbleyel committed Oct 27, 2024
1 parent 5aa7ab3 commit 5bab9bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
61 changes: 48 additions & 13 deletions lib/dvb/subtitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ int eDVBSubtitleParser::subtitle_process_pixel_data(subtitle_region *region, sub
}
}

int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment, bool isBufferProcess)
{
int segment_type, page_id, segment_length, processed_length;
if (*segment++ != 0x0F)
if (*segment++ != DVB_SUB_SYNC_BYTE)
{
eDebug("[eDVBSubtitleParser] out of sync.");
return -1;
Expand All @@ -269,9 +269,9 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
page_id |= *segment++;
segment_length = *segment++ << 8;
segment_length |= *segment++;
if (segment_type == 0xFF)
if (segment_type == DVB_SUB_SEGMENT_STUFFING)
return segment_length + 6;
if (page_id != m_composition_page_id && page_id != m_ancillary_page_id)
if (page_id != m_composition_page_id && page_id != m_ancillary_page_id && !isBufferProcess)
return segment_length + 6;

subtitle_page *page, **ppage;
Expand All @@ -290,7 +290,7 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)

switch (segment_type)
{
case 0x10: // page composition segment
case DVB_SUB_SEGMENT_PAGE_COMPOSITION:
{
int page_time_out = *segment++; processed_length++;
int page_version_number = *segment >> 4;
Expand All @@ -307,7 +307,8 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
page->cluts = 0;
page->next = 0;
*ppage = page;
} else
}
else
{
if (page->pcs_size != segment_length)
page->page_version_number = -1;
Expand Down Expand Up @@ -383,7 +384,7 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
eDebug("[eDVBSubtitleParser] %d != %d", processed_length, segment_length);
break;
}
case 0x11: // region composition segment
case DVB_SUB_SEGMENT_REGION_COMPOSITION:
{
int region_id = *segment++; processed_length++;
int version_number = *segment >> 4;
Expand Down Expand Up @@ -521,7 +522,7 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)

break;
}
case 0x12: // CLUT definition segment
case DVB_SUB_SEGMENT_CLUT_DEFINITION:
{
int CLUT_id, CLUT_version_number;
subtitle_clut *clut, **pclut;
Expand Down Expand Up @@ -623,7 +624,7 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
}
break;
}
case 0x13: // object data segment
case DVB_SUB_SEGMENT_OBJECT_DATA:
{
int object_id;
int object_coding_method;
Expand Down Expand Up @@ -720,7 +721,7 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
}
break;
}
case 0x14: // display definition segment
case DVB_SUB_SEGMENT_DISPLAY_DEFINITION:
{
if (segment_length > 4)
{
Expand Down Expand Up @@ -752,13 +753,13 @@ int eDVBSubtitleParser::subtitle_process_segment(uint8_t *segment)
eDebug("[eDVBSubtitleParser] display definition segment to short %d!", segment_length);
break;
}
case 0x80: // end of display set segment
case DVB_SUB_SEGMENT_END_OF_DISPLAY_SET:
{
subtitle_redraw_all();
m_seen_eod = true;
break;
}
case 0xFF: // stuffing
case DVB_SUB_SEGMENT_STUFFING:
break;
default:
eDebug("[eDVBSubtitleParser] unhandled segment type %02x", segment_type);
Expand Down Expand Up @@ -792,7 +793,7 @@ void eDVBSubtitleParser::subtitle_process_pes(uint8_t *pkt, int len)

m_seen_eod = false;

while (len && *pkt == 0x0F)
while (len && *pkt == DVB_SUB_SYNC_BYTE)
{
int l = subtitle_process_segment(pkt);
if (l < 0)
Expand Down Expand Up @@ -820,6 +821,35 @@ void eDVBSubtitleParser::subtitle_redraw_all()
}
}


void eDVBSubtitleParser::processBuffer(uint8_t *data, size_t len, pts_t pts)
{
m_show_time = pts;

if (*data != 0x20) {
eWarning("[eDVBSubtitleParser] Tried to handle a PES packet private data that isn't a subtitle packet (does not start with 0x20)");
return;
}

data++; len--; // data identifier
data++; len--; // stream id;


m_seen_eod = false;
while (len && *data == DVB_SUB_SYNC_BYTE)
{
int l = subtitle_process_segment(data, true);
if (l < 0)
break;
data += l;
len -= l;
}

if (len && *data != DVB_SUB_SEGMENT_STUFFING)
eDebug("[eDVBSubtitleParser] strange data at the end");

}

void eDVBSubtitleParser::subtitle_reset()
{
while (subtitle_page *page = m_pages)
Expand Down Expand Up @@ -1072,6 +1102,11 @@ void eDVBSubtitleParser::subtitle_redraw(int page_id)

DEFINE_REF(eDVBSubtitleParser);

eDVBSubtitleParser::eDVBSubtitleParser()
:m_pages(0), m_display_size(720,576)
{
}

eDVBSubtitleParser::eDVBSubtitleParser(iDVBDemux *demux)
:m_pages(0), m_display_size(720,576)
{
Expand Down
14 changes: 13 additions & 1 deletion lib/dvb/subtitle.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#include <lib/dvb/pesparse.h>
#include <lib/gdi/gpixmap.h>

#define DVB_SUB_SEGMENT_PAGE_COMPOSITION 0x10
#define DVB_SUB_SEGMENT_REGION_COMPOSITION 0x11
#define DVB_SUB_SEGMENT_CLUT_DEFINITION 0x12
#define DVB_SUB_SEGMENT_OBJECT_DATA 0x13
#define DVB_SUB_SEGMENT_DISPLAY_DEFINITION 0x14
#define DVB_SUB_SEGMENT_END_OF_DISPLAY_SET 0x80
#define DVB_SUB_SEGMENT_STUFFING 0xFF

#define DVB_SUB_SYNC_BYTE 0x0F

struct subtitle_clut_entry
{
uint8_t Y, Cr, Cb, T;
Expand Down Expand Up @@ -125,9 +135,11 @@ class eDVBSubtitleParser
bool m_seen_eod;
eSize m_display_size;
public:
eDVBSubtitleParser();
eDVBSubtitleParser(iDVBDemux *demux);
virtual ~eDVBSubtitleParser();
int start(int pid, int composition_page_id, int ancillary_page_id);
void processBuffer(uint8_t *data, size_t len, pts_t pts);
int stop();
#if SIGCXX_MAJOR_VERSION == 2
void connectNewPage(const sigc::slot1<void, const eDVBSubtitlePage&> &slot, ePtr<eConnection> &connection);
Expand All @@ -137,7 +149,7 @@ class eDVBSubtitleParser
private:
void subtitle_process_line(subtitle_region *region, subtitle_region_object *object, int line, uint8_t *data, int len);
int subtitle_process_pixel_data(subtitle_region *region, subtitle_region_object *object, int *linenr, int *linep, uint8_t *data);
int subtitle_process_segment(uint8_t *segment);
int subtitle_process_segment(uint8_t *segment, bool isBufferProcess=false);
void subtitle_process_pes(uint8_t *buffer, int len);
void subtitle_redraw_all();
void subtitle_reset();
Expand Down

0 comments on commit 5bab9bc

Please sign in to comment.