Mercurial > libavcodec.hg
comparison vp3.c @ 1626:f74ae637ffa9 libavcodec
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
author | alex |
---|---|
date | Sun, 23 Nov 2003 18:43:09 +0000 |
parents | 932d306bf1dc |
children | a80b15c0b9d5 |
comparison
equal
deleted
inserted
replaced
1625:c910ff78ef80 | 1626:f74ae637ffa9 |
---|---|
220 AVFrame golden_frame; | 220 AVFrame golden_frame; |
221 AVFrame last_frame; | 221 AVFrame last_frame; |
222 AVFrame current_frame; | 222 AVFrame current_frame; |
223 int keyframe; | 223 int keyframe; |
224 DSPContext dsp; | 224 DSPContext dsp; |
225 int flipped_image; | |
225 | 226 |
226 int quality_index; | 227 int quality_index; |
227 int last_quality_index; | 228 int last_quality_index; |
228 | 229 |
229 int superblock_count; | 230 int superblock_count; |
2363 if (plane == 0) { | 2364 if (plane == 0) { |
2364 dequantizer = s->intra_y_dequant; | 2365 dequantizer = s->intra_y_dequant; |
2365 output_plane = s->current_frame.data[0]; | 2366 output_plane = s->current_frame.data[0]; |
2366 last_plane = s->last_frame.data[0]; | 2367 last_plane = s->last_frame.data[0]; |
2367 golden_plane = s->golden_frame.data[0]; | 2368 golden_plane = s->golden_frame.data[0]; |
2368 stride = -s->current_frame.linesize[0]; | 2369 stride = s->current_frame.linesize[0]; |
2370 if (!s->flipped_image) stride = -stride; | |
2369 upper_motion_limit = 7 * s->current_frame.linesize[0]; | 2371 upper_motion_limit = 7 * s->current_frame.linesize[0]; |
2370 lower_motion_limit = height * s->current_frame.linesize[0] + width - 8; | 2372 lower_motion_limit = height * s->current_frame.linesize[0] + width - 8; |
2371 } else if (plane == 1) { | 2373 } else if (plane == 1) { |
2372 dequantizer = s->intra_c_dequant; | 2374 dequantizer = s->intra_c_dequant; |
2373 output_plane = s->current_frame.data[1]; | 2375 output_plane = s->current_frame.data[1]; |
2374 last_plane = s->last_frame.data[1]; | 2376 last_plane = s->last_frame.data[1]; |
2375 golden_plane = s->golden_frame.data[1]; | 2377 golden_plane = s->golden_frame.data[1]; |
2376 stride = -s->current_frame.linesize[1]; | 2378 stride = s->current_frame.linesize[1]; |
2379 if (!s->flipped_image) stride = -stride; | |
2377 upper_motion_limit = 7 * s->current_frame.linesize[1]; | 2380 upper_motion_limit = 7 * s->current_frame.linesize[1]; |
2378 lower_motion_limit = height * s->current_frame.linesize[1] + width - 8; | 2381 lower_motion_limit = height * s->current_frame.linesize[1] + width - 8; |
2379 } else { | 2382 } else { |
2380 dequantizer = s->intra_c_dequant; | 2383 dequantizer = s->intra_c_dequant; |
2381 output_plane = s->current_frame.data[2]; | 2384 output_plane = s->current_frame.data[2]; |
2382 last_plane = s->last_frame.data[2]; | 2385 last_plane = s->last_frame.data[2]; |
2383 golden_plane = s->golden_frame.data[2]; | 2386 golden_plane = s->golden_frame.data[2]; |
2384 stride = -s->current_frame.linesize[2]; | 2387 stride = s->current_frame.linesize[2]; |
2388 if (!s->flipped_image) stride = -stride; | |
2385 upper_motion_limit = 7 * s->current_frame.linesize[2]; | 2389 upper_motion_limit = 7 * s->current_frame.linesize[2]; |
2386 lower_motion_limit = height * s->current_frame.linesize[2] + width - 8; | 2390 lower_motion_limit = height * s->current_frame.linesize[2] + width - 8; |
2387 } | 2391 } |
2388 | 2392 |
2389 /* for each fragment row... */ | 2393 /* for each fragment row... */ |
2434 motion_source += ((motion_y >> 1) * stride); | 2438 motion_source += ((motion_y >> 1) * stride); |
2435 | 2439 |
2436 if(src_x<0 || src_y<0 || src_x + 9 >= width || src_y + 9 >= height){ | 2440 if(src_x<0 || src_y<0 || src_x + 9 >= width || src_y + 9 >= height){ |
2437 uint8_t *temp= s->edge_emu_buffer; | 2441 uint8_t *temp= s->edge_emu_buffer; |
2438 if(stride<0) temp -= 9*stride; | 2442 if(stride<0) temp -= 9*stride; |
2443 else temp += 9*stride; | |
2439 | 2444 |
2440 ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, width, height); | 2445 ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, width, height); |
2441 motion_source= temp; | 2446 motion_source= temp; |
2442 } | 2447 } |
2443 } | 2448 } |
2534 } | 2539 } |
2535 | 2540 |
2536 /* V plane */ | 2541 /* V plane */ |
2537 i = s->v_fragment_start; | 2542 i = s->v_fragment_start; |
2538 for (y = s->fragment_height / 2; y > 0; y--) { | 2543 for (y = s->fragment_height / 2; y > 0; y--) { |
2544 for (x = 0; x < s->fragment_width / 2; x++) { | |
2545 s->all_fragments[i++].first_pixel = | |
2546 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - | |
2547 s->golden_frame.linesize[2] + | |
2548 x * FRAGMENT_PIXELS; | |
2549 debug_init(" fragment %d, first pixel @ %d\n", | |
2550 i-1, s->all_fragments[i-1].first_pixel); | |
2551 } | |
2552 } | |
2553 } | |
2554 | |
2555 /* FIXME: this should be merged with the above! */ | |
2556 static void theora_calculate_pixel_addresses(Vp3DecodeContext *s) | |
2557 { | |
2558 | |
2559 int i, x, y; | |
2560 | |
2561 /* figure out the first pixel addresses for each of the fragments */ | |
2562 /* Y plane */ | |
2563 i = 0; | |
2564 for (y = 1; y <= s->fragment_height; y++) { | |
2565 for (x = 0; x < s->fragment_width; x++) { | |
2566 s->all_fragments[i++].first_pixel = | |
2567 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - | |
2568 s->golden_frame.linesize[0] + | |
2569 x * FRAGMENT_PIXELS; | |
2570 debug_init(" fragment %d, first pixel @ %d\n", | |
2571 i-1, s->all_fragments[i-1].first_pixel); | |
2572 } | |
2573 } | |
2574 | |
2575 /* U plane */ | |
2576 i = s->u_fragment_start; | |
2577 for (y = 1; y <= s->fragment_height / 2; y++) { | |
2578 for (x = 0; x < s->fragment_width / 2; x++) { | |
2579 s->all_fragments[i++].first_pixel = | |
2580 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - | |
2581 s->golden_frame.linesize[1] + | |
2582 x * FRAGMENT_PIXELS; | |
2583 debug_init(" fragment %d, first pixel @ %d\n", | |
2584 i-1, s->all_fragments[i-1].first_pixel); | |
2585 } | |
2586 } | |
2587 | |
2588 /* V plane */ | |
2589 i = s->v_fragment_start; | |
2590 for (y = 1; y <= s->fragment_height / 2; y++) { | |
2539 for (x = 0; x < s->fragment_width / 2; x++) { | 2591 for (x = 0; x < s->fragment_width / 2; x++) { |
2540 s->all_fragments[i++].first_pixel = | 2592 s->all_fragments[i++].first_pixel = |
2541 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - | 2593 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - |
2542 s->golden_frame.linesize[2] + | 2594 s->golden_frame.linesize[2] + |
2543 x * FRAGMENT_PIXELS; | 2595 x * FRAGMENT_PIXELS; |
2707 av_log(s->avctx, AV_LOG_ERROR, "Theora: bad frame indicator\n"); | 2759 av_log(s->avctx, AV_LOG_ERROR, "Theora: bad frame indicator\n"); |
2708 return -1; | 2760 return -1; |
2709 } | 2761 } |
2710 | 2762 |
2711 s->keyframe = !get_bits1(&gb); | 2763 s->keyframe = !get_bits1(&gb); |
2712 if (s->theora && s->keyframe) | 2764 if (s->theora) |
2713 { | 2765 { |
2714 if (get_bits1(&gb)) | 2766 s->last_quality_index = s->quality_index; |
2715 av_log(s->avctx, AV_LOG_ERROR, "Theora: warning, unsupported keyframe coding type?!\n"); | 2767 s->quality_index = get_bits(&gb, 6); |
2716 skip_bits(&gb, 2); /* reserved? */ | 2768 if ( s->keyframe) |
2769 { | |
2770 if (get_bits1(&gb)) | |
2771 av_log(s->avctx, AV_LOG_ERROR, "Theora: warning, unsupported keyframe coding type?!\n"); | |
2772 skip_bits(&gb, 2); /* reserved? */ | |
2773 } | |
2717 } | 2774 } |
2718 else | 2775 else |
2776 { | |
2719 skip_bits(&gb, 1); | 2777 skip_bits(&gb, 1); |
2720 s->last_quality_index = s->quality_index; | 2778 s->last_quality_index = s->quality_index; |
2721 s->quality_index = get_bits(&gb, 6); | 2779 s->quality_index = get_bits(&gb, 6); |
2780 } | |
2722 | 2781 |
2723 debug_vp3(" VP3 %sframe #%d: Q index = %d\n", | 2782 debug_vp3(" VP3 %sframe #%d: Q index = %d\n", |
2724 s->keyframe?"key":"", counter, s->quality_index); | 2783 s->keyframe?"key":"", counter, s->quality_index); |
2725 counter++; | 2784 counter++; |
2726 | 2785 |
2750 /* golden frame is also the current frame */ | 2809 /* golden frame is also the current frame */ |
2751 memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame)); | 2810 memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame)); |
2752 | 2811 |
2753 /* time to figure out pixel addresses? */ | 2812 /* time to figure out pixel addresses? */ |
2754 if (!s->pixel_addresses_inited) | 2813 if (!s->pixel_addresses_inited) |
2755 vp3_calculate_pixel_addresses(s); | 2814 { |
2756 | 2815 if (!s->flipped_image) |
2816 vp3_calculate_pixel_addresses(s); | |
2817 else | |
2818 theora_calculate_pixel_addresses(s); | |
2819 } | |
2757 } else { | 2820 } else { |
2758 /* allocate a new current frame */ | 2821 /* allocate a new current frame */ |
2759 s->current_frame.reference = 3; | 2822 s->current_frame.reference = 3; |
2760 if(avctx->get_buffer(avctx, &s->current_frame) < 0) { | 2823 if(avctx->get_buffer(avctx, &s->current_frame) < 0) { |
2761 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); | 2824 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); |
2848 * to the same frame as either the golden or last frame */ | 2911 * to the same frame as either the golden or last frame */ |
2849 | 2912 |
2850 return 0; | 2913 return 0; |
2851 } | 2914 } |
2852 | 2915 |
2853 /* current version is 3.2.0 */ | |
2854 | |
2855 static int theora_decode_header(AVCodecContext *avctx, GetBitContext gb) | 2916 static int theora_decode_header(AVCodecContext *avctx, GetBitContext gb) |
2856 { | 2917 { |
2857 Vp3DecodeContext *s = avctx->priv_data; | 2918 Vp3DecodeContext *s = avctx->priv_data; |
2858 | 2919 int major, minor, micro; |
2859 skip_bits(&gb, 8); /* version major */ | 2920 |
2860 skip_bits(&gb, 8); /* version minor */ | 2921 major = get_bits(&gb, 8); /* version major */ |
2861 skip_bits(&gb, 8); /* version micro */ | 2922 minor = get_bits(&gb, 8); /* version minor */ |
2862 | 2923 micro = get_bits(&gb, 8); /* version micro */ |
2924 av_log(avctx, AV_LOG_INFO, "Theora bitstream version %d.%d.%d\n", | |
2925 major, minor, micro); | |
2926 | |
2927 /* 3.3.0 aka alpha3 has the same frame orientation as original vp3 */ | |
2928 /* but previous versions have the image flipped relative to vp3 */ | |
2929 if ((major <= 3) && (minor < 3)) | |
2930 { | |
2931 s->flipped_image = 1; | |
2932 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n"); | |
2933 } | |
2934 | |
2863 s->width = get_bits(&gb, 16) << 4; | 2935 s->width = get_bits(&gb, 16) << 4; |
2864 s->height = get_bits(&gb, 16) << 4; | 2936 s->height = get_bits(&gb, 16) << 4; |
2865 | 2937 |
2866 skip_bits(&gb, 24); /* frame width */ | 2938 skip_bits(&gb, 24); /* frame width */ |
2867 skip_bits(&gb, 24); /* frame height */ | 2939 skip_bits(&gb, 24); /* frame height */ |