comparison vp3.c @ 2979:bfabfdf9ce55 libavcodec

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents ef2149182f1c
children 0b546eab515d
comparison
equal deleted inserted replaced
2978:403183bbb505 2979:bfabfdf9ce55
2215 int c_height; 2215 int c_height;
2216 int y_superblock_count; 2216 int y_superblock_count;
2217 int c_superblock_count; 2217 int c_superblock_count;
2218 2218
2219 if (avctx->codec_tag == MKTAG('V','P','3','0')) 2219 if (avctx->codec_tag == MKTAG('V','P','3','0'))
2220 s->version = 0; 2220 s->version = 0;
2221 else 2221 else
2222 s->version = 1; 2222 s->version = 1;
2223 2223
2224 s->avctx = avctx; 2224 s->avctx = avctx;
2225 s->width = (avctx->width + 15) & 0xFFFFFFF0; 2225 s->width = (avctx->width + 15) & 0xFFFFFFF0;
2226 s->height = (avctx->height + 15) & 0xFFFFFFF0; 2226 s->height = (avctx->height + 15) & 0xFFFFFFF0;
2227 avctx->pix_fmt = PIX_FMT_YUV420P; 2227 avctx->pix_fmt = PIX_FMT_YUV420P;
2286 s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); 2286 s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int));
2287 s->pixel_addresses_inited = 0; 2287 s->pixel_addresses_inited = 0;
2288 2288
2289 if (!s->theora_tables) 2289 if (!s->theora_tables)
2290 { 2290 {
2291 for (i = 0; i < 64; i++) 2291 for (i = 0; i < 64; i++)
2292 s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i]; 2292 s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i];
2293 for (i = 0; i < 64; i++) 2293 for (i = 0; i < 64; i++)
2294 s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i]; 2294 s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i];
2295 for (i = 0; i < 64; i++) 2295 for (i = 0; i < 64; i++)
2296 s->coded_intra_y_dequant[i] = vp31_intra_y_dequant[i]; 2296 s->coded_intra_y_dequant[i] = vp31_intra_y_dequant[i];
2297 for (i = 0; i < 64; i++) 2297 for (i = 0; i < 64; i++)
2298 s->coded_intra_c_dequant[i] = vp31_intra_c_dequant[i]; 2298 s->coded_intra_c_dequant[i] = vp31_intra_c_dequant[i];
2299 for (i = 0; i < 64; i++) 2299 for (i = 0; i < 64; i++)
2300 s->coded_inter_dequant[i] = vp31_inter_dequant[i]; 2300 s->coded_inter_dequant[i] = vp31_inter_dequant[i];
2301 for (i = 0; i < 64; i++) 2301 for (i = 0; i < 64; i++)
2302 s->filter_limit_values[i] = vp31_filter_limit_values[i]; 2302 s->filter_limit_values[i] = vp31_filter_limit_values[i];
2303 2303
2304 /* init VLC tables */ 2304 /* init VLC tables */
2305 for (i = 0; i < 16; i++) { 2305 for (i = 0; i < 16; i++) {
2306 2306
2307 /* DC histograms */ 2307 /* DC histograms */
2406 init_get_bits(&gb, buf, buf_size * 8); 2406 init_get_bits(&gb, buf, buf_size * 8);
2407 2407
2408 if (s->theora && get_bits1(&gb)) 2408 if (s->theora && get_bits1(&gb))
2409 { 2409 {
2410 #if 1 2410 #if 1
2411 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); 2411 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");
2412 return -1; 2412 return -1;
2413 #else 2413 #else
2414 int ptype = get_bits(&gb, 7); 2414 int ptype = get_bits(&gb, 7);
2415 2415
2416 skip_bits(&gb, 6*8); /* "theora" */ 2416 skip_bits(&gb, 6*8); /* "theora" */
2417 2417
2418 switch(ptype) 2418 switch(ptype)
2419 { 2419 {
2420 case 1: 2420 case 1:
2421 theora_decode_comments(avctx, gb); 2421 theora_decode_comments(avctx, gb);
2422 break; 2422 break;
2423 case 2: 2423 case 2:
2424 theora_decode_tables(avctx, gb); 2424 theora_decode_tables(avctx, gb);
2425 init_dequantizer(s); 2425 init_dequantizer(s);
2426 break; 2426 break;
2427 default: 2427 default:
2428 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); 2428 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype);
2429 } 2429 }
2430 return buf_size; 2430 return buf_size;
2431 #endif 2431 #endif
2432 } 2432 }
2433 2433
2434 s->keyframe = !get_bits1(&gb); 2434 s->keyframe = !get_bits1(&gb);
2435 if (!s->theora) 2435 if (!s->theora)
2436 skip_bits(&gb, 1); 2436 skip_bits(&gb, 1);
2437 s->last_quality_index = s->quality_index; 2437 s->last_quality_index = s->quality_index;
2438 s->quality_index = get_bits(&gb, 6); 2438 s->quality_index = get_bits(&gb, 6);
2439 if (s->theora >= 0x030200) 2439 if (s->theora >= 0x030200)
2440 skip_bits1(&gb); 2440 skip_bits1(&gb);
2441 2441
2442 if (s->avctx->debug & FF_DEBUG_PICT_INFO) 2442 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2443 av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", 2443 av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",
2444 s->keyframe?"key":"", counter, s->quality_index); 2444 s->keyframe?"key":"", counter, s->quality_index);
2445 counter++; 2445 counter++;
2446 2446
2447 if (s->quality_index != s->last_quality_index) { 2447 if (s->quality_index != s->last_quality_index) {
2448 init_dequantizer(s); 2448 init_dequantizer(s);
2449 init_loop_filter(s); 2449 init_loop_filter(s);
2450 } 2450 }
2451 2451
2452 if (s->keyframe) { 2452 if (s->keyframe) {
2453 if (!s->theora) 2453 if (!s->theora)
2454 { 2454 {
2455 skip_bits(&gb, 4); /* width code */ 2455 skip_bits(&gb, 4); /* width code */
2456 skip_bits(&gb, 4); /* height code */ 2456 skip_bits(&gb, 4); /* height code */
2457 if (s->version) 2457 if (s->version)
2458 { 2458 {
2459 s->version = get_bits(&gb, 5); 2459 s->version = get_bits(&gb, 5);
2460 if (counter == 1) 2460 if (counter == 1)
2461 av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); 2461 av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version);
2462 } 2462 }
2463 } 2463 }
2464 if (s->version || s->theora) 2464 if (s->version || s->theora)
2465 { 2465 {
2466 if (get_bits1(&gb)) 2466 if (get_bits1(&gb))
2467 av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); 2467 av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n");
2468 skip_bits(&gb, 2); /* reserved? */ 2468 skip_bits(&gb, 2); /* reserved? */
2469 } 2469 }
2470 2470
2471 if (s->last_frame.data[0] == s->golden_frame.data[0]) { 2471 if (s->last_frame.data[0] == s->golden_frame.data[0]) {
2472 if (s->golden_frame.data[0]) 2472 if (s->golden_frame.data[0])
2473 avctx->release_buffer(avctx, &s->golden_frame); 2473 avctx->release_buffer(avctx, &s->golden_frame);
2474 s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ 2474 s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */
2488 /* golden frame is also the current frame */ 2488 /* golden frame is also the current frame */
2489 memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame)); 2489 memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame));
2490 2490
2491 /* time to figure out pixel addresses? */ 2491 /* time to figure out pixel addresses? */
2492 if (!s->pixel_addresses_inited) 2492 if (!s->pixel_addresses_inited)
2493 { 2493 {
2494 if (!s->flipped_image) 2494 if (!s->flipped_image)
2495 vp3_calculate_pixel_addresses(s); 2495 vp3_calculate_pixel_addresses(s);
2496 else 2496 else
2497 theora_calculate_pixel_addresses(s); 2497 theora_calculate_pixel_addresses(s);
2498 } 2498 }
2499 } else { 2499 } else {
2500 /* allocate a new current frame */ 2500 /* allocate a new current frame */
2501 s->current_frame.reference = 3; 2501 s->current_frame.reference = 3;
2502 if(avctx->get_buffer(avctx, &s->current_frame) < 0) { 2502 if(avctx->get_buffer(avctx, &s->current_frame) < 0) {
2503 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); 2503 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n");
2653 2653
2654 major = get_bits(&gb, 8); /* version major */ 2654 major = get_bits(&gb, 8); /* version major */
2655 minor = get_bits(&gb, 8); /* version minor */ 2655 minor = get_bits(&gb, 8); /* version minor */
2656 micro = get_bits(&gb, 8); /* version micro */ 2656 micro = get_bits(&gb, 8); /* version micro */
2657 av_log(avctx, AV_LOG_INFO, "Theora bitstream version %d.%d.%d\n", 2657 av_log(avctx, AV_LOG_INFO, "Theora bitstream version %d.%d.%d\n",
2658 major, minor, micro); 2658 major, minor, micro);
2659 2659
2660 /* FIXME: endianess? */ 2660 /* FIXME: endianess? */
2661 s->theora = (major << 16) | (minor << 8) | micro; 2661 s->theora = (major << 16) | (minor << 8) | micro;
2662 2662
2663 /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */ 2663 /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */
2664 /* but previous versions have the image flipped relative to vp3 */ 2664 /* but previous versions have the image flipped relative to vp3 */
2665 if (s->theora < 0x030200) 2665 if (s->theora < 0x030200)
2666 { 2666 {
2667 s->flipped_image = 1; 2667 s->flipped_image = 1;
2668 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n"); 2668 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
2669 } 2669 }
2670 2670
2671 s->width = get_bits(&gb, 16) << 4; 2671 s->width = get_bits(&gb, 16) << 4;
2672 s->height = get_bits(&gb, 16) << 4; 2672 s->height = get_bits(&gb, 16) << 4;
2677 return -1; 2677 return -1;
2678 } 2678 }
2679 2679
2680 if (s->theora >= 0x030400) 2680 if (s->theora >= 0x030400)
2681 { 2681 {
2682 skip_bits(&gb, 32); /* total number of superblocks in a frame */ 2682 skip_bits(&gb, 32); /* total number of superblocks in a frame */
2683 // fixme, the next field is 36bits long 2683 // fixme, the next field is 36bits long
2684 skip_bits(&gb, 32); /* total number of blocks in a frame */ 2684 skip_bits(&gb, 32); /* total number of blocks in a frame */
2685 skip_bits(&gb, 4); /* total number of blocks in a frame */ 2685 skip_bits(&gb, 4); /* total number of blocks in a frame */
2686 skip_bits(&gb, 32); /* total number of macroblocks in a frame */ 2686 skip_bits(&gb, 32); /* total number of macroblocks in a frame */
2687 2687
2688 skip_bits(&gb, 24); /* frame width */ 2688 skip_bits(&gb, 24); /* frame width */
2689 skip_bits(&gb, 24); /* frame height */ 2689 skip_bits(&gb, 24); /* frame height */
2690 } 2690 }
2691 else 2691 else
2692 { 2692 {
2693 skip_bits(&gb, 24); /* frame width */ 2693 skip_bits(&gb, 24); /* frame width */
2694 skip_bits(&gb, 24); /* frame height */ 2694 skip_bits(&gb, 24); /* frame height */
2695 } 2695 }
2696 2696
2697 skip_bits(&gb, 8); /* offset x */ 2697 skip_bits(&gb, 8); /* offset x */
2698 skip_bits(&gb, 8); /* offset y */ 2698 skip_bits(&gb, 8); /* offset y */
2699 2699
2701 skip_bits(&gb, 32); /* fps denumerator */ 2701 skip_bits(&gb, 32); /* fps denumerator */
2702 skip_bits(&gb, 24); /* aspect numerator */ 2702 skip_bits(&gb, 24); /* aspect numerator */
2703 skip_bits(&gb, 24); /* aspect denumerator */ 2703 skip_bits(&gb, 24); /* aspect denumerator */
2704 2704
2705 if (s->theora < 0x030200) 2705 if (s->theora < 0x030200)
2706 skip_bits(&gb, 5); /* keyframe frequency force */ 2706 skip_bits(&gb, 5); /* keyframe frequency force */
2707 skip_bits(&gb, 8); /* colorspace */ 2707 skip_bits(&gb, 8); /* colorspace */
2708 if (s->theora >= 0x030400) 2708 if (s->theora >= 0x030400)
2709 skip_bits(&gb, 2); /* pixel format: 420,res,422,444 */ 2709 skip_bits(&gb, 2); /* pixel format: 420,res,422,444 */
2710 skip_bits(&gb, 24); /* bitrate */ 2710 skip_bits(&gb, 24); /* bitrate */
2711 2711
2712 skip_bits(&gb, 6); /* quality hint */ 2712 skip_bits(&gb, 6); /* quality hint */
2713 2713
2714 if (s->theora >= 0x030200) 2714 if (s->theora >= 0x030200)
2715 { 2715 {
2716 skip_bits(&gb, 5); /* keyframe frequency force */ 2716 skip_bits(&gb, 5); /* keyframe frequency force */
2717 2717
2718 if (s->theora < 0x030400) 2718 if (s->theora < 0x030400)
2719 skip_bits(&gb, 5); /* spare bits */ 2719 skip_bits(&gb, 5); /* spare bits */
2720 } 2720 }
2721 2721
2722 // align_get_bits(&gb); 2722 // align_get_bits(&gb);
2723 2723
2724 avctx->width = s->width; 2724 avctx->width = s->width;
2742 Vp3DecodeContext *s = avctx->priv_data; 2742 Vp3DecodeContext *s = avctx->priv_data;
2743 int len; 2743 int len;
2744 2744
2745 if (s->theora <= 0x030200) 2745 if (s->theora <= 0x030200)
2746 { 2746 {
2747 int i, comments; 2747 int i, comments;
2748 2748
2749 // vendor string 2749 // vendor string
2750 len = get_bits_long(&gb, 32); 2750 len = get_bits_long(&gb, 32);
2751 len = le2me_32(len); 2751 len = le2me_32(len);
2752 while(len--) 2752 while(len--)
2753 skip_bits(&gb, 8); 2753 skip_bits(&gb, 8);
2754 2754
2755 // user comments 2755 // user comments
2756 comments = get_bits_long(&gb, 32); 2756 comments = get_bits_long(&gb, 32);
2757 comments = le2me_32(comments); 2757 comments = le2me_32(comments);
2758 for (i = 0; i < comments; i++) 2758 for (i = 0; i < comments; i++)
2759 { 2759 {
2760 len = get_bits_long(&gb, 32); 2760 len = get_bits_long(&gb, 32);
2761 len = be2me_32(len); 2761 len = be2me_32(len);
2762 while(len--) 2762 while(len--)
2763 skip_bits(&gb, 8); 2763 skip_bits(&gb, 8);
2764 } 2764 }
2765 } 2765 }
2766 else 2766 else
2767 { 2767 {
2768 do { 2768 do {
2769 len = get_bits_long(&gb, 32); 2769 len = get_bits_long(&gb, 32);
2770 len = le2me_32(len); 2770 len = le2me_32(len);
2771 if (len <= 0) 2771 if (len <= 0)
2772 break; 2772 break;
2773 while (len--) 2773 while (len--)
2774 skip_bits(&gb, 8); 2774 skip_bits(&gb, 8);
2775 } while (1); 2775 } while (1);
2776 } 2776 }
2777 return 0; 2777 return 0;
2778 } 2778 }
2779 2779
2780 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb) 2780 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb)
2793 n = get_bits(&gb, 4) + 1; 2793 n = get_bits(&gb, 4) + 1;
2794 else 2794 else
2795 n = 16; 2795 n = 16;
2796 /* quality threshold table */ 2796 /* quality threshold table */
2797 for (i = 0; i < 64; i++) 2797 for (i = 0; i < 64; i++)
2798 s->coded_ac_scale_factor[i] = get_bits(&gb, n); 2798 s->coded_ac_scale_factor[i] = get_bits(&gb, n);
2799 2799
2800 if (s->theora >= 0x030200) 2800 if (s->theora >= 0x030200)
2801 n = get_bits(&gb, 4) + 1; 2801 n = get_bits(&gb, 4) + 1;
2802 else 2802 else
2803 n = 16; 2803 n = 16;
2804 /* dc scale factor table */ 2804 /* dc scale factor table */
2805 for (i = 0; i < 64; i++) 2805 for (i = 0; i < 64; i++)
2806 s->coded_dc_scale_factor[i] = get_bits(&gb, n); 2806 s->coded_dc_scale_factor[i] = get_bits(&gb, n);
2807 2807
2808 if (s->theora >= 0x030200) 2808 if (s->theora >= 0x030200)
2809 matrices = get_bits(&gb, 9) + 1; 2809 matrices = get_bits(&gb, 9) + 1;
2810 else 2810 else
2811 matrices = 3; 2811 matrices = 3;
2813 av_log(avctx,AV_LOG_ERROR, "unsupported matrices: %d\n", matrices); 2813 av_log(avctx,AV_LOG_ERROR, "unsupported matrices: %d\n", matrices);
2814 // return -1; 2814 // return -1;
2815 } 2815 }
2816 /* y coeffs */ 2816 /* y coeffs */
2817 for (i = 0; i < 64; i++) 2817 for (i = 0; i < 64; i++)
2818 s->coded_intra_y_dequant[i] = get_bits(&gb, 8); 2818 s->coded_intra_y_dequant[i] = get_bits(&gb, 8);
2819 2819
2820 /* uv coeffs */ 2820 /* uv coeffs */
2821 for (i = 0; i < 64; i++) 2821 for (i = 0; i < 64; i++)
2822 s->coded_intra_c_dequant[i] = get_bits(&gb, 8); 2822 s->coded_intra_c_dequant[i] = get_bits(&gb, 8);
2823 2823
2824 /* inter coeffs */ 2824 /* inter coeffs */
2825 for (i = 0; i < 64; i++) 2825 for (i = 0; i < 64; i++)
2826 s->coded_inter_dequant[i] = get_bits(&gb, 8); 2826 s->coded_inter_dequant[i] = get_bits(&gb, 8);
2827 2827
2828 /* skip unknown matrices */ 2828 /* skip unknown matrices */
2829 n = matrices - 3; 2829 n = matrices - 3;
2830 while(n--) 2830 while(n--)
2831 for (i = 0; i < 64; i++) 2831 for (i = 0; i < 64; i++)
2832 skip_bits(&gb, 8); 2832 skip_bits(&gb, 8);
2833 2833
2834 for (i = 0; i <= 1; i++) { 2834 for (i = 0; i <= 1; i++) {
2835 for (n = 0; n <= 2; n++) { 2835 for (n = 0; n <= 2; n++) {
2836 int newqr; 2836 int newqr;
2837 if (i > 0 || n > 0) 2837 if (i > 0 || n > 0)
2849 qi += get_bits(&gb, av_log2(63-qi)+1) + 1; 2849 qi += get_bits(&gb, av_log2(63-qi)+1) + 1;
2850 skip_bits(&gb, av_log2(matrices-1)+1); 2850 skip_bits(&gb, av_log2(matrices-1)+1);
2851 } 2851 }
2852 if (qi > 63) { 2852 if (qi > 63) {
2853 av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi); 2853 av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi);
2854 return -1; 2854 return -1;
2855 } 2855 }
2856 } 2856 }
2857 } 2857 }
2858 } 2858 }
2859 2859
2860 /* Huffman tables */ 2860 /* Huffman tables */
2885 s->theora = 1; 2885 s->theora = 1;
2886 2886
2887 if (!avctx->extradata_size) 2887 if (!avctx->extradata_size)
2888 { 2888 {
2889 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n"); 2889 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n");
2890 return -1; 2890 return -1;
2891 } 2891 }
2892 2892
2893 for(i=0;i<3;i++) { 2893 for(i=0;i<3;i++) {
2894 op_bytes = *(p++)<<8; 2894 op_bytes = *(p++)<<8;
2895 op_bytes += *(p++); 2895 op_bytes += *(p++);
2901 debug_vp3("Theora headerpacket type: %x\n", ptype); 2901 debug_vp3("Theora headerpacket type: %x\n", ptype);
2902 2902
2903 if (!(ptype & 0x80)) 2903 if (!(ptype & 0x80))
2904 { 2904 {
2905 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n"); 2905 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
2906 return -1; 2906 return -1;
2907 } 2907 }
2908 2908
2909 // FIXME: check for this aswell 2909 // FIXME: check for this aswell
2910 skip_bits(&gb, 6*8); /* "theora" */ 2910 skip_bits(&gb, 6*8); /* "theora" */
2911 2911
2912 switch(ptype) 2912 switch(ptype)
2913 { 2913 {
2914 case 0x80: 2914 case 0x80:
2915 theora_decode_header(avctx, gb); 2915 theora_decode_header(avctx, gb);
2916 break; 2916 break;
2917 case 0x81: 2917 case 0x81:
2918 // FIXME: is this needed? it breaks sometimes 2918 // FIXME: is this needed? it breaks sometimes
2919 // theora_decode_comments(avctx, gb); 2919 // theora_decode_comments(avctx, gb);
2920 break; 2920 break;
2921 case 0x82: 2921 case 0x82:
2922 theora_decode_tables(avctx, gb); 2922 theora_decode_tables(avctx, gb);
2923 break; 2923 break;
2924 default: 2924 default:
2925 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80); 2925 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80);
2926 break; 2926 break;
2927 } 2927 }
2928 } 2928 }
2929 2929
2930 vp3_decode_init(avctx); 2930 vp3_decode_init(avctx);
2931 return 0; 2931 return 0;