Ticket #7876: mpegts-33bit.diff

File mpegts-33bit.diff, 1.3 KB (added by malakudi, 7 years ago)

Implements smooth 33-bit mpeg-ts timestamp overflow in mpegts muxer.

  • libavformat/mpegts.c

    old new  
    163163    /** structure to keep track of Program->pids mapping */
    164164    unsigned int nb_prg;
    165165    struct Program *prg;
     166   
     167    /** base timestamp for smooth rolling over 33bits */
     168    int64_t base_ts;
    166169
    167170    int8_t crc_validity[NB_PID_MAX];
    168171    /** filters for various streams specified by PMT + for the PAT and PMT */
    … …  
    982985    pkt->size = len;
    983986}
    984987
     988static int64_t unroll_timestamp(MpegTSContext *ts, int64_t t)
     989{
     990    int64_t dt;
     991
     992    if (t == AV_NOPTS_VALUE)
     993        return t;
     994
     995    if (!ts->base_ts)
     996        ts->base_ts = t;
     997
     998    dt = (t - ts->base_ts) & 0x01ffffffffll;
     999    if (dt & 0x0100000000ll) {
     1000        dt |= 0xffffffff00000000ll;
     1001    }
     1002
     1003    ts->base_ts += dt;
     1004
     1005    return ts->base_ts;
     1006}
     1007
    9851008static int new_pes_packet(PESContext *pes, AVPacket *pkt)
    9861009{
    9871010    uint8_t *sd;
    … …  
    10051028        pkt->stream_index = pes->sub_st->index;
    10061029    else
    10071030        pkt->stream_index = pes->st->index;
    1008     pkt->pts = pes->pts;
    1009     pkt->dts = pes->dts;
     1031    pkt->pts = unroll_timestamp(pes->ts, pes->pts);
     1032    pkt->dts = unroll_timestamp(pes->ts, pes->dts);
    10101033    /* store position of first TS packet of this PES packet */
    10111034    pkt->pos   = pes->ts_packet_pos;
    10121035    pkt->flags = pes->flags;