Commit 38e009aa authored by Marko Ristola's avatar Marko Ristola Committed by Mauro Carvalho Chehab

[media] Speed up DVB TS stream delivery from DMA buffer into dvb-core's buffer

Avoid unnecessary DVB TS 188 sized packet copying from DMA buffer into stack.
Backtrack one 188 sized packet just after some garbage bytes when possible.
This obsoletes patch https://patchwork.kernel.org/patch/118147/Signed-off-by: default avatarMarko Ristola <marko.ristola@kolumbus.fi>
Acked-by: default avatarAndreas Oberritter <obi@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3f84a4e1
...@@ -478,97 +478,94 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, ...@@ -478,97 +478,94 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
EXPORT_SYMBOL(dvb_dmx_swfilter_packets); EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) static inline int find_next_packet(const u8 *buf, int pos, size_t count,
const int pktsize)
{ {
int p = 0, i, j; int start = pos, lost;
spin_lock(&demux->lock); while (pos < count) {
if (buf[pos] == 0x47 ||
if (demux->tsbufp) { (pktsize == 204 && buf[pos] == 0xB8))
i = demux->tsbufp; break;
j = 188 - i; pos++;
if (count < j) {
memcpy(&demux->tsbuf[i], buf, count);
demux->tsbufp += count;
goto bailout;
}
memcpy(&demux->tsbuf[i], buf, j);
if (demux->tsbuf[0] == 0x47)
dvb_dmx_swfilter_packet(demux, demux->tsbuf);
demux->tsbufp = 0;
p += j;
} }
while (p < count) { lost = pos - start;
if (buf[p] == 0x47) { if (lost) {
if (count - p >= 188) { /* This garbage is part of a valid packet? */
dvb_dmx_swfilter_packet(demux, &buf[p]); int backtrack = pos - pktsize;
p += 188; if (backtrack >= 0 && (buf[backtrack] == 0x47 ||
} else { (pktsize == 204 && buf[backtrack] == 0xB8)))
i = count - p; return backtrack;
memcpy(demux->tsbuf, &buf[p], i);
demux->tsbufp = i;
goto bailout;
}
} else
p++;
} }
bailout: return pos;
spin_unlock(&demux->lock);
} }
EXPORT_SYMBOL(dvb_dmx_swfilter); /* Filter all pktsize= 188 or 204 sized packets and skip garbage. */
static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) size_t count, const int pktsize)
{ {
int p = 0, i, j; int p = 0, i, j;
u8 tmppack[188]; const u8 *q;
spin_lock(&demux->lock); spin_lock(&demux->lock);
if (demux->tsbufp) { if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */
i = demux->tsbufp; i = demux->tsbufp;
j = 204 - i; j = pktsize - i;
if (count < j) { if (count < j) {
memcpy(&demux->tsbuf[i], buf, count); memcpy(&demux->tsbuf[i], buf, count);
demux->tsbufp += count; demux->tsbufp += count;
goto bailout; goto bailout;
} }
memcpy(&demux->tsbuf[i], buf, j); memcpy(&demux->tsbuf[i], buf, j);
if ((demux->tsbuf[0] == 0x47) || (demux->tsbuf[0] == 0xB8)) { if (demux->tsbuf[0] == 0x47) /* double check */
memcpy(tmppack, demux->tsbuf, 188); dvb_dmx_swfilter_packet(demux, demux->tsbuf);
if (tmppack[0] == 0xB8)
tmppack[0] = 0x47;
dvb_dmx_swfilter_packet(demux, tmppack);
}
demux->tsbufp = 0; demux->tsbufp = 0;
p += j; p += j;
} }
while (p < count) { while (1) {
if ((buf[p] == 0x47) || (buf[p] == 0xB8)) { p = find_next_packet(buf, p, count, pktsize);
if (count - p >= 204) { if (p >= count)
memcpy(tmppack, &buf[p], 188); break;
if (tmppack[0] == 0xB8) if (count - p < pktsize)
tmppack[0] = 0x47; break;
dvb_dmx_swfilter_packet(demux, tmppack);
p += 204; q = &buf[p];
} else {
i = count - p; if (pktsize == 204 && (*q == 0xB8)) {
memcpy(demux->tsbuf, &buf[p], i); memcpy(demux->tsbuf, q, 188);
demux->tsbufp = i; demux->tsbuf[0] = 0x47;
goto bailout; q = demux->tsbuf;
}
} else {
p++;
} }
dvb_dmx_swfilter_packet(demux, q);
p += pktsize;
}
i = count - p;
if (i) {
memcpy(demux->tsbuf, &buf[p], i);
demux->tsbufp = i;
if (pktsize == 204 && demux->tsbuf[0] == 0xB8)
demux->tsbuf[0] = 0x47;
} }
bailout: bailout:
spin_unlock(&demux->lock); spin_unlock(&demux->lock);
} }
void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
{
_dvb_dmx_swfilter(demux, buf, count, 188);
}
EXPORT_SYMBOL(dvb_dmx_swfilter);
void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
{
_dvb_dmx_swfilter(demux, buf, count, 204);
}
EXPORT_SYMBOL(dvb_dmx_swfilter_204); EXPORT_SYMBOL(dvb_dmx_swfilter_204);
static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux) static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment