Ticket #2252: replex.diff

File replex.diff, 3.7 KB (added by paulh, 18 years ago)

replex patch (apply from within the replex directory)

  • element.h

     
    115115        uint32_t mode_extension;
    116116        uint32_t emphasis;
    117117        uint32_t framesize;
     118    uint32_t frametime;
    118119        uint32_t off;
    119120} audio_frame_t;
    120121
  • replex.c

     
    117117        while (c < len){
    118118                if ( (pos = find_audio_sync(rbuf, buf, c+off, type, len-c) )
    119119                     >= 0 ){
    120                         if (!aframe->set){
     120            if (!aframe->set){
    121121                                switch( type ){
    122122                                case AC3:
    123123                                        re = get_ac3_info(rbuf, aframe,
     
    183183                                }
    184184                        }
    185185
     186                        if (aframe->set && rx->fix_sync && first){
     187                                int frame_time = aframe->frametime;
     188                                int64_t diff;
     189                                diff = ptsdiff(trans_pts_dts(p->pts), add_pts_audio(0, aframe,*acount + 1) + *fpts);
     190                                if (abs ((int)diff) >= frame_time){
     191                                        fprintf(stderr,"fixing audio PTS inconsistency - diff: ");
     192                                        printpts(abs(diff));
     193                                        fprintf(stderr,"\n");
    186194
     195                                        if (diff < 0){
     196                                                diff = abs(diff);
     197                                                int framesdiff = diff / frame_time;
     198                                                fprintf(stderr, "need to remove %d frame(s)\n", framesdiff);
     199                                                //FIXME need to remove audio frame(s) here
     200                                                iu->pts = add_pts_audio(0, aframe, -framesdiff);
     201                                        } else {
     202                                                int framesdiff = diff / frame_time;
     203                                                fprintf(stderr, "need to add %d frame(s)\n", framesdiff);
     204
     205                                                // get a copy of the current audio frame
     206                                                uint8_t *framebuf;
     207                                                if ( !(framebuf = (uint8_t *) malloc(sizeof(uint8_t *) * aframe->framesize))) {
     208                                                        fprintf(stderr,"Not enough memory for audio frame\n");
     209                                                        exit(1);
     210                                                }
     211
     212                                                int res;
     213                                                res = ring_peek(rbuf, framebuf, aframe->framesize, 0);
     214                                                if (res != aframe->framesize) {
     215                                                        fprintf(stderr,"ring buffer failed to peek frame res: %d\n", res);
     216                                                        exit(1);
     217                                                }
     218
     219                                                // add each extra frame required direct to the output file
     220                                                int x;
     221                                                for (x = 0; x < framesdiff; x++){
     222                                                        //FIXME need to fix for ac3 streams
     223                                                        write(rx->dmx_out[num+1], framebuf, aframe->framesize);
     224                                                        *acount += 1;
     225                                                }
     226                                        }
     227                                }
     228                        }
     229
    187230                        if (aframe->set){
    188231                                if(iu->active){
    189232                                        iu->length = ring_posdiff(rbuf,
    190233                                                                  iu->start,
    191234                                                                  p->ini_pos +
    192235                                                                  pos+c);
    193                                         if (iu->length < aframe->framesize ||
     236
     237                                if (iu->length < aframe->framesize ||
    194238                                            iu->length > aframe->framesize+1){
    195239                                                fprintf(stderr,"Wrong audio frame size: %d\n", iu->length);
    196240                                                iu->err= FRAME_ERR;
     
    23512395                        }
    23522396                        fprintf(stderr,"AC3%d output File is: %s\n",i,fname);
    23532397                }
    2354                 do_demux(&rx);
     2398        // FIXME
     2399        rx.fix_sync = 1;
     2400        do_demux(&rx);
    23552401        } else if (analyze){
    23562402                rx.demux=1;
    23572403                do_analyze(&rx);
  • replex.h

     
    4545        int otype;
    4646        int ignore_pts;
    4747        int keep_pts;
     48        int fix_sync;
    4849        uint64_t inflength;
    4950        uint64_t finread;
    5051        int lastper;
  • element.c

     
    517517        af->off = c;
    518518        af->set = 1;
    519519
     520        af->frametime = ((samples [3-af->layer] * 27000000ULL) / af->frequency);
    520521        af->framesize = af->bit_rate *slots [3-af->layer]/ af->frequency;
    521522        fprintf(stderr," frame size: %d (", af->framesize);
    522         printpts( ((samples [3-af->layer] * 27000000ULL)
    523                    / af->frequency));
     523        printpts(af->frametime);
    524524        fprintf(stderr,") ");
    525525
    526526        return c;
     
    572572
    573573        af->off = c;
    574574        af->set = 1;
    575         return c;
     575
     576        //FIXME calculate frametime
     577        af->frametime = 0;
     578
     579    return c;
    576580}
    577581
    578582