[Ffmpeg-cvslog] r7393 - in trunk: libavcodec/mpc.c libavformat/mpc.c

kostya subversion
Mon Jan 1 06:32:27 CET 2007


Author: kostya
Date: Mon Jan  1 06:32:27 2007
New Revision: 7393

Modified:
   trunk/libavcodec/mpc.c
   trunk/libavformat/mpc.c

Log:
Decode previous 32 frames to avoid seeking artifacts in MPC

Modified: trunk/libavcodec/mpc.c
==============================================================================
--- trunk/libavcodec/mpc.c	(original)
+++ trunk/libavcodec/mpc.c	Mon Jan  1 06:32:27 2007
@@ -51,6 +51,7 @@
     int lastframelen, bands;
     int oldDSCF[2][BANDS];
     int rnd;
+    int frames_to_skip;
     /* for synthesis */
     DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]);
     int synth_buf_offset[MPA_MAX_CHANNELS];
@@ -98,6 +99,7 @@
     c->lastframelen = get_bits(&gb, 11);
     av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
             c->IS, c->MSS, c->gapless, c->lastframelen, c->bands);
+    c->frames_to_skip = 0;
 
     if(vlc_inited) return 0;
     av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
@@ -328,11 +330,23 @@
         av_log(NULL,0, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail);
         return -1;
     }
+    if(c->frames_to_skip){
+        c->frames_to_skip--;
+        *data_size = 0;
+        return buf_size;
+    }
     *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4;
 
     return buf_size;
 }
 
+static void mpc7_decode_flush(AVCodecContext *avctx)
+{
+    MPCContext *c = avctx->priv_data;
+
+    memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
+    c->frames_to_skip = 32;
+}
 
 AVCodec mpc7_decoder = {
     "mpc sv7",
@@ -343,4 +357,5 @@
     NULL,
     NULL,
     mpc7_decode_frame,
+    .flush = mpc7_decode_flush,
 };

Modified: trunk/libavformat/mpc.c
==============================================================================
--- trunk/libavformat/mpc.c	(original)
+++ trunk/libavformat/mpc.c	Mon Jan  1 06:32:27 2007
@@ -22,6 +22,7 @@
 #include "bitstream.h"
 
 #define MPC_FRAMESIZE  1152
+#define DELAY_FRAMES   32
 
 static const int mpc_rate[4] = { 44100, 48000, 37800, 32000 };
 typedef struct {
@@ -155,6 +156,7 @@
     pkt->data[1] = (c->curframe > c->fcount);
 
     pkt->stream_index = 0;
+    pkt->pts = cur;
     ret = get_buffer(&s->pb, pkt->data + 4, size);
     if(c->curbits)
         url_fseek(&s->pb, -4, SEEK_CUR);
@@ -188,7 +190,7 @@
     MPCContext *c = s->priv_data;
     AVPacket pkt1, *pkt = &pkt1;
     int ret;
-    int index = av_index_search_timestamp(st, timestamp, flags);
+    int index = av_index_search_timestamp(st, timestamp - DELAY_FRAMES, flags);
     uint32_t lastframe;
 
     /* if found, seek there */
@@ -199,6 +201,7 @@
     /* if timestamp is out of bounds, return error */
     if(timestamp < 0 || timestamp >= c->fcount)
         return -1;
+    timestamp -= DELAY_FRAMES;
     /* seek to the furthest known position and read packets until
        we reach desired position */
     lastframe = c->curframe;




More information about the ffmpeg-cvslog mailing list