75 changes: 37 additions & 38 deletions mythtv/programs/mythtranscode/external/replex/multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ static int buffers_filled(multiplex_t *mx)
return 0;
}

static int use_video(uint64_t vpts, extdata_t *ext, const int *aok, int n)
static int use_video(uint64_t vpts, ext_arr &ext, const aok_arr &aok, int n)
{
for (int i=0; i < n; i++)
if(aok[i] && ptscmp(vpts,ext[i].pts) > 0)
return 0;
return 1;
}
static int which_ext(extdata_t *ext, const int *aok, int n)
static int which_ext(ext_arr &ext, const aok_arr &aok, int n)
{
int started = 0;
int pos = -1;
Expand Down Expand Up @@ -183,7 +183,7 @@ static uint8_t get_ptsdts(multiplex_t *mx, index_unit *viu)

static void writeout_video(multiplex_t *mx)
{
uint8_t outbuf[3000];
std::array<uint8_t,3000> outbuf {};
int written=0;
uint8_t ptsdts=0;
int frame_len=0;
Expand All @@ -201,13 +201,13 @@ static void writeout_video(multiplex_t *mx)
if (viu->frame_start && viu->seq_header && viu->gop &&
viu->frame == I_FRAME){
if (!mx->startup && mx->is_ts){
write_ts_patpmt(mx->ext, mx->extcnt, 1, outbuf);
write(mx->fd_out, outbuf, mx->pack_size*2);
write_ts_patpmt(mx->ext.data(), mx->extcnt, 1, outbuf.data());
write(mx->fd_out, outbuf.data(), mx->pack_size*2);
ptsinc(&mx->SCR, mx->SCRinc*2);
} else if (!mx->startup && mx->navpack){
write_nav_pack(mx->pack_size, mx->extcnt,
mx->SCR, mx->muxr, outbuf);
write(mx->fd_out, outbuf, mx->pack_size);
mx->SCR, mx->muxr, outbuf.data());
write(mx->fd_out, outbuf.data(), mx->pack_size);
ptsinc(&mx->SCR, mx->SCRinc);
} else mx->startup = 0;
#ifdef OUT_DEBUG
Expand Down Expand Up @@ -247,11 +247,11 @@ static void writeout_video(multiplex_t *mx)
if (viu->frame_start){
viu->frame_start=0;
if (viu->gop){
uint8_t gop[8];
std::vector<uint8_t> gop(8);
frame_len=length-frame_len;
ring_peek(mx->vrbuffer, gop, 8, frame_len);
pts2time( viu->pts + mx->video_delay, gop, 8);
ring_poke(mx->vrbuffer, gop, 8, frame_len);
ring_peek(mx->vrbuffer, gop, frame_len);
pts2time( viu->pts + mx->video_delay, gop.data(), 8);
ring_poke(mx->vrbuffer, gop.data(), 8, frame_len);
viu->gop=0;
}
if (mx->VBR) {
Expand All @@ -276,13 +276,13 @@ static void writeout_video(multiplex_t *mx)
if (mx->is_ts) {
written = write_video_ts( viu->pts+mx->video_delay,
viu->dts+mx->video_delay,
mx->SCR, outbuf, &nlength,
mx->SCR, outbuf.data(), &nlength,
ptsdts, mx->vrbuffer);
} else {
written = write_video_pes( mx->pack_size, mx->extcnt,
viu->pts+mx->video_delay,
viu->dts+mx->video_delay,
mx->SCR, mx->muxr, outbuf, &nlength,
mx->SCR, mx->muxr, outbuf.data(), &nlength,
ptsdts, mx->vrbuffer);
}

Expand All @@ -298,7 +298,7 @@ static void writeout_video(multiplex_t *mx)
//estimate next pts based on bitrate of this stream and data written
viu->dts = uptsdiff(viu->dts + ((nlength*viu->ptsrate)>>8), 0);

write(mx->fd_out, outbuf, written);
write(mx->fd_out, outbuf.data(), written);

#ifdef OUT_DEBUG
LOG(VB_GENERAL, LOG_DEBUG, "VPTS");
Expand All @@ -316,7 +316,7 @@ static void writeout_video(multiplex_t *mx)

static void writeout_ext(multiplex_t *mx, int n)
{
uint8_t outbuf[3000];
std::array<uint8_t,3000> outbuf {};
int written=0;
uint64_t dpts=0;
int newpts=0;
Expand Down Expand Up @@ -412,24 +412,24 @@ static void writeout_ext(multiplex_t *mx, int n)
case MPEG_AUDIO:
if(mx->is_ts) {
written = write_audio_ts( mx->ext[n].strmnum, pts,
outbuf, &nlength, newpts ? 0 : PTS_ONLY,
outbuf.data(), &nlength, newpts ? 0 : PTS_ONLY,
&mx->extrbuffer[n]);
} else {
written = write_audio_pes( mx->pack_size, mx->extcnt,
mx->ext[n].strmnum, pts, mx->SCR,
mx->muxr, outbuf, &nlength, PTS_ONLY,
mx->muxr, outbuf.data(), &nlength, PTS_ONLY,
&mx->extrbuffer[n]);
}
break;
case AC3:
if(mx->is_ts) {
written = write_ac3_ts(mx->ext[n].strmnum, pts,
outbuf, &nlength, newpts ? 0 : PTS_ONLY,
outbuf.data(), &nlength, newpts ? 0 : PTS_ONLY,
mx->ext[n].frmperpkt, &mx->extrbuffer[n]);
} else {
written = write_ac3_pes( mx->pack_size, mx->extcnt,
mx->ext[n].strmnum, pts, mx->SCR,
mx->muxr, outbuf, &nlength, PTS_ONLY,
mx->muxr, outbuf.data(), &nlength, PTS_ONLY,
nframes, ac3_off,
&mx->extrbuffer[n]);
}
Expand All @@ -442,7 +442,7 @@ static void writeout_ext(multiplex_t *mx, int n)
return;

length -= nlength;
write(mx->fd_out, outbuf, written);
write(mx->fd_out, outbuf.data(), written);

dummy_add(dbuf, dpts, aiu->length-length);
aiu->length = length;
Expand Down Expand Up @@ -472,21 +472,21 @@ static void writeout_ext(multiplex_t *mx, int n)

static void writeout_padding (multiplex_t *mx)
{
uint8_t outbuf[3000];
std::array<uint8_t,3000> outbuf {};
#if 0
LOG(VB_GENERAL, LOG_INFO, "writing PADDING pack");
#endif

write_padding_pes( mx->pack_size, mx->extcnt, mx->SCR,
mx->muxr, outbuf);
write(mx->fd_out, outbuf, mx->pack_size);
mx->muxr, outbuf.data());
write(mx->fd_out, outbuf.data(), mx->pack_size);
}

void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start)
void check_times( multiplex_t *mx, int *video_ok, aok_arr &ext_ok, int *start)
{
int set_ok = 0;

memset(ext_ok, 0, N_AUDIO*sizeof(int));
ext_ok.fill(false);
*video_ok = 0;

if (mx->fill_buffers(mx->priv, mx->finish)< 0) {
Expand Down Expand Up @@ -555,7 +555,7 @@ void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start)
mx->ext[i].iu.length > 0 &&
ptscmp(mx->ext[i].pts, 500*CLOCK_MS + mx->oldSCR) < 0
&& ring_avail(&mx->index_extrbuffer[i])){
ext_ok[i] = 1;
ext_ok[i] = true;
set_ok = 1; //NOLINT(clang-analyzer-deadcode.DeadStores)
}
}
Expand All @@ -578,7 +578,7 @@ void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start)
(void)set_ok;
#endif
}
void write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok)
void write_out_packs( multiplex_t *mx, int video_ok, aok_arr &ext_ok)
{
if (video_ok && use_video(mx->viu.dts + mx->video_delay,
mx->ext, ext_ok, mx->extcnt)) {
Expand All @@ -601,11 +601,10 @@ void finish_mpg(multiplex_t *mx)
{
int start=0;
int video_ok = 0;
int ext_ok[N_AUDIO];
aok_arr ext_ok {};
int n = 0;
uint8_t mpeg_end[4] = { 0x00, 0x00, 0x01, 0xB9 };
std::array<uint8_t,4> mpeg_end { 0x00, 0x00, 0x01, 0xB9 };

memset(ext_ok, 0, N_AUDIO*sizeof(int));
mx->finish = 1;

int old = 0;
Expand Down Expand Up @@ -641,7 +640,7 @@ void finish_mpg(multiplex_t *mx)
}

if (mx->otype == REPLEX_MPEG2)
write(mx->fd_out, mpeg_end,4);
write(mx->fd_out, mpeg_end.data(), 4);

dummy_destroy(&mx->vdbuf);
for (int i=0; i<mx->extcnt;i++)
Expand Down Expand Up @@ -807,7 +806,7 @@ void init_multiplex( multiplex_t *mx, sequence_t *seq_head,
//Use best guess for TS streams
mx->data_size = get_ts_video_overhead(mx->pack_size, seq_head);
mx->extsize = get_ts_ext_overhead(mx->pack_size, extframe,
mx->ext, mx->extcnt);
mx->ext.data(), mx->extcnt);

} else {
//Use worst case for PS streams
Expand Down Expand Up @@ -855,16 +854,16 @@ void setup_multiplex(multiplex_t *mx)

// write first VOBU header
if (mx->is_ts) {
uint8_t outbuf[2048];
write_ts_patpmt(mx->ext, mx->extcnt, 1, outbuf);
write(mx->fd_out, outbuf, mx->pack_size*2);
std::array<uint8_t,2048> outbuf {};
write_ts_patpmt(mx->ext.data(), mx->extcnt, 1, outbuf.data());
write(mx->fd_out, outbuf.data(), mx->pack_size*2);
ptsinc(&mx->SCR, mx->SCRinc*2);
mx->startup = 1;
} else if (mx->navpack){
uint8_t outbuf[2048];
std::array<uint8_t,2048> outbuf {};
write_nav_pack(mx->pack_size, mx->extcnt,
mx->SCR, mx->muxr, outbuf);
write(mx->fd_out, outbuf, mx->pack_size);
mx->SCR, mx->muxr, outbuf.data());
write(mx->fd_out, outbuf.data(), mx->pack_size);
ptsinc(&mx->SCR, mx->SCRinc);
mx->startup = 1;
} else mx->startup = 0;
Expand Down
11 changes: 8 additions & 3 deletions mythtv/programs/mythtranscode/external/replex/multiplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@
#ifndef MULTIPLEX_H
#define MULTIPLEX_H

#include <array>

#include "mpg_common.h"
#include "pes.h"
#include "element.h"

#define N_AUDIO 32
#define N_AC3 8

using ext_arr = std::array<extdata_t,N_AUDIO>;
using aok_arr = std::array<bool,N_AUDIO>;

struct multiplex_t {
int fd_out;
#define REPLEX_MPEG2 0
Expand Down Expand Up @@ -71,7 +76,7 @@ struct multiplex_t {

dummy_buffer vdbuf;

extdata_t ext[N_AUDIO];
ext_arr ext;
int extcnt;

ringbuffer *extrbuffer;
Expand All @@ -83,8 +88,8 @@ struct multiplex_t {
void *priv;
};

void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start);
void write_out_packs( multiplex_t *mx, int video_ok, int *ext_ok);
void check_times( multiplex_t *mx, int *video_ok, aok_arr &ext_ok, int *start);
void write_out_packs( multiplex_t *mx, int video_ok, aok_arr &ext_ok);
void finish_mpg(multiplex_t *mx);
void init_multiplex( multiplex_t *mx, sequence_t *seq_head,
audio_frame_t *extframe, int *exttype, const int *exttypcnt,
Expand Down
46 changes: 24 additions & 22 deletions mythtv/programs/mythtranscode/external/replex/pes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
*/

#include <array>
#include <cstdio>
#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -165,7 +166,7 @@ void get_pes (pes_in_t *p, uint8_t *buf, int count, void (*func)(pes_in_t *p))
unsigned short *pl = nullptr;
bool done = true;

uint8_t headr[3] = { 0x00, 0x00, 0x01} ;
std::array<uint8_t,3> headr { 0x00, 0x00, 0x01} ;
do {
int c=0;
done = true;
Expand Down Expand Up @@ -287,11 +288,11 @@ void get_pes (pes_in_t *p, uint8_t *buf, int count, void (*func)(pes_in_t *p))
case PRIVATE_STREAM1:

if (p->withbuf){
memcpy(p->buf, headr, 3);
memcpy(p->buf, headr.data(), 3);
p->buf[3] = p->cid;
memcpy(p->buf+4,p->plen,2);
} else {
memcpy(p->hbuf, headr, 3);
memcpy(p->hbuf, headr.data(), 3);
p->hbuf[3] = p->cid;
memcpy(p->hbuf+4,p->plen,2);
}
Expand Down Expand Up @@ -461,12 +462,12 @@ static void setl_ps(ps_packet *p)
static int cwrite_ps(uint8_t *buf, ps_packet *p, uint32_t length)
{
(void)length;
uint8_t headr1[4] = {0x00, 0x00, 0x01, PACK_START };
uint8_t headr2[4] = {0x00, 0x00, 0x01, SYS_START };
std::array<uint8_t,4> headr1 {0x00, 0x00, 0x01, PACK_START };
std::array<uint8_t,4> headr2 {0x00, 0x00, 0x01, SYS_START };
uint8_t buffy = 0xFF;


memcpy(buf,headr1,4);
memcpy(buf,headr1.data(),4);
long count = 4;
memcpy(buf+count,p->scr,6);
count += 6;
Expand All @@ -480,7 +481,7 @@ static int cwrite_ps(uint8_t *buf, ps_packet *p, uint32_t length)
}

if (p->sheader_length){
memcpy(buf+count,headr2,4);
memcpy(buf+count,headr2.data(),4);
count += 4;
memcpy(buf+count,p->sheader_llength,2);
count += 2;
Expand Down Expand Up @@ -582,8 +583,9 @@ static int write_ps_header(uint8_t *buf,
return PS_HEADER_L1;
}

using pts_arr = std::array<uint8_t,5>;

static void get_pespts(const uint8_t *spts,uint8_t *pts)
static void get_pespts(const uint8_t *spts, pts_arr &pts)
{
//Make sure to set the 1st 4 bits properly
pts[0] = 0x01 |
Expand All @@ -600,11 +602,11 @@ static void get_pespts(const uint8_t *spts,uint8_t *pts)
int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,
uint8_t *obuf, int stuffing, uint8_t ptsdts)
{
uint8_t le[2];
uint8_t dummy[3];
uint8_t ppts[5];
uint8_t pdts[5];
uint8_t headr[3] = {0x00, 0x00, 0x01};
std::array<uint8_t,2> le {};
std::array<uint8_t,3> dummy {};
pts_arr ppts {};
pts_arr pdts {};
std::array<uint8_t,3> headr {0x00, 0x00, 0x01};

uint32_t lpts = htonl((PTS/300ULL) & 0x00000000FFFFFFFFULL);
auto *pts = (uint8_t *) &lpts;
Expand All @@ -617,7 +619,7 @@ int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,
if ((DTS/300ULL) & 0x0000000100000000ULL) pdts[0] |= 0x80;

int c = 0;
memcpy(obuf+c,headr,3);
memcpy(obuf+c,headr.data(),3);
c += 3;
memcpy(obuf+c,&id,1);
c++;
Expand All @@ -628,7 +630,7 @@ int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,

le[0] |= ((uint8_t)(length >> 8) & 0xFF);
le[1] |= ((uint8_t)(length) & 0xFF);
memcpy(obuf+c,le,2);
memcpy(obuf+c,le.data(),2);
c += 2;

if (id == PADDING_STREAM){
Expand All @@ -653,16 +655,16 @@ int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,
}


memcpy(obuf+c,dummy,3);
memcpy(obuf+c,dummy.data(),3);
c += 3;

if (ptsdts == PTS_ONLY){
memcpy(obuf+c,ppts,5);
memcpy(obuf+c,ppts.data(),5);
c += 5;
} else if ( ptsdts == PTS_DTS ){
memcpy(obuf+c,ppts,5);
memcpy(obuf+c,ppts.data(),5);
c += 5;
memcpy(obuf+c,pdts,5);
memcpy(obuf+c,pdts.data(),5);
c += 5;
}

Expand Down Expand Up @@ -836,17 +838,17 @@ int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr,
uint8_t *buf)
{
int pos = 0;
uint8_t headr[5] = {0x00, 0x00, 0x01, PRIVATE_STREAM2, 0x03 };
std::array<uint8_t,5> headr {0x00, 0x00, 0x01, PRIVATE_STREAM2, 0x03 };
(void)pack_size;

pos = write_ps_header( buf, SCR, muxr, extcnt, 0, 0, 1, 1, 1, 1);
memcpy(buf+pos, headr, 5);
memcpy(buf+pos, headr.data(), 5);
buf[pos+5] = 0xD4;
pos += 6;
memset(buf+pos, 0, 0x03d4);
pos += 0x03d4;

memcpy(buf+pos, headr, 5);
memcpy(buf+pos, headr.data(), 5);
buf[pos+5] = 0xFA;
pos += 6;
memset(buf+pos, 0, 0x03fA);
Expand Down
12 changes: 5 additions & 7 deletions mythtv/programs/mythtranscode/external/replex/replex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void analyze_audio( pes_in_t *p, struct replex *rx, int len, int num, int
uint64_t *lpts=nullptr;
int bsize = 0;
int first = 1;
uint8_t buf[7];
audio_sync_buf buf;
int off=0;
int *apes_abort=nullptr;
int re=0;
Expand Down Expand Up @@ -508,7 +508,7 @@ static void analyze_audio( pes_in_t *p, struct replex *rx, int len, int num, int

static void analyze_video( pes_in_t *p, struct replex *rx, int len)
{
uint8_t buf[8];
std::vector<uint8_t> buf(8);
int c=0;
int pos=0;
uint8_t head;
Expand Down Expand Up @@ -745,8 +745,7 @@ static void analyze_video( pes_in_t *p, struct replex *rx, int len)
gop = 1;
gop_off = c+pos - seq_p;

if (ring_peek(rbuf, (uint8_t *) buf, 7,
off+c+pos) < 0){
if (ring_peek(rbuf, buf, 7, off+c+pos) < 0) {
rx->vpes_abort = len -(c+pos-1);
return;
}
Expand Down Expand Up @@ -774,7 +773,7 @@ static void analyze_video( pes_in_t *p, struct replex *rx, int len)
return;
}

if (ring_peek(rbuf, (uint8_t *) buf, 6,
if (ring_peek(rbuf, buf, 6,
off+c+pos) < 0) return;


Expand Down Expand Up @@ -2341,14 +2340,13 @@ static void do_demux(struct replex *rx)
static void do_replex(struct replex *rx)
{
int video_ok = 0;
int ext_ok[N_AUDIO];
aok_arr ext_ok {};
int start=1;
multiplex_t mx;


LOG(VB_GENERAL, LOG_INFO, "STARTING REPLEX");
memset(&mx, 0, sizeof(mx));
memset(ext_ok, 0, N_AUDIO*sizeof(int));

while (!replex_all_set(rx)){
if (replex_fill_buffers(rx, nullptr)< 0) {
Expand Down
45 changes: 28 additions & 17 deletions mythtv/programs/mythtranscode/external/replex/ringbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
return count;
}

int ring_peek(ringbuffer *rbuf, peek_poke_vec data, unsigned int count, uint32_t off)
{
return ring_peek(rbuf, data.data(), count, off);
}

int ring_peek(ringbuffer *rbuf, peek_poke_vec data, uint32_t off)
{
return ring_peek(rbuf, data.data(), data.size(), off);
}

int ring_poke(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
{
if (off+count > rbuf->size || off+count >ring_avail(rbuf))
Expand Down Expand Up @@ -177,6 +187,16 @@ int ring_poke(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
return count;
}

int ring_poke(ringbuffer *rbuf, peek_poke_vec data, unsigned int count, uint32_t off)
{
return ring_poke(rbuf, data.data(), count, off);
}

int ring_poke(ringbuffer *rbuf, peek_poke_vec data, uint32_t off)
{
return ring_poke(rbuf, data.data(), data.size(), off);
}

int ring_read(ringbuffer *rbuf, uint8_t *data, int count)
{
if (count <=0 ) return 0;
Expand Down Expand Up @@ -318,40 +338,31 @@ int ring_read_file(ringbuffer *rbuf, int fd, int count)

static void show(uint8_t *buf, int length)
{
char temp[8];
char buffer[100];
buffer[0] = '\0';
QString buffer;

for (int i=0; i<length; i+=16){
int j = 0;
for (j=0; j < 8 && j+i<length; j++)
{
std::sprintf(temp, "0x%02x ", (int)(buf[i+j]));
std::strcat(buffer, temp);
}
buffer += QString("0x%1 ").arg(buf[i+j],16,2,QChar('0'));
for (int r=j; r<8; r++)
std::strcat(buffer, " ");
buffer += " ";

std::strcat(buffer," ");
buffer += " ";

for (j=8; j < 16 && j+i<length; j++)
{
std::sprintf(temp, "0x%02x ", (int)(buf[i+j]));
std::strcat(buffer, temp);
}
buffer += QString("0x%1 ").arg(buf[i+j],16,2,QChar('0'));
for (int r=j; r<16; r++)
std::strcat(buffer, " ");
buffer += " ";

for (j=0; j < 16 && j+i<length; j++){
switch(buf[i+j]){
case '0'...'Z':
case 'a'...'z':
std::sprintf(temp, "%c", buf[i+j]);
buffer += QString(buf[i+j]);
break;
default:
std::sprintf(temp, ".");
buffer += ".";
}
std::strcat(buffer, temp);
}
LOG(VB_GENERAL, LOG_INFO, buffer);
}
Expand Down
9 changes: 9 additions & 0 deletions mythtv/programs/mythtranscode/external/replex/ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <cstdio>
#include <cstdint>
#include <unistd.h>
#include <vector>

using peek_poke_vec = std::vector<uint8_t>;

#define FULL_BUFFER (-1000)
#define EMPTY_BUFFER (-1000)
Expand Down Expand Up @@ -61,8 +64,14 @@
int ring_read_file(ringbuffer *rbuf, int fd, int count);
int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count,
uint32_t off);
int ring_peek(ringbuffer *rbuf, peek_poke_vec data, unsigned int count,
uint32_t off);
int ring_peek(ringbuffer *rbuf, peek_poke_vec data, uint32_t off);
int ring_poke(ringbuffer *rbuf, uint8_t *data, unsigned int count,
uint32_t off);
int ring_poke(ringbuffer *rbuf, peek_poke_vec data, unsigned int count,
uint32_t off);
int ring_poke(ringbuffer *rbuf, peek_poke_vec data, uint32_t off);
int ring_skip(ringbuffer *rbuf, int count);

static inline int ring_wpos(ringbuffer *rbuf)
Expand Down
27 changes: 15 additions & 12 deletions mythtv/programs/mythtranscode/external/replex/ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
*/

#include <array>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -130,7 +131,7 @@ int find_pids(uint16_t *vpid, uint16_t *apid, uint16_t *ac3pid,uint8_t *buf, int

//taken and adapted from libdtv, (c) Rolf Hakenes
// CRC32 lookup table for polynomial 0x04c11db7
static unsigned int crc_table[256] = {
static const std::array <const uint32_t,256> crc_table {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
Expand Down Expand Up @@ -287,8 +288,8 @@ int write_video_ts(uint64_t vpts, uint64_t vdts, uint64_t SCR, uint8_t *buf,
int write_audio_ts(int n, uint64_t pts, uint8_t *buf, int *alength,
uint8_t ptsdts, ringbuffer *arbuffer)
{
static int s_count[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static std::array<int,32> s_count {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int pos = 0;
int stuff = 0;
int length = *alength;
Expand Down Expand Up @@ -330,8 +331,8 @@ int write_audio_ts(int n, uint64_t pts, uint8_t *buf, int *alength,
int write_ac3_ts(int n, uint64_t pts, uint8_t *buf, int *alength,
uint8_t ptsdts, int nframes, ringbuffer *ac3rbuffer)
{
static int s_count[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static std::array<int,32> s_count {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int pos = 0;
int stuff = 0;
int length = *alength;
Expand Down Expand Up @@ -384,16 +385,18 @@ void write_ts_patpmt(extdata_t *ext, int extcnt, uint8_t prog_num, uint8_t *buf)
int pmtpos = 13;
//PMT Program number = 1
//PMT PID = 0x20
uint8_t pat[17] = {0x00, 0x00, 0xb0, 0x0d, 0xfe, 0xef, 0xc1, 0x00, 0x00,
0x00, 0x00, 0xe0, PMTPID, 0x00, 0x00, 0x00, 0x00};
uint8_t pmt[184] ={0x00, 0x02, 0xb0, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x00};
std::array<uint8_t,17> pat
{0x00, 0x00, 0xb0, 0x0d, 0xfe, 0xef, 0xc1, 0x00, 0x00,
0x00, 0x00, 0xe0, PMTPID, 0x00, 0x00, 0x00, 0x00};
std::array<uint8_t,184> pmt
{0x00, 0x02, 0xb0, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x00};

//PAT
pat[10] = prog_num;
int pos = write_ts_header(0x00, 1, s_count, -1, buf, 0);
*(uint32_t *)(pat+13)= htonl(crc32_04c11db7(pat+1, 12, 0xffffffff));
memcpy(buf+pos, pat, 17);
*(uint32_t *)(pat.data()+13)= htonl(crc32_04c11db7(pat.data()+1, 12, 0xffffffff));
memcpy(buf+pos, pat.data(), 17);
pos += 17;
memset(buf+pos, 0xff, TS_SIZE - pos);
pos = TS_SIZE;
Expand Down Expand Up @@ -439,7 +442,7 @@ void write_ts_patpmt(extdata_t *ext, int extcnt, uint8_t prog_num, uint8_t *buf)
*(uint32_t *)&pmt[pmtpos] = htonl(crc32_04c11db7(&pmt[1], pmtpos -1,
0xffffffff));
pmtpos+=4;
memcpy(buf+pos, pmt, pmtpos);
memcpy(buf+pos, pmt.data(), pmtpos);
pos += pmtpos;
memset(buf+pos, 0xff, 2*TS_SIZE - pos);
// pos = 2*TS_SIZE;
Expand Down
16 changes: 7 additions & 9 deletions mythtv/programs/mythtranscode/mpeg2fix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void MPEG2replex::Start()
//array defines number of allowed audio streams
// note that although only 1 stream is currently supported, multiplex.c
// expects the size to by N_AUDIO
int ext_ok[N_AUDIO];
aok_arr ext_ok {};
int video_ok = 0;

//seq_head should be set only for the 1st sequence header. If a new
Expand All @@ -547,8 +547,6 @@ void MPEG2replex::Start()
int video_delay = 0;
int audio_delay = 0;

memset(ext_ok, 0, sizeof(ext_ok));

mx.priv = (void *)this;

int fd_out = open(m_outfile.toLocal8Bit().constData(),
Expand Down Expand Up @@ -976,8 +974,8 @@ int MPEG2fixup::ProcessVideo(MPEG2frame *vf, mpeg2dec_t *dec)
// (for B-frames only).
// 0xb2 is 'user data' and is actually illegal between pic
// headers, but it is just discarded by libmpeg2
uint8_t tmp[8] = {0x00, 0x00, 0x01, 0xb2, 0xff, 0xff, 0xff, 0xff};
mpeg2_buffer(dec, tmp, tmp + 8);
std::array<uint8_t,8> tmp {0x00, 0x00, 0x01, 0xb2, 0xff, 0xff, 0xff, 0xff};
mpeg2_buffer(dec, tmp.data(), tmp.data() + 8);
mpeg2_parse(dec);
}
}
Expand Down Expand Up @@ -1131,7 +1129,7 @@ void MPEG2fixup::WriteData(const QString& filename, uint8_t *data, int size)

bool MPEG2fixup::BuildFrame(AVPacket *pkt, const QString& fname)
{
uint16_t intra_matrix[64] ATTR_ALIGN(16);
std::array<uint16_t,64> intra_matrix {} ATTR_ALIGN(16);
int64_t savedPts = pkt->pts; // save the original pts

const mpeg2_info_t *info = mpeg2_info(m_imgDecoder);
Expand Down Expand Up @@ -1234,7 +1232,7 @@ bool MPEG2fixup::BuildFrame(AVPacket *pkt, const QString& fname)
// c->flags=CODEC_FLAG_LOW_DELAY;

if (intra_matrix[0] == 0x08)
c->intra_matrix = intra_matrix;
c->intra_matrix = intra_matrix.data();

c->qmin = c->qmax = 2;

Expand Down Expand Up @@ -1891,7 +1889,7 @@ void MPEG2fixup::AddRangeList(const QStringList& rangelist, int type)
if (tmp.size() < 2)
continue;

bool ok[2] = { false, false };
std::array<bool,2> ok { false, false };

long long start = tmp[0].toLongLong(&ok[0]);
long long end = tmp[1].toLongLong(&ok[1]);
Expand Down Expand Up @@ -2015,7 +2013,7 @@ int MPEG2fixup::Start()
// accounting of rounding errors (still won't be right, but better)
int64_t lastPTS = 0;
int64_t deltaPTS = 0;
int64_t origaPTS[N_AUDIO];
std::array<int64_t,N_AUDIO> origaPTS {};
int64_t cutStartPTS = 0;
int64_t cutEndPTS = 0;
uint64_t frame_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtranscode/mpeg2fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class MPEG2fixup
int m_frameNum {0};
int m_statusUpdateTime {5};
uint64_t m_lastWrittenPos {0};
uint16_t m_invZigzagDirect16[64] {};
std::array<uint16_t,64> m_invZigzagDirect16 {};
bool m_zigzagInit {false};
};

Expand Down