comparison truemotion2.c @ 8722:ad457492fd92 libavcodec

Factorize stream reading in TM2 decoder
author kostya
date Sun, 01 Feb 2009 15:20:20 +0000
parents e9d9d946f213
children 0acc958e87b0
comparison
equal deleted inserted replaced
8721:42e258f2b931 8722:ad457492fd92
755 } 755 }
756 756
757 return keyframe; 757 return keyframe;
758 } 758 }
759 759
760 static const int tm2_stream_order[TM2_NUM_STREAMS] = {
761 TM2_C_HI, TM2_C_LO, TM2_L_HI, TM2_L_LO, TM2_UPD, TM2_MOT, TM2_TYPE
762 };
763
760 static int decode_frame(AVCodecContext *avctx, 764 static int decode_frame(AVCodecContext *avctx,
761 void *data, int *data_size, 765 void *data, int *data_size,
762 const uint8_t *buf, int buf_size) 766 const uint8_t *buf, int buf_size)
763 { 767 {
764 TM2Context * const l = avctx->priv_data; 768 TM2Context * const l = avctx->priv_data;
765 AVFrame * const p= (AVFrame*)&l->pic; 769 AVFrame * const p= (AVFrame*)&l->pic;
766 int skip, t; 770 int i, skip, t;
767 771
768 p->reference = 1; 772 p->reference = 1;
769 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; 773 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
770 if(avctx->reget_buffer(avctx, p) < 0){ 774 if(avctx->reget_buffer(avctx, p) < 0){
771 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 775 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
776 skip = tm2_read_header(l, buf); 780 skip = tm2_read_header(l, buf);
777 781
778 if(skip == -1) 782 if(skip == -1)
779 return -1; 783 return -1;
780 784
781 t = tm2_read_stream(l, buf + skip, TM2_C_HI); 785 for(i = 0; i < TM2_NUM_STREAMS; i++){
782 if(t == -1) 786 t = tm2_read_stream(l, buf + skip, tm2_stream_order[i]);
783 return -1; 787 if(t == -1){
784 skip += t; 788 return -1;
785 t = tm2_read_stream(l, buf + skip, TM2_C_LO); 789 }
786 if(t == -1) 790 skip += t;
787 return -1; 791 }
788 skip += t;
789 t = tm2_read_stream(l, buf + skip, TM2_L_HI);
790 if(t == -1)
791 return -1;
792 skip += t;
793 t = tm2_read_stream(l, buf + skip, TM2_L_LO);
794 if(t == -1)
795 return -1;
796 skip += t;
797 t = tm2_read_stream(l, buf + skip, TM2_UPD);
798 if(t == -1)
799 return -1;
800 skip += t;
801 t = tm2_read_stream(l, buf + skip, TM2_MOT);
802 if(t == -1)
803 return -1;
804 skip += t;
805 t = tm2_read_stream(l, buf + skip, TM2_TYPE);
806 if(t == -1)
807 return -1;
808 p->key_frame = tm2_decode_blocks(l, p); 792 p->key_frame = tm2_decode_blocks(l, p);
809 if(p->key_frame) 793 if(p->key_frame)
810 p->pict_type = FF_I_TYPE; 794 p->pict_type = FF_I_TYPE;
811 else 795 else
812 p->pict_type = FF_P_TYPE; 796 p->pict_type = FF_P_TYPE;