/ivfenc.dox
/libvpx.so*
/libvpx.ver
-/obj_int_extract
/samples.dox
/test_libvpx
/vp8_api1_migration.dox
+++ /dev/null
-/*
- * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vpx_config.h"
-#include "vpx/vpx_integer.h"
-
-typedef enum {
- OUTPUT_FMT_PLAIN,
- OUTPUT_FMT_RVDS,
- OUTPUT_FMT_GAS,
- OUTPUT_FMT_C_HEADER,
-} output_fmt_t;
-
-int log_msg(const char *fmt, ...) {
- int res;
- va_list ap;
- va_start(ap, fmt);
- res = vfprintf(stderr, fmt, ap);
- va_end(ap);
- return res;
-}
-
-#if defined(__GNUC__) && __GNUC__
-
-#if defined(FORCE_PARSE_ELF)
-
-#if defined(__MACH__)
-#undef __MACH__
-#endif
-
-#if !defined(__ELF__)
-#define __ELF__
-#endif
-#endif
-
-#if defined(__MACH__)
-
-#include <mach-o/loader.h>
-#include <mach-o/nlist.h>
-
-int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) {
- switch (mode) {
- case OUTPUT_FMT_RVDS:
- printf("%-40s EQU %5d\n", name, val);
- return 0;
- case OUTPUT_FMT_GAS:
- printf(".set %-40s, %5d\n", name, val);
- return 0;
- case OUTPUT_FMT_C_HEADER:
- printf("#define %-40s %5d\n", name, val);
- return 0;
- default:
- log_msg("Unsupported mode: %d", mode);
- return 1;
- }
-}
-
-int parse_macho(uint8_t *base_buf, size_t sz, output_fmt_t mode) {
- int i, j;
- struct mach_header header;
- uint8_t *buf = base_buf;
- int base_data_section = 0;
- int bits = 0;
-
- /* We can read in mach_header for 32 and 64 bit architectures
- * because it's identical to mach_header_64 except for the last
- * element (uint32_t reserved), which we don't use. Then, when
- * we know which architecture we're looking at, increment buf
- * appropriately.
- */
- memcpy(&header, buf, sizeof(struct mach_header));
-
- if (header.magic == MH_MAGIC) {
- if (header.cputype == CPU_TYPE_ARM
- || header.cputype == CPU_TYPE_X86) {
- bits = 32;
- buf += sizeof(struct mach_header);
- } else {
- log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_[ARM|X86].\n");
- goto bail;
- }
- } else if (header.magic == MH_MAGIC_64) {
- if (header.cputype == CPU_TYPE_X86_64) {
- bits = 64;
- buf += sizeof(struct mach_header_64);
- } else {
- log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_X86_64.\n");
- goto bail;
- }
- } else {
- log_msg("Bad magic number for object file. 0x%x or 0x%x expected, 0x%x found.\n",
- MH_MAGIC, MH_MAGIC_64, header.magic);
- goto bail;
- }
-
- if (header.filetype != MH_OBJECT) {
- log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n");
- goto bail;
- }
-
- for (i = 0; i < header.ncmds; i++) {
- struct load_command lc;
-
- memcpy(&lc, buf, sizeof(struct load_command));
-
- if (lc.cmd == LC_SEGMENT) {
- uint8_t *seg_buf = buf;
- struct section s;
- struct segment_command seg_c;
-
- memcpy(&seg_c, seg_buf, sizeof(struct segment_command));
- seg_buf += sizeof(struct segment_command);
-
- /* Although each section is given it's own offset, nlist.n_value
- * references the offset of the first section. This isn't
- * apparent without debug information because the offset of the
- * data section is the same as the first section. However, with
- * debug sections mixed in, the offset of the debug section
- * increases but n_value still references the first section.
- */
- if (seg_c.nsects < 1) {
- log_msg("Not enough sections\n");
- goto bail;
- }
-
- memcpy(&s, seg_buf, sizeof(struct section));
- base_data_section = s.offset;
- } else if (lc.cmd == LC_SEGMENT_64) {
- uint8_t *seg_buf = buf;
- struct section_64 s;
- struct segment_command_64 seg_c;
-
- memcpy(&seg_c, seg_buf, sizeof(struct segment_command_64));
- seg_buf += sizeof(struct segment_command_64);
-
- /* Explanation in LG_SEGMENT */
- if (seg_c.nsects < 1) {
- log_msg("Not enough sections\n");
- goto bail;
- }
-
- memcpy(&s, seg_buf, sizeof(struct section_64));
- base_data_section = s.offset;
- } else if (lc.cmd == LC_SYMTAB) {
- if (base_data_section != 0) {
- struct symtab_command sc;
- uint8_t *sym_buf = base_buf;
- uint8_t *str_buf = base_buf;
-
- memcpy(&sc, buf, sizeof(struct symtab_command));
-
- if (sc.cmdsize != sizeof(struct symtab_command)) {
- log_msg("Can't find symbol table!\n");
- goto bail;
- }
-
- sym_buf += sc.symoff;
- str_buf += sc.stroff;
-
- for (j = 0; j < sc.nsyms; j++) {
- /* Location of string is cacluated each time from the
- * start of the string buffer. On darwin the symbols
- * are prefixed by "_", so we bump the pointer by 1.
- * The target value is defined as an int in *_asm_*_offsets.c,
- * which is 4 bytes on all targets we currently use.
- */
- if (bits == 32) {
- struct nlist nl;
- int val;
-
- memcpy(&nl, sym_buf, sizeof(struct nlist));
- sym_buf += sizeof(struct nlist);
-
- memcpy(&val, base_buf + base_data_section + nl.n_value,
- sizeof(val));
- print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
- } else { /* if (bits == 64) */
- struct nlist_64 nl;
- int val;
-
- memcpy(&nl, sym_buf, sizeof(struct nlist_64));
- sym_buf += sizeof(struct nlist_64);
-
- memcpy(&val, base_buf + base_data_section + nl.n_value,
- sizeof(val));
- print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
- }
- }
- }
- }
-
- buf += lc.cmdsize;
- }
-
- return 0;
-bail:
- return 1;
-
-}
-
-#elif defined(__ELF__)
-#include "elf.h"
-
-#define COPY_STRUCT(dst, buf, ofst, sz) do {\
- if(ofst + sizeof((*(dst))) > sz) goto bail;\
- memcpy(dst, buf+ofst, sizeof((*(dst))));\
- } while(0)
-
-#define ENDIAN_ASSIGN(val, memb) do {\
- if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\
- (val) = (memb);\
- } while(0)
-
-#define ENDIAN_ASSIGN_IN_PLACE(memb) do {\
- ENDIAN_ASSIGN(memb, memb);\
- } while(0)
-
-typedef struct {
- uint8_t *buf; /* Buffer containing ELF data */
- size_t sz; /* Buffer size */
- int le_data; /* Data is little-endian */
- unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
- int bits; /* 32 or 64 */
- Elf32_Ehdr hdr32;
- Elf64_Ehdr hdr64;
-} elf_obj_t;
-
-int parse_elf_header(elf_obj_t *elf) {
- int res;
- /* Verify ELF Magic numbers */
- COPY_STRUCT(&elf->e_ident, elf->buf, 0, elf->sz);
- res = elf->e_ident[EI_MAG0] == ELFMAG0;
- res &= elf->e_ident[EI_MAG1] == ELFMAG1;
- res &= elf->e_ident[EI_MAG2] == ELFMAG2;
- res &= elf->e_ident[EI_MAG3] == ELFMAG3;
- res &= elf->e_ident[EI_CLASS] == ELFCLASS32
- || elf->e_ident[EI_CLASS] == ELFCLASS64;
- res &= elf->e_ident[EI_DATA] == ELFDATA2LSB;
-
- if (!res) goto bail;
-
- elf->le_data = elf->e_ident[EI_DATA] == ELFDATA2LSB;
-
- /* Read in relevant values */
- if (elf->e_ident[EI_CLASS] == ELFCLASS32) {
- elf->bits = 32;
- COPY_STRUCT(&elf->hdr32, elf->buf, 0, elf->sz);
-
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_type);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_machine);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_version);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_entry);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phoff);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shoff);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_flags);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_ehsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phentsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phnum);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shentsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shnum);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shstrndx);
- } else { /* if (elf->e_ident[EI_CLASS] == ELFCLASS64) */
- elf->bits = 64;
- COPY_STRUCT(&elf->hdr64, elf->buf, 0, elf->sz);
-
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_type);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_machine);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_version);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_entry);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phoff);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shoff);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_flags);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_ehsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phentsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phnum);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shentsize);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shnum);
- ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shstrndx);
- }
-
- return 0;
-bail:
- log_msg("Failed to parse ELF file header");
- return 1;
-}
-
-int parse_elf_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr32, Elf64_Shdr *hdr64) {
- if (hdr32) {
- if (idx >= elf->hdr32.e_shnum)
- goto bail;
-
- COPY_STRUCT(hdr32, elf->buf, elf->hdr32.e_shoff + idx * elf->hdr32.e_shentsize,
- elf->sz);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_name);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_type);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_flags);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addr);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_offset);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_size);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_link);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_info);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addralign);
- ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_entsize);
- } else { /* if (hdr64) */
- if (idx >= elf->hdr64.e_shnum)
- goto bail;
-
- COPY_STRUCT(hdr64, elf->buf, elf->hdr64.e_shoff + idx * elf->hdr64.e_shentsize,
- elf->sz);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_name);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_type);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_flags);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addr);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_offset);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_size);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_link);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_info);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addralign);
- ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_entsize);
- }
-
- return 0;
-bail:
- return 1;
-}
-
-const char *parse_elf_string_table(elf_obj_t *elf, int s_idx, int idx) {
- if (elf->bits == 32) {
- Elf32_Shdr shdr;
-
- if (parse_elf_section(elf, s_idx, &shdr, NULL)) {
- log_msg("Failed to parse ELF string table: section %d, index %d\n",
- s_idx, idx);
- return "";
- }
-
- return (char *)(elf->buf + shdr.sh_offset + idx);
- } else { /* if (elf->bits == 64) */
- Elf64_Shdr shdr;
-
- if (parse_elf_section(elf, s_idx, NULL, &shdr)) {
- log_msg("Failed to parse ELF string table: section %d, index %d\n",
- s_idx, idx);
- return "";
- }
-
- return (char *)(elf->buf + shdr.sh_offset + idx);
- }
-}
-
-int parse_elf_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym32, Elf64_Sym *sym64) {
- if (sym32) {
- COPY_STRUCT(sym32, elf->buf, ofst, elf->sz);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_name);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_value);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_size);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_info);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_other);
- ENDIAN_ASSIGN_IN_PLACE(sym32->st_shndx);
- } else { /* if (sym64) */
- COPY_STRUCT(sym64, elf->buf, ofst, elf->sz);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_name);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_value);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_size);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_info);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_other);
- ENDIAN_ASSIGN_IN_PLACE(sym64->st_shndx);
- }
- return 0;
-bail:
- return 1;
-}
-
-int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) {
- elf_obj_t elf;
- unsigned int ofst;
- int i;
- Elf32_Off strtab_off32;
- Elf64_Off strtab_off64; /* save String Table offset for later use */
-
- memset(&elf, 0, sizeof(elf));
- elf.buf = buf;
- elf.sz = sz;
-
- /* Parse Header */
- if (parse_elf_header(&elf))
- goto bail;
-
- if (elf.bits == 32) {
- Elf32_Shdr shdr;
- for (i = 0; i < elf.hdr32.e_shnum; i++) {
- parse_elf_section(&elf, i, &shdr, NULL);
-
- if (shdr.sh_type == SHT_STRTAB) {
- char strtsb_name[128];
-
- strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
-
- if (!(strcmp(strtsb_name, ".shstrtab"))) {
- /* log_msg("found section: %s\n", strtsb_name); */
- strtab_off32 = shdr.sh_offset;
- break;
- }
- }
- }
- } else { /* if (elf.bits == 64) */
- Elf64_Shdr shdr;
- for (i = 0; i < elf.hdr64.e_shnum; i++) {
- parse_elf_section(&elf, i, NULL, &shdr);
-
- if (shdr.sh_type == SHT_STRTAB) {
- char strtsb_name[128];
-
- strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
-
- if (!(strcmp(strtsb_name, ".shstrtab"))) {
- /* log_msg("found section: %s\n", strtsb_name); */
- strtab_off64 = shdr.sh_offset;
- break;
- }
- }
- }
- }
-
- /* Parse all Symbol Tables */
- if (elf.bits == 32) {
- Elf32_Shdr shdr;
- for (i = 0; i < elf.hdr32.e_shnum; i++) {
- parse_elf_section(&elf, i, &shdr, NULL);
-
- if (shdr.sh_type == SHT_SYMTAB) {
- for (ofst = shdr.sh_offset;
- ofst < shdr.sh_offset + shdr.sh_size;
- ofst += shdr.sh_entsize) {
- Elf32_Sym sym;
-
- parse_elf_symbol(&elf, ofst, &sym, NULL);
-
- /* For all OBJECTS (data objects), extract the value from the
- * proper data segment.
- */
- /* if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
- log_msg("found data object %s\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name));
- */
-
- if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT
- && sym.st_size == 4) {
- Elf32_Shdr dhdr;
- int val = 0;
- char section_name[128];
-
- parse_elf_section(&elf, sym.st_shndx, &dhdr, NULL);
-
- /* For explanition - refer to _MSC_VER version of code */
- strcpy(section_name, (char *)(elf.buf + strtab_off32 + dhdr.sh_name));
- /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
-
- if (strcmp(section_name, ".bss")) {
- if (sizeof(val) != sym.st_size) {
- /* The target value is declared as an int in
- * *_asm_*_offsets.c, which is 4 bytes on all
- * targets we currently use. Complain loudly if
- * this is not true.
- */
- log_msg("Symbol size is wrong\n");
- goto bail;
- }
-
- memcpy(&val,
- elf.buf + dhdr.sh_offset + sym.st_value,
- sym.st_size);
- }
-
- if (!elf.le_data) {
- log_msg("Big Endian data not supported yet!\n");
- goto bail;
- }
-
- switch (mode) {
- case OUTPUT_FMT_RVDS:
- printf("%-40s EQU %5d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- break;
- case OUTPUT_FMT_GAS:
- printf(".equ %-40s, %5d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- break;
- case OUTPUT_FMT_C_HEADER:
- printf("#define %-40s %5d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- break;
- default:
- printf("%s = %d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- }
- }
- }
- }
- }
- } else { /* if (elf.bits == 64) */
- Elf64_Shdr shdr;
- for (i = 0; i < elf.hdr64.e_shnum; i++) {
- parse_elf_section(&elf, i, NULL, &shdr);
-
- if (shdr.sh_type == SHT_SYMTAB) {
- for (ofst = shdr.sh_offset;
- ofst < shdr.sh_offset + shdr.sh_size;
- ofst += shdr.sh_entsize) {
- Elf64_Sym sym;
-
- parse_elf_symbol(&elf, ofst, NULL, &sym);
-
- /* For all OBJECTS (data objects), extract the value from the
- * proper data segment.
- */
- /* if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
- log_msg("found data object %s\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name));
- */
-
- if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT
- && sym.st_size == 4) {
- Elf64_Shdr dhdr;
- int val = 0;
- char section_name[128];
-
- parse_elf_section(&elf, sym.st_shndx, NULL, &dhdr);
-
- /* For explanition - refer to _MSC_VER version of code */
- strcpy(section_name, (char *)(elf.buf + strtab_off64 + dhdr.sh_name));
- /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
-
- if ((strcmp(section_name, ".bss"))) {
- if (sizeof(val) != sym.st_size) {
- /* The target value is declared as an int in
- * *_asm_*_offsets.c, which is 4 bytes on all
- * targets we currently use. Complain loudly if
- * this is not true.
- */
- log_msg("Symbol size is wrong\n");
- goto bail;
- }
-
- memcpy(&val,
- elf.buf + dhdr.sh_offset + sym.st_value,
- sym.st_size);
- }
-
- if (!elf.le_data) {
- log_msg("Big Endian data not supported yet!\n");
- goto bail;
- }
-
- switch (mode) {
- case OUTPUT_FMT_RVDS:
- printf("%-40s EQU %5d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- break;
- case OUTPUT_FMT_GAS:
- printf(".equ %-40s, %5d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- break;
- default:
- printf("%s = %d\n",
- parse_elf_string_table(&elf,
- shdr.sh_link,
- sym.st_name),
- val);
- }
- }
- }
- }
- }
- }
-
- if (mode == OUTPUT_FMT_RVDS)
- printf(" END\n");
-
- return 0;
-bail:
- log_msg("Parse error: File does not appear to be valid ELF32 or ELF64\n");
- return 1;
-}
-
-#endif
-#endif /* defined(__GNUC__) && __GNUC__ */
-
-
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
-/* See "Microsoft Portable Executable and Common Object File Format Specification"
- for reference.
-*/
-#define get_le32(x) ((*(x)) | (*(x+1)) << 8 |(*(x+2)) << 16 | (*(x+3)) << 24 )
-#define get_le16(x) ((*(x)) | (*(x+1)) << 8)
-
-int parse_coff(uint8_t *buf, size_t sz) {
- unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr;
- unsigned int sectionrawdata_ptr;
- unsigned int i;
- uint8_t *ptr;
- uint32_t symoffset;
-
- char **sectionlist; // this array holds all section names in their correct order.
- // it is used to check if the symbol is in .bss or .rdata section.
-
- nsections = get_le16(buf + 2);
- symtab_ptr = get_le32(buf + 8);
- symtab_sz = get_le32(buf + 12);
- strtab_ptr = symtab_ptr + symtab_sz * 18;
-
- if (nsections > 96) {
- log_msg("Too many sections\n");
- return 1;
- }
-
- sectionlist = malloc(nsections * sizeof(sectionlist));
-
- if (sectionlist == NULL) {
- log_msg("Allocating first level of section list failed\n");
- return 1;
- }
-
- // log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections);
-
- /*
- The size of optional header is always zero for an obj file. So, the section header
- follows the file header immediately.
- */
-
- ptr = buf + 20; // section header
-
- for (i = 0; i < nsections; i++) {
- char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
- strncpy(sectionname, ptr, 8);
- // log_msg("COFF: Parsing section %s\n",sectionname);
-
- sectionlist[i] = malloc(strlen(sectionname) + 1);
-
- if (sectionlist[i] == NULL) {
- log_msg("Allocating storage for %s failed\n", sectionname);
- goto bail;
- }
- strcpy(sectionlist[i], sectionname);
-
- // check if it's .rdata and is not a COMDAT section.
- if (!strcmp(sectionname, ".rdata") &&
- (get_le32(ptr + 36) & 0x1000) == 0) {
- sectionrawdata_ptr = get_le32(ptr + 20);
- }
-
- ptr += 40;
- }
-
- // log_msg("COFF: Symbol table at offset %u\n", symtab_ptr);
- // log_msg("COFF: raw data pointer ofset for section .rdata is %u\n", sectionrawdata_ptr);
-
- /* The compiler puts the data with non-zero offset in .rdata section, but puts the data with
- zero offset in .bss section. So, if the data in in .bss section, set offset=0.
- Note from Wiki: In an object module compiled from C, the bss section contains
- the local variables (but not functions) that were declared with the static keyword,
- except for those with non-zero initial values. (In C, static variables are initialized
- to zero by default.) It also contains the non-local (both extern and static) variables
- that are also initialized to zero (either explicitly or by default).
- */
- // move to symbol table
- /* COFF symbol table:
- offset field
- 0 Name(*)
- 8 Value
- 12 SectionNumber
- 14 Type
- 16 StorageClass
- 17 NumberOfAuxSymbols
- */
- ptr = buf + symtab_ptr;
-
- for (i = 0; i < symtab_sz; i++) {
- int16_t section = get_le16(ptr + 12); // section number
-
- if (section > 0 && ptr[16] == 2) {
- // if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) {
-
- if (get_le32(ptr)) {
- char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
- strncpy(name, ptr, 8);
- // log_msg("COFF: Parsing symbol %s\n",name);
- /* The 64bit Windows compiler doesn't prefix with an _.
- * Check what's there, and bump if necessary
- */
- if (name[0] == '_')
- printf("%-40s EQU ", name + 1);
- else
- printf("%-40s EQU ", name);
- } else {
- // log_msg("COFF: Parsing symbol %s\n",
- // buf + strtab_ptr + get_le32(ptr+4));
- if ((buf + strtab_ptr + get_le32(ptr + 4))[0] == '_')
- printf("%-40s EQU ",
- buf + strtab_ptr + get_le32(ptr + 4) + 1);
- else
- printf("%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4));
- }
-
- if (!(strcmp(sectionlist[section - 1], ".bss"))) {
- symoffset = 0;
- } else {
- symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8));
- }
-
- // log_msg(" Section: %d\n",section);
- // log_msg(" Class: %d\n",ptr[16]);
- // log_msg(" Address: %u\n",get_le32(ptr+8));
- // log_msg(" Offset: %u\n", symoffset);
-
- printf("%5d\n", symoffset);
- }
-
- ptr += 18;
- }
-
- printf(" END\n");
-
- for (i = 0; i < nsections; i++) {
- free(sectionlist[i]);
- }
-
- free(sectionlist);
-
- return 0;
-bail:
-
- for (i = 0; i < nsections; i++) {
- free(sectionlist[i]);
- }
-
- free(sectionlist);
-
- return 1;
-}
-#endif /* defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) */
-
-int main(int argc, char **argv) {
- output_fmt_t mode = OUTPUT_FMT_PLAIN;
- const char *f;
- uint8_t *file_buf;
- int res;
- FILE *fp;
- long int file_size;
-
- if (argc < 2 || argc > 3) {
- fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]);
- fprintf(stderr, " <obj file>\tobject file to parse\n");
- fprintf(stderr, "Output Formats:\n");
- fprintf(stderr, " gas - compatible with GNU assembler\n");
- fprintf(stderr, " rvds - compatible with armasm\n");
- fprintf(stderr, " cheader - c/c++ header file\n");
- goto bail;
- }
-
- f = argv[2];
-
- if (!strcmp(argv[1], "rvds"))
- mode = OUTPUT_FMT_RVDS;
- else if (!strcmp(argv[1], "gas"))
- mode = OUTPUT_FMT_GAS;
- else if (!strcmp(argv[1], "cheader"))
- mode = OUTPUT_FMT_C_HEADER;
- else
- f = argv[1];
-
- fp = fopen(f, "rb");
-
- if (!fp) {
- perror("Unable to open file");
- goto bail;
- }
-
- if (fseek(fp, 0, SEEK_END)) {
- perror("stat");
- goto bail;
- }
-
- file_size = ftell(fp);
- file_buf = malloc(file_size);
-
- if (!file_buf) {
- perror("malloc");
- goto bail;
- }
-
- rewind(fp);
-
- if (fread(file_buf, sizeof(char), file_size, fp) != file_size) {
- perror("read");
- goto bail;
- }
-
- if (fclose(fp)) {
- perror("close");
- goto bail;
- }
-
-#if defined(__GNUC__) && __GNUC__
-#if defined(__MACH__)
- res = parse_macho(file_buf, file_size, mode);
-#elif defined(__ELF__)
- res = parse_elf(file_buf, file_size, mode);
-#endif
-#endif
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
- res = parse_coff(file_buf, file_size);
-#endif
-
- free(file_buf);
-
- if (!res)
- return EXIT_SUCCESS;
-
-bail:
- return EXIT_FAILURE;
-}
cfg_.g_timebase = video->timebase();
cfg_.rc_twopass_stats_in = stats_->buf();
- // Default to 1 thread and 1 tile column.
+ // Default to 1 thread.
cfg_.g_threads = 1;
res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_,
init_flags_);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
- std::string codec_name(encoder_.name);
- if (codec_name.find("WebM Project VP9 Encoder") != std::string::npos) {
+#if CONFIG_VP9_ENCODER
+ if (CodecInterface() == &vpx_codec_vp9_cx_algo) {
+ // Default to 1 tile column for VP9.
const int log2_tile_columns = 0;
res = vpx_codec_control_(&encoder_, VP9E_SET_TILE_COLUMNS,
log2_tile_columns);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
+ } else
+#endif
+ {
+#if CONFIG_VP8_ENCODER
+ ASSERT_EQ(&vpx_codec_vp8_cx_algo, CodecInterface())
+ << "Unknown Codec Interface";
+#endif
}
}
}
VP9_IVF_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-09-subpixel-00.ivf"
VP9_WEBM_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-00-quantizer-00.webm"
+VP9_FPM_WEBM_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-07-frame_parallel-1.webm"
YUV_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/hantro_collage_w352h288.yuv"
YUV_RAW_INPUT_WIDTH=352
# Environment check: Make sure input is available.
vpxdec_verify_environment() {
- if [ ! -e "${VP8_IVF_FILE}" ] || [ ! -e "${VP9_WEBM_FILE}" ]; then
+ if [ ! -e "${VP8_IVF_FILE}" ] || [ ! -e "${VP9_WEBM_FILE}" ] || \
+ [ ! -e "${VP9_FPM_WEBM_FILE}" ] ; then
elog "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH."
return 1
fi
fi
}
+vpxdec_vp9_webm_frame_parallel() {
+ if [ "$(vpxdec_can_decode_vp9)" = "yes" ] && \
+ [ "$(webm_io_available)" = "yes" ]; then
+ for threads in 2 3 4 5 6 7 8; do
+ vpxdec "${VP9_FPM_WEBM_FILE}" --summary --noblit --threads=$threads \
+ --frame-parallel
+ done
+ fi
+
+}
+
vpxdec_tests="vpxdec_vp8_ivf
vpxdec_vp8_ivf_pipe_input
- vpxdec_vp9_webm"
+ vpxdec_vp9_webm
+ vpxdec_vp9_webm_frame_parallel"
run_tests vpxdec_verify_environment "${vpxdec_tests}"
+++ /dev/null
-/*
- * Copyright (c) 2011 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#include "vpx_ports/asm_offsets.h"
-
-BEGIN
-
-END
// excess of the cycle time, i.e., in the case of all zero motion, block
// will be refreshed every (100/percent_refresh + time_for_refresh) frames.
int time_for_refresh;
- // // Target number of (8x8) blocks that are set for delta-q (segment 1).
+ // Target number of (8x8) blocks that are set for delta-q.
int target_num_seg_blocks;
- // Actual number of (8x8) blocks that were applied delta-q (segment 1).
- int actual_num_seg_blocks;
+ // Actual number of (8x8) blocks that were applied delta-q.
+ int actual_num_seg1_blocks;
+ int actual_num_seg2_blocks;
// RD mult. parameters for segment 1.
int rdmult;
// Cyclic refresh map.
// Rate target ratio to set q delta.
double rate_ratio_qdelta;
double low_content_avg;
+ int qindex_delta_seg1;
+ int qindex_delta_seg2;
};
CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) {
mv.col > cr->motion_thresh || mv.col < -cr->motion_thresh ||
!is_inter_block(mbmi)))
return CR_SEGMENT_ID_BASE;
- else if (bsize >= BLOCK_32X32 &&
+ else if (bsize >= BLOCK_16X16 &&
rate < cr->thresh_rate_sb &&
is_inter_block(mbmi) &&
mbmi->mv[0].as_int == 0)
int num8x8bl = mbs << 2;
// Weight for non-base segments: use actual number of blocks refreshed in
// previous/just encoded frame. Note number of blocks here is in 8x8 units.
- double weight_segment = (double)cr->actual_num_seg_blocks / num8x8bl;
- // Compute delta-q that was used in the just encoded frame.
- int deltaq = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta);
+ double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl;
+ double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl;
// Take segment weighted average for estimated bits.
- estimated_bits = (int)((1.0 - weight_segment) *
+ estimated_bits = (int)((1.0 - weight_segment1 - weight_segment2) *
vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs,
correction_factor, cm->bit_depth) +
- weight_segment *
- vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex + deltaq, mbs,
+ weight_segment1 *
+ vp9_estimate_bits_at_q(cm->frame_type,
+ cm->base_qindex + cr->qindex_delta_seg1, mbs,
+ correction_factor, cm->bit_depth) +
+ weight_segment2 *
+ vp9_estimate_bits_at_q(cm->frame_type,
+ cm->base_qindex + cr->qindex_delta_seg2, mbs,
correction_factor, cm->bit_depth));
return estimated_bits;
}
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
int bits_per_mb;
int num8x8bl = cm->MBs << 2;
- // Weight for segment 1 prior to encoding: take the target number for the
- // frame to be encoded. Number of blocks here is in 8x8 units.
- // Note that this is called in rc_regulate_q, which is called before the
- // cyclic_refresh_setup (which sets cr->target_num_seg_blocks). So a mismatch
- // may occur between the cr->target_num_seg_blocks value here and the
- // cr->target_num_seg_block set for encoding the frame. For the current use
- // case of fixed cr->percent_refresh and cr->time_for_refresh = 0, mismatch
- // does not occur/is very small.
- double weight_segment = (double)cr->target_num_seg_blocks / num8x8bl;
+ // Weight for segment prior to encoding: take the average of the target
+ // number for the frame to be encoded and the actual from the previous frame.
+ double weight_segment = (double)((cr->target_num_seg_blocks +
+ cr->actual_num_seg1_blocks + cr->actual_num_seg2_blocks) >> 1) /
+ num8x8bl;
// Compute delta-q corresponding to qindex i.
int deltaq = compute_deltaq(cpi, i, cr->rate_ratio_qdelta);
// Take segment weighted average for bits per mb.
int mi_row, int mi_col,
BLOCK_SIZE bsize,
int64_t rate,
- int64_t dist) {
+ int64_t dist,
+ int skip) {
const VP9_COMMON *const cm = &cpi->common;
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
const int bw = num_8x8_blocks_wide_lookup[bsize];
// If this block is labeled for refresh, check if we should reset the
// segment_id.
- if (cyclic_refresh_segment_id_boosted(mbmi->segment_id))
+ if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) {
mbmi->segment_id = refresh_this_block;
+ // Reset segment_id if will be skipped.
+ if (skip)
+ mbmi->segment_id = CR_SEGMENT_ID_BASE;
+ }
// Update the cyclic refresh map, to be used for setting segmentation map
// for the next frame. If the block will be refreshed this frame, mark it
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
unsigned char *const seg_map = cpi->segmentation_map;
int mi_row, mi_col;
- cr->actual_num_seg_blocks = 0;
+ cr->actual_num_seg1_blocks = 0;
+ cr->actual_num_seg2_blocks = 0;
for (mi_row = 0; mi_row < cm->mi_rows; mi_row++)
for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
- if (cyclic_refresh_segment_id_boosted(
- seg_map[mi_row * cm->mi_cols + mi_col]))
- cr->actual_num_seg_blocks++;
+ if (cyclic_refresh_segment_id(
+ seg_map[mi_row * cm->mi_cols + mi_col]) == CR_SEGMENT_ID_BOOST1)
+ cr->actual_num_seg1_blocks++;
+ else if (cyclic_refresh_segment_id(
+ seg_map[mi_row * cm->mi_cols + mi_col]) == CR_SEGMENT_ID_BOOST2)
+ cr->actual_num_seg2_blocks++;
}
}
cr->time_for_refresh = 0;
// Set rate threshold to some multiple (set to 2 for now) of the target
// rate (target is given by sb64_target_rate and scaled by 256).
- cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 1;
+ cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 2;
// Distortion threshold, quadratic in Q, scale factor to be adjusted.
// q will not exceed 457, so (q * q) is within 32bit; see:
// vp9_convert_qindex_to_q(), vp9_ac_quant(), ac_qlookup*[].
// Set the q delta for segment BOOST1.
qindex_delta = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta);
+ cr->qindex_delta_seg1 = qindex_delta;
// Compute rd-mult for segment BOOST1.
qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ);
+
cr->rdmult = vp9_compute_rd_mult(cpi, qindex2);
vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q, qindex_delta);
qindex_delta = compute_deltaq(cpi, cm->base_qindex,
MIN(CR_MAX_RATE_TARGET_RATIO,
CR_BOOST2_FAC * cr->rate_ratio_qdelta));
+ cr->qindex_delta_seg2 = qindex_delta;
vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q, qindex_delta);
// Update the segmentation and refresh map.
void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
MB_MODE_INFO *const mbmi,
int mi_row, int mi_col, BLOCK_SIZE bsize,
- int64_t rate, int64_t dist);
+ int64_t rate, int64_t dist, int skip);
// Update the segmentation map, and related quantities: cyclic refresh map,
// refresh sb_index, and target number of blocks to be refreshed.
segment_id == CR_SEGMENT_ID_BOOST2;
}
+static INLINE int cyclic_refresh_segment_id(int segment_id) {
+ if (segment_id == CR_SEGMENT_ID_BOOST1)
+ return CR_SEGMENT_ID_BOOST1;
+ else if (segment_id == CR_SEGMENT_ID_BOOST2)
+ return CR_SEGMENT_ID_BOOST2;
+ else
+ return CR_SEGMENT_ID_BASE;
+}
+
#ifdef __cplusplus
} // extern "C"
#endif
int16_t vp9_int_pro_col_c(uint8_t const *ref, const int width) {
int idx;
int16_t sum = 0;
- const int norm_factor = MAX(8, width >> 1);
for (idx = 0; idx < width; ++idx)
sum += ref[idx];
- return sum / norm_factor;
+ return sum;
}
int vp9_vector_var_c(int16_t const *ref, int16_t const *src,
#include "vp9/encoder/vp9_segmentation.h"
#include "vp9/encoder/vp9_tokenize.h"
-#define GF_ZEROMV_ZBIN_BOOST 0
-#define LF_ZEROMV_ZBIN_BOOST 0
-#define MV_ZBIN_BOOST 0
-#define SPLIT_MV_ZBIN_BOOST 0
-#define INTRA_ZBIN_BOOST 0
-
static void encode_superblock(VP9_COMP *cpi, ThreadData * td,
TOKENEXTRA **t, int output_enabled,
int mi_row, int mi_col, BLOCK_SIZE bsize,
int mi_col,
int64_t threshold,
BLOCK_SIZE bsize_min,
- int segment_id) {
+ int force_split) {
VP9_COMMON * const cm = &cpi->common;
variance_node vt;
const int block_width = num_8x8_blocks_wide_lookup[bsize];
assert(block_height == block_width);
tree_to_node(data, bsize, &vt);
- // No 64x64 blocks on segments other than base (un-boosted) segment.
- if (cyclic_refresh_segment_id_boosted(segment_id) && bsize == BLOCK_64X64)
+ if (force_split)
return 0;
// For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if
}
return 0;
} else if (bsize > bsize_min) {
- get_variance(&vt.part_variances->none);
+ // Variance is already computed for 32x32 blocks to set the force_split.
+ if (bsize != BLOCK_32X32)
+ get_variance(&vt.part_variances->none);
// For key frame or low_res: for bsize above 32X32 or very high variance,
// take split.
if (cm->frame_type == KEY_FRAME &&
return;
} else {
VP9_COMMON *const cm = &cpi->common;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
const int is_key_frame = (cm->frame_type == KEY_FRAME);
- const int use_4x4_partition = is_key_frame;
- const int low_res = (cm->width <= 352 && cm->height <= 288);
const int threshold_multiplier = is_key_frame ? 80 : 4;
const int64_t threshold_base = (int64_t)(threshold_multiplier *
vp9_convert_qindex_to_q(q, cm->bit_depth));
- cpi->vbp_threshold = threshold_base;
- cpi->vbp_threshold_bsize_min = threshold_base << oxcf->speed;
- cpi->vbp_threshold_bsize_max = threshold_base;
- if (is_key_frame) {
- cpi->vbp_threshold = threshold_base >> 2;
- cpi->vbp_threshold_bsize_min = threshold_base << 2;
- } else if (low_res) {
- cpi->vbp_threshold_bsize_min = threshold_base << 3;
- cpi->vbp_threshold_bsize_max = threshold_base >> 2;
- }
// TODO(marpan): Allow 4x4 partitions for inter-frames.
// use_4x4_partition = (variance4x4downsample[i2 + j] == 1);
// If 4x4 partition is not used, then 8x8 partition will be selected
// if variance of 16x16 block is very high, so use larger threshold
// for 16x16 (threshold_bsize_min) in that case.
- cpi->vbp_threshold_16x16 = (use_4x4_partition) ?
- cpi->vbp_threshold : cpi->vbp_threshold_bsize_min;
- cpi->vbp_bsize_min = (use_4x4_partition) ? BLOCK_8X8 : BLOCK_16X16;
+ if (is_key_frame) {
+ cpi->vbp_threshold = threshold_base >> 2;
+ cpi->vbp_threshold_bsize_max = threshold_base;
+ cpi->vbp_threshold_bsize_min = threshold_base << 2;
+ cpi->vbp_threshold_16x16 = cpi->vbp_threshold;
+ cpi->vbp_bsize_min = BLOCK_8X8;
+ } else {
+ cpi->vbp_threshold = threshold_base;
+ if (cm->width <= 352 && cm->height <= 288) {
+ cpi->vbp_threshold_bsize_max = threshold_base >> 2;
+ cpi->vbp_threshold_bsize_min = threshold_base << 3;
+ } else {
+ cpi->vbp_threshold_bsize_max = threshold_base;
+ cpi->vbp_threshold_bsize_min = threshold_base << cpi->oxcf.speed;
+ }
+ cpi->vbp_threshold_16x16 = cpi->vbp_threshold_bsize_min;
+ cpi->vbp_bsize_min = BLOCK_16X16;
+ }
}
}
int i, j, k, m;
v64x64 vt;
v16x16 vt2[16];
+ int force_split[5];
uint8_t *s;
const uint8_t *d;
int sp;
#endif // CONFIG_VP9_HIGHBITDEPTH
}
+ // Index for force_split: 0 for 64x64, 1-4 for 32x32 blocks,
+ force_split[0] = 0;
// Fill in the entire tree of 8x8 (or 4x4 under some conditions) variances
// for splits.
for (i = 0; i < 4; i++) {
const int x32_idx = ((i & 1) << 5);
const int y32_idx = ((i >> 1) << 5);
const int i2 = i << 2;
+ force_split[i + 1] = 0;
for (j = 0; j < 4; j++) {
const int x16_idx = x32_idx + ((j & 1) << 4);
const int y16_idx = y32_idx + ((j >> 1) << 4);
}
}
+ // No 64x64 blocks on segments other than base (un-boosted) segment,
+ // so force split.
+ if (cyclic_refresh_segment_id_boosted(segment_id))
+ force_split[0] = 1;
+
// Fill the rest of the variance tree by summing split partition values.
for (i = 0; i < 4; i++) {
const int i2 = i << 2;
if (variance4x4downsample[i2 + j] == 1) {
v16x16 *vtemp = (!is_key_frame) ? &vt2[i2 + j] :
&vt.split[i].split[j];
- for (m = 0; m < 4; m++) {
+ for (m = 0; m < 4; m++)
fill_variance_tree(&vtemp->split[m], BLOCK_8X8);
- }
fill_variance_tree(vtemp, BLOCK_16X16);
}
}
fill_variance_tree(&vt.split[i], BLOCK_32X32);
+ // If variance of this 32x32 block is above the threshold, force the block
+ // to split. This also forces a split on the upper (64x64) level.
+ get_variance(&vt.split[i].part_variances.none);
+ if (vt.split[i].part_variances.none.variance > cpi->vbp_threshold) {
+ force_split[i + 1] = 1;
+ force_split[0] = 1;
+ }
}
- fill_variance_tree(&vt, BLOCK_64X64);
+ if (!force_split[0])
+ fill_variance_tree(&vt, BLOCK_64X64);
// Now go through the entire structure, splitting every block size until
// we get to one that's got a variance lower than our threshold.
if ( mi_col + 8 > cm->mi_cols || mi_row + 8 > cm->mi_rows ||
!set_vt_partitioning(cpi, xd, &vt, BLOCK_64X64, mi_row, mi_col,
cpi->vbp_threshold_bsize_max, BLOCK_16X16,
- segment_id)) {
+ force_split[0])) {
for (i = 0; i < 4; ++i) {
const int x32_idx = ((i & 1) << 2);
const int y32_idx = ((i >> 1) << 2);
if (!set_vt_partitioning(cpi, xd, &vt.split[i], BLOCK_32X32,
(mi_row + y32_idx), (mi_col + x32_idx),
cpi->vbp_threshold,
- BLOCK_16X16, segment_id)) {
+ BLOCK_16X16, force_split[i + 1])) {
for (j = 0; j < 4; ++j) {
const int x16_idx = ((j & 1) << 1);
const int y16_idx = ((j >> 1) << 1);
mi_row + y32_idx + y16_idx,
mi_col + x32_idx + x16_idx,
cpi->vbp_threshold_16x16,
- cpi->vbp_bsize_min, segment_id)) {
+ cpi->vbp_bsize_min, 0)) {
for (k = 0; k < 4; ++k) {
const int x8_idx = (k & 1);
const int y8_idx = (k >> 1);
mi_row + y32_idx + y16_idx + y8_idx,
mi_col + x32_idx + x16_idx + x8_idx,
cpi->vbp_threshold_bsize_min,
- BLOCK_8X8, segment_id)) {
+ BLOCK_8X8, 0)) {
set_block_size(cpi, xd,
(mi_row + y32_idx + y16_idx + y8_idx),
(mi_col + x32_idx + x16_idx + x8_idx),
// and then update the quantizer.
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0].src_mi->mbmi, mi_row,
- mi_col, bsize, ctx->rate, ctx->dist);
+ mi_col, bsize, ctx->rate, ctx->dist,
+ x->skip);
}
}
} else {
// Setting segmentation map for cyclic_refresh.
vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize,
- ctx->rate, ctx->dist);
+ ctx->rate, ctx->dist, x->skip);
}
vp9_init_plane_quantizers(cpi, x);
}
#include "vp9/encoder/vp9_context_tree.h"
#include "vp9/encoder/vp9_encodeframe.h"
#include "vp9/encoder/vp9_encodemv.h"
+#include "vp9/encoder/vp9_encoder.h"
#include "vp9/encoder/vp9_ethread.h"
#include "vp9/encoder/vp9_firstpass.h"
#include "vp9/encoder/vp9_mbgraph.h"
-#include "vp9/encoder/vp9_encoder.h"
#include "vp9/encoder/vp9_picklpf.h"
#include "vp9/encoder/vp9_ratectrl.h"
#include "vp9/encoder/vp9_rd.h"
+#include "vp9/encoder/vp9_resize.h"
#include "vp9/encoder/vp9_segmentation.h"
+#include "vp9/encoder/vp9_skin_detection.h"
#include "vp9/encoder/vp9_speed_features.h"
#if CONFIG_INTERNAL_STATS
#include "vp9/encoder/vp9_ssim.h"
#endif
-#include "vp9/encoder/vp9_temporal_filter.h"
-#include "vp9/encoder/vp9_resize.h"
#include "vp9/encoder/vp9_svc_layercontext.h"
-#include "vp9/encoder/vp9_skin_detection.h"
+#include "vp9/encoder/vp9_temporal_filter.h"
#define AM_SEGMENT_ID_INACTIVE 7
#define AM_SEGMENT_ID_ACTIVE 0
}
#endif // CONFIG_VP9_HIGHBITDEPTH
+static void realloc_segmentation_maps(VP9_COMP *cpi) {
+ VP9_COMMON *const cm = &cpi->common;
+
+ // Create the encoder segmentation map and set all entries to 0
+ vpx_free(cpi->segmentation_map);
+ CHECK_MEM_ERROR(cm, cpi->segmentation_map,
+ vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
+
+ // Create a map used for cyclic background refresh.
+ if (cpi->cyclic_refresh)
+ vp9_cyclic_refresh_free(cpi->cyclic_refresh);
+ CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
+ vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
+
+ // Create a map used to mark inactive areas.
+ vpx_free(cpi->active_map.map);
+ CHECK_MEM_ERROR(cm, cpi->active_map.map,
+ vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
+
+ // And a place holder structure is the coding context
+ // for use if we want to save and restore it
+ vpx_free(cpi->coding_context.last_frame_seg_map_copy);
+ CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
+ vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
+}
+
void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
if (cpi->initial_width) {
if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) {
vp9_free_context_buffers(cm);
- vp9_alloc_context_buffers(cm, cm->width, cm->height);
+ vp9_alloc_compressor_data(cpi);
+ realloc_segmentation_maps(cpi);
cpi->initial_width = cpi->initial_height = 0;
}
}
cpi->partition_search_skippable_frame = 0;
cpi->tile_data = NULL;
- // TODO(aconverse): Realloc these tables on frame resize
- // Create the encoder segmentation map and set all entries to 0
- CHECK_MEM_ERROR(cm, cpi->segmentation_map,
- vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
-
- // Create a map used for cyclic background refresh.
- CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
- vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
-
- CHECK_MEM_ERROR(cm, cpi->active_map.map,
- vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
-
- // And a place holder structure is the coding context
- // for use if we want to save and restore it
- CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
- vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
+ realloc_segmentation_maps(cpi);
CHECK_MEM_ERROR(cm, cpi->nmvcosts[0],
vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0])));
pred_mv[0] = mbmi->ref_mvs[ref_frame][0].as_mv;
pred_mv[1] = mbmi->ref_mvs[ref_frame][1].as_mv;
pred_mv[2] = x->pred_mv[ref_frame];
+ assert(num_mv_refs <= (int)(sizeof(pred_mv) / sizeof(pred_mv[0])));
// Get the sad for each candidate reference mv.
for (i = 0; i < num_mv_refs; ++i) {
uint8_t *tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) *
(width < height ? height : width));
uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * (height + height2));
+ assert(width > 0);
+ assert(height > 0);
+ assert(width2 > 0);
+ assert(height2 > 0);
for (i = 0; i < height; ++i)
resize_multistep(input + in_stride * i, width,
intbuf + width2 * i, width2, tmpbuf);
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
#include <emmintrin.h> // SSE2
#include "vp9/common/vp9_idct.h" // for cospi constants
#include "vp9/encoder/vp9_dct.h"
__m128i qcoeff0, qcoeff1;
__m128i qtmp0, qtmp1;
+ assert(index < (int)(sizeof(in) / sizeof(in[0])) - 1);
coeff0 = *in[index];
coeff1 = *in[index + 1];
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
#if defined(_MSC_VER) && _MSC_VER <= 1500
// Need to include math.h before calling tmmintrin.h/intrin.h
// in certain versions of MSVS.
__m128i qcoeff0, qcoeff1;
__m128i qtmp0, qtmp1;
+ assert(index < (int)(sizeof(in) / sizeof(in[0])) - 1);
coeff0 = *in[index];
coeff1 = *in[index + 1];
vpx_codec_err_t res = VPX_CODEC_OK;
VP9_COMP *const cpi = ctx->cpi;
const vpx_rational_t *const timebase = &ctx->cfg.g_timebase;
+ size_t data_sz;
if (img != NULL) {
res = validate_img(ctx, img);
// TODO(jzern) the checks related to cpi's validity should be treated as a
// failure condition, encoder setup is done fully in init() currently.
- if (res == VPX_CODEC_OK && cpi != NULL && ctx->cx_data == NULL) {
+ if (res == VPX_CODEC_OK && cpi != NULL) {
// There's no codec control for multiple alt-refs so check the encoder
// instance for its status to determine the compressed data size.
- ctx->cx_data_sz = ctx->cfg.g_w * ctx->cfg.g_h *
- get_image_bps(img) / 8 *
- (cpi->multi_arf_allowed ? 8 : 2);
- if (ctx->cx_data_sz < 4096) ctx->cx_data_sz = 4096;
-
- ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz);
- if (ctx->cx_data == NULL) {
- return VPX_CODEC_MEM_ERROR;
+ data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 *
+ (cpi->multi_arf_allowed ? 8 : 2);
+ if (data_sz < 4096)
+ data_sz = 4096;
+ if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
+ ctx->cx_data_sz = data_sz;
+ free(ctx->cx_data);
+ ctx->cx_data = (unsigned char*)malloc(ctx->cx_data_sz);
+ if (ctx->cx_data == NULL) {
+ return VPX_CODEC_MEM_ERROR;
+ }
}
}
}
+++ /dev/null
-/*
- * Copyright (c) 2011 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#ifndef VPX_PORTS_ASM_OFFSETS_H_
-#define VPX_PORTS_ASM_OFFSETS_H_
-
-#include <stddef.h>
-
-#define ct_assert(name,cond) \
- static void assert_##name(void) UNUSED;\
- static void assert_##name(void) {switch(0){case 0:case !!(cond):;}}
-
-#if INLINE_ASM
-#define DEFINE(sym, val) asm("\n" #sym " EQU %0" : : "i" (val))
-#define BEGIN int main(void) {
-#define END return 0; }
-#else
-#define DEFINE(sym, val) const int sym = val
-#define BEGIN
-#define END
-#endif
-
-#endif // VPX_PORTS_ASM_OFFSETS_H_
PORTS_SRCS-yes += vpx_ports.mk
-PORTS_SRCS-$(BUILD_LIBVPX) += asm_offsets.h
PORTS_SRCS-$(BUILD_LIBVPX) += mem.h
PORTS_SRCS-$(BUILD_LIBVPX) += vpx_timer.h
+++ /dev/null
-/*
- * Copyright (c) 2011 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#include "vpx_ports/asm_offsets.h"
-
-BEGIN
-
-END
"o", "output", 1, "Output file name pattern (see below)");
static const arg_def_t threadsarg = ARG_DEF(
"t", "threads", 1, "Max threads to use");
+static const arg_def_t frameparallelarg = ARG_DEF(
+ NULL, "frame-parallel", 0, "Frame parallel decode");
static const arg_def_t verbosearg = ARG_DEF(
"v", "verbose", 0, "Show version string");
static const arg_def_t error_concealment = ARG_DEF(
static const arg_def_t *all_args[] = {
&codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg,
&progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile,
- &threadsarg, &verbosearg, &scalearg, &fb_arg,
+ &threadsarg, &frameparallelarg, &verbosearg, &scalearg, &fb_arg,
&md5arg, &error_concealment, &continuearg,
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
&outbitdeptharg,
size_t bytes_in_buffer = 0, buffer_size = 0;
FILE *infile;
int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
- int do_md5 = 0, progress = 0;
+ int do_md5 = 0, progress = 0, frame_parallel = 0;
int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
int arg_skip = 0;
int ec_enabled = 0;
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
vpx_image_t *img_shifted = NULL;
#endif
- int frame_avail, got_data;
+ int frame_avail, got_data, flush_decoder = 0;
int num_external_frame_buffers = 0;
struct ExternalFrameBufferList ext_fb_list = {0, NULL};
summary = 1;
else if (arg_match(&arg, &threadsarg, argi))
cfg.threads = arg_parse_uint(&arg);
+#if CONFIG_VP9_DECODER
+ else if (arg_match(&arg, &frameparallelarg, argi))
+ frame_parallel = 1;
+#endif
else if (arg_match(&arg, &verbosearg, argi))
quiet = 0;
else if (arg_match(&arg, &scalearg, argi))
interface = get_vpx_decoder_by_index(0);
dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) |
- (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0);
+ (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0) |
+ (frame_parallel ? VPX_CODEC_USE_FRAME_THREADING : 0);
if (vpx_codec_dec_init(&decoder, interface->codec_interface(),
&cfg, dec_flags)) {
fprintf(stderr, "Failed to initialize decoder: %s\n",
vpx_codec_iter_t iter = NULL;
vpx_image_t *img;
struct vpx_usec_timer timer;
- int corrupted;
+ int corrupted = 0;
frame_avail = 0;
if (!stop_after || frame_in < stop_after) {
vpx_usec_timer_mark(&timer);
dx_time += vpx_usec_timer_elapsed(&timer);
+ } else {
+ flush_decoder = 1;
}
+ } else {
+ flush_decoder = 1;
}
vpx_usec_timer_start(&timer);
+ if (flush_decoder) {
+ // Flush the decoder in frame parallel decode.
+ if (vpx_codec_decode(&decoder, NULL, 0, NULL, 0)) {
+ warn("Failed to flush decoder: %s", vpx_codec_error(&decoder));
+ }
+ }
+
got_data = 0;
if ((img = vpx_codec_get_frame(&decoder, &iter))) {
++frame_out;
vpx_usec_timer_mark(&timer);
dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer);
- if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) {
+ if (!frame_parallel &&
+ vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) {
warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder));
if (!keep_going)
goto fail;