Compare commits
	
		
			12 Commits
		
	
	
		
			sandbox/ji
			...
			sandbox/ho
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					3cf0ef4593 | ||
| 
						 | 
					0909b83427 | ||
| 
						 | 
					62da6700dc | ||
| 
						 | 
					98ea0d71a4 | ||
| 
						 | 
					8d49ea12c2 | ||
| 
						 | 
					766ad7edb6 | ||
| 
						 | 
					20431c1354 | ||
| 
						 | 
					1b913c1f78 | ||
| 
						 | 
					a64b37fdbc | ||
| 
						 | 
					a2951d8deb | ||
| 
						 | 
					83a2b4e114 | ||
| 
						 | 
					1422ce5cff | 
							
								
								
									
										3
									
								
								configure
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								configure
									
									
									
									
										vendored
									
									
								
							@@ -37,6 +37,7 @@ Advanced options:
 | 
			
		||||
  ${toggle_multithread}           multithreaded encoding and decoding.
 | 
			
		||||
  ${toggle_spatial_resampling}    spatial sampling (scaling) support
 | 
			
		||||
  ${toggle_realtime_only}         enable this option while building for real-time encoding
 | 
			
		||||
  ${toggle_error_concealment}     enable this option to get a decoder which is able to conceal losses
 | 
			
		||||
  ${toggle_runtime_cpu_detect}    runtime cpu detection
 | 
			
		||||
  ${toggle_shared}                shared library support
 | 
			
		||||
  ${toggle_small}                 favor smaller size over speed
 | 
			
		||||
@@ -249,6 +250,7 @@ CONFIG_LIST="
 | 
			
		||||
    static_msvcrt
 | 
			
		||||
    spatial_resampling
 | 
			
		||||
    realtime_only
 | 
			
		||||
    error_concealment
 | 
			
		||||
    shared
 | 
			
		||||
    small
 | 
			
		||||
    arm_asm_detok
 | 
			
		||||
@@ -289,6 +291,7 @@ CMDLINE_SELECT="
 | 
			
		||||
    mem_tracker
 | 
			
		||||
    spatial_resampling
 | 
			
		||||
    realtime_only
 | 
			
		||||
    error_concealment
 | 
			
		||||
    shared
 | 
			
		||||
    small
 | 
			
		||||
    arm_asm_detok
 | 
			
		||||
 
 | 
			
		||||
@@ -77,6 +77,11 @@ GEN_EXAMPLES-$(CONFIG_ENCODERS) += decode_with_drops.c
 | 
			
		||||
endif
 | 
			
		||||
decode_with_drops.GUID           = CE5C53C4-8DDA-438A-86ED-0DDD3CDB8D26
 | 
			
		||||
decode_with_drops.DESCRIPTION    = Drops frames while decoding
 | 
			
		||||
ifeq ($(CONFIG_DECODERS),yes)
 | 
			
		||||
GEN_EXAMPLES-$(CONFIG_ENCODERS) += decode_with_partial_drops.c
 | 
			
		||||
endif
 | 
			
		||||
decode_partial_with_drops.GUID           = CE5C53C4-8DDA-438A-86ED-0DDD3CDB8D27
 | 
			
		||||
decode_partial_with_drops.DESCRIPTION    = Drops parts of frames while decoding
 | 
			
		||||
GEN_EXAMPLES-$(CONFIG_ENCODERS) += error_resilient.c
 | 
			
		||||
error_resilient.GUID             = DF5837B9-4145-4F92-A031-44E4F832E00C
 | 
			
		||||
error_resilient.DESCRIPTION      = Error Resiliency Feature
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										213
									
								
								examples/decode_with_partial_drops.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										213
									
								
								examples/decode_with_partial_drops.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,213 @@
 | 
			
		||||
@TEMPLATE decoder_tmpl.c
 | 
			
		||||
Decode With Drops Example
 | 
			
		||||
=========================
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
 | 
			
		||||
This is an example utility which drops a series of frames, as specified
 | 
			
		||||
on the command line. This is useful for observing the error recovery
 | 
			
		||||
features of the codec.
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
 | 
			
		||||
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_INCLUDES
 | 
			
		||||
#include <time.h>
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_INCLUDES
 | 
			
		||||
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELPERS
 | 
			
		||||
struct parsed_header
 | 
			
		||||
{
 | 
			
		||||
    char key_frame;
 | 
			
		||||
    int version;
 | 
			
		||||
    char show_frame;
 | 
			
		||||
    int first_part_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int next_packet(struct parsed_header* hdr, int pos, int length, int mtu)
 | 
			
		||||
{
 | 
			
		||||
    int size = 0;
 | 
			
		||||
    int remaining = length - pos;
 | 
			
		||||
    /* Uncompressed part is 3 bytes for P frames and 10 bytes for I frames */
 | 
			
		||||
    int uncomp_part_size = (hdr->key_frame ? 10 : 3);
 | 
			
		||||
    /* number of bytes yet to send from header and the first partition */
 | 
			
		||||
    int remainFirst = uncomp_part_size + hdr->first_part_size - pos;
 | 
			
		||||
    if (remainFirst > 0)
 | 
			
		||||
    {
 | 
			
		||||
        if (remainFirst <= mtu)
 | 
			
		||||
        {
 | 
			
		||||
            size = remainFirst;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            size = mtu;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* second partition; just slot it up according to MTU */
 | 
			
		||||
    if (remaining <= mtu)
 | 
			
		||||
    {
 | 
			
		||||
        size = remaining;
 | 
			
		||||
        return size;
 | 
			
		||||
    }
 | 
			
		||||
    return mtu;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void throw_packets(unsigned char* frame, int* size, int loss_rate, int* thrown, int* kept)
 | 
			
		||||
{
 | 
			
		||||
    unsigned char loss_frame[256*1024];
 | 
			
		||||
    int pkg_size = 1;
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    int pos = 0;
 | 
			
		||||
    int loss_pos = 0;
 | 
			
		||||
    struct parsed_header hdr;
 | 
			
		||||
    unsigned int tmp;
 | 
			
		||||
    int mtu = 100;
 | 
			
		||||
 | 
			
		||||
    if (*size < 3)
 | 
			
		||||
    {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    putc('|', stdout);
 | 
			
		||||
    /* parse uncompressed 3 bytes */
 | 
			
		||||
    tmp = (frame[2] << 16) | (frame[1] << 8) | frame[0];
 | 
			
		||||
    hdr.key_frame = !(tmp & 0x1); /* inverse logic */
 | 
			
		||||
    hdr.version = (tmp >> 1) & 0x7;
 | 
			
		||||
    hdr.show_frame = (tmp >> 4) & 0x1;
 | 
			
		||||
    hdr.first_part_size = (tmp >> 5) & 0x7FFFF;
 | 
			
		||||
 | 
			
		||||
    /* don't drop key frames */
 | 
			
		||||
    if (hdr.key_frame)
 | 
			
		||||
    {
 | 
			
		||||
        int i;
 | 
			
		||||
        *kept = *size/mtu + ((*size % mtu > 0) ? 1 : 0); /* approximate */
 | 
			
		||||
        for (i=0; i < *kept; i++)
 | 
			
		||||
            putc('.', stdout);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while ((pkg_size = next_packet(&hdr, pos, *size, mtu)) > 0)
 | 
			
		||||
    {
 | 
			
		||||
        int loss_event = ((rand() + 1.0)/(RAND_MAX + 1.0) < loss_rate/100.0);
 | 
			
		||||
        if (*thrown == 0 && !loss_event)
 | 
			
		||||
        {
 | 
			
		||||
            memcpy(loss_frame + loss_pos, frame + pos, pkg_size);
 | 
			
		||||
            loss_pos += pkg_size;
 | 
			
		||||
            (*kept)++;
 | 
			
		||||
            putc('.', stdout);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            (*thrown)++;
 | 
			
		||||
            putc('X', stdout);
 | 
			
		||||
        }
 | 
			
		||||
        pos += pkg_size;
 | 
			
		||||
    }
 | 
			
		||||
    memcpy(frame, loss_frame, loss_pos);
 | 
			
		||||
    memset(frame + loss_pos, 0, *size - loss_pos);
 | 
			
		||||
    *size = loss_pos;
 | 
			
		||||
}
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELPERS
 | 
			
		||||
 | 
			
		||||
Usage
 | 
			
		||||
-----
 | 
			
		||||
This example adds a single argument to the `simple_decoder` example,
 | 
			
		||||
which specifies the range or pattern of frames to drop. The parameter is
 | 
			
		||||
parsed as follows:
 | 
			
		||||
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
 | 
			
		||||
if(argc!=4 && argc != 5)
 | 
			
		||||
    die("Usage: %s <infile> <outfile> <N-M|N/M|L,S>\n", argv[0]);
 | 
			
		||||
{
 | 
			
		||||
    char *nptr;
 | 
			
		||||
    n = strtol(argv[3], &nptr, 0);
 | 
			
		||||
    mode = (*nptr == '\0' || *nptr == ',') ? 2 : (*nptr == '-') ? 1 : 0;
 | 
			
		||||
 | 
			
		||||
    m = strtol(nptr+1, NULL, 0);
 | 
			
		||||
    if((!n && !m) || (*nptr != '-' && *nptr != '/' &&
 | 
			
		||||
        *nptr != '\0' && *nptr != ','))
 | 
			
		||||
        die("Couldn't parse pattern %s\n", argv[3]);
 | 
			
		||||
}
 | 
			
		||||
seed = (m > 0) ? m : (unsigned int)time(NULL);
 | 
			
		||||
srand(seed);thrown_frame = 0;
 | 
			
		||||
printf("Seed: %u\n", seed);
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Dropping A Range Of Frames
 | 
			
		||||
--------------------------
 | 
			
		||||
To drop a range of frames, specify the starting frame and the ending
 | 
			
		||||
frame to drop, separated by a dash. The following command will drop
 | 
			
		||||
frames 5 through 10 (base 1).
 | 
			
		||||
 | 
			
		||||
  $ ./decode_with_drops in.ivf out.i420 5-10
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Dropping A Pattern Of Frames
 | 
			
		||||
----------------------------
 | 
			
		||||
To drop a pattern of frames, specify the number of frames to drop and
 | 
			
		||||
the number of frames after which to repeat the pattern, separated by
 | 
			
		||||
a forward-slash. The following command will drop 3 of 7 frames.
 | 
			
		||||
Specifically, it will decode 4 frames, then drop 3 frames, and then
 | 
			
		||||
repeat.
 | 
			
		||||
 | 
			
		||||
  $ ./decode_with_drops in.ivf out.i420 3/7
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Extra Variables
 | 
			
		||||
---------------
 | 
			
		||||
This example maintains the pattern passed on the command line in the
 | 
			
		||||
`n`, `m`, and `is_range` variables:
 | 
			
		||||
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_VARS
 | 
			
		||||
int              n, m, mode;                                        //
 | 
			
		||||
unsigned int     seed;
 | 
			
		||||
int              thrown=0, kept=0;
 | 
			
		||||
int              thrown_frame=0, kept_frame=0;
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_VARS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Making The Drop Decision
 | 
			
		||||
------------------------
 | 
			
		||||
The example decides whether to drop the frame based on the current
 | 
			
		||||
frame number, immediately before decoding the frame.
 | 
			
		||||
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE
 | 
			
		||||
/* Decide whether to throw parts of the frame or the whole frame
 | 
			
		||||
   depending on the drop mode */
 | 
			
		||||
thrown_frame = 0;
 | 
			
		||||
kept_frame = 0;
 | 
			
		||||
switch (mode)
 | 
			
		||||
{
 | 
			
		||||
case 0:
 | 
			
		||||
    if (m - (frame_cnt-1)%m <= n)
 | 
			
		||||
    {
 | 
			
		||||
        frame_sz = 0;
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
case 1:
 | 
			
		||||
    if (frame_cnt >= n && frame_cnt <= m)
 | 
			
		||||
    {
 | 
			
		||||
        frame_sz = 0;
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
case 2:
 | 
			
		||||
    throw_packets(frame, &frame_sz, n, &thrown_frame, &kept_frame);
 | 
			
		||||
    break;
 | 
			
		||||
default: break;
 | 
			
		||||
}
 | 
			
		||||
if (mode < 2)
 | 
			
		||||
{
 | 
			
		||||
    if (frame_sz == 0)
 | 
			
		||||
    {
 | 
			
		||||
        putc('X', stdout);
 | 
			
		||||
        thrown_frame++;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        putc('.', stdout);
 | 
			
		||||
        kept_frame++;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
thrown += thrown_frame;
 | 
			
		||||
kept += kept_frame;
 | 
			
		||||
fflush(stdout);
 | 
			
		||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE
 | 
			
		||||
@@ -42,6 +42,8 @@ static void die(const char *fmt, ...) {
 | 
			
		||||
 | 
			
		||||
@DIE_CODEC
 | 
			
		||||
 | 
			
		||||
@HELPERS
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
    FILE            *infile, *outfile;
 | 
			
		||||
    vpx_codec_ctx_t  codec;
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@
 | 
			
		||||
#include "vpx_ports/config.h"
 | 
			
		||||
#include "blockd.h"
 | 
			
		||||
#include "vpx_mem/vpx_mem.h"
 | 
			
		||||
#include "error_concealment.h"
 | 
			
		||||
#include "onyxc_int.h"
 | 
			
		||||
#include "findnearmv.h"
 | 
			
		||||
#include "entropymode.h"
 | 
			
		||||
@@ -28,6 +29,9 @@ void vp8_update_mode_info_border(MODE_INFO *mi, int rows, int cols)
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < rows; i++)
 | 
			
		||||
    {
 | 
			
		||||
        /* TODO(holmer): Bug? This updates the last element of each row
 | 
			
		||||
         * rather than the border element!
 | 
			
		||||
         */
 | 
			
		||||
        vpx_memset(&mi[i*cols-1], 0, sizeof(MODE_INFO));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -44,9 +48,11 @@ void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
 | 
			
		||||
 | 
			
		||||
    vpx_free(oci->above_context);
 | 
			
		||||
    vpx_free(oci->mip);
 | 
			
		||||
    vpx_free(oci->prev_mip);
 | 
			
		||||
 | 
			
		||||
    oci->above_context = 0;
 | 
			
		||||
    oci->mip = 0;
 | 
			
		||||
    oci->prev_mip = 0;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -111,6 +117,16 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
 | 
			
		||||
 | 
			
		||||
    oci->mi = oci->mip + oci->mode_info_stride + 1;
 | 
			
		||||
 | 
			
		||||
    /* allocate memory for last frame MODE_INFO array */
 | 
			
		||||
    oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
 | 
			
		||||
 | 
			
		||||
    if (!oci->prev_mip)
 | 
			
		||||
    {
 | 
			
		||||
        vp8_de_alloc_frame_buffers(oci);
 | 
			
		||||
        return ALLOC_FAILURE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    oci->prev_mi = oci->prev_mip + oci->mode_info_stride + 1;
 | 
			
		||||
 | 
			
		||||
    oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -140,6 +140,8 @@ typedef struct VP8Common
 | 
			
		||||
 | 
			
		||||
    MODE_INFO *mip; /* Base of allocated array */
 | 
			
		||||
    MODE_INFO *mi;  /* Corresponds to upper left visible macroblock */
 | 
			
		||||
    MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */
 | 
			
		||||
    MODE_INFO *prev_mi;  /* 'mi' from last frame (points into prev_mip) */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    INTERPOLATIONFILTERTYPE mcomp_filter_type;
 | 
			
		||||
 
 | 
			
		||||
@@ -126,7 +126,7 @@ static void vp8dx_bool_decoder_fill(BOOL_DECODER *br) {
 | 
			
		||||
        for(shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); shift >= 0; ) \
 | 
			
		||||
        { \
 | 
			
		||||
            if((_bufptr) >= (_bufend)) { \
 | 
			
		||||
                (_count) = VP8_LOTS_OF_BITS; \
 | 
			
		||||
                (_count) += VP8_LOTS_OF_BITS; \
 | 
			
		||||
                break; \
 | 
			
		||||
            } \
 | 
			
		||||
            (_count) += 8; \
 | 
			
		||||
@@ -209,18 +209,19 @@ static int vp8_decode_value(BOOL_DECODER *br, int bits)
 | 
			
		||||
 | 
			
		||||
static int vp8dx_bool_error(BOOL_DECODER *br)
 | 
			
		||||
{
 | 
			
		||||
  /* Check if we have reached the end of the buffer.
 | 
			
		||||
   *
 | 
			
		||||
   * Variable 'count' stores the number of bits in the 'value' buffer,
 | 
			
		||||
   * minus 8. So if count == 8, there are 16 bits available to be read.
 | 
			
		||||
   * Normally, count is filled with 8 and one byte is filled into the
 | 
			
		||||
   * value buffer. When we reach the end of the buffer, count is instead
 | 
			
		||||
   * filled with VP8_LOTS_OF_BITS, 8 of which represent the last 8 real
 | 
			
		||||
   * bits from the bitstream. So the last bit in the bitstream will be
 | 
			
		||||
   * represented by count == VP8_LOTS_OF_BITS - 16.
 | 
			
		||||
   */
 | 
			
		||||
    if ((br->count > VP8_BD_VALUE_SIZE)
 | 
			
		||||
        && (br->count <= VP8_LOTS_OF_BITS - 16))
 | 
			
		||||
    /* Check if we have reached the end of the buffer.
 | 
			
		||||
     *
 | 
			
		||||
     * Variable 'count' stores the number of bits in the 'value' buffer, minus
 | 
			
		||||
     * 8. The top byte is part of the algorithm, and the remainder is buffered
 | 
			
		||||
     * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
 | 
			
		||||
     * occupied, 8 for the algorithm and 8 in the buffer.
 | 
			
		||||
     *
 | 
			
		||||
     * When reading a byte from the user's buffer, count is filled with 8 and
 | 
			
		||||
     * one byte is filled into the value buffer. When we reach the end of the
 | 
			
		||||
     * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
 | 
			
		||||
     * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
 | 
			
		||||
     */
 | 
			
		||||
    if ((br->count > VP8_BD_VALUE_SIZE) && (br->count < VP8_LOTS_OF_BITS))
 | 
			
		||||
    {
 | 
			
		||||
       /* We have tried to decode bits after the end of
 | 
			
		||||
        * stream was encountered.
 | 
			
		||||
 
 | 
			
		||||
@@ -251,6 +251,7 @@ void vp8_mb_mode_mv_init(VP8D_COMP *pbi)
 | 
			
		||||
    vp8_reader *const bc = & pbi->bc;
 | 
			
		||||
    MV_CONTEXT *const mvc = pbi->common.fc.mvc;
 | 
			
		||||
 | 
			
		||||
    pbi->mvs_corrupt_from_mb = -1;
 | 
			
		||||
    pbi->prob_skip_false = 0;
 | 
			
		||||
    if (pbi->common.mb_no_coeff_skip)
 | 
			
		||||
        pbi->prob_skip_false = (vp8_prob)vp8_read_literal(bc, 8);
 | 
			
		||||
@@ -412,7 +413,7 @@ void vp8_read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
 | 
			
		||||
 | 
			
		||||
                    do {
 | 
			
		||||
                        mi->bmi[ *fill_offset] = bmi;
 | 
			
		||||
                      fill_offset++;
 | 
			
		||||
                        fill_offset++;
 | 
			
		||||
 | 
			
		||||
                    }while (--fill_count);
 | 
			
		||||
                }
 | 
			
		||||
@@ -543,12 +544,18 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
 | 
			
		||||
 | 
			
		||||
        while (++mb_col < pbi->common.mb_cols)
 | 
			
		||||
        {
 | 
			
		||||
            int mb_num = mb_row * pbi->common.mb_cols + mb_col;
 | 
			
		||||
            /*vp8_read_mb_modes_mv(pbi, xd->mode_info_context, &xd->mode_info_context->mbmi, mb_row, mb_col);*/
 | 
			
		||||
            if(pbi->common.frame_type == KEY_FRAME)
 | 
			
		||||
                vp8_kfread_modes(pbi, mi, mb_row, mb_col);
 | 
			
		||||
            else
 | 
			
		||||
                vp8_read_mb_modes_mv(pbi, mi, &mi->mbmi, mb_row, mb_col);
 | 
			
		||||
 | 
			
		||||
            /* look for corruption */
 | 
			
		||||
            if (vp8dx_bool_error(&pbi->bc) && mb_num < pbi->mvs_corrupt_from_mb)
 | 
			
		||||
                pbi->mvs_corrupt_from_mb = mb_num;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            mi++;       /* next macroblock */
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,7 @@
 | 
			
		||||
 | 
			
		||||
#include "decodemv.h"
 | 
			
		||||
#include "extend.h"
 | 
			
		||||
#include "error_concealment.h"
 | 
			
		||||
#include "vpx_mem/vpx_mem.h"
 | 
			
		||||
#include "idct.h"
 | 
			
		||||
#include "dequantize.h"
 | 
			
		||||
@@ -176,11 +177,21 @@ void clamp_mvs(MACROBLOCKD *xd)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd)
 | 
			
		||||
void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, unsigned int mb_idx)
 | 
			
		||||
{
 | 
			
		||||
    int eobtotal = 0;
 | 
			
		||||
    int i, do_clamp = xd->mode_info_context->mbmi.need_to_clamp_mvs;
 | 
			
		||||
 | 
			
		||||
    /* TODO(holmer): change when we have MB level error tracking
 | 
			
		||||
     * The residuals may not match the predicted signal when a macroblock is
 | 
			
		||||
     * corrupted due to previous losses. Should we try to add the residual
 | 
			
		||||
     * anyway, or just throw it away? Should test this on a couple of files.
 | 
			
		||||
     */
 | 
			
		||||
    if (pbi->ec_enabled && mb_idx >= pbi->mvs_corrupt_from_mb)
 | 
			
		||||
    {
 | 
			
		||||
        xd->mode_info_context->mbmi.mb_skip_coeff = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (xd->mode_info_context->mbmi.mb_skip_coeff)
 | 
			
		||||
    {
 | 
			
		||||
        vp8_reset_mb_tokens_context(xd);
 | 
			
		||||
@@ -333,6 +344,7 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
 | 
			
		||||
    int dst_fb_idx = pc->new_fb_idx;
 | 
			
		||||
    int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride;
 | 
			
		||||
    int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride;
 | 
			
		||||
    int corrupt_partition = 0;
 | 
			
		||||
 | 
			
		||||
    vpx_memset(&pc->left_context, 0, sizeof(pc->left_context));
 | 
			
		||||
    recon_yoffset = mb_row * recon_y_stride * 16;
 | 
			
		||||
@@ -347,6 +359,28 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
 | 
			
		||||
 | 
			
		||||
    for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
 | 
			
		||||
    {
 | 
			
		||||
        /* Distance of Mb to the various image edges.
 | 
			
		||||
         * These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
 | 
			
		||||
         */
 | 
			
		||||
        xd->mb_to_left_edge = -((mb_col * 16) << 3);
 | 
			
		||||
        xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
 | 
			
		||||
 | 
			
		||||
        if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME &&
 | 
			
		||||
            corrupt_partition)
 | 
			
		||||
        {
 | 
			
		||||
            /* We have an intra block with corrupt coefficients,
 | 
			
		||||
             * better to conceal with an inter block. Interpolate MVs
 | 
			
		||||
             * from neighboring MBs.
 | 
			
		||||
             */
 | 
			
		||||
            /* TODO(holmer): We will fail to conceal an intra block with missing
 | 
			
		||||
             * coefficients if it's the first block with missing coefficients,
 | 
			
		||||
             * since the bool dec error detection is done after reconstruction.
 | 
			
		||||
             */
 | 
			
		||||
            vp8_interpolate_motion(xd,
 | 
			
		||||
                                   mb_row, mb_col,
 | 
			
		||||
                                   pc->mb_rows, pc->mb_cols,
 | 
			
		||||
                                   pc->mode_info_stride);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
 | 
			
		||||
        {
 | 
			
		||||
@@ -357,12 +391,6 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Distance of Mb to the various image edges.
 | 
			
		||||
         * These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
 | 
			
		||||
         */
 | 
			
		||||
        xd->mb_to_left_edge = -((mb_col * 16) << 3);
 | 
			
		||||
        xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
 | 
			
		||||
 | 
			
		||||
        xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
 | 
			
		||||
        xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
 | 
			
		||||
        xd->dst.v_buffer = pc->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
 | 
			
		||||
@@ -395,10 +423,11 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
 | 
			
		||||
        else
 | 
			
		||||
        pbi->debugoutput =0;
 | 
			
		||||
        */
 | 
			
		||||
        vp8_decode_macroblock(pbi, xd);
 | 
			
		||||
        vp8_decode_macroblock(pbi, xd, mb_row * pc->mb_cols + mb_col);
 | 
			
		||||
 | 
			
		||||
        /* check if the boolean decoder has suffered an error */
 | 
			
		||||
        xd->corrupted |= vp8dx_bool_error(xd->current_bc);
 | 
			
		||||
        corrupt_partition = vp8dx_bool_error(xd->current_bc);
 | 
			
		||||
        xd->corrupted |= corrupt_partition;
 | 
			
		||||
 | 
			
		||||
        recon_yoffset += 16;
 | 
			
		||||
        recon_uvoffset += 8;
 | 
			
		||||
@@ -469,8 +498,8 @@ static void setup_token_decoder(VP8D_COMP *pbi,
 | 
			
		||||
            partition_size = user_data_end - partition;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (partition + partition_size > user_data_end
 | 
			
		||||
            || partition + partition_size < partition)
 | 
			
		||||
        if (!pbi->ec_enabled && (partition + partition_size > user_data_end
 | 
			
		||||
            || partition + partition_size < partition))
 | 
			
		||||
            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                               "Truncated packet or corrupt partition "
 | 
			
		||||
                               "%d length", i + 1);
 | 
			
		||||
@@ -584,63 +613,87 @@ int vp8_decode_frame(VP8D_COMP *pbi)
 | 
			
		||||
    pc->yv12_fb[pc->new_fb_idx].corrupted = 0;
 | 
			
		||||
 | 
			
		||||
    if (data_end - data < 3)
 | 
			
		||||
        vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                           "Truncated packet");
 | 
			
		||||
    pc->frame_type = (FRAME_TYPE)(data[0] & 1);
 | 
			
		||||
    pc->version = (data[0] >> 1) & 7;
 | 
			
		||||
    pc->show_frame = (data[0] >> 4) & 1;
 | 
			
		||||
    first_partition_length_in_bytes =
 | 
			
		||||
        (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5;
 | 
			
		||||
    data += 3;
 | 
			
		||||
 | 
			
		||||
    if (data + first_partition_length_in_bytes > data_end
 | 
			
		||||
        || data + first_partition_length_in_bytes < data)
 | 
			
		||||
        vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                           "Truncated packet or corrupt partition 0 length");
 | 
			
		||||
    vp8_setup_version(pc);
 | 
			
		||||
 | 
			
		||||
    if (pc->frame_type == KEY_FRAME)
 | 
			
		||||
    {
 | 
			
		||||
        const int Width = pc->Width;
 | 
			
		||||
        const int Height = pc->Height;
 | 
			
		||||
 | 
			
		||||
        /* vet via sync code */
 | 
			
		||||
        if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a)
 | 
			
		||||
            vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
 | 
			
		||||
                               "Invalid frame sync code");
 | 
			
		||||
 | 
			
		||||
        pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
 | 
			
		||||
        pc->horiz_scale = data[4] >> 6;
 | 
			
		||||
        pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
 | 
			
		||||
        pc->vert_scale = data[6] >> 6;
 | 
			
		||||
        data += 7;
 | 
			
		||||
 | 
			
		||||
        if (Width != pc->Width  ||  Height != pc->Height)
 | 
			
		||||
        if (pbi->ec_enabled)
 | 
			
		||||
        {
 | 
			
		||||
            int prev_mb_rows = pc->mb_rows;
 | 
			
		||||
            /* Declare the missing frame as an inter frame since it will
 | 
			
		||||
               be handled as an inter frame when we have estimated its
 | 
			
		||||
               motion vectors. */
 | 
			
		||||
            pc->frame_type = INTER_FRAME;
 | 
			
		||||
            pc->version = 0;
 | 
			
		||||
            pc->show_frame = 1;
 | 
			
		||||
            first_partition_length_in_bytes = 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                               "Truncated packet");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        pc->frame_type = (FRAME_TYPE)(data[0] & 1);
 | 
			
		||||
        pc->version = (data[0] >> 1) & 7;
 | 
			
		||||
        pc->show_frame = (data[0] >> 4) & 1;
 | 
			
		||||
        first_partition_length_in_bytes =
 | 
			
		||||
            (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5;
 | 
			
		||||
        data += 3;
 | 
			
		||||
 | 
			
		||||
            if (pc->Width <= 0)
 | 
			
		||||
        if (!pbi->ec_enabled && (data + first_partition_length_in_bytes > data_end
 | 
			
		||||
            || data + first_partition_length_in_bytes < data))
 | 
			
		||||
            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                               "Truncated packet or corrupt partition 0 length");
 | 
			
		||||
        vp8_setup_version(pc);
 | 
			
		||||
 | 
			
		||||
        if (pc->frame_type == KEY_FRAME)
 | 
			
		||||
        {
 | 
			
		||||
            const int Width = pc->Width;
 | 
			
		||||
            const int Height = pc->Height;
 | 
			
		||||
 | 
			
		||||
            /* vet via sync code */
 | 
			
		||||
            if (!pbi->ec_enabled &&
 | 
			
		||||
                (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a))
 | 
			
		||||
                vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
 | 
			
		||||
                                   "Invalid frame sync code");
 | 
			
		||||
 | 
			
		||||
            pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
 | 
			
		||||
            pc->horiz_scale = data[4] >> 6;
 | 
			
		||||
            pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
 | 
			
		||||
            pc->vert_scale = data[6] >> 6;
 | 
			
		||||
            data += 7;
 | 
			
		||||
 | 
			
		||||
            if (Width != pc->Width  ||  Height != pc->Height)
 | 
			
		||||
            {
 | 
			
		||||
                pc->Width = Width;
 | 
			
		||||
                vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                                   "Invalid frame width");
 | 
			
		||||
            }
 | 
			
		||||
                int prev_mb_rows = pc->mb_rows;
 | 
			
		||||
 | 
			
		||||
            if (pc->Height <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                pc->Height = Height;
 | 
			
		||||
                vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                                   "Invalid frame height");
 | 
			
		||||
            }
 | 
			
		||||
                if (pc->Width <= 0)
 | 
			
		||||
                {
 | 
			
		||||
                    pc->Width = Width;
 | 
			
		||||
                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                                       "Invalid frame width");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
 | 
			
		||||
                vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
 | 
			
		||||
                                   "Failed to allocate frame buffers");
 | 
			
		||||
                if (pc->Height <= 0)
 | 
			
		||||
                {
 | 
			
		||||
                    pc->Height = Height;
 | 
			
		||||
                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
 | 
			
		||||
                                       "Invalid frame height");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
 | 
			
		||||
                    vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
 | 
			
		||||
                                       "Failed to allocate frame buffers");
 | 
			
		||||
 | 
			
		||||
                if (vp8_alloc_overlap_lists(pbi))
 | 
			
		||||
                    vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
 | 
			
		||||
                                       "Failed to allocate overlap lists for "
 | 
			
		||||
                                       "error concealment");
 | 
			
		||||
 | 
			
		||||
#if CONFIG_MULTITHREAD
 | 
			
		||||
            if (pbi->b_multithreaded_rd)
 | 
			
		||||
                vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
 | 
			
		||||
                if (pbi->b_multithreaded_rd)
 | 
			
		||||
                    vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
 | 
			
		||||
#endif
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -862,6 +915,12 @@ int vp8_decode_frame(VP8D_COMP *pbi)
 | 
			
		||||
 | 
			
		||||
    vp8_decode_mode_mvs(pbi);
 | 
			
		||||
 | 
			
		||||
    if (pbi->ec_enabled &&
 | 
			
		||||
            pbi->mvs_corrupt_from_mb < (unsigned int)pc->mb_cols * pc->mb_rows)
 | 
			
		||||
    {
 | 
			
		||||
        vp8_estimate_missing_mvs(pbi);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_cols);
 | 
			
		||||
 | 
			
		||||
    vpx_memcpy(&xd->block[0].bmi, &xd->mode_info_context->bmi[0], sizeof(B_MODE_INFO));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								vp8/decoder/ec_types.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								vp8/decoder/ec_types.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Copyright (c) 2011 The WebM project authors. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  Use of this source code is governed by a BSD-style license
 | 
			
		||||
 *  that can be found in the LICENSE file in the root of the source
 | 
			
		||||
 *  tree. An additional intellectual property rights grant can be found
 | 
			
		||||
 *  in the file PATENTS.  All contributing project authors may
 | 
			
		||||
 *  be found in the AUTHORS file in the root of the source tree.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef VP8_DEC_EC_TYPES_H
 | 
			
		||||
#define VP8_DEC_EC_TYPES_H
 | 
			
		||||
 | 
			
		||||
#define MAX_OVERLAPS 16
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    int overlap;
 | 
			
		||||
    B_MODE_INFO *bmi;
 | 
			
		||||
    MV_REFERENCE_FRAME ref_frame;
 | 
			
		||||
} OVERLAP_NODE;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    /* TODO(holmer): This array should be exchanged for a linked list */
 | 
			
		||||
    OVERLAP_NODE overlaps[MAX_OVERLAPS];
 | 
			
		||||
} B_OVERLAP;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    B_OVERLAP overlaps[16];
 | 
			
		||||
} MB_OVERLAP;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    MV mv;
 | 
			
		||||
    MV_REFERENCE_FRAME ref_frame;
 | 
			
		||||
} EC_BLOCK;
 | 
			
		||||
 | 
			
		||||
#endif /* VP8_DEC_EC_TYPES_H */
 | 
			
		||||
							
								
								
									
										612
									
								
								vp8/decoder/error_concealment.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										612
									
								
								vp8/decoder/error_concealment.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,612 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Copyright (c) 2011 The WebM project authors. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  Use of this source code is governed by a BSD-style license
 | 
			
		||||
 *  that can be found in the LICENSE file in the root of the source
 | 
			
		||||
 *  tree. An additional intellectual property rights grant can be found
 | 
			
		||||
 *  in the file PATENTS.  All contributing project authors may
 | 
			
		||||
 *  be found in the AUTHORS file in the root of the source tree.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "error_concealment.h"
 | 
			
		||||
#include "onyxd_int.h"
 | 
			
		||||
#include "vpx_mem/vpx_mem.h"
 | 
			
		||||
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
 | 
			
		||||
#define MIN(x,y) (((x)<(y))?(x):(y))
 | 
			
		||||
#define MAX(x,y) (((x)>(y))?(x):(y))
 | 
			
		||||
 | 
			
		||||
#define FLOOR(x,q) ((x) & -(1 << (q)))
 | 
			
		||||
 | 
			
		||||
#define NUM_NEIGHBORS 20
 | 
			
		||||
 | 
			
		||||
typedef struct ec_position
 | 
			
		||||
{
 | 
			
		||||
    int row;
 | 
			
		||||
    int col;
 | 
			
		||||
} EC_POS;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Regenerate the table in Matlab with:
 | 
			
		||||
 * x = meshgrid((1:4), (1:4));
 | 
			
		||||
 * y = meshgrid((1:4), (1:4))';
 | 
			
		||||
 * W = round((1./(sqrt(x.^2 + y.^2))*2^7));
 | 
			
		||||
 * W(1,1) = 0;
 | 
			
		||||
 */
 | 
			
		||||
static const int weights_q7[5][5] = {
 | 
			
		||||
       {  0,   128,    64,    43,    32 },
 | 
			
		||||
       {128,    91,    57,    40,    31 },
 | 
			
		||||
       { 64,    57,    45,    36,    29 },
 | 
			
		||||
       { 43,    40,    36,    30,    26 },
 | 
			
		||||
       { 32,    31,    29,    26,    23 }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int vp8_need_to_clamp_mv(MV *mv,
 | 
			
		||||
                         int mb_to_left_edge,
 | 
			
		||||
                         int mb_to_right_edge,
 | 
			
		||||
                         int mb_to_top_edge,
 | 
			
		||||
                         int mb_to_bottom_edge)
 | 
			
		||||
{
 | 
			
		||||
    return (mv->col < mb_to_left_edge) ||
 | 
			
		||||
           (mv->col > mb_to_right_edge) ||
 | 
			
		||||
           (mv->row < mb_to_top_edge) ||
 | 
			
		||||
           (mv->row > mb_to_bottom_edge);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int vp8_alloc_overlap_lists(VP8D_COMP *pbi)
 | 
			
		||||
{
 | 
			
		||||
    if (pbi->overlaps != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        vpx_free(pbi->overlaps);
 | 
			
		||||
        pbi->overlaps = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    pbi->overlaps = vpx_calloc(pbi->common.mb_rows * pbi->common.mb_cols,
 | 
			
		||||
                               sizeof(MB_OVERLAP));
 | 
			
		||||
    vpx_memset(pbi->overlaps, 0,
 | 
			
		||||
               sizeof(MB_OVERLAP) * pbi->common.mb_rows * pbi->common.mb_cols);
 | 
			
		||||
    if (pbi->overlaps == NULL)
 | 
			
		||||
        return -1;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_de_alloc_overlap_lists(VP8D_COMP *pbi)
 | 
			
		||||
{
 | 
			
		||||
    if (pbi->overlaps != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        vpx_free(pbi->overlaps);
 | 
			
		||||
        pbi->overlaps = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_assign_overlap(OVERLAP_NODE* overlaps,
 | 
			
		||||
                        B_MODE_INFO *bmi,
 | 
			
		||||
                        MV_REFERENCE_FRAME ref_frame,
 | 
			
		||||
                        int overlap)
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    if (overlap <= 0)
 | 
			
		||||
        return;
 | 
			
		||||
    for (i = 0; i < MAX_OVERLAPS; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (overlaps[i].bmi == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            overlaps[i].bmi = bmi;
 | 
			
		||||
            overlaps[i].ref_frame = ref_frame;
 | 
			
		||||
            overlaps[i].overlap = overlap;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int vp8_block_overlap(int b1_row, int b1_col, int b2_row, int b2_col)
 | 
			
		||||
{
 | 
			
		||||
    const int int_top = MAX(b1_row, b2_row); // top
 | 
			
		||||
    const int int_left = MAX(b1_col, b2_col); // left
 | 
			
		||||
    const int int_right = MIN(b1_col + (4<<3), b2_col + (4<<3)); // right
 | 
			
		||||
    const int int_bottom = MIN(b1_row + (4<<3), b2_row + (4<<3)); // bottom
 | 
			
		||||
    return (int_bottom - int_top) * (int_right - int_left);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
 | 
			
		||||
                               MV_REFERENCE_FRAME ref_frame,
 | 
			
		||||
                               int new_row, int new_col,
 | 
			
		||||
                               int mb_row, int mb_col,
 | 
			
		||||
                               int first_blk_row, int first_blk_col)
 | 
			
		||||
{
 | 
			
		||||
    /* Find the blocks within this MB which are overlapped by bmi and
 | 
			
		||||
     * calculate and assign overlap for each of those blocks. */
 | 
			
		||||
 | 
			
		||||
    /* Block coordinates relative the upper-left block */
 | 
			
		||||
    const int rel_ol_blk_row = first_blk_row - mb_row * 4;
 | 
			
		||||
    const int rel_ol_blk_col = first_blk_col - mb_col * 4;
 | 
			
		||||
    /* If the block partly overlaps any previous MB, these coordinates
 | 
			
		||||
     * can be < 0. We don't want to access blocks in previous MBs.
 | 
			
		||||
     */
 | 
			
		||||
    const int blk_idx = MAX(rel_ol_blk_row,0) * 4 + MAX(rel_ol_blk_col,0);
 | 
			
		||||
    /* Upper left overlapping block */
 | 
			
		||||
    B_OVERLAP *b_ol_ul = &(b_overlaps[blk_idx]);
 | 
			
		||||
 | 
			
		||||
    /* Calculate and assign overlaps for all blocks in this MB
 | 
			
		||||
     * which the motion compensated block overlaps
 | 
			
		||||
     */
 | 
			
		||||
    /* Avoid calculating overlaps for blocks in later MBs */
 | 
			
		||||
    int end_row = MIN(4 + mb_row * 4 - first_blk_row, 2);
 | 
			
		||||
    int end_col = MIN(4 + mb_col * 4 - first_blk_col, 2);
 | 
			
		||||
    int row, col;
 | 
			
		||||
 | 
			
		||||
    /* Check if new_row and new_col are evenly divisible by 4 (Q3),
 | 
			
		||||
     * and if so we shouldn't check neighboring blocks
 | 
			
		||||
     */
 | 
			
		||||
    if (new_row >= 0 && (new_row & 0x1F) == 0)
 | 
			
		||||
        end_row = 1;
 | 
			
		||||
    if (new_col >= 0 && (new_col & 0x1F) == 0)
 | 
			
		||||
        end_col = 1;
 | 
			
		||||
 | 
			
		||||
    /* Check if the overlapping block partly overlaps a previous MB
 | 
			
		||||
     * and if so, we're overlapping fewer blocks in this MB.
 | 
			
		||||
     */
 | 
			
		||||
    if (new_row < (mb_row*16)<<3)
 | 
			
		||||
        end_row = 1;
 | 
			
		||||
    if (new_col < (mb_col*16)<<3)
 | 
			
		||||
        end_col = 1;
 | 
			
		||||
 | 
			
		||||
    for (row = 0; row < end_row; ++row)
 | 
			
		||||
    {
 | 
			
		||||
        for (col = 0; col < end_col; ++col)
 | 
			
		||||
        {
 | 
			
		||||
            /* input in Q3, result in Q6 */
 | 
			
		||||
            const int overlap = vp8_block_overlap(new_row, new_col,
 | 
			
		||||
                                                  (((first_blk_row + row) *
 | 
			
		||||
                                                      4) << 3),
 | 
			
		||||
                                                  (((first_blk_col + col) *
 | 
			
		||||
                                                      4) << 3));
 | 
			
		||||
            vp8_assign_overlap(b_ol_ul[row * 4 + col].overlaps,
 | 
			
		||||
                               bmi,
 | 
			
		||||
                               ref_frame,
 | 
			
		||||
                               overlap);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_calculate_overlaps(MB_OVERLAP *overlap_ul,
 | 
			
		||||
                            int mb_rows, int mb_cols,
 | 
			
		||||
                            B_MODE_INFO *bmi,
 | 
			
		||||
                            MV_REFERENCE_FRAME ref_frame,
 | 
			
		||||
                            int b_row, int b_col)
 | 
			
		||||
{
 | 
			
		||||
    MB_OVERLAP *mb_overlap;
 | 
			
		||||
    int row, col, rel_row, rel_col;
 | 
			
		||||
    int new_row, new_col;
 | 
			
		||||
    int new_row_pos, new_col_pos;
 | 
			
		||||
    int end_row, end_col;
 | 
			
		||||
    int overlap_b_row, overlap_b_col;
 | 
			
		||||
    int overlap_mb_row, overlap_mb_col;
 | 
			
		||||
    int i;
 | 
			
		||||
    B_MODE_INFO *obmi;
 | 
			
		||||
    int overlap;
 | 
			
		||||
 | 
			
		||||
    if (ref_frame == INTRA_FRAME)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    /* mb subpixel position */
 | 
			
		||||
    row = (4 * b_row) << 3; /* Q3 */
 | 
			
		||||
    col = (4 * b_col) << 3; /* Q3 */
 | 
			
		||||
 | 
			
		||||
    /* reverse compensate for motion */
 | 
			
		||||
    new_row = row - bmi->mv.as_mv.row;
 | 
			
		||||
    new_col = col - bmi->mv.as_mv.col;
 | 
			
		||||
 | 
			
		||||
    if (new_row >= ((16*mb_rows) << 3) || new_col >= ((16*mb_cols) << 3))
 | 
			
		||||
    {
 | 
			
		||||
        /* the new block ended up outside the frame */
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (new_row <= (-4 << 3) || new_col <= (-4 << 3))
 | 
			
		||||
    {
 | 
			
		||||
        /* outside the frame */
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    /* overlapping block's position in blocks */
 | 
			
		||||
    overlap_b_row = FLOOR(new_row / 4, 3) >> 3;
 | 
			
		||||
    overlap_b_col = FLOOR(new_col / 4, 3) >> 3;
 | 
			
		||||
 | 
			
		||||
    /* overlapping block's MB position in MBs
 | 
			
		||||
     * operations are done in Q3
 | 
			
		||||
     */
 | 
			
		||||
    overlap_mb_row = FLOOR((overlap_b_row << 3) / 4, 3) >> 3;
 | 
			
		||||
    overlap_mb_col = FLOOR((overlap_b_col << 3) / 4, 3) >> 3;
 | 
			
		||||
 | 
			
		||||
    end_row = MIN(mb_rows - overlap_mb_row, 2);
 | 
			
		||||
    end_col = MIN(mb_cols - overlap_mb_col, 2);
 | 
			
		||||
 | 
			
		||||
    /* Don't calculate overlap for MBs we don't overlap */
 | 
			
		||||
    /* Check if the new block row starts at the last block row of the MB */
 | 
			
		||||
    if (abs(new_row - ((16*overlap_mb_row) << 3)) < ((3*4) << 3))
 | 
			
		||||
        end_row = 1;
 | 
			
		||||
    /* Check if the new block col starts at the last block col of the MB */
 | 
			
		||||
    if (abs(new_col - ((16*overlap_mb_col) << 3)) < ((3*4) << 3))
 | 
			
		||||
        end_col = 1;
 | 
			
		||||
 | 
			
		||||
    /* find the MB(s) this block is overlapping */
 | 
			
		||||
    for (rel_row = 0; rel_row < end_row; ++rel_row)
 | 
			
		||||
    {
 | 
			
		||||
        for (rel_col = 0; rel_col < end_col; ++rel_col)
 | 
			
		||||
        {
 | 
			
		||||
            if (overlap_mb_row + rel_row < 0 ||
 | 
			
		||||
                overlap_mb_col + rel_col < 0)
 | 
			
		||||
                continue;
 | 
			
		||||
            mb_overlap = overlap_ul + (overlap_mb_row + rel_row) * mb_cols +
 | 
			
		||||
                 overlap_mb_col + rel_col;
 | 
			
		||||
 | 
			
		||||
            vp8_calculate_overlaps_mb(mb_overlap->overlaps, bmi, ref_frame,
 | 
			
		||||
                                      new_row, new_col,
 | 
			
		||||
                                      overlap_mb_row + rel_row,
 | 
			
		||||
                                      overlap_mb_col + rel_col,
 | 
			
		||||
                                      overlap_b_row + rel_row,
 | 
			
		||||
                                      overlap_b_col + rel_col);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MV_REFERENCE_FRAME vp8_largest_overlap_type(const B_OVERLAP *block_overlaps)
 | 
			
		||||
{
 | 
			
		||||
    int i, j;
 | 
			
		||||
    int overlap_per_type[MAX_REF_FRAMES] = {0};
 | 
			
		||||
    int largest_overlap = 0;
 | 
			
		||||
    MV_REFERENCE_FRAME largest_overlap_type = LAST_FRAME;
 | 
			
		||||
    for (i=0; i < 16; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        const OVERLAP_NODE *overlaps = block_overlaps->overlaps;
 | 
			
		||||
        for (j=0; j < MAX_OVERLAPS; ++j)
 | 
			
		||||
        {
 | 
			
		||||
            if (overlaps[j].bmi != NULL)
 | 
			
		||||
            {
 | 
			
		||||
                overlap_per_type[overlaps[j].ref_frame] += overlaps[j].overlap;
 | 
			
		||||
                if (overlap_per_type[overlaps[j].ref_frame] > largest_overlap)
 | 
			
		||||
                {
 | 
			
		||||
                    largest_overlap = overlap_per_type[overlaps[j].ref_frame];
 | 
			
		||||
                    largest_overlap_type = overlaps[j].ref_frame;
 | 
			
		||||
                }
 | 
			
		||||
                assert(overlaps[j].overlap < (16*16)<<6);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        ++block_overlaps;
 | 
			
		||||
    }
 | 
			
		||||
    return largest_overlap_type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_estimate_mv(const OVERLAP_NODE *overlaps, B_MODE_INFO *bmi,
 | 
			
		||||
                                   MV_REFERENCE_FRAME type)
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    int overlap_sum = 0;
 | 
			
		||||
    int row_acc = 0;
 | 
			
		||||
    int col_acc = 0;
 | 
			
		||||
 | 
			
		||||
    bmi->mv.as_int = 0;
 | 
			
		||||
    for (i=0; i < MAX_OVERLAPS; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if (overlaps[i].bmi != NULL &&
 | 
			
		||||
            overlaps[i].ref_frame == type)
 | 
			
		||||
        {
 | 
			
		||||
            col_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.col;
 | 
			
		||||
            row_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.row;
 | 
			
		||||
            overlap_sum += overlaps[i].overlap;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (overlap_sum > 0)
 | 
			
		||||
    {
 | 
			
		||||
        /* Q9 / Q6 = Q3 */
 | 
			
		||||
        bmi->mv.as_mv.col = col_acc / overlap_sum;
 | 
			
		||||
        bmi->mv.as_mv.row = row_acc / overlap_sum;
 | 
			
		||||
        bmi->mode = NEW4X4;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        bmi->mv.as_mv.col = 0;
 | 
			
		||||
        bmi->mv.as_mv.row = 0;
 | 
			
		||||
        bmi->mode = NEW4X4;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_estimate_mb_mvs(const B_OVERLAP *block_overlaps,
 | 
			
		||||
                         MODE_INFO *mi,
 | 
			
		||||
                         int mb_to_left_edge,
 | 
			
		||||
                         int mb_to_right_edge,
 | 
			
		||||
                         int mb_to_top_edge,
 | 
			
		||||
                         int mb_to_bottom_edge)
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    int non_zero_count = 0;
 | 
			
		||||
    MV * const filtered_mv = &(mi->mbmi.mv.as_mv);
 | 
			
		||||
    B_MODE_INFO * const bmi = mi->bmi;
 | 
			
		||||
    filtered_mv->col = 0;
 | 
			
		||||
    filtered_mv->row = 0;
 | 
			
		||||
    for (i = 0; i < 16; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        /* Estimate vectors for all blocks which are overlapped by this
 | 
			
		||||
         * type
 | 
			
		||||
         */
 | 
			
		||||
        /* Interpolate/extrapolate the rest of the block's MVs */
 | 
			
		||||
        vp8_estimate_mv(block_overlaps[i].overlaps, bmi + i,
 | 
			
		||||
                mi->mbmi.ref_frame);
 | 
			
		||||
        mi->mbmi.need_to_clamp_mvs = vp8_need_to_clamp_mv(&(bmi[i].mv.as_mv),
 | 
			
		||||
                                                          mb_to_left_edge,
 | 
			
		||||
                                                          mb_to_right_edge,
 | 
			
		||||
                                                          mb_to_top_edge,
 | 
			
		||||
                                                          mb_to_bottom_edge);
 | 
			
		||||
        if (bmi[i].mv.as_int != 0)
 | 
			
		||||
        {
 | 
			
		||||
            ++non_zero_count;
 | 
			
		||||
            filtered_mv->col += bmi[i].mv.as_mv.col;
 | 
			
		||||
            filtered_mv->row += bmi[i].mv.as_mv.row;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (non_zero_count > 0)
 | 
			
		||||
    {
 | 
			
		||||
        filtered_mv->col /= non_zero_count;
 | 
			
		||||
        filtered_mv->row /= non_zero_count;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_estimate_missing_mvs(VP8D_COMP *pbi)
 | 
			
		||||
{
 | 
			
		||||
    VP8_COMMON * const pc = &pbi->common;
 | 
			
		||||
    vp8_estimate_missing_mvs_ex(pbi->overlaps,
 | 
			
		||||
                                pc->mi, pc->prev_mi,
 | 
			
		||||
                                pc->mb_rows, pc->mb_cols,
 | 
			
		||||
                                pbi->mvs_corrupt_from_mb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
 | 
			
		||||
                                 MODE_INFO *mi, MODE_INFO *prev_mi,
 | 
			
		||||
                                 int mb_rows, int mb_cols,
 | 
			
		||||
                                 unsigned int first_corrupt)
 | 
			
		||||
{
 | 
			
		||||
    const unsigned int num_mbs = mb_rows * mb_cols;
 | 
			
		||||
    int mb_row, mb_col;
 | 
			
		||||
    vpx_memset(overlaps, 0, sizeof(MB_OVERLAP) * mb_rows * mb_cols);
 | 
			
		||||
    /* First calculate the overlaps for all blocks */
 | 
			
		||||
    for (mb_row = 0; mb_row < mb_rows; ++mb_row)
 | 
			
		||||
    {
 | 
			
		||||
        for (mb_col = 0; mb_col < mb_cols; ++mb_col)
 | 
			
		||||
        {
 | 
			
		||||
            int sub_row;
 | 
			
		||||
            int sub_col;
 | 
			
		||||
            for (sub_row = 0; sub_row < 4; ++sub_row)
 | 
			
		||||
            {
 | 
			
		||||
                for (sub_col = 0; sub_col < 4; ++sub_col)
 | 
			
		||||
                {
 | 
			
		||||
                    vp8_calculate_overlaps(
 | 
			
		||||
                                        overlaps, mb_rows, mb_cols,
 | 
			
		||||
                                        &(prev_mi->bmi[sub_row * 4 + sub_col]),
 | 
			
		||||
                                        prev_mi->mbmi.ref_frame,
 | 
			
		||||
                                        4 * mb_row + sub_row,
 | 
			
		||||
                                        4 * mb_col + sub_col);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            ++prev_mi;
 | 
			
		||||
        }
 | 
			
		||||
        ++prev_mi;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mb_row = first_corrupt / mb_cols;
 | 
			
		||||
    mb_col = first_corrupt - mb_row * mb_cols;
 | 
			
		||||
    mi += mb_row*(mb_cols + 1) + mb_col;
 | 
			
		||||
    /* Go through all macroblocks in the current image with missing MVs
 | 
			
		||||
     * and calculate new MVs using the overlaps.
 | 
			
		||||
     */
 | 
			
		||||
    for (; mb_row < mb_rows; ++mb_row)
 | 
			
		||||
    {
 | 
			
		||||
        int mb_to_top_edge = -((mb_row * 16)) << 3;
 | 
			
		||||
        int mb_to_bottom_edge = ((mb_rows - 1 - mb_row) * 16) << 3;
 | 
			
		||||
        for (; mb_col < mb_cols; ++mb_col)
 | 
			
		||||
        {
 | 
			
		||||
            int mb_to_left_edge = -((mb_col * 16) << 3);
 | 
			
		||||
            int mb_to_right_edge = ((mb_cols - 1 - mb_col) * 16) << 3;
 | 
			
		||||
            int i;
 | 
			
		||||
            MV_REFERENCE_FRAME type = LAST_FRAME;
 | 
			
		||||
            int largest_overlap = 0;
 | 
			
		||||
            const B_OVERLAP *block_overlaps =
 | 
			
		||||
                    overlaps[mb_row*mb_cols + mb_col].overlaps;
 | 
			
		||||
            /* Find largest overlap and its type */
 | 
			
		||||
            mi->mbmi.ref_frame = vp8_largest_overlap_type(block_overlaps);
 | 
			
		||||
            vp8_estimate_mb_mvs(block_overlaps,
 | 
			
		||||
                                mi,
 | 
			
		||||
                                mb_to_left_edge,
 | 
			
		||||
                                mb_to_right_edge,
 | 
			
		||||
                                mb_to_top_edge,
 | 
			
		||||
                                mb_to_bottom_edge);
 | 
			
		||||
            mi->mbmi.mode = SPLITMV;
 | 
			
		||||
            mi->mbmi.uv_mode = DC_PRED;
 | 
			
		||||
            mi->mbmi.partitioning = 3;
 | 
			
		||||
            ++mi;
 | 
			
		||||
        }
 | 
			
		||||
        mb_col = 0;
 | 
			
		||||
        ++mi;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void assign_neighbor(EC_BLOCK *neighbor, MODE_INFO *mi, int block_idx)
 | 
			
		||||
{
 | 
			
		||||
    assert(mi->mbmi.ref_frame < MAX_REF_FRAMES);
 | 
			
		||||
    neighbor->ref_frame = mi->mbmi.ref_frame;
 | 
			
		||||
    neighbor->mv = mi->bmi[block_idx].mv.as_mv;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_find_neighboring_blocks(MODE_INFO *mi,
 | 
			
		||||
                                 EC_BLOCK *neighbors,
 | 
			
		||||
                                 int mb_row, int mb_col,
 | 
			
		||||
                                 int mb_rows, int mb_cols,
 | 
			
		||||
                                 int mi_stride)
 | 
			
		||||
{
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    int j;
 | 
			
		||||
    if (mb_row > 0)
 | 
			
		||||
    {
 | 
			
		||||
        /* upper left */
 | 
			
		||||
        if (mb_col > 0)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi - mi_stride - 1, 15);
 | 
			
		||||
        ++i;
 | 
			
		||||
        /* above */
 | 
			
		||||
        for (j = 12; j < 16; ++j, ++i)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi - mi_stride, j);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        i += 5;
 | 
			
		||||
    if (mb_col < mb_cols - 1)
 | 
			
		||||
    {
 | 
			
		||||
        /* upper right */
 | 
			
		||||
        if (mb_row > 0)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi - mi_stride + 1, 12);
 | 
			
		||||
        ++i;
 | 
			
		||||
        /* right */
 | 
			
		||||
        for (j = 0; j <= 12; j += 4, ++i)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi + 1, j);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        i += 5;
 | 
			
		||||
    if (mb_row < mb_rows - 1)
 | 
			
		||||
    {
 | 
			
		||||
        /* lower right */
 | 
			
		||||
        if (mb_col < mb_cols - 1)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi + mi_stride + 1, 0);
 | 
			
		||||
        ++i;
 | 
			
		||||
        /* below */
 | 
			
		||||
        for (j = 0; j < 4; ++j, ++i)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi + mi_stride, j);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        i += 5;
 | 
			
		||||
    if (mb_col > 0)
 | 
			
		||||
    {
 | 
			
		||||
        /* lower left */
 | 
			
		||||
        if (mb_row < mb_rows - 1)
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi + mi_stride - 1, 4);
 | 
			
		||||
        ++i;
 | 
			
		||||
        /* left */
 | 
			
		||||
        for (j = 3; j < 16; j += 4, ++i)
 | 
			
		||||
        {
 | 
			
		||||
            assign_neighbor(&neighbors[i], mi - 1, j);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        i += 5;
 | 
			
		||||
    assert(i == 20);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MV_REFERENCE_FRAME vp8_dominant_ref_frame(EC_BLOCK *neighbors)
 | 
			
		||||
{
 | 
			
		||||
    /* Default to referring to "skip" */
 | 
			
		||||
    MV_REFERENCE_FRAME dom_ref_frame = LAST_FRAME;
 | 
			
		||||
    int max_ref_frame_cnt = 0;
 | 
			
		||||
    int ref_frame_cnt[MAX_REF_FRAMES] = {0};
 | 
			
		||||
    int i;
 | 
			
		||||
    /* Count neighboring reference frames */
 | 
			
		||||
    for (i = 0; i < NUM_NEIGHBORS; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if (neighbors[i].ref_frame < MAX_REF_FRAMES)
 | 
			
		||||
            ++ref_frame_cnt[neighbors[i].ref_frame];
 | 
			
		||||
    }
 | 
			
		||||
    /* Find maximum */
 | 
			
		||||
    for (i = 0; i < MAX_REF_FRAMES; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if (ref_frame_cnt[i] > max_ref_frame_cnt)
 | 
			
		||||
        {
 | 
			
		||||
            dom_ref_frame = i;
 | 
			
		||||
            max_ref_frame_cnt = ref_frame_cnt[i];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return dom_ref_frame;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_interpolate_mvs(MACROBLOCKD *mb,
 | 
			
		||||
                         EC_BLOCK *neighbors,
 | 
			
		||||
                         MV_REFERENCE_FRAME dom_ref_frame)
 | 
			
		||||
{
 | 
			
		||||
    int row, col, i;
 | 
			
		||||
    MODE_INFO * const mi = mb->mode_info_context;
 | 
			
		||||
    /* Table with the position of the neighboring blocks relative the position
 | 
			
		||||
     * of the upper left block of the current MB. Starting with the upper left
 | 
			
		||||
     * neighbor and going to the right.
 | 
			
		||||
     */
 | 
			
		||||
    const EC_POS neigh_pos[NUM_NEIGHBORS] = {
 | 
			
		||||
                                        {-1,-1}, {-1,0}, {-1,1}, {-1,2}, {-1,3},
 | 
			
		||||
                                        {-1,4}, {0,4}, {1,4}, {2,4}, {3,4},
 | 
			
		||||
                                        {4,4}, {4,3}, {4,2}, {4,1}, {4,0},
 | 
			
		||||
                                        {4,-1}, {3,-1}, {2,-1}, {1,-1}, {0,-1}
 | 
			
		||||
                                      };
 | 
			
		||||
    for (row = 0; row < 4; ++row)
 | 
			
		||||
    {
 | 
			
		||||
        for (col = 0; col < 4; ++col)
 | 
			
		||||
        {
 | 
			
		||||
            int w_sum = 0;
 | 
			
		||||
            int mv_row_sum = 0;
 | 
			
		||||
            int mv_col_sum = 0;
 | 
			
		||||
            MV * const mv = &(mi->bmi[row*4 + col].mv.as_mv);
 | 
			
		||||
            for (i = 0; i < NUM_NEIGHBORS; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                /* Calculate the weighted sum of neighboring MVs referring
 | 
			
		||||
                 * to the dominant frame type.
 | 
			
		||||
                 */
 | 
			
		||||
                const int w = weights_q7[abs(row - neigh_pos[i].row)]
 | 
			
		||||
                                        [abs(col - neigh_pos[i].col)];
 | 
			
		||||
                if (neighbors[i].ref_frame != dom_ref_frame)
 | 
			
		||||
                    continue;
 | 
			
		||||
                w_sum += w;
 | 
			
		||||
                /* Q7 * Q3 = Q10 */
 | 
			
		||||
                mv_row_sum += w*neighbors[i].mv.row;
 | 
			
		||||
                mv_col_sum += w*neighbors[i].mv.col;
 | 
			
		||||
            }
 | 
			
		||||
            if (w_sum > 0)
 | 
			
		||||
            {
 | 
			
		||||
                /* Avoid division by zero.
 | 
			
		||||
                 * Normalize with the sum of the coefficients
 | 
			
		||||
                 * Q3 = Q10 / Q7
 | 
			
		||||
                 */
 | 
			
		||||
                mv->row = mv_row_sum / w_sum;
 | 
			
		||||
                mv->col = mv_col_sum / w_sum;
 | 
			
		||||
                mi->bmi[row*4 + col].mode = NEW4X4;
 | 
			
		||||
                mi->mbmi.need_to_clamp_mvs = vp8_need_to_clamp_mv(mv,
 | 
			
		||||
                                                       mb->mb_to_left_edge,
 | 
			
		||||
                                                       mb->mb_to_right_edge,
 | 
			
		||||
                                                       mb->mb_to_top_edge,
 | 
			
		||||
                                                       mb->mb_to_bottom_edge);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void vp8_interpolate_motion(MACROBLOCKD *mb,
 | 
			
		||||
                        int mb_row, int mb_col,
 | 
			
		||||
                        int mb_rows, int mb_cols,
 | 
			
		||||
                        int mi_stride)
 | 
			
		||||
{
 | 
			
		||||
    /* Find relevant neighboring blocks */
 | 
			
		||||
    EC_BLOCK neighbors[NUM_NEIGHBORS];
 | 
			
		||||
    MV_REFERENCE_FRAME dom_ref_frame;
 | 
			
		||||
    int i;
 | 
			
		||||
    /* Initialize the array. MAX_REF_FRAMES is interpreted as "doesn't exist" */
 | 
			
		||||
    for (i = 0; i < NUM_NEIGHBORS; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        neighbors[i].ref_frame = MAX_REF_FRAMES;
 | 
			
		||||
        neighbors[i].mv.row = neighbors[i].mv.col = 0;
 | 
			
		||||
    }
 | 
			
		||||
    vp8_find_neighboring_blocks(mb->mode_info_context,
 | 
			
		||||
                                neighbors,
 | 
			
		||||
                                mb_row, mb_col,
 | 
			
		||||
                                mb_rows, mb_cols,
 | 
			
		||||
                                mb->mode_info_stride);
 | 
			
		||||
    /* Determine the dominant block type */
 | 
			
		||||
    dom_ref_frame = vp8_dominant_ref_frame(neighbors);
 | 
			
		||||
    /* Interpolate MVs for the missing blocks
 | 
			
		||||
     * from the dominating MVs */
 | 
			
		||||
    vp8_interpolate_mvs(mb, neighbors, dom_ref_frame);
 | 
			
		||||
 | 
			
		||||
    mb->mode_info_context->mbmi.ref_frame = dom_ref_frame;
 | 
			
		||||
    mb->mode_info_context->mbmi.mode = SPLITMV;
 | 
			
		||||
    mb->mode_info_context->mbmi.uv_mode = DC_PRED;
 | 
			
		||||
    mb->mode_info_context->mbmi.partitioning = 3;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										112
									
								
								vp8/decoder/error_concealment.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								vp8/decoder/error_concealment.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Copyright (c) 2011 The WebM project authors. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  Use of this source code is governed by a BSD-style license
 | 
			
		||||
 *  that can be found in the LICENSE file in the root of the source
 | 
			
		||||
 *  tree. An additional intellectual property rights grant can be found
 | 
			
		||||
 *  in the file PATENTS.  All contributing project authors may
 | 
			
		||||
 *  be found in the AUTHORS file in the root of the source tree.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef ERROR_CONCEALMENT_H
 | 
			
		||||
#define ERROR_CONCEALMENT_H
 | 
			
		||||
 | 
			
		||||
#include "onyxd_int.h"
 | 
			
		||||
#include "ec_types.h"
 | 
			
		||||
 | 
			
		||||
/* Allocate memory for the overlap lists */
 | 
			
		||||
int vp8_alloc_overlap_lists(VP8D_COMP *pbi);
 | 
			
		||||
 | 
			
		||||
/* Deallocate the overlap lists */
 | 
			
		||||
void vp8_de_alloc_overlap_lists(VP8D_COMP *pbi);
 | 
			
		||||
 | 
			
		||||
/* Inserts a new overlap area value to the list of overlaps of a block */
 | 
			
		||||
void vp8_assign_overlap(OVERLAP_NODE* overlaps,
 | 
			
		||||
                        B_MODE_INFO *bmi,
 | 
			
		||||
                        MV_REFERENCE_FRAME ref_frame,
 | 
			
		||||
                        int overlap);
 | 
			
		||||
 | 
			
		||||
/* Calculates the overlap area between two 4x4 squares, where the first
 | 
			
		||||
 * square has its upper-left corner at (b1_row, b1_col) and the second
 | 
			
		||||
 * square has its upper-left corner at (b2_row, b2_col). Doesn't
 | 
			
		||||
 * properly handle squares which doesn't overlap.
 | 
			
		||||
 */
 | 
			
		||||
int vp8_block_overlap(int b1_row, int b1_col, int b2_row, int b2_col);
 | 
			
		||||
 | 
			
		||||
/* Finds the reference frame type which has the largest overlapping area. */
 | 
			
		||||
MV_REFERENCE_FRAME vp8_largest_overlap_type(const B_OVERLAP *block_overlaps);
 | 
			
		||||
 | 
			
		||||
/* Calculates the overlap area for all blocks in a macroblock at position
 | 
			
		||||
 * (mb_row, mb_col) in macroblocks, which are being overlapped by a given
 | 
			
		||||
 * overlapping block at position (new_row, new_col) (in pixels, Q3). The
 | 
			
		||||
 * first block being overlapped in the macroblock has position (first_blk_row,
 | 
			
		||||
 * first_blk_col) in blocks relative the upper-left corner of the image.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
 | 
			
		||||
                               MV_REFERENCE_FRAME ref_frame,
 | 
			
		||||
                               int new_row, int new_col,
 | 
			
		||||
                               int mb_row, int mb_col,
 | 
			
		||||
                               int first_blk_row, int first_blk_col);
 | 
			
		||||
 | 
			
		||||
/* Estimates a motion vector given the overlapping blocks' motion vectors.
 | 
			
		||||
 * Filters out all overlapping blocks which doesn't refer to the correct
 | 
			
		||||
 * reference frame type.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_estimate_mv(const OVERLAP_NODE *overlaps, B_MODE_INFO *bmi,
 | 
			
		||||
                     MV_REFERENCE_FRAME type);
 | 
			
		||||
 | 
			
		||||
/* Estimates all motion vectors for a macroblock given the lists of
 | 
			
		||||
 * overlaps for each block. Decides whether or not the MVs must be clamped.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_estimate_mb_mvs(const B_OVERLAP *block_overlaps,
 | 
			
		||||
                         MODE_INFO *mi,
 | 
			
		||||
                         int mb_to_left_edge,
 | 
			
		||||
                         int mb_to_right_edge,
 | 
			
		||||
                         int mb_to_top_edge,
 | 
			
		||||
                         int mb_to_bottom_edge);
 | 
			
		||||
 | 
			
		||||
/* Estimate all missing motion vectors.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_estimate_missing_mvs(VP8D_COMP *pbi);
 | 
			
		||||
 | 
			
		||||
/* Estimate all missing motion vectors */
 | 
			
		||||
void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
 | 
			
		||||
                                 MODE_INFO *mi, MODE_INFO *prev_mi,
 | 
			
		||||
                                 int mb_rows, int mb_cols,
 | 
			
		||||
                                 unsigned int first_corrupt);
 | 
			
		||||
 | 
			
		||||
/* Functions for spatial MV interpolation */
 | 
			
		||||
 | 
			
		||||
/* Finds the neighboring blocks of a macroblocks. In the general case
 | 
			
		||||
 * 20 blocks are found. If a fewer number of blocks are found due to
 | 
			
		||||
 * image boundaries, those positions in the EC_BLOCK array are left "empty".
 | 
			
		||||
 * The neighbors are enumerated with the upper-left neighbor as the first
 | 
			
		||||
 * element, the second element refers to the neighbor to right of the previous
 | 
			
		||||
 * neighbor, and so on. The last element refers to the neighbor below the first
 | 
			
		||||
 * neighbor.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_find_neighboring_blocks(MODE_INFO *mi,
 | 
			
		||||
                                 EC_BLOCK *neighbors,
 | 
			
		||||
                                 int mb_row, int mb_col,
 | 
			
		||||
                                 int mb_rows, int mb_cols,
 | 
			
		||||
                                 int mi_stride);
 | 
			
		||||
 | 
			
		||||
/* Calculates which reference frame type is dominating among the neighbors */
 | 
			
		||||
MV_REFERENCE_FRAME vp8_dominant_ref_frame(EC_BLOCK *neighbors);
 | 
			
		||||
 | 
			
		||||
/* Interpolates all motion vectors for a macroblock from the neighboring blocks'
 | 
			
		||||
 * motion vectors.
 | 
			
		||||
 */
 | 
			
		||||
void vp8_interpolate_mvs(MACROBLOCKD *mb,
 | 
			
		||||
                         EC_BLOCK *neighbors,
 | 
			
		||||
                         MV_REFERENCE_FRAME dom_ref_frame);
 | 
			
		||||
 | 
			
		||||
/* Interpolates all motion vectors for a macroblock mb at position
 | 
			
		||||
 * (mb_row, mb_col). */
 | 
			
		||||
void vp8_interpolate_motion(MACROBLOCKD *mb,
 | 
			
		||||
                            int mb_row, int mb_col,
 | 
			
		||||
                            int mb_rows, int mb_cols,
 | 
			
		||||
                            int mi_stride);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -135,6 +135,13 @@ VP8D_PTR vp8dx_create_decompressor(VP8D_CONFIG *oxcf)
 | 
			
		||||
    vp8_init_detokenizer(pbi);
 | 
			
		||||
#endif
 | 
			
		||||
    pbi->common.error.setjmp = 0;
 | 
			
		||||
 | 
			
		||||
#if CONFIG_ERROR_CONCEALMENT
 | 
			
		||||
    pbi->ec_enabled = 1;
 | 
			
		||||
#else
 | 
			
		||||
    pbi->ec_enabled = 0;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    return (VP8D_PTR) pbi;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -150,6 +157,7 @@ void vp8dx_remove_decompressor(VP8D_PTR ptr)
 | 
			
		||||
    if (pbi->b_multithreaded_rd)
 | 
			
		||||
        vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
 | 
			
		||||
#endif
 | 
			
		||||
    vp8_de_alloc_overlap_lists(pbi);
 | 
			
		||||
    vp8_decoder_remove_threads(pbi);
 | 
			
		||||
    vp8_remove_common(&pbi->common);
 | 
			
		||||
    vpx_free(pbi);
 | 
			
		||||
@@ -338,11 +346,14 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
 | 
			
		||||
        */
 | 
			
		||||
        cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
 | 
			
		||||
 | 
			
		||||
        /* Signal that we have no frame to show. */
 | 
			
		||||
        cm->show_frame = 0;
 | 
			
		||||
        if (!pbi->ec_enabled)
 | 
			
		||||
        {
 | 
			
		||||
            /* Signal that we have no frame to show. */
 | 
			
		||||
            cm->show_frame = 0;
 | 
			
		||||
 | 
			
		||||
        /* Nothing more to do. */
 | 
			
		||||
        return 0;
 | 
			
		||||
            /* Nothing more to do. */
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -407,6 +418,16 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
 | 
			
		||||
        return retcode;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* copy mode info to storage for future error concealment */
 | 
			
		||||
    if (pbi->common.prev_mip)
 | 
			
		||||
    {
 | 
			
		||||
        /* size allocated in vp8_alloc_frame_buffers() */
 | 
			
		||||
        int size_of_mip = (pbi->common.mb_cols + 1) * (pbi->common.mb_rows + 1)
 | 
			
		||||
            * sizeof(MODE_INFO);
 | 
			
		||||
 | 
			
		||||
        memcpy(pbi->common.prev_mip, pbi->common.mip, size_of_mip);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (pbi->b_multithreaded_rd && cm->multi_token_partition != ONE_PARTITION)
 | 
			
		||||
    {
 | 
			
		||||
        if (swap_frame_buffers (cm))
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@
 | 
			
		||||
#include "onyxc_int.h"
 | 
			
		||||
#include "threading.h"
 | 
			
		||||
#include "dequantize.h"
 | 
			
		||||
#include "ec_types.h"
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
@@ -134,6 +135,10 @@ typedef struct VP8Decompressor
 | 
			
		||||
    vp8_prob prob_gf;
 | 
			
		||||
    vp8_prob prob_skip_false;
 | 
			
		||||
 | 
			
		||||
    MB_OVERLAP *overlaps;
 | 
			
		||||
    unsigned int mvs_corrupt_from_mb;
 | 
			
		||||
    int ec_enabled;
 | 
			
		||||
 | 
			
		||||
} VP8D_COMP;
 | 
			
		||||
 | 
			
		||||
int vp8_decode_frame(VP8D_COMP *cpi);
 | 
			
		||||
 
 | 
			
		||||
@@ -56,12 +56,14 @@ VP8_DX_SRCS-yes += decoder/decodemv.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/decodframe.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/dequantize.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/detokenize.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/error_concealment.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/generic/dsystemdependent.c
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/dboolhuff.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/decodemv.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/decoderthreading.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/dequantize.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/detokenize.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/error_concealment.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/onyxd_int.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/treereader.h
 | 
			
		||||
VP8_DX_SRCS-yes += decoder/onyxd_if.c
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user