Compare commits

...

13 commits

236 changed files with 59184 additions and 60744 deletions

View file

@ -0,0 +1,46 @@
name: Test openperf
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
checkout_repos:
runs-on: nix
strategy:
matrix:
arch: ["native"] # Define architectures here
test_name: ["stream"] # Define test names here
steps:
- name: Checkout Main Repo (openperf)
uses: actions/checkout@v4
with:
repository: openperf/openperf
path: openperf
- name: Checkout Abstract Machine Repo
uses: actions/checkout@v4
with:
repository: openperf/abstract-machine
path: abstract-machine
- name: Checkout Nemu Repo
uses: actions/checkout@v4
with:
repository: openperf/nemu
path: nemu
- name: Build and Run with Matrix
working-directory: openperf
env:
AM_HOME: "${{ github.workspace }}/abstract-machine"
NEMU_HOME: "${{ github.workspace }}/nemu"
run: |
nix develop .#native --impure --command make ARCH=${{ matrix.arch }} ALL=${{ matrix.test_name }} run

2
.gitignore vendored
View file

@ -17,4 +17,4 @@ _*
build/ build/
!.gitignore !.gitignore
.vscode .vscode
!mersenne-riscv32e.bin abstract-machine/

View file

@ -1,7 +1,7 @@
BENCH_LIBS := bench openlibm soft-fp BENCH_LIBS := bench openlibm soft-fp
$(BENCH_LIBS): %: latest $(BENCH_LIBS): %:
$(MAKE) -s -C ./src/common/$* archive $(MAKE) -s -C ./src/common/$* archive
COLOR_RED = \033[1;31m COLOR_RED = \033[1;31m
@ -11,38 +11,78 @@ COLOR_NONE = \033[0m
RESULT = .result RESULT = .result
$(shell > $(RESULT)) $(shell > $(RESULT))
ALL = cpuemu mcf x264 tcc stream linpack gemm whetstone KEEP_LOG_FAILED ?= true
KEEP_LOG_SUCCEED ?= false
TIME := $(shell date --iso=seconds)
ALL = mcf x264 tcc stream linpack gemm whetstone
all: $(BENCH_LIBS) $(ALL) all: $(BENCH_LIBS) $(ALL)
@echo "test list [$(words $(ALL)) item(s)]:" $(ALL) @echo "OpenPerf [$(words $(ALL)) item(s)]:" $(ALL)
@if [ -z "$(mainargs)" ]; then \
echo "Empty mainargs, use \"ref\" by default"; \
echo "====== Running OpenPerf [input *ref*] ======"; \
else \
echo "====== Running OpenPerf [input *$${mainargs}*] ======"; \
fi
$(ALL): %: $(BENCH_LIBS) latest $(ALL): %: $(BENCH_LIBS)
@{\ @{\
TMP=$*.tmp;\ TMP=$*.tmp;\
make -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\ $(MAKE) -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\
if [ $${PIPESTATUS[0]} -eq 0 ]; then \ if [ $${PIPESTATUS[0]} -eq 0 ]; then \
printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE) " $* >> $(RESULT); \ printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE) " $* >> $(RESULT); \
cat $$TMP | grep -E -i -e "time: ([0-9]*\.)?[0-9]* ms" >> $(RESULT); \ cat $$TMP | grep -E -i -e "OpenPerf time: ([0-9]*\.)?[0-9]*" >> $(RESULT); \
rm $$TMP;\ if $(KEEP_LOG_SUCCEED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
else \ else \
printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $* >> $(RESULT); \ printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $* >> $(RESULT); \
rm $$TMP; \ if $(KEEP_LOG_FAILED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
fi \ fi \
} }
run: $(BENCH_LIBS) all run: $(BENCH_LIBS) all
@cat $(RESULT) @cat $(RESULT)
@cat $(RESULT) | grep -E -o "time: ([0-9]*\.[0-9]*) ms" | awk '{sum += $$2} END {print sum " ms"}' @echo "============================================="
@if grep -q -i -e "fail" "$(RESULT)"; then \
echo "OpenPerf FAIL"; \
else \
echo "OpenPerf PASS"; \
fi
@awk '\
{ \
h = min = s = ms = us = 0;\
if (match($$0, /([0-9]+) h/, arr)) h = arr[1]; \
if (match($$0, /([0-9]+) min/, arr)) min = arr[1]; \
if (match($$0, /([0-9]+) s/, arr)) s = arr[1]; \
if (match($$0, /([0-9]+)\.([0-9]*) ms/, arr)) {ms = arr[1]; us = arr[2]} \
total_ms += h * 3600000 + min * 60000 + s * 1000 + ms; \
} \
END { \
printf "Total time: %d h %d min %d s %d.%d ms\n", \
int(total_ms / 3600000), \
int((total_ms % 3600000) / 60000), \
int((total_ms % 60000) / 1000), \
total_ms % 1000, \
us; \
} \
' $(RESULT)
@rm $(RESULT) @rm $(RESULT)
CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile)) CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile))
clean-all: $(CLEAN_ALL) clean-all: $(CLEAN_ALL)
$(CLEAN_ALL): $(CLEAN_ALL):
-@$(MAKE) -s -C $@ clean -@$(MAKE) -s -C $@ clean
.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all latest .PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all
latest:

View file

@ -1,13 +1,42 @@
#include <am.h> #include <am.h>
#include <klib.h> #include <bench_debug.h>
#include <klib-macros.h> #include <klib-macros.h>
#include <klib.h>
uint64_t uptime() uint64_t uptime() { return (io_read(AM_TIMER_UPTIME).us); }
{
return (io_read(AM_TIMER_UPTIME).us);
}
char *format_time(uint64_t us) { char *format_time(uint64_t us) {
static char buf[128];
uint64_t ms = us / 1000;
uint64_t s = ms / 1000;
uint64_t min = s / 60;
uint64_t h = min / 60;
us %= 1000;
ms %= 1000;
s %= 60;
min %= 60;
int len = 0;
if (h > 0) {
len = bench_sprintf(buf, "%ld h %ld min %ld s %ld.000 ms", h, min, s, ms);
} else if (min > 0) {
len = bench_sprintf(buf, "%ld min %ld s, %ld.000 ms", min, s, ms);
} else if (s > 0) {
len = bench_sprintf(buf, "%ld s, %ld.000 ms", s, ms);
} else {
len = bench_sprintf(buf, "%ld.000 ms", ms);
}
char *p = &buf[len - 4];
while (us > 0) {
*(p--) = '0' + us % 10;
us /= 10;
}
return buf;
}
/* char *format_time(uint64_t us) {
static char buf[32]; static char buf[32];
uint64_t ms = us / 1000; uint64_t ms = us / 1000;
us -= ms * 1000; us -= ms * 1000;
@ -19,14 +48,14 @@ char *format_time(uint64_t us) {
us /= 10; us /= 10;
} }
return buf; return buf;
} } */
// FNV hash // FNV hash
uint32_t checksum(void *start, void *end) { uint32_t checksum(void *start, void *end) {
const uint32_t x = 16777619; const uint32_t x = 16777619;
uint32_t h1 = 2166136261u; uint32_t h1 = 2166136261u;
for (uint8_t *p = (uint8_t*)start; p + 4 < (uint8_t*)end; p += 4) { for (uint8_t *p = (uint8_t *)start; p + 4 < (uint8_t *)end; p += 4) {
for (int i = 0; i < 4; i ++) { for (int i = 0; i < 4; i++) {
h1 = (h1 ^ p[i]) * x; h1 = (h1 ^ p[i]) * x;
} }
} }

View file

@ -0,0 +1,438 @@
#include <am.h>
#include <klib-macros.h>
#include <klib.h>
#include <stdarg.h>
#define ZEROPAD 1
#define SIGN 2
#define PLUS 4
#define SPACE 8
#define LEFT 16
#define SPECIAL 32
#define LARGE 64
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define SZ_NUM_BUF 32
static char sprint_fe[SZ_NUM_BUF + 1];
#define PRINT_BUF_SIZE 512
static const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static const char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static size_t strnlen(const char *s, size_t count) {
const char *sc;
for (sc = s; *sc != '\0' && count--; ++sc)
;
return sc - s;
}
static int skip_atoi(const char **s) {
int i = 0;
while (is_digit(**s))
i = i * 10 + *((*s)++) - '0';
return i;
}
static char *number(char *str, long num, int base, int size, int precision,
int type) {
char c, sign, tmp[66];
const char *dig = digits;
int i;
if (type & LARGE)
dig = upper_digits;
if (type & LEFT)
type &= ~ZEROPAD;
if (base < 2 || base > 36)
return 0;
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN) {
if (num < 0) {
sign = '-';
num = -num;
size--;
} else if (type & PLUS) {
sign = '+';
size--;
} else if (type & SPACE) {
sign = ' ';
size--;
}
}
if (type & SPECIAL) {
if (base == 16)
size -= 2;
else if (base == 8)
size--;
}
i = 0;
if (num == 0)
tmp[i++] = '0';
else {
while (num != 0) {
tmp[i++] = dig[((unsigned long)num) % (unsigned)base];
num = ((unsigned long)num) / (unsigned)base;
}
}
if (i > precision)
precision = i;
size -= precision;
if (!(type & (ZEROPAD | LEFT)))
while (size-- > 0)
*str++ = ' ';
if (sign)
*str++ = sign;
if (type & SPECIAL) {
if (base == 8)
*str++ = '0'; // 0
else if (base == 16) {
*str++ = '0';
*str++ = digits[33]; // 0x
}
}
if (!(type & LEFT))
while (size-- > 0)
*str++ = c;
while (i < precision--)
*str++ = '0';
while (i-- > 0)
*str++ = tmp[i];
while (size-- > 0)
*str++ = ' ';
return str;
}
static int ilog10(double n) {
int rv = 0;
while (n >= 10) {
if (n >= 100000) {
n /= 100000;
rv += 5;
} else {
n /= 10;
rv++;
}
}
while (n < 1) {
if (n < 0.00001) {
n *= 100000;
rv -= 5;
} else {
n *= 10;
rv--;
}
}
return rv;
}
static double i10x(int n) {
double rv = 1;
while (n > 0) {
if (n >= 5) {
rv *= 100000;
n -= 5;
} else {
rv *= 10;
n--;
}
}
while (n < 0) { /* Right shift */
if (n <= -5) {
rv /= 100000;
n += 5;
} else {
rv /= 10;
n++;
}
}
return rv;
}
static void ftoa(char *buf, double val, int prec, char fmt) {
int d;
int e = 0, m = 0;
char sign = 0;
double w;
const char *er = 0;
const char ds = '.';
unsigned int *pu = (unsigned int *)&val;
if (((pu[1] & 0x7ff00000) == 0x7ff00000) &&
(((pu[1] & 0xfffff) != 0) || (pu[0] != 0))) {
er = "NaN";
} else {
if (prec < 0)
prec = 6;
if (val < 0) {
val = 0 - val;
sign = '-';
} else {
sign = '+';
}
if (((pu[1] & 0x7fffffff) == 0x7ff00000) && (pu[0] == 0)) {
er = "INF";
} else {
if (fmt == 'f') {
val += i10x(0 - prec) / 2;
m = ilog10(val);
if (m < 0)
m = 0;
if (m + prec + 3 >= SZ_NUM_BUF)
er = "OV";
} else {
if (val != 0) {
val += i10x(ilog10(val) - prec) / 2;
e = ilog10(val);
if (e > 99 || prec + 7 >= SZ_NUM_BUF) {
er = "OV";
} else {
if (e < -99)
e = -99;
val /= i10x(e);
}
}
}
}
if (!er) {
if (sign == '-')
*buf++ = sign;
do {
if (m == -1)
*buf++ = ds;
w = i10x(m);
d = (int)(val / w);
val -= d * w;
*buf++ = (char)('0' + d);
} while (--m >= -prec);
if (fmt != 'f') {
*buf++ = (char)fmt;
if (e < 0) {
e = 0 - e;
*buf++ = '-';
} else {
*buf++ = '+';
}
*buf++ = (char)('0' + e / 10);
*buf++ = (char)('0' + e % 10);
}
}
}
if (er) {
if (sign)
*buf++ = sign;
do {
*buf++ = *er++;
} while (*er);
}
*buf = 0;
}
int bench_vsprintf(char *buf, const char *fmt, va_list args) {
int len = 0;
unsigned long long num = 0;
int i = 0, j = 0, base = 0;
char *str;
const char *s;
int flags; /* flags to number() */
int field_width; /* width of output field */
int precision; /* min. # of digits for integers; max number of chars for from
string */
int qualifier; /* 'h', 'l', or 'L' for integer fields */
/* 'z' support added 23/7/1999 S.H. */
/* 'z' changed to 'Z' --davidm 1/25/99 */
for (str = buf; *fmt; ++fmt) {
if (*fmt != '%') {
*str++ = *fmt;
continue;
}
/* flags */
flags = 0;
repeat:
++fmt;
switch (*fmt) {
case '-':
flags |= LEFT;
goto repeat;
case '+':
flags |= PLUS;
goto repeat;
case ' ':
flags |= SPACE;
goto repeat;
case '#':
flags |= SPECIAL;
goto repeat;
case '0':
flags |= ZEROPAD;
goto repeat;
}
field_width = -1;
if ('0' <= *fmt && *fmt <= '9')
field_width = skip_atoi(&fmt);
else if (*fmt == '*') {
++fmt; /*skip '*' */
/* it's the next argument */
field_width = va_arg(args, int);
if (field_width < 0) {
field_width = -field_width;
flags |= LEFT;
}
}
precision = -1;
if (*fmt == '.') {
++fmt;
if ('0' <= *fmt && *fmt <= '9')
precision = skip_atoi(&fmt);
else if (*fmt == '*') {
++fmt;
/* it's the next argument */
precision = va_arg(args, int);
}
if (precision < 0)
precision = 0;
}
qualifier = -1;
if (*fmt == 'l' && *(fmt + 1) == 'l') {
qualifier = 'q';
fmt += 2;
} else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') {
qualifier = *fmt;
++fmt;
}
/* default base */
base = 10;
switch (*fmt) {
case 'c':
if (!(flags & LEFT))
while (--field_width > 0)
*str++ = ' ';
*str++ = (unsigned char)va_arg(args, int);
while (--field_width > 0)
*str++ = ' ';
continue;
case 's':
s = va_arg(args, char *);
if (!s)
s = "";
len = strnlen(s, precision);
if (!(flags & LEFT))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
case 'p':
if (field_width == -1) {
field_width = 2 * sizeof(void *);
flags |= ZEROPAD;
}
str = number(str, (unsigned long)va_arg(args, void *), 16, field_width,
precision, flags);
continue;
case 'n':
if (qualifier == 'l') {
long *ip = va_arg(args, long *);
*ip = (str - buf);
} else if (qualifier == 'Z') {
size_t *ip = va_arg(args, size_t *);
*ip = (str - buf);
} else {
int *ip = va_arg(args, int *);
*ip = (str - buf);
}
continue;
case 'f': /* Floating point (decimal) */
case 'e': /* Floating point (e) */
case 'E': /* Floating point (E) */
ftoa(sprint_fe, va_arg(args, double), precision, *fmt); /* 浮点转字符串*/
if (!(flags & LEFT)) {
for (j = strnlen(sprint_fe, SZ_NUM_BUF); j < field_width; j++)
*str++ = ' ';
}
i = 0;
while (sprint_fe[i])
*str++ = sprint_fe[i++]; /* 主体 */
while (j++ < field_width)
*str++ = ' ';
continue;
case '%':
*str++ = '%';
continue;
case 'o':
base = 8;
break;
case 'X':
flags |= LARGE;
case 'x':
base = 16;
break;
case 'd':
case 'i':
flags |= SIGN;
case 'u':
break;
default:
*str++ = '%';
if (*fmt)
*str++ = *fmt;
else
--fmt;
continue;
}
if (qualifier == 'l') {
num = va_arg(args, unsigned long);
if (flags & SIGN)
num = (signed long)num;
} else if (qualifier == 'q') {
num = va_arg(args, unsigned long long);
if (flags & SIGN)
num = (signed long long)num;
} else if (qualifier == 'Z') {
num = va_arg(args, size_t);
} else if (qualifier == 'h') {
num = (unsigned short)va_arg(args, int);
if (flags & SIGN)
num = (signed short)num;
} else {
num = va_arg(args, unsigned int);
if (flags & SIGN)
num = (signed int)num;
}
str = number(str, num, base, field_width, precision, flags);
}
*str = '\0';
return str - buf;
}
int bench_sprintf(char *s, const char *fmt, ...) {
va_list arg;
va_start(arg, fmt);
int length = bench_vsprintf(s, fmt, arg);
va_end(arg);
return length;
}
int bench_printf(const char *fmt, ...) {
char s[PRINT_BUF_SIZE];
va_list arg;
va_start(arg, fmt);
int length = bench_vsprintf(s, fmt, arg);
va_end(arg);
for (int i = 0; s[i] != '\0'; i++) {
putch(s[i]);
}
return length;
}

View file

@ -1,6 +1,6 @@
#include <am.h>
#include <bench_malloc.h> #include <bench_malloc.h>
#include <klib.h> #include <klib.h>
#include <am.h>
#include <stdint.h> #include <stdint.h>
static intptr_t program_break = 0; static intptr_t program_break = 0;
@ -21,139 +21,136 @@ static void *sbrk(intptr_t increment) {
// } // }
static inline size_t word_align(size_t size) { static inline size_t word_align(size_t size) {
return ( size + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1); return (size + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1);
} }
struct chunk { struct chunk {
struct chunk *next, *prev; struct chunk *next, *prev;
size_t size; size_t size;
size_t free; size_t free;
void *data; void *data;
}; };
typedef struct chunk *Chunk; typedef struct chunk *Chunk;
static void *malloc_base() { static void *malloc_base() {
static Chunk b = NULL; static Chunk b = NULL;
if (!b) { if (!b) {
b = sbrk(word_align(sizeof(struct chunk))); b = sbrk(word_align(sizeof(struct chunk)));
if (b == (void*) -1) { if (b == (void *)-1) {
// _exit(127); // _exit(127);
assert(0); assert(0);
}
b->next = NULL;
b->prev = NULL;
b->size = 0;
b->free = 0;
b->data = NULL;
} }
return b; b->next = NULL;
b->prev = NULL;
b->size = 0;
b->free = 0;
b->data = NULL;
}
return b;
} }
//We need this function because we use variable `heap` // We need this function because the variable `heap` is used
//and it is initialized in run time. // and initialized at runtime.
void bench_malloc_init() { void bench_malloc_init() { program_break = (intptr_t)heap.start; }
program_break = (intptr_t)heap.start;
}
static Chunk malloc_chunk_find(size_t s, Chunk *heap) { static Chunk malloc_chunk_find(size_t s, Chunk *heap) {
Chunk c = malloc_base(); Chunk c = malloc_base();
for (; c && (!c->free || c->size < s); *heap = c, c = c->next); for (; c && (!c->free || c->size < s); *heap = c, c = c->next)
return c; ;
return c;
} }
static void malloc_merge_next(Chunk c) { static void malloc_merge_next(Chunk c) {
c->size = c->size + c->next->size + sizeof(struct chunk); c->size = c->size + c->next->size + sizeof(struct chunk);
c->next = c->next->next; c->next = c->next->next;
if (c->next) { if (c->next) {
c->next->prev = c; c->next->prev = c;
} }
} }
static void malloc_split_next(Chunk c, size_t size) { static void malloc_split_next(Chunk c, size_t size) {
Chunk newc = (Chunk)((char*) c + size); Chunk newc = (Chunk)((char *)c + size);
newc->prev = c; newc->prev = c;
newc->next = c->next; newc->next = c->next;
newc->size = c->size - size; newc->size = c->size - size;
newc->free = 1; newc->free = 1;
newc->data = newc + 1; newc->data = newc + 1;
if (c->next) { if (c->next) {
c->next->prev = newc; c->next->prev = newc;
} }
c->next = newc; c->next = newc;
c->size = size - sizeof(struct chunk); c->size = size - sizeof(struct chunk);
} }
void *bench_malloc(size_t size) { void *bench_malloc(size_t size) {
if (!size) return NULL; if (!size)
size_t length = word_align(size + sizeof(struct chunk)); return NULL;
Chunk prev = NULL; size_t length = word_align(size + sizeof(struct chunk));
Chunk c = malloc_chunk_find(size, &prev); Chunk prev = NULL;
if (!c) { Chunk c = malloc_chunk_find(size, &prev);
Chunk newc = sbrk(length); if (!c) {
if (newc == (void*) -1) { Chunk newc = sbrk(length);
return NULL; if (newc == (void *)-1) {
} return NULL;
newc->next = NULL;
newc->prev = prev;
newc->size = length - sizeof(struct chunk);
newc->data = newc + 1;
prev->next = newc;
c = newc;
} else if (length + sizeof(size_t) < c->size) {
malloc_split_next(c, length);
} }
c->free = 0; newc->next = NULL;
return c->data; newc->prev = prev;
newc->size = length - sizeof(struct chunk);
newc->data = newc + 1;
prev->next = newc;
c = newc;
} else if (length + sizeof(size_t) < c->size) {
malloc_split_next(c, length);
}
c->free = 0;
return c->data;
} }
void bench_free(void *ptr) { void bench_free(void *ptr) {
if (!ptr || ptr < malloc_base() || ptr > sbrk(0)) return; if (!ptr || ptr < malloc_base() || ptr > sbrk(0))
Chunk c = (Chunk) ptr - 1; return;
if (c->data != ptr) return; Chunk c = (Chunk)ptr - 1;
c->free = 1; if (c->data != ptr)
return;
c->free = 1;
if (c->next && c->next->free) { if (c->next && c->next->free) {
malloc_merge_next(c); malloc_merge_next(c);
} }
if (c->prev->free) { if (c->prev->free) {
malloc_merge_next(c = c->prev); malloc_merge_next(c = c->prev);
} }
if (!c->next) { if (!c->next) {
c->prev->next = NULL; c->prev->next = NULL;
sbrk(- c->size - sizeof(struct chunk)); sbrk(-c->size - sizeof(struct chunk));
} }
} }
void *bench_calloc(size_t nmemb, size_t size) { void *bench_calloc(size_t nmemb, size_t size) {
size_t length = nmemb * size; size_t length = nmemb * size;
void *ptr = bench_malloc(length); void *ptr = bench_malloc(length);
if (ptr) { if (ptr) {
char *dst = ptr; char *dst = ptr;
for (size_t i = 0; i < length; *dst = 0, ++dst, ++i); for (size_t i = 0; i < length; *dst = 0, ++dst, ++i)
} ;
return ptr; }
return ptr;
} }
void *bench_realloc(void *ptr, size_t size) { void *bench_realloc(void *ptr, size_t size) {
void *newptr = bench_malloc(size); void *newptr = bench_malloc(size);
if (newptr && ptr && ptr >= malloc_base() && ptr <= sbrk(0)) { if (newptr && ptr && ptr >= malloc_base() && ptr <= sbrk(0)) {
Chunk c = (Chunk) ptr - 1; Chunk c = (Chunk)ptr - 1;
if (c->data == ptr) { if (c->data == ptr) {
size_t length = c->size > size ? size : c->size; size_t length = c->size > size ? size : c->size;
char *dst = newptr, *src = ptr; char *dst = newptr, *src = ptr;
for (size_t i = 0; i < length; *dst = *src, ++src, ++dst, ++i); for (size_t i = 0; i < length; *dst = *src, ++src, ++dst, ++i)
bench_free(ptr); ;
} bench_free(ptr);
} }
return newptr; }
return newptr;
} }
void bench_all_free() { void bench_all_free() { program_break = (intptr_t)heap.start; }
program_break = (intptr_t)heap.start;
}

View file

@ -1,456 +1,418 @@
#include <klib.h>
#include <bench_malloc.h> #include <bench_malloc.h>
#include <klib.h>
#define __tolower(c) ((('A' <= (c)) && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))
#define __tolower(c) ((('A' <= (c))&&((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c)) int strcasecmp(const char *s1, const char *s2) {
int strcasecmp(const char *s1, const char *s2) if (s1 == NULL || s2 == NULL)
{
if(s1 == NULL || s2 == NULL)
return 0; return 0;
while((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2))) while ((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2))) {
{ s1++;
s1++; s2++; s2++;
} }
return (*s1 - *s2); return (*s1 - *s2);
} }
int strncasecmp(const char *s1, const char *s2, size_t n) int strncasecmp(const char *s1, const char *s2, size_t n) {
{ if (s1 == NULL || s2 == NULL)
if(s1 == NULL || s2 == NULL)
return 0; return 0;
while((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2)) && (n > 1)) while ((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2)) && (n > 1)) {
{ s1++;
s1++; s2++; s2++;
n--; n--;
} }
return (*s1 - *s2); return (*s1 - *s2);
} }
char* strdup(const char* str) char *strdup(const char *str) {
{ if (str == NULL)
if(str == NULL)
return NULL; return NULL;
char* strat = (char*)str; char *strat = (char *)str;
int len = 0; int len = 0;
while (*str++ != '\0') while (*str++ != '\0')
len++; len++;
char* ret = (char*)bench_malloc(len + 1); char *ret = (char *)bench_malloc(len + 1);
while ((*ret++ = *strat++) != '\0') while ((*ret++ = *strat++) != '\0') {
{} }
return ret - (len + 1); return ret - (len + 1);
} }
size_t strspn(const char *str, const char *group) size_t strspn(const char *str, const char *group) {
{ const char *p = NULL;
const char *p = NULL; const char *a = NULL;
const char *a = NULL; size_t count = 0;
size_t count = 0;
for (p = str; *p != '\0'; ++p) for (p = str; *p != '\0'; ++p) {
{ for (a = group; *a != '\0'; ++a) {
for (a = group; *a != '\0'; ++a) if (*p == *a) {
{ ++count;
if (*p == *a) break;
{ }
++count; }
break;
}
}
if (*a == '\0') if (*a == '\0') {
{ return count;
return count; }
} }
}
return count; return count;
} }
size_t strcspn ( const char * str1, const char * str2 ) { size_t strcspn(const char *str1, const char *str2) {
char *p1 = (char *)str1; char *p1 = (char *)str1;
char *p2; char *p2;
while (*p1 != '\0') { while (*p1 != '\0') {
p2 = (char *)str2; p2 = (char *)str2;
while (*p2 != '\0') { while (*p2 != '\0') {
if (*p2 == *p1) return p1-str1; if (*p2 == *p1)
++p2; return p1 - str1;
++p2;
} }
++p1; ++p1;
} }
return p1 - str1; return p1 - str1;
} }
unsigned long strtoul(const char *pstart, char **pend, int base) unsigned long strtoul(const char *pstart, char **pend, int base) {
{ const char *s = pstart;
const char *s = pstart; unsigned long result = 0;
unsigned long result = 0; char c;
char c;
assert (base > 2 && base < 36); assert(base > 2 && base < 36);
do { do {
c = *s++; c = *s++;
} while (c == ' '); } while (c == ' ');
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
c = *s++; c = *s++;
} }
if ((base == 0 || base == 16) && if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') &&
c == '0' && (*s == 'x' || *s == 'X') && ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') ||
((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'a' && s[1] <= 'f'))) {
(s[1] >= 'A' && s[1] <= 'F') || c = s[1];
(s[1] >= 'a' && s[1] <= 'f'))) { s += 2;
c = s[1]; base = 16;
s += 2; }
base = 16;
}
if (base == 0) { if (base == 0) {
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
} }
for ( ; *s; c = *s++) { for (; *s; c = *s++) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
c -= '0'; c -= '0';
} else if (c >= 'A' && c <= 'Z') { } else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 10; c -= 'A' - 10;
} else if (c >= 'a' && c <= 'z') { } else if (c >= 'a' && c <= 'z') {
c -= 'a' - 10; c -= 'a' - 10;
} else { } else {
break; break;
} }
result *= base; result *= base;
result += c; result += c;
}
if (pend != NULL) {
*pend = (char *)(s - 1);
} }
return result; if (pend != NULL) {
*pend = (char *)(s - 1);
}
return result;
} }
unsigned long long strtoull(const char *pstart, char **pend, int base) unsigned long long strtoull(const char *pstart, char **pend, int base) {
{ const char *s = pstart;
const char *s = pstart; unsigned long long result = 0;
unsigned long long result = 0; char c;
char c;
assert (base > 2 && base < 36); assert(base > 2 && base < 36);
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
c = *s++; c = *s++;
} }
if ((base == 0 || base == 16) && if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') &&
c == '0' && (*s == 'x' || *s == 'X') && ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') ||
((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'a' && s[1] <= 'f'))) {
(s[1] >= 'A' && s[1] <= 'F') || c = s[1];
(s[1] >= 'a' && s[1] <= 'f'))) { s += 2;
c = s[1]; base = 16;
s += 2; }
base = 16;
}
if (base == 0) { if (base == 0) {
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
} }
for ( ; *s; c = *s++) { for (; *s; c = *s++) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
c -= '0'; c -= '0';
} else if (c >= 'A' && c <= 'Z') { } else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 10; c -= 'A' - 10;
} else if (c >= 'a' && c <= 'z') { } else if (c >= 'a' && c <= 'z') {
c -= 'a' - 10; c -= 'a' - 10;
} else { } else {
break; break;
} }
result *= base; result *= base;
result += c; result += c;
}
if (pend != NULL) {
*pend = (char *)(s - 1);
} }
return result; if (pend != NULL) {
*pend = (char *)(s - 1);
}
return result;
} }
long strtol(const char *pstart, char **pend, int base) long strtol(const char *pstart, char **pend, int base) {
{ const char *s = pstart;
const char *s = pstart; long result = 0;
long result = 0; char c;
char c;
long sign = 1; long sign = 1;
assert (base > 2 && base < 36); assert(base > 2 && base < 36);
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
sign = (c == '-') ? -1: 1; sign = (c == '-') ? -1 : 1;
c = *s++; c = *s++;
} }
if ((base == 0 || base == 16) && if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') &&
c == '0' && (*s == 'x' || *s == 'X') && ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') ||
((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'a' && s[1] <= 'f'))) {
(s[1] >= 'A' && s[1] <= 'F') || c = s[1];
(s[1] >= 'a' && s[1] <= 'f'))) { s += 2;
c = s[1]; base = 16;
s += 2; }
base = 16;
}
if (base == 0) { if (base == 0) {
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
} }
for ( ; *s; c = *s++) { for (; *s; c = *s++) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
c -= '0'; c -= '0';
} else if (c >= 'A' && c <= 'Z') { } else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 10; c -= 'A' - 10;
} else if (c >= 'a' && c <= 'z') { } else if (c >= 'a' && c <= 'z') {
c -= 'a' - 10; c -= 'a' - 10;
} else { } else {
break; break;
} }
result *= base; result *= base;
result += c; result += c;
}
if (pend != NULL) {
*pend = (char *)(s - 1);
} }
return sign * result; if (pend != NULL) {
*pend = (char *)(s - 1);
}
return sign * result;
} }
long long strtoll(const char *pstart, char **pend, int base) long long strtoll(const char *pstart, char **pend, int base) {
{ const char *s = pstart;
const char *s = pstart; long long result = 0;
long long result = 0; char c;
char c;
long long sign = 1; long long sign = 1;
assert (base > 2 && base < 36); assert(base > 2 && base < 36);
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
sign = (c == '-') ? -1: 1; sign = (c == '-') ? -1 : 1;
c = *s++; c = *s++;
} }
if ((base == 0 || base == 16) && if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') &&
c == '0' && (*s == 'x' || *s == 'X') && ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') ||
((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'a' && s[1] <= 'f'))) {
(s[1] >= 'A' && s[1] <= 'F') || c = s[1];
(s[1] >= 'a' && s[1] <= 'f'))) { s += 2;
c = s[1]; base = 16;
s += 2; }
base = 16;
}
if (base == 0) { if (base == 0) {
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
} }
for ( ; *s; c = *s++) { for (; *s; c = *s++) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
c -= '0'; c -= '0';
} else if (c >= 'A' && c <= 'Z') { } else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 10; c -= 'A' - 10;
} else if (c >= 'a' && c <= 'z') { } else if (c >= 'a' && c <= 'z') {
c -= 'a' - 10; c -= 'a' - 10;
} else { } else {
break; break;
} }
result *= base; result *= base;
result += c; result += c;
}
if (pend != NULL) {
*pend = (char *)(s - 1);
} }
return sign * result; if (pend != NULL) {
*pend = (char *)(s - 1);
}
return sign * result;
} }
double strtod(const char *pstart, char **pend) double strtod(const char *pstart, char **pend) {
{ const char *s = pstart;
const char *s = pstart; double result = 0;
double result = 0; char c;
char c;
double sign = 1.0; double sign = 1.0;
double frac = 0.1; double frac = 0.1;
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
sign = (c == '-') ? -1.0 : 1.0; sign = (c == '-') ? -1.0 : 1.0;
c = *s++;
}
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
}
if(c == '.') {
c = *s++; c = *s++;
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
} }
if (pend != NULL) { for (;; c = *s++) {
*pend = (char *)(s - 1); if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
} }
return (sign * result); if (c == '.') {
c = *s++;
for (;; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
}
if (pend != NULL) {
*pend = (char *)(s - 1);
}
return (sign * result);
} }
long double strtold(const char *pstart, char **pend) long double strtold(const char *pstart, char **pend) {
{ const char *s = pstart;
const char *s = pstart; long double result = 0;
long double result = 0; char c;
char c;
long double sign = 1.0; long double sign = 1.0;
long double frac = 0.1; long double frac = 0.1;
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
sign = (c == '-') ? -1.0 : 1.0; sign = (c == '-') ? -1.0 : 1.0;
c = *s++;
}
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
}
if(c == '.') {
c = *s++; c = *s++;
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
} }
if (pend != NULL) { for (;; c = *s++) {
*pend = (char *)(s - 1); if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
} }
return (sign * result); if (c == '.') {
c = *s++;
for (;; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
}
if (pend != NULL) {
*pend = (char *)(s - 1);
}
return (sign * result);
} }
float strtof(const char *pstart, char **pend) float strtof(const char *pstart, char **pend) {
{ const char *s = pstart;
const char *s = pstart; float result = 0;
float result = 0; char c;
char c;
float sign = 1.0; float sign = 1.0;
float frac = 0.1; float frac = 0.1;
do { do {
c = *s++; c = *s++;
} while ((c == ' ')); } while ((c == ' '));
if (c == '-' || c == '+'){ if (c == '-' || c == '+') {
sign = (c == '-') ? -1.0 : 1.0; sign = (c == '-') ? -1.0 : 1.0;
c = *s++;
}
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
}
if(c == '.') {
c = *s++; c = *s++;
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
} }
if (pend != NULL) { for (;; c = *s++) {
*pend = (char *)(s - 1); if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result *= 10;
result += c;
} }
return (sign * result); if (c == '.') {
c = *s++;
for (;; c = *s++) {
if (c >= '0' && c <= '9') {
c -= '0';
} else {
break;
}
result += c * frac;
frac *= 0.1;
}
}
if (pend != NULL) {
*pend = (char *)(s - 1);
}
return (sign * result);
} }
char *strchr(const char *s, const char ch) char *strchr(const char *s, const char ch) {
{
if (NULL == s) if (NULL == s)
return NULL; return NULL;
const char *pSrc = s; const char *pSrc = s;
while ('\0' != *pSrc) while ('\0' != *pSrc) {
{ if (*pSrc == ch) {
if (*pSrc == ch)
{
return (char *)pSrc; return (char *)pSrc;
} }
pSrc++; pSrc++;
} }
if(ch == 0) if (ch == 0) {
{
return (char *)pSrc; return (char *)pSrc;
} }
return NULL; return NULL;
} }
char *strrchr(const char *s, const char ch) char *strrchr(const char *s, const char ch) {
{ if (s == NULL) {
if(s == NULL) return NULL;
{
return NULL;
} }
char *p_char = NULL; char *p_char = NULL;
while(*s != '\0') while (*s != '\0') {
{ if (*s == ch) {
if(*s == ch) p_char = (char *)s;
{
p_char = (char *)s;
} }
s++; s++;
} }
if(ch == 0) if (ch == 0) {
{
p_char = (char *)s; p_char = (char *)s;
} }
return p_char; return p_char;
} }
char* strstr(const char* dest, const char* src) char *strstr(const char *dest, const char *src) { assert(0); }
{
assert(0);
}

View file

@ -1,8 +1,8 @@
#ifndef __BENCH_COMMON #ifndef __BENCH_COMMON
#define __BENCH_COMMON #define __BENCH_COMMON
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
uint64_t uptime(); uint64_t uptime();
char *format_time(uint64_t us); char *format_time(uint64_t us);
@ -14,6 +14,6 @@ typedef struct {
uint64_t ref_time; uint64_t ref_time;
uint32_t checksum; uint32_t checksum;
size_t repeat_time; size_t repeat_time;
} Setting; } Setting;
#endif #endif

View file

@ -0,0 +1,35 @@
#ifndef __BENCH_DEBUG_H
#define __BENCH_DEBUG_H
#include <stdarg.h>
#define ANSI_ERROR "\33[1;31m"
#define ANSI_WARN "\33[1;93m"
#define ANSI_INFO "\33[1;34m"
#define ANSI_DEBUG "\33[1;32m"
#define ANSI_TRACE "\33[1;90m"
#define ANSI_NONE "\33[0m"
#ifndef LOG_LEVEL
#define LOG_LEVEL 2
#endif
#define LOG_LEVEL_ERROR 0
#define LOG_LEVEL_WARN 1
#define LOG_LEVEL_INFO 2
#define LOG_LEVEL_DEBUG 3
#define LOG_LEVEL_TRACE 4
#define ANSI_FMT(str, fmt) fmt str ANSI_NONE "\n"
#define BENCH_LOG(level, str, ...) \
do { \
if (LOG_LEVEL >= LOG_LEVEL_##level) { \
bench_printf(ANSI_FMT(str, ANSI_##level), ##__VA_ARGS__); \
} \
} while (0)
int bench_vsprintf(char *buf, const char *fmt, va_list args);
int bench_sprintf(char *s, const char *fmt, ...);
int bench_printf(const char *fmt, ...);
#endif

View file

@ -5,11 +5,10 @@
#include <stdint.h> #include <stdint.h>
void bench_malloc_init(); void bench_malloc_init();
void *bench_malloc (size_t size); void *bench_malloc(size_t size);
void *bench_calloc (size_t number, size_t size); void *bench_calloc(size_t number, size_t size);
void *bench_realloc (void *p, size_t size); void *bench_realloc(void *p, size_t size);
void bench_free (void *ptr); void bench_free(void *ptr);
void bench_all_free (void); void bench_all_free(void);
#endif #endif

View file

@ -3,12 +3,11 @@
#include <stddef.h> #include <stddef.h>
int strcasecmp (const char *s1, const char *s2); int strcasecmp(const char *s1, const char *s2);
int strncasecmp (const char *s1, const char *s2, size_t n); int strncasecmp(const char *s1, const char *s2, size_t n);
char* strdup (const char* str); char *strdup(const char *str);
size_t strspn (const char *str, const char *group); size_t strspn(const char *str, const char *group);
size_t strcspn ( const char * str1, const char * str2 ); size_t strcspn(const char *str1, const char *str2);
unsigned long strtoul(const char *pstart, char **pend, int base); unsigned long strtoul(const char *pstart, char **pend, int base);
unsigned long long strtoull(const char *pstart, char **pend, int base); unsigned long long strtoull(const char *pstart, char **pend, int base);
@ -18,9 +17,7 @@ double strtod(const char *pstart, char **pend);
long double strtold(const char *pstart, char **pend); long double strtold(const char *pstart, char **pend);
float strtof(const char *pstart, char **pend); float strtof(const char *pstart, char **pend);
char *strchr(const char *s, const char ch); char *strchr(const char *s, const char ch);
char* strstr(const char* dest, const char* src); char *strstr(const char *dest, const char *src);
char *strrchr(const char *s, const char ch); char *strrchr(const char *s, const char ch);
#endif #endif

View file

@ -7,34 +7,30 @@
* Annex B Byte Stream format * Annex B Byte Stream format
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
************************************************************************************* *************************************************************************************
*/ */
#include "global.h"
#include "annexb.h" #include "annexb.h"
#include "memalloc.h"
#include "fast_memory.h" #include "fast_memory.h"
#include "global.h"
#include "memalloc.h"
static const int IOBUFFERSIZE = 512*1024; //65536; static const int IOBUFFERSIZE = 512 * 1024; // 65536;
void malloc_annex_b(VideoParameters *p_Vid) void malloc_annex_b(VideoParameters *p_Vid) {
{ if ((p_Vid->annex_b = (ANNEXB_t *)calloc(1, sizeof(ANNEXB_t))) == NULL) {
if ( (p_Vid->annex_b = (ANNEXB_t *) calloc(1, sizeof(ANNEXB_t))) == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Annex_B file failed"); snprintf(errortext, ET_SIZE, "Memory allocation for Annex_B file failed");
error(errortext,100); error(errortext, 100);
} }
if ((p_Vid->annex_b->Buf = (byte*) malloc(p_Vid->nalu->max_size)) == NULL) if ((p_Vid->annex_b->Buf = (byte *)malloc(p_Vid->nalu->max_size)) == NULL) {
{
error("GetAnnexbNALU: Buf", 101); error("GetAnnexbNALU: Buf", 101);
} }
} }
void init_annex_b(ANNEXB_t *annex_b) {
void init_annex_b(ANNEXB_t *annex_b)
{
annex_b->BitStreamFile = -1; annex_b->BitStreamFile = -1;
annex_b->iobuffer = NULL; annex_b->iobuffer = NULL;
annex_b->iobufferread = NULL; annex_b->iobufferread = NULL;
@ -44,12 +40,11 @@ void init_annex_b(ANNEXB_t *annex_b)
annex_b->nextstartcodebytes = 0; annex_b->nextstartcodebytes = 0;
} }
void free_annex_b(VideoParameters *p_Vid) void free_annex_b(VideoParameters *p_Vid) {
{
free(p_Vid->annex_b->Buf); free(p_Vid->annex_b->Buf);
p_Vid->annex_b->Buf = NULL; p_Vid->annex_b->Buf = NULL;
free(p_Vid->annex_b); free(p_Vid->annex_b);
p_Vid->annex_b = NULL; p_Vid->annex_b = NULL;
} }
/*! /*!
@ -58,11 +53,10 @@ void free_annex_b(VideoParameters *p_Vid)
* fill IO buffer * fill IO buffer
************************************************************************ ************************************************************************
*/ */
static inline int getChunk(ANNEXB_t *annex_b) static inline int getChunk(ANNEXB_t *annex_b) {
{ unsigned int readbytes =
unsigned int readbytes = read (annex_b->BitStreamFile, annex_b->iobuffer, annex_b->iIOBufferSize); read(annex_b->BitStreamFile, annex_b->iobuffer, annex_b->iIOBufferSize);
if (0==readbytes) if (0 == readbytes) {
{
annex_b->is_eof = TRUE; annex_b->is_eof = TRUE;
return 0; return 0;
} }
@ -78,10 +72,8 @@ static inline int getChunk(ANNEXB_t *annex_b)
* returns a byte from IO buffer * returns a byte from IO buffer
************************************************************************ ************************************************************************
*/ */
static inline byte getfbyte(ANNEXB_t *annex_b) static inline byte getfbyte(ANNEXB_t *annex_b) {
{ if (0 == annex_b->bytesinbuffer) {
if (0 == annex_b->bytesinbuffer)
{
if (0 == getChunk(annex_b)) if (0 == getChunk(annex_b))
return 0; return 0;
} }
@ -105,25 +97,21 @@ static inline byte getfbyte(ANNEXB_t *annex_b)
* indicates number of 0x00 bytes in start-code. * indicates number of 0x00 bytes in start-code.
************************************************************************ ************************************************************************
*/ */
static inline int FindStartCode (unsigned char *Buf, int zeros_in_startcode) static inline int FindStartCode(unsigned char *Buf, int zeros_in_startcode) {
{
int i; int i;
for (i = 0; i < zeros_in_startcode; i++) for (i = 0; i < zeros_in_startcode; i++) {
{ if (*(Buf++) != 0) {
if(*(Buf++) != 0)
{
return 0; return 0;
} }
} }
if(*Buf != 1) if (*Buf != 1)
return 0; return 0;
return 1; return 1;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -143,8 +131,7 @@ static inline int FindStartCode (unsigned char *Buf, int zeros_in_startcode)
************************************************************************ ************************************************************************
*/ */
int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu) int GetAnnexbNALU(VideoParameters *p_Vid, NALU_t *nalu) {
{
ANNEXB_t *annex_b = p_Vid->annex_b; ANNEXB_t *annex_b = p_Vid->annex_b;
int i; int i;
int info2 = 0, info3 = 0, pos = 0; int info2 = 0, info3 = 0, pos = 0;
@ -152,150 +139,139 @@ int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu)
int LeadingZero8BitsCount = 0; int LeadingZero8BitsCount = 0;
byte *pBuf = annex_b->Buf; byte *pBuf = annex_b->Buf;
if (annex_b->nextstartcodebytes != 0) if (annex_b->nextstartcodebytes != 0) {
{ for (i = 0; i < annex_b->nextstartcodebytes - 1; i++) {
for (i=0; i<annex_b->nextstartcodebytes-1; i++)
{
(*pBuf++) = 0; (*pBuf++) = 0;
pos++; pos++;
} }
(*pBuf++) = 1; (*pBuf++) = 1;
pos++; pos++;
} } else {
else while (!annex_b->is_eof) {
{
while(!annex_b->is_eof)
{
pos++; pos++;
if ((*(pBuf++)= getfbyte(annex_b))!= 0) if ((*(pBuf++) = getfbyte(annex_b)) != 0)
break; break;
} }
} }
if(annex_b->is_eof == TRUE) if (annex_b->is_eof == TRUE) {
{ if (pos == 0) {
if(pos==0)
{
return 0; return 0;
} } else {
else printf("GetAnnexbNALU can't read start code\n");
{
printf( "GetAnnexbNALU can't read start code\n");
return -1; return -1;
} }
} }
if(*(pBuf - 1) != 1 || pos < 3) if (*(pBuf - 1) != 1 || pos < 3) {
{ printf("GetAnnexbNALU: no Start Code at the beginning of the NALU, return "
printf ("GetAnnexbNALU: no Start Code at the beginning of the NALU, return -1\n"); "-1\n");
return -1; return -1;
} }
if (pos == 3) if (pos == 3) {
{
nalu->startcodeprefix_len = 3; nalu->startcodeprefix_len = 3;
} } else {
else
{
LeadingZero8BitsCount = pos - 4; LeadingZero8BitsCount = pos - 4;
nalu->startcodeprefix_len = 4; nalu->startcodeprefix_len = 4;
} }
//the 1st byte stream NAL unit can has leading_zero_8bits, but subsequent ones are not // the 1st byte stream NAL unit can has leading_zero_8bits, but subsequent
//allowed to contain it since these zeros(if any) are considered trailing_zero_8bits // ones are not allowed to contain it since these zeros(if any) are considered
//of the previous byte stream NAL unit. // trailing_zero_8bits of the previous byte stream NAL unit.
if(!annex_b->IsFirstByteStreamNALU && LeadingZero8BitsCount > 0) if (!annex_b->IsFirstByteStreamNALU && LeadingZero8BitsCount > 0) {
{ printf("GetAnnexbNALU: The leading_zero_8bits syntax can only be present "
printf ("GetAnnexbNALU: The leading_zero_8bits syntax can only be present in the first byte stream NAL unit, return -1\n"); "in the first byte stream NAL unit, return -1\n");
return -1; return -1;
} }
LeadingZero8BitsCount = pos; LeadingZero8BitsCount = pos;
annex_b->IsFirstByteStreamNALU = 0; annex_b->IsFirstByteStreamNALU = 0;
while (!StartCodeFound) while (!StartCodeFound) {
{ if (annex_b->is_eof == TRUE) {
if (annex_b->is_eof == TRUE)
{
pBuf -= 2; pBuf -= 2;
while(*(pBuf--)==0) while (*(pBuf--) == 0)
pos--; pos--;
nalu->len = (pos - 1) - LeadingZero8BitsCount; nalu->len = (pos - 1) - LeadingZero8BitsCount;
memcpy (nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); memcpy(nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len);
nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1;
nalu->nal_reference_idc = (NalRefIdc) ((*(nalu->buf) >> 5) & 3); nalu->nal_reference_idc = (NalRefIdc)((*(nalu->buf) >> 5) & 3);
nalu->nal_unit_type = (NaluType) ((*(nalu->buf)) & 0x1f); nalu->nal_unit_type = (NaluType)((*(nalu->buf)) & 0x1f);
annex_b->nextstartcodebytes = 0; annex_b->nextstartcodebytes = 0;
// printf ("GetAnnexbNALU, eof case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type); // printf ("GetAnnexbNALU, eof case: pos %d nalu->len %d,
// nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len,
// nalu->nal_reference_idc, nalu->nal_unit_type);
#if TRACE #if TRACE
fprintf (p_Dec->p_trace, "\n\nLast NALU in File\n\n"); fprintf(p_Dec->p_trace, "\n\nLast NALU in File\n\n");
fprintf (p_Dec->p_trace, "Annex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n", fprintf(p_Dec->p_trace,
nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type); "Annex B NALU w/ %s startcode, len %d, forbidden_bit %d, "
fflush (p_Dec->p_trace); "nal_reference_idc %d, nal_unit_type %d\n\n",
nalu->startcodeprefix_len == 4 ? "long" : "short", nalu->len,
nalu->forbidden_bit, nalu->nal_reference_idc,
nalu->nal_unit_type);
fflush(p_Dec->p_trace);
#endif #endif
return (pos - 1); return (pos - 1);
} }
pos++; pos++;
*(pBuf ++) = getfbyte(annex_b); *(pBuf++) = getfbyte(annex_b);
info3 = FindStartCode(pBuf - 4, 3); info3 = FindStartCode(pBuf - 4, 3);
if(info3 != 1) if (info3 != 1) {
{
info2 = FindStartCode(pBuf - 3, 2); info2 = FindStartCode(pBuf - 3, 2);
StartCodeFound = info2 & 0x01; StartCodeFound = info2 & 0x01;
} } else
else
StartCodeFound = 1; StartCodeFound = 1;
} }
// Here, we have found another start code (and read length of startcode bytes more than we should // Here, we have found another start code (and read length of startcode bytes
// have. Hence, go back in the file // more than we should have. Hence, go back in the file
if(info3 == 1) //if the detected start code is 00 00 01, trailing_zero_8bits is sure not to be present if (info3 == 1) // if the detected start code is 00 00 01, trailing_zero_8bits
// is sure not to be present
{ {
pBuf -= 5; pBuf -= 5;
while(*(pBuf--) == 0) while (*(pBuf--) == 0)
pos--; pos--;
annex_b->nextstartcodebytes = 4; annex_b->nextstartcodebytes = 4;
} } else if (info2 == 1)
else if (info2 == 1)
annex_b->nextstartcodebytes = 3; annex_b->nextstartcodebytes = 3;
else else {
{
printf(" Panic: Error in next start code search \n"); printf(" Panic: Error in next start code search \n");
return -1; return -1;
} }
pos -= annex_b->nextstartcodebytes; pos -= annex_b->nextstartcodebytes;
// Here the leading zeros(if any), Start code, the complete NALU, trailing zeros(if any) // Here the leading zeros(if any), Start code, the complete NALU, trailing
// and the next start code is in the Buf. // zeros(if any) and the next start code is in the Buf. The size of Buf is pos
// The size of Buf is pos - rewind, pos are the number of bytes excluding the next // - rewind, pos are the number of bytes excluding the next start code, and
// start code, and (pos) - LeadingZero8BitsCount // (pos) - LeadingZero8BitsCount is the size of the NALU.
// is the size of the NALU.
nalu->len = pos - LeadingZero8BitsCount; nalu->len = pos - LeadingZero8BitsCount;
fast_memcpy (nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); fast_memcpy(nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len);
nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1;
nalu->nal_reference_idc = (NalRefIdc) ((*(nalu->buf) >> 5) & 3); nalu->nal_reference_idc = (NalRefIdc)((*(nalu->buf) >> 5) & 3);
nalu->nal_unit_type = (NaluType) ((*(nalu->buf)) & 0x1f); nalu->nal_unit_type = (NaluType)((*(nalu->buf)) & 0x1f);
nalu->lost_packets = 0; nalu->lost_packets = 0;
// printf ("GetAnnexbNALU, regular case: pos %d nalu->len %d,
//printf ("GetAnnexbNALU, regular case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type); // nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len,
// nalu->nal_reference_idc, nalu->nal_unit_type);
#if TRACE #if TRACE
fprintf (p_Dec->p_trace, "\n\nAnnex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n", fprintf(p_Dec->p_trace,
nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type); "\n\nAnnex B NALU w/ %s startcode, len %d, forbidden_bit %d, "
fflush (p_Dec->p_trace); "nal_reference_idc %d, nal_unit_type %d\n\n",
nalu->startcodeprefix_len == 4 ? "long" : "short", nalu->len,
nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type);
fflush(p_Dec->p_trace);
#endif #endif
return (pos); return (pos);
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -304,51 +280,43 @@ int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu)
* none * none
************************************************************************ ************************************************************************
*/ */
void OpenAnnexBFile (VideoParameters *p_Vid, char *fn) void OpenAnnexBFile(VideoParameters *p_Vid, char *fn) {
{
ANNEXB_t *annex_b = p_Vid->annex_b; ANNEXB_t *annex_b = p_Vid->annex_b;
if (NULL != annex_b->iobuffer) if (NULL != annex_b->iobuffer) {
{ error("OpenAnnexBFile: tried to open Annex B file twice", 500);
error ("OpenAnnexBFile: tried to open Annex B file twice",500);
} }
if ((annex_b->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) if ((annex_b->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) {
{ snprintf(errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'",
snprintf (errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'", fn); fn);
error(errortext,500); error(errortext, 500);
} }
annex_b->iIOBufferSize = IOBUFFERSIZE * sizeof (byte); annex_b->iIOBufferSize = IOBUFFERSIZE * sizeof(byte);
annex_b->iobuffer = malloc (annex_b->iIOBufferSize); annex_b->iobuffer = malloc(annex_b->iIOBufferSize);
if (NULL == annex_b->iobuffer) if (NULL == annex_b->iobuffer) {
{ error("OpenAnnexBFile: cannot allocate IO buffer", 500);
error ("OpenAnnexBFile: cannot allocate IO buffer",500);
} }
annex_b->is_eof = FALSE; annex_b->is_eof = FALSE;
getChunk(annex_b); getChunk(annex_b);
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Closes the bit stream file * Closes the bit stream file
************************************************************************ ************************************************************************
*/ */
void CloseAnnexBFile(VideoParameters *p_Vid) void CloseAnnexBFile(VideoParameters *p_Vid) {
{
ANNEXB_t *annex_b = p_Vid->annex_b; ANNEXB_t *annex_b = p_Vid->annex_b;
if (annex_b->BitStreamFile != -1) if (annex_b->BitStreamFile != -1) {
{
close(annex_b->BitStreamFile); close(annex_b->BitStreamFile);
annex_b->BitStreamFile = - 1; annex_b->BitStreamFile = -1;
} }
free (annex_b->iobuffer); free(annex_b->iobuffer);
annex_b->iobuffer = NULL; annex_b->iobuffer = NULL;
} }
void ResetAnnexB(ANNEXB_t *annex_b) {
void ResetAnnexB(ANNEXB_t *annex_b)
{
annex_b->is_eof = FALSE; annex_b->is_eof = FALSE;
annex_b->bytesinbuffer = 0; annex_b->bytesinbuffer = 0;
annex_b->iobufferread = annex_b->iobuffer; annex_b->iobufferread = annex_b->iobuffer;

View file

@ -5,27 +5,27 @@
* \brief * \brief
* Binary arithmetic decoder routines. * Binary arithmetic decoder routines.
* *
* This modified implementation of the M Coder is based on JVT-U084 * This modified implementation of the M Coder is based on JVT-U084
* with the choice of M_BITS = 16. * with the choice of M_BITS = 16.
* *
* \date * \date
* 21. Oct 2000 * 21. Oct 2000
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Detlev Marpe <marpe@hhi.de> * - Detlev Marpe <marpe@hhi.de>
* - Gabi Blaettermann * - Gabi Blaettermann
* - Gunnar Marten * - Gunnar Marten
************************************************************************************* *************************************************************************************
*/ */
#include "biaridecod.h"
#include "global.h" #include "global.h"
#include "memalloc.h" #include "memalloc.h"
#include "biaridecod.h"
#define B_BITS 10 // Number of bits to represent the whole coding interval
#define B_BITS 10 // Number of bits to represent the whole coding interval #define HALF 0x01FE //(1 << (B_BITS-1)) - 2
#define HALF 0x01FE //(1 << (B_BITS-1)) - 2 #define QUARTER 0x0100 //(1 << (B_BITS-2))
#define QUARTER 0x0100 //(1 << (B_BITS-2))
/*! /*!
************************************************************************ ************************************************************************
@ -35,30 +35,25 @@
* allocates memory * allocates memory
************************************************************************ ************************************************************************
*/ */
DecodingEnvironmentPtr arideco_create_decoding_environment() DecodingEnvironmentPtr arideco_create_decoding_environment() {
{
DecodingEnvironmentPtr dep; DecodingEnvironmentPtr dep;
if ((dep = calloc(1,sizeof(DecodingEnvironment))) == NULL) if ((dep = calloc(1, sizeof(DecodingEnvironment))) == NULL)
no_mem_exit("arideco_create_decoding_environment: dep"); no_mem_exit("arideco_create_decoding_environment: dep");
return dep; return dep;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* Frees memory of the DecodingEnvironment struct * Frees memory of the DecodingEnvironment struct
*********************************************************************** ***********************************************************************
*/ */
void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep) void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep) {
{ if (dep == NULL) {
if (dep == NULL)
{
snprintf(errortext, ET_SIZE, "Error freeing dep (NULL pointer)"); snprintf(errortext, ET_SIZE, "Error freeing dep (NULL pointer)");
error (errortext, 200); error(errortext, 200);
} } else
else
free(dep); free(dep);
} }
@ -68,10 +63,9 @@ void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep)
* finalize arithetic decoding(): * finalize arithetic decoding():
************************************************************************ ************************************************************************
*/ */
void arideco_done_decoding(DecodingEnvironmentPtr dep) void arideco_done_decoding(DecodingEnvironmentPtr dep) {
{
(*dep->Dcodestrm_len)++; (*dep->Dcodestrm_len)++;
#if(TRACE==2) #if (TRACE == 2)
fprintf(p_trace, "done_decoding: %d\n", *dep->Dcodestrm_len); fprintf(p_trace, "done_decoding: %d\n", *dep->Dcodestrm_len);
#endif #endif
} }
@ -82,9 +76,8 @@ void arideco_done_decoding(DecodingEnvironmentPtr dep)
* read one byte from the bitstream * read one byte from the bitstream
************************************************************************ ************************************************************************
*/ */
unsigned int getbyte(DecodingEnvironmentPtr dep) unsigned int getbyte(DecodingEnvironmentPtr dep) {
{ #if (TRACE == 2)
#if(TRACE==2)
fprintf(p_trace, "get_byte: %d\n", (*dep->Dcodestrm_len)); fprintf(p_trace, "get_byte: %d\n", (*dep->Dcodestrm_len));
#endif #endif
return dep->Dcodestrm[(*dep->Dcodestrm_len)++]; return dep->Dcodestrm[(*dep->Dcodestrm_len)++];
@ -96,15 +89,14 @@ unsigned int getbyte(DecodingEnvironmentPtr dep)
* read two bytes from the bitstream * read two bytes from the bitstream
************************************************************************ ************************************************************************
*/ */
unsigned int getword(DecodingEnvironmentPtr dep) unsigned int getword(DecodingEnvironmentPtr dep) {
{
int d = *dep->Dcodestrm_len; int d = *dep->Dcodestrm_len;
#if(TRACE==2) #if (TRACE == 2)
fprintf(p_trace, "get_byte: %d\n", d); fprintf(p_trace, "get_byte: %d\n", d);
fprintf(p_trace, "get_byte: %d\n", d + 1); fprintf(p_trace, "get_byte: %d\n", d + 1);
#endif #endif
*dep->Dcodestrm_len += 2; *dep->Dcodestrm_len += 2;
return ((dep->Dcodestrm[d]<<8) | dep->Dcodestrm[d+1]); return ((dep->Dcodestrm[d] << 8) | dep->Dcodestrm[d + 1]);
} }
/*! /*!
************************************************************************ ************************************************************************
@ -112,43 +104,43 @@ unsigned int getword(DecodingEnvironmentPtr dep)
* Initializes the DecodingEnvironment for the arithmetic coder * Initializes the DecodingEnvironment for the arithmetic coder
************************************************************************ ************************************************************************
*/ */
void arideco_start_decoding(DecodingEnvironmentPtr dep, unsigned char *code_buffer, void arideco_start_decoding(DecodingEnvironmentPtr dep,
int firstbyte, int *code_len) unsigned char *code_buffer, int firstbyte,
{ int *code_len) {
dep->Dcodestrm = code_buffer; dep->Dcodestrm = code_buffer;
dep->Dcodestrm_len = code_len; dep->Dcodestrm_len = code_len;
*dep->Dcodestrm_len = firstbyte; *dep->Dcodestrm_len = firstbyte;
dep->Dvalue = getbyte(dep); dep->Dvalue = getbyte(dep);
dep->Dvalue = (dep->Dvalue << 16) | getword(dep); // lookahead of 2 bytes: always make sure that bitstream buffer dep->Dvalue =
// contains 2 more bytes than actual bitstream (dep->Dvalue << 16) |
getword(dep); // lookahead of 2 bytes: always make sure that bitstream
// buffer contains 2 more bytes than actual bitstream
dep->DbitsLeft = 15; dep->DbitsLeft = 15;
dep->Drange = HALF; dep->Drange = HALF;
#if (2==TRACE) #if (2 == TRACE)
fprintf(p_trace, "value: %d firstbyte: %d code_len: %d\n", dep->Dvalue >> dep->DbitsLeft, firstbyte, *code_len); fprintf(p_trace, "value: %d firstbyte: %d code_len: %d\n",
dep->Dvalue >> dep->DbitsLeft, firstbyte, *code_len);
#endif #endif
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* arideco_bits_read * arideco_bits_read
************************************************************************ ************************************************************************
*/ */
int arideco_bits_read(DecodingEnvironmentPtr dep) int arideco_bits_read(DecodingEnvironmentPtr dep) {
{
int tmp = ((*dep->Dcodestrm_len) << 3) - dep->DbitsLeft; int tmp = ((*dep->Dcodestrm_len) << 3) - dep->DbitsLeft;
#if (2==TRACE) #if (2 == TRACE)
fprintf(p_trace, "tmp: %d\n", tmp); fprintf(p_trace, "tmp: %d\n", tmp);
#endif #endif
return tmp; return tmp;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -157,53 +149,48 @@ int arideco_bits_read(DecodingEnvironmentPtr dep)
* the decoded symbol * the decoded symbol
************************************************************************ ************************************************************************
*/ */
unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi_ct ) unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep,
{ BiContextTypePtr bi_ct) {
unsigned int bit = bi_ct->MPS; unsigned int bit = bi_ct->MPS;
unsigned int *value = &dep->Dvalue; unsigned int *value = &dep->Dvalue;
unsigned int *range = &dep->Drange; unsigned int *range = &dep->Drange;
uint16 *state = &bi_ct->state; uint16 *state = &bi_ct->state;
unsigned int rLPS = rLPS_table_64x4[*state][(*range>>6) & 0x03]; unsigned int rLPS = rLPS_table_64x4[*state][(*range >> 6) & 0x03];
int *DbitsLeft = &dep->DbitsLeft; int *DbitsLeft = &dep->DbitsLeft;
*range -= rLPS; *range -= rLPS;
if(*value < (*range << *DbitsLeft)) //MPS if (*value < (*range << *DbitsLeft)) // MPS
{ {
*state = AC_next_state_MPS_64[*state]; // next state *state = AC_next_state_MPS_64[*state]; // next state
if( *range >= QUARTER ) if (*range >= QUARTER) {
{
return (bit); return (bit);
} } else
else
*range <<= 1; *range <<= 1;
(*DbitsLeft)--; (*DbitsLeft)--;
} } else // LPS
else // LPS
{ {
int renorm = renorm_table_32[(rLPS>>3) & 0x1F]; int renorm = renorm_table_32[(rLPS >> 3) & 0x1F];
*value -= (*range << dep->DbitsLeft); *value -= (*range << dep->DbitsLeft);
*range = (rLPS << renorm); *range = (rLPS << renorm);
(*DbitsLeft) -= renorm; (*DbitsLeft) -= renorm;
bit ^= 0x01; bit ^= 0x01;
if (!(*state)) // switch meaning of MPS if necessary if (!(*state)) // switch meaning of MPS if necessary
bi_ct->MPS ^= 0x01; bi_ct->MPS ^= 0x01;
*state = AC_next_state_LPS_64[*state]; // next state *state = AC_next_state_LPS_64[*state]; // next state
} }
if( *DbitsLeft > 0 ) if (*DbitsLeft > 0) {
{
return (bit); return (bit);
} } else {
else
{
*value <<= 16; *value <<= 16;
*value |= getword(dep); // lookahead of 2 bytes: always make sure that bitstream buffer *value |= getword(
dep); // lookahead of 2 bytes: always make sure that bitstream buffer
// contains 2 more bytes than actual bitstream // contains 2 more bytes than actual bitstream
(*DbitsLeft) += 16; (*DbitsLeft) += 16;
@ -211,7 +198,6 @@ unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi
} }
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -220,26 +206,23 @@ unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi
* the decoded symbol * the decoded symbol
************************************************************************ ************************************************************************
*/ */
unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep) unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep) {
{ int tmp_value;
int tmp_value; unsigned int *value = &dep->Dvalue;
unsigned int *value = &dep->Dvalue; int *DbitsLeft = &dep->DbitsLeft;
int *DbitsLeft = &dep->DbitsLeft;
if(--(*DbitsLeft) == 0) if (--(*DbitsLeft) == 0) {
{ *value =
*value = (*value << 16) | getword( dep ); // lookahead of 2 bytes: always make sure that bitstream buffer (*value << 16) |
// contains 2 more bytes than actual bitstream getword(dep); // lookahead of 2 bytes: always make sure that bitstream
// buffer contains 2 more bytes than actual bitstream
*DbitsLeft = 16; *DbitsLeft = 16;
} }
tmp_value = *value - (dep->Drange << *DbitsLeft); tmp_value = *value - (dep->Drange << *DbitsLeft);
if (tmp_value < 0) if (tmp_value < 0) {
{
return 0; return 0;
} } else {
else
{
*value = tmp_value; *value = tmp_value;
return 1; return 1;
} }
@ -253,35 +236,30 @@ unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep)
* the decoded symbol * the decoded symbol
************************************************************************ ************************************************************************
*/ */
unsigned int biari_decode_final(DecodingEnvironmentPtr dep) unsigned int biari_decode_final(DecodingEnvironmentPtr dep) {
{ unsigned int range = dep->Drange - 2;
unsigned int range = dep->Drange - 2; int value = dep->Dvalue;
int value = dep->Dvalue;
value -= (range << dep->DbitsLeft); value -= (range << dep->DbitsLeft);
if (value < 0) if (value < 0) {
{ if (range >= QUARTER) {
if( range >= QUARTER )
{
dep->Drange = range; dep->Drange = range;
return 0; return 0;
} } else {
else
{
dep->Drange = (range << 1); dep->Drange = (range << 1);
if( --(dep->DbitsLeft) > 0 ) if (--(dep->DbitsLeft) > 0)
return 0; return 0;
else else {
{ dep->Dvalue =
dep->Dvalue = (dep->Dvalue << 16) | getword( dep ); // lookahead of 2 bytes: always make sure that bitstream buffer (dep->Dvalue << 16) |
// contains 2 more bytes than actual bitstream getword(
dep); // lookahead of 2 bytes: always make sure that bitstream
// buffer contains 2 more bytes than actual bitstream
dep->DbitsLeft = 16; dep->DbitsLeft = 16;
return 0; return 0;
} }
} }
} } else {
else
{
return 1; return 1;
} }
} }
@ -292,21 +270,16 @@ unsigned int biari_decode_final(DecodingEnvironmentPtr dep)
* Initializes a given context with some pre-defined probability state * Initializes a given context with some pre-defined probability state
************************************************************************ ************************************************************************
*/ */
void biari_init_context (int qp, BiContextTypePtr ctx, const signed char* ini) void biari_init_context(int qp, BiContextTypePtr ctx, const signed char *ini) {
{ int pstate = ((ini[0] * qp) >> 4) + ini[1];
int pstate = ((ini[0]* qp )>>4) + ini[1];
if ( pstate >= 64 ) if (pstate >= 64) {
{
pstate = imin(126, pstate); pstate = imin(126, pstate);
ctx->state = (uint16) (pstate - 64); ctx->state = (uint16)(pstate - 64);
ctx->MPS = 1; ctx->MPS = 1;
} } else {
else
{
pstate = imax(1, pstate); pstate = imax(1, pstate);
ctx->state = (uint16) (63 - pstate); ctx->state = (uint16)(63 - pstate);
ctx->MPS = 0; ctx->MPS = 0;
} }
} }

View file

@ -6,7 +6,8 @@
* Block Prediction related functions * Block Prediction related functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************************* *************************************************************************************
@ -14,49 +15,48 @@
#include "contributors.h" #include "contributors.h"
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include <stdlib.h>
#include "block.h" #include "block.h"
#include "global.h" #include "global.h"
#include "macroblock.h"
#include "mc_prediction.h"
#include "image.h" #include "image.h"
#include "macroblock.h"
#include "mb_access.h" #include "mb_access.h"
#include "mc_prediction.h"
void compute_residue (imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, int opix_x, int width, int height) void compute_residue(imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x,
{ int opix_x, int width, int height) {
imgpel *imgOrg, *imgPred; imgpel *imgOrg, *imgPred;
int *m7; int *m7;
int i, j; int i, j;
for (j = 0; j < height; j++) for (j = 0; j < height; j++) {
{ imgOrg = &curImg[j][opix_x];
imgOrg = &curImg[j][opix_x];
imgPred = &mpr[j][mb_x]; imgPred = &mpr[j][mb_x];
m7 = &mb_rres[j][mb_x]; m7 = &mb_rres[j][mb_x];
for (i = 0; i < width; i++) for (i = 0; i < width; i++) {
{
*m7++ = *imgOrg++ - *imgPred++; *m7++ = *imgOrg++ - *imgPred++;
} }
} }
} }
void sample_reconstruct (imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, int opix_x, int width, int height, int max_imgpel_value, int dq_bits) void sample_reconstruct(imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x,
{ int opix_x, int width, int height, int max_imgpel_value,
int dq_bits) {
imgpel *imgOrg, *imgPred; imgpel *imgOrg, *imgPred;
int *m7; int *m7;
int i, j; int i, j;
for (j = 0; j < height; j++) for (j = 0; j < height; j++) {
{
imgOrg = &curImg[j][opix_x]; imgOrg = &curImg[j][opix_x];
imgPred = &mpr[j][mb_x]; imgPred = &mpr[j][mb_x];
m7 = &mb_rres[j][mb_x]; m7 = &mb_rres[j][mb_x];
for (i=0;i<width;i++) for (i = 0; i < width; i++)
*imgOrg++ = (imgpel) iClip1( max_imgpel_value, rshift_rnd_sf(*m7++, dq_bits) + *imgPred++); *imgOrg++ = (imgpel)iClip1(max_imgpel_value,
rshift_rnd_sf(*m7++, dq_bits) + *imgPred++);
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -6,39 +6,36 @@
* \brief * \brief
* Configuration handling. * Configuration handling.
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and affiliation
*details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
* \note * \note
* In the future this module should hide the Parameters and offer only * In the future this module should hide the Parameters and offer only
* Functions for their access. Modules which make frequent use of some parameters * Functions for their access. Modules which make frequent use of some
* (e.g. picture size in macroblocks) are free to buffer them on local variables. *parameters (e.g. picture size in macroblocks) are free to buffer them on local
* This will not only avoid global variable and make the code more readable, but also *variables. This will not only avoid global variable and make the code more
* speed it up. It will also greatly facilitate future enhancements such as the *readable, but also speed it up. It will also greatly facilitate future
* handling of different picture sizes in the same sequence. \n *enhancements such as the handling of different picture sizes in the same
* \n *sequence. \n \n For now, everything is just copied to
* For now, everything is just copied to the inp_par structure (gulp) *the inp_par structure (gulp)
* *
************************************************************************************** **************************************************************************************
* \par Configuration File Format * \par Configuration File Format
************************************************************************************** **************************************************************************************
* Format is line oriented, maximum of one parameter per line \n * Format is line oriented, maximum of one parameter per line \n \n Lines have
* \n *the following format: \n
* Lines have the following format: \n * \<ParameterName\> = \<ParameterValue\> # Comments \\n \n Whitespace is space
* \<ParameterName\> = \<ParameterValue\> # Comments \\n \n *and \\t \par
* Whitespace is space and \\t * \<ParameterName\> are the predefined names for Parameters and are case
* \par *sensitive. See configfile.h for the definition of those names and their
* \<ParameterName\> are the predefined names for Parameters and are case sensitive. *mapping to cfgparams->values. \par
* See configfile.h for the definition of those names and their mapping to
* cfgparams->values.
* \par
* \<ParameterValue\> are either integers [0..9]* or strings. * \<ParameterValue\> are either integers [0..9]* or strings.
* Integers must fit into the wordlengths, signed values are generally assumed. * Integers must fit into the wordlengths, signed values are generally
* Strings containing no whitespace characters can be used directly. Strings containing *assumed. Strings containing no whitespace characters can be used directly.
* whitespace characters are to be inclosed in double quotes ("string with whitespace") *Strings containing whitespace characters are to be inclosed in double quotes
* The double quote character is forbidden (may want to implement something smarter here). *("string with whitespace") The double quote character is forbidden (may want
* \par *to implement something smarter here). \par Any Parameters whose ParameterName
* Any Parameters whose ParameterName is undefined lead to the termination of the program *is undefined lead to the termination of the program with an error message.
* with an error message.
* *
* \par Known bug/Shortcoming: * \par Known bug/Shortcoming:
* zero-length strings (i.e. to signal an non-existing file * zero-length strings (i.e. to signal an non-existing file
@ -46,29 +43,29 @@
* *
* \par Rules for using command files * \par Rules for using command files
* \n * \n
* All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in configfile.h. * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in
* If an -f \<config\> parameter is present in the command line then this file is used to *configfile.h. If an -f \<config\> parameter is present in the command line
* update the defaults of DEFAULTCONFIGFILENAME. There can be more than one -f parameters *then this file is used to update the defaults of DEFAULTCONFIGFILENAME. There
* present. If -p <ParameterName = ParameterValue> parameters are present then these *can be more than one -f parameters present. If -p <ParameterName =
* override the default and the additional config file's settings, and are themselves *ParameterValue> parameters are present then these override the default and the
* overridden by future -p parameters. There must be whitespace between -f and -p commands *additional config file's settings, and are themselves overridden by future -p
* and their respective parameters *parameters. There must be whitespace between -f and -p commands and their
*respective parameters
*********************************************************************** ***********************************************************************
*/ */
#include <sys/stat.h> #include <sys/stat.h>
#include "global.h"
#include "configfile.h" #include "configfile.h"
#include "global.h"
#include "memalloc.h" #include "memalloc.h"
static int ParameterNameToMapIndex (Mapping *Map, char *s); static int ParameterNameToMapIndex(Mapping *Map, char *s);
#define MAX_ITEMS_TO_PARSE 10000
#define MAX_ITEMS_TO_PARSE 10000
#ifdef SPEC #ifdef SPEC
#ifdef SPEC_WINDOWS #ifdef SPEC_WINDOWS
#define STRCMP(x,y) _stricmp(x,y) #define STRCMP(x, y) _stricmp(x, y)
#else #else
#define STRCMP strcmp #define STRCMP strcmp
#endif #endif
@ -88,69 +85,66 @@ static int ParameterNameToMapIndex (Mapping *Map, char *s);
* NULL in case of error. Error message will be set in errortext * NULL in case of error. Error message will be set in errortext
*********************************************************************** ***********************************************************************
*/ */
char *GetConfigFileContent (char *Filename) char *GetConfigFileContent(char *Filename) {
{
long FileSize; long FileSize;
FILE *f; FILE *f;
char *buf; char *buf;
if (NULL == (f = fopen (Filename, "r"))) if (NULL == (f = fopen(Filename, "r"))) {
{ snprintf(errortext, ET_SIZE, "Cannot open configuration file %s.",
snprintf (errortext, ET_SIZE, "Cannot open configuration file %s.", Filename); Filename);
return NULL;
}
if (0 != fseek (f, 0, SEEK_END))
{
snprintf (errortext, ET_SIZE, "Cannot fseek in configuration file %s.", Filename);
return NULL; return NULL;
} }
FileSize = ftell (f); if (0 != fseek(f, 0, SEEK_END)) {
if (FileSize < 0 || FileSize > 100000) snprintf(errortext, ET_SIZE, "Cannot fseek in configuration file %s.",
{ Filename);
snprintf (errortext, ET_SIZE, "Unreasonable Filesize %ld reported by ftell for configuration file %s.", FileSize, Filename);
return NULL;
}
if (0 != fseek (f, 0, SEEK_SET))
{
snprintf (errortext, ET_SIZE, "Cannot fseek in configuration file %s.", Filename);
return NULL; return NULL;
} }
if ((buf = malloc (FileSize + 1))==NULL) no_mem_exit("GetConfigFileContent: buf"); FileSize = ftell(f);
if (FileSize < 0 || FileSize > 100000) {
snprintf(errortext, ET_SIZE,
"Unreasonable Filesize %ld reported by ftell for configuration "
"file %s.",
FileSize, Filename);
return NULL;
}
if (0 != fseek(f, 0, SEEK_SET)) {
snprintf(errortext, ET_SIZE, "Cannot fseek in configuration file %s.",
Filename);
return NULL;
}
// Note that ftell() gives us the file size as the file system sees it. The actual file size, if ((buf = malloc(FileSize + 1)) == NULL)
// as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or no_mem_exit("GetConfigFileContent: buf");
// control characters after the dos EOF marker in the file.
FileSize = (long) fread (buf, 1, FileSize, f); // Note that ftell() gives us the file size as the file system sees it. The
// actual file size, as reported by fread() below will be often smaller due to
// CR/LF to CR conversion and/or control characters after the dos EOF marker
// in the file.
FileSize = (long)fread(buf, 1, FileSize, f);
buf[FileSize] = '\0'; buf[FileSize] = '\0';
fclose(f);
fclose (f);
return buf; return buf;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* Parses the character array buf and writes global variable input, which is defined in * Parses the character array buf and writes global variable input, which is
* configfile.h. This hack will continue to be necessary to facilitate the addition of *defined in configfile.h. This hack will continue to be necessary to
* new parameters through the Map[] mechanism (Need compiler-generated addresses in map[]). *facilitate the addition of new parameters through the Map[] mechanism (Need
* \param p_Inp *compiler-generated addresses in map[]). \param p_Inp InputParameters of
* InputParameters of configuration *configuration \param Map Mapping structure to specify the name and value
* \param Map *mapping relation \param buf buffer to be parsed \param bufsize buffer size of
* Mapping structure to specify the name and value mapping relation *buffer
* \param buf
* buffer to be parsed
* \param bufsize
* buffer size of buffer
*********************************************************************** ***********************************************************************
*/ */
void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) void ParseContent(InputParameters *p_Inp, Mapping *Map, char *buf,
{ int bufsize) {
char *items[MAX_ITEMS_TO_PARSE] = {NULL}; char *items[MAX_ITEMS_TO_PARSE] = {NULL};
int MapIdx; int MapIdx;
int item = 0; int item = 0;
@ -161,19 +155,20 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize)
double DoubleContent; double DoubleContent;
int i; int i;
// Stage one: Generate an argc/argv-type list in items[], without comments and whitespace. // Stage one: Generate an argc/argv-type list in items[], without comments and
// This is context insensitive and could be done most easily with lex(1). // whitespace. This is context insensitive and could be done most easily with
// lex(1).
while (p < bufend) while (p < bufend) {
{ switch (*p) {
switch (*p)
{
case 13: case 13:
++p; ++p;
break; break;
case '#': // Found comment case '#': // Found comment
*p = '\0'; // Replace '#' with '\0' in case of comment immediately following integer or string *p = '\0'; // Replace '#' with '\0' in case of comment immediately
while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first // following integer or string
while (*p != '\n' &&
p < bufend) // Skip till EOL or EOF, whichever comes first
++p; ++p;
InString = 0; InString = 0;
InItem = 0; InItem = 0;
@ -181,34 +176,30 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize)
case '\n': case '\n':
InItem = 0; InItem = 0;
InString = 0; InString = 0;
*p++='\0'; *p++ = '\0';
break; break;
case ' ': case ' ':
case '\t': // Skip whitespace, leave state unchanged case '\t': // Skip whitespace, leave state unchanged
if (InString) if (InString)
p++; p++;
else else { // Terminate non-strings once whitespace is found
{ // Terminate non-strings once whitespace is found
*p++ = '\0'; *p++ = '\0';
InItem = 0; InItem = 0;
} }
break; break;
case '"': // Begin/End of String case '"': // Begin/End of String
*p++ = '\0'; *p++ = '\0';
if (!InString) if (!InString) {
{
items[item++] = p; items[item++] = p;
InItem = ~InItem; InItem = ~InItem;
} } else
else
InItem = 0; InItem = 0;
InString = ~InString; // Toggle InString = ~InString; // Toggle
break; break;
default: default:
if (!InItem) if (!InItem) {
{
items[item++] = p; items[item++] = p;
InItem = ~InItem; InItem = ~InItem;
} }
@ -218,53 +209,57 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize)
item--; item--;
for (i=0; i<item; i+= 3) for (i = 0; i < item; i += 3) {
{ if (0 > (MapIdx = ParameterNameToMapIndex(Map, items[i]))) {
if (0 > (MapIdx = ParameterNameToMapIndex (Map, items[i]))) // snprintf (errortext, ET_SIZE, " Parsing error in config file: Parameter
{ // Name '%s' not recognized.", items[i]); error (errortext, 300);
//snprintf (errortext, ET_SIZE, " Parsing error in config file: Parameter Name '%s' not recognized.", items[i]); printf("\n\tParsing error in config file: Parameter Name '%s' not "
//error (errortext, 300); "recognized.",
printf ("\n\tParsing error in config file: Parameter Name '%s' not recognized.", items[i]); items[i]);
i -= 2 ; i -= 2;
continue; continue;
} }
if (STRCMP ("=", items[i+1])) if (STRCMP("=", items[i + 1])) {
{ snprintf(errortext, ET_SIZE,
snprintf (errortext, ET_SIZE, " Parsing error in config file: '=' expected as the second token in each line."); " Parsing error in config file: '=' expected as the second "
error (errortext, 300); "token in each line.");
error(errortext, 300);
} }
// Now interpret the Value, context sensitive... // Now interpret the Value, context sensitive...
switch (Map[MapIdx].Type) switch (Map[MapIdx].Type) {
{ case 0: // Numerical
case 0: // Numerical if (1 != sscanf(items[i + 2], "%d", &IntContent)) {
if (1 != sscanf (items[i+2], "%d", &IntContent)) snprintf(errortext, ET_SIZE,
{ " Parsing error: Expected numerical value for Parameter of "
snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]); "%s, found '%s'.",
error (errortext, 300); items[i], items[i + 2]);
error(errortext, 300);
} }
* (int *) (Map[MapIdx].Place) = IntContent; *(int *)(Map[MapIdx].Place) = IntContent;
printf ("."); printf(".");
break; break;
case 1: case 1:
if (items[i + 2] == NULL) if (items[i + 2] == NULL)
memset((char *) Map[MapIdx].Place, 0, Map[MapIdx].char_size); memset((char *)Map[MapIdx].Place, 0, Map[MapIdx].char_size);
else else
strncpy ((char *) Map[MapIdx].Place, items [i+2], Map[MapIdx].char_size); strncpy((char *)Map[MapIdx].Place, items[i + 2], Map[MapIdx].char_size);
printf ("."); printf(".");
break; break;
case 2: // Numerical double case 2: // Numerical double
if (1 != sscanf (items[i+2], "%lf", &DoubleContent)) if (1 != sscanf(items[i + 2], "%lf", &DoubleContent)) {
{ snprintf(errortext, ET_SIZE,
snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]); " Parsing error: Expected numerical value for Parameter of "
error (errortext, 300); "%s, found '%s'.",
items[i], items[i + 2]);
error(errortext, 300);
} }
* (double *) (Map[MapIdx].Place) = DoubleContent; *(double *)(Map[MapIdx].Place) = DoubleContent;
printf ("."); printf(".");
break; break;
default: default:
error ("Unknown value type in the map definition of configfile.h",-1); error("Unknown value type in the map definition of configfile.h", -1);
} }
} }
*p_Inp = cfgparams; *p_Inp = cfgparams;
@ -283,12 +278,11 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize)
* -1 for error * -1 for error
*********************************************************************** ***********************************************************************
*/ */
static int ParameterNameToMapIndex (Mapping *Map, char *s) static int ParameterNameToMapIndex(Mapping *Map, char *s) {
{
int i = 0; int i = 0;
while (Map[i].TokenName != NULL) while (Map[i].TokenName != NULL)
if (0==STRCMP (Map[i].TokenName, s)) if (0 == STRCMP(Map[i].TokenName, s))
return i; return i;
else else
i++; i++;
@ -303,17 +297,15 @@ static int ParameterNameToMapIndex (Mapping *Map, char *s)
* -1 for error * -1 for error
*********************************************************************** ***********************************************************************
*/ */
int InitParams(Mapping *Map) int InitParams(Mapping *Map) {
{
int i = 0; int i = 0;
while (Map[i].TokenName != NULL) while (Map[i].TokenName != NULL) {
{
if (Map[i].Type == 0) if (Map[i].Type == 0)
* (int *) (Map[i].Place) = (int) Map[i].Default; *(int *)(Map[i].Place) = (int)Map[i].Default;
else if (Map[i].Type == 2) else if (Map[i].Type == 2)
* (double *) (Map[i].Place) = Map[i].Default; *(double *)(Map[i].Place) = Map[i].Default;
i++; i++;
} }
return -1; return -1;
} }
@ -326,64 +318,65 @@ int InitParams(Mapping *Map)
* -1 for error * -1 for error
*********************************************************************** ***********************************************************************
*/ */
int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) {
{
int i = 0; int i = 0;
while (Map[i].TokenName != NULL) while (Map[i].TokenName != NULL) {
{ if (Map[i].param_limits == 1) {
if (Map[i].param_limits == 1) if (Map[i].Type == 0) {
{ if (*(int *)(Map[i].Place) < (int)Map[i].min_limit ||
if (Map[i].Type == 0) *(int *)(Map[i].Place) > (int)Map[i].max_limit) {
{ snprintf(errortext, ET_SIZE,
if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit || * (int *) (Map[i].Place) > (int) Map[i].max_limit ) "Error in input parameter %s. Check configuration file. "
{ "Value should be in [%d, %d] range.",
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, (int) Map[i].min_limit,(int)Map[i].max_limit ); Map[i].TokenName, (int)Map[i].min_limit,
error (errortext, 400); (int)Map[i].max_limit);
error(errortext, 400);
} }
} } else if (Map[i].Type == 2) {
else if (Map[i].Type == 2) if (*(double *)(Map[i].Place) < Map[i].min_limit ||
{ *(double *)(Map[i].Place) > Map[i].max_limit) {
if ( * (double *) (Map[i].Place) < Map[i].min_limit || * (double *) (Map[i].Place) > Map[i].max_limit ) snprintf(errortext, ET_SIZE,
{ "Error in input parameter %s. Check configuration file. "
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%.2f, %.2f] range.", Map[i].TokenName,Map[i].min_limit ,Map[i].max_limit ); "Value should be in [%.2f, %.2f] range.",
error (errortext, 400); Map[i].TokenName, Map[i].min_limit, Map[i].max_limit);
error(errortext, 400);
} }
} }
} } else if (Map[i].param_limits == 2) {
else if (Map[i].param_limits == 2) if (Map[i].Type == 0) {
if (*(int *)(Map[i].Place) < (int)Map[i].min_limit) {
snprintf(errortext, ET_SIZE,
"Error in input parameter %s. Check configuration file. "
"Value should not be smaller than %d.",
Map[i].TokenName, (int)Map[i].min_limit);
error(errortext, 400);
}
} else if (Map[i].Type == 2) {
if (*(double *)(Map[i].Place) < Map[i].min_limit) {
snprintf(errortext, ET_SIZE,
"Error in input parameter %s. Check configuration file. "
"Value should not be smaller than %2.f.",
Map[i].TokenName, Map[i].min_limit);
error(errortext, 400);
}
}
} else if (Map[i].param_limits == 3) // Only used for QPs
{ {
if (Map[i].Type == 0)
{ if (Map[i].Type == 0) {
if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit ) int cur_qp = *(int *)(Map[i].Place);
{ int min_qp = (int)(Map[i].min_limit -
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %d.", Map[i].TokenName, (int) Map[i].min_limit); (bitdepth_qp_scale ? bitdepth_qp_scale[0] : 0));
error (errortext, 400); int max_qp = (int)Map[i].max_limit;
}
} if ((cur_qp < min_qp) || (cur_qp > max_qp)) {
else if (Map[i].Type == 2) snprintf(errortext, ET_SIZE,
{ "Error in input parameter %s. Check configuration file. "
if ( * (double *) (Map[i].Place) < Map[i].min_limit ) "Value should be in [%d, %d] range.",
{ Map[i].TokenName, min_qp, max_qp);
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %2.f.", Map[i].TokenName,Map[i].min_limit); error(errortext, 400);
error (errortext, 400);
}
}
}
else if (Map[i].param_limits == 3) // Only used for QPs
{
if (Map[i].Type == 0)
{
int cur_qp = * (int *) (Map[i].Place);
int min_qp = (int) (Map[i].min_limit - (bitdepth_qp_scale? bitdepth_qp_scale[0]: 0));
int max_qp = (int) Map[i].max_limit;
if (( cur_qp < min_qp ) || ( cur_qp > max_qp ))
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, min_qp, max_qp );
error (errortext, 400);
} }
} }
} }
@ -393,8 +386,6 @@ int TestParams(Mapping *Map, int bitdepth_qp_scale[3])
return -1; return -1;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
@ -403,24 +394,25 @@ int TestParams(Mapping *Map, int bitdepth_qp_scale[3])
* -1 for error * -1 for error
*********************************************************************** ***********************************************************************
*/ */
int DisplayParams(Mapping *Map, char *message) int DisplayParams(Mapping *Map, char *message) {
{
int i = 0; int i = 0;
printf("******************************************************\n"); printf("******************************************************\n");
printf("* %s *\n", message); printf("* %s *\n", message);
printf("******************************************************\n"); printf("******************************************************\n");
while (Map[i].TokenName != NULL) while (Map[i].TokenName != NULL) {
{
if (Map[i].Type == 0) if (Map[i].Type == 0)
printf("Parameter %s = %d\n",Map[i].TokenName,* (int *) (Map[i].Place)); printf("Parameter %s = %d\n", Map[i].TokenName, *(int *)(Map[i].Place));
else if (Map[i].Type == 1) else if (Map[i].Type == 1)
printf("Parameter %s = ""%s""\n",Map[i].TokenName,(char *) (Map[i].Place)); printf("Parameter %s = "
"%s"
"\n",
Map[i].TokenName, (char *)(Map[i].Place));
else if (Map[i].Type == 2) else if (Map[i].Type == 2)
printf("Parameter %s = %.2f\n",Map[i].TokenName,* (double *) (Map[i].Place)); printf("Parameter %s = %.2f\n", Map[i].TokenName,
i++; *(double *)(Map[i].Place));
i++;
} }
printf("******************************************************\n"); printf("******************************************************\n");
return i; return i;
} }

View file

@ -6,39 +6,36 @@
* \brief * \brief
* Configuration handling. * Configuration handling.
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and affiliation
*details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
* \note * \note
* In the future this module should hide the Parameters and offer only * In the future this module should hide the Parameters and offer only
* Functions for their access. Modules which make frequent use of some parameters * Functions for their access. Modules which make frequent use of some
* (e.g. picture size in macroblocks) are free to buffer them on local variables. *parameters (e.g. picture size in macroblocks) are free to buffer them on local
* This will not only avoid global variable and make the code more readable, but also *variables. This will not only avoid global variable and make the code more
* speed it up. It will also greatly facilitate future enhancements such as the *readable, but also speed it up. It will also greatly facilitate future
* handling of different picture sizes in the same sequence. \n *enhancements such as the handling of different picture sizes in the same
* \n *sequence. \n \n For now, everything is just copied to
* For now, everything is just copied to the inp_par structure (gulp) *the inp_par structure (gulp)
* *
************************************************************************************** **************************************************************************************
* \par Configuration File Format * \par Configuration File Format
************************************************************************************** **************************************************************************************
* Format is line oriented, maximum of one parameter per line \n * Format is line oriented, maximum of one parameter per line \n \n Lines have
* \n *the following format: \n
* Lines have the following format: \n * \<ParameterName\> = \<ParameterValue\> # Comments \\n \n Whitespace is space
* \<ParameterName\> = \<ParameterValue\> # Comments \\n \n *and \\t \par
* Whitespace is space and \\t * \<ParameterName\> are the predefined names for Parameters and are case
* \par *sensitive. See configfile.h for the definition of those names and their
* \<ParameterName\> are the predefined names for Parameters and are case sensitive. *mapping to cfgparams->values. \par
* See configfile.h for the definition of those names and their mapping to
* cfgparams->values.
* \par
* \<ParameterValue\> are either integers [0..9]* or strings. * \<ParameterValue\> are either integers [0..9]* or strings.
* Integers must fit into the wordlengths, signed values are generally assumed. * Integers must fit into the wordlengths, signed values are generally
* Strings containing no whitespace characters can be used directly. Strings containing *assumed. Strings containing no whitespace characters can be used directly.
* whitespace characters are to be inclosed in double quotes ("string with whitespace") *Strings containing whitespace characters are to be inclosed in double quotes
* The double quote character is forbidden (may want to implement something smarter here). *("string with whitespace") The double quote character is forbidden (may want
* \par *to implement something smarter here). \par Any Parameters whose ParameterName
* Any Parameters whose ParameterName is undefined lead to the termination of the program *is undefined lead to the termination of the program with an error message.
* with an error message.
* *
* \par Known bug/Shortcoming: * \par Known bug/Shortcoming:
* zero-length strings (i.e. to signal an non-existing file * zero-length strings (i.e. to signal an non-existing file
@ -46,13 +43,14 @@
* *
* \par Rules for using command files * \par Rules for using command files
* \n * \n
* All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in configfile.h. * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in
* If an -f \<config\> parameter is present in the command line then this file is used to *configfile.h. If an -f \<config\> parameter is present in the command line
* update the defaults of DEFAULTCONFIGFILENAME. There can be more than one -f parameters *then this file is used to update the defaults of DEFAULTCONFIGFILENAME. There
* present. If -p <ParameterName = ParameterValue> parameters are present then these *can be more than one -f parameters present. If -p <ParameterName =
* override the default and the additional config file's settings, and are themselves *ParameterValue> parameters are present then these override the default and the
* overridden by future -p parameters. There must be whitespace between -f and -p commands *additional config file's settings, and are themselves overridden by future -p
* and their respective parameters *parameters. There must be whitespace between -f and -p commands and their
*respective parameters
*********************************************************************** ***********************************************************************
*/ */
@ -60,13 +58,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "global.h"
#include "memalloc.h"
#include "config_common.h" #include "config_common.h"
#include "configfile.h" #include "configfile.h"
#define MAX_ITEMS_TO_PARSE 10000 #include "global.h"
#include "memalloc.h"
#define MAX_ITEMS_TO_PARSE 10000
static void PatchInp (InputParameters *p_Inp); static void PatchInp(InputParameters *p_Inp);
/*! /*!
*********************************************************************** ***********************************************************************
@ -74,43 +72,46 @@ static void PatchInp (InputParameters *p_Inp);
* print help message and exit * print help message and exit
*********************************************************************** ***********************************************************************
*/ */
void JMDecHelpExit (void) void JMDecHelpExit(void) {
{ fprintf(
fprintf( stderr, "\n ldecod [-h] [-d defdec.cfg] {[-f curenc1.cfg]...[-f curencN.cfg]}" stderr,
" {[-p EncParam1=EncValue1]..[-p EncParamM=EncValueM]}\n\n" "\n ldecod [-h] [-d defdec.cfg] {[-f curenc1.cfg]...[-f curencN.cfg]}"
"## Parameters\n\n" " {[-p EncParam1=EncValue1]..[-p EncParamM=EncValueM]}\n\n"
"## Parameters\n\n"
"## Options\n" "## Options\n"
" -h : prints function usage\n" " -h : prints function usage\n"
" -d : use <defdec.cfg> as default file for parameter initializations.\n" " -d : use <defdec.cfg> as default file for parameter "
" If not used then file defaults to encoder.cfg in local directory.\n" "initializations.\n"
" -f : read <curencM.cfg> for reseting selected encoder parameters.\n" " If not used then file defaults to encoder.cfg in local "
" Multiple files could be used that set different parameters\n" "directory.\n"
" -p : Set parameter <DecParamM> to <DecValueM>.\n" " -f : read <curencM.cfg> for reseting selected encoder parameters.\n"
" See default decoder.cfg file for description of all parameters.\n\n" " Multiple files could be used that set different parameters\n"
" -p : Set parameter <DecParamM> to <DecValueM>.\n"
" See default decoder.cfg file for description of all "
"parameters.\n\n"
"## Examples of usage:\n" "## Examples of usage:\n"
" ldecod\n" " ldecod\n"
" ldecod -h\n" " ldecod -h\n"
" ldecod -d default.cfg\n" " ldecod -d default.cfg\n"
" ldecod -f curenc1.cfg\n" " ldecod -f curenc1.cfg\n"
" ldecod -f curenc1.cfg -p InputFile=\"e:\\data\\container_qcif_30.264\" -p OutputFile=\"dec.yuv\" -p RefFile=\"Rec.yuv\"\n"); " ldecod -f curenc1.cfg -p "
"InputFile=\"e:\\data\\container_qcif_30.264\" -p OutputFile=\"dec.yuv\" "
"-p RefFile=\"Rec.yuv\"\n");
exit(-1); exit(-1);
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* exit with error message if reading from config file failed * exit with error message if reading from config file failed
************************************************************************ ************************************************************************
*/ */
static inline void conf_read_check (int val, int expected) static inline void conf_read_check(int val, int expected) {
{ if (val != expected) {
if (val != expected) error("init_conf: error reading from config file", 500);
{
error ("init_conf: error reading from config file", 500);
} }
} }
@ -128,16 +129,13 @@ static inline void conf_read_check (int val, int expected)
* command line parameters * command line parameters
*********************************************************************** ***********************************************************************
*/ */
void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) {
{
char *content = NULL; char *content = NULL;
int CLcount, ContentLen, NumberParams; int CLcount, ContentLen, NumberParams;
char *filename=DEFAULTCONFIGFILENAME; char *filename = DEFAULTCONFIGFILENAME;
if (ac==2) if (ac == 2) {
{ if (0 == strncmp(av[1], "-v", 2)) {
if (0 == strncmp (av[1], "-v", 2))
{
#if !defined(SPEC) #if !defined(SPEC)
printf("JM " JM ": compiled " __DATE__ " " __TIME__ "\n"); printf("JM " JM ": compiled " __DATE__ " " __TIME__ "\n");
#else #else
@ -146,103 +144,99 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[])
exit(-1); exit(-1);
} }
if (0 == strncmp (av[1], "-h", 2)) if (0 == strncmp(av[1], "-h", 2)) {
{
JMDecHelpExit(); JMDecHelpExit();
} }
} }
memset (&cfgparams, 0, sizeof (InputParameters)); memset(&cfgparams, 0, sizeof(InputParameters));
//Set default parameters. // Set default parameters.
printf ("Setting Default Parameters...\n"); printf("Setting Default Parameters...\n");
InitParams(Map); InitParams(Map);
// Process default config file // Process default config file
CLcount = 1; CLcount = 1;
if (ac>=3) if (ac >= 3) {
{ if (0 == strncmp(av[1], "-d", 2)) {
if (0 == strncmp (av[1], "-d", 2)) if (0 == strncmp(av[2], "null", 4))
{ filename = NULL;
if(0 == strncmp (av[2], "null", 4))
filename=NULL;
else else
filename=av[2]; filename = av[2];
CLcount = 3; CLcount = 3;
} }
if (0 == strncmp (av[1], "-h", 2)) if (0 == strncmp(av[1], "-h", 2)) {
{
JMDecHelpExit(); JMDecHelpExit();
} }
} }
if(filename) if (filename) {
{ printf("Parsing Configfile %s\n", filename);
printf ("Parsing Configfile %s\n", filename); content = GetConfigFileContent(filename);
content = GetConfigFileContent (filename); if (NULL != content) {
if (NULL != content) // error (errortext, 300);
{ ParseContent(p_Inp, Map, content, (int)strlen(content));
//error (errortext, 300); printf("\n");
ParseContent (p_Inp, Map, content, (int) strlen(content)); free(content);
printf ("\n");
free (content);
} }
} }
// Parse the command line // Parse the command line
while (CLcount < ac) while (CLcount < ac) {
{ if (0 == strncmp(av[CLcount], "-h", 2)) {
if (0 == strncmp (av[CLcount], "-h", 2))
{
JMDecHelpExit(); JMDecHelpExit();
} }
if (0 == strncmp (av[CLcount], "-f", 2) || 0 == strncmp (av[CLcount], "-F", 2)) // A file parameter? if (0 == strncmp(av[CLcount], "-f", 2) ||
0 == strncmp(av[CLcount], "-F", 2)) // A file parameter?
{ {
content = GetConfigFileContent (av[CLcount+1]); content = GetConfigFileContent(av[CLcount + 1]);
if (NULL==content) if (NULL == content)
error (errortext, 300); error(errortext, 300);
printf ("Parsing Configfile %s", av[CLcount+1]); printf("Parsing Configfile %s", av[CLcount + 1]);
ParseContent (p_Inp, Map, content, (int) strlen (content)); ParseContent(p_Inp, Map, content, (int)strlen(content));
printf ("\n"); printf("\n");
free (content); free(content);
CLcount += 2; CLcount += 2;
} } else if (0 == strncmp(av[CLcount], "-i", 2) ||
else if (0 == strncmp (av[CLcount], "-i", 2) || 0 == strncmp (av[CLcount], "-I", 2)) // A file parameter? 0 == strncmp(av[CLcount], "-I", 2)) // A file parameter?
{ {
strncpy(p_Inp->infile, av[CLcount+1], FILE_NAME_SIZE); strncpy(p_Inp->infile, av[CLcount + 1], FILE_NAME_SIZE);
CLcount += 2; CLcount += 2;
} } else if (0 == strncmp(av[CLcount], "-r", 2) ||
else if (0 == strncmp (av[CLcount], "-r", 2) || 0 == strncmp (av[CLcount], "-R", 2)) // A file parameter? 0 == strncmp(av[CLcount], "-R", 2)) // A file parameter?
{ {
strncpy(p_Inp->reffile, av[CLcount+1], FILE_NAME_SIZE); strncpy(p_Inp->reffile, av[CLcount + 1], FILE_NAME_SIZE);
CLcount += 2; CLcount += 2;
} } else if (0 == strncmp(av[CLcount], "-o", 2) ||
else if (0 == strncmp (av[CLcount], "-o", 2) || 0 == strncmp (av[CLcount], "-O", 2)) // A file parameter? 0 == strncmp(av[CLcount], "-O", 2)) // A file parameter?
{ {
strncpy(p_Inp->outfile, av[CLcount+1], FILE_NAME_SIZE); strncpy(p_Inp->outfile, av[CLcount + 1], FILE_NAME_SIZE);
CLcount += 2; CLcount += 2;
} } else if (0 == strncmp(av[CLcount], "-s", 2) ||
else if (0 == strncmp (av[CLcount], "-s", 2) || 0 == strncmp (av[CLcount], "-S", 2)) // A file parameter? 0 == strncmp(av[CLcount], "-S", 2)) // A file parameter?
{ {
p_Inp->silent = 1; p_Inp->silent = 1;
CLcount += 1; CLcount += 1;
} } else if (0 == strncmp(av[CLcount], "-n", 2) ||
else if (0 == strncmp (av[CLcount], "-n", 2) || 0 == strncmp (av[CLcount], "-N", 2)) // A file parameter? 0 == strncmp(av[CLcount], "-N", 2)) // A file parameter?
{ {
conf_read_check (sscanf(av[CLcount+1],"%d", &p_Inp->iDecFrmNum), 1); conf_read_check(sscanf(av[CLcount + 1], "%d", &p_Inp->iDecFrmNum), 1);
CLcount += 2; CLcount += 2;
} }
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
else if (0 == strncmp (av[CLcount], "-mpr", 4) || 0 == strncmp (av[CLcount], "-MPR", 4)) // A file parameter? else if (0 == strncmp(av[CLcount], "-mpr", 4) ||
0 == strncmp(av[CLcount], "-MPR", 4)) // A file parameter?
{ {
conf_read_check (sscanf(av[CLcount+1],"%d", &p_Inp->DecodeAllLayers), 1); conf_read_check(sscanf(av[CLcount + 1], "%d", &p_Inp->DecodeAllLayers),
1);
CLcount += 2; CLcount += 2;
} }
#endif #endif
else if (0 == strncmp (av[CLcount], "-p", 2) || 0 == strncmp (av[CLcount], "-P", 2)) // A config change? else if (0 == strncmp(av[CLcount], "-p", 2) ||
0 == strncmp(av[CLcount], "-P", 2)) // A config change?
{ {
// Collect all data until next parameter (starting with -<x> (x is any character)), // Collect all data until next parameter (starting with -<x> (x is any
// put it into content, and parse content. // character)), put it into content, and parse content.
++CLcount; ++CLcount;
ContentLen = 0; ContentLen = 0;
@ -250,46 +244,49 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[])
// determine the necessary size for content // determine the necessary size for content
while (NumberParams < ac && av[NumberParams][0] != '-') while (NumberParams < ac && av[NumberParams][0] != '-')
ContentLen += (int) strlen (av[NumberParams++]); // Space for all the strings ContentLen +=
ContentLen += 1000; // Additional 1000 bytes for spaces and \0s (int)strlen(av[NumberParams++]); // Space for all the strings
ContentLen += 1000; // Additional 1000 bytes for spaces and \0s
if ((content = malloc(ContentLen)) == NULL)
if ((content = malloc (ContentLen))==NULL) no_mem_exit("Configure: content");; no_mem_exit("Configure: content");
;
content[0] = '\0'; content[0] = '\0';
// concatenate all parameters identified before // concatenate all parameters identified before
while (CLcount < NumberParams) while (CLcount < NumberParams) {
{
char *source = &av[CLcount][0]; char *source = &av[CLcount][0];
char *destin = &content[(int) strlen (content)]; char *destin = &content[(int)strlen(content)];
while (*source != '\0') while (*source != '\0') {
{ if (*source ==
if (*source == '=') // The Parser expects whitespace before and after '=' '=') // The Parser expects whitespace before and after '='
{ {
*destin++=' '; *destin++='='; *destin++=' '; // Hence make sure we add it *destin++ = ' ';
} *destin++ = '=';
else *destin++ = ' '; // Hence make sure we add it
*destin++=*source; } else
*destin++ = *source;
source++; source++;
} }
*destin = '\0'; *destin = '\0';
CLcount++; CLcount++;
} }
printf ("Parsing command line string '%s'", content); printf("Parsing command line string '%s'", content);
ParseContent (p_Inp, Map, content, (int) strlen(content)); ParseContent(p_Inp, Map, content, (int)strlen(content));
free (content); free(content);
printf ("\n"); printf("\n");
} } else {
else snprintf(errortext, ET_SIZE,
{ "Error in command line, ac %d, around string '%s', missing -f "
snprintf (errortext, ET_SIZE, "Error in command line, ac %d, around string '%s', missing -f or -p parameters?", CLcount, av[CLcount]); "or -p parameters?",
error (errortext, 300); CLcount, av[CLcount]);
error(errortext, 300);
} }
} }
printf ("\n"); printf("\n");
PatchInp(p_Inp); PatchInp(p_Inp);
cfgparams = *p_Inp; cfgparams = *p_Inp;
p_Inp->enable_32_pulldown = 0; p_Inp->enable_32_pulldown = 0;
@ -297,19 +294,15 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[])
DisplayParams(Map, "Decoder Parameters"); DisplayParams(Map, "Decoder Parameters");
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* Checks the input parameters for consistency. * Checks the input parameters for consistency.
*********************************************************************** ***********************************************************************
*/ */
static void PatchInp (InputParameters *p_Inp) static void PatchInp(InputParameters *p_Inp) {
{ // int i;
//int i; // int storedBplus1;
//int storedBplus1;
TestParams(Map, NULL); TestParams(Map, NULL);
} }

View file

@ -7,7 +7,8 @@
* CABAC context initializations * CABAC context initializations
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Detlev Marpe <marpe@hhi.de> * - Detlev Marpe <marpe@hhi.de>
* - Heiko Schwarz <hschwarz@hhi.de> * - Heiko Schwarz <hschwarz@hhi.de>
************************************************************************************** **************************************************************************************
@ -15,108 +16,127 @@
#define CONTEXT_INI_C #define CONTEXT_INI_C
#include "defines.h"
#include "global.h"
#include "biaridecod.h" #include "biaridecod.h"
#include "ctx_tables.h" #include "ctx_tables.h"
#include "defines.h"
#include "global.h"
#define IBIARI_CTX_INIT2(ii, jj, ctx, tab, num, qp) \
{ \
for (i = 0; i < ii; ++i) \
for (j = 0; j < jj; ++j) { \
biari_init_context(qp, &(ctx[i][j]), tab##_I[num][i][j]); \
} \
}
#define IBIARI_CTX_INIT2(ii,jj,ctx,tab,num, qp) \ #define PBIARI_CTX_INIT2(ii, jj, ctx, tab, num, qp) \
{ \ { \
for (i=0; i<ii; ++i) \ for (i = 0; i < ii; ++i) \
for (j=0; j<jj; ++j) \ for (j = 0; j < jj; ++j) { \
{ \ biari_init_context(qp, &(ctx[i][j]), tab##_P[num][i][j]); \
biari_init_context (qp, &(ctx[i][j]), tab ## _I[num][i][j]); \ } \
} \ }
}
#define PBIARI_CTX_INIT2(ii,jj,ctx,tab,num, qp) \ #define IBIARI_CTX_INIT1(jj, ctx, tab, num, qp) \
{ \ { \
for (i=0; i<ii; ++i) \ for (j = 0; j < jj; ++j) { \
for (j=0; j<jj; ++j) \ biari_init_context(qp, &(ctx[j]), tab##_I[num][0][j]); \
{ \ } \
biari_init_context (qp, &(ctx[i][j]), tab ## _P[num][i][j]); \ }
} \
}
#define PBIARI_CTX_INIT1(jj, ctx, tab, num, qp) \
{{for (j = 0; j < jj; \
++j){biari_init_context(qp, &(ctx[j]), tab##_P[num][0][j]); \
} \
} \
}
#define IBIARI_CTX_INIT1(jj,ctx,tab,num, qp) \ void init_contexts(Slice *currSlice) {
{ \ MotionInfoContexts *mc = currSlice->mot_ctx;
for (j=0; j<jj; ++j) \ TextureInfoContexts *tc = currSlice->tex_ctx;
{ \
biari_init_context (qp, &(ctx[j]), tab ## _I[num][0][j]); \
} \
}
#define PBIARI_CTX_INIT1(jj,ctx,tab,num, qp) \
{ \
{ \
for (j=0; j<jj; ++j) \
{ \
biari_init_context (qp, &(ctx[j]), tab ## _P[num][0][j]); \
} \
} \
}
void init_contexts (Slice *currSlice)
{
MotionInfoContexts* mc = currSlice->mot_ctx;
TextureInfoContexts* tc = currSlice->tex_ctx;
int i, j; int i, j;
int qp = imax(0, currSlice->qp); //p_Vid->qp); int qp = imax(0, currSlice->qp); // p_Vid->qp);
int model_number = currSlice->model_number; int model_number = currSlice->model_number;
//printf("%d -", p_Vid->currentSlice->model_number); // printf("%d -", p_Vid->currentSlice->model_number);
//--- motion coding contexts --- //--- motion coding contexts ---
if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE)) if ((currSlice->slice_type == I_SLICE) ||
{ (currSlice->slice_type == SI_SLICE)) {
IBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); IBIARI_CTX_INIT2(3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE,
IBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); model_number, qp);
IBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); IBIARI_CTX_INIT2(2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE,
IBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); model_number, qp);
IBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); IBIARI_CTX_INIT2(2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES,
IBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); model_number, qp);
IBIARI_CTX_INIT2(2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO,
model_number, qp);
IBIARI_CTX_INIT1(NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP,
model_number, qp);
IBIARI_CTX_INIT1(NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF,
model_number, qp);
//--- texture coding contexts --- //--- texture coding contexts ---
IBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); IBIARI_CTX_INIT1(NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts,
IBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); INIT_TRANSFORM_SIZE, model_number, qp);
IBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); IBIARI_CTX_INIT1(NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp);
IBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); IBIARI_CTX_INIT1(NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number,
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); qp);
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); IBIARI_CTX_INIT2(3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number,
qp);
IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts,
INIT_BCBP, model_number, qp);
IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0],
INIT_MAP, model_number, qp);
#if ENABLE_FIELD_CTX #if ENABLE_FIELD_CTX
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1],
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); INIT_FLD_MAP, model_number, qp);
IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1],
INIT_FLD_LAST, model_number, qp);
#endif #endif
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0],
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); INIT_LAST, model_number, qp);
IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE,
} model_number, qp);
else IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS,
{ model_number, qp);
PBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); } else {
PBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); PBIARI_CTX_INIT2(3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE,
PBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); model_number, qp);
PBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); PBIARI_CTX_INIT2(2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE,
PBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); model_number, qp);
PBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); PBIARI_CTX_INIT2(2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES,
model_number, qp);
PBIARI_CTX_INIT2(2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO,
model_number, qp);
PBIARI_CTX_INIT1(NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP,
model_number, qp);
PBIARI_CTX_INIT1(NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF,
model_number, qp);
//--- texture coding contexts --- //--- texture coding contexts ---
PBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); PBIARI_CTX_INIT1(NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts,
PBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); INIT_TRANSFORM_SIZE, model_number, qp);
PBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); PBIARI_CTX_INIT1(NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp);
PBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); PBIARI_CTX_INIT1(NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number,
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); qp);
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); PBIARI_CTX_INIT2(3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number,
qp);
PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts,
INIT_BCBP, model_number, qp);
PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0],
INIT_MAP, model_number, qp);
#if ENABLE_FIELD_CTX #if ENABLE_FIELD_CTX
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1],
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); INIT_FLD_MAP, model_number, qp);
PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1],
INIT_FLD_LAST, model_number, qp);
#endif #endif
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0],
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); INIT_LAST, model_number, qp);
PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE,
model_number, qp);
PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS,
model_number, qp);
} }
} }

View file

@ -4,9 +4,10 @@
* \file * \file
* decoder_test.c * decoder_test.c
* \brief * \brief
* H.264/AVC decoder test * H.264/AVC decoder test
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Yuwen He <yhe@dolby.com> * - Yuwen He <yhe@dolby.com>
*********************************************************************** ***********************************************************************
*/ */
@ -15,44 +16,44 @@
#include <sys/stat.h> #include <sys/stat.h>
//#include "global.h" // #include "global.h"
#include "h264decoder.h"
#include "configfile.h" #include "configfile.h"
#include "h264decoder.h"
#define DECOUTPUT_TEST 0 #define DECOUTPUT_TEST 0
#define PRINT_OUTPUT_POC 0 #define PRINT_OUTPUT_POC 0
#define BITSTREAM_FILENAME "test.264" #define BITSTREAM_FILENAME "test.264"
#define DECRECON_FILENAME "test_dec.yuv" #define DECRECON_FILENAME "test_dec.yuv"
#define ENCRECON_FILENAME "test_rec.yuv" #define ENCRECON_FILENAME "test_rec.yuv"
#define DECOUTPUT_VIEW0_FILENAME "H264_Decoder_Output_View0.yuv" #define DECOUTPUT_VIEW0_FILENAME "H264_Decoder_Output_View0.yuv"
#define DECOUTPUT_VIEW1_FILENAME "H264_Decoder_Output_View1.yuv" #define DECOUTPUT_VIEW1_FILENAME "H264_Decoder_Output_View1.yuv"
static void Configure(InputParameters *p_Inp, int ac, char *av[]) {
static void Configure(InputParameters *p_Inp, int ac, char *av[]) // char *config_filename=NULL;
{ // char errortext[ET_SIZE];
//char *config_filename=NULL;
//char errortext[ET_SIZE];
memset(p_Inp, 0, sizeof(InputParameters)); memset(p_Inp, 0, sizeof(InputParameters));
strcpy(p_Inp->infile, BITSTREAM_FILENAME); //! set default bitstream name strcpy(p_Inp->infile, BITSTREAM_FILENAME); //! set default bitstream name
strcpy(p_Inp->outfile, DECRECON_FILENAME); //! set default output file name strcpy(p_Inp->outfile, DECRECON_FILENAME); //! set default output file name
strcpy(p_Inp->reffile, ENCRECON_FILENAME); //! set default reference file name strcpy(p_Inp->reffile, ENCRECON_FILENAME); //! set default reference file name
p_Inp->FileFormat = PAR_OF_ANNEXB; p_Inp->FileFormat = PAR_OF_ANNEXB;
p_Inp->ref_offset=0; p_Inp->ref_offset = 0;
p_Inp->poc_scale=2; p_Inp->poc_scale = 2;
p_Inp->silent = FALSE; p_Inp->silent = FALSE;
p_Inp->intra_profile_deblocking = 0; p_Inp->intra_profile_deblocking = 0;
#ifdef _LEAKYBUCKET_ #ifdef _LEAKYBUCKET_
p_Inp->R_decoder=500000; //! Decoder rate p_Inp->R_decoder = 500000; //! Decoder rate
p_Inp->B_decoder=104000; //! Decoder buffer size p_Inp->B_decoder = 104000; //! Decoder buffer size
p_Inp->F_decoder=73000; //! Decoder initial delay p_Inp->F_decoder = 73000; //! Decoder initial delay
strcpy(p_Inp->LeakyBucketParamFile,"leakybucketparam.cfg"); // file where Leaky Bucket parameters (computed by encoder) are stored strcpy(p_Inp->LeakyBucketParamFile,
"leakybucketparam.cfg"); // file where Leaky Bucket parameters
// (computed by encoder) are stored
#endif #endif
p_Inp->iDecFrmNum = 0; p_Inp->iDecFrmNum = 0;
p_Inp->write_uv=1; p_Inp->write_uv = 1;
// picture error concealment // picture error concealment
p_Inp->conceal_mode = 0; p_Inp->conceal_mode = 0;
p_Inp->ref_poc_gap = 2; p_Inp->ref_poc_gap = 2;
@ -60,116 +61,123 @@ static void Configure(InputParameters *p_Inp, int ac, char *av[])
ParseCommand(p_Inp, ac, av); ParseCommand(p_Inp, ac, av);
fprintf(stdout,"----------------------------- JM %s %s -----------------------------\n", VERSION, EXT_VERSION); fprintf(
//fprintf(stdout," Decoder config file : %s \n",config_filename); stdout,
if(!p_Inp->bDisplayDecParams) "----------------------------- JM %s %s -----------------------------\n",
{ VERSION, EXT_VERSION);
fprintf(stdout,"--------------------------------------------------------------------------\n"); // fprintf(stdout," Decoder config file : %s
fprintf(stdout," Input H.264 bitstream : %s \n",p_Inp->infile); // \n",config_filename);
fprintf(stdout," Output decoded YUV : %s \n",p_Inp->outfile); if (!p_Inp->bDisplayDecParams) {
//fprintf(stdout," Output status file : %s \n",LOGFILE); fprintf(stdout, "----------------------------------------------------------"
fprintf(stdout," Input reference file : %s \n",p_Inp->reffile); "----------------\n");
fprintf(stdout, " Input H.264 bitstream : %s \n",
p_Inp->infile);
fprintf(stdout, " Output decoded YUV : %s \n",
p_Inp->outfile);
// fprintf(stdout," Output status file : %s
// \n",LOGFILE);
fprintf(stdout, " Input reference file : %s \n",
p_Inp->reffile);
fprintf(stdout,"--------------------------------------------------------------------------\n"); fprintf(stdout, "----------------------------------------------------------"
#ifdef _LEAKYBUCKET_ "----------------\n");
fprintf(stdout," Rate_decoder : %8ld \n",p_Inp->R_decoder); #ifdef _LEAKYBUCKET_
fprintf(stdout," B_decoder : %8ld \n",p_Inp->B_decoder); fprintf(stdout, " Rate_decoder : %8ld \n", p_Inp->R_decoder);
fprintf(stdout," F_decoder : %8ld \n",p_Inp->F_decoder); fprintf(stdout, " B_decoder : %8ld \n", p_Inp->B_decoder);
fprintf(stdout," LeakyBucketParamFile: %s \n",p_Inp->LeakyBucketParamFile); // Leaky Bucket Param file fprintf(stdout, " F_decoder : %8ld \n", p_Inp->F_decoder);
fprintf(stdout, " LeakyBucketParamFile: %s \n",
p_Inp->LeakyBucketParamFile); // Leaky Bucket Param file
calc_buffer(p_Inp); calc_buffer(p_Inp);
fprintf(stdout,"--------------------------------------------------------------------------\n"); fprintf(stdout, "----------------------------------------------------------"
#endif "----------------\n");
#endif
} }
if (!p_Inp->silent) if (!p_Inp->silent) {
{ fprintf(stdout, "POC must = frame# or field# for SNRs to be correct\n");
fprintf(stdout,"POC must = frame# or field# for SNRs to be correct\n"); fprintf(stdout, "----------------------------------------------------------"
fprintf(stdout,"--------------------------------------------------------------------------\n"); "----------------\n");
fprintf(stdout," Frame POC Pic# QP SnrY SnrU SnrV Y:U:V Time(ms)\n"); fprintf(stdout, " Frame POC Pic# QP SnrY SnrU SnrV "
fprintf(stdout,"--------------------------------------------------------------------------\n"); " Y:U:V Time(ms)\n");
fprintf(stdout, "----------------------------------------------------------"
"----------------\n");
} }
} }
/********************************************************* /*********************************************************
if bOutputAllFrames is 1, then output all valid frames to file onetime; if bOutputAllFrames is 1, then output all valid frames to file onetime;
else output the first valid frame and move the buffer to the end of list; else output the first valid frame and move the buffer to the end of list;
*********************************************************/ *********************************************************/
static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOutput1, int bOutputAllFrames) static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0,
{ int hFileOutput1, int bOutputAllFrames) {
int iOutputFrame=0; int iOutputFrame = 0;
DecodedPicList *pPic = pDecPic; DecodedPicList *pPic = pDecPic;
if(pPic && (((pPic->iYUVStorageFormat==2) && pPic->bValid==3) || ((pPic->iYUVStorageFormat!=2) && pPic->bValid==1)) ) if (pPic && (((pPic->iYUVStorageFormat == 2) && pPic->bValid == 3) ||
{ ((pPic->iYUVStorageFormat != 2) && pPic->bValid == 1))) {
int i, iWidth, iHeight, iStride, iWidthUV, iHeightUV, iStrideUV; int i, iWidth, iHeight, iStride, iWidthUV, iHeightUV, iStrideUV;
byte *pbBuf; byte *pbBuf;
int hFileOutput; int hFileOutput;
iWidth = pPic->iWidth*((pPic->iBitDepth+7)>>3); iWidth = pPic->iWidth * ((pPic->iBitDepth + 7) >> 3);
iHeight = pPic->iHeight; iHeight = pPic->iHeight;
iStride = pPic->iYBufStride; iStride = pPic->iYBufStride;
if(pPic->iYUVFormat != YUV444) if (pPic->iYUVFormat != YUV444)
iWidthUV = pPic->iWidth>>1; iWidthUV = pPic->iWidth >> 1;
else else
iWidthUV = pPic->iWidth; iWidthUV = pPic->iWidth;
if(pPic->iYUVFormat == YUV420) if (pPic->iYUVFormat == YUV420)
iHeightUV = pPic->iHeight>>1; iHeightUV = pPic->iHeight >> 1;
else else
iHeightUV = pPic->iHeight; iHeightUV = pPic->iHeight;
iWidthUV *= ((pPic->iBitDepth+7)>>3); iWidthUV *= ((pPic->iBitDepth + 7) >> 3);
iStrideUV = pPic->iUVBufStride; iStrideUV = pPic->iUVBufStride;
do do {
{ if (pPic->iYUVStorageFormat == 2)
if(pPic->iYUVStorageFormat==2) hFileOutput = (pPic->iViewId & 0xffff) ? hFileOutput1 : hFileOutput0;
hFileOutput = (pPic->iViewId&0xffff)? hFileOutput1 : hFileOutput0;
else else
hFileOutput = hFileOutput0; hFileOutput = hFileOutput0;
if(hFileOutput >=0) if (hFileOutput >= 0) {
{ // Y;
//Y;
pbBuf = pPic->pY; pbBuf = pPic->pY;
for(i=0; i<iHeight; i++) for (i = 0; i < iHeight; i++)
write(hFileOutput, pbBuf+i*iStride, iWidth); write(hFileOutput, pbBuf + i * iStride, iWidth);
if(pPic->iYUVFormat != YUV400) if (pPic->iYUVFormat != YUV400) {
{ // U;
//U; pbBuf = pPic->pU;
pbBuf = pPic->pU; for (i = 0; i < iHeightUV; i++)
for(i=0; i<iHeightUV; i++) write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV);
write(hFileOutput, pbBuf+i*iStrideUV, iWidthUV); // V;
//V; pbBuf = pPic->pV;
pbBuf = pPic->pV; for (i = 0; i < iHeightUV; i++)
for(i=0; i<iHeightUV; i++) write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV);
write(hFileOutput, pbBuf+i*iStrideUV, iWidthUV);
} }
iOutputFrame++; iOutputFrame++;
} }
if((pPic->iYUVStorageFormat==2)) if ((pPic->iYUVStorageFormat == 2)) {
{ hFileOutput =
hFileOutput = ((pPic->iViewId>>16)&0xffff)? hFileOutput1 : hFileOutput0; ((pPic->iViewId >> 16) & 0xffff) ? hFileOutput1 : hFileOutput0;
if(hFileOutput>=0) if (hFileOutput >= 0) {
{ int iPicSize = iHeight * iStride;
int iPicSize =iHeight*iStride; // Y;
//Y; pbBuf = pPic->pY + iPicSize;
pbBuf = pPic->pY+iPicSize; for (i = 0; i < iHeight; i++)
for(i=0; i<iHeight; i++) write(hFileOutput, pbBuf + i * iStride, iWidth);
write(hFileOutput, pbBuf+i*iStride, iWidth);
if(pPic->iYUVFormat != YUV400) if (pPic->iYUVFormat != YUV400) {
{ iPicSize = iHeightUV * iStrideUV;
iPicSize = iHeightUV*iStrideUV; // U;
//U; pbBuf = pPic->pU + iPicSize;
pbBuf = pPic->pU+iPicSize; for (i = 0; i < iHeightUV; i++)
for(i=0; i<iHeightUV; i++) write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV);
write(hFileOutput, pbBuf+i*iStrideUV, iWidthUV); // V;
//V; pbBuf = pPic->pV + iPicSize;
pbBuf = pPic->pV+iPicSize; for (i = 0; i < iHeightUV; i++)
for(i=0; i<iHeightUV; i++) write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV);
write(hFileOutput, pbBuf+i*iStrideUV, iWidthUV);
} }
iOutputFrame++; iOutputFrame++;
@ -181,7 +189,7 @@ static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOut
#endif #endif
pPic->bValid = 0; pPic->bValid = 0;
pPic = pPic->pNext; pPic = pPic->pNext;
}while(pPic != NULL && pPic->bValid && bOutputAllFrames); } while (pPic != NULL && pPic->bValid && bOutputAllFrames);
} }
#if PRINT_OUTPUT_POC #if PRINT_OUTPUT_POC
else else
@ -197,65 +205,62 @@ static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOut
* main function for JM decoder * main function for JM decoder
*********************************************************************** ***********************************************************************
*/ */
int main(int argc, char **argv) int main(int argc, char **argv) {
{
int iRet; int iRet;
DecodedPicList *pDecPicList; DecodedPicList *pDecPicList;
int hFileDecOutput0=-1, hFileDecOutput1=-1; int hFileDecOutput0 = -1, hFileDecOutput1 = -1;
int iFramesOutput=0, iFramesDecoded=0; int iFramesOutput = 0, iFramesDecoded = 0;
InputParameters InputParams; InputParameters InputParams;
#if DECOUTPUT_TEST #if DECOUTPUT_TEST
hFileDecOutput0 = open(DECOUTPUT_VIEW0_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); hFileDecOutput0 =
open(DECOUTPUT_VIEW0_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS);
fprintf(stdout, "Decoder output view0: %s\n", DECOUTPUT_VIEW0_FILENAME); fprintf(stdout, "Decoder output view0: %s\n", DECOUTPUT_VIEW0_FILENAME);
hFileDecOutput1 = open(DECOUTPUT_VIEW1_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); hFileDecOutput1 =
open(DECOUTPUT_VIEW1_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS);
fprintf(stdout, "Decoder output view1: %s\n", DECOUTPUT_VIEW1_FILENAME); fprintf(stdout, "Decoder output view1: %s\n", DECOUTPUT_VIEW1_FILENAME);
#endif #endif
//get input parameters; // get input parameters;
Configure(&InputParams, argc, argv); Configure(&InputParams, argc, argv);
//open decoder; // open decoder;
iRet = OpenDecoder(&InputParams); iRet = OpenDecoder(&InputParams);
if(iRet != DEC_OPEN_NOERR) if (iRet != DEC_OPEN_NOERR) {
{
fprintf(stderr, "Open encoder failed: 0x%x!\n", iRet); fprintf(stderr, "Open encoder failed: 0x%x!\n", iRet);
return -1; //failed; return -1; // failed;
} }
//decoding; // decoding;
do do {
{
iRet = DecodeOneFrame(&pDecPicList); iRet = DecodeOneFrame(&pDecPicList);
if(iRet==DEC_EOS || iRet==DEC_SUCCEED) if (iRet == DEC_EOS || iRet == DEC_SUCCEED) {
{ // process the decoded picture, output or display;
//process the decoded picture, output or display; iFramesOutput +=
iFramesOutput += WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 0); WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 0);
iFramesDecoded++; iFramesDecoded++;
} } else {
else // error handling;
{
//error handling;
fprintf(stderr, "Error in decoding process: 0x%x\n", iRet); fprintf(stderr, "Error in decoding process: 0x%x\n", iRet);
} }
}while((iRet == DEC_SUCCEED) && ((p_Dec->p_Inp->iDecFrmNum==0) || (iFramesDecoded<p_Dec->p_Inp->iDecFrmNum))); } while ((iRet == DEC_SUCCEED) &&
((p_Dec->p_Inp->iDecFrmNum == 0) ||
(iFramesDecoded < p_Dec->p_Inp->iDecFrmNum)));
iRet = FinitDecoder(&pDecPicList); iRet = FinitDecoder(&pDecPicList);
iFramesOutput += WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1 , 1); iFramesOutput +=
WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 1);
iRet = CloseDecoder(); iRet = CloseDecoder();
//quit; // quit;
if(hFileDecOutput0>=0) if (hFileDecOutput0 >= 0) {
{
close(hFileDecOutput0); close(hFileDecOutput0);
} }
if(hFileDecOutput1>=0) if (hFileDecOutput1 >= 0) {
{
close(hFileDecOutput1); close(hFileDecOutput1);
} }
//printf("%d frames are decoded.\n", iFramesDecoded); // printf("%d frames are decoded.\n", iFramesDecoded);
//printf("%d frames are decoded, %d frames output.\n", iFramesDecoded, iFramesOutput); // printf("%d frames are decoded, %d frames output.\n", iFramesDecoded,
// iFramesOutput);
return 0; return 0;
} }

View file

@ -4,7 +4,8 @@
* \file erc_api.c * \file erc_api.c
* *
* \brief * \brief
* External (still inside video decoder) interface for error concealment module * External (still inside video decoder) interface for error concealment
*module
* *
* \author * \author
* - Ari Hourunranta <ari.hourunranta@nokia.com> * - Ari Hourunranta <ari.hourunranta@nokia.com>
@ -14,11 +15,10 @@
************************************************************************************* *************************************************************************************
*/ */
#include "global.h"
#include "memalloc.h"
#include "erc_api.h" #include "erc_api.h"
#include "fast_memory.h" #include "fast_memory.h"
#include "global.h"
#include "memalloc.h"
/*! /*!
************************************************************************ ************************************************************************
@ -26,11 +26,12 @@
* Initinize the error concealment module * Initinize the error concealment module
************************************************************************ ************************************************************************
*/ */
void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag) void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag) {
{
ercClose(p_Vid, p_Vid->erc_errorVar); ercClose(p_Vid, p_Vid->erc_errorVar);
p_Vid->erc_object_list = (objectBuffer_t *) calloc((pic_sizex * pic_sizey) >> 6, sizeof(objectBuffer_t)); p_Vid->erc_object_list = (objectBuffer_t *)calloc(
if (p_Vid->erc_object_list == NULL) no_mem_exit("ercInit: erc_object_list"); (pic_sizex * pic_sizey) >> 6, sizeof(objectBuffer_t));
if (p_Vid->erc_object_list == NULL)
no_mem_exit("ercInit: erc_object_list");
// the error concealment instance is allocated // the error concealment instance is allocated
p_Vid->erc_errorVar = ercOpen(); p_Vid->erc_errorVar = ercOpen();
@ -47,12 +48,12 @@ void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag)
* The allocated ercVariables_t is returned. * The allocated ercVariables_t is returned.
************************************************************************ ************************************************************************
*/ */
ercVariables_t *ercOpen( void ) ercVariables_t *ercOpen(void) {
{
ercVariables_t *errorVar = NULL; ercVariables_t *errorVar = NULL;
errorVar = (ercVariables_t *)malloc( sizeof(ercVariables_t)); errorVar = (ercVariables_t *)malloc(sizeof(ercVariables_t));
if ( errorVar == NULL ) no_mem_exit("ercOpen: errorVar"); if (errorVar == NULL)
no_mem_exit("ercOpen: errorVar");
errorVar->nOfMBs = 0; errorVar->nOfMBs = 0;
errorVar->segments = NULL; errorVar->segments = NULL;
@ -82,49 +83,55 @@ ercVariables_t *ercOpen( void )
* Width of the frame in pixels. * Width of the frame in pixels.
************************************************************************ ************************************************************************
*/ */
void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picSizeX ) void ercReset(ercVariables_t *errorVar, int nOfMBs, int numOfSegments,
{ int picSizeX) {
signed char *tmp = NULL; signed char *tmp = NULL;
int i = 0; int i = 0;
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{
ercSegment_t *segments = NULL; ercSegment_t *segments = NULL;
// If frame size has been changed // If frame size has been changed
if ( nOfMBs != errorVar->nOfMBs && errorVar->yCondition != NULL ) if (nOfMBs != errorVar->nOfMBs && errorVar->yCondition != NULL) {
{ free(errorVar->yCondition);
free( errorVar->yCondition );
errorVar->yCondition = NULL; errorVar->yCondition = NULL;
free( errorVar->prevFrameYCondition ); free(errorVar->prevFrameYCondition);
errorVar->prevFrameYCondition = NULL; errorVar->prevFrameYCondition = NULL;
free( errorVar->uCondition ); free(errorVar->uCondition);
errorVar->uCondition = NULL; errorVar->uCondition = NULL;
free( errorVar->vCondition ); free(errorVar->vCondition);
errorVar->vCondition = NULL; errorVar->vCondition = NULL;
free( errorVar->segments ); free(errorVar->segments);
errorVar->segments = NULL; errorVar->segments = NULL;
} }
// If the structures are uninitialized (first frame, or frame size is changed) // If the structures are uninitialized (first frame, or frame size is
if ( errorVar->yCondition == NULL ) // changed)
{ if (errorVar->yCondition == NULL) {
errorVar->segments = (ercSegment_t *)malloc( numOfSegments*sizeof(ercSegment_t) ); errorVar->segments =
if ( errorVar->segments == NULL ) no_mem_exit("ercReset: errorVar->segments"); (ercSegment_t *)malloc(numOfSegments * sizeof(ercSegment_t));
fast_memset( errorVar->segments, 0, numOfSegments*sizeof(ercSegment_t)); if (errorVar->segments == NULL)
no_mem_exit("ercReset: errorVar->segments");
fast_memset(errorVar->segments, 0, numOfSegments * sizeof(ercSegment_t));
errorVar->nOfSegments = numOfSegments; errorVar->nOfSegments = numOfSegments;
errorVar->yCondition = (signed char *)malloc( 4*nOfMBs*sizeof(signed char) ); errorVar->yCondition =
if ( errorVar->yCondition == NULL ) no_mem_exit("ercReset: errorVar->yCondition"); (signed char *)malloc(4 * nOfMBs * sizeof(signed char));
errorVar->prevFrameYCondition = (signed char *)malloc( 4*nOfMBs*sizeof(signed char) ); if (errorVar->yCondition == NULL)
if ( errorVar->prevFrameYCondition == NULL ) no_mem_exit("ercReset: errorVar->prevFrameYCondition"); no_mem_exit("ercReset: errorVar->yCondition");
errorVar->uCondition = (signed char *)malloc( nOfMBs*sizeof(signed char) ); errorVar->prevFrameYCondition =
if ( errorVar->uCondition == NULL ) no_mem_exit("ercReset: errorVar->uCondition"); (signed char *)malloc(4 * nOfMBs * sizeof(signed char));
errorVar->vCondition = (signed char *)malloc( nOfMBs*sizeof(signed char) ); if (errorVar->prevFrameYCondition == NULL)
if ( errorVar->vCondition == NULL ) no_mem_exit("ercReset: errorVar->vCondition"); no_mem_exit("ercReset: errorVar->prevFrameYCondition");
errorVar->uCondition =
(signed char *)malloc(nOfMBs * sizeof(signed char));
if (errorVar->uCondition == NULL)
no_mem_exit("ercReset: errorVar->uCondition");
errorVar->vCondition =
(signed char *)malloc(nOfMBs * sizeof(signed char));
if (errorVar->vCondition == NULL)
no_mem_exit("ercReset: errorVar->vCondition");
errorVar->nOfMBs = nOfMBs; errorVar->nOfMBs = nOfMBs;
} } else {
else
{
// Store the yCondition struct of the previous frame // Store the yCondition struct of the previous frame
tmp = errorVar->prevFrameYCondition; tmp = errorVar->prevFrameYCondition;
errorVar->prevFrameYCondition = errorVar->yCondition; errorVar->prevFrameYCondition = errorVar->yCondition;
@ -132,26 +139,30 @@ void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picS
} }
// Reset tables and parameters // Reset tables and parameters
fast_memset( errorVar->yCondition, 0, 4*nOfMBs*sizeof(*errorVar->yCondition)); fast_memset(errorVar->yCondition, 0,
fast_memset( errorVar->uCondition, 0, nOfMBs*sizeof(*errorVar->uCondition)); 4 * nOfMBs * sizeof(*errorVar->yCondition));
fast_memset( errorVar->vCondition, 0, nOfMBs*sizeof(*errorVar->vCondition)); fast_memset(errorVar->uCondition, 0,
nOfMBs * sizeof(*errorVar->uCondition));
fast_memset(errorVar->vCondition, 0,
nOfMBs * sizeof(*errorVar->vCondition));
if (errorVar->nOfSegments != numOfSegments) if (errorVar->nOfSegments != numOfSegments) {
{ free(errorVar->segments);
free( errorVar->segments );
errorVar->segments = NULL; errorVar->segments = NULL;
errorVar->segments = (ercSegment_t *)malloc( numOfSegments*sizeof(ercSegment_t) ); errorVar->segments =
if ( errorVar->segments == NULL ) no_mem_exit("ercReset: errorVar->segments"); (ercSegment_t *)malloc(numOfSegments * sizeof(ercSegment_t));
if (errorVar->segments == NULL)
no_mem_exit("ercReset: errorVar->segments");
errorVar->nOfSegments = numOfSegments; errorVar->nOfSegments = numOfSegments;
} }
//memset( errorVar->segments, 0, errorVar->nOfSegments * sizeof(ercSegment_t)); // memset( errorVar->segments, 0, errorVar->nOfSegments *
// sizeof(ercSegment_t));
segments = errorVar->segments; segments = errorVar->segments;
for ( i = 0; i < errorVar->nOfSegments; i++ ) for (i = 0; i < errorVar->nOfSegments; i++) {
{
segments->startMBPos = 0; segments->startMBPos = 0;
segments->endMBPos = (short) (nOfMBs - 1); segments->endMBPos = (short)(nOfMBs - 1);
(segments++)->fCorrupted = 1; //! mark segments as corrupted (segments++)->fCorrupted = 1; //! mark segments as corrupted
} }
@ -171,71 +182,57 @@ void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picS
* Variables for error concealment * Variables for error concealment
************************************************************************ ************************************************************************
*/ */
void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar ) void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar) {
{ if (errorVar != NULL) {
if ( errorVar != NULL ) if (errorVar->yCondition != NULL) {
{ free(errorVar->segments);
if (errorVar->yCondition != NULL) free(errorVar->yCondition);
{ free(errorVar->uCondition);
free( errorVar->segments ); free(errorVar->vCondition);
free( errorVar->yCondition ); free(errorVar->prevFrameYCondition);
free( errorVar->uCondition );
free( errorVar->vCondition );
free( errorVar->prevFrameYCondition );
} }
free( errorVar ); free(errorVar);
errorVar = NULL; errorVar = NULL;
} }
if (p_Vid->erc_object_list) if (p_Vid->erc_object_list) {
{
free(p_Vid->erc_object_list); free(p_Vid->erc_object_list);
p_Vid->erc_object_list=NULL; p_Vid->erc_object_list = NULL;
} }
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Sets error concealment ON/OFF. Can be invoked only between frames, not during a frame * Sets error concealment ON/OFF. Can be invoked only between frames, not
* \param errorVar *during a frame \param errorVar Variables for error concealment \param value
* Variables for error concealment
* \param value
* New value * New value
************************************************************************ ************************************************************************
*/ */
void ercSetErrorConcealment( ercVariables_t *errorVar, int value ) void ercSetErrorConcealment(ercVariables_t *errorVar, int value) {
{ if (errorVar != NULL)
if ( errorVar != NULL )
errorVar->concealment = value; errorVar->concealment = value;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Creates a new segment in the segment-list, and marks the start MB and bit position. * Creates a new segment in the segment-list, and marks the start MB and
* If the end of the previous segment was not explicitly marked by "ercStopSegment", *bit position. If the end of the previous segment was not explicitly marked by
* also marks the end of the previous segment. *"ercStopSegment", also marks the end of the previous segment. If needed, it
* If needed, it reallocates the segment-list for a larger storage place. *reallocates the segment-list for a larger storage place. \param currMBNum The
* \param currMBNum *MB number where the new slice/segment starts \param segment Segment/Slice No.
* The MB number where the new slice/segment starts *counted by the caller \param bitPos Bitstream pointer: number of bits read
* \param segment *from the buffer. \param errorVar Variables for error detector
* Segment/Slice No. counted by the caller
* \param bitPos
* Bitstream pointer: number of bits read from the buffer.
* \param errorVar
* Variables for error detector
************************************************************************ ************************************************************************
*/ */
void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ) void ercStartSegment(int currMBNum, int segment, unsigned int bitPos,
{ ercVariables_t *errorVar) {
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{
errorVar->currSegmentCorrupted = 0; errorVar->currSegmentCorrupted = 0;
errorVar->segments[ segment ].fCorrupted = 0; errorVar->segments[segment].fCorrupted = 0;
errorVar->segments[ segment ].startMBPos = (short) currMBNum; errorVar->segments[segment].startMBPos = (short)currMBNum;
} }
} }
@ -254,11 +251,10 @@ void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariab
* Variables for error detector * Variables for error detector
************************************************************************ ************************************************************************
*/ */
void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ) void ercStopSegment(int currMBNum, int segment, unsigned int bitPos,
{ ercVariables_t *errorVar) {
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{ errorVar->segments[segment].endMBPos = (short)currMBNum;
errorVar->segments[ segment ].endMBPos = (short) currMBNum;
errorVar->currSegment++; errorVar->currSegment++;
} }
} }
@ -274,26 +270,23 @@ void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariabl
* Variables for error detector * Variables for error detector
************************************************************************ ************************************************************************
*/ */
void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar ) void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar) {
{
int j = 0; int j = 0;
int current_segment; int current_segment;
current_segment = errorVar->currSegment-1; current_segment = errorVar->currSegment - 1;
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{ if (errorVar->currSegmentCorrupted == 0) {
if (errorVar->currSegmentCorrupted == 0)
{
errorVar->nOfCorruptedSegments++; errorVar->nOfCorruptedSegments++;
errorVar->currSegmentCorrupted = 1; errorVar->currSegmentCorrupted = 1;
} }
for ( j = errorVar->segments[current_segment].startMBPos; j <= errorVar->segments[current_segment].endMBPos; j++ ) for (j = errorVar->segments[current_segment].startMBPos;
{ j <= errorVar->segments[current_segment].endMBPos; j++) {
errorVar->yCondition[MBNum2YBlock (j, 0, picSizeX)] = ERC_BLOCK_CORRUPTED; errorVar->yCondition[MBNum2YBlock(j, 0, picSizeX)] = ERC_BLOCK_CORRUPTED;
errorVar->yCondition[MBNum2YBlock (j, 1, picSizeX)] = ERC_BLOCK_CORRUPTED; errorVar->yCondition[MBNum2YBlock(j, 1, picSizeX)] = ERC_BLOCK_CORRUPTED;
errorVar->yCondition[MBNum2YBlock (j, 2, picSizeX)] = ERC_BLOCK_CORRUPTED; errorVar->yCondition[MBNum2YBlock(j, 2, picSizeX)] = ERC_BLOCK_CORRUPTED;
errorVar->yCondition[MBNum2YBlock (j, 3, picSizeX)] = ERC_BLOCK_CORRUPTED; errorVar->yCondition[MBNum2YBlock(j, 3, picSizeX)] = ERC_BLOCK_CORRUPTED;
errorVar->uCondition[j] = ERC_BLOCK_CORRUPTED; errorVar->uCondition[j] = ERC_BLOCK_CORRUPTED;
errorVar->vCondition[j] = ERC_BLOCK_CORRUPTED; errorVar->vCondition[j] = ERC_BLOCK_CORRUPTED;
} }
@ -312,21 +305,19 @@ void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar )
* Variables for error detector * Variables for error detector
************************************************************************ ************************************************************************
*/ */
void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ) void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar) {
{
int j = 0; int j = 0;
int current_segment; int current_segment;
current_segment = errorVar->currSegment-1; current_segment = errorVar->currSegment - 1;
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{
// mark all the Blocks belonging to the segment as OK */ // mark all the Blocks belonging to the segment as OK */
for ( j = errorVar->segments[current_segment].startMBPos; j <= errorVar->segments[current_segment].endMBPos; j++ ) for (j = errorVar->segments[current_segment].startMBPos;
{ j <= errorVar->segments[current_segment].endMBPos; j++) {
errorVar->yCondition[MBNum2YBlock (j, 0, picSizeX)] = ERC_BLOCK_OK; errorVar->yCondition[MBNum2YBlock(j, 0, picSizeX)] = ERC_BLOCK_OK;
errorVar->yCondition[MBNum2YBlock (j, 1, picSizeX)] = ERC_BLOCK_OK; errorVar->yCondition[MBNum2YBlock(j, 1, picSizeX)] = ERC_BLOCK_OK;
errorVar->yCondition[MBNum2YBlock (j, 2, picSizeX)] = ERC_BLOCK_OK; errorVar->yCondition[MBNum2YBlock(j, 2, picSizeX)] = ERC_BLOCK_OK;
errorVar->yCondition[MBNum2YBlock (j, 3, picSizeX)] = ERC_BLOCK_OK; errorVar->yCondition[MBNum2YBlock(j, 3, picSizeX)] = ERC_BLOCK_OK;
errorVar->uCondition[j] = ERC_BLOCK_OK; errorVar->uCondition[j] = ERC_BLOCK_OK;
errorVar->vCondition[j] = ERC_BLOCK_OK; errorVar->vCondition[j] = ERC_BLOCK_OK;
} }
@ -337,9 +328,8 @@ void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar )
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Marks the Blocks of the given component (YUV) of the current MB as concealed. * Marks the Blocks of the given component (YUV) of the current MB as
* \param currMBNum *concealed. \param currMBNum Selects the segment where this MB number is in.
* Selects the segment where this MB number is in.
* \param comp * \param comp
* Component to mark (0:Y, 1:U, 2:V, <0:All) * Component to mark (0:Y, 1:U, 2:V, <0:All)
* \param picSizeX * \param picSizeX
@ -348,25 +338,26 @@ void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar )
* Variables for error detector * Variables for error detector
************************************************************************ ************************************************************************
*/ */
void ercMarkCurrMBConcealed( int currMBNum, int comp, int picSizeX, ercVariables_t *errorVar ) void ercMarkCurrMBConcealed(int currMBNum, int comp, int picSizeX,
{ ercVariables_t *errorVar) {
int setAll = 0; int setAll = 0;
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{ if (comp < 0) {
if (comp < 0)
{
setAll = 1; setAll = 1;
comp = 0; comp = 0;
} }
switch (comp) switch (comp) {
{
case 0: case 0:
errorVar->yCondition[MBNum2YBlock (currMBNum, 0, picSizeX)] = ERC_BLOCK_CONCEALED; errorVar->yCondition[MBNum2YBlock(currMBNum, 0, picSizeX)] =
errorVar->yCondition[MBNum2YBlock (currMBNum, 1, picSizeX)] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
errorVar->yCondition[MBNum2YBlock (currMBNum, 2, picSizeX)] = ERC_BLOCK_CONCEALED; errorVar->yCondition[MBNum2YBlock(currMBNum, 1, picSizeX)] =
errorVar->yCondition[MBNum2YBlock (currMBNum, 3, picSizeX)] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
errorVar->yCondition[MBNum2YBlock(currMBNum, 2, picSizeX)] =
ERC_BLOCK_CONCEALED;
errorVar->yCondition[MBNum2YBlock(currMBNum, 3, picSizeX)] =
ERC_BLOCK_CONCEALED;
if (!setAll) if (!setAll)
break; break;
case 1: case 1:

View file

@ -15,11 +15,15 @@
************************************************************************************* *************************************************************************************
*/ */
#include "global.h"
#include "erc_do.h" #include "erc_do.h"
#include "global.h"
static void concealBlocks ( VideoParameters *p_Vid, int lastColumn, int lastRow, int comp, frame *recfr, int picSizeX, signed char *condition ); static void concealBlocks(VideoParameters *p_Vid, int lastColumn, int lastRow,
static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgpel *block, int blockSize, int frameWidth ); int comp, frame *recfr, int picSizeX,
signed char *condition);
static void pixMeanInterpolateBlock(VideoParameters *p_Vid, imgpel *src[],
imgpel *block, int blockSize,
int frameWidth);
/*! /*!
************************************************************************ ************************************************************************
@ -27,9 +31,8 @@ static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgp
* The main function for Intra frame concealment. * The main function for Intra frame concealment.
* Calls "concealBlocks" for each color component (Y,U,V) separately * Calls "concealBlocks" for each color component (Y,U,V) separately
* \return * \return
* 0, if the concealment was not successful and simple concealment should be used * 0, if the concealment was not successful and simple concealment should
* 1, otherwise (even if none of the blocks were concealed) *be used 1, otherwise (even if none of the blocks were concealed) \param p_Vid
* \param p_Vid
* video encoding parameters for current picture * video encoding parameters for current picture
* \param recfr * \param recfr
* Reconstructed frame buffer * Reconstructed frame buffer
@ -41,32 +44,32 @@ static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgp
* Variables for error concealment * Variables for error concealment
************************************************************************ ************************************************************************
*/ */
int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, int picSizeY, ercVariables_t *errorVar ) int ercConcealIntraFrame(VideoParameters *p_Vid, frame *recfr, int picSizeX,
{ int picSizeY, ercVariables_t *errorVar) {
int lastColumn = 0, lastRow = 0; int lastColumn = 0, lastRow = 0;
// if concealment is on // if concealment is on
if ( errorVar && errorVar->concealment ) if (errorVar && errorVar->concealment) {
{
// if there are segments to be concealed // if there are segments to be concealed
if ( errorVar->nOfCorruptedSegments ) if (errorVar->nOfCorruptedSegments) {
{
// Y // Y
lastRow = (int) (picSizeY>>3); lastRow = (int)(picSizeY >> 3);
lastColumn = (int) (picSizeX>>3); lastColumn = (int)(picSizeX >> 3);
concealBlocks( p_Vid, lastColumn, lastRow, 0, recfr, picSizeX, errorVar->yCondition ); concealBlocks(p_Vid, lastColumn, lastRow, 0, recfr, picSizeX,
errorVar->yCondition);
// U (dimensions halved compared to Y) // U (dimensions halved compared to Y)
lastRow = (int) (picSizeY>>4); lastRow = (int)(picSizeY >> 4);
lastColumn = (int) (picSizeX>>4); lastColumn = (int)(picSizeX >> 4);
concealBlocks( p_Vid, lastColumn, lastRow, 1, recfr, picSizeX, errorVar->uCondition ); concealBlocks(p_Vid, lastColumn, lastRow, 1, recfr, picSizeX,
errorVar->uCondition);
// V ( dimensions equal to U ) // V ( dimensions equal to U )
concealBlocks( p_Vid, lastColumn, lastRow, 2, recfr, picSizeX, errorVar->vCondition ); concealBlocks(p_Vid, lastColumn, lastRow, 2, recfr, picSizeX,
errorVar->vCondition);
} }
return 1; return 1;
} } else
else
return 0; return 0;
} }
@ -84,38 +87,42 @@ int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, in
* \param column * \param column
* x coordinate in blocks * x coordinate in blocks
* \param predBlocks[] * \param predBlocks[]
* list of neighboring source blocks (numbering 0 to 7, 1 means: use the neighbor) * list of neighboring source blocks (numbering 0 to 7, 1 means: use the
* \param frameWidth *neighbor) \param frameWidth width of frame in pixels \param mbWidthInBlocks 2
* width of frame in pixels *for Y, 1 for U/V components
* \param mbWidthInBlocks
* 2 for Y, 1 for U/V components
************************************************************************ ************************************************************************
*/ */
void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, int column, int predBlocks[], int frameWidth, int mbWidthInBlocks) void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row,
{ int column, int predBlocks[], int frameWidth,
imgpel *src[8]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; int mbWidthInBlocks) {
imgpel *currBlock = NULL; imgpel *src[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
imgpel *currBlock = NULL;
// collect the reliable neighboring blocks // collect the reliable neighboring blocks
if (predBlocks[0]) if (predBlocks[0])
src[0] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + (column+mbWidthInBlocks)*8; src[0] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 +
if (predBlocks[1]) (column + mbWidthInBlocks) * 8;
src[1] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + (column-mbWidthInBlocks)*8; if (predBlocks[1])
if (predBlocks[2]) src[1] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 +
src[2] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + (column-mbWidthInBlocks)*8; (column - mbWidthInBlocks) * 8;
if (predBlocks[3]) if (predBlocks[2])
src[3] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + (column+mbWidthInBlocks)*8; src[2] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 +
if (predBlocks[4]) (column - mbWidthInBlocks) * 8;
src[4] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + column*8; if (predBlocks[3])
if (predBlocks[5]) src[3] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 +
src[5] = currFrame + row*frameWidth*8 + (column-mbWidthInBlocks)*8; (column + mbWidthInBlocks) * 8;
if (predBlocks[6]) if (predBlocks[4])
src[6] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + column*8; src[4] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 + column * 8;
if (predBlocks[7]) if (predBlocks[5])
src[7] = currFrame + row*frameWidth*8 + (column+mbWidthInBlocks)*8; src[5] = currFrame + row * frameWidth * 8 + (column - mbWidthInBlocks) * 8;
if (predBlocks[6])
src[6] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 + column * 8;
if (predBlocks[7])
src[7] = currFrame + row * frameWidth * 8 + (column + mbWidthInBlocks) * 8;
currBlock = currFrame + row*frameWidth*8 + column*8; currBlock = currFrame + row * frameWidth * 8 + column * 8;
pixMeanInterpolateBlock( p_Vid, src, currBlock, mbWidthInBlocks*8, frameWidth ); pixMeanInterpolateBlock(p_Vid, src, currBlock, mbWidthInBlocks * 8,
frameWidth);
} }
/*! /*!
@ -151,79 +158,80 @@ void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, int co
* No corner neighbors are considered * No corner neighbors are considered
************************************************************************ ************************************************************************
*/ */
int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int ercCollect8PredBlocks(int predBlocks[], int currRow, int currColumn,
int maxRow, int maxColumn, int step, byte fNoCornerNeigh ) signed char *condition, int maxRow, int maxColumn,
{ int step, byte fNoCornerNeigh) {
int srcCounter = 0; int srcCounter = 0;
int srcCountMin = (fNoCornerNeigh ? 2 : 4); int srcCountMin = (fNoCornerNeigh ? 2 : 4);
int threshold = ERC_BLOCK_OK; int threshold = ERC_BLOCK_OK;
memset( predBlocks, 0, 8*sizeof(int) ); memset(predBlocks, 0, 8 * sizeof(int));
// collect the reliable neighboring blocks // collect the reliable neighboring blocks
do do {
{
srcCounter = 0; srcCounter = 0;
// top // top
if (currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn ] >= threshold ) if (currRow > 0 &&
{ //ERC_BLOCK_OK (3) or ERC_BLOCK_CONCEALED (2) condition[(currRow - 1) * maxColumn + currColumn] >=
predBlocks[4] = condition[ (currRow-1)*maxColumn + currColumn ]; threshold) { // ERC_BLOCK_OK (3) or ERC_BLOCK_CONCEALED (2)
predBlocks[4] = condition[(currRow - 1) * maxColumn + currColumn];
srcCounter++; srcCounter++;
} }
// bottom // bottom
if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn ] >= threshold ) if (currRow < (maxRow - step) &&
{ condition[(currRow + step) * maxColumn + currColumn] >= threshold) {
predBlocks[6] = condition[ (currRow+step)*maxColumn + currColumn ]; predBlocks[6] = condition[(currRow + step) * maxColumn + currColumn];
srcCounter++; srcCounter++;
} }
if ( currColumn > 0 ) if (currColumn > 0) {
{
// left // left
if ( condition[ currRow*maxColumn + currColumn - 1 ] >= threshold ) if (condition[currRow * maxColumn + currColumn - 1] >= threshold) {
{ predBlocks[5] = condition[currRow * maxColumn + currColumn - 1];
predBlocks[5] = condition[ currRow*maxColumn + currColumn - 1 ];
srcCounter++; srcCounter++;
} }
if ( !fNoCornerNeigh ) if (!fNoCornerNeigh) {
{
// top-left // top-left
if ( currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn - 1 ] >= threshold ) if (currRow > 0 &&
{ condition[(currRow - 1) * maxColumn + currColumn - 1] >=
predBlocks[1] = condition[ (currRow-1)*maxColumn + currColumn - 1 ]; threshold) {
predBlocks[1] = condition[(currRow - 1) * maxColumn + currColumn - 1];
srcCounter++; srcCounter++;
} }
// bottom-left // bottom-left
if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn - 1 ] >= threshold ) if (currRow < (maxRow - step) &&
{ condition[(currRow + step) * maxColumn + currColumn - 1] >=
predBlocks[2] = condition[ (currRow+step)*maxColumn + currColumn - 1 ]; threshold) {
predBlocks[2] =
condition[(currRow + step) * maxColumn + currColumn - 1];
srcCounter++; srcCounter++;
} }
} }
} }
if ( currColumn < (maxColumn-step) ) if (currColumn < (maxColumn - step)) {
{
// right // right
if ( condition[ currRow*maxColumn+currColumn + step ] >= threshold ) if (condition[currRow * maxColumn + currColumn + step] >= threshold) {
{ predBlocks[7] = condition[currRow * maxColumn + currColumn + step];
predBlocks[7] = condition[ currRow*maxColumn+currColumn + step ];
srcCounter++; srcCounter++;
} }
if ( !fNoCornerNeigh ) if (!fNoCornerNeigh) {
{
// top-right // top-right
if ( currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn + step ] >= threshold ) if (currRow > 0 &&
{ condition[(currRow - 1) * maxColumn + currColumn + step] >=
predBlocks[0] = condition[ (currRow-1)*maxColumn + currColumn + step ]; threshold) {
predBlocks[0] =
condition[(currRow - 1) * maxColumn + currColumn + step];
srcCounter++; srcCounter++;
} }
// bottom-right // bottom-right
if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn + step ] >= threshold ) if (currRow < (maxRow - step) &&
{ condition[(currRow + step) * maxColumn + currColumn + step] >=
predBlocks[3] = condition[ (currRow+step)*maxColumn + currColumn + step ]; threshold) {
predBlocks[3] =
condition[(currRow + step) * maxColumn + currColumn + step];
srcCounter++; srcCounter++;
} }
} }
@ -232,7 +240,7 @@ int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed
threshold--; threshold--;
if (threshold < ERC_BLOCK_CONCEALED) if (threshold < ERC_BLOCK_CONCEALED)
break; break;
} while ( srcCounter < srcCountMin); } while (srcCounter < srcCountMin);
return srcCounter; return srcCounter;
} }
@ -260,20 +268,19 @@ int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed
* in vertical/horizontal direction. (Y:2 U,V:1) * in vertical/horizontal direction. (Y:2 U,V:1)
************************************************************************ ************************************************************************
*/ */
int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int maxRow, int maxColumn, int step ) int ercCollectColumnBlocks(int predBlocks[], int currRow, int currColumn,
{ signed char *condition, int maxRow, int maxColumn,
int step) {
int srcCounter = 0, threshold = ERC_BLOCK_CORRUPTED; int srcCounter = 0, threshold = ERC_BLOCK_CORRUPTED;
memset( predBlocks, 0, 8*sizeof(int) ); memset(predBlocks, 0, 8 * sizeof(int));
// in this case, row > 0 and row < 17 // in this case, row > 0 and row < 17
if ( condition[ (currRow-1)*maxColumn + currColumn ] > threshold ) if (condition[(currRow - 1) * maxColumn + currColumn] > threshold) {
{
predBlocks[4] = 1; predBlocks[4] = 1;
srcCounter++; srcCounter++;
} }
if ( condition[ (currRow+step)*maxColumn + currColumn ] > threshold ) if (condition[(currRow + step) * maxColumn + currColumn] > threshold) {
{
predBlocks[6] = 1; predBlocks[6] = 1;
srcCounter++; srcCounter++;
} }
@ -289,189 +296,177 @@ int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signe
* Finds the corrupted blocks and calls pixel interpolation functions * Finds the corrupted blocks and calls pixel interpolation functions
* to correct them, one block at a time. * to correct them, one block at a time.
* Scanning is done vertically and each corrupted column is corrected * Scanning is done vertically and each corrupted column is corrected
* bi-directionally, i.e., first block, last block, first block+1, last block -1 ... * bi-directionally, i.e., first block, last block, first block+1, last
* \param p_Vid *block -1 ... \param p_Vid video encoding parameters for current picture \param
* video encoding parameters for current picture *lastColumn Number of block columns in the frame \param lastRow Number of block
* \param lastColumn *rows in the frame \param comp color component \param recfr Reconstructed frame
* Number of block columns in the frame *buffer \param picSizeX Width of the frame in pixels \param condition The block
* \param lastRow *condition (ok, lost) table
* Number of block rows in the frame
* \param comp
* color component
* \param recfr
* Reconstructed frame buffer
* \param picSizeX
* Width of the frame in pixels
* \param condition
* The block condition (ok, lost) table
************************************************************************ ************************************************************************
*/ */
static void concealBlocks( VideoParameters *p_Vid, int lastColumn, int lastRow, int comp, frame *recfr, int picSizeX, signed char *condition ) static void concealBlocks(VideoParameters *p_Vid, int lastColumn, int lastRow,
{ int comp, frame *recfr, int picSizeX,
int row, column, srcCounter = 0, thr = ERC_BLOCK_CORRUPTED, signed char *condition) {
lastCorruptedRow = -1, firstCorruptedRow = -1, currRow = 0, int row, column, srcCounter = 0, thr = ERC_BLOCK_CORRUPTED,
areaHeight = 0, i = 0, smoothColumn = 0; lastCorruptedRow = -1, firstCorruptedRow = -1, currRow = 0,
areaHeight = 0, i = 0, smoothColumn = 0;
int predBlocks[8], step = 1; int predBlocks[8], step = 1;
// in the Y component do the concealment MB-wise (not block-wise): // in the Y component do the concealment MB-wise (not block-wise):
// this is useful if only whole MBs can be damaged or lost // this is useful if only whole MBs can be damaged or lost
if ( comp == 0 ) if (comp == 0)
step = 2; step = 2;
else else
step = 1; step = 1;
for ( column = 0; column < lastColumn; column += step ) for (column = 0; column < lastColumn; column += step) {
{ for (row = 0; row < lastRow; row += step) {
for ( row = 0; row < lastRow; row += step ) if (condition[row * lastColumn + column] <= thr) {
{
if ( condition[row*lastColumn+column] <= thr )
{
firstCorruptedRow = row; firstCorruptedRow = row;
// find the last row which has corrupted blocks (in same continuous area) // find the last row which has corrupted blocks (in same continuous
for ( lastCorruptedRow = row+step; lastCorruptedRow < lastRow; lastCorruptedRow += step ) // area)
{ for (lastCorruptedRow = row + step; lastCorruptedRow < lastRow;
lastCorruptedRow += step) {
// check blocks in the current column // check blocks in the current column
if ( condition[ lastCorruptedRow*lastColumn + column ] > thr ) if (condition[lastCorruptedRow * lastColumn + column] > thr) {
{
// current one is already OK, so the last was the previous one // current one is already OK, so the last was the previous one
lastCorruptedRow -= step; lastCorruptedRow -= step;
break; break;
} }
} }
if ( lastCorruptedRow >= lastRow ) if (lastCorruptedRow >= lastRow) {
{
// correct only from above // correct only from above
lastCorruptedRow = lastRow-step; lastCorruptedRow = lastRow - step;
for ( currRow = firstCorruptedRow; currRow < lastRow; currRow += step ) for (currRow = firstCorruptedRow; currRow < lastRow;
{ currRow += step) {
srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); srcCounter =
ercCollect8PredBlocks(predBlocks, currRow, column, condition,
lastRow, lastColumn, step, 1);
switch( comp ) switch (comp) {
{ case 0:
case 0 : ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks,
ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); picSizeX, 2);
break; break;
case 1 : case 1:
ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
case 2 : case 2:
ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
} }
if ( comp == 0 ) if (comp == 0) {
{ condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + 1] =
condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + lastColumn] =
condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
condition[currRow * lastColumn + column + lastColumn + 1] =
ERC_BLOCK_CONCEALED;
} else {
condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
} }
else
{
condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED;
}
} }
row = lastRow; row = lastRow;
} } else if (firstCorruptedRow == 0) {
else if ( firstCorruptedRow == 0 )
{
// correct only from below // correct only from below
for ( currRow = lastCorruptedRow; currRow >= 0; currRow -= step ) for (currRow = lastCorruptedRow; currRow >= 0; currRow -= step) {
{ srcCounter =
srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); ercCollect8PredBlocks(predBlocks, currRow, column, condition,
lastRow, lastColumn, step, 1);
switch( comp ) switch (comp) {
{ case 0:
case 0 : ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks,
ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); picSizeX, 2);
break; break;
case 1 : case 1:
ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
case 2 : case 2:
ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
} }
if ( comp == 0 ) if (comp == 0) {
{ condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + 1] =
condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + lastColumn] =
condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
condition[currRow * lastColumn + column + lastColumn + 1] =
ERC_BLOCK_CONCEALED;
} else {
condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
} }
else
{
condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED;
}
} }
row = lastCorruptedRow+step; row = lastCorruptedRow + step;
} } else {
else
{
// correct bi-directionally // correct bi-directionally
row = lastCorruptedRow+step; row = lastCorruptedRow + step;
areaHeight = lastCorruptedRow-firstCorruptedRow+step; areaHeight = lastCorruptedRow - firstCorruptedRow + step;
// Conceal the corrupted area switching between the up and the bottom rows // Conceal the corrupted area switching between the up and the bottom
for ( i = 0; i < areaHeight; i += step ) // rows
{ for (i = 0; i < areaHeight; i += step) {
if ( i % 2 ) if (i % 2) {
{
currRow = lastCorruptedRow; currRow = lastCorruptedRow;
lastCorruptedRow -= step; lastCorruptedRow -= step;
} } else {
else
{
currRow = firstCorruptedRow; currRow = firstCorruptedRow;
firstCorruptedRow += step; firstCorruptedRow += step;
} }
if (smoothColumn > 0) if (smoothColumn > 0) {
{ srcCounter =
srcCounter = ercCollectColumnBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step ); ercCollectColumnBlocks(predBlocks, currRow, column, condition,
} lastRow, lastColumn, step);
else } else {
{ srcCounter =
srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); ercCollect8PredBlocks(predBlocks, currRow, column, condition,
lastRow, lastColumn, step, 1);
} }
switch( comp ) switch (comp) {
{ case 0:
case 0 : ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks,
ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); picSizeX, 2);
break; break;
case 1 : case 1:
ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
case 2 : case 2:
ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks,
(picSizeX >> 1), 1);
break; break;
} }
if ( comp == 0 ) if (comp == 0) {
{ condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + 1] =
condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column + lastColumn] =
condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; ERC_BLOCK_CONCEALED;
} condition[currRow * lastColumn + column + lastColumn + 1] =
else ERC_BLOCK_CONCEALED;
{ } else {
condition[ currRow*lastColumn+column ] = ERC_BLOCK_CONCEALED; condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED;
} }
} }
} }
lastCorruptedRow = -1; lastCorruptedRow = -1;
firstCorruptedRow = -1; firstCorruptedRow = -1;
} }
} }
} }
@ -494,50 +489,47 @@ static void concealBlocks( VideoParameters *p_Vid, int lastColumn, int lastRow,
* Width of the frame in pixels * Width of the frame in pixels
************************************************************************ ************************************************************************
*/ */
static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgpel *block, int blockSize, int frameWidth ) static void pixMeanInterpolateBlock(VideoParameters *p_Vid, imgpel *src[],
{ imgpel *block, int blockSize,
int frameWidth) {
int row, column, k, tmp, srcCounter = 0, weight = 0, bmax = blockSize - 1; int row, column, k, tmp, srcCounter = 0, weight = 0, bmax = blockSize - 1;
k = 0; k = 0;
for ( row = 0; row < blockSize; row++ ) for (row = 0; row < blockSize; row++) {
{ for (column = 0; column < blockSize; column++) {
for ( column = 0; column < blockSize; column++ )
{
tmp = 0; tmp = 0;
srcCounter = 0; srcCounter = 0;
// above // above
if ( src[4] != NULL ) if (src[4] != NULL) {
{ weight = blockSize - row;
weight = blockSize-row; tmp += weight * (*(src[4] + bmax * frameWidth + column));
tmp += weight * (*(src[4]+bmax*frameWidth+column));
srcCounter += weight; srcCounter += weight;
} }
// left // left
if ( src[5] != NULL ) if (src[5] != NULL) {
{ weight = blockSize - column;
weight = blockSize-column; tmp += weight * (*(src[5] + row * frameWidth + bmax));
tmp += weight * (*(src[5]+row*frameWidth+bmax));
srcCounter += weight; srcCounter += weight;
} }
// below // below
if ( src[6] != NULL ) if (src[6] != NULL) {
{ weight = row + 1;
weight = row+1; tmp += weight * (*(src[6] + column));
tmp += weight * (*(src[6]+column));
srcCounter += weight; srcCounter += weight;
} }
// right // right
if ( src[7] != NULL ) if (src[7] != NULL) {
{ weight = column + 1;
weight = column+1; tmp += weight * (*(src[7] + row * frameWidth));
tmp += weight * (*(src[7]+row*frameWidth));
srcCounter += weight; srcCounter += weight;
} }
if ( srcCounter > 0 ) if (srcCounter > 0)
block[ k + column ] = (imgpel)(tmp/srcCounter); block[k + column] = (imgpel)(tmp / srcCounter);
else else
block[ k + column ] = (imgpel) (blockSize == 8 ? p_Vid->dc_pred_value_comp[1] : p_Vid->dc_pred_value_comp[0]); block[k + column] =
(imgpel)(blockSize == 8 ? p_Vid->dc_pred_value_comp[1]
: p_Vid->dc_pred_value_comp[0]);
} }
k += frameWidth; k += frameWidth;
} }

File diff suppressed because it is too large Load diff

View file

@ -16,24 +16,22 @@
* This simple error concealment implemented in this decoder uses * This simple error concealment implemented in this decoder uses
* the existing dependencies of syntax elements. * the existing dependencies of syntax elements.
* In case that an element is detected as false this elements and all * In case that an element is detected as false this elements and all
* dependend elements are marked as elements to conceal in the p_Vid->ec_flag[] * dependend elements are marked as elements to conceal in the
* array. If the decoder requests a new element by the function *p_Vid->ec_flag[] array. If the decoder requests a new element by the function
* readSyntaxElement_xxxx() this array is checked first if an error concealment has * readSyntaxElement_xxxx() this array is checked first if an error
* to be applied on this element. *concealment has to be applied on this element. In case that an error occured a
* In case that an error occured a concealed element is given to the *concealed element is given to the decoding function in macroblock().
* decoding function in macroblock().
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Sebastian Purreiter <sebastian.purreiter@mch.siemens.de> * - Sebastian Purreiter <sebastian.purreiter@mch.siemens.de>
*********************************************************************** ***********************************************************************
*/ */
#include "contributors.h" #include "contributors.h"
#include "global.h"
#include "elements.h" #include "elements.h"
#include "global.h"
/*! /*!
*********************************************************************** ***********************************************************************
@ -49,75 +47,71 @@
* EX_SYNC sync on next header * EX_SYNC sync on next header
*********************************************************************** ***********************************************************************
*/ */
int set_ec_flag(VideoParameters *p_Vid, int se) int set_ec_flag(VideoParameters *p_Vid, int se) {
{
/* /*
if (p_Vid->ec_flag[se] == NO_EC) if (p_Vid->ec_flag[se] == NO_EC)
printf("Error concealment on element %s\n",SEtypes[se]); printf("Error concealment on element %s\n",SEtypes[se]);
*/ */
switch (se) switch (se) {
{ case SE_HEADER:
case SE_HEADER :
p_Vid->ec_flag[SE_HEADER] = EC_REQ; p_Vid->ec_flag[SE_HEADER] = EC_REQ;
case SE_PTYPE : case SE_PTYPE:
p_Vid->ec_flag[SE_PTYPE] = EC_REQ; p_Vid->ec_flag[SE_PTYPE] = EC_REQ;
case SE_MBTYPE : case SE_MBTYPE:
p_Vid->ec_flag[SE_MBTYPE] = EC_REQ; p_Vid->ec_flag[SE_MBTYPE] = EC_REQ;
case SE_REFFRAME : case SE_REFFRAME:
p_Vid->ec_flag[SE_REFFRAME] = EC_REQ; p_Vid->ec_flag[SE_REFFRAME] = EC_REQ;
p_Vid->ec_flag[SE_MVD] = EC_REQ; // set all motion vectors to zero length p_Vid->ec_flag[SE_MVD] = EC_REQ; // set all motion vectors to zero length
se = SE_CBP_INTER; // conceal also Inter texture elements se = SE_CBP_INTER; // conceal also Inter texture elements
break; break;
case SE_INTRAPREDMODE : case SE_INTRAPREDMODE:
p_Vid->ec_flag[SE_INTRAPREDMODE] = EC_REQ; p_Vid->ec_flag[SE_INTRAPREDMODE] = EC_REQ;
se = SE_CBP_INTRA; // conceal also Intra texture elements se = SE_CBP_INTRA; // conceal also Intra texture elements
break; break;
case SE_MVD : case SE_MVD:
p_Vid->ec_flag[SE_MVD] = EC_REQ; p_Vid->ec_flag[SE_MVD] = EC_REQ;
se = SE_CBP_INTER; // conceal also Inter texture elements se = SE_CBP_INTER; // conceal also Inter texture elements
break; break;
default: default:
break; break;
} }
switch (se) switch (se) {
{ case SE_CBP_INTRA:
case SE_CBP_INTRA :
p_Vid->ec_flag[SE_CBP_INTRA] = EC_REQ; p_Vid->ec_flag[SE_CBP_INTRA] = EC_REQ;
case SE_LUM_DC_INTRA : case SE_LUM_DC_INTRA:
p_Vid->ec_flag[SE_LUM_DC_INTRA] = EC_REQ; p_Vid->ec_flag[SE_LUM_DC_INTRA] = EC_REQ;
case SE_CHR_DC_INTRA : case SE_CHR_DC_INTRA:
p_Vid->ec_flag[SE_CHR_DC_INTRA] = EC_REQ; p_Vid->ec_flag[SE_CHR_DC_INTRA] = EC_REQ;
case SE_LUM_AC_INTRA : case SE_LUM_AC_INTRA:
p_Vid->ec_flag[SE_LUM_AC_INTRA] = EC_REQ; p_Vid->ec_flag[SE_LUM_AC_INTRA] = EC_REQ;
case SE_CHR_AC_INTRA : case SE_CHR_AC_INTRA:
p_Vid->ec_flag[SE_CHR_AC_INTRA] = EC_REQ; p_Vid->ec_flag[SE_CHR_AC_INTRA] = EC_REQ;
break; break;
case SE_CBP_INTER : case SE_CBP_INTER:
p_Vid->ec_flag[SE_CBP_INTER] = EC_REQ; p_Vid->ec_flag[SE_CBP_INTER] = EC_REQ;
case SE_LUM_DC_INTER : case SE_LUM_DC_INTER:
p_Vid->ec_flag[SE_LUM_DC_INTER] = EC_REQ; p_Vid->ec_flag[SE_LUM_DC_INTER] = EC_REQ;
case SE_CHR_DC_INTER : case SE_CHR_DC_INTER:
p_Vid->ec_flag[SE_CHR_DC_INTER] = EC_REQ; p_Vid->ec_flag[SE_CHR_DC_INTER] = EC_REQ;
case SE_LUM_AC_INTER : case SE_LUM_AC_INTER:
p_Vid->ec_flag[SE_LUM_AC_INTER] = EC_REQ; p_Vid->ec_flag[SE_LUM_AC_INTER] = EC_REQ;
case SE_CHR_AC_INTER : case SE_CHR_AC_INTER:
p_Vid->ec_flag[SE_CHR_AC_INTER] = EC_REQ; p_Vid->ec_flag[SE_CHR_AC_INTER] = EC_REQ;
break; break;
case SE_DELTA_QUANT_INTER : case SE_DELTA_QUANT_INTER:
p_Vid->ec_flag[SE_DELTA_QUANT_INTER] = EC_REQ; p_Vid->ec_flag[SE_DELTA_QUANT_INTER] = EC_REQ;
break; break;
case SE_DELTA_QUANT_INTRA : case SE_DELTA_QUANT_INTRA:
p_Vid->ec_flag[SE_DELTA_QUANT_INTRA] = EC_REQ; p_Vid->ec_flag[SE_DELTA_QUANT_INTRA] = EC_REQ;
break; break;
default: default:
break; break;
} }
return EC_REQ; return EC_REQ;
} }
@ -129,14 +123,12 @@ int set_ec_flag(VideoParameters *p_Vid, int se)
* *
*********************************************************************** ***********************************************************************
*/ */
void reset_ec_flags(VideoParameters *p_Vid) void reset_ec_flags(VideoParameters *p_Vid) {
{
int i; int i;
for (i=0; i<SE_MAX_ELEMENTS; i++) for (i = 0; i < SE_MAX_ELEMENTS; i++)
p_Vid->ec_flag[i] = NO_EC; p_Vid->ec_flag[i] = NO_EC;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
@ -148,59 +140,57 @@ void reset_ec_flags(VideoParameters *p_Vid)
* EC_REQ if element requires error concealment * EC_REQ if element requires error concealment
*********************************************************************** ***********************************************************************
*/ */
int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym) int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym) {
{
if (p_Vid->ec_flag[sym->type] == NO_EC) if (p_Vid->ec_flag[sym->type] == NO_EC)
return NO_EC; return NO_EC;
/* /*
#if TRACE #if TRACE
printf("TRACE: get concealed element for %s!!!\n", SEtypes[sym->type]); printf("TRACE: get concealed element for %s!!!\n", SEtypes[sym->type]);
#endif #endif
*/ */
switch (sym->type) switch (sym->type) {
{ case SE_HEADER:
case SE_HEADER :
sym->len = 31; sym->len = 31;
sym->inf = 0; // Picture Header sym->inf = 0; // Picture Header
break; break;
case SE_PTYPE : // inter_img_1 case SE_PTYPE: // inter_img_1
case SE_MBTYPE : // set COPY_MB case SE_MBTYPE: // set COPY_MB
case SE_REFFRAME : case SE_REFFRAME:
sym->len = 1; sym->len = 1;
sym->inf = 0; sym->inf = 0;
break; break;
case SE_INTRAPREDMODE : case SE_INTRAPREDMODE:
case SE_MVD : case SE_MVD:
sym->len = 1; sym->len = 1;
sym->inf = 0; // set vector to zero length sym->inf = 0; // set vector to zero length
break; break;
case SE_CBP_INTRA : case SE_CBP_INTRA:
sym->len = 5; sym->len = 5;
sym->inf = 0; // codenumber 3 <=> no CBP information for INTRA images sym->inf = 0; // codenumber 3 <=> no CBP information for INTRA images
break; break;
case SE_LUM_DC_INTRA : case SE_LUM_DC_INTRA:
case SE_CHR_DC_INTRA : case SE_CHR_DC_INTRA:
case SE_LUM_AC_INTRA : case SE_LUM_AC_INTRA:
case SE_CHR_AC_INTRA : case SE_CHR_AC_INTRA:
sym->len = 1; sym->len = 1;
sym->inf = 0; // return EOB sym->inf = 0; // return EOB
break; break;
case SE_CBP_INTER : case SE_CBP_INTER:
sym->len = 1; sym->len = 1;
sym->inf = 0; // codenumber 1 <=> no CBP information for INTER images sym->inf = 0; // codenumber 1 <=> no CBP information for INTER images
break; break;
case SE_LUM_DC_INTER : case SE_LUM_DC_INTER:
case SE_CHR_DC_INTER : case SE_CHR_DC_INTER:
case SE_LUM_AC_INTER : case SE_LUM_AC_INTER:
case SE_CHR_AC_INTER : case SE_CHR_AC_INTER:
sym->len = 1; sym->len = 1;
sym->inf = 0; // return EOB sym->inf = 0; // return EOB
break; break;
case SE_DELTA_QUANT_INTER: case SE_DELTA_QUANT_INTER:
@ -217,4 +207,3 @@ int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym)
return EC_REQ; return EC_REQ;
} }

View file

@ -6,7 +6,8 @@
* \brief * \brief
* Trace file handling and standard error handling function. * Trace file handling and standard error handling function.
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Karsten Suehring <suehring@hhi.de> * - Karsten Suehring <suehring@hhi.de>
*************************************************************************************** ***************************************************************************************
*/ */
@ -15,7 +16,6 @@
#include "global.h" #include "global.h"
#include "mbuffer.h" #include "mbuffer.h"
#if TRACE #if TRACE
/*! /*!
@ -24,10 +24,7 @@
* decrement trace p_Dec->bitcounter (used for special case in mb aff) * decrement trace p_Dec->bitcounter (used for special case in mb aff)
************************************************************************ ************************************************************************
*/ */
void dectracebitcnt(int count) void dectracebitcnt(int count) { p_Dec->bitcounter -= count; }
{
p_Dec->bitcounter -= count;
}
/*! /*!
************************************************************************ ************************************************************************
@ -37,57 +34,54 @@ void dectracebitcnt(int count)
************************************************************************ ************************************************************************
*/ */
void tracebits( void tracebits(
const signed char *trace_str, //!< tracing information, signed char array describing the symbol const signed char *trace_str, //!< tracing information, signed char array
int len, //!< length of syntax element in bits //!< describing the symbol
int info, //!< infoword of syntax element int len, //!< length of syntax element in bits
int value1) int info, //!< infoword of syntax element
{ int value1) {
int i, chars; int i, chars;
// int outint = 1; // int outint = 1;
if(len>=64) if (len >= 64) {
{ snprintf(errortext, ET_SIZE,
snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work"); "Length argument to put too long for trace to work");
error (errortext, 600); error(errortext, 600);
} }
putc('@', p_Dec->p_trace); putc('@', p_Dec->p_trace);
chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter); chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter);
while(chars++ < 5) while (chars++ < 5)
putc(' ',p_Dec->p_trace); putc(' ', p_Dec->p_trace);
chars += fprintf(p_Dec->p_trace, " %s", trace_str); chars += fprintf(p_Dec->p_trace, " %s", trace_str);
while(chars++ < 55) while (chars++ < 55)
putc(' ',p_Dec->p_trace); putc(' ', p_Dec->p_trace);
// Align bitpattern // Align bitpattern
if(len<15) if (len < 15) {
{ for (i = 0; i < 15 - len; i++)
for(i=0 ; i<15-len ; i++)
fputc(' ', p_Dec->p_trace); fputc(' ', p_Dec->p_trace);
} }
// Print bitpattern // Print bitpattern
for(i=0 ; i<len/2 ; i++) for (i = 0; i < len / 2; i++) {
{
fputc('0', p_Dec->p_trace); fputc('0', p_Dec->p_trace);
} }
// put 1 // put 1
fprintf(p_Dec->p_trace, "1"); fprintf(p_Dec->p_trace, "1");
// Print bitpattern // Print bitpattern
for(i=0 ; i<len/2 ; i++) for (i = 0; i < len / 2; i++) {
{ if (0x01 & (info >> ((len / 2 - i) - 1)))
if (0x01 & ( info >> ((len/2-i)-1))) fputc('1', p_Dec->p_trace);
fputc('1', p_Dec->p_trace); else
else fputc('0', p_Dec->p_trace);
fputc('0', p_Dec->p_trace);
} }
fprintf(p_Dec->p_trace, " (%3d) \n", value1); fprintf(p_Dec->p_trace, " (%3d) \n", value1);
p_Dec->bitcounter += len; p_Dec->bitcounter += len;
fflush (p_Dec->p_trace); fflush(p_Dec->p_trace);
} }
/*! /*!
@ -97,52 +91,48 @@ void tracebits(
************************************************************************ ************************************************************************
*/ */
void tracebits2( void tracebits2(
const signed char *trace_str, //!< tracing information, signed char array describing the symbol const signed char *trace_str, //!< tracing information, signed char array
int len, //!< length of syntax element in bits //!< describing the symbol
int info) int len, //!< length of syntax element in bits
{ int info) {
int i, chars; int i, chars;
// int outint = 1; // int outint = 1;
if(len>=64) if (len >= 64) {
{ snprintf(errortext, ET_SIZE,
snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work"); "Length argument to put too long for trace to work");
error (errortext, 600); error(errortext, 600);
} }
putc('@', p_Dec->p_trace); putc('@', p_Dec->p_trace);
chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter); chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter);
while(chars++ < 5) while (chars++ < 5)
putc(' ',p_Dec->p_trace); putc(' ', p_Dec->p_trace);
chars += fprintf(p_Dec->p_trace, " %s", trace_str); chars += fprintf(p_Dec->p_trace, " %s", trace_str);
while(chars++ < 55) while (chars++ < 55)
putc(' ',p_Dec->p_trace); putc(' ', p_Dec->p_trace);
// Align bitpattern // Align bitpattern
if(len < 15) if (len < 15) {
{ for (i = 0; i < 15 - len; i++)
for(i = 0; i < 15 - len; i++)
fputc(' ', p_Dec->p_trace); fputc(' ', p_Dec->p_trace);
} }
p_Dec->bitcounter += len; p_Dec->bitcounter += len;
while (len >= 32) while (len >= 32) {
{ for (i = 0; i < 8; i++) {
for(i = 0; i < 8; i++)
{
fputc('0', p_Dec->p_trace); fputc('0', p_Dec->p_trace);
} }
len -= 8; len -= 8;
} }
// Print bitpattern // Print bitpattern
for(i=0 ; i<len ; i++) for (i = 0; i < len; i++) {
{ if (0x01 & (info >> (len - i - 1)))
if (0x01 & ( info >> (len-i-1)))
fputc('1', p_Dec->p_trace); fputc('1', p_Dec->p_trace);
else else
fputc('0', p_Dec->p_trace); fputc('0', p_Dec->p_trace);
@ -150,7 +140,6 @@ void tracebits2(
fprintf(p_Dec->p_trace, " (%3d) \n", info); fprintf(p_Dec->p_trace, " (%3d) \n", info);
fflush (p_Dec->p_trace); fflush(p_Dec->p_trace);
} }
#endif #endif

View file

@ -8,29 +8,39 @@
* Support for Flexible Macroblock Ordering (FMO) * Support for Flexible Macroblock Ordering (FMO)
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger stewe@cs.tu-berlin.de * - Stephan Wenger stewe@cs.tu-berlin.de
* - Karsten Suehring suehring@hhi.de * - Karsten Suehring suehring@hhi.de
****************************************************************************** ******************************************************************************
*/ */
#include "global.h"
#include "elements.h"
#include "defines.h"
#include "header.h"
#include "fmo.h" #include "fmo.h"
#include "defines.h"
#include "elements.h"
#include "fast_memory.h" #include "fast_memory.h"
#include "global.h"
#include "header.h"
//#define PRINT_FMO_MAPS // #define PRINT_FMO_MAPS
static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits );
static void FmoGenerateType1MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits );
static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits );
static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice );
static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice );
static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice );
static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits );
static void FmoGenerateType0MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits);
static void FmoGenerateType1MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits);
static void FmoGenerateType2MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits);
static void FmoGenerateType3MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits,
Slice *currSlice);
static void FmoGenerateType4MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits,
Slice *currSlice);
static void FmoGenerateType5MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits,
Slice *currSlice);
static void FmoGenerateType6MapUnitMap(VideoParameters *p_Vid,
unsigned PicSizeInMapUnits);
/*! /*!
************************************************************************ ************************************************************************
@ -43,69 +53,72 @@ static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static int FmoGenerateMapUnitToSliceGroupMap (VideoParameters *p_Vid, Slice *currSlice) static int FmoGenerateMapUnitToSliceGroupMap(VideoParameters *p_Vid,
{ Slice *currSlice) {
seq_parameter_set_rbsp_t* sps = p_Vid->active_sps; seq_parameter_set_rbsp_t *sps = p_Vid->active_sps;
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned int NumSliceGroupMapUnits; unsigned int NumSliceGroupMapUnits;
NumSliceGroupMapUnits = (sps->pic_height_in_map_units_minus1+1)* (sps->pic_width_in_mbs_minus1+1); NumSliceGroupMapUnits = (sps->pic_height_in_map_units_minus1 + 1) *
(sps->pic_width_in_mbs_minus1 + 1);
if (pps->slice_group_map_type == 6) if (pps->slice_group_map_type == 6) {
{ if ((pps->pic_size_in_map_units_minus1 + 1) != NumSliceGroupMapUnits) {
if ((pps->pic_size_in_map_units_minus1 + 1) != NumSliceGroupMapUnits) error(
{ "wrong pps->pic_size_in_map_units_minus1 for used SPS and FMO type 6",
error ("wrong pps->pic_size_in_map_units_minus1 for used SPS and FMO type 6", 500); 500);
} }
} }
// allocate memory for p_Vid->MapUnitToSliceGroupMap // allocate memory for p_Vid->MapUnitToSliceGroupMap
if (p_Vid->MapUnitToSliceGroupMap) if (p_Vid->MapUnitToSliceGroupMap)
free (p_Vid->MapUnitToSliceGroupMap); free(p_Vid->MapUnitToSliceGroupMap);
if ((p_Vid->MapUnitToSliceGroupMap = malloc ((NumSliceGroupMapUnits) * sizeof (int))) == NULL) if ((p_Vid->MapUnitToSliceGroupMap =
{ malloc((NumSliceGroupMapUnits) * sizeof(int))) == NULL) {
printf ("cannot allocated %d bytes for p_Vid->MapUnitToSliceGroupMap, exit\n", (int) ( (pps->pic_size_in_map_units_minus1+1) * sizeof (int))); printf(
exit (-1); "cannot allocated %d bytes for p_Vid->MapUnitToSliceGroupMap, exit\n",
(int)((pps->pic_size_in_map_units_minus1 + 1) * sizeof(int)));
exit(-1);
} }
if (pps->num_slice_groups_minus1 == 0) // only one slice group if (pps->num_slice_groups_minus1 == 0) // only one slice group
{ {
fast_memset (p_Vid->MapUnitToSliceGroupMap, 0, NumSliceGroupMapUnits * sizeof (int)); fast_memset(p_Vid->MapUnitToSliceGroupMap, 0,
NumSliceGroupMapUnits * sizeof(int));
return 0; return 0;
} }
switch (pps->slice_group_map_type) switch (pps->slice_group_map_type) {
{
case 0: case 0:
FmoGenerateType0MapUnitMap (p_Vid, NumSliceGroupMapUnits); FmoGenerateType0MapUnitMap(p_Vid, NumSliceGroupMapUnits);
break; break;
case 1: case 1:
FmoGenerateType1MapUnitMap (p_Vid, NumSliceGroupMapUnits); FmoGenerateType1MapUnitMap(p_Vid, NumSliceGroupMapUnits);
break; break;
case 2: case 2:
FmoGenerateType2MapUnitMap (p_Vid, NumSliceGroupMapUnits); FmoGenerateType2MapUnitMap(p_Vid, NumSliceGroupMapUnits);
break; break;
case 3: case 3:
FmoGenerateType3MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); FmoGenerateType3MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice);
break; break;
case 4: case 4:
FmoGenerateType4MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); FmoGenerateType4MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice);
break; break;
case 5: case 5:
FmoGenerateType5MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); FmoGenerateType5MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice);
break; break;
case 6: case 6:
FmoGenerateType6MapUnitMap (p_Vid, NumSliceGroupMapUnits); FmoGenerateType6MapUnitMap(p_Vid, NumSliceGroupMapUnits);
break; break;
default: default:
printf ("Illegal slice_group_map_type %d , exit \n", (int) pps->slice_group_map_type); printf("Illegal slice_group_map_type %d , exit \n",
exit (-1); (int)pps->slice_group_map_type);
exit(-1);
} }
return 0; return 0;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -116,66 +129,58 @@ static int FmoGenerateMapUnitToSliceGroupMap (VideoParameters *p_Vid, Slice *cur
* *
************************************************************************ ************************************************************************
*/ */
static int FmoGenerateMbToSliceGroupMap (VideoParameters *p_Vid, Slice *pSlice) static int FmoGenerateMbToSliceGroupMap(VideoParameters *p_Vid, Slice *pSlice) {
{ seq_parameter_set_rbsp_t *sps = p_Vid->active_sps;
seq_parameter_set_rbsp_t* sps = p_Vid->active_sps;
unsigned i; unsigned i;
// allocate memory for p_Vid->MbToSliceGroupMap // allocate memory for p_Vid->MbToSliceGroupMap
if (p_Vid->MbToSliceGroupMap) if (p_Vid->MbToSliceGroupMap)
free (p_Vid->MbToSliceGroupMap); free(p_Vid->MbToSliceGroupMap);
if ((p_Vid->MbToSliceGroupMap = malloc ((p_Vid->PicSizeInMbs) * sizeof (int))) == NULL) if ((p_Vid->MbToSliceGroupMap =
{ malloc((p_Vid->PicSizeInMbs) * sizeof(int))) == NULL) {
printf ("cannot allocate %d bytes for p_Vid->MbToSliceGroupMap, exit\n", (int) ((p_Vid->PicSizeInMbs) * sizeof (int))); printf("cannot allocate %d bytes for p_Vid->MbToSliceGroupMap, exit\n",
exit (-1); (int)((p_Vid->PicSizeInMbs) * sizeof(int)));
exit(-1);
} }
if ((sps->frame_mbs_only_flag) || pSlice->field_pic_flag) {
if ((sps->frame_mbs_only_flag)|| pSlice->field_pic_flag)
{
int *MbToSliceGroupMap = p_Vid->MbToSliceGroupMap; int *MbToSliceGroupMap = p_Vid->MbToSliceGroupMap;
int *MapUnitToSliceGroupMap = p_Vid->MapUnitToSliceGroupMap; int *MapUnitToSliceGroupMap = p_Vid->MapUnitToSliceGroupMap;
for (i=0; i<p_Vid->PicSizeInMbs; i++) for (i = 0; i < p_Vid->PicSizeInMbs; i++) {
{
*MbToSliceGroupMap++ = *MapUnitToSliceGroupMap++; *MbToSliceGroupMap++ = *MapUnitToSliceGroupMap++;
} }
} else if (sps->mb_adaptive_frame_field_flag && (!pSlice->field_pic_flag)) {
for (i = 0; i < p_Vid->PicSizeInMbs; i++) {
p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[i / 2];
}
} else {
for (i = 0; i < p_Vid->PicSizeInMbs; i++) {
p_Vid->MbToSliceGroupMap[i] =
p_Vid->MapUnitToSliceGroupMap[(i / (2 * p_Vid->PicWidthInMbs)) *
p_Vid->PicWidthInMbs +
(i % p_Vid->PicWidthInMbs)];
}
} }
else
if (sps->mb_adaptive_frame_field_flag && (!pSlice->field_pic_flag))
{
for (i=0; i<p_Vid->PicSizeInMbs; i++)
{
p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[i/2];
}
}
else
{
for (i=0; i<p_Vid->PicSizeInMbs; i++)
{
p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[(i/(2*p_Vid->PicWidthInMbs))*p_Vid->PicWidthInMbs+(i%p_Vid->PicWidthInMbs)];
}
}
return 0; return 0;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* FMO initialization: Generates p_Vid->MapUnitToSliceGroupMap and p_Vid->MbToSliceGroupMap. * FMO initialization: Generates p_Vid->MapUnitToSliceGroupMap and
*p_Vid->MbToSliceGroupMap.
* *
* \param p_Vid * \param p_Vid
* video encoding parameters for current picture * video encoding parameters for current picture
************************************************************************ ************************************************************************
*/ */
int fmo_init(VideoParameters *p_Vid, Slice *pSlice) int fmo_init(VideoParameters *p_Vid, Slice *pSlice) {
{ pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps;
#ifdef PRINT_FMO_MAPS #ifdef PRINT_FMO_MAPS
unsigned i,j; unsigned i, j;
#endif #endif
FmoGenerateMapUnitToSliceGroupMap(p_Vid, pSlice); FmoGenerateMapUnitToSliceGroupMap(p_Vid, pSlice);
@ -187,22 +192,19 @@ int fmo_init(VideoParameters *p_Vid, Slice *pSlice)
printf("\n"); printf("\n");
printf("FMO Map (Units):\n"); printf("FMO Map (Units):\n");
for (j=0; j<p_Vid->PicHeightInMapUnits; j++) for (j = 0; j < p_Vid->PicHeightInMapUnits; j++) {
{ for (i = 0; i < p_Vid->PicWidthInMbs; i++) {
for (i=0; i<p_Vid->PicWidthInMbs; i++) printf("%c",
{ 48 + p_Vid->MapUnitToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]);
printf("%c",48+p_Vid->MapUnitToSliceGroupMap[i+j*p_Vid->PicWidthInMbs]);
} }
printf("\n"); printf("\n");
} }
printf("\n"); printf("\n");
printf("FMO Map (Mb):\n"); printf("FMO Map (Mb):\n");
for (j=0; j<p_Vid->PicHeightInMbs; j++) for (j = 0; j < p_Vid->PicHeightInMbs; j++) {
{ for (i = 0; i < p_Vid->PicWidthInMbs; i++) {
for (i=0; i<p_Vid->PicWidthInMbs; i++) printf("%c", 48 + p_Vid->MbToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]);
{
printf("%c",48 + p_Vid->MbToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]);
} }
printf("\n"); printf("\n");
} }
@ -213,29 +215,24 @@ int fmo_init(VideoParameters *p_Vid, Slice *pSlice)
return 0; return 0;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Free memory allocated by FMO functions * Free memory allocated by FMO functions
************************************************************************ ************************************************************************
*/ */
int FmoFinit(VideoParameters *p_Vid) int FmoFinit(VideoParameters *p_Vid) {
{ if (p_Vid->MbToSliceGroupMap) {
if (p_Vid->MbToSliceGroupMap) free(p_Vid->MbToSliceGroupMap);
{
free (p_Vid->MbToSliceGroupMap);
p_Vid->MbToSliceGroupMap = NULL; p_Vid->MbToSliceGroupMap = NULL;
} }
if (p_Vid->MapUnitToSliceGroupMap) if (p_Vid->MapUnitToSliceGroupMap) {
{ free(p_Vid->MapUnitToSliceGroupMap);
free (p_Vid->MapUnitToSliceGroupMap);
p_Vid->MapUnitToSliceGroupMap = NULL; p_Vid->MapUnitToSliceGroupMap = NULL;
} }
return 0; return 0;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -245,12 +242,10 @@ int FmoFinit(VideoParameters *p_Vid)
* VideoParameters * VideoParameters
************************************************************************ ************************************************************************
*/ */
int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid) int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid) {
{
return p_Vid->NumberOfSliceGroups; return p_Vid->NumberOfSliceGroups;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -263,12 +258,10 @@ int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid)
* None * None
************************************************************************ ************************************************************************
*/ */
int FmoGetLastMBOfPicture(VideoParameters *p_Vid) int FmoGetLastMBOfPicture(VideoParameters *p_Vid) {
{ return FmoGetLastMBInSliceGroup(p_Vid, FmoGetNumberOfSliceGroup(p_Vid) - 1);
return FmoGetLastMBInSliceGroup (p_Vid, FmoGetNumberOfSliceGroup(p_Vid)-1);
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -279,18 +272,15 @@ int FmoGetLastMBOfPicture(VideoParameters *p_Vid)
************************************************************************ ************************************************************************
*/ */
int FmoGetLastMBInSliceGroup (VideoParameters *p_Vid, int SliceGroup) int FmoGetLastMBInSliceGroup(VideoParameters *p_Vid, int SliceGroup) {
{
int i; int i;
for (i=p_Vid->PicSizeInMbs-1; i>=0; i--) for (i = p_Vid->PicSizeInMbs - 1; i >= 0; i--)
if (FmoGetSliceGroupId (p_Vid, i) == SliceGroup) if (FmoGetSliceGroupId(p_Vid, i) == SliceGroup)
return i; return i;
return -1; return -1;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -302,14 +292,12 @@ int FmoGetLastMBInSliceGroup (VideoParameters *p_Vid, int SliceGroup)
* Macroblock number (in scan order) * Macroblock number (in scan order)
************************************************************************ ************************************************************************
*/ */
int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb) int FmoGetSliceGroupId(VideoParameters *p_Vid, int mb) {
{ assert(mb < (int)p_Vid->PicSizeInMbs);
assert (mb < (int) p_Vid->PicSizeInMbs); assert(p_Vid->MbToSliceGroupMap != NULL);
assert (p_Vid->MbToSliceGroupMap != NULL);
return p_Vid->MbToSliceGroupMap[mb]; return p_Vid->MbToSliceGroupMap[mb];
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -322,20 +310,19 @@ int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb)
* number of the current macroblock * number of the current macroblock
************************************************************************ ************************************************************************
*/ */
int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr) int FmoGetNextMBNr(VideoParameters *p_Vid, int CurrentMbNr) {
{ int SliceGroup = FmoGetSliceGroupId(p_Vid, CurrentMbNr);
int SliceGroup = FmoGetSliceGroupId (p_Vid, CurrentMbNr);
while (++CurrentMbNr<(int)p_Vid->PicSizeInMbs && p_Vid->MbToSliceGroupMap [CurrentMbNr] != SliceGroup) while (++CurrentMbNr < (int)p_Vid->PicSizeInMbs &&
p_Vid->MbToSliceGroupMap[CurrentMbNr] != SliceGroup)
; ;
if (CurrentMbNr >= (int)p_Vid->PicSizeInMbs) if (CurrentMbNr >= (int)p_Vid->PicSizeInMbs)
return -1; // No further MB in this slice (could be end of picture) return -1; // No further MB in this slice (could be end of picture)
else else
return CurrentMbNr; return CurrentMbNr;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -343,25 +330,23 @@ int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr)
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) static void FmoGenerateType0MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits) {
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned iGroup, j; unsigned iGroup, j;
unsigned i = 0; unsigned i = 0;
do do {
{ for (iGroup = 0;
for( iGroup = 0;
(iGroup <= pps->num_slice_groups_minus1) && (i < PicSizeInMapUnits); (iGroup <= pps->num_slice_groups_minus1) && (i < PicSizeInMapUnits);
i += pps->run_length_minus1[iGroup++] + 1 ) i += pps->run_length_minus1[iGroup++] + 1) {
{ for (j = 0;
for( j = 0; j <= pps->run_length_minus1[ iGroup ] && i + j < PicSizeInMapUnits; j++ ) j <= pps->run_length_minus1[iGroup] && i + j < PicSizeInMapUnits;
p_Vid->MapUnitToSliceGroupMap[i+j] = iGroup; j++)
p_Vid->MapUnitToSliceGroupMap[i + j] = iGroup;
} }
} } while (i < PicSizeInMapUnits);
while( i < PicSizeInMapUnits );
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -369,47 +354,48 @@ static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType1MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) static void FmoGenerateType1MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits) {
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned i; unsigned i;
for( i = 0; i < PicSizeInMapUnits; i++ ) for (i = 0; i < PicSizeInMapUnits; i++) {
{ p_Vid->MapUnitToSliceGroupMap[i] =
p_Vid->MapUnitToSliceGroupMap[i] = ((i%p_Vid->PicWidthInMbs)+(((i/p_Vid->PicWidthInMbs)*(pps->num_slice_groups_minus1+1))/2)) ((i % p_Vid->PicWidthInMbs) +
%(pps->num_slice_groups_minus1+1); (((i / p_Vid->PicWidthInMbs) * (pps->num_slice_groups_minus1 + 1)) /
2)) %
(pps->num_slice_groups_minus1 + 1);
} }
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Generate foreground with left-over slice group map type MapUnit map (type 2) * Generate foreground with left-over slice group map type MapUnit map (type
*2)
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) static void FmoGenerateType2MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits) {
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
int iGroup; int iGroup;
unsigned i, x, y; unsigned i, x, y;
unsigned yTopLeft, xTopLeft, yBottomRight, xBottomRight; unsigned yTopLeft, xTopLeft, yBottomRight, xBottomRight;
for( i = 0; i < PicSizeInMapUnits; i++ ) for (i = 0; i < PicSizeInMapUnits; i++)
p_Vid->MapUnitToSliceGroupMap[ i ] = pps->num_slice_groups_minus1; p_Vid->MapUnitToSliceGroupMap[i] = pps->num_slice_groups_minus1;
for( iGroup = pps->num_slice_groups_minus1 - 1 ; iGroup >= 0; iGroup-- ) for (iGroup = pps->num_slice_groups_minus1 - 1; iGroup >= 0; iGroup--) {
{ yTopLeft = pps->top_left[iGroup] / p_Vid->PicWidthInMbs;
yTopLeft = pps->top_left[ iGroup ] / p_Vid->PicWidthInMbs; xTopLeft = pps->top_left[iGroup] % p_Vid->PicWidthInMbs;
xTopLeft = pps->top_left[ iGroup ] % p_Vid->PicWidthInMbs; yBottomRight = pps->bottom_right[iGroup] / p_Vid->PicWidthInMbs;
yBottomRight = pps->bottom_right[ iGroup ] / p_Vid->PicWidthInMbs; xBottomRight = pps->bottom_right[iGroup] % p_Vid->PicWidthInMbs;
xBottomRight = pps->bottom_right[ iGroup ] % p_Vid->PicWidthInMbs; for (y = yTopLeft; y <= yBottomRight; y++)
for( y = yTopLeft; y <= yBottomRight; y++ ) for (x = xTopLeft; x <= xBottomRight; x++)
for( x = xTopLeft; x <= xBottomRight; x++ ) p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] = iGroup;
p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] = iGroup; }
}
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -417,74 +403,66 @@ static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) static void FmoGenerateType3MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits,
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; Slice *currSlice) {
pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned i, k; unsigned i, k;
int leftBound, topBound, rightBound, bottomBound; int leftBound, topBound, rightBound, bottomBound;
int x, y, xDir, yDir; int x, y, xDir, yDir;
int mapUnitVacant; int mapUnitVacant;
unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); unsigned mapUnitsInSliceGroup0 =
imin((pps->slice_group_change_rate_minus1 + 1) *
currSlice->slice_group_change_cycle,
PicSizeInMapUnits);
for( i = 0; i < PicSizeInMapUnits; i++ ) for (i = 0; i < PicSizeInMapUnits; i++)
p_Vid->MapUnitToSliceGroupMap[ i ] = 2; p_Vid->MapUnitToSliceGroupMap[i] = 2;
x = ( p_Vid->PicWidthInMbs - pps->slice_group_change_direction_flag ) / 2; x = (p_Vid->PicWidthInMbs - pps->slice_group_change_direction_flag) / 2;
y = ( p_Vid->PicHeightInMapUnits - pps->slice_group_change_direction_flag ) / 2; y = (p_Vid->PicHeightInMapUnits - pps->slice_group_change_direction_flag) / 2;
leftBound = x; leftBound = x;
topBound = y; topBound = y;
rightBound = x; rightBound = x;
bottomBound = y; bottomBound = y;
xDir = pps->slice_group_change_direction_flag - 1; xDir = pps->slice_group_change_direction_flag - 1;
yDir = pps->slice_group_change_direction_flag; yDir = pps->slice_group_change_direction_flag;
for( k = 0; k < PicSizeInMapUnits; k += mapUnitVacant ) for (k = 0; k < PicSizeInMapUnits; k += mapUnitVacant) {
{ mapUnitVacant =
mapUnitVacant = ( p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] == 2 ); (p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] == 2);
if( mapUnitVacant ) if (mapUnitVacant)
p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] = ( k >= mapUnitsInSliceGroup0 ); p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] =
(k >= mapUnitsInSliceGroup0);
if( xDir == -1 && x == leftBound ) if (xDir == -1 && x == leftBound) {
{ leftBound = imax(leftBound - 1, 0);
leftBound = imax( leftBound - 1, 0 );
x = leftBound; x = leftBound;
xDir = 0; xDir = 0;
yDir = 2 * pps->slice_group_change_direction_flag - 1; yDir = 2 * pps->slice_group_change_direction_flag - 1;
} else if (xDir == 1 && x == rightBound) {
rightBound = imin(rightBound + 1, (int)p_Vid->PicWidthInMbs - 1);
x = rightBound;
xDir = 0;
yDir = 1 - 2 * pps->slice_group_change_direction_flag;
} else if (yDir == -1 && y == topBound) {
topBound = imax(topBound - 1, 0);
y = topBound;
xDir = 1 - 2 * pps->slice_group_change_direction_flag;
yDir = 0;
} else if (yDir == 1 && y == bottomBound) {
bottomBound = imin(bottomBound + 1, (int)p_Vid->PicHeightInMapUnits - 1);
y = bottomBound;
xDir = 2 * pps->slice_group_change_direction_flag - 1;
yDir = 0;
} else {
x = x + xDir;
y = y + yDir;
} }
else
if( xDir == 1 && x == rightBound )
{
rightBound = imin( rightBound + 1, (int)p_Vid->PicWidthInMbs - 1 );
x = rightBound;
xDir = 0;
yDir = 1 - 2 * pps->slice_group_change_direction_flag;
}
else
if( yDir == -1 && y == topBound )
{
topBound = imax( topBound - 1, 0 );
y = topBound;
xDir = 1 - 2 * pps->slice_group_change_direction_flag;
yDir = 0;
}
else
if( yDir == 1 && y == bottomBound )
{
bottomBound = imin( bottomBound + 1, (int)p_Vid->PicHeightInMapUnits - 1 );
y = bottomBound;
xDir = 2 * pps->slice_group_change_direction_flag - 1;
yDir = 0;
}
else
{
x = x + xDir;
y = y + yDir;
}
} }
} }
/*! /*!
@ -494,21 +472,28 @@ static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) static void FmoGenerateType4MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits,
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; Slice *currSlice) {
pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); unsigned mapUnitsInSliceGroup0 =
unsigned sizeOfUpperLeftGroup = pps->slice_group_change_direction_flag ? ( PicSizeInMapUnits - mapUnitsInSliceGroup0 ) : mapUnitsInSliceGroup0; imin((pps->slice_group_change_rate_minus1 + 1) *
currSlice->slice_group_change_cycle,
PicSizeInMapUnits);
unsigned sizeOfUpperLeftGroup =
pps->slice_group_change_direction_flag
? (PicSizeInMapUnits - mapUnitsInSliceGroup0)
: mapUnitsInSliceGroup0;
unsigned i; unsigned i;
for( i = 0; i < PicSizeInMapUnits; i++ ) for (i = 0; i < PicSizeInMapUnits; i++)
if( i < sizeOfUpperLeftGroup ) if (i < sizeOfUpperLeftGroup)
p_Vid->MapUnitToSliceGroupMap[ i ] = pps->slice_group_change_direction_flag; p_Vid->MapUnitToSliceGroupMap[i] = pps->slice_group_change_direction_flag;
else else
p_Vid->MapUnitToSliceGroupMap[ i ] = 1 - pps->slice_group_change_direction_flag; p_Vid->MapUnitToSliceGroupMap[i] =
1 - pps->slice_group_change_direction_flag;
} }
/*! /*!
@ -518,22 +503,30 @@ static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) static void FmoGenerateType5MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits,
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; Slice *currSlice) {
pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); unsigned mapUnitsInSliceGroup0 =
unsigned sizeOfUpperLeftGroup = pps->slice_group_change_direction_flag ? ( PicSizeInMapUnits - mapUnitsInSliceGroup0 ) : mapUnitsInSliceGroup0; imin((pps->slice_group_change_rate_minus1 + 1) *
currSlice->slice_group_change_cycle,
PicSizeInMapUnits);
unsigned sizeOfUpperLeftGroup =
pps->slice_group_change_direction_flag
? (PicSizeInMapUnits - mapUnitsInSliceGroup0)
: mapUnitsInSliceGroup0;
unsigned i,j, k = 0; unsigned i, j, k = 0;
for( j = 0; j < p_Vid->PicWidthInMbs; j++ )
for( i = 0; i < p_Vid->PicHeightInMapUnits; i++ )
if( k++ < sizeOfUpperLeftGroup )
p_Vid->MapUnitToSliceGroupMap[ i * p_Vid->PicWidthInMbs + j ] = pps->slice_group_change_direction_flag;
else
p_Vid->MapUnitToSliceGroupMap[ i * p_Vid->PicWidthInMbs + j ] = 1 - pps->slice_group_change_direction_flag;
for (j = 0; j < p_Vid->PicWidthInMbs; j++)
for (i = 0; i < p_Vid->PicHeightInMapUnits; i++)
if (k++ < sizeOfUpperLeftGroup)
p_Vid->MapUnitToSliceGroupMap[i * p_Vid->PicWidthInMbs + j] =
pps->slice_group_change_direction_flag;
else
p_Vid->MapUnitToSliceGroupMap[i * p_Vid->PicWidthInMbs + j] =
1 - pps->slice_group_change_direction_flag;
} }
/*! /*!
@ -543,13 +536,11 @@ static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSize
* *
************************************************************************ ************************************************************************
*/ */
static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) static void FmoGenerateType6MapUnitMap(VideoParameters *p_Vid,
{ unsigned PicSizeInMapUnits) {
pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; pic_parameter_set_rbsp_t *pps = p_Vid->active_pps;
unsigned i; unsigned i;
for (i=0; i<PicSizeInMapUnits; i++) for (i = 0; i < PicSizeInMapUnits; i++) {
{
p_Vid->MapUnitToSliceGroupMap[i] = pps->slice_group_id[i]; p_Vid->MapUnitToSliceGroupMap[i] = pps->slice_group_id[i];
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -7,13 +7,14 @@
* image I/O related functions * image I/O related functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
#include "img_io.h"
#include "contributors.h" #include "contributors.h"
#include "global.h" #include "global.h"
#include "img_io.h"
#include "report.h" #include "report.h"
#ifdef SPEC #ifdef SPEC
#define STRCMP strcmp #define STRCMP strcmp
@ -22,19 +23,10 @@
#endif #endif
static const VIDEO_SIZE VideoRes[] = { static const VIDEO_SIZE VideoRes[] = {
{ "qcif" , 176, 144}, {"qcif", 176, 144}, {"qqvga", 160, 128}, {"qvga", 320, 240},
{ "qqvga" , 160, 128}, {"sif", 352, 240}, {"cif", 352, 288}, {"vga", 640, 480},
{ "qvga" , 320, 240}, {"sd1", 720, 480}, {"sd2", 704, 576}, {"sd3", 720, 576},
{ "sif" , 352, 240}, {"720p", 1280, 720}, {"1080p", 1920, 1080}, {NULL, 0, 0}};
{ "cif" , 352, 288},
{ "vga" , 640, 480},
{ "sd1" , 720, 480},
{ "sd2" , 704, 576},
{ "sd3" , 720, 576},
{ "720p" , 1280, 720},
{ "1080p" , 1920, 1080},
{ NULL, 0, 0}
};
/*! /*!
************************************************************************ ************************************************************************
@ -43,8 +35,8 @@ static const VIDEO_SIZE VideoRes[] = {
* *
************************************************************************ ************************************************************************
*/ */
int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, double *fps) int ParseSizeFromString(VideoDataFile *input_file, int *x_size, int *y_size,
{ double *fps) {
char *p1, *p2, *tail; char *p1, *p2, *tail;
char *fn = input_file->fname; char *fn = input_file->fname;
char c; char c;
@ -52,27 +44,26 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
*x_size = *y_size = -1; *x_size = *y_size = -1;
p1 = p2 = fn; p1 = p2 = fn;
while (p1 != NULL && p2 != NULL) while (p1 != NULL && p2 != NULL) {
{
// Search for first '_' // Search for first '_'
p1 = strstr( p1, "_"); p1 = strstr(p1, "_");
if (p1 == NULL) if (p1 == NULL)
break; break;
// Search for end character of x_size (first 'x' after last '_') // Search for end character of x_size (first 'x' after last '_')
p2 = strstr( p1, "x"); p2 = strstr(p1, "x");
// If no 'x' is found, exit // If no 'x' is found, exit
if (p2 == NULL) if (p2 == NULL)
break; break;
// Try conversion of number // Try conversion of number
*p2 = 0; *p2 = 0;
*x_size = strtol( p1 + 1, &tail, 10); *x_size = strtol(p1 + 1, &tail, 10);
// If there are characters left in the string, or the string is null, discard conversion // If there are characters left in the string, or the string is null,
if (*tail != '\0' || *(p1 + 1) == '\0') // discard conversion
{ if (*tail != '\0' || *(p1 + 1) == '\0') {
*p2 = 'x'; *p2 = 'x';
p1 = tail; p1 = tail;
continue; continue;
@ -82,10 +73,9 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
*p2 = 'x'; *p2 = 'x';
// Search for end character of y_size (first '_' or '.' after last 'x') // Search for end character of y_size (first '_' or '.' after last 'x')
p1 = strpbrk( p2 + 1, "_."); p1 = strpbrk(p2 + 1, "_.");
// If no '_' or '.' is found, try again from current position // If no '_' or '.' is found, try again from current position
if (p1 == NULL) if (p1 == NULL) {
{
p1 = p2 + 1; p1 = p2 + 1;
continue; continue;
} }
@ -93,11 +83,11 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
// Try conversion of number // Try conversion of number
c = *p1; c = *p1;
*p1 = 0; *p1 = 0;
*y_size = strtol( p2 + 1, &tail, 10); *y_size = strtol(p2 + 1, &tail, 10);
// If there are characters left in the string, or the string is null, discard conversion // If there are characters left in the string, or the string is null,
if (*tail != '\0' || *(p2 + 1) == '\0') // discard conversion
{ if (*tail != '\0' || *(p2 + 1) == '\0') {
*p1 = c; *p1 = c;
p1 = tail; p1 = tail;
continue; continue;
@ -107,20 +97,20 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
*p1 = c; *p1 = c;
// Search for end character of y_size (first 'i' or 'p' after last '_') // Search for end character of y_size (first 'i' or 'p' after last '_')
p2 = strstr( p1 + 1, "ip"); p2 = strstr(p1 + 1, "ip");
// If no 'i' or 'p' is found, exit // If no 'i' or 'p' is found, exit
if (p2 == NULL) if (p2 == NULL)
break; break;
// Try conversion of number // Try conversion of number
c = *p2; c = *p2;
*p2 = 0; *p2 = 0;
*fps = strtod( p1 + 1, &tail); *fps = strtod(p1 + 1, &tail);
// If there are characters left in the string, or the string is null, discard conversion // If there are characters left in the string, or the string is null,
if (*tail != '\0' || *(p1 + 1) == '\0') // discard conversion
{ if (*tail != '\0' || *(p1 + 1) == '\0') {
*p2 = c; *p2 = c;
p1 = tail; p1 = tail;
continue; continue;
@ -132,21 +122,18 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
} }
// Now lets test some common video file formats // Now lets test some common video file formats
if (p1 == NULL || p2 == NULL) if (p1 == NULL || p2 == NULL) {
{ for (i = 0; VideoRes[i].name != NULL; i++) {
for (i = 0; VideoRes[i].name != NULL; i++) if (STRCMP(fn, VideoRes[i].name)) {
{
if (STRCMP (fn, VideoRes[i].name))
{
*x_size = VideoRes[i].x_size; *x_size = VideoRes[i].x_size;
*y_size = VideoRes[i].y_size; *y_size = VideoRes[i].y_size;
// Should add frame rate support as well // Should add frame rate support as well
break; break;
} }
} }
} }
return (*x_size == -1 || *y_size == -1) ? 0 : 1; return (*x_size == -1 || *y_size == -1) ? 0 : 1;
} }
/*! /*!
@ -156,45 +143,43 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do
* *
************************************************************************ ************************************************************************
*/ */
void ParseFrameNoFormatFromString (VideoDataFile *input_file) void ParseFrameNoFormatFromString(VideoDataFile *input_file) {
{ char *p1, *p2, *tail;
char *p1, *p2, *tail; char *fn = input_file->fname;
char *fn = input_file->fname; char *fhead = input_file->fhead;
char *fhead = input_file->fhead; char *ftail = input_file->ftail;
char *ftail = input_file->ftail; int *zero_pad = &input_file->zero_pad;
int *zero_pad = &input_file->zero_pad; int *num_digits = &input_file->num_digits;
int *num_digits = &input_file->num_digits;
*zero_pad = 0; *zero_pad = 0;
*num_digits = -1; *num_digits = -1;
p1 = p2 = fn; p1 = p2 = fn;
while (p1 != NULL && p2 != NULL) while (p1 != NULL && p2 != NULL) {
{
// Search for first '_' // Search for first '_'
p1 = strstr( p1, "%"); p1 = strstr(p1, "%");
if (p1 == NULL) if (p1 == NULL)
break; break;
strncpy(fhead, fn, p1 - fn); strncpy(fhead, fn, p1 - fn);
// Search for end character of x_size (first 'x' after last '_') // Search for end character of x_size (first 'x' after last '_')
p2 = strstr( p1, "d"); p2 = strstr(p1, "d");
// If no 'x' is found, exit // If no 'x' is found, exit
if (p2 == NULL) if (p2 == NULL)
break; break;
// Try conversion of number // Try conversion of number
*p2 = 0; *p2 = 0;
if (*(p1 + 1) == '0') if (*(p1 + 1) == '0')
*zero_pad = 1; *zero_pad = 1;
*num_digits = strtol( p1 + 1, &tail, 10); *num_digits = strtol(p1 + 1, &tail, 10);
// If there are characters left in the string, or the string is null, discard conversion // If there are characters left in the string, or the string is null,
if (*tail != '\0' || *(p1 + 1) == '\0') // discard conversion
{ if (*tail != '\0' || *(p1 + 1) == '\0') {
*p2 = 'd'; *p2 = 'd';
p1 = tail; p1 = tail;
continue; continue;
@ -204,15 +189,13 @@ void ParseFrameNoFormatFromString (VideoDataFile *input_file)
*p2 = 'd'; *p2 = 'd';
tail++; tail++;
strncpy(ftail, tail, (int) strlen(tail)); strncpy(ftail, tail, (int)strlen(tail));
break; break;
} }
if (input_file->vdtype == VIDEO_TIFF) if (input_file->vdtype == VIDEO_TIFF) {
{
input_file->is_concatenated = 0; input_file->is_concatenated = 0;
} } else
else
input_file->is_concatenated = (*num_digits == -1) ? 1 : 0; input_file->is_concatenated = (*num_digits == -1) ? 1 : 0;
} }
@ -222,31 +205,29 @@ void ParseFrameNoFormatFromString (VideoDataFile *input_file)
* Open file containing a single frame * Open file containing a single frame
************************************************************************ ************************************************************************
*/ */
void OpenFrameFile( VideoDataFile *input_file, int FrameNumberInFile) void OpenFrameFile(VideoDataFile *input_file, int FrameNumberInFile) {
{ char infile[FILE_NAME_SIZE], in_number[16];
char infile [FILE_NAME_SIZE], in_number[16];
int length = 0; int length = 0;
in_number[length]='\0'; in_number[length] = '\0';
length = (int) strlen(input_file->fhead); length = (int)strlen(input_file->fhead);
strncpy(infile, input_file->fhead, length); strncpy(infile, input_file->fhead, length);
infile[length]='\0'; infile[length] = '\0';
if (input_file->zero_pad) if (input_file->zero_pad)
snprintf(in_number, 16, "%0*d", input_file->num_digits, FrameNumberInFile); snprintf(in_number, 16, "%0*d", input_file->num_digits, FrameNumberInFile);
else else
snprintf(in_number, 16, "%*d", input_file->num_digits, FrameNumberInFile); snprintf(in_number, 16, "%*d", input_file->num_digits, FrameNumberInFile);
strncat(infile, in_number, sizeof(in_number)); strncat(infile, in_number, sizeof(in_number));
length += sizeof(in_number); length += sizeof(in_number);
infile[length]='\0'; infile[length] = '\0';
strncat(infile, input_file->ftail, strlen(input_file->ftail)); strncat(infile, input_file->ftail, strlen(input_file->ftail));
length += (int) strlen(input_file->ftail); length += (int)strlen(input_file->ftail);
infile[length]='\0'; infile[length] = '\0';
if ((input_file->f_num = open(infile, OPENFLAGS_READ)) == -1) if ((input_file->f_num = open(infile, OPENFLAGS_READ)) == -1) {
{ printf("OpenFrameFile: cannot open file %s\n", infile);
printf ("OpenFrameFile: cannot open file %s\n", infile);
report_stats_on_error(); report_stats_on_error();
} }
} }
/*! /*!
@ -255,20 +236,18 @@ void OpenFrameFile( VideoDataFile *input_file, int FrameNumberInFile)
* Open file(s) containing the entire frame sequence * Open file(s) containing the entire frame sequence
************************************************************************ ************************************************************************
*/ */
void OpenFiles( VideoDataFile *input_file) void OpenFiles(VideoDataFile *input_file) {
{ if (input_file->is_concatenated == 1) {
if (input_file->is_concatenated == 1) if ((int)strlen(input_file->fname) == 0) {
{ snprintf(errortext, ET_SIZE,
if ((int) strlen(input_file->fname) == 0) "No input sequence name was provided. Please check settings.");
{ error(errortext, 500);
snprintf(errortext, ET_SIZE, "No input sequence name was provided. Please check settings.");
error (errortext, 500);
} }
if ((input_file->f_num = open(input_file->fname, OPENFLAGS_READ)) == -1) if ((input_file->f_num = open(input_file->fname, OPENFLAGS_READ)) == -1) {
{ snprintf(errortext, ET_SIZE, "Input file %s does not exist",
snprintf(errortext, ET_SIZE, "Input file %s does not exist",input_file->fname); input_file->fname);
error (errortext, 500); error(errortext, 500);
} }
} }
} }
@ -279,8 +258,7 @@ void OpenFiles( VideoDataFile *input_file)
* Close input file * Close input file
************************************************************************ ************************************************************************
*/ */
void CloseFiles(VideoDataFile *input_file) void CloseFiles(VideoDataFile *input_file) {
{
if (input_file->f_num != -1) if (input_file->f_num != -1)
close(input_file->f_num); close(input_file->f_num);
input_file->f_num = -1; input_file->f_num = -1;
@ -291,38 +269,28 @@ void CloseFiles(VideoDataFile *input_file)
* ParseVideoType * ParseVideoType
* *
* ========================================================================== * ==========================================================================
*/ */
VideoFileType ParseVideoType (VideoDataFile *input_file) VideoFileType ParseVideoType(VideoDataFile *input_file) {
{
char *format; char *format;
format = input_file->fname + (int) strlen(input_file->fname) - 3; format = input_file->fname + (int)strlen(input_file->fname) - 3;
if (STRCMP (format, "yuv") == 0) if (STRCMP(format, "yuv") == 0) {
{
input_file->vdtype = VIDEO_YUV; input_file->vdtype = VIDEO_YUV;
input_file->format.yuv_format = YUV420; input_file->format.yuv_format = YUV420;
input_file->avi = NULL; input_file->avi = NULL;
} } else if (STRCMP(format, "rgb") == 0) {
else if (STRCMP (format, "rgb") == 0)
{
input_file->vdtype = VIDEO_RGB; input_file->vdtype = VIDEO_RGB;
input_file->format.yuv_format = YUV444; input_file->format.yuv_format = YUV444;
input_file->avi = NULL; input_file->avi = NULL;
} } else if (STRCMP(format, "tif") == 0) {
else if (STRCMP (format, "tif") == 0)
{
input_file->vdtype = VIDEO_TIFF; input_file->vdtype = VIDEO_TIFF;
input_file->avi = NULL; input_file->avi = NULL;
} } else if (STRCMP(format, "avi") == 0) {
else if (STRCMP (format, "avi") == 0)
{
input_file->vdtype = VIDEO_AVI; input_file->vdtype = VIDEO_AVI;
} } else {
else // snprintf(errortext, ET_SIZE, "ERROR: video file format not supported");
{ // error (errortext, 500);
//snprintf(errortext, ET_SIZE, "ERROR: video file format not supported");
//error (errortext, 500);
input_file->vdtype = VIDEO_YUV; input_file->vdtype = VIDEO_YUV;
input_file->format.yuv_format = YUV420; input_file->format.yuv_format = YUV420;
input_file->avi = NULL; input_file->avi = NULL;

View file

@ -6,42 +6,40 @@
* Input data Image Processing functions * Input data Image Processing functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexis.tourapis@dolby.com> * - Alexis Michael Tourapis <alexis.tourapis@dolby.com>
* *
************************************************************************************* *************************************************************************************
*/ */
#include "contributors.h"
#include "global.h"
#include "img_process.h" #include "img_process.h"
#include "contributors.h"
#include "fast_memory.h"
#include "global.h"
#include "io_image.h" #include "io_image.h"
#include "memalloc.h" #include "memalloc.h"
#include "fast_memory.h"
static inline void ResetImage(ImageData *imgOut) {
fast_memset(imgOut->frm_data[0][0], 0,
imgOut->format.height[0] * imgOut->format.width[0] *
sizeof(imgpel));
static inline void ResetImage(ImageData *imgOut) if (imgOut->format.yuv_format != YUV400) {
{ if (sizeof(imgpel) == sizeof(signed char)) {
fast_memset(imgOut->frm_data[0][0], 0, imgOut->format.height[0] * imgOut->format.width[0] * sizeof (imgpel)); fast_memset(imgOut->frm_data[1][0], 128,
imgOut->format.height[1] * imgOut->format.width[1] *
if (imgOut->format.yuv_format != YUV400) sizeof(imgpel));
{ fast_memset(imgOut->frm_data[2][0], 128,
if (sizeof(imgpel) == sizeof(signed char)) imgOut->format.height[1] * imgOut->format.width[1] *
{ sizeof(imgpel));
fast_memset(imgOut->frm_data[1][0], 128, imgOut->format.height[1] * imgOut->format.width[1] * sizeof (imgpel)); } else {
fast_memset(imgOut->frm_data[2][0], 128, imgOut->format.height[1] * imgOut->format.width[1] * sizeof (imgpel));
}
else
{
int i, j, k; int i, j, k;
imgpel med_value; imgpel med_value;
for (k = 1; k <=2; k++) for (k = 1; k <= 2; k++) {
{ med_value = (imgpel)(imgOut->format.max_value[k] + 1) >> 1;
med_value = (imgpel) (imgOut->format.max_value[k] + 1) >> 1; for (j = 0; j < imgOut->format.height[1]; j++) {
for (j = 0; j < imgOut->format.height[1]; j++) for (i = 0; i < imgOut->format.width[1]; i++) {
{
for (i = 0; i < imgOut->format.width[1]; i++)
{
imgOut->frm_data[k][j][i] = med_value; imgOut->frm_data[k][j][i] = med_value;
} }
} }
@ -50,124 +48,129 @@ static inline void ResetImage(ImageData *imgOut)
} }
} }
static inline void CPImage(ImageData *imgOut, ImageData *imgIn) {
memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0],
imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel));
static inline void CPImage(ImageData *imgOut, ImageData *imgIn) if (imgIn->format.yuv_format != YUV400) {
{ memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0],
memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0],
if (imgIn->format.yuv_format != YUV400) imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
{
memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel));
memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel));
} }
} }
// to be modified // to be modified
static inline void FilterImage(ImageData *imgOut, ImageData *imgIn) static inline void FilterImage(ImageData *imgOut, ImageData *imgIn) {
{ memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0],
memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel));
if (imgIn->format.yuv_format != YUV400) if (imgIn->format.yuv_format != YUV400) {
{ memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0],
memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0],
imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
} }
} }
// Line interleaving for 3:2 pulldown // Line interleaving for 3:2 pulldown
static inline void BlendImageLines(ImageData *imgIn0, ImageData *imgIn1) static inline void BlendImageLines(ImageData *imgIn0, ImageData *imgIn1) {
{
int j; int j;
for (j = 1; j < imgIn1->format.height[0]; j += 2) for (j = 1; j < imgIn1->format.height[0]; j += 2)
memcpy(imgIn0->frm_data[0][j], imgIn1->frm_data[0][j], imgIn1->format.width[0] * sizeof (imgpel)); memcpy(imgIn0->frm_data[0][j], imgIn1->frm_data[0][j],
imgIn1->format.width[0] * sizeof(imgpel));
if (imgIn1->format.yuv_format != YUV400) if (imgIn1->format.yuv_format != YUV400) {
{ for (j = 1; j < imgIn1->format.height[1]; j += 2) {
for (j = 1; j < imgIn1->format.height[1]; j += 2) memcpy(imgIn0->frm_data[1][j], imgIn1->frm_data[1][j],
{ imgIn1->format.width[1] * sizeof(imgpel));
memcpy(imgIn0->frm_data[1][j], imgIn1->frm_data[1][j], imgIn1->format.width[1] * sizeof (imgpel));
} }
for (j = 1; j < imgIn1->format.height[2]; j += 2) for (j = 1; j < imgIn1->format.height[2]; j += 2) {
{ memcpy(imgIn0->frm_data[2][j], imgIn1->frm_data[2][j],
memcpy(imgIn0->frm_data[2][j], imgIn1->frm_data[2][j], imgIn1->format.width[2] * sizeof (imgpel)); imgIn1->format.width[2] * sizeof(imgpel));
} }
} }
} }
// to be modified // to be modified
static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn) static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn) {
{
int i, j; int i, j;
static const int SepFilter[6] = {1, -5, 20, 20, -5, 1}; static const int SepFilter[6] = {1, -5, 20, 20, -5, 1};
int max_width = imgOut->format.width[0] - 1; int max_width = imgOut->format.width[0] - 1;
int max_height = imgOut->format.height[0] - 1; int max_height = imgOut->format.height[0] - 1;
int **temp_data = new_mem2Dint(imgIn->format.height[0], imgIn->format.width[0]); // temp memory for filtering. Could be allocated once to speed up code int **temp_data = new_mem2Dint(
imgIn->format.height[0],
imgIn->format.width[0]); // temp memory for filtering. Could be allocated
// once to speed up code
// implementation was not optimized. only just implemented as proof of concept // implementation was not optimized. only just implemented as proof of concept
// horizontal filtering // horizontal filtering
for (j = 0; j < imgOut->format.height[0]; j++) for (j = 0; j < imgOut->format.height[0]; j++) {
{ for (i = 0; i < imgOut->format.width[0]; i++) {
for (i = 0; i < imgOut->format.width[0]; i++) temp_data[j][i] =
{ SepFilter[0] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 2)] +
temp_data[j][i] = SepFilter[1] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 1)] +
SepFilter[0] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 2)] + SepFilter[2] * imgIn->frm_data[0][j][iClip3(0, max_width, i)] +
SepFilter[1] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 1)] + SepFilter[3] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 1)] +
SepFilter[2] * imgIn->frm_data[0][j][iClip3(0, max_width, i )] + SepFilter[4] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 2)] +
SepFilter[3] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 1)] + SepFilter[5] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 3)];
SepFilter[4] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 2)] +
SepFilter[5] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 3)];
} }
} }
for (j = 0; j < imgOut->format.height[0]; j++) for (j = 0; j < imgOut->format.height[0]; j++) {
{ for (i = 0; i < imgOut->format.width[0]; i++) {
for (i = 0; i < imgOut->format.width[0]; i++) imgOut->frm_data[0][j][i] = (imgpel)iClip3(
{ 0, imgOut->format.max_value[0],
imgOut->frm_data[0][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[0], rshift_rnd_sign( rshift_rnd_sign(
SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] +
SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] + SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] +
SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] + SepFilter[2] * temp_data[iClip3(0, max_height, j)][i] +
SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] + SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] +
SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] + SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] +
SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10)); SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i],
10));
} }
} }
if (imgOut->format.yuv_format != YUV400) if (imgOut->format.yuv_format != YUV400) {
{
int k; int k;
max_width = imgOut->format.width[1] - 1; max_width = imgOut->format.width[1] - 1;
max_height = imgOut->format.height[1] - 1; max_height = imgOut->format.height[1] - 1;
for (k = 1; k <=2; k++) for (k = 1; k <= 2; k++) {
{
// horizontal filtering // horizontal filtering
for (j = 0; j < imgOut->format.height[1]; j++) for (j = 0; j < imgOut->format.height[1]; j++) {
{ for (i = 0; i < imgOut->format.width[1]; i++) {
for (i = 0; i < imgOut->format.width[1]; i++) temp_data[j][i] =
{ SepFilter[0] *
temp_data[j][i] = imgIn->frm_data[k][j][iClip3(0, max_width, i - 2)] +
SepFilter[0] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 2)] + SepFilter[1] *
SepFilter[1] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 1)] + imgIn->frm_data[k][j][iClip3(0, max_width, i - 1)] +
SepFilter[2] * imgIn->frm_data[k][j][iClip3(0, max_width, i )] + SepFilter[2] * imgIn->frm_data[k][j][iClip3(0, max_width, i)] +
SepFilter[3] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 1)] + SepFilter[3] *
SepFilter[4] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 2)] + imgIn->frm_data[k][j][iClip3(0, max_width, i + 1)] +
SepFilter[5] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 3)]; SepFilter[4] *
imgIn->frm_data[k][j][iClip3(0, max_width, i + 2)] +
SepFilter[5] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 3)];
} }
} }
for (j = 0; j < imgOut->format.height[1]; j++) for (j = 0; j < imgOut->format.height[1]; j++) {
{ for (i = 0; i < imgOut->format.width[1]; i++) {
for (i = 0; i < imgOut->format.width[1]; i++) imgOut->frm_data[k][j][i] = (imgpel)iClip3(
{ 0, imgOut->format.max_value[k],
imgOut->frm_data[k][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[k], rshift_rnd_sign( rshift_rnd_sign(
SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] +
SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] + SepFilter[1] *
SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] + temp_data[iClip3(0, max_height, j - 1)][i] +
SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] + SepFilter[2] * temp_data[iClip3(0, max_height, j)][i] +
SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] + SepFilter[3] *
SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10)); temp_data[iClip3(0, max_height, j + 1)][i] +
SepFilter[4] *
temp_data[iClip3(0, max_height, j + 2)][i] +
SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i],
10));
} }
} }
} }
@ -176,70 +179,66 @@ static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn)
free_mem2Dint(temp_data); free_mem2Dint(temp_data);
} }
// to be modified // to be modified
static inline void MuxImages(ImageData *imgOut, ImageData *imgIn0, ImageData *imgIn1, ImageData *Map) static inline void MuxImages(ImageData *imgOut, ImageData *imgIn0,
{ ImageData *imgIn1, ImageData *Map) {
int i, j; int i, j;
for (j = 0; j < imgOut->format.height[0]; j++) for (j = 0; j < imgOut->format.height[0]; j++) {
{ for (i = 0; i < imgOut->format.width[0]; i++) {
for (i = 0; i < imgOut->format.width[0]; i++) imgOut->frm_data[0][j][i] = (imgpel)rshift_rnd_sf(
{ imgIn0->frm_data[0][j][i] *
imgOut->frm_data[0][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[0][j][i] * (Map->format.max_value[0] - Map->frm_data[0][j][i]) + imgIn1->frm_data[0][j][i] * Map->frm_data[0][j][i], Map->format.bit_depth[0]); (Map->format.max_value[0] - Map->frm_data[0][j][i]) +
imgIn1->frm_data[0][j][i] * Map->frm_data[0][j][i],
Map->format.bit_depth[0]);
} }
} }
if (imgOut->format.yuv_format != YUV400) if (imgOut->format.yuv_format != YUV400) {
{
int k; int k;
for (k = 1; k <=2; k++) for (k = 1; k <= 2; k++) {
{ for (j = 0; j < imgOut->format.height[1]; j++) {
for (j = 0; j < imgOut->format.height[1]; j++) for (i = 0; i < imgOut->format.width[1]; i++) {
{ imgOut->frm_data[k][j][i] = (imgpel)rshift_rnd_sf(
for (i = 0; i < imgOut->format.width[1]; i++) imgIn0->frm_data[k][j][i] *
{ (Map->format.max_value[k] - Map->frm_data[k][j][i]) +
imgOut->frm_data[k][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[k][j][i] * (Map->format.max_value[k] - Map->frm_data[k][j][i]) + imgIn1->frm_data[k][j][i] * Map->frm_data[k][j][i], Map->format.bit_depth[k]); imgIn1->frm_data[k][j][i] * Map->frm_data[k][j][i],
Map->format.bit_depth[k]);
} }
} }
} }
} }
} }
static inline void YV12toYUV(ImageData *imgOut, ImageData *imgIn) static inline void YV12toYUV(ImageData *imgOut, ImageData *imgIn) {
{ memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0],
memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel));
if (imgIn->format.yuv_format != YUV400) if (imgIn->format.yuv_format != YUV400) {
{ memcpy(imgOut->frm_data[1][0], imgIn->frm_data[2][0],
memcpy(imgOut->frm_data[1][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
memcpy(imgOut->frm_data[2][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); memcpy(imgOut->frm_data[2][0], imgIn->frm_data[1][0],
imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel));
} }
} }
int init_process_image( VideoParameters *p_Vid, InputParameters *p_Inp) int init_process_image(VideoParameters *p_Vid, InputParameters *p_Inp) {
{
int memory_size = 0; int memory_size = 0;
switch( p_Inp->ProcessInput ) switch (p_Inp->ProcessInput) {
{
default: default:
break; break;
} }
return memory_size; return memory_size;
} }
void clear_process_image( VideoParameters *p_Vid, InputParameters *p_Inp) void clear_process_image(VideoParameters *p_Vid, InputParameters *p_Inp) {
{ switch (p_Inp->ProcessInput) {
switch( p_Inp->ProcessInput )
{
default: default:
break; break;
} }
} }
void process_image( VideoParameters *p_Vid, InputParameters *p_Inp ) void process_image(VideoParameters *p_Vid, InputParameters *p_Inp) {
{ switch (p_Inp->ProcessInput) {
switch( p_Inp->ProcessInput )
{
default: default:
case 0: case 0:
CPImage(&p_Vid->imgData, &p_Vid->imgData0); CPImage(&p_Vid->imgData, &p_Vid->imgData0);
@ -248,33 +247,31 @@ void process_image( VideoParameters *p_Vid, InputParameters *p_Inp )
break; break;
case 1: case 1:
FilterImage(&p_Vid->imgData, &p_Vid->imgData0); FilterImage(&p_Vid->imgData, &p_Vid->imgData0);
if (p_Inp->enable_32_pulldown) if (p_Inp->enable_32_pulldown) {
{
FilterImage(&p_Vid->imgData32, &p_Vid->imgData4); FilterImage(&p_Vid->imgData32, &p_Vid->imgData4);
BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32);
} }
break; break;
case 2: case 2:
YV12toYUV(&p_Vid->imgData, &p_Vid->imgData0); YV12toYUV(&p_Vid->imgData, &p_Vid->imgData0);
if (p_Inp->enable_32_pulldown) if (p_Inp->enable_32_pulldown) {
{
YV12toYUV(&p_Vid->imgData32, &p_Vid->imgData4); YV12toYUV(&p_Vid->imgData32, &p_Vid->imgData4);
BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32);
} }
break; break;
case 3: case 3:
MuxImages(&p_Vid->imgData, &p_Vid->imgData0, &p_Vid->imgData1, &p_Vid->imgData2); MuxImages(&p_Vid->imgData, &p_Vid->imgData0, &p_Vid->imgData1,
if (p_Inp->enable_32_pulldown) &p_Vid->imgData2);
{ if (p_Inp->enable_32_pulldown) {
MuxImages(&p_Vid->imgData32, &p_Vid->imgData4, &p_Vid->imgData5, &p_Vid->imgData6); MuxImages(&p_Vid->imgData32, &p_Vid->imgData4, &p_Vid->imgData5,
&p_Vid->imgData6);
BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32);
} }
break; break;
case 4: case 4:
FilterImageSep(&p_Vid->imgData, &p_Vid->imgData0); FilterImageSep(&p_Vid->imgData, &p_Vid->imgData0);
if (p_Inp->enable_32_pulldown) if (p_Inp->enable_32_pulldown) {
{
FilterImageSep(&p_Vid->imgData, &p_Vid->imgData4); FilterImageSep(&p_Vid->imgData, &p_Vid->imgData4);
BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32);
} }
@ -282,6 +279,3 @@ void process_image( VideoParameters *p_Vid, InputParameters *p_Inp )
break; break;
} }
} }

View file

@ -14,9 +14,8 @@
#include "nalucommon.h" #include "nalucommon.h"
typedef struct annex_b_struct typedef struct annex_b_struct {
{ int BitStreamFile; //!< the bit stream file
int BitStreamFile; //!< the bit stream file
byte *iobuffer; byte *iobuffer;
byte *iobufferread; byte *iobufferread;
int bytesinbuffer; int bytesinbuffer;
@ -25,15 +24,14 @@ typedef struct annex_b_struct
int IsFirstByteStreamNALU; int IsFirstByteStreamNALU;
int nextstartcodebytes; int nextstartcodebytes;
byte *Buf; byte *Buf;
} ANNEXB_t; } ANNEXB_t;
extern int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu); extern int GetAnnexbNALU(VideoParameters *p_Vid, NALU_t *nalu);
extern void OpenAnnexBFile (VideoParameters *p_Vid, char *fn); extern void OpenAnnexBFile(VideoParameters *p_Vid, char *fn);
extern void CloseAnnexBFile(VideoParameters *p_Vid); extern void CloseAnnexBFile(VideoParameters *p_Vid);
extern void malloc_annex_b (VideoParameters *p_Vid); extern void malloc_annex_b(VideoParameters *p_Vid);
extern void free_annex_b (VideoParameters *p_Vid); extern void free_annex_b(VideoParameters *p_Vid);
extern void init_annex_b (ANNEXB_t *annex_b); extern void init_annex_b(ANNEXB_t *annex_b);
extern void ResetAnnexB (ANNEXB_t *annex_b); extern void ResetAnnexB(ANNEXB_t *annex_b);
#endif #endif

View file

@ -20,116 +20,63 @@
#ifndef _BIARIDECOD_H_ #ifndef _BIARIDECOD_H_
#define _BIARIDECOD_H_ #define _BIARIDECOD_H_
/************************************************************************ /************************************************************************
* D e f i n i t i o n s * D e f i n i t i o n s
*********************************************************************** ***********************************************************************
*/ */
/* Range table for LPS */ /* Range table for LPS */
static const byte rLPS_table_64x4[64][4]= static const byte rLPS_table_64x4[64][4] = {
{ {128, 176, 208, 240}, {128, 167, 197, 227}, {128, 158, 187, 216},
{ 128, 176, 208, 240}, {123, 150, 178, 205}, {116, 142, 169, 195}, {111, 135, 160, 185},
{ 128, 167, 197, 227}, {105, 128, 152, 175}, {100, 122, 144, 166}, {95, 116, 137, 158},
{ 128, 158, 187, 216}, {90, 110, 130, 150}, {85, 104, 123, 142}, {81, 99, 117, 135},
{ 123, 150, 178, 205}, {77, 94, 111, 128}, {73, 89, 105, 122}, {69, 85, 100, 116},
{ 116, 142, 169, 195}, {66, 80, 95, 110}, {62, 76, 90, 104}, {59, 72, 86, 99},
{ 111, 135, 160, 185}, {56, 69, 81, 94}, {53, 65, 77, 89}, {51, 62, 73, 85},
{ 105, 128, 152, 175}, {48, 59, 69, 80}, {46, 56, 66, 76}, {43, 53, 63, 72},
{ 100, 122, 144, 166}, {41, 50, 59, 69}, {39, 48, 56, 65}, {37, 45, 54, 62},
{ 95, 116, 137, 158}, {35, 43, 51, 59}, {33, 41, 48, 56}, {32, 39, 46, 53},
{ 90, 110, 130, 150}, {30, 37, 43, 50}, {29, 35, 41, 48}, {27, 33, 39, 45},
{ 85, 104, 123, 142}, {26, 31, 37, 43}, {24, 30, 35, 41}, {23, 28, 33, 39},
{ 81, 99, 117, 135}, {22, 27, 32, 37}, {21, 26, 30, 35}, {20, 24, 29, 33},
{ 77, 94, 111, 128}, {19, 23, 27, 31}, {18, 22, 26, 30}, {17, 21, 25, 28},
{ 73, 89, 105, 122}, {16, 20, 23, 27}, {15, 19, 22, 25}, {14, 18, 21, 24},
{ 69, 85, 100, 116}, {14, 17, 20, 23}, {13, 16, 19, 22}, {12, 15, 18, 21},
{ 66, 80, 95, 110}, {12, 14, 17, 20}, {11, 14, 16, 19}, {11, 13, 15, 18},
{ 62, 76, 90, 104}, {10, 12, 15, 17}, {10, 12, 14, 16}, {9, 11, 13, 15},
{ 59, 72, 86, 99}, {9, 11, 12, 14}, {8, 10, 12, 14}, {8, 9, 11, 13},
{ 56, 69, 81, 94}, {7, 9, 11, 12}, {7, 9, 10, 12}, {7, 8, 10, 11},
{ 53, 65, 77, 89}, {6, 8, 9, 11}, {6, 7, 9, 10}, {6, 7, 8, 9},
{ 51, 62, 73, 85}, {2, 2, 2, 2}};
{ 48, 59, 69, 80},
{ 46, 56, 66, 76},
{ 43, 53, 63, 72},
{ 41, 50, 59, 69},
{ 39, 48, 56, 65},
{ 37, 45, 54, 62},
{ 35, 43, 51, 59},
{ 33, 41, 48, 56},
{ 32, 39, 46, 53},
{ 30, 37, 43, 50},
{ 29, 35, 41, 48},
{ 27, 33, 39, 45},
{ 26, 31, 37, 43},
{ 24, 30, 35, 41},
{ 23, 28, 33, 39},
{ 22, 27, 32, 37},
{ 21, 26, 30, 35},
{ 20, 24, 29, 33},
{ 19, 23, 27, 31},
{ 18, 22, 26, 30},
{ 17, 21, 25, 28},
{ 16, 20, 23, 27},
{ 15, 19, 22, 25},
{ 14, 18, 21, 24},
{ 14, 17, 20, 23},
{ 13, 16, 19, 22},
{ 12, 15, 18, 21},
{ 12, 14, 17, 20},
{ 11, 14, 16, 19},
{ 11, 13, 15, 18},
{ 10, 12, 15, 17},
{ 10, 12, 14, 16},
{ 9, 11, 13, 15},
{ 9, 11, 12, 14},
{ 8, 10, 12, 14},
{ 8, 9, 11, 13},
{ 7, 9, 11, 12},
{ 7, 9, 10, 12},
{ 7, 8, 10, 11},
{ 6, 8, 9, 11},
{ 6, 7, 9, 10},
{ 6, 7, 8, 9},
{ 2, 2, 2, 2}
};
static const byte AC_next_state_MPS_64[64] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 62, 63};
static const byte AC_next_state_MPS_64[64] = static const byte AC_next_state_LPS_64[64] = {
{ 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9, 11, 11, 12,
1,2,3,4,5,6,7,8,9,10, 13, 13, 15, 15, 16, 16, 18, 18, 19, 19, 21, 21, 22, 22, 23, 24,
11,12,13,14,15,16,17,18,19,20, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 30, 30, 31, 32, 32, 33,
21,22,23,24,25,26,27,28,29,30, 33, 33, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 63};
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,62,63
};
static const byte renorm_table_32[32] = {6, 5, 4, 4, 3, 3, 3, 3, 2, 2, 2,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
static const byte AC_next_state_LPS_64[64] = extern void arideco_start_decoding(DecodingEnvironmentPtr eep,
{ unsigned char *code_buffer, int firstbyte,
0, 0, 1, 2, 2, 4, 4, 5, 6, 7, int *code_len);
8, 9, 9,11,11,12,13,13,15,15, extern int arideco_bits_read(DecodingEnvironmentPtr dep);
16,16,18,18,19,19,21,21,22,22,
23,24,24,25,26,26,27,27,28,29,
29,30,30,30,31,32,32,33,33,33,
34,34,35,35,35,36,36,36,37,37,
37,38,38,63
};
static const byte renorm_table_32[32]={6,5,4,4,3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
extern void arideco_start_decoding(DecodingEnvironmentPtr eep, unsigned char *code_buffer, int firstbyte, int *code_len);
extern int arideco_bits_read(DecodingEnvironmentPtr dep);
extern void arideco_done_decoding(DecodingEnvironmentPtr dep); extern void arideco_done_decoding(DecodingEnvironmentPtr dep);
extern void biari_init_context (int qp, BiContextTypePtr ctx, const signed char* ini); extern void biari_init_context(int qp, BiContextTypePtr ctx,
extern unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi_ct ); const signed char *ini);
extern unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep,
BiContextTypePtr bi_ct);
extern unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep); extern unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep);
extern unsigned int biari_decode_final(DecodingEnvironmentPtr dep); extern unsigned int biari_decode_final(DecodingEnvironmentPtr dep);
extern unsigned int getbyte(DecodingEnvironmentPtr dep); extern unsigned int getbyte(DecodingEnvironmentPtr dep);
extern unsigned int getword(DecodingEnvironmentPtr dep); extern unsigned int getword(DecodingEnvironmentPtr dep);
#endif // BIARIDECOD_H_ #endif // BIARIDECOD_H_

View file

@ -8,7 +8,7 @@
* block prediction header * block prediction header
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
@ -19,7 +19,9 @@
#define _BLK_PREDICTION_H_ #define _BLK_PREDICTION_H_
#include "mbuffer.h" #include "mbuffer.h"
extern void compute_residue (imgpel **curImg, imgpel **mb_pred, int **mb_rres, int mb_x, int opix_x, int width, int height); extern void compute_residue(imgpel **curImg, imgpel **mb_pred, int **mb_rres,
extern void sample_reconstruct (imgpel **curImg, imgpel **mb_pred, int **mb_rres, int mb_x, int opix_x, int width, int height, int max_imgpel_value, int dq_bits); int mb_x, int opix_x, int width, int height);
extern void sample_reconstruct(imgpel **curImg, imgpel **mb_pred, int **mb_rres,
int mb_x, int opix_x, int width, int height,
int max_imgpel_value, int dq_bits);
#endif #endif

View file

@ -21,111 +21,101 @@
#include "global.h" #include "global.h"
#include "transform8x8.h" #include "transform8x8.h"
static const byte QP_SCALE_CR[52]= static const byte QP_SCALE_CR[52] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33,
12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 39
28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
37,38,38,38,39,39,39,39
}; };
//! look up tables for FRExt_chroma support //! look up tables for FRExt_chroma support
static const unsigned char subblk_offset_x[3][8][4] = static const unsigned char subblk_offset_x[3][8][4] = {{
{ {0, 4, 0, 4},
{ {0, 4, 0, 4},
{0, 4, 0, 4}, {0, 0, 0, 0},
{0, 4, 0, 4}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, },
{0, 0, 0, 0}, {
}, {0, 4, 0, 4},
{ {0, 4, 0, 4},
{0, 4, 0, 4}, {0, 4, 0, 4},
{0, 4, 0, 4}, {0, 4, 0, 4},
{0, 4, 0, 4}, {0, 0, 0, 0},
{0, 4, 0, 4}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, },
{0, 0, 0, 0}, {{0, 4, 0, 4},
}, {8, 12, 8, 12},
{ {0, 4, 0, 4},
{0, 4, 0, 4}, {8, 12, 8, 12},
{8,12, 8,12}, {0, 4, 0, 4},
{0, 4, 0, 4}, {8, 12, 8, 12},
{8,12, 8,12}, {0, 4, 0, 4},
{0, 4, 0, 4}, {8, 12, 8, 12}}};
{8,12, 8,12},
{0, 4, 0, 4},
{8,12, 8,12}
}
};
static const unsigned char subblk_offset_y[3][8][4] = {{{0, 0, 4, 4},
{0, 0, 4, 4},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}},
{{0, 0, 4, 4},
{8, 8, 12, 12},
{0, 0, 4, 4},
{8, 8, 12, 12},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}},
{{0, 0, 4, 4},
{0, 0, 4, 4},
{8, 8, 12, 12},
{8, 8, 12, 12},
{0, 0, 4, 4},
{0, 0, 4, 4},
{8, 8, 12, 12},
{8, 8, 12, 12}}};
static const unsigned char subblk_offset_y[3][8][4] = static const byte decode_block_scan[16] = {0, 1, 4, 5, 2, 3, 6, 7,
{ 8, 9, 12, 13, 10, 11, 14, 15};
{
{0, 0, 4, 4},
{0, 0, 4, 4},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 4, 4},
{8, 8,12,12},
{0, 0, 4, 4},
{8, 8,12,12},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 4, 4},
{0, 0, 4, 4},
{8, 8,12,12},
{8, 8,12,12},
{0, 0, 4, 4},
{0, 0, 4, 4},
{8, 8,12,12},
{8, 8,12,12}
}
};
static const byte decode_block_scan[16] = {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
extern void iMBtrans4x4(Macroblock *currMB, ColorPlane pl, int smb); extern void iMBtrans4x4(Macroblock *currMB, ColorPlane pl, int smb);
extern void iMBtrans8x8(Macroblock *currMB, ColorPlane pl); extern void iMBtrans8x8(Macroblock *currMB, ColorPlane pl);
extern void itrans_sp_cr(Macroblock *currMB, int uv); extern void itrans_sp_cr(Macroblock *currMB, int uv);
extern void intrapred_chroma (Macroblock *currMB); extern void intrapred_chroma(Macroblock *currMB);
extern void intrapred_chroma_mbaff(Macroblock *currMB); extern void intrapred_chroma_mbaff(Macroblock *currMB);
extern void Inv_Residual_trans_4x4(Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void Inv_Residual_trans_4x4(Macroblock *currMB, ColorPlane pl, int ioff,
extern void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff); int joff);
extern void Inv_Residual_trans_16x16 (Macroblock *currMB, ColorPlane pl); extern void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,
int joff);
extern void Inv_Residual_trans_16x16(Macroblock *currMB, ColorPlane pl);
extern void Inv_Residual_trans_Chroma(Macroblock *currMB, int uv); extern void Inv_Residual_trans_Chroma(Macroblock *currMB, int uv);
extern void itrans4x4 (Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void itrans4x4(Macroblock *currMB, ColorPlane pl, int ioff, int joff);
extern void itrans4x4_ls(Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void itrans4x4_ls(Macroblock *currMB, ColorPlane pl, int ioff, int joff);
extern void itrans_sp (Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void itrans_sp(Macroblock *currMB, ColorPlane pl, int ioff, int joff);
extern int intrapred (Macroblock *currMB, ColorPlane pl, int ioff,int joff,int i4,int j4); extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff,
extern void itrans_2 (Macroblock *currMB, ColorPlane pl); int i4, int j4);
extern void iTransform (Macroblock *currMB, ColorPlane pl, int smb); extern void itrans_2(Macroblock *currMB, ColorPlane pl);
extern void iTransform(Macroblock *currMB, ColorPlane pl, int smb);
extern void copy_image_data (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2, int width, int height); extern void copy_image_data(imgpel **imgBuf1, imgpel **imgBuf2, int off1,
extern void copy_image_data_16x16 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); int off2, int width, int height);
extern void copy_image_data_8x8 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); extern void copy_image_data_16x16(imgpel **imgBuf1, imgpel **imgBuf2, int off1,
extern void copy_image_data_4x4 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); int off2);
extern void copy_image_data_8x8(imgpel **imgBuf1, imgpel **imgBuf2, int off1,
int off2);
extern void copy_image_data_4x4(imgpel **imgBuf1, imgpel **imgBuf2, int off1,
int off2);
extern int CheckVertMV(Macroblock *currMB, int vec1_y, int block_size_y); extern int CheckVertMV(Macroblock *currMB, int vec1_y, int block_size_y);
#endif #endif

View file

@ -21,42 +21,61 @@
#include "global.h" #include "global.h"
extern MotionInfoContexts* create_contexts_MotionInfo(void); extern MotionInfoContexts *create_contexts_MotionInfo(void);
extern TextureInfoContexts* create_contexts_TextureInfo(void); extern TextureInfoContexts *create_contexts_TextureInfo(void);
extern void delete_contexts_MotionInfo(MotionInfoContexts *enco_ctx); extern void delete_contexts_MotionInfo(MotionInfoContexts *enco_ctx);
extern void delete_contexts_TextureInfo(TextureInfoContexts *enco_ctx); extern void delete_contexts_TextureInfo(TextureInfoContexts *enco_ctx);
extern void cabac_new_slice(Slice *currSlice); extern void cabac_new_slice(Slice *currSlice);
extern void readMB_typeInfo_CABAC_i_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, SyntaxElement *se,
extern void readMB_typeInfo_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void readMB_typeInfo_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se,
extern void readB8_typeInfo_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void readB8_typeInfo_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se,
extern void readIntraPredMode_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void readRefFrame_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readB8_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se,
extern void read_MVD_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void read_CBP_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readB8_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se,
extern void readRunLevel_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void read_dQuant_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readIntraPredMode_CABAC(Macroblock *currMB, SyntaxElement *se,
extern void readCIPredMode_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void read_skip_flag_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void readRefFrame_CABAC(Macroblock *currMB, SyntaxElement *se,
extern void read_skip_flag_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void readFieldModeInfo_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); extern void read_MVD_CABAC(Macroblock *currMB, SyntaxElement *se,
extern void readMB_transform_size_flag_CABAC(Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); DecodingEnvironmentPtr dep_dp);
extern void read_CBP_CABAC(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void readRunLevel_CABAC(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void read_dQuant_CABAC(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void readCIPredMode_CABAC(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void read_skip_flag_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void read_skip_flag_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void readFieldModeInfo_CABAC(Macroblock *currMB, SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void readMB_transform_size_flag_CABAC(Macroblock *currMB,
SyntaxElement *se,
DecodingEnvironmentPtr dep_dp);
extern void readIPCM_CABAC(Slice *currSlice, struct datapartition *dP); extern void readIPCM_CABAC(Slice *currSlice, struct datapartition *dP);
extern int cabac_startcode_follows(Slice *currSlice, int eos_bit); extern int cabac_startcode_follows(Slice *currSlice, int eos_bit);
extern int readSyntaxElement_CABAC (Macroblock *currMB, SyntaxElement *se, DataPartition *this_dataPart); extern int readSyntaxElement_CABAC(Macroblock *currMB, SyntaxElement *se,
DataPartition *this_dataPart);
extern int check_next_mb_and_get_field_mode_CABAC_p_slice( Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); extern int check_next_mb_and_get_field_mode_CABAC_p_slice(
extern int check_next_mb_and_get_field_mode_CABAC_b_slice( Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); Slice *currSlice, SyntaxElement *se, DataPartition *act_dp);
extern int check_next_mb_and_get_field_mode_CABAC_b_slice(
Slice *currSlice, SyntaxElement *se, DataPartition *act_dp);
extern void CheckAvailabilityOfNeighborsCABAC(Macroblock *currMB); extern void CheckAvailabilityOfNeighborsCABAC(Macroblock *currMB);
extern void set_read_and_store_CBP(Macroblock **currMB, int chroma_format_idc); extern void set_read_and_store_CBP(Macroblock **currMB, int chroma_format_idc);
#endif // _CABAC_H_ #endif // _CABAC_H_

View file

@ -7,7 +7,8 @@
* Common Config parsing functions * Common Config parsing functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Tourapis <alexismt@ieee.org> * - Alexis Tourapis <alexismt@ieee.org>
* *
************************************************************************ ************************************************************************
@ -17,19 +18,22 @@
//! Maps parameter name to its address, type etc. //! Maps parameter name to its address, type etc.
typedef struct { typedef struct {
char *TokenName; //!< name char *TokenName; //!< name
void *Place; //!< address void *Place; //!< address
int Type; //!< type: 0-int, 1-char[], 2-double int Type; //!< type: 0-int, 1-char[], 2-double
double Default; //!< default value double Default; //!< default value
int param_limits; //!< 0: no limits, 1: both min and max, 2: only min (i.e. no negatives), 3: special case for QPs since min needs bitdepth_qp_scale int param_limits; //!< 0: no limits, 1: both min and max, 2: only min (i.e. no
//!< negatives), 3: special case for QPs since min needs
//!< bitdepth_qp_scale
double min_limit; double min_limit;
double max_limit; double max_limit;
int char_size; //!< Dimension of type char[] int char_size; //!< Dimension of type char[]
} Mapping; } Mapping;
extern char *GetConfigFileContent (char *Filename); extern char *GetConfigFileContent(char *Filename);
extern int InitParams (Mapping *Map); extern int InitParams(Mapping *Map);
extern int TestParams (Mapping *Map, int bitdepth_qp_scale[3]); extern int TestParams(Mapping *Map, int bitdepth_qp_scale[3]);
extern int DisplayParams (Mapping *Map, char *message); extern int DisplayParams(Mapping *Map, char *message);
extern void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize); extern void ParseContent(InputParameters *p_Inp, Mapping *Map, char *buf,
int bufsize);
#endif #endif

View file

@ -14,51 +14,86 @@
#define DEFAULTCONFIGFILENAME "decoder.cfg" #define DEFAULTCONFIGFILENAME "decoder.cfg"
#include "config_common.h" #include "config_common.h"
//#define PROFILE_IDC 88 // #define PROFILE_IDC 88
//#define LEVEL_IDC 21 // #define LEVEL_IDC 21
InputParameters cfgparams; InputParameters cfgparams;
#ifdef INCLUDED_BY_CONFIGFILE_C #ifdef INCLUDED_BY_CONFIGFILE_C
// Mapping_Map Syntax: // Mapping_Map Syntax:
// {NAMEinConfigFile, &cfgparams.VariableName, Type, InitialValue, LimitType, MinLimit, MaxLimit, CharSize} // {NAMEinConfigFile, &cfgparams.VariableName, Type, InitialValue, LimitType,
// Types : {0:int, 1:text, 2: double} // MinLimit, MaxLimit, CharSize} Types : {0:int, 1:text, 2: double} LimitType:
// LimitType: {0:none, 1:both, 2:minimum, 3: QP based} // {0:none, 1:both, 2:minimum, 3: QP based} We could separate this based on
// We could separate this based on types to make it more flexible and allow also defaults for text types. // types to make it more flexible and allow also defaults for text types.
Mapping Map[] = { Mapping Map[] = {
{"InputFile", &cfgparams.infile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, {
{"OutputFile", &cfgparams.outfile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, "InputFile",
{"RefFile", &cfgparams.reffile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, &cfgparams.infile,
{"WriteUV", &cfgparams.write_uv, 0, 0.0, 1, 0.0, 1.0, 0 }, 1,
{"FileFormat", &cfgparams.FileFormat, 0, 0.0, 1, 0.0, 1.0, 0 }, 0.0,
{"RefOffset", &cfgparams.ref_offset, 0, 0.0, 1, 0.0, 256.0, 0 }, 0,
{"POCScale", &cfgparams.poc_scale, 0, 2.0, 1, 1.0, 10.0, 0 }, 0.0,
0.0,
FILE_NAME_SIZE,
},
{
"OutputFile",
&cfgparams.outfile,
1,
0.0,
0,
0.0,
0.0,
FILE_NAME_SIZE,
},
{
"RefFile",
&cfgparams.reffile,
1,
0.0,
0,
0.0,
0.0,
FILE_NAME_SIZE,
},
{"WriteUV", &cfgparams.write_uv, 0, 0.0, 1, 0.0, 1.0, 0},
{"FileFormat", &cfgparams.FileFormat, 0, 0.0, 1, 0.0, 1.0, 0},
{"RefOffset", &cfgparams.ref_offset, 0, 0.0, 1, 0.0, 256.0, 0},
{"POCScale", &cfgparams.poc_scale, 0, 2.0, 1, 1.0, 10.0, 0},
#ifdef _LEAKYBUCKET_ #ifdef _LEAKYBUCKET_
{"R_decoder", &cfgparams.R_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, {"R_decoder", &cfgparams.R_decoder, 0, 0.0, 2, 0.0, 0.0, 0},
{"B_decoder", &cfgparams.B_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, {"B_decoder", &cfgparams.B_decoder, 0, 0.0, 2, 0.0, 0.0, 0},
{"F_decoder", &cfgparams.F_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, {"F_decoder", &cfgparams.F_decoder, 0, 0.0, 2, 0.0, 0.0, 0},
{"LeakyBucketParamFile", &cfgparams.LeakyBucketParamFile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, {
"LeakyBucketParamFile",
&cfgparams.LeakyBucketParamFile,
1,
0.0,
0,
0.0,
0.0,
FILE_NAME_SIZE,
},
#endif #endif
{"DisplayDecParams", &cfgparams.bDisplayDecParams, 0, 1.0, 1, 0.0, 1.0, 0 }, {"DisplayDecParams", &cfgparams.bDisplayDecParams, 0, 1.0, 1, 0.0, 1.0, 0},
{"ConcealMode", &cfgparams.conceal_mode, 0, 0.0, 1, 0.0, 2.0, 0 }, {"ConcealMode", &cfgparams.conceal_mode, 0, 0.0, 1, 0.0, 2.0, 0},
{"RefPOCGap", &cfgparams.ref_poc_gap, 0, 2.0, 1, 0.0, 4.0, 0 }, {"RefPOCGap", &cfgparams.ref_poc_gap, 0, 2.0, 1, 0.0, 4.0, 0},
{"POCGap", &cfgparams.poc_gap, 0, 2.0, 1, 0.0, 4.0, 0 }, {"POCGap", &cfgparams.poc_gap, 0, 2.0, 1, 0.0, 4.0, 0},
{"Silent", &cfgparams.silent, 0, 0.0, 1, 0.0, 1.0, 0 }, {"Silent", &cfgparams.silent, 0, 0.0, 1, 0.0, 1.0, 0},
{"IntraProfileDeblocking", &cfgparams.intra_profile_deblocking, 0, 1.0, 1, 0.0, 1.0, 0 }, {"IntraProfileDeblocking", &cfgparams.intra_profile_deblocking, 0, 1.0, 1,
{"DecFrmNum", &cfgparams.iDecFrmNum, 0, 0.0, 2, 0.0, 0.0, 0 }, 0.0, 1.0, 0},
{"DecFrmNum", &cfgparams.iDecFrmNum, 0, 0.0, 2, 0.0, 0.0, 0},
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
{"DecodeAllLayers", &cfgparams.DecodeAllLayers, 0, 0.0, 1, 0.0, 1.0, 0 }, {"DecodeAllLayers", &cfgparams.DecodeAllLayers, 0, 0.0, 1, 0.0, 1.0, 0},
#endif #endif
{NULL, NULL, -1, 0.0, 0, 0.0, 0.0, 0 }, {NULL, NULL, -1, 0.0, 0, 0.0, 0.0, 0},
}; };
#endif #endif
#ifndef INCLUDED_BY_CONFIGFILE_C #ifndef INCLUDED_BY_CONFIGFILE_C
extern Mapping Map[]; extern Mapping Map[];
#endif #endif
extern void JMDecHelpExit (); extern void JMDecHelpExit();
extern void ParseCommand(InputParameters *p_Inp, int ac, char *av[]); extern void ParseCommand(InputParameters *p_Inp, int ac, char *av[]);
#endif #endif

View file

@ -7,17 +7,16 @@
* CABAC context initializations * CABAC context initializations
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Detlev Marpe <marpe@hhi.de> * - Detlev Marpe <marpe@hhi.de>
* - Heiko Schwarz <hschwarz@hhi.de> * - Heiko Schwarz <hschwarz@hhi.de>
************************************************************************************** **************************************************************************************
*/ */
#ifndef _CONTEXT_INI_ #ifndef _CONTEXT_INI_
#define _CONTEXT_INI_ #define _CONTEXT_INI_
extern void init_contexts (Slice *currslice); extern void init_contexts(Slice *currslice);
#endif #endif

View file

@ -15,10 +15,10 @@
Nokia Inc., USA Nokia Inc., USA
Nokia Corporation, Finland Nokia Corporation, Finland
Siemens AG, Germany Siemens AG, Germany
Fraunhofer-Institute for Telecommunications Heinrich-Hertz-Institut (HHI), Germany Fraunhofer-Institute for Telecommunications Heinrich-Hertz-Institut (HHI),
University of Hannover, Institut of Communication Theory and Signal Processing, Germany Germany University of Hannover, Institut of Communication Theory and Signal
TICSP, Tampere University of Technology, Finland Processing, Germany TICSP, Tampere University of Technology, Finland Munich
Munich University of Technology, Institute for Communications Engineering, Germany University of Technology, Institute for Communications Engineering, Germany
Videolocus, Canada Videolocus, Canada
Motorola Inc., USA Motorola Inc., USA
Microsoft Corp., USA Microsoft Corp., USA
@ -30,12 +30,9 @@
\par Full Contact Information \par Full Contact Information
\verbatim \verbatim
Lowell Winger <lwinger@videolocus.com><lwinger@uwaterloo.ca> Lowell Winger <lwinger@videolocus.com><lwinger@uwaterloo.ca> Guy Côté
Guy Côté <gcote@videolocus.com> <gcote@videolocus.com> Michael Gallant <mgallant@videolocus.com> VideoLocus
Michael Gallant <mgallant@videolocus.com> Inc. 97 Randall Dr. Waterloo, ON, Canada N2V1C5
VideoLocus Inc.
97 Randall Dr.
Waterloo, ON, Canada N2V1C5
Inge Lille-Langøy <inge.lille-langoy@telenor.com> Inge Lille-Langøy <inge.lille-langoy@telenor.com>
Telenor Satellite Services Telenor Satellite Services
@ -152,10 +149,8 @@
San Diego, CA 92121 USA San Diego, CA 92121 USA
Feng Wu <fengwu@microsoft.com> Feng Wu <fengwu@microsoft.com>
Xiaoyan Sun <sunxiaoyan@msrchina.research.microsoft.com> Xiaoyan Sun <sunxiaoyan@msrchina.research.microsoft.com> Microsoft
Microsoft Research Asia Research Asia 3/F, Beijing Sigma Center No.49, Zhichun Road, Hai Dian District,
3/F, Beijing Sigma Center
No.49, Zhichun Road, Hai Dian District,
Beijing China 100080 Beijing China 100080
Yoshihiro Kikuchi <yoshihiro.kikuchi@toshiba.co.jp> Yoshihiro Kikuchi <yoshihiro.kikuchi@toshiba.co.jp>
@ -211,22 +206,20 @@
2 Independence Way 2 Independence Way
Princeton, NJ 08540 Princeton, NJ 08540
Shun-ichi Sekiguchi <Sekiguchi.Shunichi@eb.MitsubishiElectric.co.jp> Shun-ichi Sekiguchi <Sekiguchi.Shunichi@eb.MitsubishiElectric.co.jp>
Information Technology R&D Center, Information Technology R&D Center,
Mitsubishi Electric Corporation Mitsubishi Electric Corporation
5-1-1, Ofuna, Kamakura, Japan 5-1-1, Ofuna, Kamakura, Japan
Yung-Lyul Lee <yllee@sejong.ac.kr> Yung-Lyul Lee <yllee@sejong.ac.kr>
Ki-Hun Han <khhan@dms.sejong.ac.kr> Ki-Hun Han <khhan@dms.sejong.ac.kr>
Department of Computer Engineering, Department of Computer Engineering,
Sejong University Sejong University
98 Kunja-Dong, Kwangjin-Gu, Seoul 143-747, Korea 98 Kunja-Dong, Kwangjin-Gu, Seoul 143-747, Korea
Jianhua Wu <jianhua.wu@sg.panasonic.com> Jianhua Wu <jianhua.wu@sg.panasonic.com> Panasonic
Panasonic Singapore Laboratories Pte Ltd Singapore Laboratories Pte Ltd Blk 1022 Tai Seng Ave #06-3530 Tai Seng Ind Est
Blk 1022 Tai Seng Ave #06-3530 Tai Seng Ind Est Singapore 534415
Singapore 534415
\endverbatim \endverbatim
*/ */

File diff suppressed because it is too large Load diff

View file

@ -7,259 +7,272 @@
* Header file containing some useful global definitions * Header file containing some useful global definitions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Detlev Marpe * - Detlev Marpe
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
* *
* \date * \date
* 21. March 2001 * 21. March 2001
************************************************************************** **************************************************************************
*/ */
#ifndef _DEFINES_H_ #ifndef _DEFINES_H_
#define _DEFINES_H_ #define _DEFINES_H_
#ifdef TRACE #ifdef TRACE
#undef TRACE #undef TRACE
#endif #endif
#if defined _DEBUG #if defined _DEBUG
# define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information #define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information
#else #else
# define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information #define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information
#endif #endif
#define JM "17 (FRExt)" #define JM "17 (FRExt)"
#define VERSION "17.1" #define VERSION "17.1"
#define EXT_VERSION "(FRExt)" #define EXT_VERSION "(FRExt)"
#define DUMP_DPB 0 //!< Dump DPB info for debug purposes #define DUMP_DPB 0 //!< Dump DPB info for debug purposes
#define PRINTREFLIST 0 //!< Print ref list info for debug purposes #define PRINTREFLIST 0 //!< Print ref list info for debug purposes
#define PAIR_FIELDS_IN_OUTPUT 0 //!< Pair field pictures for output purposes #define PAIR_FIELDS_IN_OUTPUT 0 //!< Pair field pictures for output purposes
#define IMGTYPE 1 //!< Define imgpel size type. 0 implies byte (cannot handle >8 bit depths) and 1 implies unsigned short #define IMGTYPE \
#define ENABLE_FIELD_CTX 1 //!< Enables Field mode related context types for CABAC 1 //!< Define imgpel size type. 0 implies byte (cannot handle >8 bit depths)
#define ENABLE_HIGH444_CTX 1 //!< Enables High 444 profile context types for CABAC. //!< and 1 implies unsigned short
#define ZEROSNR 0 //!< PSNR computation method #define ENABLE_FIELD_CTX \
#define ENABLE_OUTPUT_TONEMAPPING 1 //!< enable tone map the output if tone mapping SEI present 1 //!< Enables Field mode related context types for CABAC
#define JCOST_CALC_SCALEUP 1 //!< 1: J = (D<<LAMBDA_ACCURACY_BITS)+Lambda*R; 0: J = D + ((Lambda*R+Rounding)>>LAMBDA_ACCURACY_BITS) #define ENABLE_HIGH444_CTX \
#define DISABLE_ERC 1 //!< Disable any error concealment processes 1 //!< Enables High 444 profile context types for CABAC.
#define JM_PARALLEL_DEBLOCK 0 //!< Enables Parallel Deblocking #define ZEROSNR 0 //!< PSNR computation method
#define ENABLE_OUTPUT_TONEMAPPING \
1 //!< enable tone map the output if tone mapping SEI present
#define JCOST_CALC_SCALEUP \
1 //!< 1: J = (D<<LAMBDA_ACCURACY_BITS)+Lambda*R; 0: J = D +
//!< ((Lambda*R+Rounding)>>LAMBDA_ACCURACY_BITS)
#define DISABLE_ERC 1 //!< Disable any error concealment processes
#define JM_PARALLEL_DEBLOCK 0 //!< Enables Parallel Deblocking
#define MVC_EXTENSION_ENABLE 1 //!< enable support for the Multiview High Profile #define MVC_EXTENSION_ENABLE \
1 //!< enable support for the Multiview High Profile
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
#define MVC_INIT_VIEW_ID -1 #define MVC_INIT_VIEW_ID -1
#define MAX_VIEW_NUM 1024 #define MAX_VIEW_NUM 1024
#define BASE_VIEW_IDX 0 #define BASE_VIEW_IDX 0
#define FREEPTR(ptr) { if(ptr) {free(ptr); (ptr)=NULL;} } #define FREEPTR(ptr) \
{ \
if (ptr) { \
free(ptr); \
(ptr) = NULL; \
} \
}
#endif #endif
#include "typedefs.h" #include "typedefs.h"
#define SSE_MEMORY_ALIGNMENT 16 #define SSE_MEMORY_ALIGNMENT 16
//#define MAX_NUM_SLICES 150 // #define MAX_NUM_SLICES 150
#define MAX_NUM_SLICES 50 #define MAX_NUM_SLICES 50
#define MAX_REFERENCE_PICTURES 32 //!< H.264 allows 32 fields #define MAX_REFERENCE_PICTURES 32 //!< H.264 allows 32 fields
#define MAX_CODED_FRAME_SIZE 8000000 //!< bytes for one frame #define MAX_CODED_FRAME_SIZE 8000000 //!< bytes for one frame
#define MAX_NUM_DECSLICES 16 #define MAX_NUM_DECSLICES 16
#define MAX_DEC_THREADS 16 //16 core deocoding; #define MAX_DEC_THREADS 16 // 16 core deocoding;
#define MCBUF_LUMA_PAD_X 32 #define MCBUF_LUMA_PAD_X 32
#define MCBUF_LUMA_PAD_Y 12 #define MCBUF_LUMA_PAD_Y 12
#define MCBUF_CHROMA_PAD_X 16 #define MCBUF_CHROMA_PAD_X 16
#define MCBUF_CHROMA_PAD_Y 8 #define MCBUF_CHROMA_PAD_Y 8
//AVC Profile IDC definitions // AVC Profile IDC definitions
typedef enum { typedef enum {
FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4" FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4"
BASELINE = 66, //!< YUV 4:2:0/8 "Baseline" BASELINE = 66, //!< YUV 4:2:0/8 "Baseline"
MAIN = 77, //!< YUV 4:2:0/8 "Main" MAIN = 77, //!< YUV 4:2:0/8 "Main"
EXTENDED = 88, //!< YUV 4:2:0/8 "Extended" EXTENDED = 88, //!< YUV 4:2:0/8 "Extended"
FREXT_HP = 100, //!< YUV 4:2:0/8 "High" FREXT_HP = 100, //!< YUV 4:2:0/8 "High"
FREXT_Hi10P = 110, //!< YUV 4:2:0/10 "High 10" FREXT_Hi10P = 110, //!< YUV 4:2:0/10 "High 10"
FREXT_Hi422 = 122, //!< YUV 4:2:2/10 "High 4:2:2" FREXT_Hi422 = 122, //!< YUV 4:2:2/10 "High 4:2:2"
FREXT_Hi444 = 244, //!< YUV 4:4:4/14 "High 4:4:4" FREXT_Hi444 = 244, //!< YUV 4:4:4/14 "High 4:4:4"
MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High" MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High"
STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High" STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High"
} ProfileIDC; } ProfileIDC;
#define FILE_NAME_SIZE 255 #define FILE_NAME_SIZE 255
#define INPUT_TEXT_SIZE 1024 #define INPUT_TEXT_SIZE 1024
#if (ENABLE_HIGH444_CTX == 1) #if (ENABLE_HIGH444_CTX == 1)
# define NUM_BLOCK_TYPES 22 #define NUM_BLOCK_TYPES 22
#else #else
# define NUM_BLOCK_TYPES 10 #define NUM_BLOCK_TYPES 10
#endif #endif
// #define _LEAKYBUCKET_
//#define _LEAKYBUCKET_ #define BLOCK_SHIFT 2
#define BLOCK_SIZE 4
#define BLOCK_SHIFT 2 #define BLOCK_SIZE_8x8 8
#define BLOCK_SIZE 4 #define SMB_BLOCK_SIZE 8
#define BLOCK_SIZE_8x8 8 #define BLOCK_PIXELS 16
#define SMB_BLOCK_SIZE 8 #define MB_BLOCK_SIZE 16
#define BLOCK_PIXELS 16 #define MB_PIXELS 256 // MB_BLOCK_SIZE * MB_BLOCK_SIZE
#define MB_BLOCK_SIZE 16 #define MB_PIXELS_SHIFT 8 // log2(MB_BLOCK_SIZE * MB_BLOCK_SIZE)
#define MB_PIXELS 256 // MB_BLOCK_SIZE * MB_BLOCK_SIZE #define MB_BLOCK_SHIFT 4
#define MB_PIXELS_SHIFT 8 // log2(MB_BLOCK_SIZE * MB_BLOCK_SIZE) #define BLOCK_MULTIPLE 4 // (MB_BLOCK_SIZE/BLOCK_SIZE)
#define MB_BLOCK_SHIFT 4 #define MB_BLOCK_PARTITIONS 16 // (BLOCK_MULTIPLE * BLOCK_MULTIPLE)
#define BLOCK_MULTIPLE 4 // (MB_BLOCK_SIZE/BLOCK_SIZE) #define BLOCK_CONTEXT 64 // (4 * MB_BLOCK_PARTITIONS)
#define MB_BLOCK_PARTITIONS 16 // (BLOCK_MULTIPLE * BLOCK_MULTIPLE)
#define BLOCK_CONTEXT 64 // (4 * MB_BLOCK_PARTITIONS)
// These variables relate to the subpel accuracy supported by the software (1/4) // These variables relate to the subpel accuracy supported by the software (1/4)
#define BLOCK_SIZE_SP 16 // BLOCK_SIZE << 2 #define BLOCK_SIZE_SP 16 // BLOCK_SIZE << 2
#define BLOCK_SIZE_8x8_SP 32 // BLOCK_SIZE8x8 << 2 #define BLOCK_SIZE_8x8_SP 32 // BLOCK_SIZE8x8 << 2
// Available MB modes // Available MB modes
typedef enum { typedef enum {
PSKIP = 0, PSKIP = 0,
BSKIP_DIRECT = 0, BSKIP_DIRECT = 0,
P16x16 = 1, P16x16 = 1,
P16x8 = 2, P16x8 = 2,
P8x16 = 3, P8x16 = 3,
SMB8x8 = 4, SMB8x8 = 4,
SMB8x4 = 5, SMB8x4 = 5,
SMB4x8 = 6, SMB4x8 = 6,
SMB4x4 = 7, SMB4x4 = 7,
P8x8 = 8, P8x8 = 8,
I4MB = 9, I4MB = 9,
I16MB = 10, I16MB = 10,
IBLOCK = 11, IBLOCK = 11,
SI4MB = 12, SI4MB = 12,
I8MB = 13, I8MB = 13,
IPCM = 14, IPCM = 14,
MAXMODE = 15 MAXMODE = 15
} MBModeTypes; } MBModeTypes;
// number of intra prediction modes // number of intra prediction modes
#define NO_INTRA_PMODE 9 #define NO_INTRA_PMODE 9
// Direct Mode types // Direct Mode types
typedef enum { typedef enum {
DIR_TEMPORAL = 0, //!< Temporal Direct Mode DIR_TEMPORAL = 0, //!< Temporal Direct Mode
DIR_SPATIAL = 1 //!< Spatial Direct Mode DIR_SPATIAL = 1 //!< Spatial Direct Mode
} DirectModes; } DirectModes;
// CAVLC block types // CAVLC block types
typedef enum { typedef enum {
LUMA = 0, LUMA = 0,
LUMA_INTRA16x16DC = 1, LUMA_INTRA16x16DC = 1,
LUMA_INTRA16x16AC = 2, LUMA_INTRA16x16AC = 2,
CB = 3, CB = 3,
CB_INTRA16x16DC = 4, CB_INTRA16x16DC = 4,
CB_INTRA16x16AC = 5, CB_INTRA16x16AC = 5,
CR = 8, CR = 8,
CR_INTRA16x16DC = 9, CR_INTRA16x16DC = 9,
CR_INTRA16x16AC = 10 CR_INTRA16x16AC = 10
} CAVLCBlockTypes; } CAVLCBlockTypes;
// CABAC block types // CABAC block types
typedef enum { typedef enum {
LUMA_16DC = 0, LUMA_16DC = 0,
LUMA_16AC = 1, LUMA_16AC = 1,
LUMA_8x8 = 2, LUMA_8x8 = 2,
LUMA_8x4 = 3, LUMA_8x4 = 3,
LUMA_4x8 = 4, LUMA_4x8 = 4,
LUMA_4x4 = 5, LUMA_4x4 = 5,
CHROMA_DC = 6, CHROMA_DC = 6,
CHROMA_AC = 7, CHROMA_AC = 7,
CHROMA_DC_2x4 = 8, CHROMA_DC_2x4 = 8,
CHROMA_DC_4x4 = 9, CHROMA_DC_4x4 = 9,
CB_16DC = 10, CB_16DC = 10,
CB_16AC = 11, CB_16AC = 11,
CB_8x8 = 12, CB_8x8 = 12,
CB_8x4 = 13, CB_8x4 = 13,
CB_4x8 = 14, CB_4x8 = 14,
CB_4x4 = 15, CB_4x4 = 15,
CR_16DC = 16, CR_16DC = 16,
CR_16AC = 17, CR_16AC = 17,
CR_8x8 = 18, CR_8x8 = 18,
CR_8x4 = 19, CR_8x4 = 19,
CR_4x8 = 20, CR_4x8 = 20,
CR_4x4 = 21 CR_4x4 = 21
} CABACBlockTypes; } CABACBlockTypes;
// Macro defines // Macro defines
#define Q_BITS 15 #define Q_BITS 15
#define DQ_BITS 6 #define DQ_BITS 6
#define Q_BITS_8 16 #define Q_BITS_8 16
#define DQ_BITS_8 6 #define DQ_BITS_8 6
#define IS_I16MB(MB) ((MB)->mb_type == I16MB || (MB)->mb_type == IPCM)
#define IS_DIRECT(MB) ((MB)->mb_type == 0 && (currSlice->slice_type == B_SLICE))
#define IS_I16MB(MB) ((MB)->mb_type==I16MB || (MB)->mb_type==IPCM) #define TOTRUN_NUM 15
#define IS_DIRECT(MB) ((MB)->mb_type==0 && (currSlice->slice_type == B_SLICE )) #define RUNBEFORE_NUM 7
#define RUNBEFORE_NUM_M1 6
#define TOTRUN_NUM 15
#define RUNBEFORE_NUM 7
#define RUNBEFORE_NUM_M1 6
// Quantization parameter range // Quantization parameter range
#define MIN_QP 0 #define MIN_QP 0
#define MAX_QP 51 #define MAX_QP 51
// 4x4 intra prediction modes // 4x4 intra prediction modes
typedef enum { typedef enum {
VERT_PRED = 0, VERT_PRED = 0,
HOR_PRED = 1, HOR_PRED = 1,
DC_PRED = 2, DC_PRED = 2,
DIAG_DOWN_LEFT_PRED = 3, DIAG_DOWN_LEFT_PRED = 3,
DIAG_DOWN_RIGHT_PRED = 4, DIAG_DOWN_RIGHT_PRED = 4,
VERT_RIGHT_PRED = 5, VERT_RIGHT_PRED = 5,
HOR_DOWN_PRED = 6, HOR_DOWN_PRED = 6,
VERT_LEFT_PRED = 7, VERT_LEFT_PRED = 7,
HOR_UP_PRED = 8 HOR_UP_PRED = 8
} I4x4PredModes; } I4x4PredModes;
// 16x16 intra prediction modes // 16x16 intra prediction modes
typedef enum { typedef enum {
VERT_PRED_16 = 0, VERT_PRED_16 = 0,
HOR_PRED_16 = 1, HOR_PRED_16 = 1,
DC_PRED_16 = 2, DC_PRED_16 = 2,
PLANE_16 = 3 PLANE_16 = 3
} I16x16PredModes; } I16x16PredModes;
// 8x8 chroma intra prediction modes // 8x8 chroma intra prediction modes
typedef enum { typedef enum {
DC_PRED_8 = 0, DC_PRED_8 = 0,
HOR_PRED_8 = 1, HOR_PRED_8 = 1,
VERT_PRED_8 = 2, VERT_PRED_8 = 2,
PLANE_8 = 3 PLANE_8 = 3
} I8x8PredModes; } I8x8PredModes;
enum { enum {
EOS = 1, //!< End Of Sequence EOS = 1, //!< End Of Sequence
SOP = 2, //!< Start Of Picture SOP = 2, //!< Start Of Picture
SOS = 3, //!< Start Of Slice SOS = 3, //!< Start Of Slice
SOS_CONT = 4 SOS_CONT = 4
}; };
// MV Prediction types // MV Prediction types
typedef enum { typedef enum {
MVPRED_MEDIAN = 0, MVPRED_MEDIAN = 0,
MVPRED_L = 1, MVPRED_L = 1,
MVPRED_U = 2, MVPRED_U = 2,
MVPRED_UR = 3 MVPRED_UR = 3
} MVPredTypes; } MVPredTypes;
enum { enum { DECODING_OK = 0, SEARCH_SYNC = 1, PICTURE_DECODED = 2 };
DECODING_OK = 0,
SEARCH_SYNC = 1,
PICTURE_DECODED = 2
};
#define LAMBDA_ACCURACY_BITS 16 #define LAMBDA_ACCURACY_BITS 16
#define INVALIDINDEX (-135792468) #define INVALIDINDEX (-135792468)
#define RC_MAX_TEMPORAL_LEVELS 5 #define RC_MAX_TEMPORAL_LEVELS 5
//Start code and Emulation Prevention need this to be defined in identical manner at encoder and decoder // Start code and Emulation Prevention need this to be defined in identical
#define ZEROBYTES_SHORTSTARTCODE 2 //indicates the number of zero bytes in the short start-code prefix // manner at encoder and decoder
#define ZEROBYTES_SHORTSTARTCODE \
2 // indicates the number of zero bytes in the short start-code prefix
#define MAX_PLANE 3 #define MAX_PLANE 3
#define IS_FREXT_PROFILE(profile_idc) ( profile_idc>=FREXT_HP || profile_idc == FREXT_CAVLC444 ) #define IS_FREXT_PROFILE(profile_idc) \
#define HI_INTRA_ONLY_PROFILE (((p_Vid->active_sps->profile_idc>=FREXT_Hi10P)&&(p_Vid->active_sps->constrained_set3_flag))||(p_Vid->active_sps->profile_idc==FREXT_CAVLC444)) (profile_idc >= FREXT_HP || profile_idc == FREXT_CAVLC444)
#define HI_INTRA_ONLY_PROFILE \
(((p_Vid->active_sps->profile_idc >= FREXT_Hi10P) && \
(p_Vid->active_sps->constrained_set3_flag)) || \
(p_Vid->active_sps->profile_idc == FREXT_CAVLC444))
#endif #endif

View file

@ -1,11 +1,11 @@
/*! /*!
************************************************************************** **************************************************************************
* \file distortion.h * \file distortion.h
* \brief * \brief
* Distortion data header file * Distortion data header file
* \date 2.23.2009, * \date 2.23.2009,
* *
* \author * \author
* Alexis Michael Tourapis <alexismt@ieee.org> * Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************** **************************************************************************
@ -15,17 +15,15 @@
#define _DISTORTION_H_ #define _DISTORTION_H_
// Distortion data structure. Could be extended in the future to support // Distortion data structure. Could be extended in the future to support
// other data // other data
typedef struct distortion_data typedef struct distortion_data {
{ int i4x4rd[4][4]; //! i4x4 rd cost
int i4x4rd[4][4]; //! i4x4 rd cost distblk i4x4[4][4]; //! i4x4 cost
distblk i4x4 [4][4]; //! i4x4 cost distblk i8x8[2][2]; //! i8x8 cost
distblk i8x8 [2][2]; //! i8x8 cost int i8x8rd[2][2]; //! i8x8 rd cost
int i8x8rd[2][2]; //! i8x8 rd cost int i16x16;
int i16x16; int i16x16rd;
int i16x16rd; double rd_cost;
double rd_cost;
} DistortionData; } DistortionData;
#endif #endif

View file

@ -39,40 +39,40 @@
* TYPE_CBP | SE_CBP_INTRA, SE_CBP_INTER * TYPE_CBP | SE_CBP_INTRA, SE_CBP_INTER
* SE_DELTA_QUANT_INTER * SE_DELTA_QUANT_INTER
* SE_DELTA_QUANT_INTRA * SE_DELTA_QUANT_INTRA
* TYPE_COEFF_Y | SE_LUM_DC_INTRA, SE_LUM_AC_INTRA, SE_LUM_DC_INTER, SE_LUM_AC_INTER * TYPE_COEFF_Y | SE_LUM_DC_INTRA, SE_LUM_AC_INTRA, SE_LUM_DC_INTER,
* TYPE_2x2DC | SE_CHR_DC_INTRA, SE_CHR_DC_INTER * SE_LUM_AC_INTER TYPE_2x2DC | SE_CHR_DC_INTRA, SE_CHR_DC_INTER
* TYPE_COEFF_C | SE_CHR_AC_INTRA, SE_CHR_AC_INTER * TYPE_COEFF_C | SE_CHR_AC_INTRA, SE_CHR_AC_INTER
* TYPE_EOS | SE_EOS * TYPE_EOS | SE_EOS
*/ */
#define SE_HEADER 0 #define SE_HEADER 0
#define SE_PTYPE 1 #define SE_PTYPE 1
#define SE_MBTYPE 2 #define SE_MBTYPE 2
#define SE_REFFRAME 3 #define SE_REFFRAME 3
#define SE_INTRAPREDMODE 4 #define SE_INTRAPREDMODE 4
#define SE_MVD 5 #define SE_MVD 5
#define SE_CBP_INTRA 6 #define SE_CBP_INTRA 6
#define SE_LUM_DC_INTRA 7 #define SE_LUM_DC_INTRA 7
#define SE_CHR_DC_INTRA 8 #define SE_CHR_DC_INTRA 8
#define SE_LUM_AC_INTRA 9 #define SE_LUM_AC_INTRA 9
#define SE_CHR_AC_INTRA 10 #define SE_CHR_AC_INTRA 10
#define SE_CBP_INTER 11 #define SE_CBP_INTER 11
#define SE_LUM_DC_INTER 12 #define SE_LUM_DC_INTER 12
#define SE_CHR_DC_INTER 13 #define SE_CHR_DC_INTER 13
#define SE_LUM_AC_INTER 14 #define SE_LUM_AC_INTER 14
#define SE_CHR_AC_INTER 15 #define SE_CHR_AC_INTER 15
#define SE_DELTA_QUANT_INTER 16 #define SE_DELTA_QUANT_INTER 16
#define SE_DELTA_QUANT_INTRA 17 #define SE_DELTA_QUANT_INTRA 17
#define SE_BFRAME 18 #define SE_BFRAME 18
#define SE_EOS 19 #define SE_EOS 19
#define SE_MAX_ELEMENTS 20 #define SE_MAX_ELEMENTS 20
#define NO_EC 0 //!< no error concealment necessary
#define EC_REQ 1 //!< error concealment required
#define EC_SYNC 2 //!< search and sync on next header element
#define NO_EC 0 //!< no error concealment necessary #define MAXPARTITIONMODES \
#define EC_REQ 1 //!< error concealment required 2 //!< maximum possible partition modes as defined in assignSE2partition[][]
#define EC_SYNC 2 //!< search and sync on next header element
#define MAXPARTITIONMODES 2 //!< maximum possible partition modes as defined in assignSE2partition[][]
/*! /*!
* \brief lookup-table to assign different elements to partition * \brief lookup-table to assign different elements to partition
@ -99,14 +99,14 @@
* outlined in document Q15-J-23. * outlined in document Q15-J-23.
*/ */
static const byte assignSE2partition[][SE_MAX_ELEMENTS] = {
static const byte assignSE2partition[][SE_MAX_ELEMENTS] = // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // element
{ // number (do not uncomment)
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // element number (do not uncomment) {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //!< all elements in one partition no data partitioning 0, 0, 0, 0, 0, 0, 0, 0, 0}, //!< all elements in one partition no data
{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 0, 0 } //!< three partitions per slice //!< partitioning
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 0, 2, 2, 2, 2, 0, 0, 0, 0} //!< three partitions per slice
}; };
#endif #endif

View file

@ -6,7 +6,8 @@
* statistics reports for the encoding process. * statistics reports for the encoding process.
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Tourapis <alexismt@ieee.org> * - Alexis Tourapis <alexismt@ieee.org>
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* *
@ -17,52 +18,55 @@
#define _ENC_STATISTICS_H_ #define _ENC_STATISTICS_H_
#include "global.h" #include "global.h"
struct stat_parameters struct stat_parameters {
{ float bitrate; //!< average bit rate for the sequence except first frame
float bitrate; //!< average bit rate for the sequence except first frame int64 bit_ctr; //!< counter for bit usage
int64 bit_ctr; //!< counter for bit usage int64 bit_ctr_n; //!< bit usage for the current frame
int64 bit_ctr_n; //!< bit usage for the current frame int64 bit_ctr_emulationprevention; //!< stored bits needed to prevent start
int64 bit_ctr_emulationprevention; //!< stored bits needed to prevent start code emulation //!< code emulation
int bit_slice; //!< number of bits in current slice int bit_slice; //!< number of bits in current slice
int stored_bit_slice; //!< keep number of bits in current slice (to restore status in case of MB re-encoding) int stored_bit_slice; //!< keep number of bits in current slice (to restore
int b8_mode_0_use [NUM_SLICE_TYPES][2]; //!< status in case of MB re-encoding)
int64 mode_use_transform[NUM_SLICE_TYPES][MAXMODE][2]; int b8_mode_0_use[NUM_SLICE_TYPES][2];
int64 intra_chroma_mode[4]; int64 mode_use_transform[NUM_SLICE_TYPES][MAXMODE][2];
int64 intra_chroma_mode[4];
// B pictures // B pictures
int NumberBFrames; int NumberBFrames;
int frame_counter; int frame_counter;
int64 quant [NUM_SLICE_TYPES]; int64 quant[NUM_SLICE_TYPES];
int64 num_macroblocks [NUM_SLICE_TYPES]; int64 num_macroblocks[NUM_SLICE_TYPES];
int frame_ctr [NUM_SLICE_TYPES]; int frame_ctr[NUM_SLICE_TYPES];
int64 bit_counter [NUM_SLICE_TYPES]; int64 bit_counter[NUM_SLICE_TYPES];
float bitrate_st [NUM_SLICE_TYPES]; float bitrate_st[NUM_SLICE_TYPES];
int64 mode_use [NUM_SLICE_TYPES][MAXMODE]; //!< Macroblock mode usage for Intra frames int64 mode_use[NUM_SLICE_TYPES]
int64 bit_use_mode [NUM_SLICE_TYPES][MAXMODE]; //!< statistics of bit usage [MAXMODE]; //!< Macroblock mode usage for Intra frames
int64 bit_use_mb_type [NUM_SLICE_TYPES]; int64 bit_use_mode[NUM_SLICE_TYPES][MAXMODE]; //!< statistics of bit usage
int64 bit_use_header [NUM_SLICE_TYPES]; int64 bit_use_mb_type[NUM_SLICE_TYPES];
int64 tmp_bit_use_cbp [NUM_SLICE_TYPES]; int64 bit_use_header[NUM_SLICE_TYPES];
int64 bit_use_coeffC [NUM_SLICE_TYPES]; int64 tmp_bit_use_cbp[NUM_SLICE_TYPES];
int64 bit_use_coeff [3][NUM_SLICE_TYPES]; int64 bit_use_coeffC[NUM_SLICE_TYPES];
int64 bit_use_delta_quant [NUM_SLICE_TYPES]; int64 bit_use_coeff[3][NUM_SLICE_TYPES];
int64 bit_use_stuffingBits[NUM_SLICE_TYPES]; int64 bit_use_delta_quant[NUM_SLICE_TYPES];
int64 bit_use_stuffingBits[NUM_SLICE_TYPES];
int bit_ctr_parametersets; int bit_ctr_parametersets;
int bit_ctr_parametersets_n; int bit_ctr_parametersets_n;
int64 bit_ctr_filler_data; int64 bit_ctr_filler_data;
int64 bit_ctr_filler_data_n; int64 bit_ctr_filler_data_n;
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
float bitrate_v[2]; //!< average bit rate for the sequence except first frame float bitrate_v[2]; //!< average bit rate for the sequence except first frame
int64 bit_ctr_v[2]; //!< counter for bit usage int64 bit_ctr_v[2]; //!< counter for bit usage
int64 bit_ctr_n_v[2]; //!< bit usage for the current frame int64 bit_ctr_n_v[2]; //!< bit usage for the current frame
int64 bit_ctr_emulationprevention_v[2]; //!< stored bits needed to prevent start code emulation int64 bit_ctr_emulationprevention_v[2]; //!< stored bits needed to prevent
int64 bit_counter_v[2][NUM_SLICE_TYPES]; //!< start code emulation
int bit_ctr_parametersets_v[2]; int64 bit_counter_v[2][NUM_SLICE_TYPES];
int bit_ctr_parametersets_n_v[2]; int bit_ctr_parametersets_v[2];
int64 bit_ctr_filler_data_v[2]; int bit_ctr_parametersets_n_v[2];
int64 bit_ctr_filler_data_n_v[2]; int64 bit_ctr_filler_data_v[2];
int64 bit_ctr_filler_data_n_v[2];
#endif #endif
}; };
typedef struct stat_parameters StatParameters; typedef struct stat_parameters StatParameters;

View file

@ -4,7 +4,8 @@
* \file erc_api.h * \file erc_api.h
* *
* \brief * \brief
* External (still inside video decoder) interface for error concealment module * External (still inside video decoder) interface for error concealment
*module
* *
* \author * \author
* - Ari Hourunranta <ari.hourunranta@nokia.com> * - Ari Hourunranta <ari.hourunranta@nokia.com>
@ -17,116 +18,117 @@
* ************************************************************************ * ************************************************************************
*/ */
#ifndef _ERC_API_H_ #ifndef _ERC_API_H_
#define _ERC_API_H_ #define _ERC_API_H_
#include "erc_globals.h" #include "erc_globals.h"
/* /*
* Defines * Defines
*/ */
/* If the average motion vector of the correctly received macroblocks is less than the /* If the average motion vector of the correctly received macroblocks is less
threshold, concealByCopy is used, otherwise concealByTrial is used. */ than the threshold, concealByCopy is used, otherwise concealByTrial is used. */
#define MVPERMB_THR 8 #define MVPERMB_THR 8
/* used to determine the size of the allocated memory for a temporal Region (MB) */ /* used to determine the size of the allocated memory for a temporal Region (MB)
#define DEF_REGION_SIZE 384 /* 8*8*6 */ */
#define DEF_REGION_SIZE 384 /* 8*8*6 */
#define ERC_BLOCK_OK 3
#define ERC_BLOCK_CONCEALED 2
#define ERC_BLOCK_CORRUPTED 1
#define ERC_BLOCK_EMPTY 0
#define ERC_BLOCK_OK 3
#define ERC_BLOCK_CONCEALED 2
#define ERC_BLOCK_CORRUPTED 1
#define ERC_BLOCK_EMPTY 0
/* /*
* Functions to convert MBNum representation to blockNum * Functions to convert MBNum representation to blockNum
*/ */
#define xPosYBlock(currYBlockNum,picSizeX) \ #define xPosYBlock(currYBlockNum, picSizeX) \
((currYBlockNum)%((picSizeX)>>3)) ((currYBlockNum) % ((picSizeX) >> 3))
#define yPosYBlock(currYBlockNum,picSizeX) \ #define yPosYBlock(currYBlockNum, picSizeX) \
((currYBlockNum)/((picSizeX)>>3)) ((currYBlockNum) / ((picSizeX) >> 3))
#define xPosMB(currMBNum,picSizeX) \ #define xPosMB(currMBNum, picSizeX) ((currMBNum) % ((picSizeX) >> 4))
((currMBNum)%((picSizeX)>>4))
#define yPosMB(currMBNum,picSizeX) \ #define yPosMB(currMBNum, picSizeX) ((currMBNum) / ((picSizeX) >> 4))
((currMBNum)/((picSizeX)>>4))
#define MBxy2YBlock(currXPos,currYPos,comp,picSizeX) \ #define MBxy2YBlock(currXPos, currYPos, comp, picSizeX) \
((((currYPos)<<1)+((comp)>>1))*((picSizeX)>>3)+((currXPos)<<1)+((comp)&1)) ((((currYPos) << 1) + ((comp) >> 1)) * ((picSizeX) >> 3) + \
((currXPos) << 1) + ((comp) & 1))
#define MBNum2YBlock(currMBNum,comp,picSizeX) \
MBxy2YBlock(xPosMB((currMBNum),(picSizeX)),yPosMB((currMBNum),(picSizeX)),(comp),(picSizeX))
#define MBNum2YBlock(currMBNum, comp, picSizeX) \
MBxy2YBlock(xPosMB((currMBNum), (picSizeX)), \
yPosMB((currMBNum), (picSizeX)), (comp), (picSizeX))
/* /*
* typedefs * typedefs
*/ */
/* segment data structure */ /* segment data structure */
typedef struct ercSegment_s typedef struct ercSegment_s {
{ short startMBPos;
short startMBPos; short endMBPos;
short endMBPos; signed char fCorrupted;
signed char fCorrupted;
} ercSegment_t; } ercSegment_t;
/* Error detector & concealment instance data structure */ /* Error detector & concealment instance data structure */
typedef struct ercVariables_s typedef struct ercVariables_s {
{
/* Number of macroblocks (size or size/4 of the arrays) */ /* Number of macroblocks (size or size/4 of the arrays) */
int nOfMBs; int nOfMBs;
/* Number of segments (slices) in frame */ /* Number of segments (slices) in frame */
int nOfSegments; int nOfSegments;
/* Array for conditions of Y blocks */ /* Array for conditions of Y blocks */
signed char *yCondition; signed char *yCondition;
/* Array for conditions of U blocks */ /* Array for conditions of U blocks */
signed char *uCondition; signed char *uCondition;
/* Array for conditions of V blocks */ /* Array for conditions of V blocks */
signed char *vCondition; signed char *vCondition;
/* Array for Slice level information */ /* Array for Slice level information */
ercSegment_t *segments; ercSegment_t *segments;
int currSegment; int currSegment;
/* Conditions of the MBs of the previous frame */ /* Conditions of the MBs of the previous frame */
signed char *prevFrameYCondition; signed char *prevFrameYCondition;
/* Flag telling if the current segment was found to be corrupted */ /* Flag telling if the current segment was found to be corrupted */
int currSegmentCorrupted; int currSegmentCorrupted;
/* Counter for corrupted segments per picture */ /* Counter for corrupted segments per picture */
int nOfCorruptedSegments; int nOfCorruptedSegments;
/* State variables for error detector and concealer */ /* State variables for error detector and concealer */
int concealment; int concealment;
} ercVariables_t; } ercVariables_t;
/* /*
* External function interface * External function interface
*/ */
void ercInit (VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag); void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag);
ercVariables_t *ercOpen( void ); ercVariables_t *ercOpen(void);
void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picSizeX ); void ercReset(ercVariables_t *errorVar, int nOfMBs, int numOfSegments,
void ercClose( VideoParameters *p_Vid, ercVariables_t *errorVar ); int picSizeX);
void ercSetErrorConcealment( ercVariables_t *errorVar, int value ); void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar);
void ercSetErrorConcealment(ercVariables_t *errorVar, int value);
void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ); void ercStartSegment(int currMBNum, int segment, unsigned int bitPos,
void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ); ercVariables_t *errorVar);
void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar ); void ercStopSegment(int currMBNum, int segment, unsigned int bitPos,
void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ); ercVariables_t *errorVar);
void ercMarkCurrMBConcealed( int currMBNum, int comp, int picSizeX, ercVariables_t *errorVar ); void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar);
void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar);
int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, int picSizeY, ercVariables_t *errorVar ); void ercMarkCurrMBConcealed(int currMBNum, int comp, int picSizeX,
int ercConcealInterFrame( frame *recfr, objectBuffer_t *object_list, ercVariables_t *errorVar);
int picSizeX, int picSizeY, ercVariables_t *errorVar, int chroma_format_idc );
int ercConcealIntraFrame(VideoParameters *p_Vid, frame *recfr, int picSizeX,
int picSizeY, ercVariables_t *errorVar);
int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list,
int picSizeX, int picSizeY, ercVariables_t *errorVar,
int chroma_format_idc);
/* Thomson APIs for concealing entire frame loss */ /* Thomson APIs for concealing entire frame loss */
@ -134,25 +136,26 @@ int ercConcealInterFrame( frame *recfr, objectBuffer_t *object_list,
#include "output.h" #include "output.h"
struct concealment_node { struct concealment_node {
StorablePicture* picture; StorablePicture *picture;
int missingpocs; int missingpocs;
struct concealment_node *next; struct concealment_node *next;
}; };
extern struct concealment_node * init_node(StorablePicture* , int ); extern struct concealment_node *init_node(StorablePicture *, int);
extern void print_node( struct concealment_node * ); extern void print_node(struct concealment_node *);
extern void print_list( struct concealment_node * ); extern void print_list(struct concealment_node *);
extern void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int , PictureStructure ); extern void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int,
PictureStructure);
extern void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff); extern void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff);
extern void conceal_lost_frames (DecodedPictureBuffer *p_Dpb, Slice *pSlice); extern void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice);
extern void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, StorablePicture *p); extern void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb,
extern void write_lost_non_ref_pic (DecodedPictureBuffer *p_Dpb, int poc, int p_out); StorablePicture *p);
extern void write_lost_ref_after_idr (DecodedPictureBuffer *p_Dpb, int pos); extern void write_lost_non_ref_pic(DecodedPictureBuffer *p_Dpb, int poc,
int p_out);
extern void write_lost_ref_after_idr(DecodedPictureBuffer *p_Dpb, int pos);
extern int comp(const void *, const void *); extern int comp(const void *, const void *);
#endif #endif

View file

@ -16,29 +16,35 @@
#ifndef _ERC_DO_H_ #ifndef _ERC_DO_H_
#define _ERC_DO_H_ #define _ERC_DO_H_
#include "erc_api.h" #include "erc_api.h"
void ercPixConcealIMB (VideoParameters *p_Vid, imgpel *currFrame, int row, int column, int predBlocks[], int frameWidth, int mbWidthInBlocks); void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row,
int column, int predBlocks[], int frameWidth,
int mbWidthInBlocks);
int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int ercCollect8PredBlocks(int predBlocks[], int currRow, int currColumn,
int maxRow, int maxColumn, int step, byte fNoCornerNeigh ); signed char *condition, int maxRow, int maxColumn,
int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int maxRow, int maxColumn, int step ); int step, byte fNoCornerNeigh);
int ercCollectColumnBlocks(int predBlocks[], int currRow, int currColumn,
signed char *condition, int maxRow, int maxColumn,
int step);
#define isSplitted(object_list,currMBNum) \ #define isSplitted(object_list, currMBNum) \
((object_list+((currMBNum)<<2))->regionMode >= REGMODE_SPLITTED) ((object_list + ((currMBNum) << 2))->regionMode >= REGMODE_SPLITTED)
/* this can be used as isBlock(...,INTRA) or isBlock(...,INTER_COPY) */ /* this can be used as isBlock(...,INTRA) or isBlock(...,INTER_COPY) */
#define isBlock(object_list,currMBNum,comp,regMode) \ #define isBlock(object_list, currMBNum, comp, regMode) \
(isSplitted(object_list,currMBNum) ? \ (isSplitted(object_list, currMBNum) \
((object_list+((currMBNum)<<2)+(comp))->regionMode == REGMODE_##regMode##_8x8) : \ ? ((object_list + ((currMBNum) << 2) + (comp))->regionMode == \
((object_list+((currMBNum)<<2))->regionMode == REGMODE_##regMode)) REGMODE_##regMode##_8x8) \
: ((object_list + ((currMBNum) << 2))->regionMode == \
REGMODE_##regMode))
/* this can be used as getParam(...,mv) or getParam(...,xMin) or getParam(...,yMin) */ /* this can be used as getParam(...,mv) or getParam(...,xMin) or
#define getParam(object_list,currMBNum,comp,param) \ * getParam(...,yMin) */
(isSplitted(object_list,currMBNum) ? \ #define getParam(object_list, currMBNum, comp, param) \
((object_list+((currMBNum)<<2)+(comp))->param) : \ (isSplitted(object_list, currMBNum) \
((object_list+((currMBNum)<<2))->param)) ? ((object_list + ((currMBNum) << 2) + (comp))->param) \
: ((object_list + ((currMBNum) << 2))->param))
#endif #endif

View file

@ -20,33 +20,34 @@
/* "block" means an 8x8 pixel area */ /* "block" means an 8x8 pixel area */
/* Region modes */ /* Region modes */
#define REGMODE_INTER_COPY 0 //!< Copy region #define REGMODE_INTER_COPY 0 //!< Copy region
#define REGMODE_INTER_PRED 1 //!< Inter region with motion vectors #define REGMODE_INTER_PRED 1 //!< Inter region with motion vectors
#define REGMODE_INTRA 2 //!< Intra region #define REGMODE_INTRA 2 //!< Intra region
#define REGMODE_SPLITTED 3 //!< Any region mode higher than this indicates that the region #define REGMODE_SPLITTED \
//!< is splitted which means 8x8 block 3 //!< Any region mode higher than this indicates that the region
#define REGMODE_INTER_COPY_8x8 4 //!< is splitted which means 8x8 block
#define REGMODE_INTER_PRED_8x8 5 #define REGMODE_INTER_COPY_8x8 4
#define REGMODE_INTRA_8x8 6 #define REGMODE_INTER_PRED_8x8 5
#define REGMODE_INTRA_8x8 6
//! YUV pixel domain image arrays for a video frame //! YUV pixel domain image arrays for a video frame
typedef struct frame_s typedef struct frame_s {
{
VideoParameters *p_Vid; VideoParameters *p_Vid;
imgpel *yptr; imgpel *yptr;
imgpel *uptr; imgpel *uptr;
imgpel *vptr; imgpel *vptr;
} frame; } frame;
//! region structure stores information about a region that is needed for concealment //! region structure stores information about a region that is needed for
typedef struct object_buffer //! concealment
{ typedef struct object_buffer {
byte regionMode; //!< region mode as above byte regionMode; //!< region mode as above
int xMin; //!< X coordinate of the pixel position of the top-left corner of the region int xMin; //!< X coordinate of the pixel position of the top-left corner of
int yMin; //!< Y coordinate of the pixel position of the top-left corner of the region //!< the region
int mv[3]; //!< motion vectors in 1/4 pixel units: mvx = mv[0], mvy = mv[1], int yMin; //!< Y coordinate of the pixel position of the top-left corner of
//!< and ref_frame = mv[2] //!< the region
int mv[3]; //!< motion vectors in 1/4 pixel units: mvx = mv[0], mvy = mv[1],
//!< and ref_frame = mv[2]
} objectBuffer_t; } objectBuffer_t;
#endif #endif

View file

@ -13,9 +13,8 @@
#ifndef _ERRORCONCEALMENT_H_ #ifndef _ERRORCONCEALMENT_H_
#define _ERRORCONCEALMENT_H_ #define _ERRORCONCEALMENT_H_
extern int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym); extern int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym);
extern int set_ec_flag (VideoParameters *p_Vid, int se); extern int set_ec_flag(VideoParameters *p_Vid, int se);
extern void reset_ec_flags (VideoParameters *p_Vid); extern void reset_ec_flags(VideoParameters *p_Vid);
#endif #endif

View file

@ -6,7 +6,8 @@
* Memory handling operations * Memory handling operations
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Chris Vogt * - Chris Vogt
* *
************************************************************************** **************************************************************************
@ -17,16 +18,12 @@
#include "typedefs.h" #include "typedefs.h"
static inline void fast_memset(void *dst, int value, int width) {
static inline void fast_memset(void *dst,int value,int width) memset(dst, value, width);
{
memset(dst,value,width);
} }
static inline void fast_memcpy(void *dst,void *src,int width) static inline void fast_memcpy(void *dst, void *src, int width) {
{ memcpy(dst, src, width);
memcpy(dst,src,width);
} }
#endif #endif

View file

@ -17,14 +17,13 @@
#ifndef _FMO_H_ #ifndef _FMO_H_
#define _FMO_H_ #define _FMO_H_
extern int fmo_init(VideoParameters *p_Vid, Slice *pSlice);
extern int fmo_init (VideoParameters *p_Vid, Slice *pSlice); extern int FmoFinit(VideoParameters *p_Vid);
extern int FmoFinit (VideoParameters *p_Vid);
extern int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid); extern int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid);
extern int FmoGetLastMBOfPicture (VideoParameters *p_Vid); extern int FmoGetLastMBOfPicture(VideoParameters *p_Vid);
extern int FmoGetLastMBInSliceGroup(VideoParameters *p_Vid, int SliceGroup); extern int FmoGetLastMBInSliceGroup(VideoParameters *p_Vid, int SliceGroup);
extern int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb); extern int FmoGetSliceGroupId(VideoParameters *p_Vid, int mb);
extern int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr); extern int FmoGetNextMBNr(VideoParameters *p_Vid, int CurrentMbNr);
#endif #endif

View file

@ -12,43 +12,37 @@
#ifndef _FRAME_H_ #ifndef _FRAME_H_
#define _FRAME_H_ #define _FRAME_H_
typedef enum { typedef enum { CM_UNKNOWN = -1, CM_YUV = 0, CM_RGB = 1, CM_XYZ = 2 } ColorModel;
CM_UNKNOWN = -1,
CM_YUV = 0,
CM_RGB = 1,
CM_XYZ = 2
} ColorModel;
typedef enum { typedef enum {
CF_UNKNOWN = -1, //!< Unknown color format CF_UNKNOWN = -1, //!< Unknown color format
YUV400 = 0, //!< Monochrome YUV400 = 0, //!< Monochrome
YUV420 = 1, //!< 4:2:0 YUV420 = 1, //!< 4:2:0
YUV422 = 2, //!< 4:2:2 YUV422 = 2, //!< 4:2:2
YUV444 = 3 //!< 4:4:4 YUV444 = 3 //!< 4:4:4
} ColorFormat; } ColorFormat;
typedef struct frame_format typedef struct frame_format {
{ ColorFormat yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4)
ColorFormat yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) ColorModel color_model; //!< 4:4:4 format (0: YUV, 1: RGB, 2: XYZ)
ColorModel color_model; //!< 4:4:4 format (0: YUV, 1: RGB, 2: XYZ) double frame_rate; //!< frame rate
double frame_rate; //!< frame rate int width[3]; //!< component frame width
int width[3]; //!< component frame width int height[3]; //!< component frame height
int height[3]; //!< component frame height int auto_crop_right; //!< luma component auto crop right
int auto_crop_right; //!< luma component auto crop right int auto_crop_bottom; //!< luma component auto crop bottom
int auto_crop_bottom; //!< luma component auto crop bottom int auto_crop_right_cr; //!< chroma component auto crop right
int auto_crop_right_cr; //!< chroma component auto crop right int auto_crop_bottom_cr; //!< chroma component auto crop bottom
int auto_crop_bottom_cr; //!< chroma component auto crop bottom int width_crop; //!< width after cropping consideration
int width_crop; //!< width after cropping consideration int height_crop; //!< height after cropping consideration
int height_crop; //!< height after cropping consideration int mb_width; //!< luma component frame width
int mb_width; //!< luma component frame width int mb_height; //!< luma component frame height
int mb_height; //!< luma component frame height int size_cmp[3]; //!< component sizes (width * height)
int size_cmp[3]; //!< component sizes (width * height) int size; //!< total image size (sum of size_cmp)
int size; //!< total image size (sum of size_cmp) int bit_depth[3]; //!< component bit depth
int bit_depth[3]; //!< component bit depth int max_value[3]; //!< component max value
int max_value[3]; //!< component max value int max_value_sq[3]; //!< component max value squared
int max_value_sq[3]; //!< component max value squared int pic_unit_size_on_disk; //!< picture sample unit size on storage medium
int pic_unit_size_on_disk; //!< picture sample unit size on storage medium int pic_unit_size_shift3; //!< pic_unit_size_on_disk >> 3
int pic_unit_size_shift3; //!< pic_unit_size_on_disk >> 3
} FrameFormat; } FrameFormat;
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@
* \author * \author
* Copyright (C) 2009 Dolby * Copyright (C) 2009 Dolby
* Yuwen He (yhe@dolby.com) * Yuwen He (yhe@dolby.com)
* *
************************************************************************ ************************************************************************
*/ */
#ifndef _H264DECODER_H_ #ifndef _H264DECODER_H_
@ -16,26 +16,24 @@
#include "global.h" #include "global.h"
typedef enum typedef enum {
{
DEC_GEN_NOERR = 0, DEC_GEN_NOERR = 0,
DEC_OPEN_NOERR = 0, DEC_OPEN_NOERR = 0,
DEC_CLOSE_NOERR = 0, DEC_CLOSE_NOERR = 0,
DEC_SUCCEED = 0, DEC_SUCCEED = 0,
DEC_EOS =1, DEC_EOS = 1,
DEC_NEED_DATA = 2, DEC_NEED_DATA = 2,
DEC_INVALID_PARAM = 3, DEC_INVALID_PARAM = 3,
DEC_ERRMASK = 0x8000 DEC_ERRMASK = 0x8000
// DEC_ERRMASK = 0x80000000 // DEC_ERRMASK = 0x80000000
}DecErrCode; } DecErrCode;
typedef struct dec_set_t typedef struct dec_set_t {
{
int iPostprocLevel; // valid interval are [0..100] int iPostprocLevel; // valid interval are [0..100]
int bDBEnable; int bDBEnable;
int bAllLayers; int bAllLayers;
int time_incr; int time_incr;
int bDecCompAdapt; int bDecCompAdapt;
} DecSet_t; } DecSet_t;
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -11,12 +11,12 @@
#define _HEADER_H_ #define _HEADER_H_
extern int FirstPartOfSliceHeader(Slice *currSlice); extern int FirstPartOfSliceHeader(Slice *currSlice);
extern int RestOfSliceHeader (Slice *currSlice); extern int RestOfSliceHeader(Slice *currSlice);
extern void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, Slice *pSlice); extern void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream,
Slice *pSlice);
extern void decode_poc(VideoParameters *p_Vid, Slice *pSlice); extern void decode_poc(VideoParameters *p_Vid, Slice *pSlice);
extern int dumppoc (VideoParameters *p_Vid); extern int dumppoc(VideoParameters *p_Vid);
#endif #endif

View file

@ -8,7 +8,8 @@
* define some inline functions that are used within the encoder. * define some inline functions that are used within the encoder.
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Tourapis <alexismt@ieee.org> * - Alexis Tourapis <alexismt@ieee.org>
* *
@ -19,308 +20,296 @@
#if !defined(SPEC) #if !defined(SPEC)
// For SPEC CPU always use static inline // For SPEC CPU always use static inline
# if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L) #if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L)
#define static #define static
#define inline #define inline
#endif #endif
#endif #endif
#include <math.h>
#include <limits.h> #include <limits.h>
#include <math.h>
static inline short smin(short a, short b) {
static inline short smin(short a, short b) return (short)(((a) < (b)) ? (a) : (b));
{
return (short) (((a) < (b)) ? (a) : (b));
} }
static inline short smax(short a, short b) static inline short smax(short a, short b) {
{ return (short)(((a) > (b)) ? (a) : (b));
return (short) (((a) > (b)) ? (a) : (b));
} }
static inline int imin(int a, int b) static inline int imin(int a, int b) { return ((a) < (b)) ? (a) : (b); }
{
return ((a) < (b)) ? (a) : (b);
}
static inline int imax(int a, int b) static inline int imax(int a, int b) { return ((a) > (b)) ? (a) : (b); }
{
return ((a) > (b)) ? (a) : (b);
}
static inline int imedian(int a,int b,int c) static inline int imedian(int a, int b, int c) {
{
if (a > b) // a > b if (a > b) // a > b
{ {
if (b > c) if (b > c)
return(b); // a > b > c return (b); // a > b > c
else if (a > c) else if (a > c)
return(c); // a > c > b return (c); // a > c > b
else
return(a); // c > a > b
}
else // b > a
{
if (a > c)
return(a); // b > a > c
else if (b > c)
return(c); // b > c > a
else else
return(b); // c > b > a return (a); // c > a > b
} else // b > a
{
if (a > c)
return (a); // b > a > c
else if (b > c)
return (c); // b > c > a
else
return (b); // c > b > a
} }
} }
static inline int imedian_old(int a, int b, int c) static inline int imedian_old(int a, int b, int c) {
{ return (a + b + c - imin(a, imin(b, c)) - imax(a, imax(b, c)));
return (a + b + c - imin(a, imin(b, c)) - imax(a, imax(b ,c)));
} }
static inline double dmin(double a, double b) static inline double dmin(double a, double b) {
{
return ((a) < (b)) ? (a) : (b); return ((a) < (b)) ? (a) : (b);
} }
static inline double dmax(double a, double b) static inline double dmax(double a, double b) {
{
return ((a) > (b)) ? (a) : (b); return ((a) > (b)) ? (a) : (b);
} }
static inline int64 i64min(int64 a, int64 b) static inline int64 i64min(int64 a, int64 b) { return ((a) < (b)) ? (a) : (b); }
{
static inline int64 i64max(int64 a, int64 b) { return ((a) > (b)) ? (a) : (b); }
static inline distblk distblkmin(distblk a, distblk b) {
return ((a) < (b)) ? (a) : (b); return ((a) < (b)) ? (a) : (b);
} }
static inline int64 i64max(int64 a, int64 b) static inline distblk distblkmax(distblk a, distblk b) {
{
return ((a) > (b)) ? (a) : (b); return ((a) > (b)) ? (a) : (b);
} }
static inline distblk distblkmin(distblk a, distblk b) static inline short sabs(short x) {
{
return ((a) < (b)) ? (a) : (b);
}
static inline distblk distblkmax(distblk a, distblk b)
{
return ((a) > (b)) ? (a) : (b);
}
static inline short sabs(short x)
{
static const short SHORT_BITS = (sizeof(short) * CHAR_BIT) - 1; static const short SHORT_BITS = (sizeof(short) * CHAR_BIT) - 1;
short y = (short) (x >> SHORT_BITS); short y = (short)(x >> SHORT_BITS);
return (short) ((x ^ y) - y); return (short)((x ^ y) - y);
} }
static inline int iabs(int x) static inline int iabs(int x) {
{
static const int INT_BITS = (sizeof(int) * CHAR_BIT) - 1; static const int INT_BITS = (sizeof(int) * CHAR_BIT) - 1;
int y = x >> INT_BITS; int y = x >> INT_BITS;
return (x ^ y) - y; return (x ^ y) - y;
} }
static inline double dabs(double x) static inline double dabs(double x) { return ((x) < 0) ? -(x) : (x); }
{
return ((x) < 0) ? -(x) : (x);
}
static inline int64 i64abs(int64 x) static inline int64 i64abs(int64 x) {
{
static const int64 INT64_BITS = (sizeof(int64) * CHAR_BIT) - 1; static const int64 INT64_BITS = (sizeof(int64) * CHAR_BIT) - 1;
int64 y = x >> INT64_BITS; int64 y = x >> INT64_BITS;
return (x ^ y) - y; return (x ^ y) - y;
} }
static inline double dabs2(double x) static inline double dabs2(double x) { return (x) * (x); }
{
return (x) * (x);
}
static inline int iabs2(int x) static inline int iabs2(int x) { return (x) * (x); }
{
return (x) * (x);
}
static inline int64 i64abs2(int64 x) static inline int64 i64abs2(int64 x) { return (x) * (x); }
{
return (x) * (x);
}
static inline int isign(int x) static inline int isign(int x) { return ((x > 0) - (x < 0)); }
{
return ( (x > 0) - (x < 0));
}
static inline int isignab(int a, int b) static inline int isignab(int a, int b) {
{
return ((b) < 0) ? -iabs(a) : iabs(a); return ((b) < 0) ? -iabs(a) : iabs(a);
} }
static inline int rshift_rnd(int x, int a) static inline int rshift_rnd(int x, int a) {
{ return (a > 0) ? ((x + (1 << (a - 1))) >> a) : (x << (-a));
return (a > 0) ? ((x + (1 << (a-1) )) >> a) : (x << (-a));
} }
static inline int rshift_rnd_sign(int x, int a) static inline int rshift_rnd_sign(int x, int a) {
{ return (x > 0) ? ((x + (1 << (a - 1))) >> a)
return (x > 0) ? ( ( x + (1 << (a-1)) ) >> a ) : (-( ( iabs(x) + (1 << (a-1)) ) >> a )); : (-((iabs(x) + (1 << (a - 1))) >> a));
} }
static inline unsigned int rshift_rnd_us(unsigned int x, unsigned int a) static inline unsigned int rshift_rnd_us(unsigned int x, unsigned int a) {
{ return (a > 0) ? ((x + (1 << (a - 1))) >> a) : x;
return (a > 0) ? ((x + (1 << (a-1))) >> a) : x;
} }
static inline int rshift_rnd_sf(int x, int a) static inline int rshift_rnd_sf(int x, int a) {
{ return ((x + (1 << (a - 1))) >> a);
return ((x + (1 << (a-1) )) >> a);
} }
static inline int shift_off_sf(int x, int o, int a) static inline int shift_off_sf(int x, int o, int a) { return ((x + o) >> a); }
{
return ((x + o) >> a); static inline unsigned int rshift_rnd_us_sf(unsigned int x, unsigned int a) {
return ((x + (1 << (a - 1))) >> a);
} }
static inline unsigned int rshift_rnd_us_sf(unsigned int x, unsigned int a) static inline int iClip1(int high, int x) {
{
return ((x + (1 << (a-1))) >> a);
}
static inline int iClip1(int high, int x)
{
x = imax(x, 0); x = imax(x, 0);
x = imin(x, high); x = imin(x, high);
return x; return x;
} }
static inline int iClip3(int low, int high, int x) static inline int iClip3(int low, int high, int x) {
{
x = imax(x, low); x = imax(x, low);
x = imin(x, high); x = imin(x, high);
return x; return x;
} }
static inline short sClip3(short low, short high, short x) static inline short sClip3(short low, short high, short x) {
{
x = smax(x, low); x = smax(x, low);
x = smin(x, high); x = smin(x, high);
return x; return x;
} }
static inline double dClip3(double low, double high, double x) static inline double dClip3(double low, double high, double x) {
{
x = dmax(x, low); x = dmax(x, low);
x = dmin(x, high); x = dmin(x, high);
return x; return x;
} }
static inline distblk weighted_cost(int factor, int bits) {
static inline distblk weighted_cost(int factor, int bits)
{
#if JCOST_CALC_SCALEUP #if JCOST_CALC_SCALEUP
return (((distblk)(factor))*((distblk)(bits))); return (((distblk)(factor)) * ((distblk)(bits)));
#else #else
#if (USE_RND_COST) #if (USE_RND_COST)
return (rshift_rnd_sf((lambda) * (bits), LAMBDA_ACCURACY_BITS)); return (rshift_rnd_sf((lambda) * (bits), LAMBDA_ACCURACY_BITS));
#else #else
return (((factor)*(bits))>>LAMBDA_ACCURACY_BITS); return (((factor) * (bits)) >> LAMBDA_ACCURACY_BITS);
#endif #endif
#endif #endif
} }
static inline int RSD(int x) static inline int RSD(int x) { return ((x & 2) ? (x | 1) : (x & (~1))); }
{
return ((x&2)?(x|1):(x&(~1)));
}
static inline int power2(int x) static inline int power2(int x) { return 1 << (x); }
{
return 1 << (x);
}
static const uint64 po2[64] = {0x1,
0x2,
0x4,
0x8,
0x10,
0x20,
0x40,
0x80,
0x100,
0x200,
0x400,
0x800,
0x1000,
0x2000,
0x4000,
0x8000,
0x10000,
0x20000,
0x40000,
0x80000,
0x100000,
0x200000,
0x400000,
0x800000,
0x1000000,
0x2000000,
0x4000000,
0x8000000,
0x10000000,
0x20000000,
0x40000000,
0x80000000,
0x100000000,
0x200000000,
0x400000000,
0x800000000,
0x1000000000,
0x2000000000,
0x4000000000,
0x8000000000,
0x10000000000,
0x20000000000,
0x40000000000,
0x80000000000,
0x100000000000,
0x200000000000,
0x400000000000,
0x800000000000,
0x1000000000000,
0x2000000000000,
0x4000000000000,
0x8000000000000,
0x10000000000000,
0x20000000000000,
0x40000000000000,
0x80000000000000,
0x100000000000000,
0x200000000000000,
0x400000000000000,
0x800000000000000,
0x1000000000000000,
0x2000000000000000,
0x4000000000000000,
0x8000000000000000};
static const uint64 po2[64] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000, static inline int64 i64_power2(int x) { return ((x > 63) ? 0 : po2[x]); }
0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,
0x10000000,0x20000000,0x40000000,0x80000000,0x100000000,0x200000000,0x400000000,0x800000000,
0x1000000000,0x2000000000,0x4000000000,0x8000000000,0x10000000000,0x20000000000,0x40000000000,0x80000000000,
0x100000000000,0x200000000000,0x400000000000,0x800000000000,
0x1000000000000,0x2000000000000,0x4000000000000,0x8000000000000,
0x10000000000000,0x20000000000000,0x40000000000000,0x80000000000000,
0x100000000000000,0x200000000000000,0x400000000000000,0x800000000000000,
0x1000000000000000,0x2000000000000000,0x4000000000000000,0x8000000000000000};
static inline int64 i64_power2(int x) static inline int float2int(float x) {
{
return((x > 63) ? 0 : po2[x]);
}
static inline int float2int (float x)
{
return (int)((x < 0) ? (x - 0.5f) : (x + 0.5f)); return (int)((x < 0) ? (x - 0.5f) : (x + 0.5f));
} }
static inline int get_bit(int64 x,int n) static inline int get_bit(int64 x, int n) { return (int)(((x >> n) & 1)); }
{
return (int)(((x >> n) & 1));
}
#if ZEROSNR #if ZEROSNR
static inline float psnr(int max_sample_sq, int samples, float sse_distortion ) static inline float psnr(int max_sample_sq, int samples, float sse_distortion) {
{ return (
return (float) (10.0 * log10(max_sample_sq * (double) ((double) samples / (sse_distortion < 1.0 ? 1.0 : sse_distortion)))); float)(10.0 *
log10(max_sample_sq *
(double)((double)samples /
(sse_distortion < 1.0 ? 1.0 : sse_distortion))));
} }
#else #else
static inline float psnr(int max_sample_sq, int samples, float sse_distortion ) static inline float psnr(int max_sample_sq, int samples, float sse_distortion) {
{ return (
return (float) (sse_distortion == 0.0 ? 0.0 : (10.0 * log10(max_sample_sq * (double) ((double) samples / sse_distortion)))); float)(sse_distortion == 0.0
? 0.0
: (10.0 * log10(max_sample_sq *
(double)((double)samples / sse_distortion))));
} }
#endif #endif
static inline int CheckCost_Shift(int64 mcost, int64 min_mcost) static inline int CheckCost_Shift(int64 mcost, int64 min_mcost) {
{ if ((mcost << LAMBDA_ACCURACY_BITS) >= min_mcost)
if((mcost<<LAMBDA_ACCURACY_BITS) >= min_mcost)
return 1; return 1;
else else
return 0; return 0;
} }
static inline int CheckCost(int64 mcost, int64 min_mcost) static inline int CheckCost(int64 mcost, int64 min_mcost) {
{
return ((mcost) >= (min_mcost)); return ((mcost) >= (min_mcost));
} }
static inline void down_scale(distblk *pblkdistCost) static inline void down_scale(distblk *pblkdistCost) {
{
#if JCOST_CALC_SCALEUP #if JCOST_CALC_SCALEUP
#if (IMGTYPE < 2) #if (IMGTYPE < 2)
*pblkdistCost = (*pblkdistCost)>>LAMBDA_ACCURACY_BITS; *pblkdistCost = (*pblkdistCost) >> LAMBDA_ACCURACY_BITS;
#else #else
*pblkdistCost = (*pblkdistCost)/(1<<LAMBDA_ACCURACY_BITS); *pblkdistCost = (*pblkdistCost) / (1 << LAMBDA_ACCURACY_BITS);
#endif #endif
#endif #endif
} }
static inline void up_scale(distblk *pblkdistCost) static inline void up_scale(distblk *pblkdistCost) {
{
#if JCOST_CALC_SCALEUP #if JCOST_CALC_SCALEUP
#if (IMGTYPE < 2) #if (IMGTYPE < 2)
*pblkdistCost = (*pblkdistCost)<<LAMBDA_ACCURACY_BITS; *pblkdistCost = (*pblkdistCost) << LAMBDA_ACCURACY_BITS;
#else #else
*pblkdistCost = (*pblkdistCost)*(1<<LAMBDA_ACCURACY_BITS); *pblkdistCost = (*pblkdistCost) * (1 << LAMBDA_ACCURACY_BITS);
#endif #endif
#endif #endif
} }
static inline distblk dist_scale(distblk blkdistCost) static inline distblk dist_scale(distblk blkdistCost) {
{
#if JCOST_CALC_SCALEUP #if JCOST_CALC_SCALEUP
#if (IMGTYPE < 2) #if (IMGTYPE < 2)
return ((blkdistCost)<<LAMBDA_ACCURACY_BITS); return ((blkdistCost) << LAMBDA_ACCURACY_BITS);
#else #else
return ((blkdistCost) *((distblk) (1<<LAMBDA_ACCURACY_BITS)); return ((blkdistCost) *((distblk) (1<<LAMBDA_ACCURACY_BITS));
#endif #endif
@ -329,23 +318,21 @@ static inline distblk dist_scale(distblk blkdistCost)
#endif #endif
} }
static inline int dist_down(distblk blkdistCost) static inline int dist_down(distblk blkdistCost) {
{
#if JCOST_CALC_SCALEUP #if JCOST_CALC_SCALEUP
#if (IMGTYPE < 2) #if (IMGTYPE < 2)
return ((int)((blkdistCost)>>LAMBDA_ACCURACY_BITS)); return ((int)((blkdistCost) >> LAMBDA_ACCURACY_BITS));
#else #else
return ((int)(blkdistCost/((distblk) (1<<LAMBDA_ACCURACY_BITS)))); return ((int)(blkdistCost / ((distblk)(1 << LAMBDA_ACCURACY_BITS))));
#endif #endif
#else #else
return ((int)blkdistCost); return ((int)blkdistCost);
#endif #endif
} }
# if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L) #if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L)
#undef static #undef static
#undef inline #undef inline
#endif #endif
#endif #endif

View file

@ -15,29 +15,31 @@
#include "mbuffer.h" #include "mbuffer.h"
extern void calculate_frame_no(VideoParameters *p_Vid, StorablePicture *p); extern void calculate_frame_no(VideoParameters *p_Vid, StorablePicture *p);
extern void find_snr (VideoParameters *p_Vid, StorablePicture *p, int *p_ref); extern void find_snr(VideoParameters *p_Vid, StorablePicture *p, int *p_ref);
extern int picture_order ( Slice *pSlice ); extern int picture_order(Slice *pSlice);
extern void decode_one_slice (Slice *currSlice); extern void decode_one_slice(Slice *currSlice);
extern int read_new_slice (Slice *currSlice); extern int read_new_slice(Slice *currSlice);
extern void exit_picture (VideoParameters *p_Vid, StorablePicture **dec_picture); extern void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture);
extern int decode_one_frame (DecoderParams *pDecoder); extern int decode_one_frame(DecoderParams *pDecoder);
extern int is_new_picture(StorablePicture *dec_picture, Slice *currSlice, OldSliceParams *p_old_slice); extern int is_new_picture(StorablePicture *dec_picture, Slice *currSlice,
OldSliceParams *p_old_slice);
extern void init_old_slice(OldSliceParams *p_old_slice); extern void init_old_slice(OldSliceParams *p_old_slice);
// For 4:4:4 independent mode // For 4:4:4 independent mode
extern void copy_dec_picture_JV (VideoParameters *p_Vid, StorablePicture *dst, StorablePicture *src ); extern void copy_dec_picture_JV(VideoParameters *p_Vid, StorablePicture *dst,
StorablePicture *src);
extern void frame_postprocessing(VideoParameters *p_Vid); extern void frame_postprocessing(VideoParameters *p_Vid);
extern void field_postprocessing(VideoParameters *p_Vid); extern void field_postprocessing(VideoParameters *p_Vid);
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
extern int GetVOIdx(VideoParameters *p_Vid, int iViewId); extern int GetVOIdx(VideoParameters *p_Vid, int iViewId);
extern int get_maxViewIdx(VideoParameters *p_Vid, int view_id, int anchor_pic_flag, int listidx); extern int get_maxViewIdx(VideoParameters *p_Vid, int view_id,
int anchor_pic_flag, int listidx);
#endif #endif
extern void init_slice(VideoParameters *p_Vid, Slice *currSlice); extern void init_slice(VideoParameters *p_Vid, Slice *currSlice);
extern void decode_slice(Slice *currSlice, int current_header); extern void decode_slice(Slice *currSlice, int current_header);
#endif #endif

View file

@ -6,7 +6,8 @@
* image I/O related functions * image I/O related functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
@ -15,16 +16,16 @@
#ifndef _IMG_IO_H_ #ifndef _IMG_IO_H_
#define _IMG_IO_H_ #define _IMG_IO_H_
#include "io_video.h"
#include "io_raw.h" #include "io_raw.h"
#include "io_tiff.h" #include "io_tiff.h"
#include "io_video.h"
extern int ParseSizeFromString (VideoDataFile *input_file, int *xlen, int *ylen, double *fps); extern int ParseSizeFromString(VideoDataFile *input_file, int *xlen, int *ylen,
extern void ParseFrameNoFormatFromString (VideoDataFile *input_file); double *fps);
extern void OpenFrameFile (VideoDataFile *input_file, int FrameNumberInFile); extern void ParseFrameNoFormatFromString(VideoDataFile *input_file);
extern void OpenFiles (VideoDataFile *input_file); extern void OpenFrameFile(VideoDataFile *input_file, int FrameNumberInFile);
extern void CloseFiles (VideoDataFile *input_file); extern void OpenFiles(VideoDataFile *input_file);
extern VideoFileType ParseVideoType (VideoDataFile *input_file); extern void CloseFiles(VideoDataFile *input_file);
extern VideoFileType ParseVideoType(VideoDataFile *input_file);
#endif #endif

View file

@ -1,12 +1,13 @@
/*! /*!
************************************************************************ ************************************************************************
* \file img_process.h * \file img_process.h
* *
* \brief * \brief
* Input data Image Processing functions * Input data Image Processing functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexis.tourapis@dolby.com> * - Alexis Michael Tourapis <alexis.tourapis@dolby.com>
* *
************************************************************************ ************************************************************************
@ -15,11 +16,8 @@
#ifndef _IMG_PROCESS_H_ #ifndef _IMG_PROCESS_H_
#define _IMG_PROCESS_H_ #define _IMG_PROCESS_H_
extern int init_process_image(VideoParameters *p_Vid, InputParameters *p_Inp);
extern int init_process_image ( VideoParameters *p_Vid, InputParameters *p_Inp ); extern void clear_process_image(VideoParameters *p_Vid, InputParameters *p_Inp);
extern void clear_process_image( VideoParameters *p_Vid, InputParameters *p_Inp); extern void process_image(VideoParameters *p_Vid, InputParameters *p_Inp);
extern void process_image ( VideoParameters *p_Vid, InputParameters *p_Inp );
#endif #endif

View file

@ -1,12 +1,13 @@
/*! /*!
************************************************************************ ************************************************************************
* \file img_process_types.h * \file img_process_types.h
* *
* \brief * \brief
* Input data Image Processing Types * Input data Image Processing Types
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexis.tourapis@dolby.com> * - Alexis Michael Tourapis <alexis.tourapis@dolby.com>
* - Athanasios Leontaris <aleon@dolby.com> * - Athanasios Leontaris <aleon@dolby.com>
* *
@ -16,9 +17,9 @@
#ifndef _IMG_PROCESS_TYPES_H_ #ifndef _IMG_PROCESS_TYPES_H_
#define _IMG_PROCESS_TYPES_H_ #define _IMG_PROCESS_TYPES_H_
#define DEMUX_META_DEBUG 0 #define DEMUX_META_DEBUG 0
#define MAX_NUM_PARTITIONS 32 #define MAX_NUM_PARTITIONS 32
#define NUM_VIEWS 2 #define NUM_VIEWS 2
#define NUM_COMPONENTS 3 #define NUM_COMPONENTS 3
#endif #endif

View file

@ -14,12 +14,18 @@
#define _INPUT_H_ #define _INPUT_H_
extern int testEndian(void); extern int testEndian(void);
extern void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output); extern void initInput(VideoParameters *p_Vid, FrameFormat *source,
extern void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameFormat *source); FrameFormat *output);
extern void DeleteFrameMemory (VideoParameters *p_Vid); extern void AllocateFrameMemory(VideoParameters *p_Vid, InputParameters *p_Inp,
FrameFormat *source);
extern void DeleteFrameMemory(VideoParameters *p_Vid);
extern int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, FrameFormat *output, imgpel **pImage[3]); extern int read_one_frame(VideoParameters *p_Vid, VideoDataFile *input_file,
extern void pad_borders ( FrameFormat output, int img_size_x, int img_size_y, int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]); int FrameNoInFile, int HeaderSize,
FrameFormat *source, FrameFormat *output,
imgpel **pImage[3]);
extern void pad_borders(FrameFormat output, int img_size_x, int img_size_y,
int img_size_x_cr, int img_size_y_cr,
imgpel **pImage[3]);
#endif #endif

View file

@ -6,7 +6,7 @@
* definitions for intra 16x16 prediction * definitions for intra 16x16 prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
@ -22,4 +22,3 @@
extern int intrapred16x16(Macroblock *currMB, ColorPlane pl, int b8); extern int intrapred16x16(Macroblock *currMB, ColorPlane pl, int b8);
#endif #endif

View file

@ -6,7 +6,7 @@
* definitions for intra 4x4 prediction * definitions for intra 4x4 prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
@ -19,7 +19,7 @@
#include "global.h" #include "global.h"
#include "mbuffer.h" #include "mbuffer.h"
extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff, int img_block_x, int img_block_y); extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff,
int img_block_x, int img_block_y);
#endif #endif

View file

@ -6,7 +6,7 @@
* definitions for intra 8x8 prediction * definitions for intra 8x8 prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
@ -22,4 +22,3 @@
extern int intrapred8x8(Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern int intrapred8x8(Macroblock *currMB, ColorPlane pl, int ioff, int joff);
#endif #endif

View file

@ -3,7 +3,7 @@
* \file io_image.h * \file io_image.h
* *
* \brief * \brief
* Image I/O * Image I/O
* *
* \author * \author
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
@ -17,20 +17,19 @@
#include "defines.h" #include "defines.h"
#include "frame.h" #include "frame.h"
typedef struct image_data typedef struct image_data {
{ FrameFormat format; //!< image format
FrameFormat format; //!< image format
// Standard data // Standard data
imgpel **frm_data[MAX_PLANE]; //!< Frame Data imgpel **frm_data[MAX_PLANE]; //!< Frame Data
imgpel **top_data[MAX_PLANE]; //!< pointers to top field data imgpel **top_data[MAX_PLANE]; //!< pointers to top field data
imgpel **bot_data[MAX_PLANE]; //!< pointers to bottom field data imgpel **bot_data[MAX_PLANE]; //!< pointers to bottom field data
//! Optional data (could also add uint8 data in case imgpel is of type uint16) //! Optional data (could also add uint8 data in case imgpel is of type uint16)
//! These can be useful for enabling input/conversion of content of different types //! These can be useful for enabling input/conversion of content of different
//! while keeping optimal processing size. //! types while keeping optimal processing size.
uint16 **frm_uint16[MAX_PLANE]; //!< optional frame Data for uint16 uint16 **frm_uint16[MAX_PLANE]; //!< optional frame Data for uint16
uint16 **top_uint16[MAX_PLANE]; //!< optional pointers to top field data uint16 **top_uint16[MAX_PLANE]; //!< optional pointers to top field data
uint16 **bot_uint16[MAX_PLANE]; //!< optional pointers to bottom field data uint16 **bot_uint16[MAX_PLANE]; //!< optional pointers to bottom field data
int frm_stride[MAX_PLANE]; int frm_stride[MAX_PLANE];
int top_stride[MAX_PLANE]; int top_stride[MAX_PLANE];
@ -38,4 +37,3 @@ typedef struct image_data
} ImageData; } ImageData;
#endif #endif

View file

@ -15,8 +15,12 @@
#ifndef _IO_RAW_H_ #ifndef _IO_RAW_H_
#define _IO_RAW_H_ #define _IO_RAW_H_
extern int ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf); extern int ReadFrameConcatenated(InputParameters *p_Inp,
extern int ReadFrameSeparate (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf); VideoDataFile *input_file, int FrameNoInFile,
int HeaderSize, FrameFormat *source,
unsigned char *buf);
extern int ReadFrameSeparate(InputParameters *p_Inp, VideoDataFile *input_file,
int FrameNoInFile, int HeaderSize,
FrameFormat *source, unsigned char *buf);
#endif #endif

View file

@ -18,7 +18,8 @@
// See TIFF 6.0 Specification // See TIFF 6.0 Specification
// http://partners.adobe.com/public/developer/tiff/index.html // http://partners.adobe.com/public/developer/tiff/index.html
extern int ReadTIFFImage(InputParameters *p_Inp, VideoDataFile *input_file,
extern int ReadTIFFImage (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, FrameFormat *source, unsigned char *buf); int FrameNoInFile, FrameFormat *source,
unsigned char *buf);
#endif #endif

View file

@ -3,7 +3,7 @@
* \file io_video.h * \file io_video.h
* *
* \brief * \brief
* Video I/O * Video I/O
* *
* \author * \author
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
@ -17,47 +17,47 @@
#include "frame.h" #include "frame.h"
typedef struct video_size { typedef struct video_size {
char* name; char *name;
int x_size; int x_size;
int y_size; int y_size;
} VIDEO_SIZE; } VIDEO_SIZE;
typedef enum { typedef enum {
VIDEO_UNKNOWN = -1, VIDEO_UNKNOWN = -1,
VIDEO_YUV = 0, VIDEO_YUV = 0,
VIDEO_RGB = 1, VIDEO_RGB = 1,
VIDEO_XYZ = 2, VIDEO_XYZ = 2,
VIDEO_TIFF = 3, VIDEO_TIFF = 3,
VIDEO_AVI = 4 VIDEO_AVI = 4
} VideoFileType; } VideoFileType;
typedef struct video_data_file typedef struct video_data_file {
{ // char* fname; //!< video file name
//char* fname; //!< video file name char fname[FILE_NAME_SIZE]; //!< video file name
char fname[FILE_NAME_SIZE]; //!< video file name char fhead[FILE_NAME_SIZE]; //!< header of video file
char fhead[FILE_NAME_SIZE]; //!< header of video file char ftail[FILE_NAME_SIZE]; //!< tail of video file
char ftail[FILE_NAME_SIZE]; //!< tail of video file int f_num; //!< video file number
int f_num; //!< video file number VideoFileType vdtype; //!< File format
VideoFileType vdtype; //!< File format FrameFormat format; //!< video format information
FrameFormat format; //!< video format information int is_concatenated; //!< Single or multifile input?
int is_concatenated; //!< Single or multifile input? int is_interleaved; //!< Support for interleaved and non-interleaved input
int is_interleaved; //!< Support for interleaved and non-interleaved input sources //!< sources
int zero_pad; //!< Used when separate image files are used as input. Enables zero padding for file numbering int zero_pad; //!< Used when separate image files are used as input. Enables
int num_digits; //!< Number of digits for file numbering //!< zero padding for file numbering
int start_frame; //!< start frame int num_digits; //!< Number of digits for file numbering
int end_frame; //!< end frame int start_frame; //!< start frame
int nframes; //!< number of frames int end_frame; //!< end frame
int crop_x_size; //!< crop information (x component) int nframes; //!< number of frames
int crop_y_size; //!< crop information (y component) int crop_x_size; //!< crop information (x component)
int crop_x_offset; //!< crop offset (x component); int crop_y_size; //!< crop information (y component)
int crop_y_offset; //!< crop offset (y component); int crop_x_offset; //!< crop offset (x component);
int crop_y_offset; //!< crop offset (y component);
// AVI related information to be added here // AVI related information to be added here
int* avi; int *avi;
//avi_t* avi; // avi_t* avi;
//int header; // int header;
//char compressor[8]; // char compressor[8];
} VideoDataFile; } VideoDataFile;
#endif #endif

View file

@ -1,11 +1,11 @@
/*! /*!
************************************************************************** **************************************************************************
* \file lagrangian.h * \file lagrangian.h
* \brief * \brief
* Distortion data header file * Distortion data header file
* \date 2.23.2009, * \date 2.23.2009,
* *
* \author * \author
* Alexis Michael Tourapis <alexismt@ieee.org> * Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************** **************************************************************************
@ -14,12 +14,10 @@
#ifndef _LAGRANGIAN_H_ #ifndef _LAGRANGIAN_H_
#define _LAGRANGIAN_H_ #define _LAGRANGIAN_H_
typedef struct lambda_params typedef struct lambda_params {
{ double md; //!< Mode decision Lambda
double md; //!< Mode decision Lambda double me[3]; //!< Motion Estimation Lambda
double me[3]; //!< Motion Estimation Lambda int mf[3]; //!< Integer formatted Motion Estimation Lambda
int mf[3]; //!< Integer formatted Motion Estimation Lambda
} LambdaParams; } LambdaParams;
#endif #endif

View file

@ -7,7 +7,8 @@
* Header for Leaky Buffer parameters * Header for Leaky Buffer parameters
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Shankar Regunathan <shanre@microsoft.com> * - Shankar Regunathan <shanre@microsoft.com>
************************************************************************************* *************************************************************************************
*/ */
@ -23,4 +24,3 @@ void calc_buffer(InputParameters *p_Inp);
#endif #endif
#endif #endif

View file

@ -9,8 +9,9 @@
* \brief * \brief
* Headerfile for loopfilter processing * Headerfile for loopfilter processing
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* - Alexis Michael Tourapis <alexismt@ieee.org> affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************** **************************************************************************
*/ */
@ -20,49 +21,61 @@
#include "global.h" #include "global.h"
#define GROUP_SIZE 1
#define GROUP_SIZE 1
/*********************************************************************************************************/ /*********************************************************************************************************/
// NOTE: In principle, the alpha and beta tables are calculated with the formulas below // NOTE: In principle, the alpha and beta tables are calculated with the
// formulas below
// Alpha( qp ) = 0.8 * (2^(qp/6) - 1) // Alpha( qp ) = 0.8 * (2^(qp/6) - 1)
// Beta ( qp ) = 0.5 * qp - 7 // Beta ( qp ) = 0.5 * qp - 7
// The tables actually used have been "hand optimized" though (by Anthony Joch). So, the // The tables actually used have been "hand optimized" though (by Anthony Joch).
// table values might be a little different to formula-generated values. Also, the first // So, the table values might be a little different to formula-generated values.
// few values of both tables is set to zero to force the filter off at low qps // Also, the first few values of both tables is set to zero to force the filter
// off at low qps
static const byte ALPHA_TABLE[52] = {0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,4,4,5,6, 7,8,9,10,12,13,15,17, 20,22,25,28,32,36,40,45, 50,56,63,71,80,90,101,113, 127,144,162,182,203,226,255,255} ; static const byte ALPHA_TABLE[52] = {
static const byte BETA_TABLE[52] = {0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,2,2,2,3, 3,3,3, 4, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 11,11,12,12,13,13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18} ; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
static const byte CLIP_TAB[52][5] = 0, 0, 0, 4, 4, 5, 6, 7, 8, 9, 10, 12, 13,
{ 15, 17, 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 63,
{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0}, 71, 80, 90, 101, 113, 127, 144, 162, 182, 203, 226, 255, 255};
{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0}, static const byte BETA_TABLE[52] = {
{ 0, 0, 0, 0, 0},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 1, 1, 1},{ 0, 0, 1, 1, 1},{ 0, 1, 1, 1, 1}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
{ 0, 1, 1, 1, 1},{ 0, 1, 1, 1, 1},{ 0, 1, 1, 1, 1},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 2, 3, 3}, 2, 3, 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
{ 0, 1, 2, 3, 3},{ 0, 2, 2, 3, 3},{ 0, 2, 2, 4, 4},{ 0, 2, 3, 4, 4},{ 0, 2, 3, 4, 4},{ 0, 3, 3, 5, 5},{ 0, 3, 4, 6, 6},{ 0, 3, 4, 6, 6}, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18};
{ 0, 4, 5, 7, 7},{ 0, 4, 5, 8, 8},{ 0, 4, 6, 9, 9},{ 0, 5, 7,10,10},{ 0, 6, 8,11,11},{ 0, 6, 8,13,13},{ 0, 7,10,14,14},{ 0, 8,11,16,16}, static const byte CLIP_TAB[52][5] = {
{ 0, 9,12,18,18},{ 0,10,13,20,20},{ 0,11,15,23,23},{ 0,13,17,25,25} {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
} ; {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 1, 1},
{0, 0, 0, 1, 1}, {0, 0, 0, 1, 1}, {0, 0, 0, 1, 1},
{0, 0, 1, 1, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1},
{0, 1, 1, 1, 1}, {0, 1, 1, 1, 1}, {0, 1, 1, 1, 1},
{0, 1, 1, 2, 2}, {0, 1, 1, 2, 2}, {0, 1, 1, 2, 2},
{0, 1, 1, 2, 2}, {0, 1, 2, 3, 3}, {0, 1, 2, 3, 3},
{0, 2, 2, 3, 3}, {0, 2, 2, 4, 4}, {0, 2, 3, 4, 4},
{0, 2, 3, 4, 4}, {0, 3, 3, 5, 5}, {0, 3, 4, 6, 6},
{0, 3, 4, 6, 6}, {0, 4, 5, 7, 7}, {0, 4, 5, 8, 8},
{0, 4, 6, 9, 9}, {0, 5, 7, 10, 10}, {0, 6, 8, 11, 11},
{0, 6, 8, 13, 13}, {0, 7, 10, 14, 14}, {0, 8, 11, 16, 16},
{0, 9, 12, 18, 18}, {0, 10, 13, 20, 20}, {0, 11, 15, 23, 23},
{0, 13, 17, 25, 25}};
static const signed char chroma_edge[2][4][4] = //[dir][edge][yuv_format] static const signed char chroma_edge[2][4][4] = //[dir][edge][yuv_format]
{ { {-4, 0, 0, 0}, {{{-4, 0, 0, 0}, {-4, -4, -4, 4}, {-4, 4, 4, 8}, {-4, -4, -4, 12}},
{-4,-4,-4, 4},
{-4, 4, 4, 8},
{-4,-4,-4, 12}},
{ {-4, 0, 0, 0}, {{-4, 0, 0, 0}, {-4, -4, 4, 4}, {-4, 4, 8, 8}, {-4, -4, 12, 12}}};
{-4,-4, 4, 4},
{-4, 4, 8, 8},
{-4,-4, 12, 12}}};
static const int pelnum_cr[2][4] = {{0,8,16,16}, {0,8, 8,16}}; //[dir:0=vert, 1=hor.][yuv_format] static const int pelnum_cr[2][4] = {
{0, 8, 16, 16}, {0, 8, 8, 16}}; //[dir:0=vert, 1=hor.][yuv_format]
static inline int compare_mvs(const MotionVector *mv0, const MotionVector *mv1,
static inline int compare_mvs(const MotionVector *mv0, const MotionVector *mv1, int mvlimit) int mvlimit) {
{ return ((iabs(mv0->mv_x - mv1->mv_x) >= 4) |
return ((iabs( mv0->mv_x - mv1->mv_x) >= 4) | (iabs( mv0->mv_y - mv1->mv_y) >= mvlimit)); (iabs(mv0->mv_y - mv1->mv_y) >= mvlimit));
} }
#endif #endif

View file

@ -13,7 +13,8 @@
#include "global.h" #include "global.h"
#include "mbuffer.h" #include "mbuffer.h"
extern void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) ; extern void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p);
extern void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p, int iStart, int iEnd) ; extern void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p,
void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag); int iStart, int iEnd);
void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag);
#endif //_LOOPFILTER_H_ #endif //_LOOPFILTER_H_

View file

@ -14,139 +14,116 @@
#ifndef _MACROBLOCK_H_ #ifndef _MACROBLOCK_H_
#define _MACROBLOCK_H_ #define _MACROBLOCK_H_
#include "block.h"
#include "global.h" #include "global.h"
#include "mbuffer.h" #include "mbuffer.h"
#include "block.h"
//! single scan pattern //! single scan pattern
static const byte SNGL_SCAN[16][2] = static const byte SNGL_SCAN[16][2] = {
{ {0, 0}, {1, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {3, 0}, {2, 1},
{0,0},{1,0},{0,1},{0,2}, {1, 2}, {0, 3}, {1, 3}, {2, 2}, {3, 1}, {3, 2}, {2, 3}, {3, 3}};
{1,1},{2,0},{3,0},{2,1},
{1,2},{0,3},{1,3},{2,2},
{3,1},{3,2},{2,3},{3,3}
};
//! field scan pattern //! field scan pattern
static const byte FIELD_SCAN[16][2] = static const byte FIELD_SCAN[16][2] = {
{ {0, 0}, {0, 1}, {1, 0}, {0, 2}, {0, 3}, {1, 1}, {1, 2}, {1, 3},
{0,0},{0,1},{1,0},{0,2}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {3, 0}, {3, 1}, {3, 2}, {3, 3}};
{0,3},{1,1},{1,2},{1,3},
{2,0},{2,1},{2,2},{2,3},
{3,0},{3,1},{3,2},{3,3}
};
//! used to control block sizes : Not used/16x16/16x8/8x16/8x8/8x4/4x8/4x4 //! used to control block sizes : Not used/16x16/16x8/8x16/8x8/8x4/4x8/4x4
static const int BLOCK_STEP[8][2]= static const int BLOCK_STEP[8][2] = {{0, 0}, {4, 4}, {4, 2}, {2, 4},
{ {2, 2}, {2, 1}, {1, 2}, {1, 1}};
{0,0},{4,4},{4,2},{2,4},{2,2},{2,1},{1,2},{1,1}
};
//! single scan pattern //! single scan pattern
static const byte SNGL_SCAN8x8[64][2] = { static const byte SNGL_SCAN8x8[64][2] = {
{0,0}, {1,0}, {0,1}, {0,2}, {1,1}, {2,0}, {3,0}, {2,1}, {1,2}, {0,3}, {0,4}, {1,3}, {2,2}, {3,1}, {4,0}, {5,0}, {0, 0}, {1, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {3, 0}, {2, 1},
{4,1}, {3,2}, {2,3}, {1,4}, {0,5}, {0,6}, {1,5}, {2,4}, {3,3}, {4,2}, {5,1}, {6,0}, {7,0}, {6,1}, {5,2}, {4,3}, {1, 2}, {0, 3}, {0, 4}, {1, 3}, {2, 2}, {3, 1}, {4, 0}, {5, 0},
{3,4}, {2,5}, {1,6}, {0,7}, {1,7}, {2,6}, {3,5}, {4,4}, {5,3}, {6,2}, {7,1}, {7,2}, {6,3}, {5,4}, {4,5}, {3,6}, {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}, {0, 6}, {1, 5}, {2, 4},
{2,7}, {3,7}, {4,6}, {5,5}, {6,4}, {7,3}, {7,4}, {6,5}, {5,6}, {4,7}, {5,7}, {6,6}, {7,5}, {7,6}, {6,7}, {7,7} {3, 3}, {4, 2}, {5, 1}, {6, 0}, {7, 0}, {6, 1}, {5, 2}, {4, 3},
}; {3, 4}, {2, 5}, {1, 6}, {0, 7}, {1, 7}, {2, 6}, {3, 5}, {4, 4},
{5, 3}, {6, 2}, {7, 1}, {7, 2}, {6, 3}, {5, 4}, {4, 5}, {3, 6},
{2, 7}, {3, 7}, {4, 6}, {5, 5}, {6, 4}, {7, 3}, {7, 4}, {6, 5},
{5, 6}, {4, 7}, {5, 7}, {6, 6}, {7, 5}, {7, 6}, {6, 7}, {7, 7}};
//! field scan pattern //! field scan pattern
static const byte FIELD_SCAN8x8[64][2] = { // 8x8 static const byte FIELD_SCAN8x8[64][2] = { // 8x8
{0,0}, {0,1}, {0,2}, {1,0}, {1,1}, {0,3}, {0,4}, {1,2}, {2,0}, {1,3}, {0,5}, {0,6}, {0,7}, {1,4}, {2,1}, {3,0}, {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, {0, 4}, {1, 2},
{2,2}, {1,5}, {1,6}, {1,7}, {2,3}, {3,1}, {4,0}, {3,2}, {2,4}, {2,5}, {2,6}, {2,7}, {3,3}, {4,1}, {5,0}, {4,2}, {2, 0}, {1, 3}, {0, 5}, {0, 6}, {0, 7}, {1, 4}, {2, 1}, {3, 0},
{3,4}, {3,5}, {3,6}, {3,7}, {4,3}, {5,1}, {6,0}, {5,2}, {4,4}, {4,5}, {4,6}, {4,7}, {5,3}, {6,1}, {6,2}, {5,4}, {2, 2}, {1, 5}, {1, 6}, {1, 7}, {2, 3}, {3, 1}, {4, 0}, {3, 2},
{5,5}, {5,6}, {5,7}, {6,3}, {7,0}, {7,1}, {6,4}, {6,5}, {6,6}, {6,7}, {7,2}, {7,3}, {7,4}, {7,5}, {7,6}, {7,7} {2, 4}, {2, 5}, {2, 6}, {2, 7}, {3, 3}, {4, 1}, {5, 0}, {4, 2},
}; {3, 4}, {3, 5}, {3, 6}, {3, 7}, {4, 3}, {5, 1}, {6, 0}, {5, 2},
{4, 4}, {4, 5}, {4, 6}, {4, 7}, {5, 3}, {6, 1}, {6, 2}, {5, 4},
{5, 5}, {5, 6}, {5, 7}, {6, 3}, {7, 0}, {7, 1}, {6, 4}, {6, 5},
{6, 6}, {6, 7}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 7}};
//! single scan pattern //! single scan pattern
static const byte SCAN_YUV422[8][2] = static const byte SCAN_YUV422[8][2] = {{0, 0}, {0, 1}, {1, 0}, {0, 2},
{ {0, 3}, {1, 1}, {1, 2}, {1, 3}};
{0,0},{0,1},
{1,0},{0,2},
{0,3},{1,1},
{1,2},{1,3}
};
static const unsigned char cbp_blk_chroma[8][4] = static const unsigned char cbp_blk_chroma[8][4] = {
{ {16, 17, 18, 19}, {16, 17, 18, 19}, {20, 21, 22, 23}, {24, 25, 26, 27}, {28, 29, 30, 31},
{20, 21, 22, 23}, {32, 33, 34, 35}, {36, 37, 38, 39}, {40, 41, 42, 43}, {44, 45, 46, 47}};
{24, 25, 26, 27},
{28, 29, 30, 31},
{32, 33, 34, 35},
{36, 37, 38, 39},
{40, 41, 42, 43},
{44, 45, 46, 47}
};
static const unsigned char cofuv_blk_x[3][8][4] = static const unsigned char cofuv_blk_x[3][8][4] = {{{0, 1, 0, 1},
{ { {0, 1, 0, 1}, {0, 1, 0, 1},
{0, 1, 0, 1}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0}},
{0, 0, 0, 0} },
{ {0, 1, 0, 1}, {{0, 1, 0, 1},
{0, 1, 0, 1}, {0, 1, 0, 1},
{0, 1, 0, 1}, {0, 1, 0, 1},
{0, 1, 0, 1}, {0, 1, 0, 1},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0, 0, 0} }, {0, 0, 0, 0}},
{ {0, 1, 0, 1}, {{0, 1, 0, 1},
{2, 3, 2, 3}, {2, 3, 2, 3},
{0, 1, 0, 1}, {0, 1, 0, 1},
{2, 3, 2, 3}, {2, 3, 2, 3},
{0, 1, 0, 1}, {0, 1, 0, 1},
{2, 3, 2, 3}, {2, 3, 2, 3},
{0, 1, 0, 1}, {0, 1, 0, 1},
{2, 3, 2, 3} } {2, 3, 2, 3}}};
};
static const unsigned char cofuv_blk_y[3][8][4] = static const unsigned char cofuv_blk_y[3][8][4] = {{{0, 0, 1, 1},
{ {0, 0, 1, 1},
{ { 0, 0, 1, 1}, {0, 0, 0, 0},
{ 0, 0, 1, 1}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0}},
{ 0, 0, 0, 0},
{ 0, 0, 0, 0} },
{ { 0, 0, 1, 1}, {{0, 0, 1, 1},
{ 2, 2, 3, 3}, {2, 2, 3, 3},
{ 0, 0, 1, 1}, {0, 0, 1, 1},
{ 2, 2, 3, 3}, {2, 2, 3, 3},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0}, {0, 0, 0, 0},
{ 0, 0, 0, 0} }, {0, 0, 0, 0}},
{ { 0, 0, 1, 1},
{ 0, 0, 1, 1},
{ 2, 2, 3, 3},
{ 2, 2, 3, 3},
{ 0, 0, 1, 1},
{ 0, 0, 1, 1},
{ 2, 2, 3, 3},
{ 2, 2, 3, 3}}
};
{{0, 0, 1, 1},
{0, 0, 1, 1},
{2, 2, 3, 3},
{2, 2, 3, 3},
{0, 0, 1, 1},
{0, 0, 1, 1},
{2, 2, 3, 3},
{2, 2, 3, 3}}};
extern void setup_slice_methods(Slice *currSlice); extern void setup_slice_methods(Slice *currSlice);
extern void get_neighbors(Macroblock *currMB, PixelPos *block, int mb_x, int mb_y, int blockshape_x); extern void get_neighbors(Macroblock *currMB, PixelPos *block, int mb_x,
int mb_y, int blockshape_x);
extern void start_macroblock (Slice *currSlice, Macroblock **currMB);
extern int decode_one_macroblock(Macroblock *currMB, StorablePicture *dec_picture);
extern Boolean exit_macroblock (Slice *currSlice, int eos_bit);
extern void update_qp (Macroblock *currMB, int qp);
extern void start_macroblock(Slice *currSlice, Macroblock **currMB);
extern int decode_one_macroblock(Macroblock *currMB,
StorablePicture *dec_picture);
extern Boolean exit_macroblock(Slice *currSlice, int eos_bit);
extern void update_qp(Macroblock *currMB, int qp);
#endif #endif

View file

@ -7,9 +7,10 @@
* Functions for macroblock neighborhoods * Functions for macroblock neighborhoods
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* - Karsten Sühring <suehring@hhi.de> *affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
@ -18,14 +19,18 @@
extern void CheckAvailabilityOfNeighbors(Macroblock *currMB); extern void CheckAvailabilityOfNeighbors(Macroblock *currMB);
extern void getAffNeighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); extern void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2],
extern void getNonAffNeighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); PixelPos *pix);
extern void get4x4Neighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); extern void getNonAffNeighbour(Macroblock *currMB, int xN, int yN,
extern void get4x4NeighbourBase (Macroblock *currMB, int block_x, int block_y, int mb_size[2], PixelPos *pix); int mb_size[2], PixelPos *pix);
extern Boolean mb_is_available (int mbAddr, Macroblock *currMB); extern void get4x4Neighbour(Macroblock *currMB, int xN, int yN, int mb_size[2],
extern void get_mb_pos (VideoParameters *p_Vid, int mb_addr, int mb_size[2], short *x, short *y); PixelPos *pix);
extern void get_mb_block_pos_normal (int mb_addr, short *x, short *y); extern void get4x4NeighbourBase(Macroblock *currMB, int block_x, int block_y,
extern void get_mb_block_pos_mbaff (int mb_addr, short *x, short *y); int mb_size[2], PixelPos *pix);
extern Boolean mb_is_available(int mbAddr, Macroblock *currMB);
extern void get_mb_pos(VideoParameters *p_Vid, int mb_addr, int mb_size[2],
short *x, short *y);
extern void get_mb_block_pos_normal(int mb_addr, short *x, short *y);
extern void get_mb_block_pos_mbaff(int mb_addr, short *x, short *y);
#endif #endif

View file

@ -7,29 +7,48 @@
* Functions for macroblock prediction * Functions for macroblock prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* - Alexis Michael Tourapis <alexismt@ieee.org> *affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
#ifndef _MB_PREDICTION_H_ #ifndef _MB_PREDICTION_H_
#define _MB_PREDICTION_H_ #define _MB_PREDICTION_H_
extern int mb_pred_intra4x4 (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); extern int mb_pred_intra4x4(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_intra16x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); imgpel **currImg, StorablePicture *dec_picture);
extern int mb_pred_intra8x8 (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); extern int mb_pred_intra16x16(Macroblock *currMB, ColorPlane curr_plane,
StorablePicture *dec_picture);
extern int mb_pred_intra8x8(Macroblock *currMB, ColorPlane curr_plane,
imgpel **currImg, StorablePicture *dec_picture);
extern int mb_pred_skip (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); extern int mb_pred_skip(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_sp_skip (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); imgpel **currImg, StorablePicture *dec_picture);
extern int mb_pred_p_inter8x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); extern int mb_pred_sp_skip(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_p_inter16x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); StorablePicture *dec_picture);
extern int mb_pred_p_inter16x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); extern int mb_pred_p_inter8x8(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_p_inter8x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); StorablePicture *dec_picture);
extern int mb_pred_b_d4x4spatial (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); extern int mb_pred_p_inter16x16(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_b_d8x8spatial (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); StorablePicture *dec_picture);
extern int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); extern int mb_pred_p_inter16x8(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); StorablePicture *dec_picture);
extern int mb_pred_b_inter8x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); extern int mb_pred_p_inter8x16(Macroblock *currMB, ColorPlane curr_plane,
extern int mb_pred_ipcm (Macroblock *currMB); StorablePicture *dec_picture);
extern int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane,
imgpel **currImg,
StorablePicture *dec_picture);
extern int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane,
imgpel **currImg,
StorablePicture *dec_picture);
extern int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane,
imgpel **currImg,
StorablePicture *dec_picture);
extern int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane,
imgpel **currImg,
StorablePicture *dec_picture);
extern int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane,
StorablePicture *dec_picture);
extern int mb_pred_ipcm(Macroblock *currMB);
#endif #endif

View file

@ -8,10 +8,11 @@
* Frame buffer functions * Frame buffer functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
affiliation details)
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* - Jill Boyce <jill.boyce@thomson.net> * - Jill Boyce <jill.boyce@thomson.net>
* - Saurav K Bandyopadhyay <saurav@ieee.org> * - Saurav K Bandyopadhyay <saurav@ieee.org>
* - Zhenyu Wu <Zhenyu.Wu@thomson.net * - Zhenyu Wu <Zhenyu.Wu@thomson.net
@ -26,109 +27,111 @@
#define MAX_LIST_SIZE 33 #define MAX_LIST_SIZE 33
//! definition of pic motion parameters //! definition of pic motion parameters
typedef struct pic_motion_params_old typedef struct pic_motion_params_old {
{ byte *mb_field; //!< field macroblock indicator
byte * mb_field; //!< field macroblock indicator
} PicMotionParamsOld; } PicMotionParamsOld;
//! definition of pic motion parameters //! definition of pic motion parameters
typedef struct pic_motion_params typedef struct pic_motion_params {
{ struct storable_picture *ref_pic[2]; //!< referrence picture pointer
struct storable_picture *ref_pic[2]; //!< referrence picture pointer MotionVector mv[2]; //!< motion vector
MotionVector mv[2]; //!< motion vector signed char ref_idx[2]; //!< reference picture [list][subblock_y][subblock_x]
signed char ref_idx[2]; //!< reference picture [list][subblock_y][subblock_x] // byte mb_field; //!< field macroblock indicator
//byte mb_field; //!< field macroblock indicator // byte field_frame; //!< indicates if co_located is field
//byte field_frame; //!< indicates if co_located is field or frame. Will be removed at some point // or frame. Will be removed at some point
} PicMotionParams; } PicMotionParams;
//! definition a picture (field or frame) //! definition a picture (field or frame)
typedef struct storable_picture typedef struct storable_picture {
{
PictureStructure structure; PictureStructure structure;
int poc; int poc;
int top_poc; int top_poc;
int bottom_poc; int bottom_poc;
int frame_poc; int frame_poc;
unsigned int frame_num; unsigned int frame_num;
unsigned int recovery_frame; unsigned int recovery_frame;
int pic_num; int pic_num;
int long_term_pic_num; int long_term_pic_num;
int long_term_frame_idx; int long_term_frame_idx;
byte is_long_term; byte is_long_term;
int used_for_reference; int used_for_reference;
int is_output; int is_output;
int non_existing; int non_existing;
int separate_colour_plane_flag; int separate_colour_plane_flag;
short max_slice_id; short max_slice_id;
int size_x, size_y, size_x_cr, size_y_cr; int size_x, size_y, size_x_cr, size_y_cr;
int size_x_m1, size_y_m1, size_x_cr_m1, size_y_cr_m1; int size_x_m1, size_y_m1, size_x_cr_m1, size_y_cr_m1;
int coded_frame; int coded_frame;
int mb_aff_frame_flag; int mb_aff_frame_flag;
unsigned PicWidthInMbs; unsigned PicWidthInMbs;
unsigned PicSizeInMbs; unsigned PicSizeInMbs;
int iLumaPadY, iLumaPadX; int iLumaPadY, iLumaPadX;
int iChromaPadY, iChromaPadX; int iChromaPadY, iChromaPadX;
imgpel **imgY; //!< Y picture component
imgpel ***imgUV; //!< U and V picture components
imgpel ***img_comp; //!< Y,U, and V components
imgpel ** imgY; //!< Y picture component struct pic_motion_params **mv_info; //!< Motion info
imgpel *** imgUV; //!< U and V picture components struct pic_motion_params **JVmv_info[MAX_PLANE]; //!< Motion info
imgpel *** img_comp; //!< Y,U, and V components
struct pic_motion_params_old motion; //!< Motion info
struct pic_motion_params_old
JVmotion[MAX_PLANE]; //!< Motion info for 4:4:4 independent mode decoding
struct pic_motion_params **mv_info; //!< Motion info short **slice_id; //!< reference picture [mb_x][mb_y]
struct pic_motion_params **JVmv_info[MAX_PLANE]; //!< Motion info
struct pic_motion_params_old motion; //!< Motion info struct storable_picture
struct pic_motion_params_old JVmotion[MAX_PLANE]; //!< Motion info for 4:4:4 independent mode decoding *top_field; // for mb aff, if frame for referencing the top field
struct storable_picture
*bottom_field; // for mb aff, if frame for referencing the bottom field
struct storable_picture
*frame; // for mb aff, if field for referencing the combined frame
short ** slice_id; //!< reference picture [mb_x][mb_y] int slice_type;
int idr_flag;
int no_output_of_prior_pics_flag;
int long_term_reference_flag;
int adaptive_ref_pic_buffering_flag;
struct storable_picture *top_field; // for mb aff, if frame for referencing the top field int chroma_format_idc;
struct storable_picture *bottom_field; // for mb aff, if frame for referencing the bottom field int frame_mbs_only_flag;
struct storable_picture *frame; // for mb aff, if field for referencing the combined frame int frame_cropping_flag;
int frame_cropping_rect_left_offset;
int slice_type; int frame_cropping_rect_right_offset;
int idr_flag; int frame_cropping_rect_top_offset;
int no_output_of_prior_pics_flag; int frame_cropping_rect_bottom_offset;
int long_term_reference_flag; int qp;
int adaptive_ref_pic_buffering_flag; int chroma_qp_offset[2];
int slice_qp_delta;
int chroma_format_idc; DecRefPicMarking_t
int frame_mbs_only_flag; *dec_ref_pic_marking_buffer; //!< stores the memory management control
int frame_cropping_flag; //!< operations
int frame_cropping_rect_left_offset;
int frame_cropping_rect_right_offset;
int frame_cropping_rect_top_offset;
int frame_cropping_rect_bottom_offset;
int qp;
int chroma_qp_offset[2];
int slice_qp_delta;
DecRefPicMarking_t *dec_ref_pic_marking_buffer; //!< stores the memory management control operations
// picture error concealment // picture error concealment
int concealed_pic; //indicates if this is a concealed picture int concealed_pic; // indicates if this is a concealed picture
// variables for tone mapping // variables for tone mapping
int seiHasTone_mapping; int seiHasTone_mapping;
int tone_mapping_model_id; int tone_mapping_model_id;
int tonemapped_bit_depth; int tonemapped_bit_depth;
imgpel* tone_mapping_lut; //!< tone mapping look up table imgpel *tone_mapping_lut; //!< tone mapping look up table
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int view_id; int view_id;
int inter_view_flag; int inter_view_flag;
int anchor_pic_flag; int anchor_pic_flag;
#endif #endif
int iLumaStride; int iLumaStride;
int iChromaStride; int iChromaStride;
int iLumaExpandedHeight; int iLumaExpandedHeight;
int iChromaExpandedHeight; int iChromaExpandedHeight;
imgpel **cur_imgY; // for more efficient get_block_luma imgpel **cur_imgY; // for more efficient get_block_luma
int no_ref; int no_ref;
int iCodingType; int iCodingType;
@ -140,31 +143,33 @@ typedef struct storable_picture
typedef StorablePicture *StorablePicturePtr; typedef StorablePicture *StorablePicturePtr;
//! definition a picture (field or frame) //! definition a picture (field or frame)
typedef struct colocated_params typedef struct colocated_params {
{ int mb_adaptive_frame_field_flag;
int mb_adaptive_frame_field_flag; int size_x, size_y;
int size_x, size_y; byte is_long_term;
byte is_long_term;
} ColocatedParams; } ColocatedParams;
//! Frame Stores for Decoded Picture Buffer //! Frame Stores for Decoded Picture Buffer
typedef struct frame_store typedef struct frame_store {
{ int is_used; //!< 0=empty; 1=top; 2=bottom; 3=both fields (or frame)
int is_used; //!< 0=empty; 1=top; 2=bottom; 3=both fields (or frame) int is_reference; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both
int is_reference; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used //!< fields (or frame) used
int is_long_term; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used int is_long_term; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both
int is_orig_reference; //!< original marking by nal_ref_idc: 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used //!< fields (or frame) used
int is_orig_reference; //!< original marking by nal_ref_idc: 0=not used for
//!< ref; 1=top used; 2=bottom used; 3=both fields (or
//!< frame) used
int is_non_existent; int is_non_existent;
unsigned frame_num; unsigned frame_num;
unsigned recovery_frame; unsigned recovery_frame;
int frame_num_wrap; int frame_num_wrap;
int long_term_frame_idx; int long_term_frame_idx;
int is_output; int is_output;
int poc; int poc;
// picture error concealment // picture error concealment
int concealment_reference; int concealment_reference;
@ -174,92 +179,95 @@ typedef struct frame_store
StorablePicture *bottom_field; StorablePicture *bottom_field;
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int view_id; int view_id;
int inter_view_flag[2]; int inter_view_flag[2];
int anchor_pic_flag[2]; int anchor_pic_flag[2];
#endif #endif
} FrameStore; } FrameStore;
//! Decoded Picture Buffer //! Decoded Picture Buffer
typedef struct decoded_picture_buffer typedef struct decoded_picture_buffer {
{
VideoParameters *p_Vid; VideoParameters *p_Vid;
InputParameters *p_Inp; InputParameters *p_Inp;
FrameStore **fs; FrameStore **fs;
FrameStore **fs_ref; FrameStore **fs_ref;
FrameStore **fs_ltref; FrameStore **fs_ltref;
unsigned size; unsigned size;
unsigned used_size; unsigned used_size;
unsigned ref_frames_in_buffer; unsigned ref_frames_in_buffer;
unsigned ltref_frames_in_buffer; unsigned ltref_frames_in_buffer;
int last_output_poc; int last_output_poc;
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int last_output_view_id; int last_output_view_id;
int max_long_term_pic_idx[MAX_VIEW_NUM]; int max_long_term_pic_idx[MAX_VIEW_NUM];
#else #else
int max_long_term_pic_idx; int max_long_term_pic_idx;
#endif #endif
int init_done; int init_done;
int num_ref_frames; int num_ref_frames;
FrameStore *last_picture; FrameStore *last_picture;
} DecodedPictureBuffer; } DecodedPictureBuffer;
extern void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb); extern void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb);
extern void re_init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb); extern void re_init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb);
extern void free_dpb(DecodedPictureBuffer *p_Dpb); extern void free_dpb(DecodedPictureBuffer *p_Dpb);
extern FrameStore* alloc_frame_store(void); extern FrameStore *alloc_frame_store(void);
extern void free_frame_store (FrameStore* f); extern void free_frame_store(FrameStore *f);
extern StorablePicture* alloc_storable_picture(VideoParameters *p_Vid, PictureStructure type, int size_x, int size_y, int size_x_cr, int size_y_cr); extern StorablePicture *alloc_storable_picture(VideoParameters *p_Vid,
extern void free_storable_picture (StorablePicture* p); PictureStructure type,
extern void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p); int size_x, int size_y,
extern StorablePicture* get_short_term_pic (DecodedPictureBuffer *p_Dpb, int picNum); int size_x_cr, int size_y_cr);
extern StorablePicture* get_long_term_pic (DecodedPictureBuffer *p_Dpb, int LongtermPicNum); extern void free_storable_picture(StorablePicture *p);
extern void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb,
StorablePicture *p);
extern StorablePicture *get_short_term_pic(DecodedPictureBuffer *p_Dpb,
int picNum);
extern StorablePicture *get_long_term_pic(DecodedPictureBuffer *p_Dpb,
int LongtermPicNum);
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
extern void flush_dpb(DecodedPictureBuffer *p_Dpb, int curr_view_id); extern void flush_dpb(DecodedPictureBuffer *p_Dpb, int curr_view_id);
extern int GetMaxDecFrameBuffering(VideoParameters *p_Vid); extern int GetMaxDecFrameBuffering(VideoParameters *p_Vid);
extern void append_interview_list(DecodedPictureBuffer *p_Dpb, extern void append_interview_list(DecodedPictureBuffer *p_Dpb,
PictureStructure currPicStructure, PictureStructure currPicStructure,
int list_idx, int list_idx, FrameStore **list,
FrameStore **list, int *listXsize, int currPOC, int curr_view_id,
int *listXsize, int anchor_pic_flag);
int currPOC, extern void update_ref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id);
int curr_view_id, extern void update_ltref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id);
int anchor_pic_flag);
extern void update_ref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id);
extern void update_ltref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id);
#else #else
extern void flush_dpb(DecodedPictureBuffer *p_Dpb); extern void flush_dpb(DecodedPictureBuffer *p_Dpb);
#endif #endif
extern void init_lists(Slice *currSlice); extern void init_lists(Slice *currSlice);
extern void init_lists_p_slice(Slice *currSlice); extern void init_lists_p_slice(Slice *currSlice);
extern void init_lists_b_slice(Slice *currSlice); extern void init_lists_b_slice(Slice *currSlice);
extern void init_lists_i_slice(Slice *currSlice); extern void init_lists_i_slice(Slice *currSlice);
extern void update_pic_num (Slice *currSlice); extern void update_pic_num(Slice *currSlice);
extern void dpb_split_field (VideoParameters *p_Vid, FrameStore *fs); extern void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs);
extern void dpb_combine_field(VideoParameters *p_Vid, FrameStore *fs); extern void dpb_combine_field(VideoParameters *p_Vid, FrameStore *fs);
extern void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs); extern void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs);
extern void reorder_ref_pic_list(Slice *currSlice, int cur_list); extern void reorder_ref_pic_list(Slice *currSlice, int cur_list);
extern void init_mbaff_lists(VideoParameters *p_Vid, Slice *currSlice); extern void init_mbaff_lists(VideoParameters *p_Vid, Slice *currSlice);
extern void alloc_ref_pic_list_reordering_buffer(Slice *currSlice); extern void alloc_ref_pic_list_reordering_buffer(Slice *currSlice);
extern void free_ref_pic_list_reordering_buffer(Slice *currSlice); extern void free_ref_pic_list_reordering_buffer(Slice *currSlice);
extern void fill_frame_num_gap(VideoParameters *p_Vid, Slice *pSlice); extern void fill_frame_num_gap(VideoParameters *p_Vid, Slice *pSlice);
extern void compute_colocated (Slice *currSlice, StorablePicture **listX[6]); extern void compute_colocated(Slice *currSlice, StorablePicture **listX[6]);
extern void gen_pic_list_from_frame_list(PictureStructure currStructure,
FrameStore **fs_list, int list_idx,
StorablePicture **list,
signed char *list_size, int long_term);
extern void gen_pic_list_from_frame_list(PictureStructure currStructure, FrameStore **fs_list, int list_idx, StorablePicture **list, signed char *list_size, int long_term); extern void pad_dec_picture(VideoParameters *p_Vid,
StorablePicture *dec_picture);
extern void pad_buf(imgpel *pImgBuf, int iWidth, int iHeight, int iStride,
extern void pad_dec_picture(VideoParameters *p_Vid, StorablePicture *dec_picture); int iPadX, int iPadY);
extern void pad_buf(imgpel *pImgBuf, int iWidth, int iHeight, int iStride, int iPadX, int iPadY);
#endif #endif

View file

@ -8,7 +8,8 @@
* MVC Frame buffer functions * MVC Frame buffer functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Athanasios Leontaris <aleon@dolby.com> * - Athanasios Leontaris <aleon@dolby.com>
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
@ -21,18 +22,24 @@
#include "global.h" #include "global.h"
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
extern void reorder_lists_mvc (Slice * currSlice, int currPOC); extern void reorder_lists_mvc(Slice *currSlice, int currPOC);
extern void init_lists_mvc (Slice *currSlice); extern void init_lists_mvc(Slice *currSlice);
extern void init_lists_p_slice_mvc(Slice *currSlice); extern void init_lists_p_slice_mvc(Slice *currSlice);
extern void init_lists_b_slice_mvc(Slice *currSlice); extern void init_lists_b_slice_mvc(Slice *currSlice);
extern void init_lists_i_slice_mvc(Slice *currSlice); extern void init_lists_i_slice_mvc(Slice *currSlice);
extern void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list, int **anchor_ref, int **non_anchor_ref, extern void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list,
int view_id, int anchor_pic_flag, int currPOC, int listidx); int **anchor_ref, int **non_anchor_ref,
int view_id, int anchor_pic_flag,
int currPOC, int listidx);
extern void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_lX_active_minus1, int picNumLX, int *refIdxLX, int currViewID); extern void reorder_short_term(Slice *currSlice, int cur_list,
extern void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int LongTermPicNum, int *refIdxLX, int currViewID); int num_ref_idx_lX_active_minus1, int picNumLX,
int *refIdxLX, int currViewID);
extern void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX,
int num_ref_idx_lX_active_minus1,
int LongTermPicNum, int *refIdxLX,
int currViewID);
#endif #endif
#endif #endif

View file

@ -7,7 +7,7 @@
* definitions for motion compensated prediction * definitions for motion compensated prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
@ -20,14 +20,22 @@
#include "global.h" #include "global.h"
#include "mbuffer.h" #include "mbuffer.h"
extern int allocate_pred_mem(Slice *currSlice); extern int allocate_pred_mem(Slice *currSlice);
extern void free_pred_mem (Slice *currSlice); extern void free_pred_mem(Slice *currSlice);
extern void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos, int hor_block_size, int ver_block_size, imgpel **block, extern void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos,
int shift_x,int maxold_x,int maxold_y,int **tmp_res,int max_imgpel_value,imgpel no_ref_value,Macroblock *currMB); int hor_block_size, int ver_block_size,
imgpel **block, int shift_x, int maxold_x,
int maxold_y, int **tmp_res, int max_imgpel_value,
imgpel no_ref_value, Macroblock *currMB);
extern void intra_cr_decoding (Macroblock *currMB, int yuv); extern void intra_cr_decoding(Macroblock *currMB, int yuv);
extern void prepare_direct_params(Macroblock *currMB, StorablePicture *dec_picture, MotionVector *pmvl0, MotionVector *pmvl1,signed char *l0_rFrame, signed char *l1_rFrame); extern void prepare_direct_params(Macroblock *currMB,
extern void perform_mc (Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int i, int j, int block_size_x, int block_size_y); StorablePicture *dec_picture,
MotionVector *pmvl0, MotionVector *pmvl1,
signed char *l0_rFrame,
signed char *l1_rFrame);
extern void perform_mc(Macroblock *currMB, ColorPlane pl,
StorablePicture *dec_picture, int pred_dir, int i, int j,
int block_size_x, int block_size_y);
#endif #endif

View file

@ -7,9 +7,10 @@
* Memory allocation and free helper funtions * Memory allocation and free helper funtions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* - Karsten Sühring <suehring@hhi.de> *affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************ ************************************************************************
*/ */
@ -17,164 +18,206 @@
#ifndef _MEMALLOC_H_ #ifndef _MEMALLOC_H_
#define _MEMALLOC_H_ #define _MEMALLOC_H_
#include "global.h"
#include "mbuffer.h"
#include "distortion.h" #include "distortion.h"
#include "global.h"
#include "lagrangian.h" #include "lagrangian.h"
#include "mbuffer.h"
#include "quant_params.h" #include "quant_params.h"
extern int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1); extern int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1);
extern int get_mem2Dlm (LambdaParams ***array2D, int dim0, int dim1); extern int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1);
extern int get_mem2Dolm (LambdaParams ***array2D, int dim0, int dim1, int offset); extern int get_mem2Dolm(LambdaParams ***array2D, int dim0, int dim1,
int offset);
extern int get_mem2Dmp (PicMotionParams ***array2D, int dim0, int dim1); extern int get_mem2Dmp(PicMotionParams ***array2D, int dim0, int dim1);
extern int get_mem3Dmp (PicMotionParams ****array3D, int dim0, int dim1, int dim2); extern int get_mem3Dmp(PicMotionParams ****array3D, int dim0, int dim1,
int dim2);
extern int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1); extern int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1);
extern int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, int dim2); extern int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1,
extern int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, int dim2, int dim3); int dim2);
extern int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); extern int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1,
int dim2, int dim3);
extern int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1,
int dim2, int dim3, int dim4);
extern int get_mem2Dmv (MotionVector ***array2D, int dim0, int dim1); extern int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1);
extern int get_mem3Dmv (MotionVector ****array3D, int dim0, int dim1, int dim2); extern int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2);
extern int get_mem4Dmv (MotionVector *****array4D, int dim0, int dim1, int dim2, int dim3); extern int get_mem4Dmv(MotionVector *****array4D, int dim0, int dim1, int dim2,
extern int get_mem5Dmv (MotionVector ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); int dim3);
extern int get_mem6Dmv (MotionVector *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5); extern int get_mem5Dmv(MotionVector ******array5D, int dim0, int dim1, int dim2,
extern int get_mem7Dmv (MotionVector ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6); int dim3, int dim4);
extern int get_mem6Dmv(MotionVector *******array6D, int dim0, int dim1,
int dim2, int dim3, int dim4, int dim5);
extern int get_mem7Dmv(MotionVector ********array7D, int dim0, int dim1,
int dim2, int dim3, int dim4, int dim5, int dim6);
extern byte** new_mem2D(int dim0, int dim1); extern byte **new_mem2D(int dim0, int dim1);
extern int get_mem2D(byte ***array2D, int dim0, int dim1); extern int get_mem2D(byte ***array2D, int dim0, int dim1);
extern int get_mem3D(byte ****array3D, int dim0, int dim1, int dim2); extern int get_mem3D(byte ****array3D, int dim0, int dim1, int dim2);
extern int get_mem4D(byte *****array4D, int dim0, int dim1, int dim2, int dim3); extern int get_mem4D(byte *****array4D, int dim0, int dim1, int dim2, int dim3);
extern int** new_mem2Dint(int dim0, int dim1); extern int **new_mem2Dint(int dim0, int dim1);
extern int get_mem2Dint(int ***array2D, int rows, int columns); extern int get_mem2Dint(int ***array2D, int rows, int columns);
extern int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY, int iPadX); extern int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY,
extern int get_mem2Dint64(int64 ***array2D, int rows, int columns); int iPadX);
extern int get_mem3Dint(int ****array3D, int frames, int rows, int columns); extern int get_mem2Dint64(int64 ***array2D, int rows, int columns);
extern int get_mem3Dint64(int64 ****array3D, int frames, int rows, int columns); extern int get_mem3Dint(int ****array3D, int frames, int rows, int columns);
extern int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns ); extern int get_mem3Dint64(int64 ****array3D, int frames, int rows, int columns);
extern int get_mem4Dint64(int64 *****array4D, int idx, int frames, int rows, int columns ); extern int get_mem4Dint(int *****array4D, int idx, int frames, int rows,
extern int get_mem5Dint(int ******array5D, int refs, int blocktype, int rows, int columns, int component); int columns);
extern int get_mem4Dint64(int64 *****array4D, int idx, int frames, int rows,
int columns);
extern int get_mem5Dint(int ******array5D, int refs, int blocktype, int rows,
int columns, int component);
extern uint16** new_mem2Duint16(int dim0, int dim1); extern uint16 **new_mem2Duint16(int dim0, int dim1);
extern int get_mem2Duint16(uint16 ***array2D, int dim0, int dim1); extern int get_mem2Duint16(uint16 ***array2D, int dim0, int dim1);
extern int get_mem3Duint16(uint16 ****array3D,int dim0, int dim1, int dim2); extern int get_mem3Duint16(uint16 ****array3D, int dim0, int dim1, int dim2);
extern int get_mem2Ddistblk(distblk ***array2D, int rows, int columns); extern int get_mem2Ddistblk(distblk ***array2D, int rows, int columns);
extern int get_mem3Ddistblk(distblk ****array3D, int frames, int rows, int columns); extern int get_mem3Ddistblk(distblk ****array3D, int frames, int rows,
extern int get_mem4Ddistblk(distblk *****array4D, int idx, int frames, int rows, int columns ); int columns);
extern int get_mem4Ddistblk(distblk *****array4D, int idx, int frames, int rows,
int columns);
extern int get_mem2Dshort(short ***array2D, int dim0, int dim1); extern int get_mem2Dshort(short ***array2D, int dim0, int dim1);
extern int get_mem3Dshort(short ****array3D, int dim0, int dim1, int dim2); extern int get_mem3Dshort(short ****array3D, int dim0, int dim1, int dim2);
extern int get_mem4Dshort(short *****array4D, int dim0, int dim1, int dim2, int dim3); extern int get_mem4Dshort(short *****array4D, int dim0, int dim1, int dim2,
extern int get_mem5Dshort(short ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); int dim3);
extern int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5); extern int get_mem5Dshort(short ******array5D, int dim0, int dim1, int dim2,
extern int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6); int dim3, int dim4);
extern int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2,
int dim3, int dim4, int dim5);
extern int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2,
int dim3, int dim4, int dim5, int dim6);
extern int get_mem1Dpel(imgpel **array2D, int rows); extern int get_mem1Dpel(imgpel **array2D, int rows);
extern int get_mem2Dpel(imgpel ***array2D, int rows, int columns); extern int get_mem2Dpel(imgpel ***array2D, int rows, int columns);
extern int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, int iPadX); extern int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY,
int iPadX);
extern int get_mem3Dpel(imgpel ****array3D, int frames, int rows, int columns); extern int get_mem3Dpel(imgpel ****array3D, int frames, int rows, int columns);
extern int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX); extern int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2,
extern int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX); int iPadY, int iPadX);
extern int get_mem4Dpel(imgpel *****array4D, int sub_x, int sub_y, int rows, int columns); extern int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1,
extern int get_mem4DpelWithPad(imgpel *****array4D, int sub_x, int sub_y, int rows, int columns, int iPadY, int iPadX); int dim2, int iPadY, int iPadX);
extern int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3, int iPadY, int iPadX); extern int get_mem4Dpel(imgpel *****array4D, int sub_x, int sub_y, int rows,
extern int get_mem5Dpel(imgpel ******array5D, int dims, int sub_x, int sub_y, int rows, int columns); int columns);
extern int get_mem5DpelWithPad(imgpel ******array5D, int dims, int sub_x, int sub_y, int rows, int columns, int iPadY, int iPadX); extern int get_mem4DpelWithPad(imgpel *****array4D, int sub_x, int sub_y,
extern int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4, int iPadY, int iPadX); int rows, int columns, int iPadY, int iPadX);
extern int get_mem2Ddouble (double ***array2D, int rows, int columns); extern int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0,
int dim1, int dim2, int dim3,
int iPadY, int iPadX);
extern int get_mem5Dpel(imgpel ******array5D, int dims, int sub_x, int sub_y,
int rows, int columns);
extern int get_mem5DpelWithPad(imgpel ******array5D, int dims, int sub_x,
int sub_y, int rows, int columns, int iPadY,
int iPadX);
extern int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0,
int dim1, int dim2, int dim3, int dim4,
int iPadY, int iPadX);
extern int get_mem2Ddouble(double ***array2D, int rows, int columns);
extern int get_mem1Dodouble(double **array1D, int dim0, int offset); extern int get_mem1Dodouble(double **array1D, int dim0, int offset);
extern int get_mem2Dodouble(double ***array2D, int rows, int columns, int offset); extern int get_mem2Dodouble(double ***array2D, int rows, int columns,
extern int get_mem3Dodouble(double ****array2D, int rows, int columns, int pels, int offset); int offset);
extern int get_mem3Dodouble(double ****array2D, int rows, int columns, int pels,
int offset);
extern int get_mem2Doint (int ***array2D, int rows, int columns, int offset); extern int get_mem2Doint(int ***array2D, int rows, int columns, int offset);
extern int get_mem3Doint (int ****array3D, int rows, int columns, int pels, int offset); extern int get_mem3Doint(int ****array3D, int rows, int columns, int pels,
int offset);
extern int get_offset_mem2Dshort(short ***array2D, int rows, int columns, int offset_y, int offset_x); extern int get_offset_mem2Dshort(short ***array2D, int rows, int columns,
int offset_y, int offset_x);
extern void free_offset_mem2Dshort(short **array2D, int columns, int offset_x, int offset_y); extern void free_offset_mem2Dshort(short **array2D, int columns, int offset_x,
int offset_y);
extern void free_mem2Ddist (DistortionData **array2D); extern void free_mem2Ddist(DistortionData **array2D);
extern void free_mem2Dlm (LambdaParams **array2D); extern void free_mem2Dlm(LambdaParams **array2D);
extern void free_mem2Dolm (LambdaParams **array2D, int offset); extern void free_mem2Dolm(LambdaParams **array2D, int offset);
extern void free_mem2Dmp (PicMotionParams **array2D); extern void free_mem2Dmp(PicMotionParams **array2D);
extern void free_mem3Dmp (PicMotionParams ***array2D); extern void free_mem3Dmp(PicMotionParams ***array2D);
extern void free_mem2Dquant(LevelQuantParams **array2D); extern void free_mem2Dquant(LevelQuantParams **array2D);
extern void free_mem3Dquant(LevelQuantParams ***array2D); extern void free_mem3Dquant(LevelQuantParams ***array2D);
extern void free_mem4Dquant(LevelQuantParams ****array2D); extern void free_mem4Dquant(LevelQuantParams ****array2D);
extern void free_mem5Dquant(LevelQuantParams *****array2D); extern void free_mem5Dquant(LevelQuantParams *****array2D);
extern void free_mem2Dmv (MotionVector **array2D); extern void free_mem2Dmv(MotionVector **array2D);
extern void free_mem3Dmv (MotionVector ***array2D); extern void free_mem3Dmv(MotionVector ***array2D);
extern void free_mem4Dmv (MotionVector ****array2D); extern void free_mem4Dmv(MotionVector ****array2D);
extern void free_mem5Dmv (MotionVector *****array2D); extern void free_mem5Dmv(MotionVector *****array2D);
extern void free_mem6Dmv (MotionVector ******array2D); extern void free_mem6Dmv(MotionVector ******array2D);
extern void free_mem7Dmv (MotionVector *******array7D); extern void free_mem7Dmv(MotionVector *******array7D);
extern int get_mem2D_spp(StorablePicturePtr ***array3D, int dim0, int dim1); extern int get_mem2D_spp(StorablePicturePtr ***array3D, int dim0, int dim1);
extern int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, int dim2); extern int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1,
int dim2);
extern void free_mem2D_spp (StorablePicturePtr **array2D); extern void free_mem2D_spp(StorablePicturePtr **array2D);
extern void free_mem3D_spp (StorablePicturePtr ***array2D); extern void free_mem3D_spp(StorablePicturePtr ***array2D);
extern void free_mem2D (byte **array2D); extern void free_mem2D(byte **array2D);
extern void free_mem3D (byte ***array3D); extern void free_mem3D(byte ***array3D);
extern void free_mem4D (byte ****array4D); extern void free_mem4D(byte ****array4D);
extern void free_mem2Dint (int **array2D); extern void free_mem2Dint(int **array2D);
extern void free_mem2DintWithPad(int **array2D, int iPadY, int iPadX); extern void free_mem2DintWithPad(int **array2D, int iPadY, int iPadX);
extern void free_mem3Dint (int ***array3D); extern void free_mem3Dint(int ***array3D);
extern void free_mem4Dint (int ****array4D); extern void free_mem4Dint(int ****array4D);
extern void free_mem5Dint (int *****array5D); extern void free_mem5Dint(int *****array5D);
extern void free_mem2Duint16(uint16 **array2D); extern void free_mem2Duint16(uint16 **array2D);
extern void free_mem3Duint16(uint16 ***array3D); extern void free_mem3Duint16(uint16 ***array3D);
extern void free_mem2Dint64(int64 **array2D); extern void free_mem2Dint64(int64 **array2D);
extern void free_mem3Dint64(int64 ***array3D); extern void free_mem3Dint64(int64 ***array3D);
extern void free_mem4Dint64(int64 ****array4D); extern void free_mem4Dint64(int64 ****array4D);
extern void free_mem2Ddistblk(distblk **array2D); extern void free_mem2Ddistblk(distblk **array2D);
extern void free_mem3Ddistblk(distblk ***array3D); extern void free_mem3Ddistblk(distblk ***array3D);
extern void free_mem4Ddistblk(distblk ****array4D); extern void free_mem4Ddistblk(distblk ****array4D);
extern void free_mem2Dshort(short **array2D); extern void free_mem2Dshort(short **array2D);
extern void free_mem3Dshort(short ***array3D); extern void free_mem3Dshort(short ***array3D);
extern void free_mem4Dshort(short ****array4D); extern void free_mem4Dshort(short ****array4D);
extern void free_mem5Dshort(short *****array5D); extern void free_mem5Dshort(short *****array5D);
extern void free_mem6Dshort(short ******array6D); extern void free_mem6Dshort(short ******array6D);
extern void free_mem7Dshort(short *******array7D); extern void free_mem7Dshort(short *******array7D);
extern void free_mem1Dpel (imgpel *array1D); extern void free_mem1Dpel(imgpel *array1D);
extern void free_mem2Dpel (imgpel **array2D); extern void free_mem2Dpel(imgpel **array2D);
extern void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX); extern void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX);
extern void free_mem3Dpel (imgpel ***array3D); extern void free_mem3Dpel(imgpel ***array3D);
extern void free_mem3DpelWithPad(imgpel ***array3D, int iPadY, int iPadX); extern void free_mem3DpelWithPad(imgpel ***array3D, int iPadY, int iPadX);
extern void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12, int iPadY, int iPadX); extern void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12,
extern void free_mem4Dpel (imgpel ****array4D); int iPadY, int iPadX);
extern void free_mem4DpelWithPad(imgpel ****array4D, int iPadY, int iPadX); extern void free_mem4Dpel(imgpel ****array4D);
extern void free_mem4DpelWithPadSeparately(imgpel ****array4D, int iFrames, int iPadY, int iPadX); extern void free_mem4DpelWithPad(imgpel ****array4D, int iPadY, int iPadX);
extern void free_mem5Dpel (imgpel *****array5D); extern void free_mem4DpelWithPadSeparately(imgpel ****array4D, int iFrames,
int iPadY, int iPadX);
extern void free_mem5Dpel(imgpel *****array5D);
extern void free_mem5DpelWithPad(imgpel *****array5D, int iPadY, int iPadX); extern void free_mem5DpelWithPad(imgpel *****array5D, int iPadY, int iPadX);
extern void free_mem5DpelWithPadSeparately(imgpel *****array5D, int iFrames, int iPadY, int iPadX); extern void free_mem5DpelWithPadSeparately(imgpel *****array5D, int iFrames,
int iPadY, int iPadX);
extern void free_mem2Ddouble(double **array2D); extern void free_mem2Ddouble(double **array2D);
extern void free_mem3Ddouble(double ***array3D); extern void free_mem3Ddouble(double ***array3D);
extern void free_mem1Dodouble(double *array1D, int offset); extern void free_mem1Dodouble(double *array1D, int offset);
extern void free_mem2Dodouble(double **array2D, int offset); extern void free_mem2Dodouble(double **array2D, int offset);
extern void free_mem3Dodouble(double ***array3D, int rows, int columns, int offset); extern void free_mem3Dodouble(double ***array3D, int rows, int columns,
extern void free_mem2Doint (int **array2D, int offset); int offset);
extern void free_mem3Doint (int ***array3D, int rows, int columns, int offset); extern void free_mem2Doint(int **array2D, int offset);
extern void free_mem3Doint(int ***array3D, int rows, int columns, int offset);
extern int init_top_bot_planes(imgpel **imgFrame, int height, imgpel ***imgTopField, imgpel ***imgBotField); extern int init_top_bot_planes(imgpel **imgFrame, int height,
imgpel ***imgTopField, imgpel ***imgBotField);
extern void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField); extern void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField);
extern void no_mem_exit(char *where); extern void no_mem_exit(char *where);

View file

@ -6,14 +6,16 @@
* Declarations for Motion Vector Prediction * Declarations for Motion Vector Prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* - Alexis Michael Tourapis <alexismt@ieee.org> *affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
#ifndef _MV_PREDICTION_H_ #ifndef _MV_PREDICTION_H_
#define _MV_PREDICTION_H_ #define _MV_PREDICTION_H_
extern void init_motion_vector_prediction(Macroblock *currMB, int mb_aff_frame_flag); extern void init_motion_vector_prediction(Macroblock *currMB,
int mb_aff_frame_flag);
#endif #endif

View file

@ -8,27 +8,26 @@
* *
* \date 25 November 2002 * \date 25 November 2002
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
*************************************************************************************** ***************************************************************************************
*/ */
#ifndef _NALU_H_ #ifndef _NALU_H_
#define _NALU_H_ #define _NALU_H_
#include "nalucommon.h" #include "nalucommon.h"
typedef struct sBitsFile typedef struct sBitsFile {
{ void (*OpenBitsFile)(VideoParameters *p_Vid, char *filename);
void (*OpenBitsFile) (VideoParameters *p_Vid, char *filename); void (*CloseBitsFile)(VideoParameters *p_Vid);
void (*CloseBitsFile) (VideoParameters *p_Vid); int (*GetNALU)(VideoParameters *p_Vid, NALU_t *nalu);
int (*GetNALU) (VideoParameters *p_Vid, NALU_t *nalu);
} BitsFile; } BitsFile;
extern void initBitsFile (VideoParameters *p_Vid, int filemode); extern void initBitsFile(VideoParameters *p_Vid, int filemode);
extern void CheckZeroByteNonVCL(VideoParameters *p_Vid, NALU_t *nalu); extern void CheckZeroByteNonVCL(VideoParameters *p_Vid, NALU_t *nalu);
extern void CheckZeroByteVCL (VideoParameters *p_Vid, NALU_t *nalu); extern void CheckZeroByteVCL(VideoParameters *p_Vid, NALU_t *nalu);
extern int read_next_nalu(VideoParameters *p_Vid, NALU_t *nalu); extern int read_next_nalu(VideoParameters *p_Vid, NALU_t *nalu);

View file

@ -6,7 +6,8 @@
* \brief * \brief
* NALU handling common to encoder and decoder * NALU handling common to encoder and decoder
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
* - Karsten Suehring <suehring@hhi.de> * - Karsten Suehring <suehring@hhi.de>
*************************************************************************************** ***************************************************************************************
@ -22,54 +23,55 @@
//! values for nal_unit_type //! values for nal_unit_type
typedef enum { typedef enum {
NALU_TYPE_SLICE = 1, NALU_TYPE_SLICE = 1,
NALU_TYPE_DPA = 2, NALU_TYPE_DPA = 2,
NALU_TYPE_DPB = 3, NALU_TYPE_DPB = 3,
NALU_TYPE_DPC = 4, NALU_TYPE_DPC = 4,
NALU_TYPE_IDR = 5, NALU_TYPE_IDR = 5,
NALU_TYPE_SEI = 6, NALU_TYPE_SEI = 6,
NALU_TYPE_SPS = 7, NALU_TYPE_SPS = 7,
NALU_TYPE_PPS = 8, NALU_TYPE_PPS = 8,
NALU_TYPE_AUD = 9, NALU_TYPE_AUD = 9,
NALU_TYPE_EOSEQ = 10, NALU_TYPE_EOSEQ = 10,
NALU_TYPE_EOSTREAM = 11, NALU_TYPE_EOSTREAM = 11,
NALU_TYPE_FILL = 12, NALU_TYPE_FILL = 12,
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
NALU_TYPE_PREFIX = 14, NALU_TYPE_PREFIX = 14,
NALU_TYPE_SUB_SPS = 15, NALU_TYPE_SUB_SPS = 15,
NALU_TYPE_SLC_EXT = 20, NALU_TYPE_SLC_EXT = 20,
NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit
#endif #endif
} NaluType; } NaluType;
//! values for nal_ref_idc //! values for nal_ref_idc
typedef enum { typedef enum {
NALU_PRIORITY_HIGHEST = 3, NALU_PRIORITY_HIGHEST = 3,
NALU_PRIORITY_HIGH = 2, NALU_PRIORITY_HIGH = 2,
NALU_PRIORITY_LOW = 1, NALU_PRIORITY_LOW = 1,
NALU_PRIORITY_DISPOSABLE = 0 NALU_PRIORITY_DISPOSABLE = 0
} NalRefIdc; } NalRefIdc;
//! NAL unit structure //! NAL unit structure
typedef struct nalu_t typedef struct nalu_t {
{ int startcodeprefix_len; //!< 4 for parameter sets and first slice in picture,
int startcodeprefix_len; //!< 4 for parameter sets and first slice in picture, 3 for everything else (suggested) //!< 3 for everything else (suggested)
unsigned len; //!< Length of the NAL unit (Excluding the start code, which does not belong to the NALU) unsigned len; //!< Length of the NAL unit (Excluding the start code, which
unsigned max_size; //!< NAL Unit Buffer size //!< does not belong to the NALU)
int forbidden_bit; //!< should be always FALSE unsigned max_size; //!< NAL Unit Buffer size
NaluType nal_unit_type; //!< NALU_TYPE_xxxx int forbidden_bit; //!< should be always FALSE
NalRefIdc nal_reference_idc; //!< NALU_PRIORITY_xxxx NaluType nal_unit_type; //!< NALU_TYPE_xxxx
byte *buf; //!< contains the first byte followed by the EBSP NalRefIdc nal_reference_idc; //!< NALU_PRIORITY_xxxx
uint16 lost_packets; //!< true, if packet loss is detected byte *buf; //!< contains the first byte followed by the EBSP
uint16 lost_packets; //!< true, if packet loss is detected
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int svc_extension_flag; //!< should be always 0, for MVC int svc_extension_flag; //!< should be always 0, for MVC
int non_idr_flag; //!< 0 = current is IDR int non_idr_flag; //!< 0 = current is IDR
int priority_id; //!< a lower value of priority_id specifies a higher priority int priority_id; //!< a lower value of priority_id specifies a higher priority
int view_id; //!< view identifier for the NAL unit int view_id; //!< view identifier for the NAL unit
int temporal_id; //!< temporal identifier for the NAL unit int temporal_id; //!< temporal identifier for the NAL unit
int anchor_pic_flag; //!< anchor access unit int anchor_pic_flag; //!< anchor access unit
int inter_view_flag; //!< inter-view prediction enable int inter_view_flag; //!< inter-view prediction enable
int reserved_one_bit; //!< shall be equal to 1 int reserved_one_bit; //!< shall be equal to 1
#endif #endif
} NALU_t; } NALU_t;

View file

@ -6,7 +6,8 @@
* \brief * \brief
* Picture writing routine headers * Picture writing routine headers
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Karsten Suehring <suehring@hhi.de> * - Karsten Suehring <suehring@hhi.de>
*************************************************************************************** ***************************************************************************************
*/ */
@ -14,11 +15,12 @@
#ifndef _OUTPUT_H_ #ifndef _OUTPUT_H_
#define _OUTPUT_H_ #define _OUTPUT_H_
extern void write_stored_frame(VideoParameters *p_Vid, FrameStore *fs,
extern void write_stored_frame(VideoParameters *p_Vid, FrameStore *fs, int p_out); int p_out);
extern void direct_output (VideoParameters *p_Vid, StorablePicture *p, int p_out); extern void direct_output(VideoParameters *p_Vid, StorablePicture *p,
extern void init_out_buffer (VideoParameters *p_Vid); int p_out);
extern void uninit_out_buffer (VideoParameters *p_Vid); extern void init_out_buffer(VideoParameters *p_Vid);
extern void uninit_out_buffer(VideoParameters *p_Vid);
#if (PAIR_FIELDS_IN_OUTPUT) #if (PAIR_FIELDS_IN_OUTPUT)
extern void flush_pending_output(VideoParameters *p_Vid, int p_out); extern void flush_pending_output(VideoParameters *p_Vid, int p_out);
#endif #endif

View file

@ -14,85 +14,101 @@
#define _PARAMS_H_ #define _PARAMS_H_
#include "defines.h" #include "defines.h"
#include "types.h"
#include "vui_params.h"
#include "frame.h" #include "frame.h"
#include "io_video.h" #include "io_video.h"
#include "types.h"
#include "vui_params.h"
//! all input parameters //! all input parameters
struct inp_par_enc struct inp_par_enc {
{ int ProfileIDC; //!< value of syntax element profile_idc
int ProfileIDC; //!< value of syntax element profile_idc int LevelIDC; //!< value of syntax element level_idc
int LevelIDC; //!< value of syntax element level_idc int IntraProfile; //!< Enable Intra profiles
int IntraProfile; //!< Enable Intra profiles
int no_frames; //!< number of frames to be encoded
int no_frames; //!< number of frames to be encoded int qp[NUM_SLICE_TYPES]; //!< QP values for all slice types
int qp[NUM_SLICE_TYPES]; //!< QP values for all slice types int qp2frame; //!< frame in display order from which to apply the Change QP
int qp2frame; //!< frame in display order from which to apply the Change QP offsets //!< offsets
int qp2off[NUM_SLICE_TYPES]; //!< Change QP offset values for all slice types int qp2off[NUM_SLICE_TYPES]; //!< Change QP offset values for all slice types
int qpsp; //!< QPSP quantization value int qpsp; //!< QPSP quantization value
int frame_skip; //!< number of frames to skip in input sequence (e.g 2 takes frame 0,3,6,9...) int frame_skip; //!< number of frames to skip in input sequence (e.g 2 takes
int jumpd; /*!< number of frames to skip in input sequence including intermediate pictures //!< frame 0,3,6,9...)
(e.g 2 takes frame 0,3,6,9...) */ int jumpd; /*!< number of frames to skip in input sequence including
int DisableSubpelME; //!< Disable sub-pixel motion estimation intermediate pictures (e.g 2 takes frame 0,3,6,9...) */
int search_range; /*!< search range - integer pel search and 16x16 blocks. The search window is int DisableSubpelME; //!< Disable sub-pixel motion estimation
generally around the predicted vector. Max vector is 2xmcrange. */ int search_range; /*!< search range - integer pel search and 16x16 blocks. The
int num_ref_frames; //!< number of reference frames to be used search window is generally around the predicted vector.
int P_List0_refs; //!< number of reference picture in list 0 in P pictures Max vector is 2xmcrange. */
int B_List0_refs; //!< number of reference picture in list 0 in B pictures int num_ref_frames; //!< number of reference frames to be used
int B_List1_refs; //!< number of reference picture in list 1 in B pictures int P_List0_refs; //!< number of reference picture in list 0 in P pictures
int Log2MaxFNumMinus4; //!< value of syntax element log2_max_frame_num int B_List0_refs; //!< number of reference picture in list 0 in B pictures
int Log2MaxPOCLsbMinus4; //!< value of syntax element log2_max_pic_order_cnt_lsb_minus4 int B_List1_refs; //!< number of reference picture in list 1 in B pictures
int Log2MaxFNumMinus4; //!< value of syntax element log2_max_frame_num
int Log2MaxPOCLsbMinus4; //!< value of syntax element
//!< log2_max_pic_order_cnt_lsb_minus4
// Input/output sequence format related variables // Input/output sequence format related variables
FrameFormat source; //!< source related information FrameFormat source; //!< source related information
FrameFormat output; //!< output related information FrameFormat output; //!< output related information
int is_interleaved; int is_interleaved;
int src_resize; //!< Control if input sequence will be resized (currently only cropping is supported) int src_resize; //!< Control if input sequence will be resized (currently only
int src_BitDepthRescale; //!< Control if input sequence bitdepth should be adjusted //!< cropping is supported)
int yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) int src_BitDepthRescale; //!< Control if input sequence bitdepth should be
int intra_upd; /*!< For error robustness. 0: no special action. 1: One GOB/frame is intra coded //!< adjusted
as regular 'update'. 2: One GOB every 2 frames is intra coded etc. int yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4)
In connection with this intra update, restrictions is put on motion vectors int intra_upd; /*!< For error robustness. 0: no special action. 1: One
to prevent errors to propagate from the past */ GOB/frame is intra coded as regular 'update'. 2: One GOB
every 2 frames is intra coded etc. In connection with this
intra update, restrictions is put on motion vectors to
prevent errors to propagate from the past */
int slice_mode; //!< Indicate what algorithm to use for setting slices int slice_mode; //!< Indicate what algorithm to use for setting slices
int slice_argument; //!< Argument to the specified slice algorithm int slice_argument; //!< Argument to the specified slice algorithm
int UseConstrainedIntraPred; //!< 0: Inter MB pixels are allowed for intra prediction 1: Not allowed int UseConstrainedIntraPred; //!< 0: Inter MB pixels are allowed for intra
int SetFirstAsLongTerm; //!< Support for temporal considerations for CB plus encoding //!< prediction 1: Not allowed
int infile_header; //!< If input file has a header set this to the length of the header int SetFirstAsLongTerm; //!< Support for temporal considerations for CB plus
int MultiSourceData; //!< encoding
VideoDataFile input_file2; //!< Input video file2 int infile_header; //!< If input file has a header set this to the length of
VideoDataFile input_file3; //!< Input video file3 //!< the header
int MultiSourceData;
VideoDataFile input_file2; //!< Input video file2
VideoDataFile input_file3; //!< Input video file3
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int num_of_views; //!< number of views to encode (1=1view, 2=2views) int num_of_views; //!< number of views to encode (1=1view, 2=2views)
int MVCInterViewReorder; //!< Reorder References according to interview pictures int MVCInterViewReorder; //!< Reorder References according to interview
int MVCFlipViews; //!< Reverse the order of the views in the bitstream (view 1 has VOIdx 0 and view 1 has VOIdx 0) //!< pictures
int MVCInterViewForceB; //!< Force B slices for enhancement layer int MVCFlipViews; //!< Reverse the order of the views in the bitstream (view 1
int View1QPOffset; //!< QP offset during rate control for View 1 //!< has VOIdx 0 and view 1 has VOIdx 0)
int enable_inter_view_flag; //!< Enables inter_view_flag (allows pictures that are to be used for inter-view only prediction) int MVCInterViewForceB; //!< Force B slices for enhancement layer
int View1QPOffset; //!< QP offset during rate control for View 1
int enable_inter_view_flag; //!< Enables inter_view_flag (allows pictures that
//!< are to be used for inter-view only
//!< prediction)
#endif #endif
VideoDataFile input_file1; //!< Input video file1 VideoDataFile input_file1; //!< Input video file1
signed char outfile [FILE_NAME_SIZE]; //!< H.264 compressed output bitstream signed char outfile[FILE_NAME_SIZE]; //!< H.264 compressed output bitstream
signed char ReconFile [FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 0 for MVC profile) signed char ReconFile[FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 0 for
signed char ReconFile2 [FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 1) //!< MVC profile)
signed char ReconFile2[FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 1)
signed char TraceFile [FILE_NAME_SIZE]; //!< Trace Outputs signed char TraceFile[FILE_NAME_SIZE]; //!< Trace Outputs
signed char StatsFile [FILE_NAME_SIZE]; //!< Stats File signed char StatsFile[FILE_NAME_SIZE]; //!< Stats File
signed char QmatrixFile [FILE_NAME_SIZE]; //!< Q matrix cfg file signed char QmatrixFile[FILE_NAME_SIZE]; //!< Q matrix cfg file
int ProcessInput; //!< Filter Input Sequence int ProcessInput; //!< Filter Input Sequence
int EnableOpenGOP; //!< support for open gops. int EnableOpenGOP; //!< support for open gops.
int EnableIDRGOP; //!< support for IDR closed gops with no shared B coded pictures. int EnableIDRGOP; //!< support for IDR closed gops with no shared B coded
int grayscale; //!< encode in grayscale (Currently only works for 8 bit, YUV 420) //!< pictures.
int grayscale; //!< encode in grayscale (Currently only works for 8 bit, YUV
//!< 420)
int idr_period; //!< IDR picture period int idr_period; //!< IDR picture period
int intra_period; //!< intra picture period int intra_period; //!< intra picture period
int intra_delay; //!< IDR picture delay int intra_delay; //!< IDR picture delay
int adaptive_idr_period; int adaptive_idr_period;
int adaptive_intra_period; //!< reinitialize start of intra period int adaptive_intra_period; //!< reinitialize start of intra period
int start_frame; //!< Encode sequence starting from Frame start_frame int start_frame; //!< Encode sequence starting from Frame start_frame
int enable_32_pulldown; int enable_32_pulldown;
@ -103,77 +119,109 @@ struct inp_par_enc
int ResendSPS; int ResendSPS;
int ResendPPS; int ResendPPS;
int SendAUD; //!< send Access Unit Delimiter NALU int SendAUD; //!< send Access Unit Delimiter NALU
int skip_gl_stats; int skip_gl_stats;
// B pictures // B pictures
int NumberBFrames; //!< number of B frames that will be used int NumberBFrames; //!< number of B frames that will be used
int PReplaceBSlice; int PReplaceBSlice;
int qpBRSOffset; //!< QP for reference B slice coded pictures int qpBRSOffset; //!< QP for reference B slice coded pictures
int direct_spatial_mv_pred_flag; //!< Direct Mode type to be used (0: Temporal, 1: Spatial) int direct_spatial_mv_pred_flag; //!< Direct Mode type to be used (0:
int directInferenceFlag; //!< Direct Mode Inference Flag //!< Temporal, 1: Spatial)
int directInferenceFlag; //!< Direct Mode Inference Flag
int BiPredMotionEstimation; //!< Use of Bipredictive motion estimation int BiPredMotionEstimation; //!< Use of Bipredictive motion estimation
int BiPredSearch[4]; //!< Bipredictive motion estimation for modes 16x16, 16x8, 8x16, and 8x8 int BiPredSearch[4]; //!< Bipredictive motion estimation for modes 16x16,
int BiPredMERefinements; //!< Max number of Iterations for Bi-predictive motion estimation //!< 16x8, 8x16, and 8x8
int BiPredMESearchRange; //!< Search range of Bi-predictive motion estimation int BiPredMERefinements; //!< Max number of Iterations for Bi-predictive
int BiPredMESubPel; //!< Use of subpixel refinement for Bi-predictive motion estimation //!< motion estimation
int BiPredMESearchRange; //!< Search range of Bi-predictive motion estimation
int BiPredMESubPel; //!< Use of subpixel refinement for Bi-predictive motion
//!< estimation
// SP/SI Pictures // SP/SI Pictures
int sp_periodicity; //!< The periodicity of SP-pictures int sp_periodicity; //!< The periodicity of SP-pictures
int sp_switch_period; //!< Switch period (in terms of switching SP/SI frames) between bitstream 1 and bitstream 2 int sp_switch_period; //!< Switch period (in terms of switching SP/SI frames)
int si_frame_indicator; //!< Flag indicating whether SI frames should be encoded rather than SP frames (0: not used, 1: used) //!< between bitstream 1 and bitstream 2
int sp2_frame_indicator; //!< Flag indicating whether switching SP frames should be encoded rather than SP frames (0: not used, 1: used) int si_frame_indicator; //!< Flag indicating whether SI frames should be
int sp_output_indicator; //!< Flag indicating whether coefficients are output to allow future encoding of switchin SP frames (0: not used, 1: used) //!< encoded rather than SP frames (0: not used, 1:
signed char sp_output_filename[FILE_NAME_SIZE]; //!<Filename where SP coefficients are output //!< used)
signed char sp2_input_filename1[FILE_NAME_SIZE]; //!<Filename of coefficients of the first bitstream when encoding SP frames to switch bitstreams int sp2_frame_indicator; //!< Flag indicating whether switching SP frames
signed char sp2_input_filename2[FILE_NAME_SIZE]; //!<Filenames of coefficients of the second bitstream when encoding SP frames to switch bitstreams //!< should be encoded rather than SP frames (0: not
//!< used, 1: used)
int sp_output_indicator; //!< Flag indicating whether coefficients are output
//!< to allow future encoding of switchin SP frames
//!< (0: not used, 1: used)
signed char sp_output_filename[FILE_NAME_SIZE]; //!< Filename where SP
//!< coefficients are output
signed char
sp2_input_filename1[FILE_NAME_SIZE]; //!< Filename of coefficients of the
//!< first bitstream when encoding SP
//!< frames to switch bitstreams
signed char
sp2_input_filename2[FILE_NAME_SIZE]; //!< Filenames of coefficients of the
//!< second bitstream when encoding
//!< SP frames to switch bitstreams
// Weighted Prediction // Weighted Prediction
int WeightedPrediction; //!< Weighted prediction for P frames (0: not used, 1: explicit) int WeightedPrediction; //!< Weighted prediction for P frames (0: not used, 1:
int WeightedBiprediction; //!< Weighted prediction for B frames (0: not used, 1: explicit, 2: implicit) //!< explicit)
int WPMethod; //!< WP method (0: DC, 1: LMS) int WeightedBiprediction; //!< Weighted prediction for B frames (0: not used,
int WPIterMC; //!< Iterative WP method //!< 1: explicit, 2: implicit)
int WPMethod; //!< WP method (0: DC, 1: LMS)
int WPIterMC; //!< Iterative WP method
int WPMCPrecision; int WPMCPrecision;
int WPMCPrecFullRef; int WPMCPrecFullRef;
int WPMCPrecBSlice; int WPMCPrecBSlice;
int EnhancedBWeightSupport; int EnhancedBWeightSupport;
int ChromaWeightSupport; //!< Weighted prediction support for chroma (0: disabled, 1: enabled) int ChromaWeightSupport; //!< Weighted prediction support for chroma (0:
int UseWeightedReferenceME; //!< Use Weighted Reference for ME. //!< disabled, 1: enabled)
int RDPictureDecision; //!< Perform RD optimal decision between various coded versions of same picture int UseWeightedReferenceME; //!< Use Weighted Reference for ME.
int RDPSliceBTest; //!< Tests B slice replacement for P. int RDPictureDecision; //!< Perform RD optimal decision between various coded
int RDPSliceITest; //!< Tests I slice replacement for P. //!< versions of same picture
int RDPictureMaxPassISlice; //!< Max # of coding passes for I-slice int RDPSliceBTest; //!< Tests B slice replacement for P.
int RDPictureMaxPassPSlice; //!< Max # of coding passes for P-slice int RDPSliceITest; //!< Tests I slice replacement for P.
int RDPictureMaxPassBSlice; //!< Max # of coding passes for B-slice int RDPictureMaxPassISlice; //!< Max # of coding passes for I-slice
int RDPictureDeblocking; //!< Whether to choose between deblocked and non-deblocked picture int RDPictureMaxPassPSlice; //!< Max # of coding passes for P-slice
int RDPictureDirectMode; //!< Whether to check the other direct mode for B slices int RDPictureMaxPassBSlice; //!< Max # of coding passes for B-slice
int RDPictureFrameQPPSlice; //!< Whether to check additional frame level QP values for P slices int RDPictureDeblocking; //!< Whether to choose between deblocked and
int RDPictureFrameQPBSlice; //!< Whether to check additional frame level QP values for B slices //!< non-deblocked picture
int RDPictureDirectMode; //!< Whether to check the other direct mode for B
//!< slices
int RDPictureFrameQPPSlice; //!< Whether to check additional frame level QP
//!< values for P slices
int RDPictureFrameQPBSlice; //!< Whether to check additional frame level QP
//!< values for B slices
int SkipIntraInInterSlices; //!< Skip intra type checking in inter slices if best_mode is skip/direct int SkipIntraInInterSlices; //!< Skip intra type checking in inter slices if
int BRefPictures; //!< B coded reference pictures replace P pictures (0: not used, 1: used) //!< best_mode is skip/direct
int BRefPictures; //!< B coded reference pictures replace P pictures (0: not
//!< used, 1: used)
int HierarchicalCoding; int HierarchicalCoding;
int HierarchyLevelQPEnable; int HierarchyLevelQPEnable;
signed char ExplicitHierarchyFormat[INPUT_TEXT_SIZE]; //!< Explicit GOP format (HierarchicalCoding==3). signed char
ExplicitHierarchyFormat[INPUT_TEXT_SIZE]; //!< Explicit GOP format
//!< (HierarchicalCoding==3).
// explicit sequence information parameters // explicit sequence information parameters
int ExplicitSeqCoding; int ExplicitSeqCoding;
signed char ExplicitSeqFile[FILE_NAME_SIZE]; signed char ExplicitSeqFile[FILE_NAME_SIZE];
int LowDelay; //!< Apply HierarchicalCoding without delay (i.e., encode in the captured/display order) int LowDelay; //!< Apply HierarchicalCoding without delay (i.e., encode in the
//!< captured/display order)
int ReferenceReorder; //!< Reordering based on Poc distances int ReferenceReorder; //!< Reordering based on Poc distances
int PocMemoryManagement; //!< Memory management based on Poc distances for hierarchical coding int PocMemoryManagement; //!< Memory management based on Poc distances for
//!< hierarchical coding
int symbol_mode; //!< Specifies the mode the symbols are mapped on bits int symbol_mode; //!< Specifies the mode the symbols are mapped on bits
int of_mode; //!< Specifies the mode of the output file int of_mode; //!< Specifies the mode of the output file
int partition_mode; //!< Specifies the mode of data partitioning int partition_mode; //!< Specifies the mode of data partitioning
int InterSearch[2][8]; int InterSearch[2][8];
int DisableIntra4x4; int DisableIntra4x4;
int DisableIntra16x16; int DisableIntra16x16;
int FastMDEnable; int FastMDEnable;
int FastIntraMD; int FastIntraMD;
int FastIntra4x4; int FastIntra4x4;
int FastIntra16x16; int FastIntra16x16;
int FastIntra8x8; int FastIntra8x8;
@ -196,14 +244,14 @@ struct inp_par_enc
int full_search; int full_search;
int rdopt; int rdopt;
int de; //!< the algorithm to estimate the distortion in the decoder int de; //!< the algorithm to estimate the distortion in the decoder
int I16rdo; int I16rdo;
int subMBCodingState; int subMBCodingState;
int Distortion[TOTAL_DIST_TYPES]; int Distortion[TOTAL_DIST_TYPES];
double VisualResWavPSNR; double VisualResWavPSNR;
int SSIMOverlapSize; int SSIMOverlapSize;
int DistortionYUVtoRGB; int DistortionYUVtoRGB;
int CtxAdptLagrangeMult; //!< context adaptive lagrangian multiplier int CtxAdptLagrangeMult; //!< context adaptive lagrangian multiplier
int FastCrIntraDecision; int FastCrIntraDecision;
int disthres; int disthres;
int nobskip; int nobskip;
@ -211,26 +259,32 @@ struct inp_par_enc
int ForceTrueRateRDO; int ForceTrueRateRDO;
#ifdef _LEAKYBUCKET_ #ifdef _LEAKYBUCKET_
int NumberLeakyBuckets; int NumberLeakyBuckets;
signed char LeakyBucketRateFile[FILE_NAME_SIZE]; signed char LeakyBucketRateFile[FILE_NAME_SIZE];
signed char LeakyBucketParamFile[FILE_NAME_SIZE]; signed char LeakyBucketParamFile[FILE_NAME_SIZE];
#endif #endif
int PicInterlace; //!< picture adaptive frame/field int PicInterlace; //!< picture adaptive frame/field
int MbInterlace; //!< macroblock adaptive frame/field int MbInterlace; //!< macroblock adaptive frame/field
int IntraBottom; //!< Force Intra Bottom at GOP periods. int IntraBottom; //!< Force Intra Bottom at GOP periods.
// Error resilient RDO parameters // Error resilient RDO parameters
double LossRateA; //!< assumed loss probablility of partition A (or full slice), in per cent, used for loss-aware R/D optimization double
double LossRateB; //!< assumed loss probablility of partition B, in per cent, used for loss-aware R/D LossRateA; //!< assumed loss probablility of partition A (or full slice),
double LossRateC; //!< assumed loss probablility of partition C, in per cent, used for loss-aware R/D //!< in per cent, used for loss-aware R/D optimization
int FirstFrameCorrect; //!< the first frame is encoded under the assumption that it is always correctly received. double LossRateB; //!< assumed loss probablility of partition B, in per cent,
//!< used for loss-aware R/D
double LossRateC; //!< assumed loss probablility of partition C, in per cent,
//!< used for loss-aware R/D
int FirstFrameCorrect; //!< the first frame is encoded under the assumption
//!< that it is always correctly received.
int NoOfDecoders; int NoOfDecoders;
int ErrorConcealment; //!< Error concealment method used for loss-aware RDO (0: Copy Concealment) int ErrorConcealment; //!< Error concealment method used for loss-aware RDO
//!< (0: Copy Concealment)
int RestrictRef; int RestrictRef;
int NumFramesInELSubSeq; int NumFramesInELSubSeq;
int RandomIntraMBRefresh; //!< Number of pseudo-random intra-MBs per picture int RandomIntraMBRefresh; //!< Number of pseudo-random intra-MBs per picture
// Chroma interpolation and buffering // Chroma interpolation and buffering
int ChromaMCBuffer; int ChromaMCBuffer;
@ -239,33 +293,38 @@ struct inp_par_enc
int MEErrorMetric[3]; int MEErrorMetric[3];
int ModeDecisionMetric; int ModeDecisionMetric;
int SkipDeBlockNonRef; int SkipDeBlockNonRef;
// Deblocking Filter parameters // Deblocking Filter parameters
int DFSendParameters; int DFSendParameters;
int DFDisableIdc[2][NUM_SLICE_TYPES]; int DFDisableIdc[2][NUM_SLICE_TYPES];
int DFAlpha [2][NUM_SLICE_TYPES]; int DFAlpha[2][NUM_SLICE_TYPES];
int DFBeta [2][NUM_SLICE_TYPES]; int DFBeta[2][NUM_SLICE_TYPES];
int SparePictureOption; int SparePictureOption;
int SPDetectionThreshold; int SPDetectionThreshold;
int SPPercentageThreshold; int SPPercentageThreshold;
// FMO // FMO
signed char SliceGroupConfigFileName[FILE_NAME_SIZE]; //!< Filename for config info fot type 0, 2, 6 signed char
int num_slice_groups_minus1; //!< "FmoNumSliceGroups" in encoder.cfg, same as FmoNumSliceGroups, which should be erased later SliceGroupConfigFileName[FILE_NAME_SIZE]; //!< Filename for config info
//!< fot type 0, 2, 6
int num_slice_groups_minus1; //!< "FmoNumSliceGroups" in encoder.cfg, same as
//!< FmoNumSliceGroups, which should be erased
//!< later
int slice_group_map_type; int slice_group_map_type;
unsigned int *top_left; //!< top_left and bottom_right store values indicating foregrounds unsigned int *top_left; //!< top_left and bottom_right store values indicating
//!< foregrounds
unsigned int *bottom_right; unsigned int *bottom_right;
byte *slice_group_id; //!< slice_group_id is for slice group type being 6 byte *slice_group_id; //!< slice_group_id is for slice group type being 6
int *run_length_minus1; //!< run_length_minus1 is for slice group type being 0 int *run_length_minus1; //!< run_length_minus1 is for slice group type being 0
int slice_group_change_direction_flag; int slice_group_change_direction_flag;
int slice_group_change_rate_minus1; int slice_group_change_rate_minus1;
int slice_group_change_cycle; int slice_group_change_cycle;
int redundant_pic_flag; //! encoding of redundant pictures int redundant_pic_flag; //! encoding of redundant pictures
int pic_order_cnt_type; //! POC type int pic_order_cnt_type; //! POC type
int context_init_method; int context_init_method;
int model_number; int model_number;
@ -285,18 +344,18 @@ struct inp_par_enc
double RCBoverPRatio; double RCBoverPRatio;
double RCISliceBitRatio; double RCISliceBitRatio;
double RCBSliceBitRatio[RC_MAX_TEMPORAL_LEVELS]; double RCBSliceBitRatio[RC_MAX_TEMPORAL_LEVELS];
int RCMinQP[NUM_SLICE_TYPES]; int RCMinQP[NUM_SLICE_TYPES];
int RCMaxQP[NUM_SLICE_TYPES]; int RCMaxQP[NUM_SLICE_TYPES];
int RCMaxQPChange; int RCMaxQPChange;
// Motion Estimation related parameters // Motion Estimation related parameters
int UseMVLimits; int UseMVLimits;
int SetMVXLimit; int SetMVXLimit;
int SetMVYLimit; int SetMVYLimit;
// Search Algorithm // Search Algorithm
SearchType SearchMode; SearchType SearchMode;
// UMHEX related parameters // UMHEX related parameters
int UMHexDSR; int UMHexDSR;
int UMHexScale; int UMHexScale;
@ -322,17 +381,22 @@ struct inp_par_enc
double LambdaWeight[6]; double LambdaWeight[6];
double FixedLambda[6]; double FixedLambda[6];
signed char QOffsetMatrixFile[FILE_NAME_SIZE]; //!< Quantization Offset matrix cfg file signed char QOffsetMatrixFile[FILE_NAME_SIZE]; //!< Quantization Offset matrix
int OffsetMatrixPresentFlag; //!< Enable Explicit Quantization Offset Matrices //!< cfg file
int OffsetMatrixPresentFlag; //!< Enable Explicit Quantization Offset Matrices
int AdaptiveRounding; //!< Adaptive Rounding parameter based on JVT-N011 int AdaptiveRounding; //!< Adaptive Rounding parameter based on JVT-N011
int AdaptRoundingFixed; //!< Global rounding for all qps int AdaptRoundingFixed; //!< Global rounding for all qps
int AdaptRndPeriod; //!< Set period for adaptive rounding of JVT-N011 in MBs int AdaptRndPeriod; //!< Set period for adaptive rounding of JVT-N011 in MBs
int AdaptRndChroma; int AdaptRndChroma;
int AdaptRndWFactor [2][NUM_SLICE_TYPES]; //!< Weighting factors for luma component based on reference indicator and slice type int AdaptRndWFactor[2][NUM_SLICE_TYPES]; //!< Weighting factors for luma
int AdaptRndCrWFactor[2][NUM_SLICE_TYPES]; //!< Weighting factors for chroma components based on reference indicator and slice type //!< component based on reference
//!< indicator and slice type
int AdaptRndCrWFactor[2][NUM_SLICE_TYPES]; //!< Weighting factors for chroma
//!< components based on reference
//!< indicator and slice type
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Fidelity Range Extensions // Fidelity Range Extensions
int ScalingMatrixPresentFlag; int ScalingMatrixPresentFlag;
int ScalingListPresentFlag[12]; int ScalingListPresentFlag[12];
@ -348,19 +412,24 @@ struct inp_par_enc
int DisposableP; int DisposableP;
int DispPQPOffset; int DispPQPOffset;
//Redundant picture // Redundant picture
int NumRedundantHierarchy; //!< number of entries to allocate redundant pictures in a GOP int NumRedundantHierarchy; //!< number of entries to allocate redundant
int PrimaryGOPLength; //!< GOP length of primary pictures //!< pictures in a GOP
int NumRefPrimary; //!< number of reference frames for primary picture int PrimaryGOPLength; //!< GOP length of primary pictures
int NumRefPrimary; //!< number of reference frames for primary picture
// tone mapping SEI message // tone mapping SEI message
int ToneMappingSEIPresentFlag; int ToneMappingSEIPresentFlag;
signed char ToneMappingFile[FILE_NAME_SIZE]; //!< ToneMapping SEI message cfg file signed char
ToneMappingFile[FILE_NAME_SIZE]; //!< ToneMapping SEI message cfg file
// prediction structure // prediction structure
int PreferDispOrder; //!< Prefer display order when building the prediction structure as opposed to coding order int PreferDispOrder; //!< Prefer display order when building the prediction
int PreferPowerOfTwo; //!< Prefer prediction structures that have lengths expressed as powers of two //!< structure as opposed to coding order
int FrmStructBufferLength; //!< Number of frames that is populated every time populate_frm_struct is called int PreferPowerOfTwo; //!< Prefer prediction structures that have lengths
//!< expressed as powers of two
int FrmStructBufferLength; //!< Number of frames that is populated every time
//!< populate_frm_struct is called
int separate_colour_plane_flag; int separate_colour_plane_flag;
double WeightY; double WeightY;
@ -369,7 +438,7 @@ struct inp_par_enc
int UseRDOQuant; int UseRDOQuant;
int RDOQ_DC; int RDOQ_DC;
int RDOQ_CR; int RDOQ_CR;
int RDOQ_DC_CR; int RDOQ_DC_CR;
int RDOQ_QP_Num; int RDOQ_QP_Num;
int RDOQ_CP_Mode; int RDOQ_CP_Mode;
int RDOQ_CP_MV; int RDOQ_CP_MV;
@ -380,10 +449,9 @@ struct inp_par_enc
VUIParameters VUI; VUIParameters VUI;
// end of VUI parameters // end of VUI parameters
int MinIDRDistance; int MinIDRDistance;
int stdRange; //!< 1 - standard range, 0 - full range int stdRange; //!< 1 - standard range, 0 - full range
int videoCode; //!< 1 - 709, 3 - 601: See VideoCode in io_tiff. int videoCode; //!< 1 - 709, 3 - 601: See VideoCode in io_tiff.
}; };
#endif #endif

View file

@ -5,63 +5,70 @@
* parset.h * parset.h
* \brief * \brief
* Picture and Sequence Parameter Sets, decoder operations * Picture and Sequence Parameter Sets, decoder operations
* *
* \date 25 November 2002 * \date 25 November 2002
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
*************************************************************************************** ***************************************************************************************
*/ */
#ifndef _PARSET_H_ #ifndef _PARSET_H_
#define _PARSET_H_ #define _PARSET_H_
#include "parsetcommon.h"
#include "nalucommon.h" #include "nalucommon.h"
#include "parsetcommon.h"
static const byte ZZ_SCAN[16] = static const byte ZZ_SCAN[16] = {0, 1, 4, 8, 5, 2, 3, 6,
{ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 9, 12, 13, 10, 7, 11, 14, 15};
};
static const byte ZZ_SCAN8[64] = static const byte ZZ_SCAN8[64] = {
{ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63};
};
extern void Scaling_List(int *scalingList, int sizeOfScalingList, Boolean *UseDefaultScalingMatrix, Bitstream *s); extern void Scaling_List(int *scalingList, int sizeOfScalingList,
Boolean *UseDefaultScalingMatrix, Bitstream *s);
extern void InitVUI(seq_parameter_set_rbsp_t *sps); extern void InitVUI(seq_parameter_set_rbsp_t *sps);
extern int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps); extern int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps);
extern int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd); extern int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd);
extern void PPSConsistencyCheck (pic_parameter_set_rbsp_t *pps); extern void PPSConsistencyCheck(pic_parameter_set_rbsp_t *pps);
extern void SPSConsistencyCheck (seq_parameter_set_rbsp_t *sps); extern void SPSConsistencyCheck(seq_parameter_set_rbsp_t *sps);
extern void MakePPSavailable (VideoParameters *p_Vid, int id, pic_parameter_set_rbsp_t *pps); extern void MakePPSavailable(VideoParameters *p_Vid, int id,
extern void MakeSPSavailable (VideoParameters *p_Vid, int id, seq_parameter_set_rbsp_t *sps); pic_parameter_set_rbsp_t *pps);
extern void MakeSPSavailable(VideoParameters *p_Vid, int id,
seq_parameter_set_rbsp_t *sps);
extern void ProcessSPS (VideoParameters *p_Vid, NALU_t *nalu); extern void ProcessSPS(VideoParameters *p_Vid, NALU_t *nalu);
extern void ProcessPPS (VideoParameters *p_Vid, NALU_t *nalu); extern void ProcessPPS(VideoParameters *p_Vid, NALU_t *nalu);
extern void CleanUpPPS(VideoParameters *p_Vid); extern void CleanUpPPS(VideoParameters *p_Vid);
extern void activate_sps (VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps); extern void activate_sps(VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps);
extern void activate_pps (VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps); extern void activate_pps(VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps);
extern void UseParameterSet (Slice *currSlice); extern void UseParameterSet(Slice *currSlice);
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
extern void SubsetSPSConsistencyCheck (subset_seq_parameter_set_rbsp_t *subset_sps); extern void
extern void ProcessSubsetSPS (VideoParameters *p_Vid, NALU_t *nalu); SubsetSPSConsistencyCheck(subset_seq_parameter_set_rbsp_t *subset_sps);
extern void ProcessSubsetSPS(VideoParameters *p_Vid, NALU_t *nalu);
extern void mvc_vui_parameters_extension(MVCVUI_t *pMVCVUI, Bitstream *s); extern void mvc_vui_parameters_extension(MVCVUI_t *pMVCVUI, Bitstream *s);
extern void seq_parameter_set_mvc_extension(subset_seq_parameter_set_rbsp_t *subset_sps, Bitstream *s); extern void
extern void init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list, int iSize); seq_parameter_set_mvc_extension(subset_seq_parameter_set_rbsp_t *subset_sps,
Bitstream *s);
extern void
init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list,
int iSize);
extern void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps); extern void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps);
extern int GetBaseViewId(VideoParameters *p_Vid, subset_seq_parameter_set_rbsp_t **subset_sps); extern int GetBaseViewId(VideoParameters *p_Vid,
subset_seq_parameter_set_rbsp_t **subset_sps);
extern void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps); extern void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps);
#endif #endif

View file

@ -4,17 +4,17 @@
* \file * \file
* parsetcommon.h * parsetcommon.h
* \brief * \brief
* Picture and Sequence Parameter Sets, structures common to encoder and decoder * Picture and Sequence Parameter Sets, structures common to encoder and
*decoder
* *
* \date 25 November 2002 * \date 25 November 2002
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de> * - Stephan Wenger <stewe@cs.tu-berlin.de>
*************************************************************************************** ***************************************************************************************
*/ */
// In the JVT syntax, frequently flags are used that indicate the presence of // In the JVT syntax, frequently flags are used that indicate the presence of
// certain pieces of information in the NALU. Here, these flags are also // certain pieces of information in the NALU. Here, these flags are also
// present. In the encoder, those bits indicate that the values signaled to // present. In the encoder, those bits indicate that the values signaled to
@ -28,205 +28,196 @@
#include "defines.h" #include "defines.h"
#define MAXIMUMPARSETRBSPSIZE 1500 #define MAXIMUMPARSETRBSPSIZE 1500
#define MAXIMUMPARSETNALUSIZE 1500 #define MAXIMUMPARSETNALUSIZE 1500
#define MAXSPS 32 #define MAXSPS 32
#define MAXPPS 256 #define MAXPPS 256
#define MAXIMUMVALUEOFcpb_cnt 32 #define MAXIMUMVALUEOFcpb_cnt 32
typedef struct typedef struct {
{ unsigned int cpb_cnt_minus1; // ue(v)
unsigned int cpb_cnt_minus1; // ue(v) unsigned int bit_rate_scale; // u(4)
unsigned int bit_rate_scale; // u(4) unsigned int cpb_size_scale; // u(4)
unsigned int cpb_size_scale; // u(4) unsigned int bit_rate_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v)
unsigned int bit_rate_value_minus1 [MAXIMUMVALUEOFcpb_cnt]; // ue(v) unsigned int cpb_size_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v)
unsigned int cpb_size_value_minus1 [MAXIMUMVALUEOFcpb_cnt]; // ue(v) unsigned int cbr_flag[MAXIMUMVALUEOFcpb_cnt]; // u(1)
unsigned int cbr_flag [MAXIMUMVALUEOFcpb_cnt]; // u(1) unsigned int initial_cpb_removal_delay_length_minus1; // u(5)
unsigned int initial_cpb_removal_delay_length_minus1; // u(5) unsigned int cpb_removal_delay_length_minus1; // u(5)
unsigned int cpb_removal_delay_length_minus1; // u(5) unsigned int dpb_output_delay_length_minus1; // u(5)
unsigned int dpb_output_delay_length_minus1; // u(5) unsigned int time_offset_length; // u(5)
unsigned int time_offset_length; // u(5)
} hrd_parameters_t; } hrd_parameters_t;
typedef struct {
typedef struct Boolean aspect_ratio_info_present_flag; // u(1)
{ unsigned int aspect_ratio_idc; // u(8)
Boolean aspect_ratio_info_present_flag; // u(1) unsigned short sar_width; // u(16)
unsigned int aspect_ratio_idc; // u(8) unsigned short sar_height; // u(16)
unsigned short sar_width; // u(16) Boolean overscan_info_present_flag; // u(1)
unsigned short sar_height; // u(16) Boolean overscan_appropriate_flag; // u(1)
Boolean overscan_info_present_flag; // u(1) Boolean video_signal_type_present_flag; // u(1)
Boolean overscan_appropriate_flag; // u(1) unsigned int video_format; // u(3)
Boolean video_signal_type_present_flag; // u(1) Boolean video_full_range_flag; // u(1)
unsigned int video_format; // u(3) Boolean colour_description_present_flag; // u(1)
Boolean video_full_range_flag; // u(1) unsigned int colour_primaries; // u(8)
Boolean colour_description_present_flag; // u(1) unsigned int transfer_characteristics; // u(8)
unsigned int colour_primaries; // u(8) unsigned int matrix_coefficients; // u(8)
unsigned int transfer_characteristics; // u(8) Boolean chroma_location_info_present_flag; // u(1)
unsigned int matrix_coefficients; // u(8) unsigned int chroma_sample_loc_type_top_field; // ue(v)
Boolean chroma_location_info_present_flag; // u(1) unsigned int chroma_sample_loc_type_bottom_field; // ue(v)
unsigned int chroma_sample_loc_type_top_field; // ue(v) Boolean timing_info_present_flag; // u(1)
unsigned int chroma_sample_loc_type_bottom_field; // ue(v) unsigned int num_units_in_tick; // u(32)
Boolean timing_info_present_flag; // u(1) unsigned int time_scale; // u(32)
unsigned int num_units_in_tick; // u(32) Boolean fixed_frame_rate_flag; // u(1)
unsigned int time_scale; // u(32) Boolean nal_hrd_parameters_present_flag; // u(1)
Boolean fixed_frame_rate_flag; // u(1) hrd_parameters_t nal_hrd_parameters; // hrd_paramters_t
Boolean nal_hrd_parameters_present_flag; // u(1) Boolean vcl_hrd_parameters_present_flag; // u(1)
hrd_parameters_t nal_hrd_parameters; // hrd_paramters_t hrd_parameters_t vcl_hrd_parameters; // hrd_paramters_t
Boolean vcl_hrd_parameters_present_flag; // u(1)
hrd_parameters_t vcl_hrd_parameters; // hrd_paramters_t
// if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag)) // if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag))
Boolean low_delay_hrd_flag; // u(1) Boolean low_delay_hrd_flag; // u(1)
Boolean pic_struct_present_flag; // u(1) Boolean pic_struct_present_flag; // u(1)
Boolean bitstream_restriction_flag; // u(1) Boolean bitstream_restriction_flag; // u(1)
Boolean motion_vectors_over_pic_boundaries_flag; // u(1) Boolean motion_vectors_over_pic_boundaries_flag; // u(1)
unsigned int max_bytes_per_pic_denom; // ue(v) unsigned int max_bytes_per_pic_denom; // ue(v)
unsigned int max_bits_per_mb_denom; // ue(v) unsigned int max_bits_per_mb_denom; // ue(v)
unsigned int log2_max_mv_length_vertical; // ue(v) unsigned int log2_max_mv_length_vertical; // ue(v)
unsigned int log2_max_mv_length_horizontal; // ue(v) unsigned int log2_max_mv_length_horizontal; // ue(v)
unsigned int num_reorder_frames; // ue(v) unsigned int num_reorder_frames; // ue(v)
unsigned int max_dec_frame_buffering; // ue(v) unsigned int max_dec_frame_buffering; // ue(v)
} vui_seq_parameters_t; } vui_seq_parameters_t;
#define MAXnum_slice_groups_minus1 8
typedef struct {
Boolean Valid; // indicates the parameter set is valid
unsigned int pic_parameter_set_id; // ue(v)
unsigned int seq_parameter_set_id; // ue(v)
Boolean entropy_coding_mode_flag; // u(1)
Boolean transform_8x8_mode_flag; // u(1)
#define MAXnum_slice_groups_minus1 8 Boolean pic_scaling_matrix_present_flag; // u(1)
typedef struct int pic_scaling_list_present_flag[12]; // u(1)
{ int ScalingList4x4[6][16]; // se(v)
Boolean Valid; // indicates the parameter set is valid int ScalingList8x8[6][64]; // se(v)
unsigned int pic_parameter_set_id; // ue(v) Boolean UseDefaultScalingMatrix4x4Flag[6];
unsigned int seq_parameter_set_id; // ue(v) Boolean UseDefaultScalingMatrix8x8Flag[6];
Boolean entropy_coding_mode_flag; // u(1)
Boolean transform_8x8_mode_flag; // u(1)
Boolean pic_scaling_matrix_present_flag; // u(1)
int pic_scaling_list_present_flag[12]; // u(1)
int ScalingList4x4[6][16]; // se(v)
int ScalingList8x8[6][64]; // se(v)
Boolean UseDefaultScalingMatrix4x4Flag[6];
Boolean UseDefaultScalingMatrix8x8Flag[6];
// if( pic_order_cnt_type < 2 ) in the sequence parameter set // if( pic_order_cnt_type < 2 ) in the sequence parameter set
Boolean bottom_field_pic_order_in_frame_present_flag; // u(1) Boolean bottom_field_pic_order_in_frame_present_flag; // u(1)
unsigned int num_slice_groups_minus1; // ue(v) unsigned int num_slice_groups_minus1; // ue(v)
unsigned int slice_group_map_type; // ue(v) unsigned int slice_group_map_type; // ue(v)
// if( slice_group_map_type = = 0 ) // if( slice_group_map_type = = 0 )
unsigned int run_length_minus1[MAXnum_slice_groups_minus1]; // ue(v) unsigned int run_length_minus1[MAXnum_slice_groups_minus1]; // ue(v)
// else if( slice_group_map_type = = 2 ) // else if( slice_group_map_type = = 2 )
unsigned int top_left[MAXnum_slice_groups_minus1]; // ue(v) unsigned int top_left[MAXnum_slice_groups_minus1]; // ue(v)
unsigned int bottom_right[MAXnum_slice_groups_minus1]; // ue(v) unsigned int bottom_right[MAXnum_slice_groups_minus1]; // ue(v)
// else if( slice_group_map_type = = 3 || 4 || 5 // else if( slice_group_map_type = = 3 || 4 || 5
Boolean slice_group_change_direction_flag; // u(1) Boolean slice_group_change_direction_flag; // u(1)
unsigned int slice_group_change_rate_minus1; // ue(v) unsigned int slice_group_change_rate_minus1; // ue(v)
// else if( slice_group_map_type = = 6 ) // else if( slice_group_map_type = = 6 )
unsigned int pic_size_in_map_units_minus1; // ue(v) unsigned int pic_size_in_map_units_minus1; // ue(v)
byte *slice_group_id; // complete MBAmap u(v) byte *slice_group_id; // complete MBAmap u(v)
int num_ref_idx_l0_active_minus1; // ue(v) int num_ref_idx_l0_active_minus1; // ue(v)
int num_ref_idx_l1_active_minus1; // ue(v) int num_ref_idx_l1_active_minus1; // ue(v)
Boolean weighted_pred_flag; // u(1) Boolean weighted_pred_flag; // u(1)
unsigned int weighted_bipred_idc; // u(2) unsigned int weighted_bipred_idc; // u(2)
int pic_init_qp_minus26; // se(v) int pic_init_qp_minus26; // se(v)
int pic_init_qs_minus26; // se(v) int pic_init_qs_minus26; // se(v)
int chroma_qp_index_offset; // se(v) int chroma_qp_index_offset; // se(v)
int second_chroma_qp_index_offset; // se(v) int second_chroma_qp_index_offset; // se(v)
Boolean deblocking_filter_control_present_flag; // u(1) Boolean deblocking_filter_control_present_flag; // u(1)
Boolean constrained_intra_pred_flag; // u(1) Boolean constrained_intra_pred_flag; // u(1)
Boolean redundant_pic_cnt_present_flag; // u(1) Boolean redundant_pic_cnt_present_flag; // u(1)
} pic_parameter_set_rbsp_t; } pic_parameter_set_rbsp_t;
#define MAXnum_ref_frames_in_pic_order_cnt_cycle 256
typedef struct {
Boolean Valid; // indicates the parameter set is valid
#define MAXnum_ref_frames_in_pic_order_cnt_cycle 256 unsigned int profile_idc; // u(8)
typedef struct Boolean constrained_set0_flag; // u(1)
{ Boolean constrained_set1_flag; // u(1)
Boolean Valid; // indicates the parameter set is valid Boolean constrained_set2_flag; // u(1)
Boolean constrained_set3_flag; // u(1)
unsigned int profile_idc; // u(8)
Boolean constrained_set0_flag; // u(1)
Boolean constrained_set1_flag; // u(1)
Boolean constrained_set2_flag; // u(1)
Boolean constrained_set3_flag; // u(1)
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
Boolean constrained_set4_flag; // u(1) Boolean constrained_set4_flag; // u(1)
#endif #endif
unsigned int level_idc; // u(8) unsigned int level_idc; // u(8)
unsigned int seq_parameter_set_id; // ue(v) unsigned int seq_parameter_set_id; // ue(v)
unsigned int chroma_format_idc; // ue(v) unsigned int chroma_format_idc; // ue(v)
Boolean seq_scaling_matrix_present_flag; // u(1) Boolean seq_scaling_matrix_present_flag; // u(1)
int seq_scaling_list_present_flag[12]; // u(1) int seq_scaling_list_present_flag[12]; // u(1)
int ScalingList4x4[6][16]; // se(v) int ScalingList4x4[6][16]; // se(v)
int ScalingList8x8[6][64]; // se(v) int ScalingList8x8[6][64]; // se(v)
Boolean UseDefaultScalingMatrix4x4Flag[6]; Boolean UseDefaultScalingMatrix4x4Flag[6];
Boolean UseDefaultScalingMatrix8x8Flag[6]; Boolean UseDefaultScalingMatrix8x8Flag[6];
unsigned int bit_depth_luma_minus8; // ue(v) unsigned int bit_depth_luma_minus8; // ue(v)
unsigned int bit_depth_chroma_minus8; // ue(v) unsigned int bit_depth_chroma_minus8; // ue(v)
unsigned int log2_max_frame_num_minus4; // ue(v) unsigned int log2_max_frame_num_minus4; // ue(v)
unsigned int pic_order_cnt_type; unsigned int pic_order_cnt_type;
// if( pic_order_cnt_type == 0 ) // if( pic_order_cnt_type == 0 )
unsigned int log2_max_pic_order_cnt_lsb_minus4; // ue(v) unsigned int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
// else if( pic_order_cnt_type == 1 ) // else if( pic_order_cnt_type == 1 )
Boolean delta_pic_order_always_zero_flag; // u(1) Boolean delta_pic_order_always_zero_flag; // u(1)
int offset_for_non_ref_pic; // se(v) int offset_for_non_ref_pic; // se(v)
int offset_for_top_to_bottom_field; // se(v) int offset_for_top_to_bottom_field; // se(v)
unsigned int num_ref_frames_in_pic_order_cnt_cycle; // ue(v) unsigned int num_ref_frames_in_pic_order_cnt_cycle; // ue(v)
// for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) // for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ )
int offset_for_ref_frame[MAXnum_ref_frames_in_pic_order_cnt_cycle]; // se(v) int offset_for_ref_frame[MAXnum_ref_frames_in_pic_order_cnt_cycle]; // se(v)
unsigned int num_ref_frames; // ue(v) unsigned int num_ref_frames; // ue(v)
Boolean gaps_in_frame_num_value_allowed_flag; // u(1) Boolean gaps_in_frame_num_value_allowed_flag; // u(1)
unsigned int pic_width_in_mbs_minus1; // ue(v) unsigned int pic_width_in_mbs_minus1; // ue(v)
unsigned int pic_height_in_map_units_minus1; // ue(v) unsigned int pic_height_in_map_units_minus1; // ue(v)
Boolean frame_mbs_only_flag; // u(1) Boolean frame_mbs_only_flag; // u(1)
// if( !frame_mbs_only_flag ) // if( !frame_mbs_only_flag )
Boolean mb_adaptive_frame_field_flag; // u(1) Boolean mb_adaptive_frame_field_flag; // u(1)
Boolean direct_8x8_inference_flag; // u(1) Boolean direct_8x8_inference_flag; // u(1)
Boolean frame_cropping_flag; // u(1) Boolean frame_cropping_flag; // u(1)
unsigned int frame_cropping_rect_left_offset; // ue(v) unsigned int frame_cropping_rect_left_offset; // ue(v)
unsigned int frame_cropping_rect_right_offset; // ue(v) unsigned int frame_cropping_rect_right_offset; // ue(v)
unsigned int frame_cropping_rect_top_offset; // ue(v) unsigned int frame_cropping_rect_top_offset; // ue(v)
unsigned int frame_cropping_rect_bottom_offset; // ue(v) unsigned int frame_cropping_rect_bottom_offset; // ue(v)
Boolean vui_parameters_present_flag; // u(1) Boolean vui_parameters_present_flag; // u(1)
vui_seq_parameters_t vui_seq_parameters; // vui_seq_parameters_t vui_seq_parameters_t vui_seq_parameters; // vui_seq_parameters_t
unsigned separate_colour_plane_flag; // u(1) unsigned separate_colour_plane_flag; // u(1)
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
int max_dec_frame_buffering; int max_dec_frame_buffering;
#endif #endif
} seq_parameter_set_rbsp_t; } seq_parameter_set_rbsp_t;
#if (MVC_EXTENSION_ENABLE) #if (MVC_EXTENSION_ENABLE)
typedef struct mvcvui_tag typedef struct mvcvui_tag {
{ int num_ops_minus1;
int num_ops_minus1; signed char *temporal_id;
signed char *temporal_id; int *num_target_output_views_minus1;
int *num_target_output_views_minus1; int **view_id;
int **view_id; signed char *timing_info_present_flag;
signed char *timing_info_present_flag; int *num_units_in_tick;
int *num_units_in_tick; int *time_scale;
int *time_scale; signed char *fixed_frame_rate_flag;
signed char *fixed_frame_rate_flag; signed char *nal_hrd_parameters_present_flag;
signed char *nal_hrd_parameters_present_flag; signed char *vcl_hrd_parameters_present_flag;
signed char *vcl_hrd_parameters_present_flag; signed char *low_delay_hrd_flag;
signed char *low_delay_hrd_flag; signed char *pic_struct_present_flag;
signed char *pic_struct_present_flag;
//hrd parameters; // hrd parameters;
signed char cpb_cnt_minus1; signed char cpb_cnt_minus1;
signed char bit_rate_scale; signed char bit_rate_scale;
signed char cpb_size_scale; signed char cpb_size_scale;
int bit_rate_value_minus1[32]; int bit_rate_value_minus1[32];
int cpb_size_value_minus1[32]; int cpb_size_value_minus1[32];
signed char cbr_flag[32]; signed char cbr_flag[32];
signed char initial_cpb_removal_delay_length_minus1; signed char initial_cpb_removal_delay_length_minus1;
signed char cpb_removal_delay_length_minus1; signed char cpb_removal_delay_length_minus1;
signed char dpb_output_delay_length_minus1; signed char dpb_output_delay_length_minus1;
signed char time_offset_length; signed char time_offset_length;
}MVCVUI_t; } MVCVUI_t;
typedef struct typedef struct {
{
seq_parameter_set_rbsp_t sps; seq_parameter_set_rbsp_t sps;
unsigned int bit_equal_to_one; unsigned int bit_equal_to_one;
@ -241,7 +232,7 @@ typedef struct
int **non_anchor_ref_l0; int **non_anchor_ref_l0;
int *num_non_anchor_refs_l1; int *num_non_anchor_refs_l1;
int **non_anchor_ref_l1; int **non_anchor_ref_l1;
int num_level_values_signalled_minus1; int num_level_values_signalled_minus1;
int *level_idc; int *level_idc;
int *num_applicable_ops_minus1; int *num_applicable_ops_minus1;
@ -251,21 +242,23 @@ typedef struct
int **applicable_op_num_views_minus1; int **applicable_op_num_views_minus1;
unsigned int mvc_vui_parameters_present_flag; unsigned int mvc_vui_parameters_present_flag;
Boolean Valid; // indicates the parameter set is valid Boolean Valid; // indicates the parameter set is valid
MVCVUI_t MVCVUIParams; MVCVUI_t MVCVUIParams;
} subset_seq_parameter_set_rbsp_t; } subset_seq_parameter_set_rbsp_t;
subset_seq_parameter_set_rbsp_t *AllocSubsetSPS (void); subset_seq_parameter_set_rbsp_t *AllocSubsetSPS(void);
void FreeSubsetSPS (subset_seq_parameter_set_rbsp_t *subset_sps); void FreeSubsetSPS(subset_seq_parameter_set_rbsp_t *subset_sps);
#endif #endif
pic_parameter_set_rbsp_t *AllocPPS (void); pic_parameter_set_rbsp_t *AllocPPS(void);
seq_parameter_set_rbsp_t *AllocSPS (void); seq_parameter_set_rbsp_t *AllocSPS(void);
void FreePPS (pic_parameter_set_rbsp_t *pps); void FreePPS(pic_parameter_set_rbsp_t *pps);
void FreeSPS (seq_parameter_set_rbsp_t *sps); void FreeSPS(seq_parameter_set_rbsp_t *sps);
int sps_is_equal(seq_parameter_set_rbsp_t *sps1, seq_parameter_set_rbsp_t *sps2); int sps_is_equal(seq_parameter_set_rbsp_t *sps1,
int pps_is_equal(pic_parameter_set_rbsp_t *pps1, pic_parameter_set_rbsp_t *pps2); seq_parameter_set_rbsp_t *sps2);
int pps_is_equal(pic_parameter_set_rbsp_t *pps1,
pic_parameter_set_rbsp_t *pps2);
#endif #endif

View file

@ -15,155 +15,101 @@
#define _QUANT_H_ #define _QUANT_H_
// exported variables // exported variables
static const int dequant_coef8[6][8][8] = static const int dequant_coef8[6][8][8] = {{{20, 19, 25, 19, 20, 19, 25, 19},
{ {19, 18, 24, 18, 19, 18, 24, 18},
{ {25, 24, 32, 24, 25, 24, 32, 24},
{20, 19, 25, 19, 20, 19, 25, 19}, {19, 18, 24, 18, 19, 18, 24, 18},
{19, 18, 24, 18, 19, 18, 24, 18}, {20, 19, 25, 19, 20, 19, 25, 19},
{25, 24, 32, 24, 25, 24, 32, 24}, {19, 18, 24, 18, 19, 18, 24, 18},
{19, 18, 24, 18, 19, 18, 24, 18}, {25, 24, 32, 24, 25, 24, 32, 24},
{20, 19, 25, 19, 20, 19, 25, 19}, {19, 18, 24, 18, 19, 18, 24, 18}},
{19, 18, 24, 18, 19, 18, 24, 18}, {{22, 21, 28, 21, 22, 21, 28, 21},
{25, 24, 32, 24, 25, 24, 32, 24}, {21, 19, 26, 19, 21, 19, 26, 19},
{19, 18, 24, 18, 19, 18, 24, 18} {28, 26, 35, 26, 28, 26, 35, 26},
}, {21, 19, 26, 19, 21, 19, 26, 19},
{ {22, 21, 28, 21, 22, 21, 28, 21},
{22, 21, 28, 21, 22, 21, 28, 21}, {21, 19, 26, 19, 21, 19, 26, 19},
{21, 19, 26, 19, 21, 19, 26, 19}, {28, 26, 35, 26, 28, 26, 35, 26},
{28, 26, 35, 26, 28, 26, 35, 26}, {21, 19, 26, 19, 21, 19, 26, 19}},
{21, 19, 26, 19, 21, 19, 26, 19}, {{26, 24, 33, 24, 26, 24, 33, 24},
{22, 21, 28, 21, 22, 21, 28, 21}, {24, 23, 31, 23, 24, 23, 31, 23},
{21, 19, 26, 19, 21, 19, 26, 19}, {33, 31, 42, 31, 33, 31, 42, 31},
{28, 26, 35, 26, 28, 26, 35, 26}, {24, 23, 31, 23, 24, 23, 31, 23},
{21, 19, 26, 19, 21, 19, 26, 19} {26, 24, 33, 24, 26, 24, 33, 24},
}, {24, 23, 31, 23, 24, 23, 31, 23},
{ {33, 31, 42, 31, 33, 31, 42, 31},
{26, 24, 33, 24, 26, 24, 33, 24}, {24, 23, 31, 23, 24, 23, 31, 23}},
{24, 23, 31, 23, 24, 23, 31, 23}, {{28, 26, 35, 26, 28, 26, 35, 26},
{33, 31, 42, 31, 33, 31, 42, 31}, {26, 25, 33, 25, 26, 25, 33, 25},
{24, 23, 31, 23, 24, 23, 31, 23}, {35, 33, 45, 33, 35, 33, 45, 33},
{26, 24, 33, 24, 26, 24, 33, 24}, {26, 25, 33, 25, 26, 25, 33, 25},
{24, 23, 31, 23, 24, 23, 31, 23}, {28, 26, 35, 26, 28, 26, 35, 26},
{33, 31, 42, 31, 33, 31, 42, 31}, {26, 25, 33, 25, 26, 25, 33, 25},
{24, 23, 31, 23, 24, 23, 31, 23} {35, 33, 45, 33, 35, 33, 45, 33},
}, {26, 25, 33, 25, 26, 25, 33, 25}},
{ {{32, 30, 40, 30, 32, 30, 40, 30},
{28, 26, 35, 26, 28, 26, 35, 26}, {30, 28, 38, 28, 30, 28, 38, 28},
{26, 25, 33, 25, 26, 25, 33, 25}, {40, 38, 51, 38, 40, 38, 51, 38},
{35, 33, 45, 33, 35, 33, 45, 33}, {30, 28, 38, 28, 30, 28, 38, 28},
{26, 25, 33, 25, 26, 25, 33, 25}, {32, 30, 40, 30, 32, 30, 40, 30},
{28, 26, 35, 26, 28, 26, 35, 26}, {30, 28, 38, 28, 30, 28, 38, 28},
{26, 25, 33, 25, 26, 25, 33, 25}, {40, 38, 51, 38, 40, 38, 51, 38},
{35, 33, 45, 33, 35, 33, 45, 33}, {30, 28, 38, 28, 30, 28, 38, 28}},
{26, 25, 33, 25, 26, 25, 33, 25} {{36, 34, 46, 34, 36, 34, 46, 34},
}, {34, 32, 43, 32, 34, 32, 43, 32},
{ {46, 43, 58, 43, 46, 43, 58, 43},
{32, 30, 40, 30, 32, 30, 40, 30}, {34, 32, 43, 32, 34, 32, 43, 32},
{30, 28, 38, 28, 30, 28, 38, 28}, {36, 34, 46, 34, 36, 34, 46, 34},
{40, 38, 51, 38, 40, 38, 51, 38}, {34, 32, 43, 32, 34, 32, 43, 32},
{30, 28, 38, 28, 30, 28, 38, 28}, {46, 43, 58, 43, 46, 43, 58, 43},
{32, 30, 40, 30, 32, 30, 40, 30}, {34, 32, 43, 32, 34, 32, 43, 32}}};
{30, 28, 38, 28, 30, 28, 38, 28},
{40, 38, 51, 38, 40, 38, 51, 38},
{30, 28, 38, 28, 30, 28, 38, 28}
},
{
{36, 34, 46, 34, 36, 34, 46, 34},
{34, 32, 43, 32, 34, 32, 43, 32},
{46, 43, 58, 43, 46, 43, 58, 43},
{34, 32, 43, 32, 34, 32, 43, 32},
{36, 34, 46, 34, 36, 34, 46, 34},
{34, 32, 43, 32, 34, 32, 43, 32},
{46, 43, 58, 43, 46, 43, 58, 43},
{34, 32, 43, 32, 34, 32, 43, 32}
}
};
//! Dequantization coefficients //! Dequantization coefficients
static const int dequant_coef[6][4][4] = { static const int dequant_coef[6][4][4] = {
{ {{10, 13, 10, 13}, {13, 16, 13, 16}, {10, 13, 10, 13}, {13, 16, 13, 16}},
{ 10, 13, 10, 13}, {{11, 14, 11, 14}, {14, 18, 14, 18}, {11, 14, 11, 14}, {14, 18, 14, 18}},
{ 13, 16, 13, 16}, {{13, 16, 13, 16}, {16, 20, 16, 20}, {13, 16, 13, 16}, {16, 20, 16, 20}},
{ 10, 13, 10, 13}, {{14, 18, 14, 18}, {18, 23, 18, 23}, {14, 18, 14, 18}, {18, 23, 18, 23}},
{ 13, 16, 13, 16}}, {{16, 20, 16, 20}, {20, 25, 20, 25}, {16, 20, 16, 20}, {20, 25, 20, 25}},
{ {{18, 23, 18, 23}, {23, 29, 23, 29}, {18, 23, 18, 23}, {23, 29, 23, 29}}};
{ 11, 14, 11, 14},
{ 14, 18, 14, 18},
{ 11, 14, 11, 14},
{ 14, 18, 14, 18}},
{
{ 13, 16, 13, 16},
{ 16, 20, 16, 20},
{ 13, 16, 13, 16},
{ 16, 20, 16, 20}},
{
{ 14, 18, 14, 18},
{ 18, 23, 18, 23},
{ 14, 18, 14, 18},
{ 18, 23, 18, 23}},
{
{ 16, 20, 16, 20},
{ 20, 25, 20, 25},
{ 16, 20, 16, 20},
{ 20, 25, 20, 25}},
{
{ 18, 23, 18, 23},
{ 23, 29, 23, 29},
{ 18, 23, 18, 23},
{ 23, 29, 23, 29}}
};
static const int quant_coef[6][4][4] = { static const int quant_coef[6][4][4] = {{{13107, 8066, 13107, 8066},
{ {8066, 5243, 8066, 5243},
{ 13107, 8066, 13107, 8066}, {13107, 8066, 13107, 8066},
{ 8066, 5243, 8066, 5243}, {8066, 5243, 8066, 5243}},
{ 13107, 8066, 13107, 8066}, {{11916, 7490, 11916, 7490},
{ 8066, 5243, 8066, 5243}}, {7490, 4660, 7490, 4660},
{ {11916, 7490, 11916, 7490},
{ 11916, 7490, 11916, 7490}, {7490, 4660, 7490, 4660}},
{ 7490, 4660, 7490, 4660}, {{10082, 6554, 10082, 6554},
{ 11916, 7490, 11916, 7490}, {6554, 4194, 6554, 4194},
{ 7490, 4660, 7490, 4660}}, {10082, 6554, 10082, 6554},
{ {6554, 4194, 6554, 4194}},
{ 10082, 6554, 10082, 6554}, {{9362, 5825, 9362, 5825},
{ 6554, 4194, 6554, 4194}, {5825, 3647, 5825, 3647},
{ 10082, 6554, 10082, 6554}, {9362, 5825, 9362, 5825},
{ 6554, 4194, 6554, 4194}}, {5825, 3647, 5825, 3647}},
{ {{8192, 5243, 8192, 5243},
{ 9362, 5825, 9362, 5825}, {5243, 3355, 5243, 3355},
{ 5825, 3647, 5825, 3647}, {8192, 5243, 8192, 5243},
{ 9362, 5825, 9362, 5825}, {5243, 3355, 5243, 3355}},
{ 5825, 3647, 5825, 3647}}, {{7282, 4559, 7282, 4559},
{ {4559, 2893, 4559, 2893},
{ 8192, 5243, 8192, 5243}, {7282, 4559, 7282, 4559},
{ 5243, 3355, 5243, 3355}, {4559, 2893, 4559, 2893}}};
{ 8192, 5243, 8192, 5243},
{ 5243, 3355, 5243, 3355}},
{
{ 7282, 4559, 7282, 4559},
{ 4559, 2893, 4559, 2893},
{ 7282, 4559, 7282, 4559},
{ 4559, 2893, 4559, 2893}}
};
// SP decoding parameter (EQ. 8-425) // SP decoding parameter (EQ. 8-425)
static const int A[4][4] = { static const int A[4][4] = {
{ 16, 20, 16, 20}, {16, 20, 16, 20}, {20, 25, 20, 25}, {16, 20, 16, 20}, {20, 25, 20, 25}};
{ 20, 25, 20, 25},
{ 16, 20, 16, 20},
{ 20, 25, 20, 25}
};
// exported functions // exported functions
// quantization initialization // quantization initialization
extern void init_qp_process (VideoParameters *p_Vid); extern void init_qp_process(VideoParameters *p_Vid);
extern void free_qp_matrices(VideoParameters *p_Vid); extern void free_qp_matrices(VideoParameters *p_Vid);
// For Q-matrix // For Q-matrix
extern void assign_quant_params (Slice *currslice); extern void assign_quant_params(Slice *currslice);
extern void CalculateQuant4x4Param(Slice *currslice); extern void CalculateQuant4x4Param(Slice *currslice);
extern void CalculateQuant8x8Param(Slice *currslice); extern void CalculateQuant8x8Param(Slice *currslice);
#endif #endif

View file

@ -15,8 +15,8 @@
#define _QUANT_PARAMS_H_ #define _QUANT_PARAMS_H_
typedef struct level_quant_params { typedef struct level_quant_params {
int OffsetComp; int OffsetComp;
int ScaleComp; int ScaleComp;
int InvScaleComp; int InvScaleComp;
} LevelQuantParams; } LevelQuantParams;
@ -37,12 +37,12 @@ typedef struct quant_params {
} QuantParameters; } QuantParameters;
typedef struct quant_methods { typedef struct quant_methods {
int block_y; int block_y;
int block_x; int block_x;
int qp; int qp;
int* ACLevel; int *ACLevel;
int* ACRun; int *ACRun;
int **fadjust; int **fadjust;
LevelQuantParams **q_params; LevelQuantParams **q_params;
int *coeff_cost; int *coeff_cost;
const byte (*pos_scan)[2]; const byte (*pos_scan)[2];
@ -51,4 +51,3 @@ typedef struct quant_methods {
} QuantMethods; } QuantMethods;
#endif #endif

View file

@ -13,13 +13,15 @@
#ifndef _REPORT_H_ #ifndef _REPORT_H_
#define _REPORT_H_ #define _REPORT_H_
#include "contributors.h" #include "contributors.h"
#include "global.h"
#include "enc_statistics.h" #include "enc_statistics.h"
#include "global.h"
extern void report ( VideoParameters *p_Vid, InputParameters *p_Inp, StatParameters *p_Stats ); extern void report(VideoParameters *p_Vid, InputParameters *p_Inp,
extern void information_init ( VideoParameters *p_Vid, InputParameters *p_Inp, StatParameters *p_Stats ); StatParameters *p_Stats);
extern void report_frame_statistic( VideoParameters *p_Vid, InputParameters *p_Inp ); extern void information_init(VideoParameters *p_Vid, InputParameters *p_Inp,
extern void report_stats_on_error (void); StatParameters *p_Stats);
extern void report_frame_statistic(VideoParameters *p_Vid,
InputParameters *p_Inp);
extern void report_stats_on_error(void);
#endif #endif

View file

@ -13,34 +13,36 @@
#include "nalucommon.h" #include "nalucommon.h"
#define MAXRTPPAYLOADLEN (65536 - 40) //!< Maximum payload size of an RTP packet */ #define MAXRTPPAYLOADLEN \
#define MAXRTPPACKETSIZE (65536 - 28) //!< Maximum size of an RTP packet incl. header */ (65536 - 40) //!< Maximum payload size of an RTP packet */
#define H264PAYLOADTYPE 105 //!< RTP paylaod type fixed here for simplicity*/ #define MAXRTPPACKETSIZE \
#define H264SSRC 0x12345678 //!< SSRC, chosen to simplify debugging */ (65536 - 28) //!< Maximum size of an RTP packet incl. header */
#define RTP_TR_TIMESTAMP_MULT 1000 //!< should be something like 27 Mhz / 29.97 Hz */ #define H264PAYLOADTYPE 105 //!< RTP paylaod type fixed here for simplicity*/
#define H264SSRC 0x12345678 //!< SSRC, chosen to simplify debugging */
#define RTP_TR_TIMESTAMP_MULT \
1000 //!< should be something like 27 Mhz / 29.97 Hz */
typedef struct typedef struct {
{ unsigned int v; //!< Version, 2 bits, MUST be 0x2
unsigned int v; //!< Version, 2 bits, MUST be 0x2 unsigned int p; //!< Padding bit, Padding MUST NOT be used
unsigned int p; //!< Padding bit, Padding MUST NOT be used unsigned int x; //!< Extension, MUST be zero
unsigned int x; //!< Extension, MUST be zero unsigned int cc; /*!< CSRC count, normally 0 in the absence
unsigned int cc; /*!< CSRC count, normally 0 in the absence of RTP mixers */
of RTP mixers */ unsigned int m; //!< Marker bit
unsigned int m; //!< Marker bit unsigned int pt; //!< 7 bits, Payload Type, dynamically established
unsigned int pt; //!< 7 bits, Payload Type, dynamically established uint16 seq; /*!< RTP sequence number, incremented by one for
uint16 seq; /*!< RTP sequence number, incremented by one for each sent packet */
each sent packet */ unsigned int timestamp; //!< timestamp, 27 MHz for H.264
unsigned int timestamp; //!< timestamp, 27 MHz for H.264 unsigned int ssrc; //!< Synchronization Source, chosen randomly
unsigned int ssrc; //!< Synchronization Source, chosen randomly byte *payload; //!< the payload including payload headers
byte * payload; //!< the payload including payload headers unsigned int paylen; //!< length of payload in bytes
unsigned int paylen; //!< length of payload in bytes byte *packet; //!< complete packet including header and payload
byte * packet; //!< complete packet including header and payload unsigned int packlen; //!< length of packet, typically paylen+12
unsigned int packlen; //!< length of packet, typically paylen+12
} RTPpacket_t; } RTPpacket_t;
void DumpRTPHeader (RTPpacket_t *p); void DumpRTPHeader(RTPpacket_t *p);
int GetRTPNALU (VideoParameters *p_Vid, NALU_t *nalu); int GetRTPNALU(VideoParameters *p_Vid, NALU_t *nalu);
void OpenRTPFile (VideoParameters *p_Vid, char *fn); void OpenRTPFile(VideoParameters *p_Vid, char *fn);
void CloseRTPFile(VideoParameters *p_Vid); void CloseRTPFile(VideoParameters *p_Vid);
#endif #endif

View file

@ -59,26 +59,26 @@ typedef enum {
SEI_BASE_VIEW_TEMPORAL_HRD, SEI_BASE_VIEW_TEMPORAL_HRD,
SEI_FRAME_PACKING_ARRANGEMENT, SEI_FRAME_PACKING_ARRANGEMENT,
SEI_MAX_ELEMENTS //!< number of maximum syntax elements SEI_MAX_ELEMENTS //!< number of maximum syntax elements
} SEI_type; } SEI_type;
#define MAX_FN 256 #define MAX_FN 256
// tone mapping information // tone mapping information
#define MAX_CODED_BIT_DEPTH 12 #define MAX_CODED_BIT_DEPTH 12
#define MAX_SEI_BIT_DEPTH 12 #define MAX_SEI_BIT_DEPTH 12
#define MAX_NUM_PIVOTS (1<<MAX_CODED_BIT_DEPTH) #define MAX_NUM_PIVOTS (1 << MAX_CODED_BIT_DEPTH)
#if (ENABLE_OUTPUT_TONEMAPPING) #if (ENABLE_OUTPUT_TONEMAPPING)
typedef struct tone_mapping_struct_s typedef struct tone_mapping_struct_s {
{
Boolean seiHasTone_mapping; Boolean seiHasTone_mapping;
unsigned int tone_map_repetition_period; unsigned int tone_map_repetition_period;
unsigned char coded_data_bit_depth; unsigned char coded_data_bit_depth;
unsigned char sei_bit_depth; unsigned char sei_bit_depth;
unsigned int model_id; unsigned int model_id;
unsigned int count; unsigned int count;
imgpel lut[1<<MAX_CODED_BIT_DEPTH]; //<! look up table for mapping the coded data value to output data value imgpel lut[1 << MAX_CODED_BIT_DEPTH]; //<! look up table for mapping the coded
//data value to output data value
Bitstream *data; Bitstream *data;
int payloadSize; int payloadSize;
@ -86,59 +86,83 @@ typedef struct tone_mapping_struct_s
#endif #endif
//! Frame packing arrangement Information //! Frame packing arrangement Information
typedef struct typedef struct {
{ unsigned int frame_packing_arrangement_id;
unsigned int frame_packing_arrangement_id; Boolean frame_packing_arrangement_cancel_flag;
Boolean frame_packing_arrangement_cancel_flag;
unsigned char frame_packing_arrangement_type; unsigned char frame_packing_arrangement_type;
Boolean quincunx_sampling_flag; Boolean quincunx_sampling_flag;
unsigned char content_interpretation_type; unsigned char content_interpretation_type;
Boolean spatial_flipping_flag; Boolean spatial_flipping_flag;
Boolean frame0_flipped_flag; Boolean frame0_flipped_flag;
Boolean field_views_flag; Boolean field_views_flag;
Boolean current_frame_is_frame0_flag; Boolean current_frame_is_frame0_flag;
Boolean frame0_self_contained_flag; Boolean frame0_self_contained_flag;
Boolean frame1_self_contained_flag; Boolean frame1_self_contained_flag;
unsigned char frame0_grid_position_x; unsigned char frame0_grid_position_x;
unsigned char frame0_grid_position_y; unsigned char frame0_grid_position_y;
unsigned char frame1_grid_position_x; unsigned char frame1_grid_position_x;
unsigned char frame1_grid_position_y; unsigned char frame1_grid_position_y;
unsigned char frame_packing_arrangement_reserved_byte; unsigned char frame_packing_arrangement_reserved_byte;
unsigned int frame_packing_arrangement_repetition_period; unsigned int frame_packing_arrangement_repetition_period;
Boolean frame_packing_arrangement_extension_flag; Boolean frame_packing_arrangement_extension_flag;
} frame_packing_arrangement_information_struct; } frame_packing_arrangement_information_struct;
void InterpretSEIMessage ( byte* payload, int size, VideoParameters *p_Vid, Slice *pSlice ); void InterpretSEIMessage(byte *payload, int size, VideoParameters *p_Vid,
void interpret_spare_pic ( byte* payload, int size, VideoParameters *p_Vid ); Slice *pSlice);
void interpret_subsequence_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_spare_pic(byte *payload, int size, VideoParameters *p_Vid);
void interpret_subsequence_layer_characteristics_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_subsequence_info(byte *payload, int size,
void interpret_subsequence_characteristics_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_scene_information ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_subsequence_layer_characteristics_info(byte *payload, int size,
void interpret_user_data_registered_itu_t_t35_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_user_data_unregistered_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_subsequence_characteristics_info(byte *payload, int size,
void interpret_pan_scan_rect_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_recovery_point_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_scene_information(byte *payload, int size,
void interpret_filler_payload_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_dec_ref_pic_marking_repetition_info ( byte* payload, int size, VideoParameters *p_Vid, Slice *pSlice ); void interpret_user_data_registered_itu_t_t35_info(byte *payload, int size,
void interpret_full_frame_freeze_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_full_frame_freeze_release_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_user_data_unregistered_info(byte *payload, int size,
void interpret_full_frame_snapshot_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_progressive_refinement_start_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_pan_scan_rect_info(byte *payload, int size,
void interpret_progressive_refinement_end_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_motion_constrained_slice_group_set_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_recovery_point_info(byte *payload, int size,
void interpret_reserved_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_buffering_period_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_filler_payload_info(byte *payload, int size,
void interpret_picture_timing_info ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_film_grain_characteristics_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_dec_ref_pic_marking_repetition_info(byte *payload, int size,
void interpret_deblocking_filter_display_preference_info( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid,
void interpret_stereo_video_info_info ( byte* payload, int size, VideoParameters *p_Vid ); Slice *pSlice);
void interpret_post_filter_hints_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_full_frame_freeze_info(byte *payload, int size,
void interpret_tone_mapping ( byte* payload, int size, VideoParameters *p_Vid ); VideoParameters *p_Vid);
void interpret_frame_packing_arrangement_info ( byte* payload, int size, VideoParameters *p_Vid ); void interpret_full_frame_freeze_release_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_full_frame_snapshot_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_progressive_refinement_start_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_progressive_refinement_end_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_motion_constrained_slice_group_set_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_reserved_info(byte *payload, int size, VideoParameters *p_Vid);
void interpret_buffering_period_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_picture_timing_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_film_grain_characteristics_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_deblocking_filter_display_preference_info(
byte *payload, int size, VideoParameters *p_Vid);
void interpret_stereo_video_info_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_post_filter_hints_info(byte *payload, int size,
VideoParameters *p_Vid);
void interpret_tone_mapping(byte *payload, int size, VideoParameters *p_Vid);
void interpret_frame_packing_arrangement_info(byte *payload, int size,
VideoParameters *p_Vid);
#if (ENABLE_OUTPUT_TONEMAPPING) #if (ENABLE_OUTPUT_TONEMAPPING)
void tone_map (imgpel** imgX, imgpel* lut, int size_x, int size_y); void tone_map(imgpel **imgX, imgpel *lut, int size_x, int size_y);
void init_tone_mapping_sei (ToneMappingSEI *seiToneMapping); void init_tone_mapping_sei(ToneMappingSEI *seiToneMapping);
void update_tone_mapping_sei(ToneMappingSEI *seiToneMapping); void update_tone_mapping_sei(ToneMappingSEI *seiToneMapping);
#endif #endif
#endif #endif

View file

@ -11,22 +11,22 @@
* 10 July 2007 * 10 July 2007
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
* Alexis Michael Tourapis *affiliation details) Alexis Michael Tourapis
**************************************************************************/ **************************************************************************/
#ifndef _TRANSFORM_H_ #ifndef _TRANSFORM_H_
#define _TRANSFORM_H_ #define _TRANSFORM_H_
extern void forward4x4 (int **block , int **tblock, int pos_y, int pos_x); extern void forward4x4(int **block, int **tblock, int pos_y, int pos_x);
extern void inverse4x4 (int **tblock, int **block , int pos_y, int pos_x); extern void inverse4x4(int **tblock, int **block, int pos_y, int pos_x);
extern void forward8x8 (int **block , int **tblock, int pos_y, int pos_x); extern void forward8x8(int **block, int **tblock, int pos_y, int pos_x);
extern void inverse8x8 (int **tblock, int **block , int pos_y, int pos_x); extern void inverse8x8(int **tblock, int **block, int pos_y, int pos_x);
extern void hadamard4x4 (int **block , int **tblock); extern void hadamard4x4(int **block, int **tblock);
extern void ihadamard4x4 (int **tblock, int **block); extern void ihadamard4x4(int **tblock, int **block);
extern void hadamard4x2 (int **block , int **tblock); extern void hadamard4x2(int **block, int **tblock);
extern void ihadamard4x2 (int **tblock, int **block); extern void ihadamard4x2(int **tblock, int **block);
extern void hadamard2x2 (int **block , int tblock[4]); extern void hadamard2x2(int **block, int tblock[4]);
extern void ihadamard2x2 (int block[4], int tblock[4]); extern void ihadamard2x2(int block[4], int tblock[4]);
#endif //_TRANSFORM_H_ #endif //_TRANSFORM_H_

View file

@ -10,13 +10,14 @@
* 9. October 2003 * 9. October 2003
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Yuri Vatis * - Yuri Vatis
**************************************************************************/ **************************************************************************/
#ifndef _TRANSFORM8X8_H_ #ifndef _TRANSFORM8X8_H_
#define _TRANSFORM8X8_H_ #define _TRANSFORM8X8_H_
extern void itrans8x8 (Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void itrans8x8(Macroblock *currMB, ColorPlane pl, int ioff, int joff);
#endif #endif

View file

@ -4,11 +4,13 @@
* *
* \brief * \brief
* Common type definitions * Common type definitions
* Currently only supports Windows and Linux operating systems. * Currently only supports Windows and Linux operating systems.
* Need to add support for other "older systems such as VAX, DECC, Unix Alpha etc * Need to add support for other "older systems such as VAX, DECC, Unix Alpha
*etc
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
************************************************************************************* *************************************************************************************
*/ */
@ -18,20 +20,21 @@
#include "win32.h" #include "win32.h"
typedef unsigned char byte; //!< byte type definition typedef unsigned char byte; //!< byte type definition
typedef unsigned char uint8; //!< type definition for unsigned char (same as byte, 8 bits) typedef unsigned char
typedef unsigned short uint16; //!< type definition for unsigned short (16 bits) uint8; //!< type definition for unsigned char (same as byte, 8 bits)
typedef unsigned int uint32; //!< type definition for unsigned int (32 bits) typedef unsigned short uint16; //!< type definition for unsigned short (16 bits)
typedef unsigned int uint32; //!< type definition for unsigned int (32 bits)
typedef signed char int8; typedef signed char int8;
typedef short int16; typedef short int16;
typedef int int32; typedef int int32;
#if (IMGTYPE == 0) #if (IMGTYPE == 0)
typedef byte imgpel; //!< pixel type typedef byte imgpel; //!< pixel type
typedef uint16 distpel; //!< distortion type (for pixels) typedef uint16 distpel; //!< distortion type (for pixels)
typedef int32 distblk; //!< distortion type (for Macroblock) typedef int32 distblk; //!< distortion type (for Macroblock)
typedef int32 transpel; //!< transformed coefficient type typedef int32 transpel; //!< transformed coefficient type
#elif (IMGTYPE == 2) #elif (IMGTYPE == 2)
typedef float imgpel; typedef float imgpel;
typedef float distpel; typedef float distpel;
@ -40,8 +43,8 @@ typedef int32 transpel;
#else #else
typedef uint16 imgpel; typedef uint16 imgpel;
typedef uint32 distpel; typedef uint32 distpel;
typedef int64 distblk; typedef int64 distblk;
typedef int32 transpel; typedef int32 transpel;
#endif #endif
#ifdef SPEC #ifdef SPEC
@ -55,17 +58,14 @@ typedef int32 transpel;
#else #else
//! Boolean Type //! Boolean Type
#ifdef FALSE #ifdef FALSE
# define Boolean int #define Boolean int
#else #else
typedef enum { typedef enum { FALSE, TRUE } Boolean;
FALSE,
TRUE
} Boolean;
#endif #endif
#endif #endif
#ifndef MAXINT64 #ifndef MAXINT64
#define MAXINT64 0x7fffffffffffffff #define MAXINT64 0x7fffffffffffffff
#endif #endif
/* /*
@ -85,4 +85,3 @@ typedef enum {
*/ */
#endif #endif

View file

@ -7,7 +7,8 @@
* type definitions. * type definitions.
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* *
************************************************************************ ************************************************************************
*/ */
@ -19,63 +20,39 @@
*********************************************************************** ***********************************************************************
*/ */
typedef enum typedef enum {
{
// YUV // YUV
PLANE_Y = 0, // PLANE_Y PLANE_Y = 0, // PLANE_Y
PLANE_U = 1, // PLANE_Cb PLANE_U = 1, // PLANE_Cb
PLANE_V = 2, // PLANE_Cr PLANE_V = 2, // PLANE_Cr
// RGB // RGB
PLANE_G = 0, PLANE_G = 0,
PLANE_B = 1, PLANE_B = 1,
PLANE_R = 2 PLANE_R = 2
} ColorPlane; } ColorPlane;
enum { enum { LIST_0 = 0, LIST_1 = 1, BI_PRED = 2, BI_PRED_L0 = 3, BI_PRED_L1 = 4 };
LIST_0 = 0,
LIST_1 = 1,
BI_PRED = 2,
BI_PRED_L0 = 3,
BI_PRED_L1 = 4
};
enum { enum { ERROR_SAD = 0, ERROR_SSE = 1, ERROR_SATD = 2, ERROR_PSATD = 3 };
ERROR_SAD = 0,
ERROR_SSE = 1,
ERROR_SATD = 2,
ERROR_PSATD = 3
};
enum { enum { ME_Y_ONLY = 0, ME_YUV_FP = 1, ME_YUV_FP_SP = 2 };
ME_Y_ONLY = 0,
ME_YUV_FP = 1,
ME_YUV_FP_SP = 2
};
enum {
DISTORTION_MSE = 0
};
enum { DISTORTION_MSE = 0 };
//! Data Partitioning Modes //! Data Partitioning Modes
typedef enum typedef enum {
{ PAR_DP_1, //!< no data partitioning is supported
PAR_DP_1, //!< no data partitioning is supported PAR_DP_3 //!< data partitioning with 3 partitions
PAR_DP_3 //!< data partitioning with 3 partitions
} PAR_DP_TYPE; } PAR_DP_TYPE;
//! Output File Types //! Output File Types
typedef enum typedef enum {
{ PAR_OF_ANNEXB, //!< Annex B byte stream format
PAR_OF_ANNEXB, //!< Annex B byte stream format PAR_OF_RTP //!< RTP packets in outfile
PAR_OF_RTP //!< RTP packets in outfile
} PAR_OF_TYPE; } PAR_OF_TYPE;
//! Field Coding Types //! Field Coding Types
typedef enum typedef enum {
{
FRAME_CODING, FRAME_CODING,
FIELD_CODING, FIELD_CODING,
ADAPTIVE_CODING, ADAPTIVE_CODING,
@ -83,8 +60,7 @@ typedef enum
} CodingType; } CodingType;
//! definition of H.264 syntax elements //! definition of H.264 syntax elements
typedef enum typedef enum {
{
SE_HEADER, SE_HEADER,
SE_PTYPE, SE_PTYPE,
SE_MBTYPE, SE_MBTYPE,
@ -106,41 +82,25 @@ typedef enum
SE_MAX_ELEMENTS = 20 //!< number of maximum syntax elements SE_MAX_ELEMENTS = 20 //!< number of maximum syntax elements
} SE_type; // substituting the definitions in elements.h } SE_type; // substituting the definitions in elements.h
typedef enum { NO_SLICES, FIXED_MB, FIXED_RATE, CALL_BACK } SliceMode;
typedef enum typedef enum { CAVLC, CABAC } SymbolMode;
{
NO_SLICES,
FIXED_MB,
FIXED_RATE,
CALL_BACK
} SliceMode;
typedef enum {
typedef enum FULL_SEARCH = -1,
{ FAST_FULL_SEARCH = 0,
CAVLC, UM_HEX = 1,
CABAC UM_HEX_SIMPLE = 2,
} SymbolMode; EPZS = 3
typedef enum
{
FULL_SEARCH = -1,
FAST_FULL_SEARCH = 0,
UM_HEX = 1,
UM_HEX_SIMPLE = 2,
EPZS = 3
} SearchType; } SearchType;
typedef enum {
typedef enum
{
FRAME, FRAME,
TOP_FIELD, TOP_FIELD,
BOTTOM_FIELD BOTTOM_FIELD
} PictureStructure; //!< New enum for field processing } PictureStructure; //!< New enum for field processing
typedef enum typedef enum {
{
P_SLICE = 0, P_SLICE = 0,
B_SLICE = 1, B_SLICE = 1,
I_SLICE = 2, I_SLICE = 2,
@ -149,55 +109,46 @@ typedef enum
NUM_SLICE_TYPES = 5 NUM_SLICE_TYPES = 5
} SliceType; } SliceType;
//Motion Estimation levels // Motion Estimation levels
typedef enum typedef enum {
{ F_PEL, //!< Full Pel refinement
F_PEL, //!< Full Pel refinement H_PEL, //!< Half Pel refinement
H_PEL, //!< Half Pel refinement Q_PEL //!< Quarter Pel refinement
Q_PEL //!< Quarter Pel refinement
} MELevel; } MELevel;
typedef enum typedef enum {
{ FAST_ACCESS = 0, //!< Fast/safe reference access
FAST_ACCESS = 0, //!< Fast/safe reference access UMV_ACCESS = 1 //!< unconstrained reference access
UMV_ACCESS = 1 //!< unconstrained reference access
} REF_ACCESS_TYPE; } REF_ACCESS_TYPE;
typedef enum typedef enum { IS_LUMA = 0, IS_CHROMA = 1 } Component_Type;
{
IS_LUMA = 0,
IS_CHROMA = 1
} Component_Type;
typedef enum typedef enum {
{
RC_MODE_0 = 0, RC_MODE_0 = 0,
RC_MODE_1 = 1, RC_MODE_1 = 1,
RC_MODE_2 = 2, RC_MODE_2 = 2,
RC_MODE_3 = 3 RC_MODE_3 = 3
} RCModeType; } RCModeType;
typedef enum { typedef enum {
SSE = 0, SSE = 0,
SSE_RGB = 1, SSE_RGB = 1,
PSNR = 2, PSNR = 2,
PSNR_RGB = 3, PSNR_RGB = 3,
SSIM = 4, SSIM = 4,
SSIM_RGB = 5, SSIM_RGB = 5,
MS_SSIM = 6, MS_SSIM = 6,
MS_SSIM_RGB = 7, MS_SSIM_RGB = 7,
TOTAL_DIST_TYPES = 8 TOTAL_DIST_TYPES = 8
} distortion_types; } distortion_types;
typedef enum { typedef enum {
WP_MCPREC_PLUS0 = 4, WP_MCPREC_PLUS0 = 4,
WP_MCPREC_PLUS1 = 5, WP_MCPREC_PLUS1 = 5,
WP_MCPREC_MINUS0 = 6, WP_MCPREC_MINUS0 = 6,
WP_MCPREC_MINUS1 = 7, WP_MCPREC_MINUS1 = 7,
WP_MCPREC_MINUS_PLUS0 = 8, WP_MCPREC_MINUS_PLUS0 = 8,
WP_REGULAR = 9 WP_REGULAR = 9
} weighted_prediction_types; } weighted_prediction_types;
#endif #endif

View file

@ -16,97 +16,101 @@
#define _VLC_H_ #define _VLC_H_
//! gives CBP value from codeword number, both for intra and inter //! gives CBP value from codeword number, both for intra and inter
static const byte NCBP[2][48][2]= static const byte NCBP[2][48][2] = {
{ {// 0 1 2 3 4 5 6 7 8 9 10
{ // 0 1 2 3 4 5 6 7 8 9 10 11 // 11
{15, 0},{ 0, 1},{ 7, 2},{11, 4},{13, 8},{14, 3},{ 3, 5},{ 5,10},{10,12},{12,15},{ 1, 7},{ 2,11}, {15, 0}, {0, 1}, {7, 2}, {11, 4}, {13, 8}, {14, 3}, {3, 5}, {5, 10},
{ 4,13},{ 8,14},{ 6, 6},{ 9, 9},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0}, {10, 12}, {12, 15}, {1, 7}, {2, 11}, {4, 13}, {8, 14}, {6, 6}, {9, 9},
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{ {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{47, 0},{31,16},{15, 1},{ 0, 2},{23, 4},{27, 8},{29,32},{30, 3},{ 7, 5},{11,10},{13,12},{14,15}, {{47, 0}, {31, 16}, {15, 1}, {0, 2}, {23, 4}, {27, 8}, {29, 32},
{39,47},{43, 7},{45,11},{46,13},{16,14},{ 3, 6},{ 5, 9},{10,31},{12,35},{19,37},{21,42},{26,44}, {30, 3}, {7, 5}, {11, 10}, {13, 12}, {14, 15}, {39, 47}, {43, 7},
{28,33},{35,34},{37,36},{42,40},{44,39},{ 1,43},{ 2,45},{ 4,46},{ 8,17},{17,18},{18,20},{20,24}, {45, 11}, {46, 13}, {16, 14}, {3, 6}, {5, 9}, {10, 31}, {12, 35},
{24,19},{ 6,21},{ 9,26},{22,28},{25,23},{32,27},{33,29},{34,30},{36,22},{40,25},{38,38},{41,41} {19, 37}, {21, 42}, {26, 44}, {28, 33}, {35, 34}, {37, 36}, {42, 40},
} {44, 39}, {1, 43}, {2, 45}, {4, 46}, {8, 17}, {17, 18}, {18, 20},
}; {20, 24}, {24, 19}, {6, 21}, {9, 26}, {22, 28}, {25, 23}, {32, 27},
{33, 29}, {34, 30}, {36, 22}, {40, 25}, {38, 38}, {41, 41}}};
//! for the linfo_levrun_inter routine //! for the linfo_levrun_inter routine
static const byte NTAB1[4][8][2] = static const byte NTAB1[4][8][2] = {
{ {{1, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{1,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{1, 1}, {1, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{1,1},{1,2},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{2, 0}, {1, 3}, {1, 4}, {1, 5}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{2,0},{1,3},{1,4},{1,5},{0,0},{0,0},{0,0},{0,0}}, {{3, 0}, {2, 1}, {2, 2}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {4, 0}},
{{3,0},{2,1},{2,2},{1,6},{1,7},{1,8},{1,9},{4,0}},
}; };
static const byte LEVRUN1[16]= static const byte LEVRUN1[16] = {
{ 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
4,2,2,1,1,1,1,1,1,1,0,0,0,0,0,0,
}; };
static const byte NTAB2[4][8][2] = {
static const byte NTAB2[4][8][2] = {{1, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{ {{1, 1}, {2, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{1,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{1, 2}, {3, 0}, {4, 0}, {5, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{1,1},{2,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{1, 3}, {1, 4}, {2, 1}, {3, 1}, {6, 0}, {7, 0}, {8, 0}, {9, 0}},
{{1,2},{3,0},{4,0},{5,0},{0,0},{0,0},{0,0},{0,0}},
{{1,3},{1,4},{2,1},{3,1},{6,0},{7,0},{8,0},{9,0}},
}; };
//! for the linfo_levrun__c2x2 routine //! for the linfo_levrun__c2x2 routine
static const byte LEVRUN3[4] = static const byte LEVRUN3[4] = {2, 1, 0, 0};
{
2,1,0,0 static const byte NTAB3[2][2][2] = {
{{1, 0}, {0, 0}},
{{2, 0}, {1, 1}},
}; };
static const byte NTAB3[2][2][2] = extern int se_v(char *tracestring, Bitstream *bitstream);
{ extern int ue_v(char *tracestring, Bitstream *bitstream);
{{1,0},{0,0}}, extern Boolean u_1(char *tracestring, Bitstream *bitstream);
{{2,0},{1,1}}, extern int u_v(int LenInBits, char *tracestring, Bitstream *bitstream);
}; extern int i_v(int LenInBits, char *tracestring, Bitstream *bitstream);
extern int se_v (char *tracestring, Bitstream *bitstream);
extern int ue_v (char *tracestring, Bitstream *bitstream);
extern Boolean u_1 (char *tracestring, Bitstream *bitstream);
extern int u_v (int LenInBits, char *tracestring, Bitstream *bitstream);
extern int i_v (int LenInBits, char *tracestring, Bitstream *bitstream);
// CAVLC mapping // CAVLC mapping
extern void linfo_ue(int len, int info, int *value1, int *dummy); extern void linfo_ue(int len, int info, int *value1, int *dummy);
extern void linfo_se(int len, int info, int *value1, int *dummy); extern void linfo_se(int len, int info, int *value1, int *dummy);
extern void linfo_cbp_intra_normal(int len,int info,int *cbp, int *dummy); extern void linfo_cbp_intra_normal(int len, int info, int *cbp, int *dummy);
extern void linfo_cbp_inter_normal(int len,int info,int *cbp, int *dummy); extern void linfo_cbp_inter_normal(int len, int info, int *cbp, int *dummy);
extern void linfo_cbp_intra_other(int len,int info,int *cbp, int *dummy); extern void linfo_cbp_intra_other(int len, int info, int *cbp, int *dummy);
extern void linfo_cbp_inter_other(int len,int info,int *cbp, int *dummy); extern void linfo_cbp_inter_other(int len, int info, int *cbp, int *dummy);
extern void linfo_levrun_inter(int len,int info,int *level,int *irun); extern void linfo_levrun_inter(int len, int info, int *level, int *irun);
extern void linfo_levrun_c2x2(int len,int info,int *level,int *irun); extern void linfo_levrun_c2x2(int len, int info, int *level, int *irun);
extern int uvlc_startcode_follows(Slice *currSlice, int dummy); extern int uvlc_startcode_follows(Slice *currSlice, int dummy);
extern int readSyntaxElement_VLC (SyntaxElement *sym, Bitstream *currStream); extern int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream);
extern int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, struct datapartition *dp); extern int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym,
extern int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, Bitstream *currStream); struct datapartition *dp);
extern int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym,
Bitstream *currStream);
extern int GetVLCSymbol (byte buffer[],int totbitoffset,int *info, int bytecount); extern int GetVLCSymbol(byte buffer[], int totbitoffset, int *info,
extern int GetVLCSymbol_IntraMode (byte buffer[],int totbitoffset,int *info, int bytecount); int bytecount);
extern int GetVLCSymbol_IntraMode(byte buffer[], int totbitoffset, int *info,
int bytecount);
extern int readSyntaxElement_FLC (SyntaxElement *sym, Bitstream *currStream); extern int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream);
extern int readSyntaxElement_NumCoeffTrailingOnes (SyntaxElement *sym, Bitstream *currStream, signed char *type); extern int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym,
extern int readSyntaxElement_NumCoeffTrailingOnesChromaDC(VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream); Bitstream *currStream,
extern int readSyntaxElement_Level_VLC0 (SyntaxElement *sym, Bitstream *currStream); signed char *type);
extern int readSyntaxElement_Level_VLCN (SyntaxElement *sym, int vlc, Bitstream *currStream); extern int readSyntaxElement_NumCoeffTrailingOnesChromaDC(
extern int readSyntaxElement_TotalZeros (SyntaxElement *sym, Bitstream *currStream); VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream);
extern int readSyntaxElement_TotalZerosChromaDC (VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream); extern int readSyntaxElement_Level_VLC0(SyntaxElement *sym,
extern int readSyntaxElement_Run (SyntaxElement *sym, Bitstream *currStream); Bitstream *currStream);
extern int GetBits (byte buffer[],int totbitoffset,int *info, int bitcount, int numbits); extern int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc,
extern int ShowBits (byte buffer[],int totbitoffset,int bitcount, int numbits); Bitstream *currStream);
extern int readSyntaxElement_TotalZeros(SyntaxElement *sym,
extern int more_rbsp_data (byte buffer[],int totbitoffset,int bytecount); Bitstream *currStream);
extern int readSyntaxElement_TotalZerosChromaDC(VideoParameters *p_Vid,
SyntaxElement *sym,
Bitstream *currStream);
extern int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream);
extern int GetBits(byte buffer[], int totbitoffset, int *info, int bitcount,
int numbits);
extern int ShowBits(byte buffer[], int totbitoffset, int bitcount, int numbits);
extern int more_rbsp_data(byte buffer[], int totbitoffset, int bytecount);
#endif #endif

View file

@ -14,8 +14,7 @@
#define _VUI_PARAMS_H_ #define _VUI_PARAMS_H_
// VUI Parameters // VUI Parameters
typedef struct vui_parameters typedef struct vui_parameters {
{
int aspect_ratio_info_present_flag; int aspect_ratio_info_present_flag;
int aspect_ratio_idc; int aspect_ratio_idc;
int sar_width; int sar_width;
@ -27,7 +26,7 @@ typedef struct vui_parameters
int video_full_range_flag; int video_full_range_flag;
int colour_description_present_flag; int colour_description_present_flag;
int colour_primaries; int colour_primaries;
int transfer_characteristics; int transfer_characteristics;
int matrix_coefficients; int matrix_coefficients;
int chroma_location_info_present_flag; int chroma_location_info_present_flag;
int chroma_sample_loc_type_top_field; int chroma_sample_loc_type_top_field;
@ -71,4 +70,3 @@ typedef struct vui_parameters
} VUIParameters; } VUIParameters;
#endif #endif

View file

@ -14,104 +14,108 @@
#ifndef _WIN32_H_ #ifndef _WIN32_H_
#define _WIN32_H_ #define _WIN32_H_
# include <fcntl.h> #include <assert.h>
# include <stdlib.h> #include <fcntl.h>
# include <stdio.h> #include <stdio.h>
# include <string.h> #include <stdlib.h>
# include <assert.h> #include <string.h>
#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) #if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \
# define OPENMP !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP)
# define NUM_THREADS 8 #define OPENMP
#define NUM_THREADS 8
#endif #endif
#if defined(WIN32) || defined (WIN64) || defined(SPEC_WINDOWS) #if defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS)
# include <io.h> #include <io.h>
#ifndef SPEC #ifndef SPEC
# include <sys/types.h> #include <sys/stat.h>
# include <sys/stat.h> #include <sys/types.h>
#endif /* !SPEC */ #endif /* !SPEC */
# include <windows.h> #include <windows.h>
#if (_MSC_VER < 1400) #if (_MSC_VER < 1400)
typedef int intptr_t; typedef int intptr_t;
#else #else
# include <crtdefs.h> #include <crtdefs.h>
#endif #endif
#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) #if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \
# include <omp.h> !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP)
#include <omp.h>
#endif #endif
# define strcmp _strcmpi #define strcmp _strcmpi
# define snprintf _snprintf #define snprintf _snprintf
# define open _open #define open _open
# define close _close #define close _close
# define read _read #define read _read
# define write _write #define write _write
# define lseek _lseeki64 #define lseek _lseeki64
# define fsync _commit #define fsync _commit
# define tell _telli64 #define tell _telli64
#ifndef SPEC #ifndef SPEC
# define TIMEB _timeb #define TIMEB _timeb
# define TIME_T LARGE_INTEGER #define TIME_T LARGE_INTEGER
#endif /*! SPEC */ #endif /*! SPEC */
# define OPENFLAGS_WRITE _O_WRONLY|_O_CREAT|_O_BINARY|_O_TRUNC #define OPENFLAGS_WRITE _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC
# define OPEN_PERMISSIONS _S_IREAD | _S_IWRITE #define OPEN_PERMISSIONS _S_IREAD | _S_IWRITE
# define OPENFLAGS_READ _O_RDONLY|_O_BINARY #define OPENFLAGS_READ _O_RDONLY | _O_BINARY
#ifndef SPEC_NO_UNDERBAR_INLINE #ifndef SPEC_NO_UNDERBAR_INLINE
# define inline _inline #define inline _inline
#endif #endif
# define forceinline __forceinline #define forceinline __forceinline
#else #else
# include <unistd.h> #include <stdint.h>
# include <sys/time.h> #include <sys/stat.h>
# include <sys/stat.h> #include <sys/time.h>
# include <time.h> #include <time.h>
# include <stdint.h> #include <unistd.h>
#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) #if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \
# include <omp.h> !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP)
#include <omp.h>
#endif #endif
# define TIMEB timeb #define TIMEB timeb
# define TIME_T struct timeval #define TIME_T struct timeval
# define tell(fd) lseek(fd, 0, SEEK_CUR) #define tell(fd) lseek(fd, 0, SEEK_CUR)
# define OPENFLAGS_WRITE O_WRONLY|O_CREAT|O_TRUNC #define OPENFLAGS_WRITE O_WRONLY | O_CREAT | O_TRUNC
# define OPENFLAGS_READ O_RDONLY #define OPENFLAGS_READ O_RDONLY
# define OPEN_PERMISSIONS S_IRUSR | S_IWUSR #define OPEN_PERMISSIONS S_IRUSR | S_IWUSR
# if __STDC_VERSION__ >= 199901L #if __STDC_VERSION__ >= 199901L
/* "inline" is a keyword */ /* "inline" is a keyword */
# else #else
# define inline /* nothing */ #define inline /* nothing */
# endif #endif
# define forceinline inline #define forceinline inline
#endif #endif
#if (defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS)) && !defined(__GNUC__) #if (defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS)) && \
typedef __int64 int64; !defined(__GNUC__)
typedef unsigned __int64 uint64; typedef __int64 int64;
# define FORMAT_OFF_T "I64d" typedef unsigned __int64 uint64;
# ifndef INT64_MIN #define FORMAT_OFF_T "I64d"
# define INT64_MIN (-9223372036854775807i64 - 1i64) #ifndef INT64_MIN
# endif #define INT64_MIN (-9223372036854775807i64 - 1i64)
#endif
#else #else
#if defined(SPEC_USE_LL_INT64) #if defined(SPEC_USE_LL_INT64)
typedef long long int64; typedef long long int64;
typedef unsigned long long uint64; typedef unsigned long long uint64;
# define FORMAT_OFF_T "lld" #define FORMAT_OFF_T "lld"
#else #else
typedef int64_t int64; typedef int64_t int64;
typedef uint64_t uint64; typedef uint64_t uint64;
# define FORMAT_OFF_T "ld" #define FORMAT_OFF_T "ld"
#endif /* SPEC_USE_LL_INT64 */ #endif /* SPEC_USE_LL_INT64 */
# ifndef INT64_MIN #ifndef INT64_MIN
# define INT64_MIN (-9223372036854775807LL - 1LL) #define INT64_MIN (-9223372036854775807LL - 1LL)
# endif #endif
#endif #endif
#ifndef SPEC #ifndef SPEC
void gettime(TIME_T* time); void gettime(TIME_T *time);
int64 timediff(TIME_T* start, TIME_T* end); int64 timediff(TIME_T *start, TIME_T *end);
int64 timenorm(int64 cur_time); int64 timenorm(int64 cur_time);
#endif #endif

View file

@ -7,10 +7,11 @@
* Input related functions * Input related functions
* *
* \author * \author
* Main contributors (see contributors.h for copyright, address and affiliation details) * Main contributors (see contributors.h for copyright, address and
*affiliation details)
* - Karsten Sühring <suehring@hhi.de> * - Karsten Sühring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************************* *************************************************************************************
*/ */
#include "contributors.h" #include "contributors.h"
@ -19,14 +20,20 @@
#include <time.h> #include <time.h>
#include "global.h" #include "global.h"
#include "input.h"
#include "img_io.h" #include "img_io.h"
#include "input.h"
#include "memalloc.h" #include "memalloc.h"
void buf2img_basic ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); void buf2img_basic(imgpel **imgX, unsigned char *buf, int size_x, int size_y,
void buf2img_endian ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); int o_size_x, int o_size_y, int symbol_size_in_bytes,
void buf2img_bitshift ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); int bitshift);
void fillPlane ( imgpel** imgX, int nVal, int size_x, int size_y); void buf2img_endian(imgpel **imgX, unsigned char *buf, int size_x, int size_y,
int o_size_x, int o_size_y, int symbol_size_in_bytes,
int bitshift);
void buf2img_bitshift(imgpel **imgX, unsigned char *buf, int size_x, int size_y,
int o_size_x, int o_size_y, int symbol_size_in_bytes,
int bitshift);
void fillPlane(imgpel **imgX, int nVal, int size_x, int size_y);
/*! /*!
************************************************************************ ************************************************************************
@ -37,20 +44,18 @@ void fillPlane ( imgpel** imgX, int nVal, int size_x, int size_y);
* 1, big-endian (e.g. SPARC, MIPS, PowerPC) * 1, big-endian (e.g. SPARC, MIPS, PowerPC)
************************************************************************ ************************************************************************
*/ */
void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output) void initInput(VideoParameters *p_Vid, FrameFormat *source,
{ FrameFormat *output) {
if (source->bit_depth[0] == output->bit_depth[0] && source->bit_depth[1] == output->bit_depth[1]) if (source->bit_depth[0] == output->bit_depth[0] &&
{ source->bit_depth[1] == output->bit_depth[1]) {
if (( sizeof(signed char) != sizeof (imgpel)) && testEndian()) if ((sizeof(signed char) != sizeof(imgpel)) && testEndian())
p_Vid->buf2img = buf2img_endian; p_Vid->buf2img = buf2img_endian;
else else
p_Vid->buf2img = buf2img_basic; p_Vid->buf2img = buf2img_basic;
} } else
else
p_Vid->buf2img = buf2img_bitshift; p_Vid->buf2img = buf2img_bitshift;
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
@ -60,16 +65,15 @@ void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output)
* 1, big-endian (e.g. SPARC, MIPS, PowerPC) * 1, big-endian (e.g. SPARC, MIPS, PowerPC)
************************************************************************ ************************************************************************
*/ */
int testEndian(void) int testEndian(void) {
{
short s; short s;
byte *p; byte *p;
p=(byte*)&s; p = (byte *)&s;
s=1; s = 1;
return (*p==0); return (*p == 0);
} }
#if (DEBUG_BITDEPTH) #if (DEBUG_BITDEPTH)
@ -79,15 +83,12 @@ int testEndian(void)
* Masking to ensure data within appropriate range * Masking to ensure data within appropriate range
************************************************************************ ************************************************************************
*/ */
static void MaskMSBs (imgpel** imgX, int mask, int width, int height) static void MaskMSBs(imgpel **imgX, int mask, int width, int height) {
{ int i, j;
int i,j;
for (j=0; j < height; j++) for (j = 0; j < height; j++) {
{ for (i = 0; i < width; i++) {
for (i=0; i < width; i++) imgX[j][i] = (imgpel)(imgX[j][i] & mask);
{
imgX[j][i]=(imgpel) (imgX[j][i] & mask);
} }
} }
} }
@ -99,25 +100,19 @@ static void MaskMSBs (imgpel** imgX, int mask, int width, int height)
* Fill plane with constant value * Fill plane with constant value
************************************************************************ ************************************************************************
*/ */
void fillPlane ( imgpel** imgX, //!< Pointer to image plane void fillPlane(imgpel **imgX, //!< Pointer to image plane
int nVal, //!< Fill value (currently 0 <= nVal < 256) int nVal, //!< Fill value (currently 0 <= nVal < 256)
int size_x, //!< horizontal size of picture int size_x, //!< horizontal size of picture
int size_y //!< vertical size of picture int size_y //!< vertical size of picture
) ) {
{
int j, i; int j, i;
if (sizeof(imgpel) == sizeof(signed char)) if (sizeof(imgpel) == sizeof(signed char)) {
{
memset(imgX[0], nVal, size_y * size_x); memset(imgX[0], nVal, size_y * size_x);
} } else {
else for (j = 0; j < size_y; j++) {
{ for (i = 0; i < size_x; i++) {
for (j = 0; j < size_y; j++) imgX[j][i] = (imgpel)nVal;
{
for (i = 0; i < size_x; i++)
{
imgX[j][i] = (imgpel) nVal;
} }
} }
} }
@ -129,12 +124,12 @@ void fillPlane ( imgpel** imgX, //!< Pointer to image plane
* Deinterleave file read buffer to source picture structure * Deinterleave file read buffer to source picture structure
************************************************************************ ************************************************************************
*/ */
static void deinterleave ( unsigned char** input, //!< input buffer static void
unsigned char** output, //!< output buffer deinterleave(unsigned char **input, //!< input buffer
FrameFormat *source, //!< format of source buffer unsigned char **output, //!< output buffer
int symbol_size_in_bytes //!< number of bytes per symbol FrameFormat *source, //!< format of source buffer
) int symbol_size_in_bytes //!< number of bytes per symbol
{ ) {
// original buffer // original buffer
unsigned char *icmp0 = *input; unsigned char *icmp0 = *input;
// final buffer // final buffer
@ -144,11 +139,10 @@ static void deinterleave ( unsigned char** input, //!< input buffer
unsigned char *ocmp2 = ocmp1 + symbol_size_in_bytes * source->size_cmp[1]; unsigned char *ocmp2 = ocmp1 + symbol_size_in_bytes * source->size_cmp[1];
int i; int i;
if (source->yuv_format == YUV420) // UYYVYY if (source->yuv_format == YUV420) // UYYVYY
{ {
for (i = 0; i < source->size_cmp[1]; i++) for (i = 0; i < source->size_cmp[1]; i++) {
{
memcpy(ocmp1, icmp0, symbol_size_in_bytes); memcpy(ocmp1, icmp0, symbol_size_in_bytes);
ocmp1 += symbol_size_in_bytes; ocmp1 += symbol_size_in_bytes;
icmp0 += symbol_size_in_bytes; icmp0 += symbol_size_in_bytes;
@ -164,14 +158,14 @@ static void deinterleave ( unsigned char** input, //!< input buffer
} }
// flip buffers // flip buffers
icmp0 = *input; icmp0 = *input;
*input = *output; *input = *output;
*output = icmp0; *output = icmp0;
} }
if (source->yuv_format == YUV422) // YUYV/YUY2. We should also maybe add UYVY given it's popularity if (source->yuv_format ==
YUV422) // YUYV/YUY2. We should also maybe add UYVY given it's popularity
{ {
for (i = 0; i < source->size_cmp[1]; i++) for (i = 0; i < source->size_cmp[1]; i++) {
{
// Y // Y
memcpy(ocmp0, icmp0, symbol_size_in_bytes); memcpy(ocmp0, icmp0, symbol_size_in_bytes);
ocmp0 += symbol_size_in_bytes; ocmp0 += symbol_size_in_bytes;
@ -191,14 +185,11 @@ static void deinterleave ( unsigned char** input, //!< input buffer
} }
// flip buffers // flip buffers
icmp0 = *input; icmp0 = *input;
*input = *output; *input = *output;
*output = icmp0; *output = icmp0;
} } else if (source->yuv_format == YUV444) {
else if (source->yuv_format == YUV444) for (i = 0; i < source->size_cmp[0]; i++) {
{
for (i = 0; i < source->size_cmp[0]; i++)
{
memcpy(ocmp0, icmp0, symbol_size_in_bytes); memcpy(ocmp0, icmp0, symbol_size_in_bytes);
ocmp0 += symbol_size_in_bytes; ocmp0 += symbol_size_in_bytes;
icmp0 += symbol_size_in_bytes; icmp0 += symbol_size_in_bytes;
@ -210,8 +201,8 @@ static void deinterleave ( unsigned char** input, //!< input buffer
icmp0 += symbol_size_in_bytes; icmp0 += symbol_size_in_bytes;
} }
// flip buffers // flip buffers
icmp0 = *input; icmp0 = *input;
*input = *output; *input = *output;
*output = icmp0; *output = icmp0;
} }
} }
@ -222,235 +213,236 @@ static void deinterleave ( unsigned char** input, //!< input buffer
* Convert file read buffer to source picture structure * Convert file read buffer to source picture structure
************************************************************************ ************************************************************************
*/ */
void buf2img_bitshift ( imgpel** imgX, //!< Pointer to image plane void buf2img_bitshift(
unsigned char* buf, //!< Buffer for file output imgpel **imgX, //!< Pointer to image plane
int size_x, //!< horizontal size of picture unsigned char *buf, //!< Buffer for file output
int size_y, //!< vertical size of picture int size_x, //!< horizontal size of picture
int o_size_x, //!< horizontal size of picture int size_y, //!< vertical size of picture
int o_size_y, //!< vertical size of picture int o_size_x, //!< horizontal size of picture
int symbol_size_in_bytes, //!< number of bytes in file used for one pixel int o_size_y, //!< vertical size of picture
int bitshift //!< variable for bitdepth expansion int symbol_size_in_bytes, //!< number of bytes in file used for one pixel
) int bitshift //!< variable for bitdepth expansion
{ ) {
int i,j; int i, j;
uint16 tmp16, ui16; uint16 tmp16, ui16;
unsigned long tmp32, ui32; unsigned long tmp32, ui32;
// This test should be done once. // This test should be done once.
if (((symbol_size_in_bytes << 3) - bitshift) > (int) (sizeof(imgpel)<< 3)) if (((symbol_size_in_bytes << 3) - bitshift) > (int)(sizeof(imgpel) << 3)) {
{ error("Source picture has higher bit depth than imgpel data type. \nPlease "
error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); "recompile with larger data type for imgpel.",
500);
} }
if (testEndian()) if (testEndian()) {
{ if (size_x != o_size_x || size_y != o_size_y) {
if (size_x != o_size_x || size_y != o_size_y) error("Rescaling not supported in big endian architectures. ", 500);
{
error ("Rescaling not supported in big endian architectures. ", 500);
} }
// big endian // big endian
switch (symbol_size_in_bytes) switch (symbol_size_in_bytes) {
{ case 1: {
case 1: for (j = 0; j < o_size_y; j++)
{ for (i = 0; i < o_size_x; i++) {
for(j = 0; j < o_size_y; j++) imgX[j][i] = (imgpel)rshift_rnd(buf[i + j * size_x], bitshift);
for(i = 0; i < o_size_x; i++) }
{ break;
imgX[j][i]= (imgpel) rshift_rnd(buf[i + j*size_x], bitshift); }
} case 2: {
break; for (j = 0; j < o_size_y; j++)
for (i = 0; i < o_size_x; i++) {
memcpy(&tmp16, buf + ((i + j * size_x) * 2), 2);
ui16 = (tmp16 >> 8) | ((tmp16 & 0xFF) << 8);
imgX[j][i] = (imgpel)rshift_rnd(ui16, bitshift);
}
break;
}
case 4: {
for (j = 0; j < o_size_y; j++)
for (i = 0; i < o_size_x; i++) {
memcpy(&tmp32, buf + ((i + j * size_x) * 4), 4);
ui32 = ((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) |
((tmp32 & 0xFF0000) >> 8) | ((tmp32 & 0xFF000000) >> 24);
imgX[j][i] = (imgpel)rshift_rnd(ui32, bitshift);
}
}
default: {
error("reading only from formats of 8, 16 or 32 bit allowed on big "
"endian architecture",
500);
break;
}
}
} else {
// little endian
int j_pos;
if (size_x == o_size_x && size_y == o_size_y) {
for (j = 0; j < o_size_y; j++) {
j_pos = j * size_x;
for (i = 0; i < o_size_x; i++) {
ui16 = 0;
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes),
symbol_size_in_bytes);
imgX[j][i] = (imgpel)rshift_rnd(ui16, bitshift);
}
} }
case 2: } else {
{ int iminwidth = imin(size_x, o_size_x);
for(j = 0; j < o_size_y; j++) int iminheight = imin(size_y, o_size_y);
for(i = 0; i < o_size_x; i++) int dst_offset_x = 0, dst_offset_y = 0;
{ int offset_x = 0, offset_y = 0; // currently not used
memcpy(&tmp16, buf+((i+j*size_x)*2), 2);
ui16 = (tmp16 >> 8) | ((tmp16&0xFF)<<8); // determine whether we need to center the copied frame or crop it
imgX[j][i] = (imgpel) rshift_rnd(ui16, bitshift); if (o_size_x >= size_x)
} dst_offset_x = (o_size_x - size_x) >> 1;
break;
} if (o_size_y >= size_y)
case 4: dst_offset_y = (o_size_y - size_y) >> 1;
{
for(j = 0; j < o_size_y; j++) // check copied area to avoid copying memory garbage
for(i = 0; i < o_size_x; i++) // source
{ iminwidth =
memcpy(&tmp32, buf+((i+j*size_x)*4), 4); ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth;
ui32 = ((tmp32&0xFF00)<<8) | ((tmp32&0xFF)<<24) | ((tmp32&0xFF0000)>>8) | ((tmp32&0xFF000000)>>24); iminheight =
imgX[j][i] = (imgpel) rshift_rnd(ui32, bitshift); ((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight;
} // destination
} iminwidth = ((dst_offset_x + iminwidth) > o_size_x)
default: ? (o_size_x - dst_offset_x)
{ : iminwidth;
error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500); iminheight = ((dst_offset_y + iminheight) > o_size_y)
break; ? (o_size_y - dst_offset_y)
: iminheight;
for (j = 0; j < iminheight; j++) {
j_pos = (j + offset_y) * size_x + offset_x;
for (i = 0; i < iminwidth; i++) {
ui16 = 0;
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes),
symbol_size_in_bytes);
imgX[j + dst_offset_y][i + dst_offset_x] =
(imgpel)rshift_rnd(ui16, bitshift);
}
} }
} }
} }
else
{
// little endian
int j_pos;
if (size_x == o_size_x && size_y == o_size_y)
{
for (j = 0; j < o_size_y; j++)
{
j_pos = j*size_x;
for (i = 0; i < o_size_x; i++)
{
ui16=0;
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes);
imgX[j][i] = (imgpel) rshift_rnd(ui16,bitshift);
}
}
}
else
{
int iminwidth = imin(size_x, o_size_x);
int iminheight = imin(size_y, o_size_y);
int dst_offset_x = 0, dst_offset_y = 0;
int offset_x = 0, offset_y = 0; // currently not used
// determine whether we need to center the copied frame or crop it
if ( o_size_x >= size_x )
dst_offset_x = ( o_size_x - size_x ) >> 1;
if (o_size_y >= size_y)
dst_offset_y = ( o_size_y - size_y ) >> 1;
// check copied area to avoid copying memory garbage
// source
iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth;
iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight;
// destination
iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth;
iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight;
for (j=0; j < iminheight; j++)
{
j_pos = (j + offset_y) * size_x + offset_x;
for (i=0; i < iminwidth; i++)
{
ui16=0;
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes);
imgX[j + dst_offset_y][i + dst_offset_x] = (imgpel) rshift_rnd(ui16,bitshift);
}
}
}
}
} }
/*! /*!
************************************************************************ ************************************************************************
* \brief * \brief
* Convert file read buffer to source picture structure * Convert file read buffer to source picture structure
************************************************************************ ************************************************************************
*/ */
void buf2img_basic (imgpel** imgX, //!< Pointer to image plane void buf2img_basic(
unsigned char* buf, //!< Buffer for file output imgpel **imgX, //!< Pointer to image plane
int size_x, //!< horizontal size of picture unsigned char *buf, //!< Buffer for file output
int size_y, //!< vertical size of picture int size_x, //!< horizontal size of picture
int o_size_x, //!< horizontal size of picture int size_y, //!< vertical size of picture
int o_size_y, //!< vertical size of picture int o_size_x, //!< horizontal size of picture
int symbol_size_in_bytes, //!< number of bytes in file used for one pixel int o_size_y, //!< vertical size of picture
int dummy //!< dummy variable used for allowing function pointer use int symbol_size_in_bytes, //!< number of bytes in file used for one pixel
) int dummy //!< dummy variable used for allowing function pointer use
{ ) {
int i,j; int i, j;
unsigned char* temp_buf = buf; unsigned char *temp_buf = buf;
if (symbol_size_in_bytes> (int) sizeof(imgpel)) if (symbol_size_in_bytes > (int)sizeof(imgpel)) {
{ error("Source picture has higher bit depth than imgpel data type. \nPlease "
error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); "recompile with larger data type for imgpel.",
500);
} }
if (( sizeof (imgpel) == symbol_size_in_bytes)) if ((sizeof(imgpel) == symbol_size_in_bytes)) {
{
// imgpel == pixel_in_file -> simple copy // imgpel == pixel_in_file -> simple copy
if (size_x == o_size_x && size_y == o_size_y) if (size_x == o_size_x && size_y == o_size_y)
memcpy(&imgX[0][0], temp_buf, size_x * size_y * sizeof(imgpel)); memcpy(&imgX[0][0], temp_buf, size_x * size_y * sizeof(imgpel));
else else {
{ int iminwidth = imin(size_x, o_size_x);
int iminwidth = imin(size_x, o_size_x); int iminheight = imin(size_y, o_size_y);
int iminheight = imin(size_y, o_size_y); int dst_offset_x = 0, dst_offset_y = 0;
int dst_offset_x = 0, dst_offset_y = 0;
int offset_x = 0, offset_y = 0; // currently not used int offset_x = 0, offset_y = 0; // currently not used
// determine whether we need to center the copied frame or crop it
if ( o_size_x >= size_x )
dst_offset_x = ( o_size_x - size_x ) >> 1;
if (o_size_y >= size_y) // determine whether we need to center the copied frame or crop it
dst_offset_y = ( o_size_y - size_y ) >> 1; if (o_size_x >= size_x)
dst_offset_x = (o_size_x - size_x) >> 1;
if (o_size_y >= size_y)
dst_offset_y = (o_size_y - size_y) >> 1;
// check copied area to avoid copying memory garbage // check copied area to avoid copying memory garbage
// source // source
iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth; iminwidth =
iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight; ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth;
iminheight =
((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight;
// destination // destination
iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth; iminwidth = ((dst_offset_x + iminwidth) > o_size_x)
iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight; ? (o_size_x - dst_offset_x)
: iminwidth;
iminheight = ((dst_offset_y + iminheight) > o_size_y)
? (o_size_y - dst_offset_y)
: iminheight;
for (i=0; i<iminheight;i++) { for (i = 0; i < iminheight; i++) {
memcpy(&imgX[i + dst_offset_y][dst_offset_x], &(temp_buf[(i + offset_y) * size_x + offset_x]), iminwidth * sizeof(imgpel)); memcpy(&imgX[i + dst_offset_y][dst_offset_x],
&(temp_buf[(i + offset_y) * size_x + offset_x]),
iminwidth * sizeof(imgpel));
} }
} }
} } else {
else
{
int j_pos; int j_pos;
uint16 ui16; uint16 ui16;
if (size_x == o_size_x && size_y == o_size_y) if (size_x == o_size_x && size_y == o_size_y) {
{ for (j = 0; j < o_size_y; j++) {
for (j=0; j < o_size_y; j++)
{
j_pos = j * size_x; j_pos = j * size_x;
for (i=0; i < o_size_x; i++) for (i = 0; i < o_size_x; i++) {
{ ui16 = 0;
ui16=0; memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes),
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes); symbol_size_in_bytes);
imgX[j][i]= (imgpel) ui16; imgX[j][i] = (imgpel)ui16;
} }
} }
} } else {
else int iminwidth = imin(size_x, o_size_x);
{ int iminheight = imin(size_y, o_size_y);
int iminwidth = imin(size_x, o_size_x); int dst_offset_x = 0, dst_offset_y = 0;
int iminheight = imin(size_y, o_size_y);
int dst_offset_x = 0, dst_offset_y = 0;
int offset_x = 0, offset_y = 0; // currently not used int offset_x = 0, offset_y = 0; // currently not used
// determine whether we need to center the copied frame or crop it
if ( o_size_x >= size_x )
dst_offset_x = ( o_size_x - size_x ) >> 1;
if (o_size_y >= size_y) // determine whether we need to center the copied frame or crop it
dst_offset_y = ( o_size_y - size_y ) >> 1; if (o_size_x >= size_x)
dst_offset_x = (o_size_x - size_x) >> 1;
if (o_size_y >= size_y)
dst_offset_y = (o_size_y - size_y) >> 1;
// check copied area to avoid copying memory garbage // check copied area to avoid copying memory garbage
// source // source
iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth; iminwidth =
iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight; ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth;
iminheight =
((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight;
// destination // destination
iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth; iminwidth = ((dst_offset_x + iminwidth) > o_size_x)
iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight; ? (o_size_x - dst_offset_x)
: iminwidth;
iminheight = ((dst_offset_y + iminheight) > o_size_y)
? (o_size_y - dst_offset_y)
: iminheight;
for (j = 0; j < iminheight; j++) { for (j = 0; j < iminheight; j++) {
memcpy(&imgX[j + dst_offset_y][dst_offset_x], &(temp_buf[(j + offset_y) * size_x + offset_x]), iminwidth * sizeof(imgpel)); memcpy(&imgX[j + dst_offset_y][dst_offset_x],
&(temp_buf[(j + offset_y) * size_x + offset_x]),
iminwidth * sizeof(imgpel));
} }
for (j=0; j < iminheight; j++) for (j = 0; j < iminheight; j++) {
{
j_pos = (j + offset_y) * size_x + offset_x; j_pos = (j + offset_y) * size_x + offset_x;
for (i=0; i < iminwidth; i++) for (i = 0; i < iminwidth; i++) {
{
ui16 = 0; ui16 = 0;
memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes); memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes),
imgX[j + dst_offset_y][i + dst_offset_x]= (imgpel) ui16; symbol_size_in_bytes);
imgX[j + dst_offset_y][i + dst_offset_x] = (imgpel)ui16;
} }
} }
} }
} }
} }
@ -461,77 +453,69 @@ void buf2img_basic (imgpel** imgX, //!< Pointer to image plane
* Convert file read buffer to source picture structure * Convert file read buffer to source picture structure
************************************************************************ ************************************************************************
*/ */
void buf2img_endian (imgpel** imgX, //!< Pointer to image plane void buf2img_endian(
unsigned char* buf, //!< Buffer for file output imgpel **imgX, //!< Pointer to image plane
int size_x, //!< horizontal size of picture unsigned char *buf, //!< Buffer for file output
int size_y, //!< vertical size of picture int size_x, //!< horizontal size of picture
int o_size_x, //!< horizontal size of picture int size_y, //!< vertical size of picture
int o_size_y, //!< vertical size of picture int o_size_x, //!< horizontal size of picture
int symbol_size_in_bytes, //!< number of bytes in file used for one pixel int o_size_y, //!< vertical size of picture
int dummy //!< dummy variable used for allowing function pointer use int symbol_size_in_bytes, //!< number of bytes in file used for one pixel
) int dummy //!< dummy variable used for allowing function pointer use
{ ) {
int i,j; int i, j;
uint16 tmp16, ui16; uint16 tmp16, ui16;
unsigned long tmp32, ui32; unsigned long tmp32, ui32;
if (symbol_size_in_bytes > (int) sizeof(imgpel)) if (symbol_size_in_bytes > (int)sizeof(imgpel)) {
{ error("Source picture has higher bit depth than imgpel data type. \nPlease "
error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); "recompile with larger data type for imgpel.",
500);
} }
if (size_x != o_size_x || size_y != o_size_y) if (size_x != o_size_x || size_y != o_size_y) {
{ error("Rescaling not supported in big endian architectures. ", 500);
error ("Rescaling not supported in big endian architectures. ", 500);
} }
// big endian // big endian
switch (symbol_size_in_bytes) switch (symbol_size_in_bytes) {
{ case 1: {
case 1: for (j = 0; j < size_y; j++) {
{ for (i = 0; i < size_x; i++) {
for(j=0;j<size_y;j++) imgX[j][i] = (imgpel)buf[i + j * size_x];
{
for(i=0;i<size_x;i++)
{
imgX[j][i]= (imgpel) buf[i + j*size_x];
}
} }
break;
} }
case 2: break;
{ }
for(j=0;j<size_y;j++) case 2: {
{ for (j = 0; j < size_y; j++) {
for(i=0;i<size_x;i++) for (i = 0; i < size_x; i++) {
{ memcpy(&tmp16, buf + ((i + j * size_x) * 2), 2);
memcpy(&tmp16, buf+((i+j*size_x)*2), 2); ui16 = (tmp16 >> 8) | ((tmp16 & 0xFF) << 8);
ui16 = (tmp16 >> 8) | ((tmp16&0xFF)<<8); imgX[j][i] = (imgpel)ui16;
imgX[j][i] = (imgpel) ui16;
}
} }
break;
} }
case 4: break;
{ }
for(j=0;j<size_y;j++) case 4: {
{ for (j = 0; j < size_y; j++) {
for(i=0;i<size_x;i++) for (i = 0; i < size_x; i++) {
{ memcpy(&tmp32, buf + ((i + j * size_x) * 4), 4);
memcpy(&tmp32, buf+((i+j*size_x)*4), 4); ui32 = ((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) |
ui32 = ((tmp32&0xFF00)<<8) | ((tmp32&0xFF)<<24) | ((tmp32&0xFF0000)>>8) | ((tmp32&0xFF000000)>>24); ((tmp32 & 0xFF0000) >> 8) | ((tmp32 & 0xFF000000) >> 24);
imgX[j][i] = (imgpel) ui32; imgX[j][i] = (imgpel)ui32;
}
} }
break;
} }
default: break;
{ }
error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500); default: {
break; error("reading only from formats of 8, 16 or 32 bit allowed on big endian "
} "architecture",
} 500);
break;
}
}
} }
/*! /*!
@ -541,13 +525,14 @@ void buf2img_endian (imgpel** imgX, //!< Pointer to image plane
* *
************************************************************************ ************************************************************************
*/ */
void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameFormat *source) void AllocateFrameMemory(VideoParameters *p_Vid, InputParameters *p_Inp,
{ FrameFormat *source) {
if (NULL == (p_Vid->buf = malloc (source->size * source->pic_unit_size_shift3))) if (NULL ==
(p_Vid->buf = malloc(source->size * source->pic_unit_size_shift3)))
no_mem_exit("AllocateFrameMemory: p_Vid->buf"); no_mem_exit("AllocateFrameMemory: p_Vid->buf");
if (p_Inp->input_file1.is_interleaved) if (p_Inp->input_file1.is_interleaved) {
{ if (NULL ==
if (NULL == (p_Vid->ibuf = malloc (source->size * source->pic_unit_size_shift3))) (p_Vid->ibuf = malloc(source->size * source->pic_unit_size_shift3)))
no_mem_exit("AllocateFrameMemory: p_Vid->ibuf"); no_mem_exit("AllocateFrameMemory: p_Vid->ibuf");
} }
} }
@ -559,12 +544,11 @@ void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameF
* *
************************************************************************ ************************************************************************
*/ */
void DeleteFrameMemory (VideoParameters *p_Vid) void DeleteFrameMemory(VideoParameters *p_Vid) {
{
if (p_Vid->buf != NULL) if (p_Vid->buf != NULL)
free (p_Vid->buf); free(p_Vid->buf);
if (p_Vid->ibuf != NULL) if (p_Vid->ibuf != NULL)
free (p_Vid->ibuf); free(p_Vid->ibuf);
} }
/*! /*!
@ -579,87 +563,98 @@ void DeleteFrameMemory (VideoParameters *p_Vid)
* \param HeaderSize * \param HeaderSize
* Number of bytes in the source file to be skipped * Number of bytes in the source file to be skipped
* \param source * \param source
* source file (on disk) information * source file (on disk) information
* \param output * \param output
* output file (for encoding) information * output file (for encoding) information
* \param pImage * \param pImage
* Image planes * Image planes
************************************************************************ ************************************************************************
*/ */
int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, FrameFormat *output, imgpel **pImage[3]) int read_one_frame(VideoParameters *p_Vid, VideoDataFile *input_file,
{ int FrameNoInFile, int HeaderSize, FrameFormat *source,
FrameFormat *output, imgpel **pImage[3]) {
InputParameters *p_Inp = p_Vid->p_Inp; InputParameters *p_Inp = p_Vid->p_Inp;
int file_read = 0; int file_read = 0;
unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3; unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3;
const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes; const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes;
const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes; const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes;
int bit_scale; int bit_scale;
Boolean rgb_input = (Boolean) (source->color_model == CM_RGB && source->yuv_format == YUV444); Boolean rgb_input =
(Boolean)(source->color_model == CM_RGB && source->yuv_format == YUV444);
if (input_file->is_concatenated == 0) if (input_file->is_concatenated == 0) {
{ if (input_file->vdtype == VIDEO_TIFF) {
if (input_file->vdtype == VIDEO_TIFF) file_read =
{ ReadTIFFImage(p_Inp, input_file, FrameNoInFile, source, p_Vid->buf);
file_read = ReadTIFFImage (p_Inp, input_file, FrameNoInFile, source, p_Vid->buf); } else {
file_read = ReadFrameSeparate(p_Inp, input_file, FrameNoInFile,
HeaderSize, source, p_Vid->buf);
} }
else } else {
{ file_read = ReadFrameConcatenated(p_Inp, input_file, FrameNoInFile,
file_read = ReadFrameSeparate (p_Inp, input_file, FrameNoInFile, HeaderSize, source, p_Vid->buf); HeaderSize, source, p_Vid->buf);
} }
} if (!file_read) {
else
{
file_read = ReadFrameConcatenated (p_Inp, input_file, FrameNoInFile, HeaderSize, source, p_Vid->buf);
}
if ( !file_read )
{
return 0; return 0;
} }
// Deinterleave input source // Deinterleave input source
if (input_file->is_interleaved) if (input_file->is_interleaved) {
{ deinterleave(&p_Vid->buf, &p_Vid->ibuf, source, symbol_size_in_bytes);
deinterleave ( &p_Vid->buf, &p_Vid->ibuf, source, symbol_size_in_bytes); }
}
bit_scale = source->bit_depth[0] - output->bit_depth[0]; bit_scale = source->bit_depth[0] - output->bit_depth[0];
if(rgb_input) if (rgb_input)
p_Vid->buf2img(pImage[0], p_Vid->buf + bytes_y, source->width[0], source->height[0], output->width[0], output->height[0], symbol_size_in_bytes, bit_scale); p_Vid->buf2img(pImage[0], p_Vid->buf + bytes_y, source->width[0],
else source->height[0], output->width[0], output->height[0],
p_Vid->buf2img(pImage[0], p_Vid->buf, source->width[0], source->height[0], output->width[0], output->height[0], symbol_size_in_bytes, bit_scale); symbol_size_in_bytes, bit_scale);
else
p_Vid->buf2img(pImage[0], p_Vid->buf, source->width[0], source->height[0],
output->width[0], output->height[0], symbol_size_in_bytes,
bit_scale);
#if (DEBUG_BITDEPTH) #if (DEBUG_BITDEPTH)
MaskMSBs(pImage[0], ((1 << output->bit_depth[0]) - 1), output->width[0], output->height[0]); MaskMSBs(pImage[0], ((1 << output->bit_depth[0]) - 1), output->width[0],
output->height[0]);
#endif #endif
if (p_Vid->yuv_format != YUV400) if (p_Vid->yuv_format != YUV400) {
{ bit_scale = source->bit_depth[1] - output->bit_depth[1];
bit_scale = source->bit_depth[1] - output->bit_depth[1];
#if (ALLOW_GRAYSCALE) #if (ALLOW_GRAYSCALE)
if (!p_Inp->grayscale) if (!p_Inp->grayscale)
#endif #endif
{ {
if(rgb_input) if (rgb_input)
p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y + bytes_uv, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y + bytes_uv,
else source->width[1], source->height[1], output->width[1],
p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); output->height[1], symbol_size_in_bytes, bit_scale);
else
p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y, source->width[1],
source->height[1], output->width[1], output->height[1],
symbol_size_in_bytes, bit_scale);
bit_scale = source->bit_depth[2] - output->bit_depth[2]; bit_scale = source->bit_depth[2] - output->bit_depth[2];
if(rgb_input) if (rgb_input)
p_Vid->buf2img(pImage[2], p_Vid->buf, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); p_Vid->buf2img(pImage[2], p_Vid->buf, source->width[1],
else source->height[1], output->width[1], output->height[1],
p_Vid->buf2img(pImage[2], p_Vid->buf + bytes_y + bytes_uv, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); symbol_size_in_bytes, bit_scale);
} else
p_Vid->buf2img(pImage[2], p_Vid->buf + bytes_y + bytes_uv,
source->width[1], source->height[1], output->width[1],
output->height[1], symbol_size_in_bytes, bit_scale);
}
#if (DEBUG_BITDEPTH) #if (DEBUG_BITDEPTH)
MaskMSBs(pImage[1], ((1 << output->bit_depth[1]) - 1), output->width[1], output->height[1]); MaskMSBs(pImage[1], ((1 << output->bit_depth[1]) - 1), output->width[1],
MaskMSBs(pImage[2], ((1 << output->bit_depth[2]) - 1), output->width[1], output->height[1]); output->height[1]);
MaskMSBs(pImage[2], ((1 << output->bit_depth[2]) - 1), output->width[1],
output->height[1]);
#endif #endif
} }
return file_read; return file_read;
} }
/*! /*!
@ -682,39 +677,38 @@ int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int Frame
* image planes * image planes
************************************************************************ ************************************************************************
*/ */
void pad_borders (FrameFormat output, int img_size_x, int img_size_y, int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]) void pad_borders(FrameFormat output, int img_size_x, int img_size_y,
{ int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]) {
int x, y; int x, y;
// Luma or 1st component // Luma or 1st component
//padding right border // padding right border
if (output.width[0] < img_size_x) if (output.width[0] < img_size_x)
for (y=0; y < output.height[0]; y++) for (y = 0; y < output.height[0]; y++)
for (x = output.width[0]; x < img_size_x; x++) for (x = output.width[0]; x < img_size_x; x++)
pImage[0] [y][x] = pImage[0][y][x-1]; pImage[0][y][x] = pImage[0][y][x - 1];
//padding bottom border // padding bottom border
if (output.height[0] < img_size_y) if (output.height[0] < img_size_y)
for (y = output.height[0]; y<img_size_y; y++) for (y = output.height[0]; y < img_size_y; y++)
memcpy(pImage[0][y], pImage[0][y - 1], img_size_x * sizeof(imgpel)); memcpy(pImage[0][y], pImage[0][y - 1], img_size_x * sizeof(imgpel));
// Chroma or all other components // Chroma or all other components
if (output.yuv_format != YUV400) if (output.yuv_format != YUV400) {
{
int k; int k;
for (k = 1; k < 3; k++) for (k = 1; k < 3; k++) {
{ // padding right border
//padding right border
if (output.width[1] < img_size_x_cr) if (output.width[1] < img_size_x_cr)
for (y=0; y < output.height[1]; y++) for (y = 0; y < output.height[1]; y++)
for (x = output.width[1]; x < img_size_x_cr; x++) for (x = output.width[1]; x < img_size_x_cr; x++)
pImage [k][y][x] = pImage[k][y][x-1]; pImage[k][y][x] = pImage[k][y][x - 1];
//padding bottom border // padding bottom border
if (output.height[1] < img_size_y_cr) if (output.height[1] < img_size_y_cr)
for (y = output.height[1]; y < img_size_y_cr; y++) for (y = output.height[1]; y < img_size_y_cr; y++)
memcpy(pImage[k][y], pImage[k][y - 1], img_size_x_cr * sizeof(imgpel)); memcpy(pImage[k][y], pImage[k][y - 1],
img_size_x_cr * sizeof(imgpel));
} }
} }
} }

View file

@ -6,42 +6,39 @@
* Functions for intra 16x16 prediction * Functions for intra 16x16 prediction
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Alexis Michael Tourapis <alexismt@ieee.org> * - Alexis Michael Tourapis <alexismt@ieee.org>
* *
************************************************************************************* *************************************************************************************
*/ */
#include "global.h"
#include "intra16x16_pred.h" #include "intra16x16_pred.h"
#include "mb_access.h" #include "global.h"
#include "image.h" #include "image.h"
#include "mb_access.h"
extern int intrapred_16x16_mbaff(Macroblock *currMB, ColorPlane pl,
extern int intrapred_16x16_mbaff (Macroblock *currMB, ColorPlane pl, int predmode); int predmode);
extern int intrapred_16x16_normal(Macroblock *currMB, ColorPlane pl, int predmode); extern int intrapred_16x16_normal(Macroblock *currMB, ColorPlane pl,
int predmode);
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* makes and returns 16x16 intra prediction blocks * makes and returns 16x16 intra prediction blocks
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* SEARCH_SYNC search next sync element as errors while decoding occured * SEARCH_SYNC search next sync element as errors while decoding occured
*********************************************************************** ***********************************************************************
*/ */
int intrapred16x16(Macroblock *currMB, //!< Current Macroblock int intrapred16x16(Macroblock *currMB, //!< Current Macroblock
ColorPlane pl, //!< Current colorplane (for 4:4:4) ColorPlane pl, //!< Current colorplane (for 4:4:4)
int predmode) //!< prediction mode int predmode) //!< prediction mode
{ {
if (currMB->p_Slice->mb_aff_frame_flag) if (currMB->p_Slice->mb_aff_frame_flag) {
{
return intrapred_16x16_mbaff(currMB, pl, predmode); return intrapred_16x16_mbaff(currMB, pl, predmode);
} } else {
else
{
return intrapred_16x16_normal(currMB, pl, predmode); return intrapred_16x16_normal(currMB, pl, predmode);
} }
} }

View file

@ -6,7 +6,7 @@
* Functions for intra 16x16 prediction (MBAFF) * Functions for intra 16x16 prediction (MBAFF)
* *
* \author * \author
* Main contributors (see contributors.h for copyright, * Main contributors (see contributors.h for copyright,
* address and affiliation details) * address and affiliation details)
* - Yuri Vatis * - Yuri Vatis
* - Jan Muenster * - Jan Muenster
@ -15,9 +15,9 @@
************************************************************************************* *************************************************************************************
*/ */
#include "global.h" #include "global.h"
#include "image.h"
#include "intra16x16_pred.h" #include "intra16x16_pred.h"
#include "mb_access.h" #include "mb_access.h"
#include "image.h"
/*! /*!
*********************************************************************** ***********************************************************************
@ -25,73 +25,69 @@
* makes and returns 16x16 DC prediction mode * makes and returns 16x16 DC prediction mode
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* *
*********************************************************************** ***********************************************************************
*/ */
static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl) static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl) {
{
Slice *currSlice = currMB->p_Slice; Slice *currSlice = currMB->p_Slice;
VideoParameters *p_Vid = currMB->p_Vid; VideoParameters *p_Vid = currMB->p_Vid;
int s0 = 0, s1 = 0, s2 = 0; int s0 = 0, s1 = 0, s2 = 0;
int i,j; int i, j;
imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1]
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); : currSlice->dec_picture->imgY;
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
PixelPos b; //!< pixel position p(0,-1) PixelPos b; //!< pixel position p(0,-1)
PixelPos left[17]; //!< pixel positions p(-1, -1..15) PixelPos left[17]; //!< pixel positions p(-1, -1..15)
int up_avail, left_avail, left_up_avail; int up_avail, left_avail, left_up_avail;
s1=s2=0; s1 = s2 = 0;
for (i=0;i<17;++i) for (i = 0; i < 17; ++i) {
{ p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]);
p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]);
} }
p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b);
if (!p_Vid->active_pps->constrained_intra_pred_flag) if (!p_Vid->active_pps->constrained_intra_pred_flag) {
{ up_avail = b.available;
up_avail = b.available; left_avail = left[1].available;
left_avail = left[1].available;
left_up_avail = left[0].available; left_up_avail = left[0].available;
} } else {
else up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0;
{
up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0;
for (i = 1, left_avail = 1; i < 17; ++i) for (i = 1, left_avail = 1; i < 17; ++i)
left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; left_avail &=
left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0;
left_up_avail =
left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0;
} }
for (i = 0; i < MB_BLOCK_SIZE; ++i) for (i = 0; i < MB_BLOCK_SIZE; ++i) {
{
if (up_avail) if (up_avail)
s1 += imgY[b.pos_y][b.pos_x+i]; // sum hor pix s1 += imgY[b.pos_y][b.pos_x + i]; // sum hor pix
if (left_avail) if (left_avail)
s2 += imgY[left[i + 1].pos_y][left[i + 1].pos_x]; // sum vert pix s2 += imgY[left[i + 1].pos_y][left[i + 1].pos_x]; // sum vert pix
} }
if (up_avail && left_avail) if (up_avail && left_avail)
s0 = (s1 + s2 + 16)>>5; // no edge s0 = (s1 + s2 + 16) >> 5; // no edge
else if (!up_avail && left_avail) else if (!up_avail && left_avail)
s0 = (s2 + 8)>>4; // upper edge s0 = (s2 + 8) >> 4; // upper edge
else if (up_avail && !left_avail) else if (up_avail && !left_avail)
s0 = (s1 + 8)>>4; // left edge s0 = (s1 + 8) >> 4; // left edge
else else
s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict from s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict
// from
for(j = 0; j < MB_BLOCK_SIZE; ++j)
{ for (j = 0; j < MB_BLOCK_SIZE; ++j) {
#if (IMGTYPE == 0) #if (IMGTYPE == 0)
memset(mb_pred[j], s0, MB_BLOCK_SIZE * sizeof(imgpel)); memset(mb_pred[j], s0, MB_BLOCK_SIZE * sizeof(imgpel));
#else #else
for(i = 0; i < MB_BLOCK_SIZE; ++i) for (i = 0; i < MB_BLOCK_SIZE; ++i) {
{ mb_pred[j][i] = (imgpel)s0;
mb_pred[j][i]=(imgpel) s0;
} }
#endif #endif
} }
@ -99,51 +95,45 @@ static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl)
return DECODING_OK; return DECODING_OK;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* makes and returns 16x16 vertical prediction mode * makes and returns 16x16 vertical prediction mode
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* *
*********************************************************************** ***********************************************************************
*/ */
static int intra16x16_vert_pred_mbaff(Macroblock *currMB, ColorPlane pl) static int intra16x16_vert_pred_mbaff(Macroblock *currMB, ColorPlane pl) {
{
Slice *currSlice = currMB->p_Slice; Slice *currSlice = currMB->p_Slice;
VideoParameters *p_Vid = currMB->p_Vid; VideoParameters *p_Vid = currMB->p_Vid;
int j; int j;
imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1]
: currSlice->dec_picture->imgY;
PixelPos b; //!< pixel position p(0,-1) PixelPos b; //!< pixel position p(0,-1)
int up_avail; int up_avail;
//getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); // getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b);
p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b);
if (!p_Vid->active_pps->constrained_intra_pred_flag) if (!p_Vid->active_pps->constrained_intra_pred_flag) {
{
up_avail = b.available; up_avail = b.available;
} } else {
else
{
up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0;
} }
if (!up_avail) if (!up_avail)
error ("invalid 16x16 intra pred Mode VERT_PRED_16",500); error("invalid 16x16 intra pred Mode VERT_PRED_16", 500);
{ {
imgpel **prd = &currSlice->mb_pred[pl][0]; imgpel **prd = &currSlice->mb_pred[pl][0];
imgpel *src = &(imgY[b.pos_y][b.pos_x]); imgpel *src = &(imgY[b.pos_y][b.pos_x]);
for(j=0;j<MB_BLOCK_SIZE; j+= 4) for (j = 0; j < MB_BLOCK_SIZE; j += 4) {
{
memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel)); memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel));
memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel)); memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel));
memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel)); memcpy(*prd++, src, MB_BLOCK_SIZE * sizeof(imgpel));
@ -154,56 +144,52 @@ static int intra16x16_vert_pred_mbaff(Macroblock *currMB, ColorPlane pl)
return DECODING_OK; return DECODING_OK;
} }
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* makes and returns 16x16 horizontal prediction mode * makes and returns 16x16 horizontal prediction mode
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* *
*********************************************************************** ***********************************************************************
*/ */
static int intra16x16_hor_pred_mbaff(Macroblock *currMB, ColorPlane pl) static int intra16x16_hor_pred_mbaff(Macroblock *currMB, ColorPlane pl) {
{
Slice *currSlice = currMB->p_Slice; Slice *currSlice = currMB->p_Slice;
VideoParameters *p_Vid = currMB->p_Vid; VideoParameters *p_Vid = currMB->p_Vid;
int i,j; int i, j;
imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1]
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); : currSlice->dec_picture->imgY;
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
imgpel prediction; imgpel prediction;
PixelPos left[17]; //!< pixel positions p(-1, -1..15) PixelPos left[17]; //!< pixel positions p(-1, -1..15)
int left_avail, left_up_avail; int left_avail, left_up_avail;
for (i=0;i<17;++i) for (i = 0; i < 17; ++i) {
{ p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]);
p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]);
} }
if (!p_Vid->active_pps->constrained_intra_pred_flag) if (!p_Vid->active_pps->constrained_intra_pred_flag) {
{ left_avail = left[1].available;
left_avail = left[1].available;
left_up_avail = left[0].available; left_up_avail = left[0].available;
} } else {
else
{
for (i = 1, left_avail = 1; i < 17; ++i) for (i = 1, left_avail = 1; i < 17; ++i)
left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; left_avail &=
left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0;
left_up_avail =
left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0;
} }
if (!left_avail) if (!left_avail)
error ("invalid 16x16 intra pred Mode HOR_PRED_16",500); error("invalid 16x16 intra pred Mode HOR_PRED_16", 500);
for(j = 0; j < MB_BLOCK_SIZE; ++j) for (j = 0; j < MB_BLOCK_SIZE; ++j) {
{ prediction = imgY[left[j + 1].pos_y][left[j + 1].pos_x];
prediction = imgY[left[j+1].pos_y][left[j+1].pos_x]; for (i = 0; i < MB_BLOCK_SIZE; ++i)
for(i = 0; i < MB_BLOCK_SIZE; ++i) mb_pred[j][i] = prediction; // store predicted 16x16 block
mb_pred[j][i]= prediction; // store predicted 16x16 block
} }
return DECODING_OK; return DECODING_OK;
@ -215,74 +201,72 @@ static int intra16x16_hor_pred_mbaff(Macroblock *currMB, ColorPlane pl)
* makes and returns 16x16 horizontal prediction mode * makes and returns 16x16 horizontal prediction mode
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* *
*********************************************************************** ***********************************************************************
*/ */
static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl) static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl) {
{
Slice *currSlice = currMB->p_Slice; Slice *currSlice = currMB->p_Slice;
VideoParameters *p_Vid = currMB->p_Vid; VideoParameters *p_Vid = currMB->p_Vid;
int i,j; int i, j;
int ih = 0, iv = 0; int ih = 0, iv = 0;
int ib,ic,iaa; int ib, ic, iaa;
imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1]
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); : currSlice->dec_picture->imgY;
imgpel **mb_pred = &(currSlice->mb_pred[pl][0]);
imgpel *mpr_line; imgpel *mpr_line;
int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; int max_imgpel_value = p_Vid->max_pel_value_comp[pl];
PixelPos b; //!< pixel position p(0,-1) PixelPos b; //!< pixel position p(0,-1)
PixelPos left[17]; //!< pixel positions p(-1, -1..15) PixelPos left[17]; //!< pixel positions p(-1, -1..15)
int up_avail, left_avail, left_up_avail; int up_avail, left_avail, left_up_avail;
for (i=0;i<17; ++i) for (i = 0; i < 17; ++i) {
{ p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]);
p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]);
} }
p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b);
if (!p_Vid->active_pps->constrained_intra_pred_flag) if (!p_Vid->active_pps->constrained_intra_pred_flag) {
{ up_avail = b.available;
up_avail = b.available; left_avail = left[1].available;
left_avail = left[1].available;
left_up_avail = left[0].available; left_up_avail = left[0].available;
} } else {
else up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0;
{
up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0;
for (i = 1, left_avail = 1; i < 17; ++i) for (i = 1, left_avail = 1; i < 17; ++i)
left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; left_avail &=
left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0;
left_up_avail =
left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0;
} }
if (!up_avail || !left_up_avail || !left_avail) if (!up_avail || !left_up_avail || !left_avail)
error ("invalid 16x16 intra pred Mode PLANE_16",500); error("invalid 16x16 intra pred Mode PLANE_16", 500);
mpr_line = &imgY[b.pos_y][b.pos_x+7]; mpr_line = &imgY[b.pos_y][b.pos_x + 7];
for (i = 1; i < 8; ++i) for (i = 1; i < 8; ++i) {
{ ih += i * (mpr_line[i] - mpr_line[-i]);
ih += i*(mpr_line[i] - mpr_line[-i]); iv += i * (imgY[left[8 + i].pos_y][left[8 + i].pos_x] -
iv += i*(imgY[left[8+i].pos_y][left[8+i].pos_x] - imgY[left[8-i].pos_y][left[8-i].pos_x]); imgY[left[8 - i].pos_y][left[8 - i].pos_x]);
} }
ih += 8*(mpr_line[8] - imgY[left[0].pos_y][left[0].pos_x]); ih += 8 * (mpr_line[8] - imgY[left[0].pos_y][left[0].pos_x]);
iv += 8*(imgY[left[16].pos_y][left[16].pos_x] - imgY[left[0].pos_y][left[0].pos_x]); iv += 8 * (imgY[left[16].pos_y][left[16].pos_x] -
imgY[left[0].pos_y][left[0].pos_x]);
ib=(5 * ih + 32)>>6; ib = (5 * ih + 32) >> 6;
ic=(5 * iv + 32)>>6; ic = (5 * iv + 32) >> 6;
iaa=16 * (mpr_line[8] + imgY[left[16].pos_y][left[16].pos_x]); iaa = 16 * (mpr_line[8] + imgY[left[16].pos_y][left[16].pos_x]);
for (j = 0;j < MB_BLOCK_SIZE; ++j) for (j = 0; j < MB_BLOCK_SIZE; ++j) {
{ for (i = 0; i < MB_BLOCK_SIZE; ++i) {
for (i = 0;i < MB_BLOCK_SIZE; ++i) mb_pred[j][i] = (imgpel)iClip1(
{ max_imgpel_value, ((iaa + (i - 7) * ib + (j - 7) * ic + 16) >> 5));
mb_pred[j][i] = (imgpel) iClip1(max_imgpel_value, ((iaa + (i - 7) * ib + (j - 7) * ic + 16) >> 5));
} }
}// store plane prediction } // store plane prediction
return DECODING_OK; return DECODING_OK;
} }
@ -290,36 +274,33 @@ static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl)
/*! /*!
*********************************************************************** ***********************************************************************
* \brief * \brief
* makes and returns 16x16 intra prediction blocks * makes and returns 16x16 intra prediction blocks
* *
* \return * \return
* DECODING_OK decoding of intraprediction mode was successful \n * DECODING_OK decoding of intraprediction mode was successful \n
* SEARCH_SYNC search next sync element as errors while decoding occured * SEARCH_SYNC search next sync element as errors while decoding occured
*********************************************************************** ***********************************************************************
*/ */
int intrapred_16x16_mbaff(Macroblock *currMB, //!< Current Macroblock int intrapred_16x16_mbaff(Macroblock *currMB, //!< Current Macroblock
ColorPlane pl, //!< Current colorplane (for 4:4:4) ColorPlane pl, //!< Current colorplane (for 4:4:4)
int predmode) //!< prediction mode int predmode) //!< prediction mode
{ {
switch (predmode) switch (predmode) {
{ case VERT_PRED_16: // vertical prediction from block above
case VERT_PRED_16: // vertical prediction from block above
return (intra16x16_vert_pred_mbaff(currMB, pl)); return (intra16x16_vert_pred_mbaff(currMB, pl));
break; break;
case HOR_PRED_16: // horizontal prediction from left block case HOR_PRED_16: // horizontal prediction from left block
return (intra16x16_hor_pred_mbaff(currMB, pl)); return (intra16x16_hor_pred_mbaff(currMB, pl));
break; break;
case DC_PRED_16: // DC prediction case DC_PRED_16: // DC prediction
return (intra16x16_dc_pred_mbaff(currMB, pl)); return (intra16x16_dc_pred_mbaff(currMB, pl));
break; break;
case PLANE_16:// 16 bit integer plan pred case PLANE_16: // 16 bit integer plan pred
return (intra16x16_plane_pred_mbaff(currMB, pl)); return (intra16x16_plane_pred_mbaff(currMB, pl));
break; break;
default: default: { // indication of fault in bitstream,exit
{ // indication of fault in bitstream,exit printf("illegal 16x16 intra prediction mode input: %d\n", predmode);
printf("illegal 16x16 intra prediction mode input: %d\n",predmode); return SEARCH_SYNC;
return SEARCH_SYNC; }
} }
}
} }

Some files were not shown because too many files have changed in this diff Show more