Mercurial > libavcodec.hg
comparison vp3.c @ 1664:1c7ded3c2b25 libavcodec
more correct header parsing
author | alex |
---|---|
date | Mon, 08 Dec 2003 11:32:06 +0000 |
parents | a80b15c0b9d5 |
children | 720c073661a1 |
comparison
equal
deleted
inserted
replaced
1663:4ac3573977e6 | 1664:1c7ded3c2b25 |
---|---|
214 #define MIN_DEQUANT_VAL 2 | 214 #define MIN_DEQUANT_VAL 2 |
215 | 215 |
216 typedef struct Vp3DecodeContext { | 216 typedef struct Vp3DecodeContext { |
217 AVCodecContext *avctx; | 217 AVCodecContext *avctx; |
218 int theora, theora_tables; | 218 int theora, theora_tables; |
219 int version; | |
219 int width, height; | 220 int width, height; |
220 AVFrame golden_frame; | 221 AVFrame golden_frame; |
221 AVFrame last_frame; | 222 AVFrame last_frame; |
222 AVFrame current_frame; | 223 AVFrame current_frame; |
223 int keyframe; | 224 int keyframe; |
299 int last_coded_c_fragment; | 300 int last_coded_c_fragment; |
300 | 301 |
301 uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc | 302 uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc |
302 uint8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16 | 303 uint8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16 |
303 } Vp3DecodeContext; | 304 } Vp3DecodeContext; |
305 | |
306 static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb); | |
307 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb); | |
304 | 308 |
305 /************************************************************************ | 309 /************************************************************************ |
306 * VP3 I/DCT | 310 * VP3 I/DCT |
307 ************************************************************************/ | 311 ************************************************************************/ |
308 | 312 |
2609 int c_width; | 2613 int c_width; |
2610 int c_height; | 2614 int c_height; |
2611 int y_superblock_count; | 2615 int y_superblock_count; |
2612 int c_superblock_count; | 2616 int c_superblock_count; |
2613 | 2617 |
2618 if (avctx->codec_tag == MKTAG('V','P','3','0')) | |
2619 s->version = 0; | |
2620 else | |
2621 s->version = 1; | |
2622 | |
2614 s->avctx = avctx; | 2623 s->avctx = avctx; |
2615 #if 0 | 2624 #if 0 |
2616 s->width = avctx->width; | 2625 s->width = avctx->width; |
2617 s->height = avctx->height; | 2626 s->height = avctx->height; |
2618 #else | 2627 #else |
2754 | 2763 |
2755 init_get_bits(&gb, buf, buf_size * 8); | 2764 init_get_bits(&gb, buf, buf_size * 8); |
2756 | 2765 |
2757 if (s->theora && get_bits1(&gb)) | 2766 if (s->theora && get_bits1(&gb)) |
2758 { | 2767 { |
2759 av_log(s->avctx, AV_LOG_ERROR, "Theora: bad frame indicator\n"); | 2768 int ptype = get_bits(&gb, 7); |
2760 return -1; | 2769 |
2770 skip_bits(&gb, 6*8); /* "theora" */ | |
2771 | |
2772 switch(ptype) | |
2773 { | |
2774 case 1: | |
2775 theora_decode_comments(avctx, gb); | |
2776 break; | |
2777 case 2: | |
2778 theora_decode_tables(avctx, gb); | |
2779 init_dequantizer(s); | |
2780 break; | |
2781 default: | |
2782 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); | |
2783 } | |
2784 return buf_size; | |
2761 } | 2785 } |
2762 | 2786 |
2763 s->keyframe = !get_bits1(&gb); | 2787 s->keyframe = !get_bits1(&gb); |
2764 if (s->theora) | 2788 if (!s->theora) |
2765 { | |
2766 s->last_quality_index = s->quality_index; | |
2767 s->quality_index = get_bits(&gb, 6); | |
2768 if (s->theora >= 0x030300) | |
2769 skip_bits1(&gb); | |
2770 if (s->keyframe) | |
2771 { | |
2772 if (get_bits1(&gb)) | |
2773 av_log(s->avctx, AV_LOG_ERROR, "Theora: warning, unsupported keyframe coding type?!\n"); | |
2774 skip_bits(&gb, 2); /* reserved? */ | |
2775 } | |
2776 } | |
2777 else | |
2778 { | |
2779 skip_bits(&gb, 1); | 2789 skip_bits(&gb, 1); |
2780 s->last_quality_index = s->quality_index; | 2790 s->last_quality_index = s->quality_index; |
2781 s->quality_index = get_bits(&gb, 6); | 2791 s->quality_index = get_bits(&gb, 6); |
2782 } | 2792 if (s->theora >= 0x030300) |
2793 skip_bits1(&gb); | |
2783 | 2794 |
2784 debug_vp3(" VP3 %sframe #%d: Q index = %d\n", | 2795 debug_vp3(" VP3 %sframe #%d: Q index = %d\n", |
2785 s->keyframe?"key":"", counter, s->quality_index); | 2796 s->keyframe?"key":"", counter, s->quality_index); |
2786 counter++; | 2797 counter++; |
2787 | 2798 |
2788 if (s->quality_index != s->last_quality_index) | 2799 if (s->quality_index != s->last_quality_index) |
2789 init_dequantizer(s); | 2800 init_dequantizer(s); |
2790 | 2801 |
2791 if (s->keyframe) { | 2802 if (s->keyframe) { |
2792 /* skip the other 2 header bytes for now */ | 2803 if (!s->theora) |
2793 if (!s->theora) skip_bits(&gb, 16); | 2804 { |
2805 skip_bits(&gb, 4); /* width code */ | |
2806 skip_bits(&gb, 4); /* height code */ | |
2807 if (s->version) | |
2808 { | |
2809 s->version = get_bits(&gb, 5); | |
2810 if (counter == 1) | |
2811 av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); | |
2812 } | |
2813 } | |
2814 if (s->version || s->theora) | |
2815 { | |
2816 if (get_bits1(&gb)) | |
2817 av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); | |
2818 skip_bits(&gb, 2); /* reserved? */ | |
2819 } | |
2820 | |
2794 if (s->last_frame.data[0] == s->golden_frame.data[0]) { | 2821 if (s->last_frame.data[0] == s->golden_frame.data[0]) { |
2795 if (s->golden_frame.data[0]) | 2822 if (s->golden_frame.data[0]) |
2796 avctx->release_buffer(avctx, &s->golden_frame); | 2823 avctx->release_buffer(avctx, &s->golden_frame); |
2797 s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ | 2824 s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ |
2798 } else { | 2825 } else { |
2977 static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb) | 3004 static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb) |
2978 { | 3005 { |
2979 int nb_comments, i, tmp; | 3006 int nb_comments, i, tmp; |
2980 | 3007 |
2981 tmp = get_bits(&gb, 32); | 3008 tmp = get_bits(&gb, 32); |
2982 while(tmp-=8) | 3009 tmp = be2me_32(tmp); |
2983 skip_bits(&gb, 8); | 3010 while(tmp--) |
3011 skip_bits(&gb, 8); | |
2984 | 3012 |
2985 nb_comments = get_bits(&gb, 32); | 3013 nb_comments = get_bits(&gb, 32); |
3014 nb_comments = be2me_32(nb_comments); | |
2986 for (i = 0; i < nb_comments; i++) | 3015 for (i = 0; i < nb_comments; i++) |
2987 { | 3016 { |
2988 tmp = get_bits(&gb, 32); | 3017 tmp = get_bits(&gb, 32); |
2989 while(tmp-=8) | 3018 tmp = be2me_32(tmp); |
3019 while(tmp--) | |
2990 skip_bits(&gb, 8); | 3020 skip_bits(&gb, 8); |
2991 } | 3021 } |
2992 | 3022 |
2993 return 0; | 3023 return 0; |
2994 } | 3024 } |
3015 s->coded_intra_c_dequant[i] = get_bits(&gb, 8); | 3045 s->coded_intra_c_dequant[i] = get_bits(&gb, 8); |
3016 | 3046 |
3017 /* inter coeffs */ | 3047 /* inter coeffs */ |
3018 for (i = 0; i < 64; i++) | 3048 for (i = 0; i < 64; i++) |
3019 s->coded_inter_dequant[i] = get_bits(&gb, 8); | 3049 s->coded_inter_dequant[i] = get_bits(&gb, 8); |
3050 | |
3051 /* FIXME: read huffmann tree.. */ | |
3020 | 3052 |
3021 s->theora_tables = 1; | 3053 s->theora_tables = 1; |
3022 | 3054 |
3023 return 0; | 3055 return 0; |
3024 } | 3056 } |