Browse code

Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.

Originally committed as revision 16918 to svn://svn.ffmpeg.org/ffmpeg/trunk

Kostya Shishkov authored on 2009/02/02 00:27:44
Showing 1 changed files
... ...
@@ -768,23 +768,33 @@ static int decode_frame(AVCodecContext *avctx,
768 768
     TM2Context * const l = avctx->priv_data;
769 769
     AVFrame * const p= (AVFrame*)&l->pic;
770 770
     int i, skip, t;
771
+    uint8_t *swbuf;
771 772
 
773
+    swbuf = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
774
+    if(!swbuf){
775
+        av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
776
+        return -1;
777
+    }
772 778
     p->reference = 1;
773 779
     p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
774 780
     if(avctx->reget_buffer(avctx, p) < 0){
775 781
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
782
+        av_free(swbuf);
776 783
         return -1;
777 784
     }
778 785
 
779
-    l->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)buf, buf_size >> 2); //FIXME SERIOUS BUG
780
-    skip = tm2_read_header(l, buf);
786
+    l->dsp.bswap_buf((uint32_t*)swbuf, (const uint32_t*)buf, buf_size >> 2);
787
+    skip = tm2_read_header(l, swbuf);
781 788
 
782
-    if(skip == -1)
789
+    if(skip == -1){
790
+        av_free(swbuf);
783 791
         return -1;
792
+    }
784 793
 
785 794
     for(i = 0; i < TM2_NUM_STREAMS; i++){
786
-        t = tm2_read_stream(l, buf + skip, tm2_stream_order[i]);
795
+        t = tm2_read_stream(l, swbuf + skip, tm2_stream_order[i]);
787 796
         if(t == -1){
797
+            av_free(swbuf);
788 798
             return -1;
789 799
         }
790 800
         skip += t;
... ...
@@ -798,6 +808,7 @@ static int decode_frame(AVCodecContext *avctx,
798 798
     l->cur = !l->cur;
799 799
     *data_size = sizeof(AVFrame);
800 800
     *(AVFrame*)data = l->pic;
801
+    av_free(swbuf);
801 802
 
802 803
     return buf_size;
803 804
 }