├── demo ├── src │ ├── H264NALDecoder.worker.js │ ├── ShaderCompiler.js │ ├── ShaderProgram.js │ ├── ShaderSources.js │ ├── Texture.js │ ├── YUVSurfaceShader.js │ └── index.js ├── dist │ ├── h264samples │ │ ├── 0 │ │ ├── 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 │ │ ├── 63 │ │ ├── 64 │ │ ├── 65 │ │ ├── 66 │ │ ├── 67 │ │ ├── 68 │ │ ├── 69 │ │ ├── 70 │ │ ├── 71 │ │ ├── 72 │ │ ├── 73 │ │ ├── 74 │ │ ├── 75 │ │ ├── 76 │ │ └── 77 │ └── index.html ├── README.md ├── package.json └── webpack.config.js ├── src ├── index.js ├── TinyH264Worker.js └── TinyH264Decoder.js ├── native ├── h264bsd_nal_unit.c ├── basetype.h ├── h264bsd_byte_stream.h ├── h264bsd_conceal.h ├── h264bsd_cavlc.h ├── h264bsd_deblocking.h ├── h264bsd_transform.h ├── h264bsd_cfg.h ├── h264bsd_slice_group_map.h ├── h264bsd_inter_prediction.h ├── h264bsd_slice_data.h ├── h264bsd_image.h ├── h264bsd_container.h ├── h264bsd_vlc.h ├── h264bsd_decoder.h ├── h264bsd_pic_order_cnt.h ├── h264bsd_stream.h ├── h264bsd_nal_unit.h ├── h264bsd_neighbour.h ├── h264bsd_pic_param_set.h ├── h264bsd_seq_param_set.h ├── h264bsd_intra_prediction.h ├── h264bsd_vui.h ├── h264bsd_dpb.h ├── h264bsd_reconstruct.h ├── h264bsd_util.h ├── h264bsd_macroblock_layer.h ├── h264bsd_storage.h ├── h264bsd_slice_header.h ├── h264bsd_stream.c ├── h264bsd_sei.h ├── h264bsd_byte_stream.c ├── h264bsd_util.c ├── h264bsd_image.c ├── h264bsd_pic_param_set.c └── h264bsd_neighbour.c ├── nwb.config.js ├── package.json ├── README.md ├── .gitignore └── LICENSE /demo/src/H264NALDecoder.worker.js: -------------------------------------------------------------------------------- 1 | import { init } from 'tinyh264' 2 | 3 | init() 4 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { init } from './TinyH264Worker' 2 | 3 | export { 4 | init 5 | } 6 | -------------------------------------------------------------------------------- /demo/dist/h264samples/0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/0 -------------------------------------------------------------------------------- /demo/dist/h264samples/1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/1 -------------------------------------------------------------------------------- /demo/dist/h264samples/2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/2 -------------------------------------------------------------------------------- /demo/dist/h264samples/3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/3 -------------------------------------------------------------------------------- /demo/dist/h264samples/4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/4 -------------------------------------------------------------------------------- /demo/dist/h264samples/5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/5 -------------------------------------------------------------------------------- /demo/dist/h264samples/6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/6 -------------------------------------------------------------------------------- /demo/dist/h264samples/7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/7 -------------------------------------------------------------------------------- /demo/dist/h264samples/8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/8 -------------------------------------------------------------------------------- /demo/dist/h264samples/9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/9 -------------------------------------------------------------------------------- /demo/dist/h264samples/10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/10 -------------------------------------------------------------------------------- /demo/dist/h264samples/11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/11 -------------------------------------------------------------------------------- /demo/dist/h264samples/12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/12 -------------------------------------------------------------------------------- /demo/dist/h264samples/13: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/13 -------------------------------------------------------------------------------- /demo/dist/h264samples/14: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/14 -------------------------------------------------------------------------------- /demo/dist/h264samples/15: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/15 -------------------------------------------------------------------------------- /demo/dist/h264samples/16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/16 -------------------------------------------------------------------------------- /demo/dist/h264samples/17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/17 -------------------------------------------------------------------------------- /demo/dist/h264samples/18: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/18 -------------------------------------------------------------------------------- /demo/dist/h264samples/19: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/19 -------------------------------------------------------------------------------- /demo/dist/h264samples/20: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/20 -------------------------------------------------------------------------------- /demo/dist/h264samples/21: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/21 -------------------------------------------------------------------------------- /demo/dist/h264samples/22: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/22 -------------------------------------------------------------------------------- /demo/dist/h264samples/23: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/23 -------------------------------------------------------------------------------- /demo/dist/h264samples/24: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/24 -------------------------------------------------------------------------------- /demo/dist/h264samples/25: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/25 -------------------------------------------------------------------------------- /demo/dist/h264samples/26: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/26 -------------------------------------------------------------------------------- /demo/dist/h264samples/27: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/27 -------------------------------------------------------------------------------- /demo/dist/h264samples/28: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/28 -------------------------------------------------------------------------------- /demo/dist/h264samples/29: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/29 -------------------------------------------------------------------------------- /demo/dist/h264samples/30: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/30 -------------------------------------------------------------------------------- /demo/dist/h264samples/31: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/31 -------------------------------------------------------------------------------- /demo/dist/h264samples/32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/32 -------------------------------------------------------------------------------- /demo/dist/h264samples/33: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/33 -------------------------------------------------------------------------------- /demo/dist/h264samples/34: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/34 -------------------------------------------------------------------------------- /demo/dist/h264samples/35: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/35 -------------------------------------------------------------------------------- /demo/dist/h264samples/36: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/36 -------------------------------------------------------------------------------- /demo/dist/h264samples/37: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/37 -------------------------------------------------------------------------------- /demo/dist/h264samples/38: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/38 -------------------------------------------------------------------------------- /demo/dist/h264samples/39: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/39 -------------------------------------------------------------------------------- /demo/dist/h264samples/40: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/40 -------------------------------------------------------------------------------- /demo/dist/h264samples/41: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/41 -------------------------------------------------------------------------------- /demo/dist/h264samples/42: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/42 -------------------------------------------------------------------------------- /demo/dist/h264samples/43: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/43 -------------------------------------------------------------------------------- /demo/dist/h264samples/44: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/44 -------------------------------------------------------------------------------- /demo/dist/h264samples/45: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/45 -------------------------------------------------------------------------------- /demo/dist/h264samples/46: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/46 -------------------------------------------------------------------------------- /demo/dist/h264samples/47: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/47 -------------------------------------------------------------------------------- /demo/dist/h264samples/48: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/48 -------------------------------------------------------------------------------- /demo/dist/h264samples/49: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/49 -------------------------------------------------------------------------------- /demo/dist/h264samples/50: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/50 -------------------------------------------------------------------------------- /demo/dist/h264samples/51: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/51 -------------------------------------------------------------------------------- /demo/dist/h264samples/52: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/52 -------------------------------------------------------------------------------- /demo/dist/h264samples/53: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/53 -------------------------------------------------------------------------------- /demo/dist/h264samples/54: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/54 -------------------------------------------------------------------------------- /demo/dist/h264samples/55: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/55 -------------------------------------------------------------------------------- /demo/dist/h264samples/56: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/56 -------------------------------------------------------------------------------- /demo/dist/h264samples/57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/57 -------------------------------------------------------------------------------- /demo/dist/h264samples/58: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/58 -------------------------------------------------------------------------------- /demo/dist/h264samples/59: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/59 -------------------------------------------------------------------------------- /demo/dist/h264samples/60: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/60 -------------------------------------------------------------------------------- /demo/dist/h264samples/61: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/61 -------------------------------------------------------------------------------- /demo/dist/h264samples/62: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/62 -------------------------------------------------------------------------------- /demo/dist/h264samples/63: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/63 -------------------------------------------------------------------------------- /demo/dist/h264samples/64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/64 -------------------------------------------------------------------------------- /demo/dist/h264samples/65: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/65 -------------------------------------------------------------------------------- /demo/dist/h264samples/66: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/66 -------------------------------------------------------------------------------- /demo/dist/h264samples/67: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/67 -------------------------------------------------------------------------------- /demo/dist/h264samples/68: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/68 -------------------------------------------------------------------------------- /demo/dist/h264samples/69: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/69 -------------------------------------------------------------------------------- /demo/dist/h264samples/70: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/70 -------------------------------------------------------------------------------- /demo/dist/h264samples/71: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/71 -------------------------------------------------------------------------------- /demo/dist/h264samples/72: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/72 -------------------------------------------------------------------------------- /demo/dist/h264samples/73: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/73 -------------------------------------------------------------------------------- /demo/dist/h264samples/74: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/74 -------------------------------------------------------------------------------- /demo/dist/h264samples/75: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/75 -------------------------------------------------------------------------------- /demo/dist/h264samples/76: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/76 -------------------------------------------------------------------------------- /demo/dist/h264samples/77: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/demo/dist/h264samples/77 -------------------------------------------------------------------------------- /native/h264bsd_nal_unit.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udevbe/tinyh264/HEAD/native/h264bsd_nal_unit.c -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 | - `yarn install` 2 | - `yarn build` 3 | - `yarn start` 4 | 5 | Server runs on `http://localhost:8080/dist`. 6 | -------------------------------------------------------------------------------- /demo/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tiny-h264 demo 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /nwb.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | type: 'web-module', 3 | npm: { 4 | esModules: true, 5 | umd: false 6 | }, 7 | babel: { 8 | env: { 9 | targets: { 10 | browsers: 'last 2 versions' 11 | }, 12 | modules: false 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "webpack --config webpack.config.js", 9 | "start": "webpack-dev-server" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "tinyh264": "link:.." 16 | }, 17 | "devDependencies": { 18 | "file-loader": "^5.0.2", 19 | "webpack": "^4.41.5", 20 | "webpack-cli": "^3.3.10", 21 | "webpack-dev-server": "^3.10.1", 22 | "worker-loader": "^2.0.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | module.exports = { 4 | entry: './src/index.js', 5 | output: { 6 | filename: 'main.js', 7 | path: path.resolve(__dirname, 'dist'), 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.worker\.js$/, 13 | use: {loader: 'worker-loader'} 14 | }, 15 | { 16 | test: /\.(asset)$/i, 17 | use: [ 18 | { 19 | loader: 'file-loader', 20 | options: { 21 | name: '[contenthash].wasm' 22 | } 23 | }, 24 | ], 25 | } 26 | ] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tinyh264", 3 | "version": "0.0.7", 4 | "description": "web assembly h264 decoder", 5 | "main": "lib/index.js", 6 | "module": "es/index.js", 7 | "files": [ 8 | "es", 9 | "lib" 10 | ], 11 | "scripts": { 12 | "build-wasm": "bash build_wasm.sh", 13 | "build": "nwb build-web-module --copy-files", 14 | "clean": "nwb clean-web-module", 15 | "prepublishOnly": "npm run build", 16 | "test": "nwb test", 17 | "test:coverage": "nwb test --coverage", 18 | "test:watch": "nwb test --server" 19 | }, 20 | "dependencies": {}, 21 | "devDependencies": { 22 | "nwb": "0.25.2" 23 | }, 24 | "author": "Erik De Rijcke", 25 | "homepage": "https://github.com/udevbe/tinyh264", 26 | "license": "Apache-2.0", 27 | "repository": "https://github.com/udevbe/tinyh264" 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tiny H264 2 | 3 | This project was forked from [h264bsd](https://github.com/oneam/h264bsd). 4 | 5 | Available on npm as `tinyh264` and meant to be used with a builder system like webpack as [worker module](https://webpack.js.org/loaders/worker-loader/). 6 | See `demo` folder for an example. 7 | 8 | All non-essential operations like color conversions, querying cropping parameters or render to canvas have been removed. 9 | All required decoding operations have been moved to C to optimize performance. 10 | 11 | Quick tests show an up to 50% performance improvement on chrome, and up to 20% on Firefox. 12 | 13 | - Input is expected to be a picture of NALs (a complete access units or AU) as Uint8Array, the output result is a yuv420 buffer as Uint8Array. 14 | - Profile must be constrained-baseline or baseline. 15 | - Only I and P frames are considered supported (so no B-frames). 16 | 17 | This project was created for use in [Greenfield](https://github.com/udevbe/greenfield) 18 | 19 | # Building 20 | ## Prerequisites 21 | - Bash 22 | 23 | Make sure you have sourced the emscripten environment and run `npm install && npm run build`. 24 | -------------------------------------------------------------------------------- /demo/src/ShaderCompiler.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Represents a WebGL shader object and provides a mechanism to load shaders from HTML 3 | * script tags. 4 | */ 5 | 6 | export default class ShaderCompiler { 7 | /** 8 | * @param {WebGLRenderingContext}gl 9 | * @param {{type: string, source: string}}script 10 | * @return {WebGLShader} 11 | */ 12 | static compile (gl, script) { 13 | let shader 14 | // Now figure out what type of shader script we have, based on its MIME type. 15 | if (script.type === 'x-shader/x-fragment') { 16 | shader = gl.createShader(gl.FRAGMENT_SHADER) 17 | } else if (script.type === 'x-shader/x-vertex') { 18 | shader = gl.createShader(gl.VERTEX_SHADER) 19 | } else { 20 | throw new Error('Unknown shader type: ' + script.type) 21 | } 22 | 23 | // Send the source to the shader object. 24 | gl.shaderSource(shader, script.source) 25 | 26 | // Compile the shader program. 27 | gl.compileShader(shader) 28 | 29 | // See if it compiled successfully. 30 | if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { 31 | throw new Error('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader)) 32 | } 33 | 34 | return shader 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demo/src/ShaderProgram.js: -------------------------------------------------------------------------------- 1 | export default class ShaderProgram { 2 | /** 3 | * @param {WebGLRenderingContext}gl 4 | */ 5 | constructor (gl) { 6 | this.gl = gl 7 | this.program = this.gl.createProgram() 8 | } 9 | 10 | /** 11 | * @param {WebGLShader}shader 12 | */ 13 | attach (shader) { 14 | this.gl.attachShader(this.program, shader) 15 | } 16 | 17 | link () { 18 | this.gl.linkProgram(this.program) 19 | // If creating the shader program failed, alert. 20 | if (!this.gl.getProgramParameter(this.program, this.gl.LINK_STATUS)) { 21 | console.error('Unable to initialize the shader program.') 22 | } 23 | } 24 | 25 | use () { 26 | this.gl.useProgram(this.program) 27 | } 28 | 29 | /** 30 | * @param {string}name 31 | * @return {number} 32 | */ 33 | getAttributeLocation (name) { 34 | return this.gl.getAttribLocation(this.program, name) 35 | } 36 | 37 | /** 38 | * @param {string}name 39 | * @return {WebGLUniformLocation | null} 40 | */ 41 | getUniformLocation (name) { 42 | return this.gl.getUniformLocation(this.program, name) 43 | } 44 | 45 | /** 46 | * @param {WebGLUniformLocation}uniformLocation 47 | * @param {Array}array 48 | */ 49 | setUniformM4 (uniformLocation, array) { 50 | this.gl.uniformMatrix4fv(uniformLocation, false, array) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /demo/src/ShaderSources.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {{type: string, source: string}} 3 | */ 4 | export const vertexQuad = { 5 | type: 'x-shader/x-vertex', 6 | source: ` 7 | precision mediump float; 8 | 9 | uniform mat4 u_projection; 10 | attribute vec2 a_position; 11 | attribute vec2 a_texCoord; 12 | varying vec2 v_texCoord; 13 | void main(){ 14 | v_texCoord = a_texCoord; 15 | gl_Position = u_projection * vec4(a_position, 0.0, 1.0); 16 | } 17 | ` 18 | } 19 | 20 | /** 21 | * @type {{type: string, source: string}} 22 | */ 23 | export const fragmentYUV = { 24 | type: 'x-shader/x-fragment', 25 | source: ` 26 | precision lowp float; 27 | 28 | varying vec2 v_texCoord; 29 | 30 | uniform sampler2D yTexture; 31 | uniform sampler2D uTexture; 32 | uniform sampler2D vTexture; 33 | 34 | const mat4 conversion = mat4( 35 | 1.0, 0.0, 1.402, -0.701, 36 | 1.0, -0.344, -0.714, 0.529, 37 | 1.0, 1.772, 0.0, -0.886, 38 | 0.0, 0.0, 0.0, 0.0 39 | ); 40 | 41 | void main(void) { 42 | float yChannel = texture2D(yTexture, v_texCoord).x; 43 | float uChannel = texture2D(uTexture, v_texCoord).x; 44 | float vChannel = texture2D(vTexture, v_texCoord).x; 45 | vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0); 46 | vec3 rgb = (channels * conversion).xyz; 47 | gl_FragColor = vec4(rgb, 1.0); 48 | } 49 | ` 50 | } 51 | -------------------------------------------------------------------------------- /src/TinyH264Worker.js: -------------------------------------------------------------------------------- 1 | import TinyH264Decoder from './TinyH264Decoder' 2 | import TinyH264 from './TinyH264' 3 | 4 | const h264Decoders = {} 5 | 6 | function init () { 7 | return TinyH264().then((tinyH264) => { 8 | self.addEventListener('message', (e) => { 9 | const message = e.data 10 | const renderStateId = message.renderStateId 11 | const messageType = message.type 12 | switch (messageType) { 13 | case 'decode': { 14 | let decoder = h264Decoders[renderStateId] 15 | if (!decoder) { 16 | decoder = new TinyH264Decoder(tinyH264, (output, width, height) => { 17 | postMessage({ 18 | type: 'pictureReady', 19 | width: width, 20 | height: height, 21 | renderStateId: renderStateId, 22 | data: output.buffer 23 | }, [output.buffer]) 24 | }) 25 | h264Decoders[renderStateId] = decoder 26 | } 27 | decoder.decode(new Uint8Array(message.data, message.offset, message.length)) 28 | break 29 | } 30 | case 'release': { 31 | const decoder = h264Decoders[renderStateId] 32 | if (decoder) { 33 | decoder.release() 34 | delete h264Decoders[renderStateId] 35 | } 36 | break 37 | } 38 | } 39 | }) 40 | 41 | self.postMessage({ 'type': 'decoderReady' }) 42 | }) 43 | } 44 | 45 | export { 46 | init 47 | } 48 | -------------------------------------------------------------------------------- /native/basetype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | #ifndef BASETYPE_H_INCLUDED 20 | #define BASETYPE_H_INCLUDED 21 | 22 | 23 | #ifdef __arm 24 | #define VOLATILE volatile 25 | #else 26 | #define VOLATILE 27 | #endif 28 | 29 | typedef unsigned char u8; 30 | typedef signed char i8; 31 | typedef unsigned short u16; 32 | typedef signed short i16; 33 | typedef unsigned int u32; 34 | typedef signed int i32; 35 | 36 | #if defined(VC1SWDEC_16BIT) || defined(MP4ENC_ARM11) 37 | typedef unsigned short u16x; 38 | typedef signed short i16x; 39 | #else 40 | typedef unsigned int u16x; 41 | typedef signed int i16x; 42 | #endif 43 | 44 | 45 | #ifndef NULL 46 | #ifdef __cplusplus 47 | #define NULL 0 48 | #else 49 | #define NULL ((void *)0) 50 | #endif 51 | #endif 52 | 53 | #endif /* BASETYPE_H_INCLUDED */ 54 | -------------------------------------------------------------------------------- /native/h264bsd_byte_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_BYTE_STREAM_H 30 | #define H264SWDEC_BYTE_STREAM_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | /*------------------------------------------------------------------------------ 44 | 3. Data types 45 | ------------------------------------------------------------------------------*/ 46 | 47 | /*------------------------------------------------------------------------------ 48 | 4. Function prototypes 49 | ------------------------------------------------------------------------------*/ 50 | 51 | u32 h264bsdExtractNalUnit(u8 *pByteStream, u32 len, strmData_t *pStrmData, 52 | u32 *readBytes); 53 | 54 | #endif /* #ifdef H264SWDEC_BYTE_STREAM_H */ 55 | 56 | -------------------------------------------------------------------------------- /native/h264bsd_conceal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_CONCEAL_H 30 | #define H264SWDEC_CONCEAL_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_slice_header.h" 38 | #include "h264bsd_storage.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | 52 | u32 h264bsdConceal(storage_t *pStorage, image_t *currImage, u32 sliceType); 53 | 54 | #endif /* #ifdef H264SWDEC_CONCEAL_H */ 55 | 56 | -------------------------------------------------------------------------------- /native/h264bsd_cavlc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_CAVLC_H 30 | #define H264SWDEC_CAVLC_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | 52 | u32 h264bsdDecodeResidualBlockCavlc( 53 | strmData_t *pStrmData, 54 | i32 *coeffLevel, 55 | i32 nc, 56 | u32 maxNumCoeff); 57 | 58 | #endif /* #ifdef H264SWDEC_CAVLC_H */ 59 | 60 | -------------------------------------------------------------------------------- /native/h264bsd_deblocking.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_DEBLOCKING_H 30 | #define H264SWDEC_DEBLOCKING_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_image.h" 38 | #include "h264bsd_macroblock_layer.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | 52 | void h264bsdFilterPicture( 53 | image_t *image, 54 | mbStorage_t *mb); 55 | 56 | #endif /* #ifdef H264SWDEC_DEBLOCKING_H */ 57 | 58 | -------------------------------------------------------------------------------- /native/h264bsd_transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_TRANSFORM_H 30 | #define H264SWDEC_TRANSFORM_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | 38 | /*------------------------------------------------------------------------------ 39 | 2. Module defines 40 | ------------------------------------------------------------------------------*/ 41 | 42 | /*------------------------------------------------------------------------------ 43 | 3. Data types 44 | ------------------------------------------------------------------------------*/ 45 | 46 | /*------------------------------------------------------------------------------ 47 | 4. Function prototypes 48 | ------------------------------------------------------------------------------*/ 49 | 50 | u32 h264bsdProcessBlock(i32 *data, u32 qp, u32 skip, u32 coeffMap); 51 | void h264bsdProcessLumaDc(i32 *data, u32 qp); 52 | void h264bsdProcessChromaDc(i32 *data, u32 qp); 53 | 54 | #endif /* #ifdef H264SWDEC_TRANSFORM_H */ 55 | 56 | -------------------------------------------------------------------------------- /native/h264bsd_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_CFG_H 30 | #define H264SWDEC_CFG_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include 38 | #include 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | #define MAX_NUM_REF_PICS 16 45 | #define MAX_NUM_SLICE_GROUPS 8 46 | #define MAX_NUM_SEQ_PARAM_SETS 32 47 | #define MAX_NUM_PIC_PARAM_SETS 256 48 | 49 | /*------------------------------------------------------------------------------ 50 | 3. Data types 51 | ------------------------------------------------------------------------------*/ 52 | 53 | 54 | /*------------------------------------------------------------------------------ 55 | 4. Function prototypes 56 | ------------------------------------------------------------------------------*/ 57 | 58 | #endif /* #ifdef H264SWDEC_CFG_H */ 59 | 60 | -------------------------------------------------------------------------------- /native/h264bsd_slice_group_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_SLICE_GROUP_MAP_H 30 | #define H264SWDEC_SLICE_GROUP_MAP_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_pic_param_set.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | 49 | /*------------------------------------------------------------------------------ 50 | 4. Function prototypes 51 | ------------------------------------------------------------------------------*/ 52 | 53 | void h264bsdDecodeSliceGroupMap( 54 | u32 *map, 55 | picParamSet_t *pps, 56 | u32 sliceGroupChangeCycle, 57 | u32 picWidth, 58 | u32 picHeight); 59 | 60 | #endif /* #ifdef H264SWDEC_SLICE_GROUP_MAP_H */ 61 | 62 | -------------------------------------------------------------------------------- /native/h264bsd_inter_prediction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_INTER_PREDICTION_H 30 | #define H264SWDEC_INTER_PREDICTION_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_image.h" 38 | #include "h264bsd_macroblock_layer.h" 39 | #include "h264bsd_dpb.h" 40 | 41 | /*------------------------------------------------------------------------------ 42 | 2. Module defines 43 | ------------------------------------------------------------------------------*/ 44 | 45 | /*------------------------------------------------------------------------------ 46 | 3. Data types 47 | ------------------------------------------------------------------------------*/ 48 | 49 | /*------------------------------------------------------------------------------ 50 | 4. Function prototypes 51 | ------------------------------------------------------------------------------*/ 52 | 53 | u32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer, 54 | dpbStorage_t *dpb, u32 mbNum, image_t *image, u8 *data); 55 | 56 | #endif /* #ifdef H264SWDEC_INTER_PREDICTION_H */ 57 | 58 | -------------------------------------------------------------------------------- /native/h264bsd_slice_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_SLICE_DATA_H 30 | #define H264SWDEC_SLICE_DATA_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_cfg.h" 39 | #include "h264bsd_slice_header.h" 40 | #include "h264bsd_storage.h" 41 | 42 | /*------------------------------------------------------------------------------ 43 | 2. Module defines 44 | ------------------------------------------------------------------------------*/ 45 | 46 | /*------------------------------------------------------------------------------ 47 | 3. Data types 48 | ------------------------------------------------------------------------------*/ 49 | 50 | /*------------------------------------------------------------------------------ 51 | 4. Function prototypes 52 | ------------------------------------------------------------------------------*/ 53 | 54 | u32 h264bsdDecodeSliceData(strmData_t *pStrmData, storage_t *pStorage, 55 | image_t *currImage, sliceHeader_t *pSliceHeader); 56 | 57 | void h264bsdMarkSliceCorrupted(storage_t *pStorage, u32 firstMbInSlice); 58 | 59 | #endif /* #ifdef H264SWDEC_SLICE_DATA_H */ 60 | 61 | -------------------------------------------------------------------------------- /native/h264bsd_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_IMAGE_H 30 | #define H264SWDEC_IMAGE_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | 38 | /*------------------------------------------------------------------------------ 39 | 2. Module defines 40 | ------------------------------------------------------------------------------*/ 41 | 42 | /*------------------------------------------------------------------------------ 43 | 3. Data types 44 | ------------------------------------------------------------------------------*/ 45 | 46 | typedef struct 47 | { 48 | u8 *data; 49 | u32 width; 50 | u32 height; 51 | /* current MB's components */ 52 | u8 *luma; 53 | u8 *cb; 54 | u8 *cr; 55 | } image_t; 56 | 57 | /*------------------------------------------------------------------------------ 58 | 4. Function prototypes 59 | ------------------------------------------------------------------------------*/ 60 | 61 | void h264bsdWriteMacroblock(image_t *image, u8 *data); 62 | 63 | #ifndef H264DEC_OMXDL 64 | void h264bsdWriteOutputBlocks(image_t *image, u32 mbNum, u8 *data, 65 | i32 residual[][16]); 66 | #endif 67 | 68 | #endif /* #ifdef H264SWDEC_IMAGE_H */ 69 | 70 | -------------------------------------------------------------------------------- /native/h264bsd_container.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_CONTAINER_H 30 | #define H264SWDEC_CONTAINER_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_storage.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | /* String length for tracing */ 44 | #define H264DEC_TRACE_STR_LEN 100 45 | 46 | /*------------------------------------------------------------------------------ 47 | 3. Data types 48 | ------------------------------------------------------------------------------*/ 49 | 50 | typedef struct 51 | { 52 | enum { 53 | UNINITIALIZED, 54 | INITIALIZED, 55 | NEW_HEADERS 56 | } decStat; 57 | 58 | u32 picNumber; 59 | storage_t storage; 60 | #ifdef H264DEC_TRACE 61 | char str[H264DEC_TRACE_STR_LEN]; 62 | #endif 63 | } decContainer_t; 64 | 65 | /*------------------------------------------------------------------------------ 66 | 4. Function prototypes 67 | ------------------------------------------------------------------------------*/ 68 | 69 | #endif /* #ifdef H264SWDEC_DECCONTAINER_H */ 70 | 71 | -------------------------------------------------------------------------------- /native/h264bsd_vlc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_VLC_H 30 | #define H264SWDEC_VLC_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_transform.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | 45 | /*------------------------------------------------------------------------------ 46 | 3. Data types 47 | ------------------------------------------------------------------------------*/ 48 | 49 | /*------------------------------------------------------------------------------ 50 | 4. Function prototypes 51 | ------------------------------------------------------------------------------*/ 52 | 53 | u32 h264bsdDecodeExpGolombUnsigned(strmData_t *pStrmData, u32 *value); 54 | 55 | u32 h264bsdDecodeExpGolombSigned(strmData_t *pStrmData, i32 *value); 56 | 57 | u32 h264bsdDecodeExpGolombMapped(strmData_t *pStrmData, u32 *value, 58 | u32 isIntra); 59 | 60 | u32 h264bsdDecodeExpGolombTruncated(strmData_t *pStrmData, u32 *value, 61 | u32 greaterThanOne); 62 | 63 | #endif /* #ifdef H264SWDEC_VLC_H */ 64 | 65 | -------------------------------------------------------------------------------- /native/h264bsd_decoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_DECODER_H 30 | #define H264SWDEC_DECODER_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | 38 | #include "h264bsd_storage.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /* enumerated return values of the functions */ 45 | enum { 46 | H264BSD_RDY, 47 | H264BSD_PIC_RDY, 48 | H264BSD_HDRS_RDY, 49 | H264BSD_ERROR, 50 | H264BSD_PARAM_SET_ERROR, 51 | H264BSD_MEMALLOC_ERROR 52 | }; 53 | 54 | /*------------------------------------------------------------------------------ 55 | 3. Data types 56 | ------------------------------------------------------------------------------*/ 57 | 58 | 59 | 60 | /*------------------------------------------------------------------------------ 61 | 4. Function prototypes 62 | ------------------------------------------------------------------------------*/ 63 | 64 | u32 h264bsdInit(storage_t *pStorage, u32 noOutputReordering); 65 | u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u8 **picture, u32 *width, u32 *height); 66 | void h264bsdShutdown(storage_t *pStorage); 67 | 68 | storage_t* h264bsdAlloc(); 69 | void h264bsdFree(storage_t *pStorage); 70 | 71 | #endif /* #ifdef H264SWDEC_DECODER_H */ 72 | 73 | -------------------------------------------------------------------------------- /native/h264bsd_pic_order_cnt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_PIC_ORDER_CNT_H 30 | #define H264SWDEC_PIC_ORDER_CNT_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_seq_param_set.h" 38 | #include "h264bsd_slice_header.h" 39 | #include "h264bsd_nal_unit.h" 40 | 41 | /*------------------------------------------------------------------------------ 42 | 2. Module defines 43 | ------------------------------------------------------------------------------*/ 44 | 45 | 46 | /*------------------------------------------------------------------------------ 47 | 3. Data types 48 | ------------------------------------------------------------------------------*/ 49 | 50 | /* structure to store information computed for previous picture, needed for 51 | * POC computation of a picture. Two first fields for POC type 0, last two 52 | * for types 1 and 2 */ 53 | typedef struct 54 | { 55 | u32 prevPicOrderCntLsb; 56 | i32 prevPicOrderCntMsb; 57 | u32 prevFrameNum; 58 | u32 prevFrameNumOffset; 59 | } pocStorage_t; 60 | 61 | /*------------------------------------------------------------------------------ 62 | 4. Function prototypes 63 | ------------------------------------------------------------------------------*/ 64 | 65 | i32 h264bsdDecodePicOrderCnt(pocStorage_t *poc, seqParamSet_t *sps, 66 | sliceHeader_t *sliceHeader, nalUnit_t *pNalUnit); 67 | 68 | #endif /* #ifdef H264SWDEC_PIC_ORDER_CNT_H */ 69 | 70 | -------------------------------------------------------------------------------- /native/h264bsd_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_STREAM_H 30 | #define H264SWDEC_STREAM_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | 38 | /*------------------------------------------------------------------------------ 39 | 2. Module defines 40 | ------------------------------------------------------------------------------*/ 41 | 42 | /*------------------------------------------------------------------------------ 43 | 3. Data types 44 | ------------------------------------------------------------------------------*/ 45 | 46 | typedef struct 47 | { 48 | u8 *pStrmBuffStart; /* pointer to start of stream buffer */ 49 | u8 *pStrmCurrPos; /* current read address in stream buffer */ 50 | u32 bitPosInWord; /* bit position in stream buffer byte */ 51 | u32 strmBuffSize; /* size of stream buffer (bytes) */ 52 | u32 strmBuffReadBits; /* number of bits read from stream buffer */ 53 | } strmData_t; 54 | 55 | /*------------------------------------------------------------------------------ 56 | 4. Function prototypes 57 | ------------------------------------------------------------------------------*/ 58 | 59 | u32 h264bsdGetBits(strmData_t *pStrmData, u32 numBits); 60 | 61 | u32 h264bsdShowBits32(strmData_t *pStrmData); 62 | 63 | u32 h264bsdFlushBits(strmData_t *pStrmData, u32 numBits); 64 | 65 | u32 h264bsdIsByteAligned(strmData_t *); 66 | 67 | #endif /* #ifdef H264SWDEC_STREAM_H */ 68 | 69 | -------------------------------------------------------------------------------- /native/h264bsd_nal_unit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_NAL_UNIT_H 30 | #define H264SWDEC_NAL_UNIT_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | /* macro to determine if NAL unit pointed by pNalUnit contains an IDR slice */ 44 | #define IS_IDR_NAL_UNIT(pNalUnit) \ 45 | ((pNalUnit)->nalUnitType == NAL_CODED_SLICE_IDR) 46 | 47 | /*------------------------------------------------------------------------------ 48 | 3. Data types 49 | ------------------------------------------------------------------------------*/ 50 | 51 | typedef enum { 52 | NAL_CODED_SLICE = 1, 53 | NAL_CODED_SLICE_IDR = 5, 54 | NAL_SEI = 6, 55 | NAL_SEQ_PARAM_SET = 7, 56 | NAL_PIC_PARAM_SET = 8, 57 | NAL_ACCESS_UNIT_DELIMITER = 9, 58 | NAL_END_OF_SEQUENCE = 10, 59 | NAL_END_OF_STREAM = 11, 60 | NAL_FILLER_DATA = 12, 61 | NAL_MAX_TYPE_VALUE = 31 62 | } nalUnitType_e; 63 | 64 | typedef struct 65 | { 66 | nalUnitType_e nalUnitType; 67 | u32 nalRefIdc; 68 | } nalUnit_t; 69 | 70 | /*------------------------------------------------------------------------------ 71 | 4. Function prototypes 72 | ------------------------------------------------------------------------------*/ 73 | 74 | u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit); 75 | 76 | #endif /* #ifdef H264SWDEC_NAL_UNIT_H */ 77 | 78 | -------------------------------------------------------------------------------- /native/h264bsd_neighbour.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_NEIGHBOUR_H 30 | #define H264SWDEC_NEIGHBOUR_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_macroblock_layer.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | typedef enum { 44 | MB_A = 0, 45 | MB_B, 46 | MB_C, 47 | MB_D, 48 | MB_CURR, 49 | MB_NA = 0xFF 50 | } neighbourMb_e; 51 | 52 | /*------------------------------------------------------------------------------ 53 | 3. Data types 54 | ------------------------------------------------------------------------------*/ 55 | 56 | typedef struct 57 | { 58 | neighbourMb_e mb; 59 | u8 index; 60 | } neighbour_t; 61 | 62 | /*------------------------------------------------------------------------------ 63 | 4. Function prototypes 64 | ------------------------------------------------------------------------------*/ 65 | 66 | void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth, 67 | u32 picSizeInMbs); 68 | 69 | mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour); 70 | 71 | u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour); 72 | 73 | const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex); 74 | const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex); 75 | const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex); 76 | const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex); 77 | 78 | #endif /* #ifdef H264SWDEC_NEIGHBOUR_H */ 79 | 80 | -------------------------------------------------------------------------------- /native/h264bsd_pic_param_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_PIC_PARAM_SET_H 30 | #define H264SWDEC_PIC_PARAM_SET_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | /*------------------------------------------------------------------------------ 44 | 3. Data types 45 | ------------------------------------------------------------------------------*/ 46 | 47 | /* data structure to store PPS information decoded from the stream */ 48 | typedef struct 49 | { 50 | u32 picParameterSetId; 51 | u32 seqParameterSetId; 52 | u32 picOrderPresentFlag; 53 | u32 numSliceGroups; 54 | u32 sliceGroupMapType; 55 | u32 *runLength; 56 | u32 *topLeft; 57 | u32 *bottomRight; 58 | u32 sliceGroupChangeDirectionFlag; 59 | u32 sliceGroupChangeRate; 60 | u32 picSizeInMapUnits; 61 | u32 *sliceGroupId; 62 | u32 numRefIdxL0Active; 63 | u32 picInitQp; 64 | i32 chromaQpIndexOffset; 65 | u32 deblockingFilterControlPresentFlag; 66 | u32 constrainedIntraPredFlag; 67 | u32 redundantPicCntPresentFlag; 68 | } picParamSet_t; 69 | 70 | /*------------------------------------------------------------------------------ 71 | 4. Function prototypes 72 | ------------------------------------------------------------------------------*/ 73 | 74 | u32 h264bsdDecodePicParamSet(strmData_t *pStrmData, 75 | picParamSet_t *pPicParamSet); 76 | 77 | #endif /* #ifdef H264SWDEC_PIC_PARAM_SET_H */ 78 | 79 | -------------------------------------------------------------------------------- /demo/src/Texture.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Erik De Rijcke 2 | // 3 | // This file is part of Greenfield. 4 | // 5 | // Greenfield is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Affero General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Greenfield is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Affero General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with Greenfield. If not, see . 17 | 18 | /** 19 | * Represents a WebGL texture object. 20 | */ 21 | export default class Texture { 22 | /** 23 | * @param {!WebGLRenderingContext}gl 24 | * @param {!number}format 25 | * @return {!Texture} 26 | */ 27 | static create (gl, format) { 28 | const texture = gl.createTexture() 29 | gl.bindTexture(gl.TEXTURE_2D, texture) 30 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) 31 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) 32 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) 33 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) 34 | gl.bindTexture(gl.TEXTURE_2D, null) 35 | return new Texture(gl, format, texture) 36 | } 37 | 38 | /** 39 | * Use Texture.create(..) instead. 40 | * @param {WebGLRenderingContext}gl 41 | * @param {number}format 42 | * @param {WebGLTexture}texture 43 | * @private 44 | */ 45 | constructor (gl, format, texture) { 46 | /** 47 | * @type {WebGLRenderingContext} 48 | */ 49 | this.gl = gl 50 | /** 51 | * @type {WebGLTexture} 52 | */ 53 | this.texture = texture 54 | /** 55 | * @type {number} 56 | */ 57 | this.format = format 58 | } 59 | 60 | /** 61 | * @param {!Uint8Array|HTMLVideoElement}buffer 62 | * @param {!Rect}geo 63 | * @param {number}stride 64 | */ 65 | subImage2dBuffer (buffer, x, y, width, height) { 66 | const gl = this.gl 67 | gl.bindTexture(gl.TEXTURE_2D, this.texture) 68 | gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, this.format, gl.UNSIGNED_BYTE, buffer) 69 | gl.bindTexture(gl.TEXTURE_2D, null) 70 | } 71 | 72 | /** 73 | * @param {!Uint8Array|HTMLVideoElement}buffer 74 | * @param {number}width 75 | * @param {number}height 76 | */ 77 | image2dBuffer (buffer, width, height) { 78 | const gl = this.gl 79 | gl.bindTexture(gl.TEXTURE_2D, this.texture) 80 | gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, buffer) 81 | gl.bindTexture(gl.TEXTURE_2D, null) 82 | } 83 | 84 | delete () { 85 | this.gl.deleteTexture(this.texture) 86 | this.texture = null 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /native/h264bsd_seq_param_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_SEQ_PARAM_SET_H 30 | #define H264SWDEC_SEQ_PARAM_SET_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_vui.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /* structure to store sequence parameter set information decoded from the 49 | * stream */ 50 | typedef struct 51 | { 52 | u32 profileIdc; 53 | u32 levelIdc; 54 | u32 seqParameterSetId; 55 | u32 maxFrameNum; 56 | u32 picOrderCntType; 57 | u32 maxPicOrderCntLsb; 58 | u32 deltaPicOrderAlwaysZeroFlag; 59 | i32 offsetForNonRefPic; 60 | i32 offsetForTopToBottomField; 61 | u32 numRefFramesInPicOrderCntCycle; 62 | i32 *offsetForRefFrame; 63 | u32 numRefFrames; 64 | u32 gapsInFrameNumValueAllowedFlag; 65 | u32 picWidthInMbs; 66 | u32 picHeightInMbs; 67 | u32 frameCroppingFlag; 68 | u32 frameCropLeftOffset; 69 | u32 frameCropRightOffset; 70 | u32 frameCropTopOffset; 71 | u32 frameCropBottomOffset; 72 | u32 vuiParametersPresentFlag; 73 | vuiParameters_t *vuiParameters; 74 | u32 maxDpbSize; 75 | } seqParamSet_t; 76 | 77 | /*------------------------------------------------------------------------------ 78 | 4. Function prototypes 79 | ------------------------------------------------------------------------------*/ 80 | 81 | u32 h264bsdDecodeSeqParamSet(strmData_t *pStrmData, 82 | seqParamSet_t *pSeqParamSet); 83 | 84 | u32 h264bsdCompareSeqParamSets(seqParamSet_t *pSps1, seqParamSet_t *pSps2); 85 | 86 | #endif /* #ifdef H264SWDEC_SEQ_PARAM_SET_H */ 87 | 88 | -------------------------------------------------------------------------------- /native/h264bsd_intra_prediction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_INTRA_PREDICTION_H 30 | #define H264SWDEC_INTRA_PREDICTION_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_image.h" 38 | #include "h264bsd_macroblock_layer.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | #ifndef H264DEC_OMXDL 52 | u32 h264bsdIntraPrediction(mbStorage_t *pMb, macroblockLayer_t *mbLayer, 53 | image_t *image, u32 mbNum, u32 constrainedIntraPred, u8 *data); 54 | 55 | u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data, 56 | macroblockLayer_t *mbLayer, 57 | u8 *above, u8 *left, u32 constrainedIntraPred); 58 | u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, i32 residual[][16], 59 | u8 *above, u8 *left, u32 constrainedIntraPred); 60 | 61 | u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, i32 residual[][16], 62 | u8 *above, u8 *left, u32 predMode, u32 constrainedIntraPred); 63 | 64 | void h264bsdGetNeighbourPels(image_t *image, u8 *above, u8 *left, u32 mbNum); 65 | 66 | #else 67 | 68 | u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data, 69 | macroblockLayer_t *mbLayer, 70 | u8 *pImage, u32 width, 71 | u32 constrainedIntraPred, u32 block); 72 | 73 | u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, u8 *pImage, 74 | u32 width, u32 constrainedIntraPred); 75 | 76 | u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, image_t *image, 77 | u32 predMode, u32 constrainedIntraPred); 78 | 79 | #endif 80 | 81 | #endif /* #ifdef H264SWDEC_INTRA_PREDICTION_H */ 82 | 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff 7 | .idea/ 8 | .idea/**/workspace.xml 9 | .idea/**/tasks.xml 10 | .idea/**/usage.statistics.xml 11 | .idea/**/dictionaries 12 | .idea/**/shelf 13 | 14 | # Generated files 15 | .idea/**/contentModel.xml 16 | 17 | # Sensitive or high-churn files 18 | .idea/**/dataSources/ 19 | .idea/**/dataSources.ids 20 | .idea/**/dataSources.local.xml 21 | .idea/**/sqlDataSources.xml 22 | .idea/**/dynamic.xml 23 | .idea/**/uiDesigner.xml 24 | .idea/**/dbnavigator.xml 25 | 26 | # Gradle 27 | .idea/**/gradle.xml 28 | .idea/**/libraries 29 | 30 | # Gradle and Maven with auto-import 31 | # When using Gradle or Maven with auto-import, you should exclude module files, 32 | # since they will be recreated, and may cause churn. Uncomment if using 33 | # auto-import. 34 | # .idea/modules.xml 35 | # .idea/*.iml 36 | # .idea/modules 37 | # *.iml 38 | # *.ipr 39 | 40 | # CMake 41 | cmake-build-*/ 42 | 43 | # Mongo Explorer plugin 44 | .idea/**/mongoSettings.xml 45 | 46 | # File-based project format 47 | *.iws 48 | 49 | # IntelliJ 50 | out/ 51 | 52 | # mpeltonen/sbt-idea plugin 53 | .idea_modules/ 54 | 55 | # JIRA plugin 56 | atlassian-ide-plugin.xml 57 | 58 | # Cursive Clojure plugin 59 | .idea/replstate.xml 60 | 61 | # Crashlytics plugin (for Android Studio and IntelliJ) 62 | com_crashlytics_export_strings.xml 63 | crashlytics.properties 64 | crashlytics-build.properties 65 | fabric.properties 66 | 67 | # Editor-based Rest Client 68 | .idea/httpRequests 69 | 70 | # Android studio 3.1+ serialized cache file 71 | .idea/caches/build_file_checksums.ser 72 | 73 | ### Node template 74 | # Logs 75 | logs 76 | *.log 77 | npm-debug.log* 78 | yarn-debug.log* 79 | yarn-error.log* 80 | lerna-debug.log* 81 | 82 | # Diagnostic reports (https://nodejs.org/api/report.html) 83 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 84 | 85 | # Runtime data 86 | pids 87 | *.pid 88 | *.seed 89 | *.pid.lock 90 | 91 | # Directory for instrumented libs generated by jscoverage/JSCover 92 | lib-cov 93 | 94 | # Coverage directory used by tools like istanbul 95 | coverage 96 | *.lcov 97 | 98 | # nyc test coverage 99 | .nyc_output 100 | 101 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 102 | .grunt 103 | 104 | # Bower dependency directory (https://bower.io/) 105 | bower_components 106 | 107 | # node-waf configuration 108 | .lock-wscript 109 | 110 | # Compiled binary addons (https://nodejs.org/api/addons.html) 111 | build/Release 112 | 113 | # Dependency directories 114 | node_modules/ 115 | jspm_packages/ 116 | 117 | # TypeScript v1 declaration files 118 | typings/ 119 | 120 | # TypeScript cache 121 | *.tsbuildinfo 122 | 123 | # Optional npm cache directory 124 | .npm 125 | 126 | # Optional eslint cache 127 | .eslintcache 128 | 129 | # Optional REPL history 130 | .node_repl_history 131 | 132 | # Output of 'npm pack' 133 | *.tgz 134 | 135 | # Yarn Integrity file 136 | .yarn-integrity 137 | 138 | # dotenv environment variables file 139 | .env 140 | .env.test 141 | 142 | # parcel-bundler cache (https://parceljs.org/) 143 | .cache 144 | 145 | # next.js build output 146 | .next 147 | 148 | # nuxt.js build output 149 | .nuxt 150 | 151 | # vuepress build output 152 | .vuepress/dist 153 | 154 | # Serverless directories 155 | .serverless/ 156 | 157 | # FuseBox cache 158 | .fusebox/ 159 | 160 | # DynamoDB Local files 161 | .dynamodb/ 162 | 163 | /es/ 164 | /lib/ 165 | -------------------------------------------------------------------------------- /src/TinyH264Decoder.js: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Sam Leitch. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to 6 | // deal in the Software without restriction, including without limitation the 7 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | // sell copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | // IN THE SOFTWARE. 21 | // 22 | 23 | /** 24 | * This class wraps the details of the h264bsd library. 25 | * Module object is an Emscripten module provided globally by TinyH264.js 26 | * 27 | * In order to use this class, you first queue encoded data using queueData. 28 | * Each call to decode() will decode a single encoded element. 29 | * When decode() returns H264bsdDecoder.PIC_RDY, a picture is ready in the output buffer. 30 | * You can also use the onPictureReady() function to determine when a picture is ready. 31 | * The output buffer can be accessed by calling getNextOutputPicture() 32 | * An output picture may also be decoded using an H264bsdCanvas. 33 | * When you're done decoding, make sure to call release() to clean up internal buffers. 34 | */ 35 | class TinyH264Decoder { 36 | constructor (tinyH264Module, onPictureReady) { 37 | this.tinyH264Module = tinyH264Module 38 | 39 | this.onPictureReady = onPictureReady 40 | 41 | this.pStorage = this.tinyH264Module._h264bsdAlloc() 42 | this.pWidth = this.tinyH264Module._malloc(4) 43 | this.pHeight = this.tinyH264Module._malloc(4) 44 | this.pPicture = this.tinyH264Module._malloc(4) 45 | 46 | this._decBuffer = this.tinyH264Module._malloc(1024 * 1024) 47 | 48 | this.tinyH264Module._h264bsdInit(this.pStorage, 0) 49 | } 50 | 51 | release () { 52 | const pStorage = this.pStorage 53 | 54 | if (pStorage !== 0) { 55 | this.tinyH264Module._h264bsdShutdown(pStorage) 56 | this.tinyH264Module._h264bsdFree(pStorage) 57 | } 58 | 59 | this.tinyH264Module._free(this.pWidth) 60 | this.tinyH264Module._free(this.pHeight) 61 | this.tinyH264Module._free(this.pPicture) 62 | 63 | this.pStorage = 0 64 | 65 | this.pWidth = 0 66 | this.pHeight = 0 67 | } 68 | 69 | decode (nal) { 70 | if (nal instanceof ArrayBuffer) { 71 | nal = new Uint8Array(nal) 72 | } 73 | 74 | this.tinyH264Module.HEAPU8.set(nal, this._decBuffer) 75 | 76 | const retCode = this.tinyH264Module._h264bsdDecode(this.pStorage, this._decBuffer, nal.byteLength, this.pPicture, this.pWidth, this.pHeight) 77 | if (retCode === TinyH264Decoder.PIC_RDY) { 78 | const width = this.tinyH264Module.getValue(this.pWidth, 'i32') 79 | const height = this.tinyH264Module.getValue(this.pHeight, 'i32') 80 | const picPtr = this.tinyH264Module.getValue(this.pPicture, 'i8*') 81 | const pic = new Uint8Array(this.tinyH264Module.HEAPU8.subarray(picPtr, picPtr + (width * height) * 3 / 2)) 82 | this.onPictureReady(pic, width, height) 83 | } 84 | } 85 | } 86 | 87 | TinyH264Decoder.RDY = 0 88 | TinyH264Decoder.PIC_RDY = 1 89 | TinyH264Decoder.HDRS_RDY = 2 90 | TinyH264Decoder.ERROR = 3 91 | TinyH264Decoder.PARAM_SET_ERROR = 4 92 | 93 | TinyH264Decoder.MEMALLOC_ERROR = 5 94 | 95 | export default TinyH264Decoder 96 | -------------------------------------------------------------------------------- /demo/src/YUVSurfaceShader.js: -------------------------------------------------------------------------------- 1 | import ShaderProgram from './ShaderProgram' 2 | import ShaderCompiler from './ShaderCompiler' 3 | import { fragmentYUV, vertexQuad } from './ShaderSources' 4 | 5 | export default class YUVSurfaceShader { 6 | /** 7 | * 8 | * @param {WebGLRenderingContext} gl 9 | * @returns {YUVSurfaceShader} 10 | */ 11 | static create (gl) { 12 | const program = this._initShaders(gl) 13 | const shaderArgs = this._initShaderArgs(gl, program) 14 | const vertexBuffer = this._initBuffers(gl) 15 | 16 | return new YUVSurfaceShader(gl, vertexBuffer, shaderArgs, program) 17 | } 18 | 19 | static _initShaders (gl) { 20 | const program = new ShaderProgram(gl) 21 | program.attach(ShaderCompiler.compile(gl, vertexQuad)) 22 | program.attach(ShaderCompiler.compile(gl, fragmentYUV)) 23 | program.link() 24 | program.use() 25 | 26 | return program 27 | } 28 | 29 | static _initShaderArgs (gl, program) { 30 | // find shader arguments 31 | const shaderArgs = {} 32 | shaderArgs.yTexture = program.getUniformLocation('yTexture') 33 | shaderArgs.uTexture = program.getUniformLocation('uTexture') 34 | shaderArgs.vTexture = program.getUniformLocation('vTexture') 35 | 36 | shaderArgs.u_projection = program.getUniformLocation('u_projection') 37 | 38 | shaderArgs.a_position = program.getAttributeLocation('a_position') 39 | gl.enableVertexAttribArray(shaderArgs.a_position) 40 | shaderArgs.a_texCoord = program.getAttributeLocation('a_texCoord') 41 | gl.enableVertexAttribArray(shaderArgs.a_texCoord) 42 | 43 | return shaderArgs 44 | } 45 | 46 | static _initBuffers (gl) { 47 | // Create vertex buffer object. 48 | return gl.createBuffer() 49 | } 50 | 51 | constructor (gl, vertexBuffer, shaderArgs, program) { 52 | this.gl = gl 53 | this.vertexBuffer = vertexBuffer 54 | this.shaderArgs = shaderArgs 55 | this.program = program 56 | } 57 | 58 | /** 59 | * 60 | * @param {Texture} textureY 61 | * @param {Texture} textureU 62 | * @param {Texture} textureV 63 | */ 64 | setTexture (textureY, textureU, textureV) { 65 | const gl = this.gl 66 | 67 | gl.uniform1i(this.shaderArgs.yTexture, 0) 68 | gl.uniform1i(this.shaderArgs.uTexture, 1) 69 | gl.uniform1i(this.shaderArgs.vTexture, 2) 70 | 71 | gl.activeTexture(gl.TEXTURE0) 72 | gl.bindTexture(gl.TEXTURE_2D, textureY.texture) 73 | 74 | gl.activeTexture(gl.TEXTURE1) 75 | gl.bindTexture(gl.TEXTURE_2D, textureU.texture) 76 | 77 | gl.activeTexture(gl.TEXTURE2) 78 | gl.bindTexture(gl.TEXTURE_2D, textureV.texture) 79 | } 80 | 81 | use () { 82 | this.program.use() 83 | } 84 | 85 | release () { 86 | const gl = this.gl 87 | gl.useProgram(null) 88 | } 89 | 90 | /** 91 | * @param {{w:number, h:number}}encodedFrameSize 92 | * @param {{maxXTexCoord:number, maxYTexCoord:number}} h264RenderState 93 | */ 94 | updateShaderData (encodedFrameSize, h264RenderState) { 95 | const { w, h } = encodedFrameSize 96 | this.gl.viewport(0, 0, w, h) 97 | this.program.setUniformM4(this.shaderArgs.u_projection, [ 98 | 2.0 / w, 0, 0, 0, 99 | 0, 2.0 / -h, 0, 0, 100 | 0, 0, 1, 0, 101 | -1, 1, 0, 1 102 | ]) 103 | this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer) 104 | this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([ 105 | // First triangle 106 | // top left: 107 | 0, 0, 0, 0, 108 | // top right: 109 | w, 0, h264RenderState.maxXTexCoord, 0, 110 | // bottom right: 111 | w, h, h264RenderState.maxXTexCoord, h264RenderState.maxYTexCoord, 112 | 113 | // Second triangle 114 | // bottom right: 115 | w, h, h264RenderState.maxXTexCoord, h264RenderState.maxYTexCoord, 116 | // bottom left: 117 | 0, h, 0, h264RenderState.maxYTexCoord, 118 | // top left: 119 | 0, 0, 0, 0 120 | ]), this.gl.DYNAMIC_DRAW) 121 | this.gl.vertexAttribPointer(this.shaderArgs.a_position, 2, this.gl.FLOAT, false, 16, 0) 122 | this.gl.vertexAttribPointer(this.shaderArgs.a_texCoord, 2, this.gl.FLOAT, false, 16, 8) 123 | } 124 | 125 | draw () { 126 | const gl = this.gl 127 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT) 128 | gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 6) 129 | gl.bindTexture(gl.TEXTURE_2D, null) 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /native/h264bsd_vui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_VUI_H 30 | #define H264SWDEC_VUI_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | 39 | /*------------------------------------------------------------------------------ 40 | 2. Module defines 41 | ------------------------------------------------------------------------------*/ 42 | 43 | #define MAX_CPB_CNT 32 44 | 45 | /*------------------------------------------------------------------------------ 46 | 3. Data types 47 | ------------------------------------------------------------------------------*/ 48 | 49 | /* enumerated sample aspect ratios, ASPECT_RATIO_M_N means M:N */ 50 | enum 51 | { 52 | ASPECT_RATIO_UNSPECIFIED = 0, 53 | ASPECT_RATIO_1_1, 54 | ASPECT_RATIO_12_11, 55 | ASPECT_RATIO_10_11, 56 | ASPECT_RATIO_16_11, 57 | ASPECT_RATIO_40_33, 58 | ASPECT_RATIO_24_11, 59 | ASPECT_RATIO_20_11, 60 | ASPECT_RATIO_32_11, 61 | ASPECT_RATIO_80_33, 62 | ASPECT_RATIO_18_11, 63 | ASPECT_RATIO_15_11, 64 | ASPECT_RATIO_64_33, 65 | ASPECT_RATIO_160_99, 66 | ASPECT_RATIO_EXTENDED_SAR = 255 67 | }; 68 | 69 | /* structure to store Hypothetical Reference Decoder (HRD) parameters */ 70 | typedef struct 71 | { 72 | u32 cpbCnt; 73 | u32 bitRateScale; 74 | u32 cpbSizeScale; 75 | u32 bitRateValue[MAX_CPB_CNT]; 76 | u32 cpbSizeValue[MAX_CPB_CNT]; 77 | u32 cbrFlag[MAX_CPB_CNT]; 78 | u32 initialCpbRemovalDelayLength; 79 | u32 cpbRemovalDelayLength; 80 | u32 dpbOutputDelayLength; 81 | u32 timeOffsetLength; 82 | } hrdParameters_t; 83 | 84 | /* storage for VUI parameters */ 85 | typedef struct 86 | { 87 | u32 aspectRatioPresentFlag; 88 | u32 aspectRatioIdc; 89 | u32 sarWidth; 90 | u32 sarHeight; 91 | u32 overscanInfoPresentFlag; 92 | u32 overscanAppropriateFlag; 93 | u32 videoSignalTypePresentFlag; 94 | u32 videoFormat; 95 | u32 videoFullRangeFlag; 96 | u32 colourDescriptionPresentFlag; 97 | u32 colourPrimaries; 98 | u32 transferCharacteristics; 99 | u32 matrixCoefficients; 100 | u32 chromaLocInfoPresentFlag; 101 | u32 chromaSampleLocTypeTopField; 102 | u32 chromaSampleLocTypeBottomField; 103 | u32 timingInfoPresentFlag; 104 | u32 numUnitsInTick; 105 | u32 timeScale; 106 | u32 fixedFrameRateFlag; 107 | u32 nalHrdParametersPresentFlag; 108 | hrdParameters_t nalHrdParameters; 109 | u32 vclHrdParametersPresentFlag; 110 | hrdParameters_t vclHrdParameters; 111 | u32 lowDelayHrdFlag; 112 | u32 picStructPresentFlag; 113 | u32 bitstreamRestrictionFlag; 114 | u32 motionVectorsOverPicBoundariesFlag; 115 | u32 maxBytesPerPicDenom; 116 | u32 maxBitsPerMbDenom; 117 | u32 log2MaxMvLengthHorizontal; 118 | u32 log2MaxMvLengthVertical; 119 | u32 numReorderFrames; 120 | u32 maxDecFrameBuffering; 121 | } vuiParameters_t; 122 | 123 | /*------------------------------------------------------------------------------ 124 | 4. Function prototypes 125 | ------------------------------------------------------------------------------*/ 126 | 127 | u32 h264bsdDecodeVuiParameters(strmData_t *pStrmData, 128 | vuiParameters_t *pVuiParameters); 129 | 130 | #endif /* #ifdef H264SWDEC_VUI_H */ 131 | 132 | -------------------------------------------------------------------------------- /native/h264bsd_dpb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_DPB_H 30 | #define H264SWDEC_DPB_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_slice_header.h" 38 | #include "h264bsd_image.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /* enumeration to represent status of buffered image */ 49 | typedef enum { 50 | UNUSED = 0, 51 | NON_EXISTING, 52 | SHORT_TERM, 53 | LONG_TERM 54 | } dpbPictureStatus_e; 55 | 56 | /* structure to represent a buffered picture */ 57 | typedef struct { 58 | u8 *data; /* 16-byte aligned pointer of pAllocatedData */ 59 | u8 *pAllocatedData; /* allocated picture pointer; (size + 15) bytes */ 60 | i32 picNum; 61 | u32 frameNum; 62 | i32 picOrderCnt; 63 | dpbPictureStatus_e status; 64 | u32 toBeDisplayed; 65 | u32 picId; 66 | u32 numErrMbs; 67 | u32 isIdr; 68 | } dpbPicture_t; 69 | 70 | /* structure to represent display image output from the buffer */ 71 | typedef struct { 72 | u8 *data; 73 | u32 picId; 74 | u32 numErrMbs; 75 | u32 isIdr; 76 | } dpbOutPicture_t; 77 | 78 | /* structure to represent DPB */ 79 | typedef struct { 80 | dpbPicture_t *buffer; 81 | dpbPicture_t **list; 82 | dpbPicture_t *currentOut; 83 | dpbOutPicture_t *outBuf; 84 | u32 numOut; 85 | u32 outIndex; 86 | u32 maxRefFrames; 87 | u32 dpbSize; 88 | u32 maxFrameNum; 89 | u32 maxLongTermFrameIdx; 90 | u32 numRefFrames; 91 | u32 fullness; 92 | u32 prevRefFrameNum; 93 | u32 lastContainsMmco5; 94 | u32 noReordering; 95 | u32 flushed; 96 | } dpbStorage_t; 97 | 98 | /*------------------------------------------------------------------------------ 99 | 4. Function prototypes 100 | ------------------------------------------------------------------------------*/ 101 | 102 | u32 h264bsdInitDpb( 103 | dpbStorage_t *dpb, 104 | u32 picSizeInMbs, 105 | u32 dpbSize, 106 | u32 numRefFrames, 107 | u32 maxFrameNum, 108 | u32 noReordering); 109 | 110 | u32 h264bsdResetDpb( 111 | dpbStorage_t *dpb, 112 | u32 picSizeInMbs, 113 | u32 dpbSize, 114 | u32 numRefFrames, 115 | u32 maxFrameNum, 116 | u32 noReordering); 117 | 118 | void h264bsdInitRefPicList(dpbStorage_t *dpb); 119 | 120 | u8* h264bsdAllocateDpbImage(dpbStorage_t *dpb); 121 | 122 | u8* h264bsdGetRefPicData(dpbStorage_t *dpb, u32 index); 123 | 124 | u32 h264bsdReorderRefPicList( 125 | dpbStorage_t *dpb, 126 | refPicListReordering_t *order, 127 | u32 currFrameNum, 128 | u32 numRefIdxActive); 129 | 130 | u32 h264bsdMarkDecRefPic( 131 | dpbStorage_t *dpb, 132 | decRefPicMarking_t *mark, 133 | image_t *image, 134 | u32 frameNum, 135 | i32 picOrderCnt, 136 | u32 isIdr, 137 | u32 picId, 138 | u32 numErrMbs); 139 | 140 | u32 h264bsdCheckGapsInFrameNum(dpbStorage_t *dpb, u32 frameNum, u32 isRefPic, 141 | u32 gapsAllowed); 142 | 143 | dpbOutPicture_t* h264bsdDpbOutputPicture(dpbStorage_t *dpb); 144 | 145 | void h264bsdFlushDpb(dpbStorage_t *dpb); 146 | 147 | void h264bsdFreeDpb(dpbStorage_t *dpb); 148 | 149 | #endif /* #ifdef H264SWDEC_DPB_H */ 150 | 151 | -------------------------------------------------------------------------------- /demo/src/index.js: -------------------------------------------------------------------------------- 1 | import Worker from './H264NALDecoder.worker' 2 | import YUVSurfaceShader from './YUVSurfaceShader' 3 | import Texture from './Texture' 4 | 5 | let tinyH264Worker = null 6 | let videoStreamId = 1 7 | 8 | let canvas = null 9 | /** 10 | * @type {YUVSurfaceShader} 11 | */ 12 | let yuvSurfaceShader = null 13 | let yTexture = null 14 | let uTexture = null 15 | let vTexture = null 16 | 17 | /** 18 | * @type {Array} 19 | */ 20 | const h264samples = [] 21 | 22 | let nroFrames = 0 23 | let start = 0 24 | 25 | /** 26 | * @param {Uint8Array} h264Nal 27 | */ 28 | function decode (h264Nal) { 29 | tinyH264Worker.postMessage({ 30 | type: 'decode', 31 | data: h264Nal.buffer, 32 | offset: h264Nal.byteOffset, 33 | length: h264Nal.byteLength, 34 | renderStateId: videoStreamId 35 | }, [h264Nal.buffer]) 36 | } 37 | 38 | /** 39 | * @param {{width:number, height:number, data: ArrayBuffer}}message 40 | */ 41 | function onPictureReady (message) { 42 | const { width, height, data } = message 43 | onPicture(new Uint8Array(data), width, height) 44 | } 45 | 46 | /** 47 | * @param {Uint8Array}buffer 48 | * @param {number}width 49 | * @param {number}height 50 | */ 51 | function onPicture (buffer, width, height) { 52 | decodeNext() 53 | 54 | canvas.width = width 55 | canvas.height = height 56 | 57 | // the width & height returned are actually padded, so we have to use the frame size to get the real image dimension 58 | // when uploading to texture 59 | const stride = width // stride 60 | // height is padded with filler rows 61 | 62 | // if we knew the size of the video before encoding, we could cut out the black filler pixels. We don't, so just set 63 | // it to the size after encoding 64 | const sourceWidth = width 65 | const sourceHeight = height 66 | const maxXTexCoord = sourceWidth / stride 67 | const maxYTexCoord = sourceHeight / height 68 | 69 | const lumaSize = stride * height 70 | const chromaSize = lumaSize >> 2 71 | 72 | const yBuffer = buffer.subarray(0, lumaSize) 73 | const uBuffer = buffer.subarray(lumaSize, lumaSize + chromaSize) 74 | const vBuffer = buffer.subarray(lumaSize + chromaSize, lumaSize + (2 * chromaSize)) 75 | 76 | const chromaHeight = height >> 1 77 | const chromaStride = stride >> 1 78 | 79 | // we upload the entire image, including stride padding & filler rows. The actual visible image will be mapped 80 | // from texture coordinates as to crop out stride padding & filler rows using maxXTexCoord and maxYTexCoord. 81 | 82 | yTexture.image2dBuffer(yBuffer, stride, height) 83 | uTexture.image2dBuffer(uBuffer, chromaStride, chromaHeight) 84 | vTexture.image2dBuffer(vBuffer, chromaStride, chromaHeight) 85 | 86 | yuvSurfaceShader.setTexture(yTexture, uTexture, vTexture) 87 | yuvSurfaceShader.updateShaderData({ w: width, h: height }, { maxXTexCoord, maxYTexCoord }) 88 | yuvSurfaceShader.draw() 89 | } 90 | 91 | function release () { 92 | if (tinyH264Worker) { 93 | tinyH264Worker.postMessage({ type: 'release', renderStateId: videoStreamId }) 94 | tinyH264Worker = null 95 | } 96 | } 97 | 98 | function decodeNext () { 99 | const nextFrame = h264samples.shift() 100 | if (nextFrame != null) { 101 | decode(nextFrame) 102 | } else { 103 | const fps = (1000 / (Date.now() - start)) * nroFrames 104 | window.alert(`Decoded ${nroFrames} (3440x1216) frames in ${Date.now() - start}ms @ ${fps >> 0}FPS`) 105 | } 106 | } 107 | 108 | function initWebGLCanvas () { 109 | canvas = document.createElement('canvas') 110 | const gl = canvas.getContext('webgl') 111 | yuvSurfaceShader = YUVSurfaceShader.create(gl) 112 | yTexture = Texture.create(gl, gl.LUMINANCE) 113 | uTexture = Texture.create(gl, gl.LUMINANCE) 114 | vTexture = Texture.create(gl, gl.LUMINANCE) 115 | 116 | document.body.append(canvas) 117 | } 118 | 119 | function main () { 120 | initWebGLCanvas() 121 | new Promise((resolve) => { 122 | /** 123 | * @type {Worker} 124 | * @private 125 | */ 126 | tinyH264Worker = new Worker() 127 | tinyH264Worker.addEventListener('message', (e) => { 128 | const message = /** @type {{type:string, width:number, height:number, data:ArrayBuffer, renderStateId:number}} */e.data 129 | switch (message.type) { 130 | case 'pictureReady': 131 | onPictureReady(message) 132 | break 133 | case 'decoderReady': 134 | resolve(tinyH264Worker) 135 | break 136 | } 137 | }) 138 | }).then(() => { 139 | const fetches = [] 140 | for (let i = 0; i < 60; i++) { 141 | fetches.push(fetch(`h264samples/${i}`).then(response => { 142 | return response.arrayBuffer().then(function (buffer) { 143 | h264samples[i] = new Uint8Array(buffer) 144 | }) 145 | })) 146 | } 147 | 148 | return Promise.all(fetches) 149 | }).then(() => { 150 | nroFrames = h264samples.length 151 | start = Date.now() 152 | decodeNext() 153 | }) 154 | } 155 | 156 | main() 157 | -------------------------------------------------------------------------------- /native/h264bsd_reconstruct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_RECONSTRUCT_H 30 | #define H264SWDEC_RECONSTRUCT_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_macroblock_layer.h" 38 | #include "h264bsd_image.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. Module defines 42 | ------------------------------------------------------------------------------*/ 43 | 44 | /*------------------------------------------------------------------------------ 45 | 3. Data types 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | #ifndef H264DEC_OMXDL 52 | void h264bsdPredictSamples( 53 | u8 *data, 54 | mv_t *mv, 55 | image_t *refPic, 56 | u32 xA, 57 | u32 yA, 58 | u32 partX, 59 | u32 partY, 60 | u32 partWidth, 61 | u32 partHeight); 62 | #else 63 | void h264bsdPredictSamples( 64 | u8 *data, 65 | mv_t *mv, 66 | image_t *refPic, 67 | u32 colAndRow,/* packaged data | column | row |*/ 68 | u32 part, /* packaged data |partX|partY|partWidth|partHeight|*/ 69 | u8 *pFill); 70 | #endif 71 | 72 | void h264bsdFillBlock( 73 | u8 * ref, 74 | u8 * fill, 75 | i32 x0, 76 | i32 y0, 77 | u32 width, 78 | u32 height, 79 | u32 blockWidth, 80 | u32 blockHeight, 81 | u32 fillScanLength); 82 | 83 | void h264bsdInterpolateChromaHor( 84 | u8 *pRef, 85 | u8 *predPartChroma, 86 | i32 x0, 87 | i32 y0, 88 | u32 width, 89 | u32 height, 90 | u32 xFrac, 91 | u32 chromaPartWidth, 92 | u32 chromaPartHeight); 93 | 94 | void h264bsdInterpolateChromaVer( 95 | u8 *pRef, 96 | u8 *predPartChroma, 97 | i32 x0, 98 | i32 y0, 99 | u32 width, 100 | u32 height, 101 | u32 yFrac, 102 | u32 chromaPartWidth, 103 | u32 chromaPartHeight); 104 | 105 | void h264bsdInterpolateChromaHorVer( 106 | u8 *ref, 107 | u8 *predPartChroma, 108 | i32 x0, 109 | i32 y0, 110 | u32 width, 111 | u32 height, 112 | u32 xFrac, 113 | u32 yFrac, 114 | u32 chromaPartWidth, 115 | u32 chromaPartHeight); 116 | 117 | void h264bsdInterpolateVerHalf( 118 | u8 *ref, 119 | u8 *mb, 120 | i32 x0, 121 | i32 y0, 122 | u32 width, 123 | u32 height, 124 | u32 partWidth, 125 | u32 partHeight); 126 | 127 | void h264bsdInterpolateVerQuarter( 128 | u8 *ref, 129 | u8 *mb, 130 | i32 x0, 131 | i32 y0, 132 | u32 width, 133 | u32 height, 134 | u32 partWidth, 135 | u32 partHeight, 136 | u32 verOffset); 137 | 138 | void h264bsdInterpolateHorHalf( 139 | u8 *ref, 140 | u8 *mb, 141 | i32 x0, 142 | i32 y0, 143 | u32 width, 144 | u32 height, 145 | u32 partWidth, 146 | u32 partHeight); 147 | 148 | void h264bsdInterpolateHorQuarter( 149 | u8 *ref, 150 | u8 *mb, 151 | i32 x0, 152 | i32 y0, 153 | u32 width, 154 | u32 height, 155 | u32 partWidth, 156 | u32 partHeight, 157 | u32 horOffset); 158 | 159 | void h264bsdInterpolateHorVerQuarter( 160 | u8 *ref, 161 | u8 *mb, 162 | i32 x0, 163 | i32 y0, 164 | u32 width, 165 | u32 height, 166 | u32 partWidth, 167 | u32 partHeight, 168 | u32 horVerOffset); 169 | 170 | void h264bsdInterpolateMidHalf( 171 | u8 *ref, 172 | u8 *mb, 173 | i32 x0, 174 | i32 y0, 175 | u32 width, 176 | u32 height, 177 | u32 partWidth, 178 | u32 partHeight); 179 | 180 | void h264bsdInterpolateMidVerQuarter( 181 | u8 *ref, 182 | u8 *mb, 183 | i32 x0, 184 | i32 y0, 185 | u32 width, 186 | u32 height, 187 | u32 partWidth, 188 | u32 partHeight, 189 | u32 verOffset); 190 | 191 | void h264bsdInterpolateMidHorQuarter( 192 | u8 *ref, 193 | u8 *mb, 194 | i32 x0, 195 | i32 y0, 196 | u32 width, 197 | u32 height, 198 | u32 partWidth, 199 | u32 partHeight, 200 | u32 horOffset); 201 | 202 | 203 | void h264bsdFillRow7( 204 | u8 *ref, 205 | u8 *fill, 206 | i32 left, 207 | i32 center, 208 | i32 right); 209 | 210 | #endif /* #ifdef H264SWDEC_RECONSTRUCT_H */ 211 | 212 | -------------------------------------------------------------------------------- /native/h264bsd_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_UTIL_H 30 | #define H264SWDEC_UTIL_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include 37 | #include "basetype.h" 38 | #include "h264bsd_cfg.h" 39 | #include "h264bsd_stream.h" 40 | #include "h264bsd_image.h" 41 | 42 | #ifdef _ASSERT_USED 43 | #include 44 | #endif 45 | 46 | #if defined(_RANGE_CHECK) || defined(_DEBUG_PRINT) || defined(_ERROR_PRINT) 47 | #include 48 | #endif 49 | 50 | /*------------------------------------------------------------------------------ 51 | 2. Module defines 52 | ------------------------------------------------------------------------------*/ 53 | 54 | #define HANTRO_OK 0 55 | #define HANTRO_NOK 1 56 | 57 | #define HANTRO_TRUE (1) 58 | #define HANTRO_FALSE (0) 59 | 60 | #ifndef NULL 61 | #define NULL 0 62 | #endif 63 | 64 | #define MEMORY_ALLOCATION_ERROR 0xFFFF 65 | #define PARAM_SET_ERROR 0xFFF0 66 | 67 | /* value to be returned by GetBits if stream buffer is empty */ 68 | #define END_OF_STREAM 0xFFFFFFFFU 69 | 70 | #define EMPTY_RESIDUAL_INDICATOR 0xFFFFFF 71 | 72 | /* macro to mark a residual block empty, i.e. contain zero coefficients */ 73 | #define MARK_RESIDUAL_EMPTY(residual) ((residual)[0] = EMPTY_RESIDUAL_INDICATOR) 74 | /* macro to check if residual block is empty */ 75 | #define IS_RESIDUAL_EMPTY(residual) ((residual)[0] == EMPTY_RESIDUAL_INDICATOR) 76 | 77 | /* macro for assertion, used only if compiler flag _ASSERT_USED is defined */ 78 | #ifdef _ASSERT_USED 79 | #define ASSERT(expr) assert(expr) 80 | #else 81 | #define ASSERT(expr) 82 | #endif 83 | 84 | /* macro for range checking an value, used only if compiler flag _RANGE_CHECK 85 | * is defined */ 86 | #ifdef _RANGE_CHECK 87 | #define RANGE_CHECK(value, minBound, maxBound) \ 88 | { \ 89 | if ((value) < (minBound) || (value) > (maxBound)) \ 90 | fprintf(stderr, "Warning: Value exceeds given limit(s)!\n"); \ 91 | } 92 | #else 93 | #define RANGE_CHECK(value, minBound, maxBound) 94 | #endif 95 | 96 | /* macro for range checking an array, used only if compiler flag _RANGE_CHECK 97 | * is defined */ 98 | #ifdef _RANGE_CHECK 99 | #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) \ 100 | { \ 101 | i32 i; \ 102 | for (i = 0; i < (length); i++) \ 103 | if ((array)[i] < (minBound) || (array)[i] > (maxBound)) \ 104 | fprintf(stderr,"Warning: Value [%d] exceeds given limit(s)!\n",i); \ 105 | } 106 | #else 107 | #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) 108 | #endif 109 | 110 | /* macro for debug printing, used only if compiler flag _DEBUG_PRINT is 111 | * defined */ 112 | #ifdef _DEBUG_PRINT 113 | #define DEBUG(args) printf args 114 | #else 115 | #define DEBUG(args) 116 | #endif 117 | 118 | /* macro for error printing, used only if compiler flag _ERROR_PRINT is 119 | * defined */ 120 | #ifdef _ERROR_PRINT 121 | #define EPRINT(msg) fprintf(stderr,"ERROR: %s\n",msg) 122 | #else 123 | #define EPRINT(msg) 124 | #endif 125 | 126 | /* macro to get smaller of two values */ 127 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 128 | 129 | /* macro to get greater of two values */ 130 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 131 | 132 | /* macro to get absolute value */ 133 | #define ABS(a) (((a) < 0) ? -(a) : (a)) 134 | 135 | /* macro to clip a value z, so that x <= z =< y */ 136 | #define CLIP3(x,y,z) (((z) < (x)) ? (x) : (((z) > (y)) ? (y) : (z))) 137 | 138 | /* macro to clip a value z, so that 0 <= z =< 255 */ 139 | #define CLIP1(z) (((z) < 0) ? 0 : (((z) > 255) ? 255 : (z))) 140 | 141 | /* macro to allocate memory */ 142 | #define ALLOCATE(ptr, count, type) \ 143 | { \ 144 | (ptr) = malloc((count) * sizeof(type)); \ 145 | } 146 | 147 | /* macro to free allocated memory */ 148 | #define FREE(ptr) \ 149 | { \ 150 | free((ptr)); (ptr) = NULL; \ 151 | } 152 | 153 | #define ALIGN(ptr, bytePos) \ 154 | (ptr + ( ((bytePos - (uintptr_t)ptr) & (bytePos - 1)) / sizeof(*ptr) )) 155 | 156 | extern const u32 h264bsdQpC[52]; 157 | 158 | /*------------------------------------------------------------------------------ 159 | 3. Data types 160 | ------------------------------------------------------------------------------*/ 161 | 162 | /*------------------------------------------------------------------------------ 163 | 4. Function prototypes 164 | ------------------------------------------------------------------------------*/ 165 | #ifndef H264DEC_NEON 166 | u32 h264bsdCountLeadingZeros(u32 value, u32 length); 167 | #else 168 | u32 h264bsdCountLeadingZeros(u32 value); 169 | #endif 170 | u32 h264bsdRbspTrailingBits(strmData_t *strmData); 171 | 172 | u32 h264bsdMoreRbspData(strmData_t *strmData); 173 | 174 | u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr); 175 | 176 | void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum); 177 | 178 | i32 abs(i32 a); 179 | i32 clip(i32 x, i32 y, i32 z); 180 | 181 | #endif /* #ifdef H264SWDEC_UTIL_H */ 182 | 183 | -------------------------------------------------------------------------------- /native/h264bsd_macroblock_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_MACROBLOCK_LAYER_H 30 | #define H264SWDEC_MACROBLOCK_LAYER_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_image.h" 39 | #include "h264bsd_dpb.h" 40 | 41 | /*------------------------------------------------------------------------------ 42 | 2. Module defines 43 | ------------------------------------------------------------------------------*/ 44 | 45 | /* Macro to determine if a mb is an intra mb */ 46 | #define IS_INTRA_MB(a) ((a).mbType > 5) 47 | 48 | /* Macro to determine if a mb is an I_PCM mb */ 49 | #define IS_I_PCM_MB(a) ((a).mbType == 31) 50 | 51 | typedef enum { 52 | P_Skip = 0, 53 | P_L0_16x16 = 1, 54 | P_L0_L0_16x8 = 2, 55 | P_L0_L0_8x16 = 3, 56 | P_8x8 = 4, 57 | P_8x8ref0 = 5, 58 | I_4x4 = 6, 59 | I_16x16_0_0_0 = 7, 60 | I_16x16_1_0_0 = 8, 61 | I_16x16_2_0_0 = 9, 62 | I_16x16_3_0_0 = 10, 63 | I_16x16_0_1_0 = 11, 64 | I_16x16_1_1_0 = 12, 65 | I_16x16_2_1_0 = 13, 66 | I_16x16_3_1_0 = 14, 67 | I_16x16_0_2_0 = 15, 68 | I_16x16_1_2_0 = 16, 69 | I_16x16_2_2_0 = 17, 70 | I_16x16_3_2_0 = 18, 71 | I_16x16_0_0_1 = 19, 72 | I_16x16_1_0_1 = 20, 73 | I_16x16_2_0_1 = 21, 74 | I_16x16_3_0_1 = 22, 75 | I_16x16_0_1_1 = 23, 76 | I_16x16_1_1_1 = 24, 77 | I_16x16_2_1_1 = 25, 78 | I_16x16_3_1_1 = 26, 79 | I_16x16_0_2_1 = 27, 80 | I_16x16_1_2_1 = 28, 81 | I_16x16_2_2_1 = 29, 82 | I_16x16_3_2_1 = 30, 83 | I_PCM = 31 84 | } mbType_e; 85 | 86 | typedef enum { 87 | P_L0_8x8 = 0, 88 | P_L0_8x4 = 1, 89 | P_L0_4x8 = 2, 90 | P_L0_4x4 = 3 91 | } subMbType_e; 92 | 93 | typedef enum { 94 | MB_P_16x16 = 0, 95 | MB_P_16x8, 96 | MB_P_8x16, 97 | MB_P_8x8 98 | } mbPartMode_e; 99 | 100 | typedef enum { 101 | MB_SP_8x8 = 0, 102 | MB_SP_8x4, 103 | MB_SP_4x8, 104 | MB_SP_4x4 105 | } subMbPartMode_e; 106 | 107 | typedef enum { 108 | PRED_MODE_INTRA4x4 = 0, 109 | PRED_MODE_INTRA16x16 , 110 | PRED_MODE_INTER 111 | } mbPartPredMode_e; 112 | 113 | /*------------------------------------------------------------------------------ 114 | 3. Data types 115 | ------------------------------------------------------------------------------*/ 116 | 117 | typedef struct 118 | { 119 | /* MvPrediction16x16 assumes that MVs are 16bits */ 120 | i16 hor; 121 | i16 ver; 122 | } mv_t; 123 | 124 | typedef struct 125 | { 126 | u32 prevIntra4x4PredModeFlag[16]; 127 | u32 remIntra4x4PredMode[16]; 128 | u32 intraChromaPredMode; 129 | u32 refIdxL0[4]; 130 | mv_t mvdL0[4]; 131 | } mbPred_t; 132 | 133 | typedef struct 134 | { 135 | subMbType_e subMbType[4]; 136 | u32 refIdxL0[4]; 137 | mv_t mvdL0[4][4]; 138 | } subMbPred_t; 139 | 140 | typedef struct 141 | { 142 | #ifdef H264DEC_OMXDL 143 | u8 posCoefBuf[27*16*3]; 144 | u8 totalCoeff[27]; 145 | #else 146 | i16 totalCoeff[27]; 147 | #endif 148 | i32 level[26][16]; 149 | u32 coeffMap[24]; 150 | } residual_t; 151 | 152 | typedef struct 153 | { 154 | mbType_e mbType; 155 | u32 codedBlockPattern; 156 | i32 mbQpDelta; 157 | mbPred_t mbPred; 158 | subMbPred_t subMbPred; 159 | residual_t residual; 160 | } macroblockLayer_t; 161 | 162 | typedef struct mbStorage 163 | { 164 | mbType_e mbType; 165 | u32 sliceId; 166 | u32 disableDeblockingFilterIdc; 167 | i32 filterOffsetA; 168 | i32 filterOffsetB; 169 | u32 qpY; 170 | i32 chromaQpIndexOffset; 171 | #ifdef H264DEC_OMXDL 172 | u8 totalCoeff[27]; 173 | #else 174 | i16 totalCoeff[27]; 175 | #endif 176 | u8 intra4x4PredMode[16]; 177 | u32 refPic[4]; 178 | u8* refAddr[4]; 179 | mv_t mv[16]; 180 | u32 decoded; 181 | struct mbStorage *mbA; 182 | struct mbStorage *mbB; 183 | struct mbStorage *mbC; 184 | struct mbStorage *mbD; 185 | } mbStorage_t; 186 | 187 | /*------------------------------------------------------------------------------ 188 | 4. Function prototypes 189 | ------------------------------------------------------------------------------*/ 190 | 191 | u32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData, 192 | macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType, 193 | u32 numRefIdxActive); 194 | 195 | u32 h264bsdNumMbPart(mbType_e mbType); 196 | u32 h264bsdNumSubMbPart(subMbType_e subMbType); 197 | 198 | subMbPartMode_e h264bsdSubMbPartMode(subMbType_e subMbType); 199 | 200 | u32 h264bsdDecodeMacroblock(mbStorage_t *pMb, macroblockLayer_t *pMbLayer, 201 | image_t *currImage, dpbStorage_t *dpb, i32 *qpY, u32 mbNum, 202 | u32 constrainedIntraPredFlag, u8* data); 203 | 204 | u32 h264bsdPredModeIntra16x16(mbType_e mbType); 205 | 206 | mbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType); 207 | #ifdef H264DEC_NEON 208 | u32 h264bsdClearMbLayer(macroblockLayer_t *pMbLayer, u32 size); 209 | #endif 210 | 211 | #endif /* #ifdef H264SWDEC_MACROBLOCK_LAYER_H */ 212 | 213 | 214 | -------------------------------------------------------------------------------- /native/h264bsd_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_STORAGE_H 30 | #define H264SWDEC_STORAGE_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_cfg.h" 38 | #include "h264bsd_seq_param_set.h" 39 | #include "h264bsd_pic_param_set.h" 40 | #include "h264bsd_macroblock_layer.h" 41 | #include "h264bsd_nal_unit.h" 42 | #include "h264bsd_slice_header.h" 43 | #include "h264bsd_seq_param_set.h" 44 | #include "h264bsd_dpb.h" 45 | #include "h264bsd_pic_order_cnt.h" 46 | 47 | /*------------------------------------------------------------------------------ 48 | 2. Module defines 49 | ------------------------------------------------------------------------------*/ 50 | 51 | /*------------------------------------------------------------------------------ 52 | 3. Data types 53 | ------------------------------------------------------------------------------*/ 54 | 55 | typedef struct 56 | { 57 | u32 sliceId; 58 | u32 numDecodedMbs; 59 | u32 lastMbAddr; 60 | } sliceStorage_t; 61 | 62 | /* structure to store parameters needed for access unit boundary checking */ 63 | typedef struct 64 | { 65 | nalUnit_t nuPrev[1]; 66 | u32 prevFrameNum; 67 | u32 prevIdrPicId; 68 | u32 prevPicOrderCntLsb; 69 | i32 prevDeltaPicOrderCntBottom; 70 | i32 prevDeltaPicOrderCnt[2]; 71 | u32 firstCallFlag; 72 | } aubCheck_t; 73 | 74 | /* storage data structure, holds all data of a decoder instance */ 75 | typedef struct storage 76 | { 77 | /* active paramet set ids and pointers */ 78 | u32 oldSpsId; 79 | u32 activePpsId; 80 | u32 activeSpsId; 81 | picParamSet_t *activePps; 82 | seqParamSet_t *activeSps; 83 | seqParamSet_t *sps[MAX_NUM_SEQ_PARAM_SETS]; 84 | picParamSet_t *pps[MAX_NUM_PIC_PARAM_SETS]; 85 | 86 | /* current slice group map, recomputed for each slice */ 87 | u32 *sliceGroupMap; 88 | 89 | u32 picSizeInMbs; 90 | 91 | /* this flag is set after all macroblocks of a picture successfully 92 | * decoded -> redundant slices not decoded */ 93 | u32 skipRedundantSlices; 94 | u32 picStarted; 95 | 96 | /* flag to indicate if current access unit contains any valid slices */ 97 | u32 validSliceInAccessUnit; 98 | 99 | /* store information needed for handling of slice decoding */ 100 | sliceStorage_t slice[1]; 101 | 102 | /* number of concealed macroblocks in the current image */ 103 | u32 numConcealedMbs; 104 | 105 | /* picId given by application */ 106 | u32 currentPicId; 107 | 108 | /* macroblock specific storages, size determined by image dimensions */ 109 | mbStorage_t *mb; 110 | 111 | /* flag to store noOutputReordering flag set by the application */ 112 | u32 noReordering; 113 | 114 | /* DPB */ 115 | dpbStorage_t dpb[1]; 116 | 117 | /* structure to store picture order count related information */ 118 | pocStorage_t poc[1]; 119 | 120 | /* access unit boundary checking related data */ 121 | aubCheck_t aub[1]; 122 | 123 | /* current processed image */ 124 | image_t currImage[1]; 125 | 126 | /* last valid NAL unit header is stored here */ 127 | nalUnit_t prevNalUnit[1]; 128 | 129 | /* slice header, second structure used as a temporary storage while 130 | * decoding slice header, first one stores last successfully decoded 131 | * slice header */ 132 | sliceHeader_t sliceHeader[2]; 133 | 134 | /* fields to store old stream buffer pointers, needed when only part of 135 | * a stream buffer is processed by h264bsdDecode function */ 136 | u32 prevBufNotFinished; 137 | u8 *prevBufPointer; 138 | u32 prevBytesConsumed; 139 | strmData_t strm[1]; 140 | 141 | /* macroblock layer structure, there is no need to store this but it 142 | * would have increased the stack size excessively and needed to be 143 | * allocated from head -> easiest to put it here */ 144 | macroblockLayer_t *mbLayer; 145 | 146 | u32 pendingActivation; /* Activate parameter sets after returning 147 | HEADERS_RDY to the user */ 148 | u32 intraConcealmentFlag; /* 0 gray picture for corrupted intra 149 | 1 previous frame used if available */ 150 | u32* conversionBuffer; // used to perform yuv conversion 151 | size_t conversionBufferSize; 152 | } storage_t; 153 | 154 | /*------------------------------------------------------------------------------ 155 | 4. Function prototypes 156 | ------------------------------------------------------------------------------*/ 157 | 158 | void h264bsdInitStorage(storage_t *pStorage); 159 | void h264bsdResetStorage(storage_t *pStorage); 160 | u32 h264bsdIsStartOfPicture(storage_t *pStorage); 161 | u32 h264bsdIsEndOfPicture(storage_t *pStorage); 162 | u32 h264bsdStoreSeqParamSet(storage_t *pStorage, seqParamSet_t *pSeqParamSet); 163 | u32 h264bsdStorePicParamSet(storage_t *pStorage, picParamSet_t *pPicParamSet); 164 | u32 h264bsdActivateParamSets(storage_t *pStorage, u32 ppsId, u32 isIdr); 165 | void h264bsdComputeSliceGroupMap(storage_t *pStorage, 166 | u32 sliceGroupChangeCycle); 167 | 168 | u32 h264bsdCheckAccessUnitBoundary( 169 | strmData_t *strm, 170 | nalUnit_t *nuNext, 171 | storage_t *storage, 172 | u32 *accessUnitBoundaryFlag); 173 | 174 | u32 h264bsdValidParamSets(storage_t *pStorage); 175 | 176 | #endif /* #ifdef H264SWDEC_STORAGE_H */ 177 | 178 | -------------------------------------------------------------------------------- /native/h264bsd_slice_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_SLICE_HEADER_H 30 | #define H264SWDEC_SLICE_HEADER_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_cfg.h" 39 | #include "h264bsd_seq_param_set.h" 40 | #include "h264bsd_pic_param_set.h" 41 | #include "h264bsd_nal_unit.h" 42 | 43 | /*------------------------------------------------------------------------------ 44 | 2. Module defines 45 | ------------------------------------------------------------------------------*/ 46 | 47 | enum { 48 | P_SLICE = 0, 49 | I_SLICE = 2 50 | }; 51 | 52 | enum {NO_LONG_TERM_FRAME_INDICES = 0xFFFF}; 53 | 54 | /* macro to determine if slice is an inter slice, sliceTypes 0 and 5 */ 55 | #define IS_P_SLICE(sliceType) (((sliceType) == P_SLICE) || \ 56 | ((sliceType) == P_SLICE + 5)) 57 | 58 | /* macro to determine if slice is an intra slice, sliceTypes 2 and 7 */ 59 | #define IS_I_SLICE(sliceType) (((sliceType) == I_SLICE) || \ 60 | ((sliceType) == I_SLICE + 5)) 61 | 62 | /*------------------------------------------------------------------------------ 63 | 3. Data types 64 | ------------------------------------------------------------------------------*/ 65 | 66 | /* structure to store data of one reference picture list reordering operation */ 67 | typedef struct 68 | { 69 | u32 reorderingOfPicNumsIdc; 70 | u32 absDiffPicNum; 71 | u32 longTermPicNum; 72 | } refPicListReorderingOperation_t; 73 | 74 | /* structure to store reference picture list reordering operations */ 75 | typedef struct 76 | { 77 | u32 refPicListReorderingFlagL0; 78 | refPicListReorderingOperation_t command[MAX_NUM_REF_PICS+1]; 79 | } refPicListReordering_t; 80 | 81 | /* structure to store data of one DPB memory management control operation */ 82 | typedef struct 83 | { 84 | u32 memoryManagementControlOperation; 85 | u32 differenceOfPicNums; 86 | u32 longTermPicNum; 87 | u32 longTermFrameIdx; 88 | u32 maxLongTermFrameIdx; 89 | } memoryManagementOperation_t; 90 | 91 | /* worst case scenario: all MAX_NUM_REF_PICS pictures in the buffer are 92 | * short term pictures, each one of them is first marked as long term 93 | * reference picture which is then marked as unused for reference. 94 | * Additionally, max long-term frame index is set and current picture is 95 | * marked as long term reference picture. Last position reserved for 96 | * end memory_management_control_operation command */ 97 | #define MAX_NUM_MMC_OPERATIONS (2*MAX_NUM_REF_PICS+2+1) 98 | 99 | /* structure to store decoded reference picture marking data */ 100 | typedef struct 101 | { 102 | u32 noOutputOfPriorPicsFlag; 103 | u32 longTermReferenceFlag; 104 | u32 adaptiveRefPicMarkingModeFlag; 105 | memoryManagementOperation_t operation[MAX_NUM_MMC_OPERATIONS]; 106 | } decRefPicMarking_t; 107 | 108 | /* structure to store slice header data decoded from the stream */ 109 | typedef struct 110 | { 111 | u32 firstMbInSlice; 112 | u32 sliceType; 113 | u32 picParameterSetId; 114 | u32 frameNum; 115 | u32 idrPicId; 116 | u32 picOrderCntLsb; 117 | i32 deltaPicOrderCntBottom; 118 | i32 deltaPicOrderCnt[2]; 119 | u32 redundantPicCnt; 120 | u32 numRefIdxActiveOverrideFlag; 121 | u32 numRefIdxL0Active; 122 | i32 sliceQpDelta; 123 | u32 disableDeblockingFilterIdc; 124 | i32 sliceAlphaC0Offset; 125 | i32 sliceBetaOffset; 126 | u32 sliceGroupChangeCycle; 127 | refPicListReordering_t refPicListReordering; 128 | decRefPicMarking_t decRefPicMarking; 129 | } sliceHeader_t; 130 | 131 | /*------------------------------------------------------------------------------ 132 | 4. Function prototypes 133 | ------------------------------------------------------------------------------*/ 134 | 135 | u32 h264bsdDecodeSliceHeader(strmData_t *pStrmData, 136 | sliceHeader_t *pSliceHeader, 137 | seqParamSet_t *pSeqParamSet, 138 | picParamSet_t *pPicParamSet, 139 | nalUnit_t *pNalUnit); 140 | 141 | u32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *ppsId); 142 | 143 | u32 h264bsdCheckFrameNum( 144 | strmData_t *pStrmData, 145 | u32 maxFrameNum, 146 | u32 *frameNum); 147 | 148 | u32 h264bsdCheckIdrPicId( 149 | strmData_t *pStrmData, 150 | u32 maxFrameNum, 151 | nalUnitType_e nalUnitType, 152 | u32 *idrPicId); 153 | 154 | u32 h264bsdCheckPicOrderCntLsb( 155 | strmData_t *pStrmData, 156 | seqParamSet_t *pSeqParamSet, 157 | nalUnitType_e nalUnitType, 158 | u32 *picOrderCntLsb); 159 | 160 | u32 h264bsdCheckDeltaPicOrderCntBottom( 161 | strmData_t *pStrmData, 162 | seqParamSet_t *pSeqParamSet, 163 | nalUnitType_e nalUnitType, 164 | i32 *deltaPicOrderCntBottom); 165 | 166 | u32 h264bsdCheckDeltaPicOrderCnt( 167 | strmData_t *pStrmData, 168 | seqParamSet_t *pSeqParamSet, 169 | nalUnitType_e nalUnitType, 170 | u32 picOrderPresentFlag, 171 | i32 *deltaPicOrderCnt); 172 | 173 | u32 h264bsdCheckRedundantPicCnt( 174 | strmData_t *pStrmData, 175 | seqParamSet_t *pSeqParamSet, 176 | picParamSet_t *pPicParamSet, 177 | nalUnitType_e nalUnitType, 178 | u32 *redundantPicCnt); 179 | 180 | u32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag, 181 | const strmData_t * pStrmData, 182 | const seqParamSet_t * pSeqParamSet, 183 | const picParamSet_t * pPicParamSet, 184 | nalUnitType_e nalUnitType); 185 | 186 | #endif /* #ifdef H264SWDEC_SLICE_HEADER_H */ 187 | 188 | -------------------------------------------------------------------------------- /native/h264bsd_stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | h264bsdGetBits 28 | h264bsdShowBits32 29 | h264bsdFlushBits 30 | h264bsdIsByteAligned 31 | 32 | ------------------------------------------------------------------------------*/ 33 | 34 | /*------------------------------------------------------------------------------ 35 | 1. Include headers 36 | ------------------------------------------------------------------------------*/ 37 | 38 | #include "h264bsd_util.h" 39 | #include "h264bsd_stream.h" 40 | 41 | /*------------------------------------------------------------------------------ 42 | 2. External compiler flags 43 | -------------------------------------------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- 46 | 3. Module defines 47 | ------------------------------------------------------------------------------*/ 48 | 49 | /*------------------------------------------------------------------------------ 50 | 4. Local function prototypes 51 | ------------------------------------------------------------------------------*/ 52 | 53 | /*------------------------------------------------------------------------------ 54 | 55 | Function: h264bsdGetBits 56 | 57 | Functional description: 58 | Read and remove bits from the stream buffer. 59 | 60 | Input: 61 | pStrmData pointer to stream data structure 62 | numBits number of bits to read 63 | 64 | Output: 65 | none 66 | 67 | Returns: 68 | bits read from stream 69 | END_OF_STREAM if not enough bits left 70 | 71 | ------------------------------------------------------------------------------*/ 72 | 73 | inline u32 h264bsdGetBits(strmData_t *pStrmData, u32 numBits) 74 | { 75 | 76 | u32 out; 77 | 78 | ASSERT(pStrmData); 79 | ASSERT(numBits < 32); 80 | 81 | out = h264bsdShowBits32(pStrmData) >> (32 - numBits); 82 | 83 | if (h264bsdFlushBits(pStrmData, numBits) == HANTRO_OK) 84 | { 85 | return(out); 86 | } 87 | else 88 | { 89 | return(END_OF_STREAM); 90 | } 91 | 92 | } 93 | 94 | /*------------------------------------------------------------------------------ 95 | 96 | Function: h264bsdShowBits32 97 | 98 | Functional description: 99 | Read 32 bits from the stream buffer. Buffer is left as it is, i.e. 100 | no bits are removed. First bit read from the stream is the MSB of 101 | the return value. If there is not enough bits in the buffer -> 102 | bits beyong the end of the stream are set to '0' in the return 103 | value. 104 | 105 | Input: 106 | pStrmData pointer to stream data structure 107 | 108 | Output: 109 | none 110 | 111 | Returns: 112 | bits read from stream 113 | 114 | ------------------------------------------------------------------------------*/ 115 | 116 | inline u32 h264bsdShowBits32(strmData_t *pStrmData) 117 | { 118 | 119 | i32 bits, shift; 120 | u32 out; 121 | u8 *pStrm; 122 | 123 | ASSERT(pStrmData); 124 | ASSERT(pStrmData->pStrmCurrPos); 125 | ASSERT(pStrmData->bitPosInWord < 8); 126 | ASSERT(pStrmData->bitPosInWord == 127 | (pStrmData->strmBuffReadBits & 0x7)); 128 | 129 | pStrm = pStrmData->pStrmCurrPos; 130 | 131 | /* number of bits left in the buffer */ 132 | bits = (i32)pStrmData->strmBuffSize*8 - (i32)pStrmData->strmBuffReadBits; 133 | 134 | /* at least 32-bits in the buffer */ 135 | if (bits >= 32) 136 | { 137 | u32 bitPosInWord = pStrmData->bitPosInWord; 138 | out = ((u32)pStrm[0] << 24) | ((u32)pStrm[1] << 16) | 139 | ((u32)pStrm[2] << 8) | ((u32)pStrm[3]); 140 | 141 | if (bitPosInWord) 142 | { 143 | u32 byte = (u32)pStrm[4]; 144 | u32 tmp = (8-bitPosInWord); 145 | out <<= bitPosInWord; 146 | out |= byte>>tmp; 147 | } 148 | return (out); 149 | } 150 | /* at least one bit in the buffer */ 151 | else if (bits > 0) 152 | { 153 | shift = (i32)(24 + pStrmData->bitPosInWord); 154 | out = (u32)(*pStrm++) << shift; 155 | bits -= (i32)(8 - pStrmData->bitPosInWord); 156 | while (bits > 0) 157 | { 158 | shift -= 8; 159 | out |= (u32)(*pStrm++) << shift; 160 | bits -= 8; 161 | } 162 | return (out); 163 | } 164 | else 165 | return (0); 166 | 167 | } 168 | 169 | /*------------------------------------------------------------------------------ 170 | 171 | Function: h264bsdFlushBits 172 | 173 | Functional description: 174 | Remove bits from the stream buffer 175 | 176 | Input: 177 | pStrmData pointer to stream data structure 178 | numBits number of bits to remove 179 | 180 | Output: 181 | none 182 | 183 | Returns: 184 | HANTRO_OK success 185 | END_OF_STREAM not enough bits left 186 | 187 | ------------------------------------------------------------------------------*/ 188 | #ifndef H264DEC_NEON 189 | inline u32 h264bsdFlushBits(strmData_t *pStrmData, u32 numBits) 190 | { 191 | 192 | ASSERT(pStrmData); 193 | ASSERT(pStrmData->pStrmBuffStart); 194 | ASSERT(pStrmData->pStrmCurrPos); 195 | ASSERT(pStrmData->bitPosInWord < 8); 196 | ASSERT(pStrmData->bitPosInWord == (pStrmData->strmBuffReadBits & 0x7)); 197 | 198 | pStrmData->strmBuffReadBits += numBits; 199 | pStrmData->bitPosInWord = pStrmData->strmBuffReadBits & 0x7; 200 | if ( (pStrmData->strmBuffReadBits ) <= (8*pStrmData->strmBuffSize) ) 201 | { 202 | pStrmData->pStrmCurrPos = pStrmData->pStrmBuffStart + 203 | (pStrmData->strmBuffReadBits >> 3); 204 | return(HANTRO_OK); 205 | } 206 | else 207 | return(END_OF_STREAM); 208 | 209 | } 210 | #endif 211 | /*------------------------------------------------------------------------------ 212 | 213 | Function: h264bsdIsByteAligned 214 | 215 | Functional description: 216 | Check if current stream position is byte aligned. 217 | 218 | Inputs: 219 | pStrmData pointer to stream data structure 220 | 221 | Outputs: 222 | none 223 | 224 | Returns: 225 | TRUE stream is byte aligned 226 | FALSE stream is not byte aligned 227 | 228 | ------------------------------------------------------------------------------*/ 229 | 230 | u32 h264bsdIsByteAligned(strmData_t *pStrmData) 231 | { 232 | 233 | /* Variables */ 234 | 235 | /* Code */ 236 | 237 | if (!pStrmData->bitPosInWord) 238 | return(HANTRO_TRUE); 239 | else 240 | return(HANTRO_FALSE); 241 | 242 | } 243 | 244 | -------------------------------------------------------------------------------- /native/h264bsd_sei.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. Module defines 24 | 3. Data types 25 | 4. Function prototypes 26 | 27 | ------------------------------------------------------------------------------*/ 28 | 29 | #ifndef H264SWDEC_SEI_H 30 | #define H264SWDEC_SEI_H 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "basetype.h" 37 | #include "h264bsd_stream.h" 38 | #include "h264bsd_slice_header.h" 39 | #include "h264bsd_seq_param_set.h" 40 | #include "h264bsd_vui.h" 41 | 42 | /*------------------------------------------------------------------------------ 43 | 2. Module defines 44 | ------------------------------------------------------------------------------*/ 45 | 46 | #define MAX_PAN_SCAN_CNT 32 47 | #define MAX_NUM_SPARE_PICS 16 48 | #define MAX_NUM_CLOCK_TS 3 49 | #define MAX_NUM_SUB_SEQ_LAYERS 256 50 | 51 | /*------------------------------------------------------------------------------ 52 | 3. Data types 53 | ------------------------------------------------------------------------------*/ 54 | 55 | typedef struct 56 | { 57 | u32 seqParameterSetId; 58 | u32 initialCpbRemovalDelay[MAX_CPB_CNT]; 59 | u32 initialCpbRemovalDelayOffset[MAX_CPB_CNT]; 60 | } seiBufferingPeriod_t; 61 | 62 | typedef struct 63 | { 64 | u32 cpbRemovalDelay; 65 | u32 dpbOutputDelay; 66 | u32 picStruct; 67 | u32 clockTimeStampFlag[MAX_NUM_CLOCK_TS]; 68 | u32 clockTimeStamp[MAX_NUM_CLOCK_TS]; 69 | u32 ctType[MAX_NUM_CLOCK_TS]; 70 | u32 nuitFieldBasedFlag[MAX_NUM_CLOCK_TS]; 71 | u32 countingType[MAX_NUM_CLOCK_TS]; 72 | u32 fullTimeStampFlag[MAX_NUM_CLOCK_TS]; 73 | u32 discontinuityFlag[MAX_NUM_CLOCK_TS]; 74 | u32 cntDroppedFlag[MAX_NUM_CLOCK_TS]; 75 | u32 nFrames[MAX_NUM_CLOCK_TS]; 76 | u32 secondsFlag[MAX_NUM_CLOCK_TS]; 77 | u32 secondsValue[MAX_NUM_CLOCK_TS]; 78 | u32 minutesFlag[MAX_NUM_CLOCK_TS]; 79 | u32 minutesValue[MAX_NUM_CLOCK_TS]; 80 | u32 hoursFlag[MAX_NUM_CLOCK_TS]; 81 | u32 hoursValue[MAX_NUM_CLOCK_TS]; 82 | i32 timeOffset[MAX_NUM_CLOCK_TS]; 83 | } seiPicTiming_t; 84 | 85 | typedef struct 86 | { 87 | u32 panScanRectId; 88 | u32 panScanRectCancelFlag; 89 | u32 panScanCnt; 90 | i32 panScanRectLeftOffset[MAX_PAN_SCAN_CNT]; 91 | i32 panScanRectRightOffset[MAX_PAN_SCAN_CNT]; 92 | i32 panScanRectTopOffset[MAX_PAN_SCAN_CNT]; 93 | i32 panScanRectBottomOffset[MAX_PAN_SCAN_CNT]; 94 | u32 panScanRectRepetitionPeriod; 95 | } seiPanScanRect_t; 96 | 97 | typedef struct 98 | { 99 | u32 ituTT35CountryCode; 100 | u32 ituTT35CountryCodeExtensionByte; 101 | u8 *ituTT35PayloadByte; 102 | u32 numPayloadBytes; 103 | } seiUserDataRegisteredItuTT35_t; 104 | 105 | typedef struct 106 | { 107 | u32 uuidIsoIec11578[4]; 108 | u8 *userDataPayloadByte; 109 | u32 numPayloadBytes; 110 | } seiUserDataUnregistered_t; 111 | 112 | typedef struct 113 | { 114 | u32 recoveryFrameCnt; 115 | u32 exactMatchFlag; 116 | u32 brokenLinkFlag; 117 | u32 changingSliceGroupIdc; 118 | } seiRecoveryPoint_t; 119 | 120 | typedef struct 121 | { 122 | u32 originalIdrFlag; 123 | u32 originalFrameNum; 124 | decRefPicMarking_t decRefPicMarking; 125 | } seiDecRefPicMarkingRepetition_t; 126 | 127 | typedef struct 128 | { 129 | u32 targetFrameNum; 130 | u32 spareFieldFlag; 131 | u32 targetBottomFieldFlag; 132 | u32 numSparePics; 133 | u32 deltaSpareFrameNum[MAX_NUM_SPARE_PICS]; 134 | u32 spareBottomFieldFlag[MAX_NUM_SPARE_PICS]; 135 | u32 spareAreaIdc[MAX_NUM_SPARE_PICS]; 136 | u32 *spareUnitFlag[MAX_NUM_SPARE_PICS]; 137 | u32 *zeroRunLength[MAX_NUM_SPARE_PICS]; 138 | } seiSparePic_t; 139 | 140 | typedef struct 141 | { 142 | u32 sceneInfoPresentFlag; 143 | u32 sceneId; 144 | u32 sceneTransitionType; 145 | u32 secondSceneId; 146 | } seiSceneInfo_t; 147 | 148 | typedef struct 149 | { 150 | u32 subSeqLayerNum; 151 | u32 subSeqId; 152 | u32 firstRefPicFlag; 153 | u32 leadingNonRefPicFlag; 154 | u32 lastPicFlag; 155 | u32 subSeqFrameNumFlag; 156 | u32 subSeqFrameNum; 157 | } seiSubSeqInfo_t; 158 | 159 | typedef struct 160 | { 161 | u32 numSubSeqLayers; 162 | u32 accurateStatisticsFlag[MAX_NUM_SUB_SEQ_LAYERS]; 163 | u32 averageBitRate[MAX_NUM_SUB_SEQ_LAYERS]; 164 | u32 averageFrameRate[MAX_NUM_SUB_SEQ_LAYERS]; 165 | } seiSubSeqLayerCharacteristics_t; 166 | 167 | typedef struct 168 | { 169 | u32 subSeqLayerNum; 170 | u32 subSeqId; 171 | u32 durationFlag; 172 | u32 subSeqDuration; 173 | u32 averageRateFlag; 174 | u32 accurateStatisticsFlag; 175 | u32 averageBitRate; 176 | u32 averageFrameRate; 177 | u32 numReferencedSubseqs; 178 | u32 refSubSeqLayerNum[MAX_NUM_SUB_SEQ_LAYERS]; 179 | u32 refSubSeqId[MAX_NUM_SUB_SEQ_LAYERS]; 180 | u32 refSubSeqDirection[MAX_NUM_SUB_SEQ_LAYERS]; 181 | } seiSubSeqCharacteristics_t; 182 | 183 | typedef struct 184 | { 185 | u32 fullFrameFreezeRepetitionPeriod; 186 | } seiFullFrameFreeze_t; 187 | 188 | typedef struct 189 | { 190 | u32 snapShotId; 191 | } seiFullFrameSnapshot_t; 192 | 193 | typedef struct 194 | { 195 | u32 progressiveRefinementId; 196 | u32 numRefinementSteps; 197 | } seiProgressiveRefinementSegmentStart_t; 198 | 199 | typedef struct 200 | { 201 | u32 progressiveRefinementId; 202 | } seiProgressiveRefinementSegmentEnd_t; 203 | 204 | typedef struct 205 | { 206 | u32 numSliceGroupsInSet; 207 | u32 sliceGroupId[MAX_NUM_SLICE_GROUPS]; 208 | u32 exactSampleValueMatchFlag; 209 | u32 panScanRectFlag; 210 | u32 panScanRectId; 211 | } seiMotionConstrainedSliceGroupSet_t; 212 | 213 | typedef struct 214 | { 215 | u8 *reservedSeiMessagePayloadByte; 216 | u32 numPayloadBytes; 217 | } seiReservedSeiMessage_t; 218 | 219 | typedef struct 220 | { 221 | u32 payloadType; 222 | seiBufferingPeriod_t bufferingPeriod; 223 | seiPicTiming_t picTiming; 224 | seiPanScanRect_t panScanRect; 225 | seiUserDataRegisteredItuTT35_t userDataRegisteredItuTT35; 226 | seiUserDataUnregistered_t userDataUnregistered; 227 | seiRecoveryPoint_t recoveryPoint; 228 | seiDecRefPicMarkingRepetition_t decRefPicMarkingRepetition; 229 | seiSparePic_t sparePic; 230 | seiSceneInfo_t sceneInfo; 231 | seiSubSeqInfo_t subSeqInfo; 232 | seiSubSeqLayerCharacteristics_t subSeqLayerCharacteristics; 233 | seiSubSeqCharacteristics_t subSeqCharacteristics; 234 | seiFullFrameFreeze_t fullFrameFreeze; 235 | seiFullFrameSnapshot_t fullFrameSnapshot; 236 | seiProgressiveRefinementSegmentStart_t progressiveRefinementSegmentStart; 237 | seiProgressiveRefinementSegmentEnd_t progressiveRefinementSegmentEnd; 238 | seiMotionConstrainedSliceGroupSet_t motionConstrainedSliceGroupSet; 239 | seiReservedSeiMessage_t reservedSeiMessage; 240 | } seiMessage_t; 241 | 242 | /*------------------------------------------------------------------------------ 243 | 4. Function prototypes 244 | ------------------------------------------------------------------------------*/ 245 | 246 | u32 h264bsdDecodeSeiMessage( 247 | strmData_t *pStrmData, 248 | seqParamSet_t *pSeqParamSet, 249 | seiMessage_t *pSeiMessage, 250 | u32 numSliceGroups); 251 | 252 | #endif /* #ifdef H264SWDEC_SEI_H */ 253 | 254 | -------------------------------------------------------------------------------- /native/h264bsd_byte_stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | ExtractNalUnit 28 | 29 | ------------------------------------------------------------------------------*/ 30 | 31 | /*------------------------------------------------------------------------------ 32 | 1. Include headers 33 | ------------------------------------------------------------------------------*/ 34 | 35 | #include "h264bsd_byte_stream.h" 36 | #include "h264bsd_util.h" 37 | 38 | /*------------------------------------------------------------------------------ 39 | 2. External compiler flags 40 | -------------------------------------------------------------------------------- 41 | 42 | -------------------------------------------------------------------------------- 43 | 3. Module defines 44 | ------------------------------------------------------------------------------*/ 45 | 46 | #define BYTE_STREAM_ERROR 0xFFFFFFFF 47 | 48 | /*------------------------------------------------------------------------------ 49 | 4. Local function prototypes 50 | ------------------------------------------------------------------------------*/ 51 | 52 | /*------------------------------------------------------------------------------ 53 | 54 | Function name: ExtractNalUnit 55 | 56 | Functional description: 57 | Extracts one NAL unit from the byte stream buffer. Removes 58 | emulation prevention bytes if present. The original stream buffer 59 | is used directly and is therefore modified if emulation prevention 60 | bytes are present in the stream. 61 | 62 | Stream buffer is assumed to contain either exactly one NAL unit 63 | and nothing else, or one or more NAL units embedded in byte 64 | stream format described in the Annex B of the standard. Function 65 | detects which one is used based on the first bytes in the buffer. 66 | 67 | Inputs: 68 | pByteStream pointer to byte stream buffer 69 | len length of the stream buffer (in bytes) 70 | 71 | Outputs: 72 | pStrmData stream information is stored here 73 | readBytes number of bytes "consumed" from the stream buffer 74 | 75 | Returns: 76 | HANTRO_OK success 77 | HANTRO_NOK error in byte stream 78 | 79 | ------------------------------------------------------------------------------*/ 80 | 81 | u32 h264bsdExtractNalUnit(u8 *pByteStream, u32 len, strmData_t *pStrmData, 82 | u32 *readBytes) 83 | { 84 | 85 | /* Variables */ 86 | 87 | u32 i, tmp; 88 | u32 byteCount,initByteCount; 89 | u32 zeroCount; 90 | u8 byte; 91 | u32 hasEmulation = HANTRO_FALSE; 92 | u32 invalidStream = HANTRO_FALSE; 93 | u8 *readPtr, *writePtr; 94 | 95 | /* Code */ 96 | 97 | ASSERT(pByteStream); 98 | ASSERT(len); 99 | ASSERT(len < BYTE_STREAM_ERROR); 100 | ASSERT(pStrmData); 101 | 102 | /* byte stream format if starts with 0x000001 or 0x000000 */ 103 | if (len > 3 && pByteStream[0] == 0x00 && pByteStream[1] == 0x00 && 104 | (pByteStream[2]&0xFE) == 0x00) 105 | { 106 | /* search for NAL unit start point, i.e. point after first start code 107 | * prefix in the stream */ 108 | zeroCount = byteCount = 2; 109 | readPtr = pByteStream + 2; 110 | /*lint -e(716) while(1) used consciously */ 111 | while (1) 112 | { 113 | byte = *readPtr++; 114 | byteCount++; 115 | 116 | if (byteCount == len) 117 | { 118 | /* no start code prefix found -> error */ 119 | *readBytes = len; 120 | return(HANTRO_NOK); 121 | } 122 | 123 | if (!byte) 124 | zeroCount++; 125 | else if ((byte == 0x01) && (zeroCount >= 2)) 126 | break; 127 | else 128 | zeroCount = 0; 129 | } 130 | 131 | initByteCount = byteCount; 132 | 133 | /* determine size of the NAL unit. Search for next start code prefix 134 | * or end of stream and ignore possible trailing zero bytes */ 135 | zeroCount = 0; 136 | /*lint -e(716) while(1) used consciously */ 137 | while (1) 138 | { 139 | byte = *readPtr++; 140 | byteCount++; 141 | if (!byte) 142 | zeroCount++; 143 | 144 | if ( (byte == 0x03) && (zeroCount == 2) ) 145 | { 146 | hasEmulation = HANTRO_TRUE; 147 | } 148 | 149 | if ( (byte == 0x01) && (zeroCount >= 2 ) ) 150 | { 151 | pStrmData->strmBuffSize = 152 | byteCount - initByteCount - zeroCount - 1; 153 | zeroCount -= MIN(zeroCount, 3); 154 | break; 155 | } 156 | else if (byte) 157 | { 158 | if (zeroCount >= 3) 159 | invalidStream = HANTRO_TRUE; 160 | zeroCount = 0; 161 | } 162 | 163 | if (byteCount == len) 164 | { 165 | pStrmData->strmBuffSize = byteCount - initByteCount - zeroCount; 166 | break; 167 | } 168 | 169 | } 170 | } 171 | /* separate NAL units as input -> just set stream params */ 172 | else 173 | { 174 | initByteCount = 0; 175 | zeroCount = 0; 176 | pStrmData->strmBuffSize = len; 177 | hasEmulation = HANTRO_TRUE; 178 | } 179 | 180 | pStrmData->pStrmBuffStart = pByteStream + initByteCount; 181 | pStrmData->pStrmCurrPos = pStrmData->pStrmBuffStart; 182 | pStrmData->bitPosInWord = 0; 183 | pStrmData->strmBuffReadBits = 0; 184 | 185 | /* return number of bytes "consumed" */ 186 | *readBytes = pStrmData->strmBuffSize + initByteCount + zeroCount; 187 | 188 | if (invalidStream) 189 | { 190 | return(HANTRO_NOK); 191 | } 192 | 193 | /* remove emulation prevention bytes before rbsp processing */ 194 | if (hasEmulation) 195 | { 196 | tmp = pStrmData->strmBuffSize; 197 | readPtr = writePtr = pStrmData->pStrmBuffStart; 198 | zeroCount = 0; 199 | for (i = tmp; i--;) 200 | { 201 | if ((zeroCount == 2) && (*readPtr == 0x03)) 202 | { 203 | /* emulation prevention byte shall be followed by one of the 204 | * following bytes: 0x00, 0x01, 0x02, 0x03. This implies that 205 | * emulation prevention 0x03 byte shall not be the last byte 206 | * of the stream. */ 207 | if ( (i == 0) || (*(readPtr+1) > 0x03) ) 208 | return(HANTRO_NOK); 209 | 210 | /* do not write emulation prevention byte */ 211 | readPtr++; 212 | zeroCount = 0; 213 | } 214 | else 215 | { 216 | /* NAL unit shall not contain byte sequences 0x000000, 217 | * 0x000001 or 0x000002 */ 218 | if ( (zeroCount == 2) && (*readPtr <= 0x02) ) 219 | return(HANTRO_NOK); 220 | 221 | if (*readPtr == 0) 222 | zeroCount++; 223 | else 224 | zeroCount = 0; 225 | 226 | *writePtr++ = *readPtr++; 227 | } 228 | } 229 | 230 | /* (readPtr - writePtr) indicates number of "removed" emulation 231 | * prevention bytes -> subtract from stream buffer size */ 232 | pStrmData->strmBuffSize -= (u32)(readPtr - writePtr); 233 | } 234 | 235 | return(HANTRO_OK); 236 | 237 | } 238 | 239 | -------------------------------------------------------------------------------- /native/h264bsd_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | h264bsdCountLeadingZeros 28 | h264bsdRbspTrailingBits 29 | h264bsdMoreRbspData 30 | h264bsdNextMbAddress 31 | h264bsdSetCurrImageMbPointers 32 | 33 | ------------------------------------------------------------------------------*/ 34 | 35 | /*------------------------------------------------------------------------------ 36 | 1. Include headers 37 | ------------------------------------------------------------------------------*/ 38 | 39 | #include "h264bsd_util.h" 40 | 41 | /*------------------------------------------------------------------------------ 42 | 2. External compiler flags 43 | -------------------------------------------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- 46 | 3. Module defines 47 | ------------------------------------------------------------------------------*/ 48 | 49 | /* look-up table for expected values of stuffing bits */ 50 | static const u32 stuffingTable[8] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80}; 51 | 52 | /* look-up table for chroma quantization parameter as a function of luma QP */ 53 | const u32 h264bsdQpC[52] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 54 | 20,21,22,23,24,25,26,27,28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,37, 55 | 38,38,38,39,39,39,39}; 56 | 57 | /*------------------------------------------------------------------------------ 58 | 4. Local function prototypes 59 | ------------------------------------------------------------------------------*/ 60 | 61 | /*------------------------------------------------------------------------------ 62 | 63 | 5.1 Function: h264bsdCountLeadingZeros 64 | 65 | Functional description: 66 | Count leading zeros in a code word. Code word is assumed to be 67 | right-aligned, last bit of the code word in the lsb of the value. 68 | 69 | Inputs: 70 | value code word 71 | length number of bits in the code word 72 | 73 | Outputs: 74 | none 75 | 76 | Returns: 77 | number of leading zeros in the code word 78 | 79 | ------------------------------------------------------------------------------*/ 80 | #ifndef H264DEC_NEON 81 | u32 h264bsdCountLeadingZeros(u32 value, u32 length) 82 | { 83 | 84 | /* Variables */ 85 | 86 | u32 zeros = 0; 87 | u32 mask = 1 << (length - 1); 88 | 89 | /* Code */ 90 | 91 | ASSERT(length <= 32); 92 | 93 | while (mask && !(value & mask)) 94 | { 95 | zeros++; 96 | mask >>= 1; 97 | } 98 | return(zeros); 99 | 100 | } 101 | #endif 102 | /*------------------------------------------------------------------------------ 103 | 104 | 5.2 Function: h264bsdRbspTrailingBits 105 | 106 | Functional description: 107 | Check Raw Byte Stream Payload (RBSP) trailing bits, i.e. stuffing. 108 | Rest of the current byte (whole byte if allready byte aligned) 109 | in the stream buffer shall contain a '1' bit followed by zero or 110 | more '0' bits. 111 | 112 | Inputs: 113 | pStrmData pointer to stream data structure 114 | 115 | Outputs: 116 | none 117 | 118 | Returns: 119 | HANTRO_OK RBSP trailing bits found 120 | HANTRO_NOK otherwise 121 | 122 | ------------------------------------------------------------------------------*/ 123 | 124 | u32 h264bsdRbspTrailingBits(strmData_t *pStrmData) 125 | { 126 | 127 | /* Variables */ 128 | 129 | u32 stuffing; 130 | u32 stuffingLength; 131 | 132 | /* Code */ 133 | 134 | ASSERT(pStrmData); 135 | ASSERT(pStrmData->bitPosInWord < 8); 136 | 137 | stuffingLength = 8 - pStrmData->bitPosInWord; 138 | 139 | stuffing = h264bsdGetBits(pStrmData, stuffingLength); 140 | if (stuffing == END_OF_STREAM) 141 | return(HANTRO_NOK); 142 | 143 | if (stuffing != stuffingTable[stuffingLength - 1]) 144 | return(HANTRO_NOK); 145 | else 146 | return(HANTRO_OK); 147 | 148 | } 149 | 150 | /*------------------------------------------------------------------------------ 151 | 152 | 5.3 Function: h264bsdMoreRbspData 153 | 154 | Functional description: 155 | Check if there is more data in the current RBSP. The standard 156 | defines this function so that there is more data if 157 | -more than 8 bits left or 158 | -last bits are not RBSP trailing bits 159 | 160 | Inputs: 161 | pStrmData pointer to stream data structure 162 | 163 | Outputs: 164 | none 165 | 166 | Returns: 167 | HANTRO_TRUE there is more data 168 | HANTRO_FALSE no more data 169 | 170 | ------------------------------------------------------------------------------*/ 171 | 172 | u32 h264bsdMoreRbspData(strmData_t *pStrmData) 173 | { 174 | 175 | /* Variables */ 176 | 177 | u32 bits; 178 | 179 | /* Code */ 180 | 181 | ASSERT(pStrmData); 182 | ASSERT(pStrmData->strmBuffReadBits <= 8 * pStrmData->strmBuffSize); 183 | 184 | bits = pStrmData->strmBuffSize * 8 - pStrmData->strmBuffReadBits; 185 | 186 | if (bits == 0) 187 | return(HANTRO_FALSE); 188 | 189 | if ( (bits > 8) || 190 | ((h264bsdShowBits32(pStrmData)>>(32-bits)) != (1ul << (bits-1))) ) 191 | return(HANTRO_TRUE); 192 | else 193 | return(HANTRO_FALSE); 194 | 195 | } 196 | 197 | /*------------------------------------------------------------------------------ 198 | 199 | 5.4 Function: h264bsdNextMbAddress 200 | 201 | Functional description: 202 | Get address of the next macroblock in the current slice group. 203 | 204 | Inputs: 205 | pSliceGroupMap slice group for each macroblock 206 | picSizeInMbs size of the picture 207 | currMbAddr where to start 208 | 209 | Outputs: 210 | none 211 | 212 | Returns: 213 | address of the next macroblock 214 | 0 if none of the following macroblocks belong to same slice 215 | group as currMbAddr 216 | 217 | ------------------------------------------------------------------------------*/ 218 | 219 | u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr) 220 | { 221 | 222 | /* Variables */ 223 | 224 | u32 i, sliceGroup; 225 | 226 | /* Code */ 227 | 228 | ASSERT(pSliceGroupMap); 229 | ASSERT(picSizeInMbs); 230 | ASSERT(currMbAddr < picSizeInMbs); 231 | 232 | sliceGroup = pSliceGroupMap[currMbAddr]; 233 | 234 | i = currMbAddr + 1; 235 | while ((i < picSizeInMbs) && (pSliceGroupMap[i] != sliceGroup)) 236 | { 237 | i++; 238 | } 239 | 240 | if (i == picSizeInMbs) 241 | i = 0; 242 | 243 | return(i); 244 | 245 | } 246 | 247 | 248 | /*------------------------------------------------------------------------------ 249 | 250 | 5.5 Function: h264bsdSetCurrImageMbPointers 251 | 252 | Functional description: 253 | Set luma and chroma pointers in image_t for current MB 254 | 255 | Inputs: 256 | image Current image 257 | mbNum number of current MB 258 | 259 | Outputs: 260 | none 261 | 262 | Returns: 263 | none 264 | ------------------------------------------------------------------------------*/ 265 | void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum) 266 | { 267 | u32 width, height; 268 | u32 picSize; 269 | u32 row, col; 270 | u32 tmp; 271 | 272 | width = image->width; 273 | height = image->height; 274 | row = mbNum / width; 275 | col = mbNum % width; 276 | 277 | tmp = row * width; 278 | picSize = width * height; 279 | 280 | image->luma = (u8*)(image->data + col * 16 + tmp * 256); 281 | image->cb = (u8*)(image->data + picSize * 256 + tmp * 64 + col * 8); 282 | image->cr = (u8*)(image->cb + picSize * 64); 283 | } 284 | -------------------------------------------------------------------------------- /native/h264bsd_image.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | h264bsdWriteMacroblock 28 | h264bsdWriteOutputBlocks 29 | 30 | ------------------------------------------------------------------------------*/ 31 | 32 | /*------------------------------------------------------------------------------ 33 | 1. Include headers 34 | ------------------------------------------------------------------------------*/ 35 | 36 | #include "h264bsd_image.h" 37 | #include "h264bsd_util.h" 38 | #include "h264bsd_neighbour.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. External compiler flags 42 | -------------------------------------------------------------------------------- 43 | 44 | -------------------------------------------------------------------------------- 45 | 3. Module defines 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /* x- and y-coordinates for each block, defined in h264bsd_intra_prediction.c */ 49 | extern const u32 h264bsdBlockX[]; 50 | extern const u32 h264bsdBlockY[]; 51 | 52 | /* clipping table, defined in h264bsd_intra_prediction.c */ 53 | extern const u8 h264bsdClip[]; 54 | 55 | /*------------------------------------------------------------------------------ 56 | 4. Local function prototypes 57 | ------------------------------------------------------------------------------*/ 58 | 59 | 60 | 61 | /*------------------------------------------------------------------------------ 62 | 63 | Function: h264bsdWriteMacroblock 64 | 65 | Functional description: 66 | Write one macroblock into the image. Both luma and chroma 67 | components will be written at the same time. 68 | 69 | Inputs: 70 | data pointer to macroblock data to be written, 256 values for 71 | luma followed by 64 values for both chroma components 72 | 73 | Outputs: 74 | image pointer to the image where the macroblock will be written 75 | 76 | Returns: 77 | none 78 | 79 | ------------------------------------------------------------------------------*/ 80 | #ifndef H264DEC_NEON 81 | void h264bsdWriteMacroblock(image_t *image, u8 *data) 82 | { 83 | 84 | /* Variables */ 85 | 86 | u32 i; 87 | u32 width; 88 | u32 *lum, *cb, *cr; 89 | u32 *ptr; 90 | u32 tmp1, tmp2; 91 | 92 | /* Code */ 93 | 94 | ASSERT(image); 95 | ASSERT(data); 96 | ASSERT(!((u32)data&0x3)); 97 | 98 | width = image->width; 99 | 100 | /*lint -save -e826 lum, cb and cr used to copy 4 bytes at the time, disable 101 | * "area too small" info message */ 102 | lum = (u32*)image->luma; 103 | cb = (u32*)image->cb; 104 | cr = (u32*)image->cr; 105 | ASSERT(!((u32)lum&0x3)); 106 | ASSERT(!((u32)cb&0x3)); 107 | ASSERT(!((u32)cr&0x3)); 108 | 109 | ptr = (u32*)data; 110 | 111 | width *= 4; 112 | for (i = 16; i ; i--) 113 | { 114 | tmp1 = *ptr++; 115 | tmp2 = *ptr++; 116 | *lum++ = tmp1; 117 | *lum++ = tmp2; 118 | tmp1 = *ptr++; 119 | tmp2 = *ptr++; 120 | *lum++ = tmp1; 121 | *lum++ = tmp2; 122 | lum += width-4; 123 | } 124 | 125 | width >>= 1; 126 | for (i = 8; i ; i--) 127 | { 128 | tmp1 = *ptr++; 129 | tmp2 = *ptr++; 130 | *cb++ = tmp1; 131 | *cb++ = tmp2; 132 | cb += width-2; 133 | } 134 | 135 | for (i = 8; i ; i--) 136 | { 137 | tmp1 = *ptr++; 138 | tmp2 = *ptr++; 139 | *cr++ = tmp1; 140 | *cr++ = tmp2; 141 | cr += width-2; 142 | } 143 | 144 | } 145 | #endif 146 | #ifndef H264DEC_OMXDL 147 | /*------------------------------------------------------------------------------ 148 | 149 | Function: h264bsdWriteOutputBlocks 150 | 151 | Functional description: 152 | Write one macroblock into the image. Prediction for the macroblock 153 | and the residual are given separately and will be combined while 154 | writing the data to the image 155 | 156 | Inputs: 157 | data pointer to macroblock prediction data, 256 values for 158 | luma followed by 64 values for both chroma components 159 | mbNum number of the macroblock 160 | residual pointer to residual data, 16 16-element arrays for luma 161 | followed by 4 16-element arrays for both chroma 162 | components 163 | 164 | Outputs: 165 | image pointer to the image where the data will be written 166 | 167 | Returns: 168 | none 169 | 170 | ------------------------------------------------------------------------------*/ 171 | 172 | void h264bsdWriteOutputBlocks(image_t *image, u32 mbNum, u8 *data, 173 | i32 residual[][16]) 174 | { 175 | 176 | /* Variables */ 177 | 178 | u32 i; 179 | u32 picWidth, picSize; 180 | u8 *lum, *cb, *cr; 181 | u8 *imageBlock; 182 | u8 *tmp; 183 | u32 row, col; 184 | u32 block; 185 | u32 x, y; 186 | i32 *pRes; 187 | i32 tmp1, tmp2, tmp3, tmp4; 188 | const u8 *clp = h264bsdClip + 512; 189 | 190 | /* Code */ 191 | 192 | ASSERT(image); 193 | ASSERT(data); 194 | ASSERT(mbNum < image->width * image->height); 195 | ASSERT(!((u32)data&0x3)); 196 | 197 | /* Image size in macroblocks */ 198 | picWidth = image->width; 199 | picSize = picWidth * image->height; 200 | row = mbNum / picWidth; 201 | col = mbNum % picWidth; 202 | 203 | /* Output macroblock position in output picture */ 204 | lum = (image->data + row * picWidth * 256 + col * 16); 205 | cb = (image->data + picSize * 256 + row * picWidth * 64 + col * 8); 206 | cr = (cb + picSize * 64); 207 | 208 | picWidth *= 16; 209 | 210 | for (block = 0; block < 16; block++) 211 | { 212 | x = h264bsdBlockX[block]; 213 | y = h264bsdBlockY[block]; 214 | 215 | pRes = residual[block]; 216 | 217 | ASSERT(pRes); 218 | 219 | tmp = data + y*16 + x; 220 | imageBlock = lum + y*picWidth + x; 221 | 222 | ASSERT(!((u32)tmp&0x3)); 223 | ASSERT(!((u32)imageBlock&0x3)); 224 | 225 | if (IS_RESIDUAL_EMPTY(pRes)) 226 | { 227 | /*lint -e826 */ 228 | i32 *in32 = (i32*)tmp; 229 | i32 *out32 = (i32*)imageBlock; 230 | 231 | /* Residual is zero => copy prediction block to output */ 232 | tmp1 = *in32; in32 += 4; 233 | tmp2 = *in32; in32 += 4; 234 | *out32 = tmp1; out32 += picWidth/4; 235 | *out32 = tmp2; out32 += picWidth/4; 236 | tmp1 = *in32; in32 += 4; 237 | tmp2 = *in32; 238 | *out32 = tmp1; out32 += picWidth/4; 239 | *out32 = tmp2; 240 | } 241 | else 242 | { 243 | 244 | RANGE_CHECK_ARRAY(pRes, -512, 511, 16); 245 | 246 | /* Calculate image = prediction + residual 247 | * Process four pixels in a loop */ 248 | for (i = 4; i; i--) 249 | { 250 | tmp1 = tmp[0]; 251 | tmp2 = *pRes++; 252 | tmp3 = tmp[1]; 253 | tmp1 = clp[tmp1 + tmp2]; 254 | tmp4 = *pRes++; 255 | imageBlock[0] = (u8)tmp1; 256 | tmp3 = clp[tmp3 + tmp4]; 257 | tmp1 = tmp[2]; 258 | tmp2 = *pRes++; 259 | imageBlock[1] = (u8)tmp3; 260 | tmp1 = clp[tmp1 + tmp2]; 261 | tmp3 = tmp[3]; 262 | tmp4 = *pRes++; 263 | imageBlock[2] = (u8)tmp1; 264 | tmp3 = clp[tmp3 + tmp4]; 265 | tmp += 16; 266 | imageBlock[3] = (u8)tmp3; 267 | imageBlock += picWidth; 268 | } 269 | } 270 | 271 | } 272 | 273 | picWidth /= 2; 274 | 275 | for (block = 16; block <= 23; block++) 276 | { 277 | x = h264bsdBlockX[block & 0x3]; 278 | y = h264bsdBlockY[block & 0x3]; 279 | 280 | pRes = residual[block]; 281 | 282 | ASSERT(pRes); 283 | 284 | tmp = data + 256; 285 | imageBlock = cb; 286 | 287 | if (block >= 20) 288 | { 289 | imageBlock = cr; 290 | tmp += 64; 291 | } 292 | 293 | tmp += y*8 + x; 294 | imageBlock += y*picWidth + x; 295 | 296 | ASSERT(!((u32)tmp&0x3)); 297 | ASSERT(!((u32)imageBlock&0x3)); 298 | 299 | if (IS_RESIDUAL_EMPTY(pRes)) 300 | { 301 | /*lint -e826 */ 302 | i32 *in32 = (i32*)tmp; 303 | i32 *out32 = (i32*)imageBlock; 304 | 305 | /* Residual is zero => copy prediction block to output */ 306 | tmp1 = *in32; in32 += 2; 307 | tmp2 = *in32; in32 += 2; 308 | *out32 = tmp1; out32 += picWidth/4; 309 | *out32 = tmp2; out32 += picWidth/4; 310 | tmp1 = *in32; in32 += 2; 311 | tmp2 = *in32; 312 | *out32 = tmp1; out32 += picWidth/4; 313 | *out32 = tmp2; 314 | } 315 | else 316 | { 317 | 318 | RANGE_CHECK_ARRAY(pRes, -512, 511, 16); 319 | 320 | for (i = 4; i; i--) 321 | { 322 | tmp1 = tmp[0]; 323 | tmp2 = *pRes++; 324 | tmp3 = tmp[1]; 325 | tmp1 = clp[tmp1 + tmp2]; 326 | tmp4 = *pRes++; 327 | imageBlock[0] = (u8)tmp1; 328 | tmp3 = clp[tmp3 + tmp4]; 329 | tmp1 = tmp[2]; 330 | tmp2 = *pRes++; 331 | imageBlock[1] = (u8)tmp3; 332 | tmp1 = clp[tmp1 + tmp2]; 333 | tmp3 = tmp[3]; 334 | tmp4 = *pRes++; 335 | imageBlock[2] = (u8)tmp1; 336 | tmp3 = clp[tmp3 + tmp4]; 337 | tmp += 8; 338 | imageBlock[3] = (u8)tmp3; 339 | imageBlock += picWidth; 340 | } 341 | } 342 | } 343 | 344 | } 345 | #endif /* H264DEC_OMXDL */ 346 | 347 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /native/h264bsd_pic_param_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | h264bsdDecodePicParamSet 28 | 29 | ------------------------------------------------------------------------------*/ 30 | 31 | /*------------------------------------------------------------------------------ 32 | 1. Include headers 33 | ------------------------------------------------------------------------------*/ 34 | 35 | #include "h264bsd_pic_param_set.h" 36 | #include "h264bsd_util.h" 37 | #include "h264bsd_vlc.h" 38 | #include "h264bsd_cfg.h" 39 | 40 | /*------------------------------------------------------------------------------ 41 | 2. External compiler flags 42 | -------------------------------------------------------------------------------- 43 | 44 | -------------------------------------------------------------------------------- 45 | 3. Module defines 46 | ------------------------------------------------------------------------------*/ 47 | 48 | /* lookup table for ceil(log2(numSliceGroups)), i.e. number of bits needed to 49 | * represent range [0, numSliceGroups) 50 | * 51 | * NOTE: if MAX_NUM_SLICE_GROUPS is higher than 8 this table has to be resized 52 | * accordingly */ 53 | static const u32 CeilLog2NumSliceGroups[8] = {1, 1, 2, 2, 3, 3, 3, 3}; 54 | 55 | /*------------------------------------------------------------------------------ 56 | 4. Local function prototypes 57 | ------------------------------------------------------------------------------*/ 58 | 59 | /*------------------------------------------------------------------------------ 60 | 61 | Function name: h264bsdDecodePicParamSet 62 | 63 | Functional description: 64 | Decode picture parameter set information from the stream. 65 | 66 | Function allocates memory for 67 | - run lengths if slice group map type is 0 68 | - top-left and bottom-right arrays if map type is 2 69 | - for slice group ids if map type is 6 70 | 71 | Validity of some of the slice group mapping information depends 72 | on the image dimensions which are not known here. Therefore the 73 | validity has to be checked afterwards, currently in the parameter 74 | set activation phase. 75 | 76 | Inputs: 77 | pStrmData pointer to stream data structure 78 | 79 | Outputs: 80 | pPicParamSet decoded information is stored here 81 | 82 | Returns: 83 | HANTRO_OK success 84 | HANTRO_NOK failure, invalid information or end of stream 85 | MEMORY_ALLOCATION_ERROR for memory allocation failure 86 | 87 | 88 | ------------------------------------------------------------------------------*/ 89 | 90 | u32 h264bsdDecodePicParamSet(strmData_t *pStrmData, picParamSet_t *pPicParamSet) 91 | { 92 | 93 | /* Variables */ 94 | 95 | u32 tmp, i, value; 96 | i32 itmp; 97 | 98 | /* Code */ 99 | 100 | ASSERT(pStrmData); 101 | ASSERT(pPicParamSet); 102 | 103 | 104 | memset(pPicParamSet, 0, sizeof(picParamSet_t)); 105 | 106 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 107 | &pPicParamSet->picParameterSetId); 108 | if (tmp != HANTRO_OK) 109 | return(tmp); 110 | if (pPicParamSet->picParameterSetId >= MAX_NUM_PIC_PARAM_SETS) 111 | { 112 | EPRINT("pic_parameter_set_id"); 113 | return(HANTRO_NOK); 114 | } 115 | 116 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 117 | &pPicParamSet->seqParameterSetId); 118 | if (tmp != HANTRO_OK) 119 | return(tmp); 120 | if (pPicParamSet->seqParameterSetId >= MAX_NUM_SEQ_PARAM_SETS) 121 | { 122 | EPRINT("seq_param_set_id"); 123 | return(HANTRO_NOK); 124 | } 125 | 126 | /* entropy_coding_mode_flag, shall be 0 for baseline profile */ 127 | tmp = h264bsdGetBits(pStrmData, 1); 128 | if (tmp) 129 | { 130 | EPRINT("entropy_coding_mode_flag"); 131 | return(HANTRO_NOK); 132 | } 133 | 134 | tmp = h264bsdGetBits(pStrmData, 1); 135 | if (tmp == END_OF_STREAM) 136 | return(HANTRO_NOK); 137 | pPicParamSet->picOrderPresentFlag = (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 138 | 139 | /* num_slice_groups_minus1 */ 140 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 141 | if (tmp != HANTRO_OK) 142 | return(tmp); 143 | pPicParamSet->numSliceGroups = value + 1; 144 | if (pPicParamSet->numSliceGroups > MAX_NUM_SLICE_GROUPS) 145 | { 146 | EPRINT("num_slice_groups_minus1"); 147 | return(HANTRO_NOK); 148 | } 149 | 150 | /* decode slice group mapping information if more than one slice groups */ 151 | if (pPicParamSet->numSliceGroups > 1) 152 | { 153 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 154 | &pPicParamSet->sliceGroupMapType); 155 | if (tmp != HANTRO_OK) 156 | return(tmp); 157 | if (pPicParamSet->sliceGroupMapType > 6) 158 | { 159 | EPRINT("slice_group_map_type"); 160 | return(HANTRO_NOK); 161 | } 162 | 163 | if (pPicParamSet->sliceGroupMapType == 0) 164 | { 165 | ALLOCATE(pPicParamSet->runLength, 166 | pPicParamSet->numSliceGroups, u32); 167 | if (pPicParamSet->runLength == NULL) 168 | return(MEMORY_ALLOCATION_ERROR); 169 | for (i = 0; i < pPicParamSet->numSliceGroups; i++) 170 | { 171 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 172 | if (tmp != HANTRO_OK) 173 | return(tmp); 174 | pPicParamSet->runLength[i] = value+1; 175 | /* param values checked in CheckPps() */ 176 | } 177 | } 178 | else if (pPicParamSet->sliceGroupMapType == 2) 179 | { 180 | ALLOCATE(pPicParamSet->topLeft, 181 | pPicParamSet->numSliceGroups - 1, u32); 182 | ALLOCATE(pPicParamSet->bottomRight, 183 | pPicParamSet->numSliceGroups - 1, u32); 184 | if (pPicParamSet->topLeft == NULL || 185 | pPicParamSet->bottomRight == NULL) 186 | return(MEMORY_ALLOCATION_ERROR); 187 | for (i = 0; i < pPicParamSet->numSliceGroups - 1; i++) 188 | { 189 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 190 | if (tmp != HANTRO_OK) 191 | return(tmp); 192 | pPicParamSet->topLeft[i] = value; 193 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 194 | if (tmp != HANTRO_OK) 195 | return(tmp); 196 | pPicParamSet->bottomRight[i] = value; 197 | /* param values checked in CheckPps() */ 198 | } 199 | } 200 | else if ( (pPicParamSet->sliceGroupMapType == 3) || 201 | (pPicParamSet->sliceGroupMapType == 4) || 202 | (pPicParamSet->sliceGroupMapType == 5) ) 203 | { 204 | tmp = h264bsdGetBits(pStrmData, 1); 205 | if (tmp == END_OF_STREAM) 206 | return(HANTRO_NOK); 207 | pPicParamSet->sliceGroupChangeDirectionFlag = 208 | (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 209 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 210 | if (tmp != HANTRO_OK) 211 | return(tmp); 212 | pPicParamSet->sliceGroupChangeRate = value + 1; 213 | /* param value checked in CheckPps() */ 214 | } 215 | else if (pPicParamSet->sliceGroupMapType == 6) 216 | { 217 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 218 | if (tmp != HANTRO_OK) 219 | return(tmp); 220 | pPicParamSet->picSizeInMapUnits = value + 1; 221 | 222 | ALLOCATE(pPicParamSet->sliceGroupId, 223 | pPicParamSet->picSizeInMapUnits, u32); 224 | if (pPicParamSet->sliceGroupId == NULL) 225 | return(MEMORY_ALLOCATION_ERROR); 226 | 227 | /* determine number of bits needed to represent range 228 | * [0, numSliceGroups) */ 229 | tmp = CeilLog2NumSliceGroups[pPicParamSet->numSliceGroups-1]; 230 | 231 | for (i = 0; i < pPicParamSet->picSizeInMapUnits; i++) 232 | { 233 | pPicParamSet->sliceGroupId[i] = h264bsdGetBits(pStrmData, tmp); 234 | if ( pPicParamSet->sliceGroupId[i] >= 235 | pPicParamSet->numSliceGroups ) 236 | { 237 | EPRINT("slice_group_id"); 238 | return(HANTRO_NOK); 239 | } 240 | } 241 | } 242 | } 243 | 244 | /* num_ref_idx_l0_active_minus1 */ 245 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 246 | if (tmp != HANTRO_OK) 247 | return(tmp); 248 | if (value > 31) 249 | { 250 | EPRINT("num_ref_idx_l0_active_minus1"); 251 | return(HANTRO_NOK); 252 | } 253 | pPicParamSet->numRefIdxL0Active = value + 1; 254 | 255 | /* num_ref_idx_l1_active_minus1 */ 256 | tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 257 | if (tmp != HANTRO_OK) 258 | return(tmp); 259 | if (value > 31) 260 | { 261 | EPRINT("num_ref_idx_l1_active_minus1"); 262 | return(HANTRO_NOK); 263 | } 264 | 265 | /* weighted_pred_flag, this shall be 0 for baseline profile */ 266 | tmp = h264bsdGetBits(pStrmData, 1); 267 | if (tmp) 268 | { 269 | EPRINT("weighted_pred_flag"); 270 | return(HANTRO_NOK); 271 | } 272 | 273 | /* weighted_bipred_idc */ 274 | tmp = h264bsdGetBits(pStrmData, 2); 275 | if (tmp > 2) 276 | { 277 | EPRINT("weighted_bipred_idc"); 278 | return(HANTRO_NOK); 279 | } 280 | 281 | /* pic_init_qp_minus26 */ 282 | tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 283 | if (tmp != HANTRO_OK) 284 | return(tmp); 285 | if ((itmp < -26) || (itmp > 25)) 286 | { 287 | EPRINT("pic_init_qp_minus26"); 288 | return(HANTRO_NOK); 289 | } 290 | pPicParamSet->picInitQp = (u32)(itmp + 26); 291 | 292 | /* pic_init_qs_minus26 */ 293 | tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 294 | if (tmp != HANTRO_OK) 295 | return(tmp); 296 | if ((itmp < -26) || (itmp > 25)) 297 | { 298 | EPRINT("pic_init_qs_minus26"); 299 | return(HANTRO_NOK); 300 | } 301 | 302 | tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 303 | if (tmp != HANTRO_OK) 304 | return(tmp); 305 | if ((itmp < -12) || (itmp > 12)) 306 | { 307 | EPRINT("chroma_qp_index_offset"); 308 | return(HANTRO_NOK); 309 | } 310 | pPicParamSet->chromaQpIndexOffset = itmp; 311 | 312 | tmp = h264bsdGetBits(pStrmData, 1); 313 | if (tmp == END_OF_STREAM) 314 | return(HANTRO_NOK); 315 | pPicParamSet->deblockingFilterControlPresentFlag = 316 | (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 317 | 318 | tmp = h264bsdGetBits(pStrmData, 1); 319 | if (tmp == END_OF_STREAM) 320 | return(HANTRO_NOK); 321 | pPicParamSet->constrainedIntraPredFlag = (tmp == 1) ? 322 | HANTRO_TRUE : HANTRO_FALSE; 323 | 324 | tmp = h264bsdGetBits(pStrmData, 1); 325 | if (tmp == END_OF_STREAM) 326 | return(HANTRO_NOK); 327 | pPicParamSet->redundantPicCntPresentFlag = (tmp == 1) ? 328 | HANTRO_TRUE : HANTRO_FALSE; 329 | 330 | tmp = h264bsdRbspTrailingBits(pStrmData); 331 | 332 | /* ignore possible errors in trailing bits of parameters sets */ 333 | return(HANTRO_OK); 334 | 335 | } 336 | 337 | -------------------------------------------------------------------------------- /native/h264bsd_neighbour.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * Modified for use by h264bsd standalone library 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /*------------------------------------------------------------------------------ 19 | 20 | Table of contents 21 | 22 | 1. Include headers 23 | 2. External compiler flags 24 | 3. Module defines 25 | 4. Local function prototypes 26 | 5. Functions 27 | h264bsdInitMbNeighbours 28 | h264bsdGetNeighbourMb 29 | h264bsdNeighbour4x4BlockA 30 | h264bsdNeighbour4x4BlockB 31 | h264bsdNeighbour4x4BlockC 32 | h264bsdNeighbour4x4BlockD 33 | 34 | ------------------------------------------------------------------------------*/ 35 | 36 | /*------------------------------------------------------------------------------ 37 | 1. Include headers 38 | ------------------------------------------------------------------------------*/ 39 | 40 | #include "h264bsd_neighbour.h" 41 | #include "h264bsd_util.h" 42 | 43 | /*------------------------------------------------------------------------------ 44 | 2. External compiler flags 45 | -------------------------------------------------------------------------------- 46 | 47 | -------------------------------------------------------------------------------- 48 | 3. Module defines 49 | ------------------------------------------------------------------------------*/ 50 | 51 | /* Following four tables indicate neighbours of each block of a macroblock. 52 | * First 16 values are for luma blocks, next 4 values for Cb and last 4 53 | * values for Cr. Elements of the table indicate to which macroblock the 54 | * neighbour block belongs and the index of the neighbour block in question. 55 | * Indexing of the blocks goes as follows 56 | * 57 | * Y Cb Cr 58 | * 0 1 4 5 16 17 20 21 59 | * 2 3 6 7 18 19 22 23 60 | * 8 9 12 13 61 | * 10 11 14 15 62 | */ 63 | 64 | /* left neighbour for each block */ 65 | static const neighbour_t N_A_4x4B[24] = { 66 | {MB_A,5}, {MB_CURR,0}, {MB_A,7}, {MB_CURR,2}, 67 | {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6}, 68 | {MB_A,13}, {MB_CURR,8}, {MB_A,15}, {MB_CURR,10}, 69 | {MB_CURR,9}, {MB_CURR,12},{MB_CURR,11},{MB_CURR,14}, 70 | {MB_A,17}, {MB_CURR,16},{MB_A,19}, {MB_CURR,18}, 71 | {MB_A,21}, {MB_CURR,20},{MB_A,23}, {MB_CURR,22} }; 72 | 73 | /* above neighbour for each block */ 74 | static const neighbour_t N_B_4x4B[24] = { 75 | {MB_B,10}, {MB_B,11}, {MB_CURR,0}, {MB_CURR,1}, 76 | {MB_B,14}, {MB_B,15}, {MB_CURR,4}, {MB_CURR,5}, 77 | {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9}, 78 | {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12},{MB_CURR,13}, 79 | {MB_B,18}, {MB_B,19}, {MB_CURR,16},{MB_CURR,17}, 80 | {MB_B,22}, {MB_B,23}, {MB_CURR,20},{MB_CURR,21} }; 81 | 82 | /* above-right neighbour for each block */ 83 | static const neighbour_t N_C_4x4B[24] = { 84 | {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_NA,4}, 85 | {MB_B,15}, {MB_C,10}, {MB_CURR,5}, {MB_NA,0}, 86 | {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12}, 87 | {MB_CURR,7}, {MB_NA,2}, {MB_CURR,13},{MB_NA,8}, 88 | {MB_B,19}, {MB_C,18}, {MB_CURR,17},{MB_NA,16}, 89 | {MB_B,23}, {MB_C,22}, {MB_CURR,21},{MB_NA,20} }; 90 | 91 | /* above-left neighbour for each block */ 92 | static const neighbour_t N_D_4x4B[24] = { 93 | {MB_D,15}, {MB_B,10}, {MB_A,5}, {MB_CURR,0}, 94 | {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_CURR,4}, 95 | {MB_A,7}, {MB_CURR,2}, {MB_A,13}, {MB_CURR,8}, 96 | {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12}, 97 | {MB_D,19}, {MB_B,18}, {MB_A,17}, {MB_CURR,16}, 98 | {MB_D,23}, {MB_B,22}, {MB_A,21}, {MB_CURR,20} }; 99 | 100 | /*------------------------------------------------------------------------------ 101 | 4. Local function prototypes 102 | ------------------------------------------------------------------------------*/ 103 | 104 | /*------------------------------------------------------------------------------ 105 | 106 | Function: h264bsdInitMbNeighbours 107 | 108 | Functional description: 109 | Initialize macroblock neighbours. Function sets neighbour 110 | macroblock pointers in macroblock structures to point to 111 | macroblocks on the left, above, above-right and above-left. 112 | Pointers are set NULL if the neighbour does not fit into the 113 | picture. 114 | 115 | Inputs: 116 | picWidth width of the picture in macroblocks 117 | picSizeInMbs no need to clarify 118 | 119 | Outputs: 120 | pMbStorage neighbour pointers of each mbStorage structure 121 | stored here 122 | 123 | Returns: 124 | none 125 | 126 | ------------------------------------------------------------------------------*/ 127 | 128 | void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth, 129 | u32 picSizeInMbs) 130 | { 131 | 132 | /* Variables */ 133 | 134 | u32 i, row, col; 135 | 136 | /* Code */ 137 | 138 | ASSERT(pMbStorage); 139 | ASSERT(picWidth); 140 | ASSERT(picWidth <= picSizeInMbs); 141 | ASSERT(((picSizeInMbs / picWidth) * picWidth) == picSizeInMbs); 142 | 143 | row = col = 0; 144 | 145 | for (i = 0; i < picSizeInMbs; i++) 146 | { 147 | 148 | if (col) 149 | pMbStorage[i].mbA = pMbStorage + i - 1; 150 | else 151 | pMbStorage[i].mbA = NULL; 152 | 153 | if (row) 154 | pMbStorage[i].mbB = pMbStorage + i - picWidth; 155 | else 156 | pMbStorage[i].mbB = NULL; 157 | 158 | if (row && (col < picWidth - 1)) 159 | pMbStorage[i].mbC = pMbStorage + i - (picWidth - 1); 160 | else 161 | pMbStorage[i].mbC = NULL; 162 | 163 | if (row && col) 164 | pMbStorage[i].mbD = pMbStorage + i - (picWidth + 1); 165 | else 166 | pMbStorage[i].mbD = NULL; 167 | 168 | col++; 169 | if (col == picWidth) 170 | { 171 | col = 0; 172 | row++; 173 | } 174 | } 175 | 176 | } 177 | 178 | /*------------------------------------------------------------------------------ 179 | 180 | Function: h264bsdGetNeighbourMb 181 | 182 | Functional description: 183 | Get pointer to neighbour macroblock. 184 | 185 | Inputs: 186 | pMb pointer to macroblock structure of the macroblock 187 | whose neighbour is wanted 188 | neighbour indicates which neighbour is wanted 189 | 190 | Outputs: 191 | none 192 | 193 | Returns: 194 | pointer to neighbour macroblock 195 | NULL if not available 196 | 197 | ------------------------------------------------------------------------------*/ 198 | 199 | mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour) 200 | { 201 | 202 | /* Variables */ 203 | 204 | 205 | /* Code */ 206 | 207 | ASSERT((neighbour <= MB_CURR) || (neighbour == MB_NA)); 208 | 209 | if (neighbour == MB_A) 210 | return(pMb->mbA); 211 | else if (neighbour == MB_B) 212 | return(pMb->mbB); 213 | else if (neighbour == MB_C) 214 | return(pMb->mbC); 215 | else if (neighbour == MB_D) 216 | return(pMb->mbD); 217 | else if (neighbour == MB_CURR) 218 | return(pMb); 219 | else 220 | return(NULL); 221 | 222 | } 223 | 224 | /*------------------------------------------------------------------------------ 225 | 226 | Function: h264bsdNeighbour4x4BlockA 227 | 228 | Functional description: 229 | Get left neighbour of the block. Function returns pointer to 230 | the table defined in the beginning of the file. 231 | 232 | Inputs: 233 | blockIndex indicates the block whose neighbours are wanted 234 | 235 | Outputs: 236 | 237 | Returns: 238 | pointer to neighbour structure 239 | 240 | ------------------------------------------------------------------------------*/ 241 | 242 | const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex) 243 | { 244 | 245 | /* Variables */ 246 | 247 | /* Code */ 248 | 249 | ASSERT(blockIndex < 24); 250 | 251 | return(N_A_4x4B+blockIndex); 252 | 253 | } 254 | 255 | /*------------------------------------------------------------------------------ 256 | 257 | Function: h264bsdNeighbour4x4BlockB 258 | 259 | Functional description: 260 | Get above neighbour of the block. Function returns pointer to 261 | the table defined in the beginning of the file. 262 | 263 | Inputs: 264 | blockIndex indicates the block whose neighbours are wanted 265 | 266 | Outputs: 267 | 268 | Returns: 269 | pointer to neighbour structure 270 | 271 | ------------------------------------------------------------------------------*/ 272 | 273 | const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex) 274 | { 275 | 276 | /* Variables */ 277 | 278 | /* Code */ 279 | 280 | ASSERT(blockIndex < 24); 281 | 282 | return(N_B_4x4B+blockIndex); 283 | 284 | } 285 | 286 | /*------------------------------------------------------------------------------ 287 | 288 | Function: h264bsdNeighbour4x4BlockC 289 | 290 | Functional description: 291 | Get above-right neighbour of the block. Function returns pointer 292 | to the table defined in the beginning of the file. 293 | 294 | Inputs: 295 | blockIndex indicates the block whose neighbours are wanted 296 | 297 | Outputs: 298 | 299 | Returns: 300 | pointer to neighbour structure 301 | 302 | ------------------------------------------------------------------------------*/ 303 | 304 | const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex) 305 | { 306 | 307 | /* Variables */ 308 | 309 | /* Code */ 310 | 311 | ASSERT(blockIndex < 24); 312 | 313 | return(N_C_4x4B+blockIndex); 314 | 315 | } 316 | 317 | /*------------------------------------------------------------------------------ 318 | 319 | Function: h264bsdNeighbour4x4BlockD 320 | 321 | Functional description: 322 | Get above-left neighbour of the block. Function returns pointer to 323 | the table defined in the beginning of the file. 324 | 325 | Inputs: 326 | blockIndex indicates the block whose neighbours are wanted 327 | 328 | Outputs: 329 | 330 | Returns: 331 | pointer to neighbour structure 332 | 333 | ------------------------------------------------------------------------------*/ 334 | 335 | const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex) 336 | { 337 | 338 | /* Variables */ 339 | 340 | /* Code */ 341 | 342 | ASSERT(blockIndex < 24); 343 | 344 | return(N_D_4x4B+blockIndex); 345 | 346 | } 347 | 348 | /*------------------------------------------------------------------------------ 349 | 350 | Function: h264bsdIsNeighbourAvailable 351 | 352 | Functional description: 353 | Check if neighbour macroblock is available. Neighbour macroblock 354 | is considered available if it is within the picture and belongs 355 | to the same slice as the current macroblock. 356 | 357 | Inputs: 358 | pMb pointer to the current macroblock 359 | pNeighbour pointer to the neighbour macroblock 360 | 361 | Outputs: 362 | none 363 | 364 | Returns: 365 | TRUE neighbour is available 366 | FALSE neighbour is not available 367 | 368 | ------------------------------------------------------------------------------*/ 369 | 370 | u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour) 371 | { 372 | 373 | /* Variables */ 374 | 375 | /* Code */ 376 | 377 | if ( (pNeighbour == NULL) || (pMb->sliceId != pNeighbour->sliceId) ) 378 | return(HANTRO_FALSE); 379 | else 380 | return(HANTRO_TRUE); 381 | 382 | } 383 | 384 | --------------------------------------------------------------------------------