Revision e278056f

View differences:

libavcodec/vp3.c
328 328
    int bounding_values_array[256];
329 329
} Vp3DecodeContext;
330 330

  
331
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb);
331
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb);
332 332

  
333 333
/************************************************************************
334 334
 * VP3 specific functions
......
2417 2417
        switch(ptype)
2418 2418
        {
2419 2419
            case 1:
2420
                theora_decode_comments(avctx, gb);
2420
                theora_decode_comments(avctx, &gb);
2421 2421
                break;
2422 2422
            case 2:
2423
                theora_decode_tables(avctx, gb);
2423
                theora_decode_tables(avctx, &gb);
2424 2424
                    init_dequantizer(s);
2425 2425
                break;
2426 2426
            default:
......
2645 2645
    return 0;
2646 2646
}
2647 2647

  
2648
static int theora_decode_header(AVCodecContext *avctx, GetBitContext gb)
2648
static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
2649 2649
{
2650 2650
    Vp3DecodeContext *s = avctx->priv_data;
2651 2651

  
2652
    s->theora = get_bits_long(&gb, 24);
2652
    s->theora = get_bits_long(gb, 24);
2653 2653
    av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora);
2654 2654

  
2655 2655
    /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */
......
2660 2660
        av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
2661 2661
    }
2662 2662

  
2663
    s->width = get_bits(&gb, 16) << 4;
2664
    s->height = get_bits(&gb, 16) << 4;
2663
    s->width = get_bits(gb, 16) << 4;
2664
    s->height = get_bits(gb, 16) << 4;
2665 2665

  
2666 2666
    if(avcodec_check_dimensions(avctx, s->width, s->height)){
2667 2667
        av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height);
......
2671 2671

  
2672 2672
    if (s->theora >= 0x030400)
2673 2673
    {
2674
        skip_bits(&gb, 32); /* total number of superblocks in a frame */
2674
        skip_bits(gb, 32); /* total number of superblocks in a frame */
2675 2675
        // fixme, the next field is 36bits long
2676
        skip_bits(&gb, 32); /* total number of blocks in a frame */
2677
        skip_bits(&gb, 4); /* total number of blocks in a frame */
2678
        skip_bits(&gb, 32); /* total number of macroblocks in a frame */
2676
        skip_bits(gb, 32); /* total number of blocks in a frame */
2677
        skip_bits(gb, 4); /* total number of blocks in a frame */
2678
        skip_bits(gb, 32); /* total number of macroblocks in a frame */
2679 2679

  
2680
        skip_bits(&gb, 24); /* frame width */
2681
        skip_bits(&gb, 24); /* frame height */
2680
        skip_bits(gb, 24); /* frame width */
2681
        skip_bits(gb, 24); /* frame height */
2682 2682
    }
2683 2683
    else
2684 2684
    {
2685
        skip_bits(&gb, 24); /* frame width */
2686
        skip_bits(&gb, 24); /* frame height */
2685
        skip_bits(gb, 24); /* frame width */
2686
        skip_bits(gb, 24); /* frame height */
2687 2687
    }
2688 2688

  
2689
    skip_bits(&gb, 8); /* offset x */
2690
    skip_bits(&gb, 8); /* offset y */
2689
    skip_bits(gb, 8); /* offset x */
2690
    skip_bits(gb, 8); /* offset y */
2691 2691

  
2692
    skip_bits(&gb, 32); /* fps numerator */
2693
    skip_bits(&gb, 32); /* fps denumerator */
2694
    skip_bits(&gb, 24); /* aspect numerator */
2695
    skip_bits(&gb, 24); /* aspect denumerator */
2692
    skip_bits(gb, 32); /* fps numerator */
2693
    skip_bits(gb, 32); /* fps denumerator */
2694
    skip_bits(gb, 24); /* aspect numerator */
2695
    skip_bits(gb, 24); /* aspect denumerator */
2696 2696

  
2697 2697
    if (s->theora < 0x030200)
2698
        skip_bits(&gb, 5); /* keyframe frequency force */
2699
    skip_bits(&gb, 8); /* colorspace */
2698
        skip_bits(gb, 5); /* keyframe frequency force */
2699
    skip_bits(gb, 8); /* colorspace */
2700 2700
    if (s->theora >= 0x030400)
2701
        skip_bits(&gb, 2); /* pixel format: 420,res,422,444 */
2702
    skip_bits(&gb, 24); /* bitrate */
2701
        skip_bits(gb, 2); /* pixel format: 420,res,422,444 */
2702
    skip_bits(gb, 24); /* bitrate */
2703 2703

  
2704
    skip_bits(&gb, 6); /* quality hint */
2704
    skip_bits(gb, 6); /* quality hint */
2705 2705

  
2706 2706
    if (s->theora >= 0x030200)
2707 2707
    {
2708
        skip_bits(&gb, 5); /* keyframe frequency force */
2708
        skip_bits(gb, 5); /* keyframe frequency force */
2709 2709

  
2710 2710
        if (s->theora < 0x030400)
2711
            skip_bits(&gb, 5); /* spare bits */
2711
            skip_bits(gb, 5); /* spare bits */
2712 2712
    }
2713 2713

  
2714
//    align_get_bits(&gb);
2714
//    align_get_bits(gb);
2715 2715

  
2716 2716
    avctx->width = s->width;
2717 2717
    avctx->height = s->height;
......
2719 2719
    return 0;
2720 2720
}
2721 2721

  
2722
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb)
2722
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
2723 2723
{
2724 2724
    Vp3DecodeContext *s = avctx->priv_data;
2725 2725
    int i, n, matrices;
2726 2726

  
2727 2727
    if (s->theora >= 0x030200) {
2728
        n = get_bits(&gb, 3);
2728
        n = get_bits(gb, 3);
2729 2729
        /* loop filter limit values table */
2730 2730
        for (i = 0; i < 64; i++)
2731
            s->filter_limit_values[i] = get_bits(&gb, n);
2731
            s->filter_limit_values[i] = get_bits(gb, n);
2732 2732
    }
2733 2733

  
2734 2734
    if (s->theora >= 0x030200)
2735
        n = get_bits(&gb, 4) + 1;
2735
        n = get_bits(gb, 4) + 1;
2736 2736
    else
2737 2737
        n = 16;
2738 2738
    /* quality threshold table */
2739 2739
    for (i = 0; i < 64; i++)
2740
        s->coded_ac_scale_factor[i] = get_bits(&gb, n);
2740
        s->coded_ac_scale_factor[i] = get_bits(gb, n);
2741 2741

  
2742 2742
    if (s->theora >= 0x030200)
2743
        n = get_bits(&gb, 4) + 1;
2743
        n = get_bits(gb, 4) + 1;
2744 2744
    else
2745 2745
        n = 16;
2746 2746
    /* dc scale factor table */
2747 2747
    for (i = 0; i < 64; i++)
2748
        s->coded_dc_scale_factor[i] = get_bits(&gb, n);
2748
        s->coded_dc_scale_factor[i] = get_bits(gb, n);
2749 2749

  
2750 2750
    if (s->theora >= 0x030200)
2751
        matrices = get_bits(&gb, 9) + 1;
2751
        matrices = get_bits(gb, 9) + 1;
2752 2752
    else
2753 2753
        matrices = 3;
2754 2754
    if (matrices != 3) {
......
2757 2757
    }
2758 2758
    /* y coeffs */
2759 2759
    for (i = 0; i < 64; i++)
2760
        s->coded_intra_y_dequant[i] = get_bits(&gb, 8);
2760
        s->coded_intra_y_dequant[i] = get_bits(gb, 8);
2761 2761

  
2762 2762
    /* uv coeffs */
2763 2763
    for (i = 0; i < 64; i++)
2764
        s->coded_intra_c_dequant[i] = get_bits(&gb, 8);
2764
        s->coded_intra_c_dequant[i] = get_bits(gb, 8);
2765 2765

  
2766 2766
    /* inter coeffs */
2767 2767
    for (i = 0; i < 64; i++)
2768
        s->coded_inter_dequant[i] = get_bits(&gb, 8);
2768
        s->coded_inter_dequant[i] = get_bits(gb, 8);
2769 2769

  
2770 2770
    /* skip unknown matrices */
2771 2771
    n = matrices - 3;
2772 2772
    while(n--)
2773 2773
        for (i = 0; i < 64; i++)
2774
            skip_bits(&gb, 8);
2774
            skip_bits(gb, 8);
2775 2775

  
2776 2776
    for (i = 0; i <= 1; i++) {
2777 2777
        for (n = 0; n <= 2; n++) {
2778 2778
            int newqr;
2779 2779
            if (i > 0 || n > 0)
2780
                newqr = get_bits(&gb, 1);
2780
                newqr = get_bits(gb, 1);
2781 2781
            else
2782 2782
                newqr = 1;
2783 2783
            if (!newqr) {
2784 2784
                if (i > 0)
2785
                    get_bits(&gb, 1);
2785
                    get_bits(gb, 1);
2786 2786
            }
2787 2787
            else {
2788 2788
                int qi = 0;
2789
                skip_bits(&gb, av_log2(matrices-1)+1);
2789
                skip_bits(gb, av_log2(matrices-1)+1);
2790 2790
                while (qi < 63) {
2791
                    qi += get_bits(&gb, av_log2(63-qi)+1) + 1;
2792
                    skip_bits(&gb, av_log2(matrices-1)+1);
2791
                    qi += get_bits(gb, av_log2(63-qi)+1) + 1;
2792
                    skip_bits(gb, av_log2(matrices-1)+1);
2793 2793
                }
2794 2794
                if (qi > 63) {
2795 2795
                    av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi);
......
2803 2803
    for (s->hti = 0; s->hti < 80; s->hti++) {
2804 2804
        s->entries = 0;
2805 2805
        s->huff_code_size = 1;
2806
        if (!get_bits(&gb, 1)) {
2806
        if (!get_bits(gb, 1)) {
2807 2807
            s->hbits = 0;
2808
            read_huffman_tree(avctx, &gb);
2808
            read_huffman_tree(avctx, gb);
2809 2809
            s->hbits = 1;
2810
            read_huffman_tree(avctx, &gb);
2810
            read_huffman_tree(avctx, gb);
2811 2811
        }
2812 2812
    }
2813 2813

  
......
2845 2845
     if (!(ptype & 0x80))
2846 2846
     {
2847 2847
        av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
2848
        return -1;
2848
//        return -1;
2849 2849
     }
2850 2850

  
2851 2851
    // FIXME: check for this aswell
......
2854 2854
    switch(ptype)
2855 2855
    {
2856 2856
        case 0x80:
2857
            theora_decode_header(avctx, gb);
2857
            theora_decode_header(avctx, &gb);
2858 2858
                break;
2859 2859
        case 0x81:
2860 2860
// FIXME: is this needed? it breaks sometimes
2861 2861
//            theora_decode_comments(avctx, gb);
2862 2862
            break;
2863 2863
        case 0x82:
2864
            theora_decode_tables(avctx, gb);
2864
            theora_decode_tables(avctx, &gb);
2865 2865
            break;
2866 2866
        default:
2867 2867
            av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80);
2868 2868
            break;
2869 2869
    }
2870
    if(8*op_bytes != get_bits_count(&gb))
2871
        av_log(avctx, AV_LOG_ERROR, "%d bits left in packet %X\n", 8*op_bytes - get_bits_count(&gb), ptype);
2870 2872
  }
2871 2873

  
2872 2874
    vp3_decode_init(avctx);

Also available in: Unified diff