├── .gitignore
├── AndroidManifest.xml
├── LICENSE
├── README.md
├── ant.properties
├── assets
├── css
│ ├── fonts
│ │ ├── glyphicons-halflings-regular.eot
│ │ ├── glyphicons-halflings-regular.svg
│ │ ├── glyphicons-halflings-regular.ttf
│ │ └── glyphicons-halflings-regular.woff
│ ├── lib
│ │ ├── bootstrap-theme.min.css
│ │ ├── bootstrap.min.css
│ │ └── jquery.nouislider.css
│ └── mystyle.css
├── favicon.ico
├── img
│ ├── github.png
│ ├── logo.png
│ └── phone.png
├── index.html
└── js
│ ├── adpcm.js
│ ├── avc
│ ├── avc.js
│ ├── util.js
│ └── yuv2rgb.js
│ ├── emscripten
│ └── module.js
│ ├── lib
│ ├── base64.js
│ ├── bootstrap.min.js
│ └── jquery.min.js
│ ├── main.js
│ ├── media.js
│ └── player.js
├── ems
├── avc-inc
│ ├── H264SwDecApi.h
│ └── basetype.h
├── avc.bc
├── avc
│ ├── Broadway.c
│ ├── DecTestBench.c
│ ├── Decoder.c
│ ├── EvaluationTestBench.x
│ ├── H264SwDecApi.c
│ ├── TestBenchMultipleInstance.x
│ ├── h264bsd_byte_stream.c
│ ├── h264bsd_byte_stream.h
│ ├── h264bsd_cavlc.c
│ ├── h264bsd_cavlc.h
│ ├── h264bsd_cfg.h
│ ├── h264bsd_conceal.c
│ ├── h264bsd_conceal.h
│ ├── h264bsd_container.h
│ ├── h264bsd_deblocking.c
│ ├── h264bsd_deblocking.h
│ ├── h264bsd_decoder.c
│ ├── h264bsd_decoder.h
│ ├── h264bsd_dpb.c
│ ├── h264bsd_dpb.h
│ ├── h264bsd_image.c
│ ├── h264bsd_image.h
│ ├── h264bsd_inter_prediction.c
│ ├── h264bsd_inter_prediction.h
│ ├── h264bsd_intra_prediction.c
│ ├── h264bsd_intra_prediction.h
│ ├── h264bsd_macroblock_layer.c
│ ├── h264bsd_macroblock_layer.h
│ ├── h264bsd_nal_unit.c
│ ├── h264bsd_nal_unit.h
│ ├── h264bsd_neighbour.c
│ ├── h264bsd_neighbour.h
│ ├── h264bsd_pic_order_cnt.c
│ ├── h264bsd_pic_order_cnt.h
│ ├── h264bsd_pic_param_set.c
│ ├── h264bsd_pic_param_set.h
│ ├── h264bsd_reconstruct.c
│ ├── h264bsd_reconstruct.h
│ ├── h264bsd_sei.c
│ ├── h264bsd_sei.h
│ ├── h264bsd_seq_param_set.c
│ ├── h264bsd_seq_param_set.h
│ ├── h264bsd_slice_data.c
│ ├── h264bsd_slice_data.h
│ ├── h264bsd_slice_group_map.c
│ ├── h264bsd_slice_group_map.h
│ ├── h264bsd_slice_header.c
│ ├── h264bsd_slice_header.h
│ ├── h264bsd_storage.c
│ ├── h264bsd_storage.h
│ ├── h264bsd_stream.c
│ ├── h264bsd_stream.h
│ ├── h264bsd_transform.c
│ ├── h264bsd_transform.h
│ ├── h264bsd_util.c
│ ├── h264bsd_util.h
│ ├── h264bsd_vlc.c
│ ├── h264bsd_vlc.h
│ ├── h264bsd_vui.c
│ └── h264bsd_vui.h
├── g72x
│ ├── adpcm_js.c
│ ├── g711.c
│ ├── g726_16.c
│ ├── g726_24.c
│ ├── g726_32.c
│ ├── g726_40.c
│ ├── g72x.c
│ ├── g72x.h
│ └── private.h
├── js
│ └── native_module.js
├── library.js
├── make.py
└── obj
│ ├── avc
│ ├── Decoder.o
│ ├── H264SwDecApi.o
│ ├── h264bsd_byte_stream.o
│ ├── h264bsd_cavlc.o
│ ├── h264bsd_conceal.o
│ ├── h264bsd_deblocking.o
│ ├── h264bsd_decoder.o
│ ├── h264bsd_dpb.o
│ ├── h264bsd_image.o
│ ├── h264bsd_inter_prediction.o
│ ├── h264bsd_intra_prediction.o
│ ├── h264bsd_macroblock_layer.o
│ ├── h264bsd_nal_unit.o
│ ├── h264bsd_neighbour.o
│ ├── h264bsd_pic_order_cnt.o
│ ├── h264bsd_pic_param_set.o
│ ├── h264bsd_reconstruct.o
│ ├── h264bsd_seq_param_set.o
│ ├── h264bsd_slice_data.o
│ ├── h264bsd_slice_group_map.o
│ ├── h264bsd_slice_header.o
│ ├── h264bsd_storage.o
│ ├── h264bsd_stream.o
│ ├── h264bsd_transform.o
│ ├── h264bsd_util.o
│ ├── h264bsd_vlc.o
│ └── h264bsd_vui.o
│ └── g72x
│ ├── adpcm_js.o
│ ├── g711.o
│ ├── g726_32.o
│ └── g72x.o
├── jni
├── Android.mk
├── Application.mk
├── build_x264.md
├── g72x
│ ├── adpcm_js.c
│ ├── g711.c
│ ├── g726_16.c
│ ├── g726_24.c
│ ├── g726_32.c
│ ├── g726_40.c
│ ├── g72x.c
│ ├── g72x.h
│ └── private.h
├── h264encoder.cpp
├── h264encoder.h
├── helper.h
└── main_jni.cpp
├── libs
└── java_websocket.jar
├── project.properties
├── res
├── drawable
│ └── icon.png
├── layout
│ └── main.xml
└── values
│ └── strings.xml
└── src
└── teaonly
└── droideye
├── CameraView.java
├── MainActivity.java
├── MediaBlock.java
├── NanoHTTPD.java
├── OverlayView.java
└── TeaServer.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | android-eye
2 | ===========
3 |
4 | Change your android phone to a surveillance security camera.
5 |
6 | ## Download ##
7 | You can download binrary from Google Play:
8 | https://play.google.com/store/apps/details?id=teaonly.droideye
9 |
10 | ## Specifications ##
11 | * Streaming
12 | * Build-in web service, you can see the video via browser in pc and another phone, a modem browser with HTML5 is reauired.
13 | * H.264 video and G.726 audio
14 | * Streaming via websocket between browser and android phone.
15 | * Decoding H.264 and G.726 in pure Javascript
16 |
17 | * Smart
18 | * Support motion detecting (doing)
19 | * Support advanced vision algorithms (doing)
20 | * Publishing alarm messages to SNS (not ready)
21 |
22 | * Access over internet
23 | * This app don't support internet, you can try my another app:
24 | https://play.google.com/store/apps/details?id=com.yacamera.p2p
25 |
26 | ## License and third party libraries
27 | * License GPL v2
28 | * X.264 : git://git.videolan.org/x264.git
29 | * Java Websocket library : https://github.com/TooTallNate/Java-WebSocket
30 | * H.264 javascript decoder: https://github.com/mbebenita/Broadway
31 |
32 | ## Update ##
33 | * 2014-10-10 Refine project with new specifications.
34 |
35 | ... (打酱油) ...
36 |
37 | * 2012-10-30 Finished audio support.
38 | * 2012-10-28 Fixed small bugs, added audio flash player in Web page.
39 | * 2012-10-18 Bugs fixed, supported IE, Firefox and Chrome.
40 | * 2012-08-04 Multiple jpeg streaming is OK, basic framework is OK.
41 | * 2012-07-26 creating project.
42 |
--------------------------------------------------------------------------------
/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 | key.store=/Users/teaonly/opt/mykey/androidrelease.keystore
18 | key.alias=teaonly
19 |
--------------------------------------------------------------------------------
/assets/css/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/css/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/assets/css/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/css/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/assets/css/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/css/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/assets/css/lib/jquery.nouislider.css:
--------------------------------------------------------------------------------
1 |
2 | /* Functional styling;
3 | * These styles are required for noUiSlider to function.
4 | * You don't need to change these rules to apply your design.
5 | */
6 | .noUi-target,
7 | .noUi-target * {
8 | -webkit-touch-callout: none;
9 | -webkit-user-select: none;
10 | -ms-touch-action: none;
11 | -ms-user-select: none;
12 | -moz-user-select: none;
13 | -moz-box-sizing: border-box;
14 | box-sizing: border-box;
15 | }
16 | .noUi-base {
17 | width: 100%;
18 | height: 100%;
19 | position: relative;
20 | }
21 | .noUi-origin {
22 | position: absolute;
23 | right: 0;
24 | top: 0;
25 | left: 0;
26 | bottom: 0;
27 | }
28 | .noUi-handle {
29 | position: relative;
30 | z-index: 1;
31 | }
32 | .noUi-stacking .noUi-handle {
33 | /* This class is applied to the lower origin when
34 | its values is > 50%. */
35 | z-index: 10;
36 | }
37 | .noUi-stacking + .noUi-origin {
38 | /* Fix stacking order in IE7, which incorrectly
39 | creates a new context for the origins. */
40 | *z-index: -1;
41 | }
42 | .noUi-state-tap .noUi-origin {
43 | -webkit-transition: left 0.3s, top 0.3s;
44 | transition: left 0.3s, top 0.3s;
45 | }
46 | .noUi-state-drag * {
47 | cursor: inherit !important;
48 | }
49 |
50 | /* Slider size and handle placement;
51 | */
52 | .noUi-horizontal {
53 | height: 18px;
54 | }
55 | .noUi-horizontal .noUi-handle {
56 | width: 34px;
57 | height: 28px;
58 | left: -17px;
59 | top: -6px;
60 | }
61 | .noUi-horizontal.noUi-extended {
62 | padding: 0 15px;
63 | }
64 | .noUi-horizontal.noUi-extended .noUi-origin {
65 | right: -15px;
66 | }
67 | .noUi-vertical {
68 | width: 18px;
69 | }
70 | .noUi-vertical .noUi-handle {
71 | width: 28px;
72 | height: 34px;
73 | left: -6px;
74 | top: -17px;
75 | }
76 | .noUi-vertical.noUi-extended {
77 | padding: 15px 0;
78 | }
79 | .noUi-vertical.noUi-extended .noUi-origin {
80 | bottom: -15px;
81 | }
82 |
83 | /* Styling;
84 | */
85 | .noUi-background {
86 | background: #FAFAFA;
87 | box-shadow: inset 0 1px 1px #f0f0f0;
88 | }
89 | .noUi-connect {
90 | background: #3FB8AF;
91 | box-shadow: inset 0 0 3px rgba(51,51,51,0.45);
92 | -webkit-transition: background 450ms;
93 | transition: background 450ms;
94 | }
95 | .noUi-origin {
96 | border-radius: 2px;
97 | }
98 | .noUi-target {
99 | border-radius: 4px;
100 | border: 1px solid #D3D3D3;
101 | box-shadow: inset 0 1px 1px #F0F0F0, 0 3px 6px -5px #BBB;
102 | }
103 | .noUi-target.noUi-connect {
104 | box-shadow: inset 0 0 3px rgba(51,51,51,0.45), 0 3px 6px -5px #BBB;
105 | }
106 |
107 | /* Handles and cursors;
108 | */
109 | .noUi-dragable {
110 | cursor: w-resize;
111 | }
112 | .noUi-vertical .noUi-dragable {
113 | cursor: n-resize;
114 | }
115 | .noUi-handle {
116 | border: 1px solid #D9D9D9;
117 | border-radius: 3px;
118 | background: #FFF;
119 | cursor: default;
120 | box-shadow: inset 0 0 1px #FFF,
121 | inset 0 1px 7px #EBEBEB,
122 | 0 3px 6px -3px #BBB;
123 | }
124 | .noUi-active {
125 | box-shadow: inset 0 0 1px #FFF,
126 | inset 0 1px 7px #DDD,
127 | 0 3px 6px -3px #BBB;
128 | }
129 |
130 | /* Handle stripes;
131 | */
132 | .noUi-handle:before,
133 | .noUi-handle:after {
134 | content: "";
135 | display: block;
136 | position: absolute;
137 | height: 14px;
138 | width: 1px;
139 | background: #E8E7E6;
140 | left: 14px;
141 | top: 6px;
142 | }
143 | .noUi-handle:after {
144 | left: 17px;
145 | }
146 | .noUi-vertical .noUi-handle:before,
147 | .noUi-vertical .noUi-handle:after {
148 | width: 14px;
149 | height: 1px;
150 | left: 6px;
151 | top: 14px;
152 | }
153 | .noUi-vertical .noUi-handle:after {
154 | top: 17px;
155 | }
156 |
157 | /* Disabled state;
158 | */
159 | [disabled].noUi-connect,
160 | [disabled] .noUi-connect {
161 | background: #B8B8B8;
162 | }
163 | [disabled] .noUi-handle {
164 | cursor: not-allowed;
165 | }
166 |
--------------------------------------------------------------------------------
/assets/css/mystyle.css:
--------------------------------------------------------------------------------
1 | html {
2 | display: table;
3 | margin: auto;
4 | }
5 |
6 | body {
7 | display: table-cell;
8 | vertical-align: middle;
9 | margin: 0px, auto;
10 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
11 | }
12 |
13 | #mainform{
14 | padding: 0px;
15 | margin: 0px;
16 | width: 700px;
17 | }
18 |
19 | .page-header {
20 | margin-top: 5px;
21 | margin-bottom: 0px;
22 | }
23 |
24 | h1.logo {
25 | color: #0000AA;
26 | font-weight: bolder;
27 | margin-top: 10px;
28 | margin-bottom: 3px;
29 | }
30 |
31 | .install {
32 | float: right;
33 | margin-top: -35px;
34 | }
35 |
36 |
37 |
38 | .video-container {
39 | box-sizing: border-box;
40 | margin-top: -35px;
41 | }
42 |
43 | div.video-player {
44 | position: relative;
45 | margin-top: 15px;
46 | margin-left: 30px;
47 | }
48 | img.video-player {
49 | position: absolute;
50 | margin-top: 35px;
51 | width: 640px;
52 | height: 360px;
53 | }
54 | canvas.video-player {
55 | background: black;
56 | position: absolute;
57 | margin-top: 35px;
58 | width: 480px;
59 | height: 290px;
60 | left: 68px;
61 | top: 35px;
62 | }
63 |
64 | .video-controls {
65 | text-align: center;
66 | margin-top: 400px;
67 | }
68 |
69 | .span-info {
70 | color: #555555;
71 | font-size: small;
72 | margin-top: 2px;
73 | margin-bottom: 2px;
74 | }
75 |
--------------------------------------------------------------------------------
/assets/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/favicon.ico
--------------------------------------------------------------------------------
/assets/img/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/img/github.png
--------------------------------------------------------------------------------
/assets/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/img/logo.png
--------------------------------------------------------------------------------
/assets/img/phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/assets/img/phone.png
--------------------------------------------------------------------------------
/assets/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Wifi Camera - Make your android phone to a security camera.
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
30 |
31 |
32 |
33 |
34 |

35 |
36 |
37 |
38 |
39 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/assets/js/adpcm.js:
--------------------------------------------------------------------------------
1 | function AdpcmDecoder() {
2 | this._inMemory = Module._malloc(1024*128);
3 | this._outMemory = Module._malloc(1024*128);
4 |
5 | this.doDecode = function(inBuffer) {
6 | Module.HEAPU8.set(inBuffer, this._inMemory);
7 | var ret = Module._adpcmDecode(this._inMemory, inBuffer.length, this._outMemory);
8 | return Module.HEAPU8.subarray(this._outMemory, this._outMemory + ret * 2);
9 | }.bind(this);
10 |
11 | this.release = function() {
12 | Module._free(this._inMemory);
13 | Module._free(this._outMemory);
14 | }.bind(this);
15 | };
16 |
--------------------------------------------------------------------------------
/assets/js/avc/util.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function error(message) {
4 | console.error(message);
5 | console.trace();
6 | }
7 |
8 | function assert(condition, message) {
9 | if (!condition) {
10 | error(message);
11 | }
12 | }
13 |
14 | function isPowerOfTwo(x) {
15 | return (x & (x - 1)) == 0;
16 | }
17 |
18 | /**
19 | * Joins a list of lines using a newline separator, not the fastest
20 | * thing in the world but good enough for initialization code.
21 | */
22 | function text(lines) {
23 | return lines.join("\n");
24 | }
25 |
26 | /**
27 | * Rounds up to the next highest power of two.
28 | */
29 | function nextHighestPowerOfTwo(x) {
30 | --x;
31 | for (var i = 1; i < 32; i <<= 1) {
32 | x = x | x >> i;
33 | }
34 | return x + 1;
35 | }
36 |
37 | /**
38 | * Represents a 2-dimensional size value.
39 | */
40 | var Size = (function size() {
41 | function constructor(w, h) {
42 | this.w = w;
43 | this.h = h;
44 | }
45 | constructor.prototype = {
46 | toString: function () {
47 | return "(" + this.w + ", " + this.h + ")";
48 | },
49 | getHalfSize: function() {
50 | return new Size(this.w >>> 1, this.h >>> 1);
51 | },
52 | length: function() {
53 | return this.w * this.h;
54 | }
55 | }
56 | return constructor;
57 | })();
58 |
59 | /**
60 | * Creates a new prototype object derived from another objects prototype along with a list of additional properties.
61 | *
62 | * @param base object whose prototype to use as the created prototype object's prototype
63 | * @param properties additional properties to add to the created prototype object
64 | */
65 | function inherit(base, properties) {
66 | var prot = Object.create(base.prototype);
67 | for (var p in properties) {
68 | prot[p] = properties[p];
69 | }
70 | return prot;
71 | }
--------------------------------------------------------------------------------
/assets/js/avc/yuv2rgb.js:
--------------------------------------------------------------------------------
1 | var yuv2ImageData = function(yuv, imageData) {
2 | var width = imageData.width;
3 | var height = imageData.height;
4 | var outputData = imageData.data;
5 |
6 | yOffset = 0;
7 | uOffset = width * height;
8 | vOffset = width * height + (width*height)/4;
9 | for (var h=0; h>1) + (h>>1) * width/2 + uOffset;
14 | vpos = (w>>1) + (h>>1) * width/2 + vOffset;
15 |
16 | Y = yuv[ypos];
17 | U = yuv[upos] - 128;
18 | V = yuv[vpos] - 128;
19 |
20 | R = (Y + 1.371*V);
21 | G = (Y - 0.698*V - 0.336*U);
22 | B = (Y + 1.732*U);
23 |
24 | outputData_pos = w*4 + width*h*4;
25 | outputData[0+outputData_pos] = R;
26 | outputData[1+outputData_pos] = G;
27 | outputData[2+outputData_pos] = B;
28 | outputData[3+outputData_pos] = 255;
29 | }
30 | }
31 | };
32 |
--------------------------------------------------------------------------------
/assets/js/lib/base64.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Base64 encode / decode
4 | * http://www.webtoolkit.info/
5 | *
6 | **/
7 | var Base64 = {
8 |
9 | // private property
10 | _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
11 |
12 | // public method for encoding
13 | encode : function (input) {
14 | var output = "";
15 | var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
16 | var i = 0;
17 |
18 | input = Base64._utf8_encode(input);
19 |
20 | while (i < input.length) {
21 |
22 | chr1 = input.charCodeAt(i++);
23 | chr2 = input.charCodeAt(i++);
24 | chr3 = input.charCodeAt(i++);
25 |
26 | enc1 = chr1 >> 2;
27 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
28 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
29 | enc4 = chr3 & 63;
30 |
31 | if (isNaN(chr2)) {
32 | enc3 = enc4 = 64;
33 | } else if (isNaN(chr3)) {
34 | enc4 = 64;
35 | }
36 |
37 | output = output +
38 | this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
39 | this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
40 |
41 | }
42 |
43 | return output;
44 | },
45 |
46 | // public method for decoding
47 | decode : function (input) {
48 | var output = "";
49 | var chr1, chr2, chr3;
50 | var enc1, enc2, enc3, enc4;
51 | var i = 0;
52 |
53 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
54 |
55 | while (i < input.length) {
56 |
57 | enc1 = this._keyStr.indexOf(input.charAt(i++));
58 | enc2 = this._keyStr.indexOf(input.charAt(i++));
59 | enc3 = this._keyStr.indexOf(input.charAt(i++));
60 | enc4 = this._keyStr.indexOf(input.charAt(i++));
61 |
62 | chr1 = (enc1 << 2) | (enc2 >> 4);
63 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
64 | chr3 = ((enc3 & 3) << 6) | enc4;
65 |
66 | output = output + String.fromCharCode(chr1);
67 |
68 | if (enc3 != 64) {
69 | output = output + String.fromCharCode(chr2);
70 | }
71 | if (enc4 != 64) {
72 | output = output + String.fromCharCode(chr3);
73 | }
74 |
75 | }
76 |
77 | output = Base64._utf8_decode(output);
78 |
79 | return output;
80 |
81 | },
82 |
83 | binDecode : function (input) {
84 | var output = new Array();
85 |
86 | var chr1, chr2, chr3;
87 | var enc1, enc2, enc3, enc4;
88 | var i = 0;
89 |
90 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
91 |
92 | var j = 0;
93 | while (i < input.length) {
94 |
95 | enc1 = this._keyStr.indexOf(input.charAt(i++));
96 | enc2 = this._keyStr.indexOf(input.charAt(i++));
97 | enc3 = this._keyStr.indexOf(input.charAt(i++));
98 | enc4 = this._keyStr.indexOf(input.charAt(i++));
99 |
100 | chr1 = (enc1 << 2) | (enc2 >> 4);
101 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
102 | chr3 = ((enc3 & 3) << 6) | enc4;
103 |
104 | //output = output + String.fromCharCode(chr1);
105 | output[j++] = chr1;
106 |
107 | if (enc3 != 64) {
108 | output[j++] = chr2;
109 | }
110 | if (enc4 != 64) {
111 | output[j++] = chr3;
112 | }
113 |
114 | }
115 |
116 | return output;
117 | },
118 |
119 |
120 |
121 | // private method for UTF-8 encoding
122 | _utf8_encode : function (string) {
123 | string = string.replace(/\r\n/g,"\n");
124 | var utftext = "";
125 |
126 | for (var n = 0; n < string.length; n++) {
127 |
128 | var c = string.charCodeAt(n);
129 |
130 | if (c < 128) {
131 | utftext += String.fromCharCode(c);
132 | }
133 | else if((c > 127) && (c < 2048)) {
134 | utftext += String.fromCharCode((c >> 6) | 192);
135 | utftext += String.fromCharCode((c & 63) | 128);
136 | }
137 | else {
138 | utftext += String.fromCharCode((c >> 12) | 224);
139 | utftext += String.fromCharCode(((c >> 6) & 63) | 128);
140 | utftext += String.fromCharCode((c & 63) | 128);
141 | }
142 |
143 | }
144 |
145 | return utftext;
146 | },
147 |
148 | // private method for UTF-8 decoding
149 | _utf8_decode : function (utftext) {
150 | var string = "";
151 | var i = 0;
152 | var c = c1 = c2 = 0;
153 |
154 | while ( i < utftext.length ) {
155 |
156 | c = utftext.charCodeAt(i);
157 |
158 | if (c < 128) {
159 | string += String.fromCharCode(c);
160 | i++;
161 | }
162 | else if((c > 191) && (c < 224)) {
163 | c2 = utftext.charCodeAt(i+1);
164 | string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
165 | i += 2;
166 | }
167 | else {
168 | c2 = utftext.charCodeAt(i+1);
169 | c3 = utftext.charCodeAt(i+2);
170 | string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
171 | i += 3;
172 | }
173 |
174 | }
175 |
176 | return string;
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/assets/js/main.js:
--------------------------------------------------------------------------------
1 | var config = {};
2 | config.streamingPort = 8088;
3 |
4 | var mediaSocket = null;
5 | var player = null;
6 | var myState = 0; // -1: error; 0: idle; 1: wainting; 2: palying
7 |
8 | var streamer = {};
9 | streamer.onOpen = function() {
10 |
11 | };
12 | streamer.onMessage = function(evt) {
13 | if ( myState != 2) {
14 | myState = 2;
15 | $("#spanInfo").html("Playing...");
16 | }
17 | var blob = evt.data;
18 | if ( blob.slice !== undefined) {
19 | var media = new TeaMedia(blob, function() {
20 | player.playMedia(media);
21 | }.bind(this) );
22 | }
23 | };
24 |
25 | streamer.onClose = function() {
26 | alert("Mobile is disconnected!");
27 | $("#btnPlay").prop('disabled', true);
28 | $("#spanInfo").html("Please relaod...");
29 | };
30 |
31 | var connect = function() {
32 | var myHost = window.location.hostname;
33 | var wsURL = "ws://" + window.location.hostname + ":" + config.streamingPort;
34 | mediaSocket = new WebSocket(wsURL);
35 | player = new Player(document.getElementById("videoPlayer"), 8000);
36 |
37 | mediaSocket.onopen = streamer.onOpen;
38 | mediaSocket.onmessage = streamer.onMessage;
39 | mediaSocket.onclose = streamer.onClose;
40 |
41 | $("#spanInfo").html("Connected, waiting for media..");
42 | };
43 |
44 | // like main function in C
45 | $(document).ready(function() {
46 | //$("#btnPlay").prop('disabled', false);
47 |
48 | $("#btnPlay").click( function() {
49 | if( myState == 0) {
50 | myState = 1;
51 | $("#btnPlay").html("Stop")
52 | $("#spanInfo").html("Connecting...");
53 |
54 | $.ajax({
55 | url: "/cgi/query",
56 | type: "get",
57 | cache: false,
58 | success: function(ret) {
59 | console.log(ret);
60 | var result = JSON.parse(ret);
61 | if ( result.state === "ok") {
62 | document.getElementById("videoPlayer").width = result.width;
63 | document.getElementById("videoPlayer").height = result.height;
64 |
65 | connect();
66 | } else {
67 | alert("Mobile is busy!");
68 | location.reload();
69 | }
70 | },
71 | error: function() {
72 | alert("Mobile is error");
73 | location.reload();
74 | },
75 | });
76 | } else if (myState != -1) {
77 | location.reload();
78 | }
79 | });
80 |
81 | });
82 |
--------------------------------------------------------------------------------
/assets/js/media.js:
--------------------------------------------------------------------------------
1 | function TeaMedia(blob, parseDone) {
2 | // vars
3 | this.pcmBlocks = null;
4 | this.nalBlocks = null;
5 |
6 | // call backs
7 | this.onParseDone = parseDone;
8 |
9 | // public interfaces
10 | this.getPicturePayload = function() {
11 |
12 | }.bind(this);
13 |
14 | this.getAudioPayload = function() {
15 |
16 | }.bind(this);
17 |
18 | // internal functions
19 | this._findNext = function(payload, i) {
20 | var block = {'type': 0, 'length': 0, 'timeStamp': -1};
21 |
22 | if ( payload[i] === 0x19 && payload[i+1] === 0x79) {
23 |
24 | block.type = 1;
25 | block.timeStamp = (payload[i+3] << 8) + payload[i+2];
26 | block.length = (payload[i+7] << 24) + (payload[i+6] << 16) + (payload[i+5] << 8) + payload[i+4];
27 | } else if ( payload[i] === 0x19 && payload[i+1] === 0x82) {
28 |
29 | block.type = 2;
30 | block.timeStamp = (payload[i+3] << 8) + payload[i+2];
31 | block.length = (payload[i+7] << 24) + (payload[i+6] << 16) + (payload[i+5] << 8) + payload[i+4];
32 | }
33 |
34 | return block;
35 |
36 | }.bind(this);
37 |
38 | this._decodeBuffer = function(arrayBuffer) {
39 | var payload = new Uint8Array(arrayBuffer);
40 |
41 | var i = 0;
42 | while(1) {
43 | if ( payload.length - i <= 8) {
44 | // drop left data, because it is not a packet.
45 | break;
46 | }
47 |
48 | var block = this._findNext(payload, i);
49 | if ( block.type === 1 ) {
50 | block.payload = payload.subarray(i+8, i+8+block.length);
51 | this.nalBlocks.push(block);
52 | i = i + 8 + block.length;
53 |
54 | } else if ( block.type === 2) {
55 | block.payload = payload.subarray(i+8, i+8+block.length);
56 | this.pcmBlocks.push(block);
57 | i = i + 8 + block.length;
58 |
59 | } else {
60 | break;
61 | }
62 | }
63 |
64 | this.onParseDone();
65 |
66 | }.bind(this);
67 |
68 | this._constructor = function() {
69 | this.pcmBlocks = [];
70 | this.nalBlocks = [];
71 |
72 | var fileReader = new FileReader();
73 | var that = this;
74 | fileReader.onload = function() {
75 | that._decodeBuffer( this.result);
76 | };
77 | fileReader.readAsArrayBuffer(blob);
78 |
79 | }.bind(this);
80 |
81 | // init
82 | this._constructor();
83 | };
84 |
--------------------------------------------------------------------------------
/assets/js/player.js:
--------------------------------------------------------------------------------
1 | var requestAnimFrame = (function(){
2 | return window.requestAnimationFrame ||
3 | window.webkitRequestAnimationFrame ||
4 | window.mozRequestAnimationFrame ||
5 | function( callback ){
6 | window.setTimeout(callback, 1000 / 60);
7 | };
8 | })();
9 |
10 | function Player (canvas, sampleRate) {
11 | // vars
12 | this._canvas = null;
13 | this._canvasContext = null;
14 | this._rgba = null;
15 | this._renderInterval = 5;
16 |
17 | this._playedTime = -1;
18 | this._lastTime = -1;
19 | this._videoTime = -1;
20 | this._lastVideoTime = -1;
21 |
22 | this._avc = null;
23 | this._videoBufferList = null;
24 |
25 | // call backs
26 | this.onStreamStarvation = null;
27 |
28 | // public functions
29 | this._constructor = function() {
30 | this._canvas = canvas;
31 | this._canvasContext = this._canvas.getContext("2d");
32 | this._canvasContext.font = "12px sans-serif";
33 | this._canvasContext.textAlign = 'right';
34 | this._canvasContext.fillStyle = 'rgba(0,255,0, 0.9)';
35 | this._rgba = this._canvasContext.getImageData(0, 0, this._canvas.width, this._canvas.height);
36 | this._videoBufferList = new Array();
37 |
38 | this._avc = new Avc();
39 |
40 | setInterval(this._playVideo, this._renderInterval);
41 | //requestAnimFrame(this._playVideo);
42 | }.bind(this);
43 |
44 | this.playMedia = function(media) {
45 | if ( this._videoBufferList.length > 150) {
46 | return;
47 | }
48 |
49 | var picture = null;
50 | this._avc.onPictureDecoded = function(buffer, wid, hei) {
51 | var yuv = new Uint8Array(buffer.length);
52 | yuv.set(buffer, 0, buffer.length);
53 | picture = {'yuv':yuv, 'wid':wid, 'hei':hei};
54 | }.bind(this);
55 |
56 | /*
57 | var doDecode = function(first) {
58 | if ( media.nalBlocks.length > 0) {
59 | picture = null;
60 | this._avc.decode(media.nalBlocks[0].payload);
61 | if( picture != null) {
62 | picture.timeStamp = media.nalBlocks[0].timeStamp;
63 | picture.flag = first;
64 | this._videoBufferList.push(picture);
65 | }
66 | media.nalBlocks.shift();
67 | setTimeout(doDecode(false), 2);
68 | } else {
69 | delete media;
70 |
71 | }
72 | }.bind(this);
73 | doDecode(true);
74 | */
75 |
76 | for (i = 0; i < media.nalBlocks.length; i++) {
77 | picture = null;
78 | this._avc.decode(media.nalBlocks[i].payload);
79 | if( picture != null) {
80 | picture.timeStamp = media.nalBlocks[i].timeStamp;
81 | if ( i === 0) {
82 | console.log(">>>>> " + picture.timeStamp);
83 | picture.flag = true;
84 | } else {
85 | picture.flag = false;
86 | }
87 |
88 | this._videoBufferList.push(picture);
89 | }
90 | }
91 |
92 | delete media;
93 |
94 | }.bind(this);
95 |
96 | // private functions
97 | this._updateInfo = function(info) {
98 | this._infoText = info;
99 | this._canvasContext.fillText(this._infoText, this._canvas.width - 5, 20);
100 | }.bind(this);
101 |
102 | this._showPicture = function(picture) {
103 | yuv2ImageData(picture.yuv, this._rgba);
104 | this._canvasContext.putImageData(this._rgba, 0, 0);
105 | }.bind(this);
106 |
107 | this._playVideo = function() {
108 | //requestAnimFrame(this._playVideo);
109 | if ( this._videoBufferList.length > 0) {
110 | if ( this._videoBufferList[0].flag === true) {
111 | this._playedTime = this._videoBufferList[0].timeStamp;
112 | this._lastVideoTime = this._videoBufferList[0].timeStamp;
113 | this._videoTime = 0;
114 | } else {
115 | this._playedTime += (new Date()).getTime() - this._lastTime;
116 | }
117 |
118 | //console.log(this._playedTime + " vs " + this._videoTime + this._videoBufferList[0].timeStamp );
119 |
120 | if ( this._playedTime >= this._videoTime + this._videoBufferList[0].timeStamp ) {
121 | // updated video time
122 | if ( this._videoBufferList[0].timeStamp < this._lastVideoTime ) {
123 | this._videoTime += 65535;
124 | }
125 | this._lastVideoTime = this._videoBufferList[0].timeStamp;
126 |
127 | //console.log(">>>>> " + this._videoBufferList[0].timeStamp)
128 | this._showPicture(this._videoBufferList[0] );
129 | delete this._videoBufferList[0];
130 | this._videoBufferList.shift();
131 | }
132 | }
133 | this._lastTime = (new Date()).getTime();
134 | }.bind(this);
135 |
136 | this._pushVideoBuffer = function(picture) {
137 | this._videoBufferList.push(picture);
138 |
139 | }.bind(this);
140 |
141 | // init
142 | this._constructor();
143 | }
144 |
--------------------------------------------------------------------------------
/ems/avc-inc/H264SwDecApi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include Headers
22 |
23 | 2. Enumerations used as a return value or a parameter.
24 | 2.1. API's return value enumerations.
25 |
26 | 3. User Structures
27 | 3.1. Structures for H264SwDecDecode() parameters.
28 | 3.2. Structures for information interchange with
29 | DEC API and user application.
30 |
31 | 4. Prototypes of Decoder API functions
32 |
33 | ------------------------------------------------------------------------------*/
34 |
35 | #ifndef H264SWDECAPI_H
36 | #define H264SWDECAPI_H
37 |
38 | #ifdef __cplusplus
39 | extern "C"
40 | {
41 | #endif
42 |
43 | /*------------------------------------------------------------------------------
44 | 1. Include Headers
45 | ------------------------------------------------------------------------------*/
46 |
47 | #include "basetype.h"
48 |
49 | /*------------------------------------------------------------------------------
50 | 2.1. API's return value enumerations.
51 | ------------------------------------------------------------------------------*/
52 |
53 | typedef enum
54 | {
55 | H264SWDEC_OK = 0,
56 | H264SWDEC_STRM_PROCESSED = 1,
57 | H264SWDEC_PIC_RDY,
58 | H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY,
59 | H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY,
60 | H264SWDEC_PARAM_ERR = -1,
61 | H264SWDEC_STRM_ERR = -2,
62 | H264SWDEC_NOT_INITIALIZED = -3,
63 | H264SWDEC_MEMFAIL = -4,
64 | H264SWDEC_INITFAIL = -5,
65 | H264SWDEC_HDRS_NOT_RDY = -6,
66 | H264SWDEC_EVALUATION_LIMIT_EXCEEDED = -7
67 | } H264SwDecRet;
68 |
69 | /*------------------------------------------------------------------------------
70 | 3.1. Structures for H264SwDecDecode() parameters.
71 | ------------------------------------------------------------------------------*/
72 |
73 | /* typedef of the Decoder instance */
74 | typedef void *H264SwDecInst;
75 |
76 | /* Input structure */
77 | typedef struct
78 | {
79 | u8 *pStream; /* Pointer to stream to be decoded */
80 | u32 dataLen; /* Number of bytes to be decoded */
81 | u32 picId; /* Identifier for the picture to be decoded */
82 | u32 intraConcealmentMethod; /* 0 = Gray concealment for intra
83 | 1 = Reference concealment for intra */
84 |
85 | } H264SwDecInput;
86 |
87 |
88 | /* Output structure */
89 | typedef struct
90 | {
91 | u8 *pStrmCurrPos; /* Pointer to stream position where decoder
92 | ended up */
93 | } H264SwDecOutput;
94 |
95 | /* Output structure for H264SwDecNextPicture */
96 | typedef struct
97 | {
98 | u32 *pOutputPicture; /* Pointer to the picture, YUV format */
99 | u32 picId; /* Identifier of the picture to be displayed*/
100 | u32 isIdrPicture; /* Flag to indicate if the picture is an
101 | IDR picture */
102 | u32 nbrOfErrMBs; /* Number of concealed MB's in the picture */
103 | } H264SwDecPicture;
104 |
105 | /*------------------------------------------------------------------------------
106 | 3.2. Structures for information interchange with DEC API
107 | and user application.
108 | ------------------------------------------------------------------------------*/
109 |
110 | typedef struct
111 | {
112 | u32 cropLeftOffset;
113 | u32 cropOutWidth;
114 | u32 cropTopOffset;
115 | u32 cropOutHeight;
116 | } CropParams;
117 |
118 | typedef struct
119 | {
120 | u32 profile;
121 | u32 picWidth;
122 | u32 picHeight;
123 | u32 videoRange;
124 | u32 matrixCoefficients;
125 | u32 parWidth;
126 | u32 parHeight;
127 | u32 croppingFlag;
128 | CropParams cropParams;
129 | } H264SwDecInfo;
130 |
131 | /* Version information */
132 | typedef struct
133 | {
134 | u32 major; /* Decoder API major version */
135 | u32 minor; /* Dncoder API minor version */
136 | } H264SwDecApiVersion;
137 |
138 | /*------------------------------------------------------------------------------
139 | 4. Prototypes of Decoder API functions
140 | ------------------------------------------------------------------------------*/
141 |
142 | H264SwDecRet H264SwDecDecode(H264SwDecInst decInst,
143 | H264SwDecInput *pInput,
144 | H264SwDecOutput *pOutput);
145 |
146 | H264SwDecRet H264SwDecInit(H264SwDecInst *decInst,
147 | u32 noOutputReordering);
148 |
149 | H264SwDecRet H264SwDecNextPicture(H264SwDecInst decInst,
150 | H264SwDecPicture *pOutput,
151 | u32 endOfStream);
152 |
153 | H264SwDecRet H264SwDecGetInfo(H264SwDecInst decInst,
154 | H264SwDecInfo *pDecInfo);
155 |
156 | void H264SwDecRelease(H264SwDecInst decInst);
157 |
158 | H264SwDecApiVersion H264SwDecGetAPIVersion(void);
159 |
160 | /* function prototype for API trace */
161 | void H264SwDecTrace(char *);
162 |
163 | /* function prototype for memory allocation */
164 | void* H264SwDecMalloc(u32 size);
165 |
166 | /* function prototype for memory free */
167 | void H264SwDecFree(void *ptr);
168 |
169 | /* function prototype for memory copy */
170 | void H264SwDecMemcpy(void *dest, void *src, u32 count);
171 |
172 | /* function prototype for memset */
173 | void H264SwDecMemset(void *ptr, i32 value, u32 count);
174 |
175 |
176 | #ifdef __cplusplus
177 | }
178 | #endif
179 |
180 | #endif /* H264SWDECAPI_H */
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/ems/avc-inc/basetype.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef BASETYPE_H_INCLUDED
19 | #define BASETYPE_H_INCLUDED
20 |
21 |
22 | #ifdef __arm
23 | #define VOLATILE volatile
24 | #else
25 | #define VOLATILE
26 | #endif
27 |
28 | typedef unsigned char u8;
29 | typedef signed char i8;
30 | typedef unsigned short u16;
31 | typedef signed short i16;
32 | typedef unsigned int u32;
33 | typedef signed int i32;
34 |
35 | #if defined(VC1SWDEC_16BIT) || defined(MP4ENC_ARM11)
36 | typedef unsigned short u16x;
37 | typedef signed short i16x;
38 | #else
39 | typedef unsigned int u16x;
40 | typedef signed int i16x;
41 | #endif
42 |
43 |
44 | #ifndef NULL
45 | #ifdef __cplusplus
46 | #define NULL 0
47 | #else
48 | #define NULL ((void *)0)
49 | #endif
50 | #endif
51 |
52 | #endif /* BASETYPE_H_INCLUDED */
53 |
--------------------------------------------------------------------------------
/ems/avc.bc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/avc.bc
--------------------------------------------------------------------------------
/ems/avc/h264bsd_byte_stream.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_BYTE_STREAM_H
29 | #define H264SWDEC_BYTE_STREAM_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.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 h264bsdExtractNalUnit(u8 *pByteStream, u32 len, strmData_t *pStrmData,
51 | u32 *readBytes);
52 |
53 | #endif /* #ifdef H264SWDEC_BYTE_STREAM_H */
54 |
55 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_cavlc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_CAVLC_H
29 | #define H264SWDEC_CAVLC_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /*------------------------------------------------------------------------------
48 | 4. Function prototypes
49 | ------------------------------------------------------------------------------*/
50 |
51 | u32 h264bsdDecodeResidualBlockCavlc(
52 | strmData_t *pStrmData,
53 | i32 *coeffLevel,
54 | i32 nc,
55 | u32 maxNumCoeff);
56 |
57 | #endif /* #ifdef H264SWDEC_CAVLC_H */
58 |
59 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_cfg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_CFG_H
29 | #define H264SWDEC_CFG_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 |
37 | /*------------------------------------------------------------------------------
38 | 2. Module defines
39 | ------------------------------------------------------------------------------*/
40 |
41 | #define MAX_NUM_REF_PICS 16
42 | #define MAX_NUM_SLICE_GROUPS 8
43 | #define MAX_NUM_SEQ_PARAM_SETS 32
44 | #define MAX_NUM_PIC_PARAM_SETS 256
45 |
46 | /*------------------------------------------------------------------------------
47 | 3. Data types
48 | ------------------------------------------------------------------------------*/
49 |
50 |
51 | /*------------------------------------------------------------------------------
52 | 4. Function prototypes
53 | ------------------------------------------------------------------------------*/
54 |
55 | #endif /* #ifdef H264SWDEC_CFG_H */
56 |
57 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_conceal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_CONCEAL_H
29 | #define H264SWDEC_CONCEAL_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_slice_header.h"
37 | #include "h264bsd_storage.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 h264bsdConceal(storage_t *pStorage, image_t *currImage, u32 sliceType);
52 |
53 | #endif /* #ifdef H264SWDEC_CONCEAL_H */
54 |
55 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_container.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_CONTAINER_H
29 | #define H264SWDEC_CONTAINER_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_storage.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | /* String length for tracing */
43 | #define H264DEC_TRACE_STR_LEN 100
44 |
45 | /*------------------------------------------------------------------------------
46 | 3. Data types
47 | ------------------------------------------------------------------------------*/
48 |
49 | typedef struct
50 | {
51 | enum {
52 | UNINITIALIZED,
53 | INITIALIZED,
54 | NEW_HEADERS
55 | } decStat;
56 |
57 | u32 picNumber;
58 | storage_t storage;
59 | #ifdef H264DEC_TRACE
60 | char str[H264DEC_TRACE_STR_LEN];
61 | #endif
62 | } decContainer_t;
63 |
64 | /*------------------------------------------------------------------------------
65 | 4. Function prototypes
66 | ------------------------------------------------------------------------------*/
67 |
68 | #endif /* #ifdef H264SWDEC_DECCONTAINER_H */
69 |
70 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_deblocking.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_DEBLOCKING_H
29 | #define H264SWDEC_DEBLOCKING_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_image.h"
37 | #include "h264bsd_macroblock_layer.h"
38 |
39 | /*------------------------------------------------------------------------------
40 | 2. Module defines
41 | ------------------------------------------------------------------------------*/
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /*------------------------------------------------------------------------------
48 | 4. Function prototypes
49 | ------------------------------------------------------------------------------*/
50 |
51 | void h264bsdFilterPicture(
52 | image_t *image,
53 | mbStorage_t *mb);
54 |
55 | #endif /* #ifdef H264SWDEC_DEBLOCKING_H */
56 |
57 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_decoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_DECODER_H
29 | #define H264SWDEC_DECODER_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_storage.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | /* enumerated return values of the functions */
43 | enum {
44 | H264BSD_RDY,
45 | H264BSD_PIC_RDY,
46 | H264BSD_HDRS_RDY,
47 | H264BSD_ERROR,
48 | H264BSD_PARAM_SET_ERROR,
49 | H264BSD_MEMALLOC_ERROR
50 | };
51 |
52 | /*------------------------------------------------------------------------------
53 | 3. Data types
54 | ------------------------------------------------------------------------------*/
55 |
56 | /*------------------------------------------------------------------------------
57 | 4. Function prototypes
58 | ------------------------------------------------------------------------------*/
59 |
60 | u32 h264bsdInit(storage_t *pStorage, u32 noOutputReordering);
61 | u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u32 picId,
62 | u32 *readBytes);
63 | void h264bsdShutdown(storage_t *pStorage);
64 |
65 | u8* h264bsdNextOutputPicture(storage_t *pStorage, u32 *picId, u32 *isIdrPic,
66 | u32 *numErrMbs);
67 |
68 | u32 h264bsdPicWidth(storage_t *pStorage);
69 | u32 h264bsdPicHeight(storage_t *pStorage);
70 | u32 h264bsdVideoRange(storage_t *pStorage);
71 | u32 h264bsdMatrixCoefficients(storage_t *pStorage);
72 | void h264bsdCroppingParams(storage_t *pStorage, u32 *croppingFlag,
73 | u32 *left, u32 *width, u32 *top, u32 *height);
74 | void h264bsdSampleAspectRatio(storage_t *pStorage,
75 | u32 *sarWidth, u32 *sarHeight);
76 | u32 h264bsdCheckValidParamSets(storage_t *pStorage);
77 |
78 | void h264bsdFlushBuffer(storage_t *pStorage);
79 |
80 | u32 h264bsdProfile(storage_t *pStorage);
81 |
82 | #endif /* #ifdef H264SWDEC_DECODER_H */
83 |
84 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_dpb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_DPB_H
29 | #define H264SWDEC_DPB_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_slice_header.h"
37 | #include "h264bsd_image.h"
38 |
39 | /*------------------------------------------------------------------------------
40 | 2. Module defines
41 | ------------------------------------------------------------------------------*/
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /* enumeration to represent status of buffered image */
48 | typedef enum {
49 | UNUSED = 0,
50 | NON_EXISTING,
51 | SHORT_TERM,
52 | LONG_TERM
53 | } dpbPictureStatus_e;
54 |
55 | /* structure to represent a buffered picture */
56 | typedef struct {
57 | u8 *data; /* 16-byte aligned pointer of pAllocatedData */
58 | u8 *pAllocatedData; /* allocated picture pointer; (size + 15) bytes */
59 | i32 picNum;
60 | u32 frameNum;
61 | i32 picOrderCnt;
62 | dpbPictureStatus_e status;
63 | u32 toBeDisplayed;
64 | u32 picId;
65 | u32 numErrMbs;
66 | u32 isIdr;
67 | } dpbPicture_t;
68 |
69 | /* structure to represent display image output from the buffer */
70 | typedef struct {
71 | u8 *data;
72 | u32 picId;
73 | u32 numErrMbs;
74 | u32 isIdr;
75 | } dpbOutPicture_t;
76 |
77 | /* structure to represent DPB */
78 | typedef struct {
79 | dpbPicture_t *buffer;
80 | dpbPicture_t **list;
81 | dpbPicture_t *currentOut;
82 | dpbOutPicture_t *outBuf;
83 | u32 numOut;
84 | u32 outIndex;
85 | u32 maxRefFrames;
86 | u32 dpbSize;
87 | u32 maxFrameNum;
88 | u32 maxLongTermFrameIdx;
89 | u32 numRefFrames;
90 | u32 fullness;
91 | u32 prevRefFrameNum;
92 | u32 lastContainsMmco5;
93 | u32 noReordering;
94 | u32 flushed;
95 | } dpbStorage_t;
96 |
97 | /*------------------------------------------------------------------------------
98 | 4. Function prototypes
99 | ------------------------------------------------------------------------------*/
100 |
101 | u32 h264bsdInitDpb(
102 | dpbStorage_t *dpb,
103 | u32 picSizeInMbs,
104 | u32 dpbSize,
105 | u32 numRefFrames,
106 | u32 maxFrameNum,
107 | u32 noReordering);
108 |
109 | u32 h264bsdResetDpb(
110 | dpbStorage_t *dpb,
111 | u32 picSizeInMbs,
112 | u32 dpbSize,
113 | u32 numRefFrames,
114 | u32 maxFrameNum,
115 | u32 noReordering);
116 |
117 | void h264bsdInitRefPicList(dpbStorage_t *dpb);
118 |
119 | u8* h264bsdAllocateDpbImage(dpbStorage_t *dpb);
120 |
121 | u8* h264bsdGetRefPicData(dpbStorage_t *dpb, u32 index);
122 |
123 | u32 h264bsdReorderRefPicList(
124 | dpbStorage_t *dpb,
125 | refPicListReordering_t *order,
126 | u32 currFrameNum,
127 | u32 numRefIdxActive);
128 |
129 | u32 h264bsdMarkDecRefPic(
130 | dpbStorage_t *dpb,
131 | decRefPicMarking_t *mark,
132 | image_t *image,
133 | u32 frameNum,
134 | i32 picOrderCnt,
135 | u32 isIdr,
136 | u32 picId,
137 | u32 numErrMbs);
138 |
139 | u32 h264bsdCheckGapsInFrameNum(dpbStorage_t *dpb, u32 frameNum, u32 isRefPic,
140 | u32 gapsAllowed);
141 |
142 | dpbOutPicture_t* h264bsdDpbOutputPicture(dpbStorage_t *dpb);
143 |
144 | void h264bsdFlushDpb(dpbStorage_t *dpb);
145 |
146 | void h264bsdFreeDpb(dpbStorage_t *dpb);
147 |
148 | #endif /* #ifdef H264SWDEC_DPB_H */
149 |
150 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_image.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_IMAGE_H
29 | #define H264SWDEC_IMAGE_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 |
37 | /*------------------------------------------------------------------------------
38 | 2. Module defines
39 | ------------------------------------------------------------------------------*/
40 |
41 | /*------------------------------------------------------------------------------
42 | 3. Data types
43 | ------------------------------------------------------------------------------*/
44 |
45 | typedef struct
46 | {
47 | u8 *data;
48 | u32 width;
49 | u32 height;
50 | /* current MB's components */
51 | u8 *luma;
52 | u8 *cb;
53 | u8 *cr;
54 | } image_t;
55 |
56 | /*------------------------------------------------------------------------------
57 | 4. Function prototypes
58 | ------------------------------------------------------------------------------*/
59 |
60 | void h264bsdWriteMacroblock(image_t *image, u8 *data);
61 |
62 | #ifndef H264DEC_OMXDL
63 | void h264bsdWriteOutputBlocks(image_t *image, u32 mbNum, u8 *data,
64 | i32 residual[][16]);
65 | #endif
66 |
67 | #endif /* #ifdef H264SWDEC_IMAGE_H */
68 |
69 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_inter_prediction.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_INTER_PREDICTION_H
29 | #define H264SWDEC_INTER_PREDICTION_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_image.h"
37 | #include "h264bsd_macroblock_layer.h"
38 | #include "h264bsd_dpb.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 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
53 | dpbStorage_t *dpb, u32 mbNum, image_t *image, u8 *data);
54 |
55 | #endif /* #ifdef H264SWDEC_INTER_PREDICTION_H */
56 |
57 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_intra_prediction.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_INTRA_PREDICTION_H
29 | #define H264SWDEC_INTRA_PREDICTION_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_image.h"
37 | #include "h264bsd_macroblock_layer.h"
38 |
39 | /*------------------------------------------------------------------------------
40 | 2. Module defines
41 | ------------------------------------------------------------------------------*/
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /*------------------------------------------------------------------------------
48 | 4. Function prototypes
49 | ------------------------------------------------------------------------------*/
50 | #ifndef H264DEC_OMXDL
51 | u32 h264bsdIntraPrediction(mbStorage_t *pMb, macroblockLayer_t *mbLayer,
52 | image_t *image, u32 mbNum, u32 constrainedIntraPred, u8 *data);
53 |
54 | u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
55 | macroblockLayer_t *mbLayer,
56 | u8 *above, u8 *left, u32 constrainedIntraPred);
57 | u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
58 | u8 *above, u8 *left, u32 constrainedIntraPred);
59 |
60 | u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
61 | u8 *above, u8 *left, u32 predMode, u32 constrainedIntraPred);
62 |
63 | void h264bsdGetNeighbourPels(image_t *image, u8 *above, u8 *left, u32 mbNum);
64 |
65 | #else
66 |
67 | u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
68 | macroblockLayer_t *mbLayer,
69 | u8 *pImage, u32 width,
70 | u32 constrainedIntraPred, u32 block);
71 |
72 | u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, u8 *pImage,
73 | u32 width, u32 constrainedIntraPred);
74 |
75 | u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, image_t *image,
76 | u32 predMode, u32 constrainedIntraPred);
77 |
78 | #endif
79 |
80 | #endif /* #ifdef H264SWDEC_INTRA_PREDICTION_H */
81 |
82 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_macroblock_layer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_MACROBLOCK_LAYER_H
29 | #define H264SWDEC_MACROBLOCK_LAYER_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 | #include "h264bsd_image.h"
38 | #include "h264bsd_dpb.h"
39 |
40 | /*------------------------------------------------------------------------------
41 | 2. Module defines
42 | ------------------------------------------------------------------------------*/
43 |
44 | /* Macro to determine if a mb is an intra mb */
45 | #define IS_INTRA_MB(a) ((a).mbType > 5)
46 |
47 | /* Macro to determine if a mb is an I_PCM mb */
48 | #define IS_I_PCM_MB(a) ((a).mbType == 31)
49 |
50 | typedef enum {
51 | P_Skip = 0,
52 | P_L0_16x16 = 1,
53 | P_L0_L0_16x8 = 2,
54 | P_L0_L0_8x16 = 3,
55 | P_8x8 = 4,
56 | P_8x8ref0 = 5,
57 | I_4x4 = 6,
58 | I_16x16_0_0_0 = 7,
59 | I_16x16_1_0_0 = 8,
60 | I_16x16_2_0_0 = 9,
61 | I_16x16_3_0_0 = 10,
62 | I_16x16_0_1_0 = 11,
63 | I_16x16_1_1_0 = 12,
64 | I_16x16_2_1_0 = 13,
65 | I_16x16_3_1_0 = 14,
66 | I_16x16_0_2_0 = 15,
67 | I_16x16_1_2_0 = 16,
68 | I_16x16_2_2_0 = 17,
69 | I_16x16_3_2_0 = 18,
70 | I_16x16_0_0_1 = 19,
71 | I_16x16_1_0_1 = 20,
72 | I_16x16_2_0_1 = 21,
73 | I_16x16_3_0_1 = 22,
74 | I_16x16_0_1_1 = 23,
75 | I_16x16_1_1_1 = 24,
76 | I_16x16_2_1_1 = 25,
77 | I_16x16_3_1_1 = 26,
78 | I_16x16_0_2_1 = 27,
79 | I_16x16_1_2_1 = 28,
80 | I_16x16_2_2_1 = 29,
81 | I_16x16_3_2_1 = 30,
82 | I_PCM = 31
83 | } mbType_e;
84 |
85 | typedef enum {
86 | P_L0_8x8 = 0,
87 | P_L0_8x4 = 1,
88 | P_L0_4x8 = 2,
89 | P_L0_4x4 = 3
90 | } subMbType_e;
91 |
92 | typedef enum {
93 | MB_P_16x16 = 0,
94 | MB_P_16x8,
95 | MB_P_8x16,
96 | MB_P_8x8
97 | } mbPartMode_e;
98 |
99 | typedef enum {
100 | MB_SP_8x8 = 0,
101 | MB_SP_8x4,
102 | MB_SP_4x8,
103 | MB_SP_4x4
104 | } subMbPartMode_e;
105 |
106 | typedef enum {
107 | PRED_MODE_INTRA4x4 = 0,
108 | PRED_MODE_INTRA16x16 ,
109 | PRED_MODE_INTER
110 | } mbPartPredMode_e;
111 |
112 | /*------------------------------------------------------------------------------
113 | 3. Data types
114 | ------------------------------------------------------------------------------*/
115 |
116 | typedef struct
117 | {
118 | /* MvPrediction16x16 assumes that MVs are 16bits */
119 | i16 hor;
120 | i16 ver;
121 | } mv_t;
122 |
123 | typedef struct
124 | {
125 | u32 prevIntra4x4PredModeFlag[16];
126 | u32 remIntra4x4PredMode[16];
127 | u32 intraChromaPredMode;
128 | u32 refIdxL0[4];
129 | mv_t mvdL0[4];
130 | } mbPred_t;
131 |
132 | typedef struct
133 | {
134 | subMbType_e subMbType[4];
135 | u32 refIdxL0[4];
136 | mv_t mvdL0[4][4];
137 | } subMbPred_t;
138 |
139 | typedef struct
140 | {
141 | #ifdef H264DEC_OMXDL
142 | u8 posCoefBuf[27*16*3];
143 | u8 totalCoeff[27];
144 | #else
145 | i16 totalCoeff[27];
146 | #endif
147 | i32 level[26][16];
148 | u32 coeffMap[24];
149 | } residual_t;
150 |
151 | typedef struct
152 | {
153 | mbType_e mbType;
154 | u32 codedBlockPattern;
155 | i32 mbQpDelta;
156 | mbPred_t mbPred;
157 | subMbPred_t subMbPred;
158 | residual_t residual;
159 | } macroblockLayer_t;
160 |
161 | typedef struct mbStorage
162 | {
163 | mbType_e mbType;
164 | u32 sliceId;
165 | u32 disableDeblockingFilterIdc;
166 | i32 filterOffsetA;
167 | i32 filterOffsetB;
168 | u32 qpY;
169 | i32 chromaQpIndexOffset;
170 | #ifdef H264DEC_OMXDL
171 | u8 totalCoeff[27];
172 | #else
173 | i16 totalCoeff[27];
174 | #endif
175 | u8 intra4x4PredMode[16];
176 | u32 refPic[4];
177 | u8* refAddr[4];
178 | mv_t mv[16];
179 | u32 decoded;
180 | struct mbStorage *mbA;
181 | struct mbStorage *mbB;
182 | struct mbStorage *mbC;
183 | struct mbStorage *mbD;
184 | } mbStorage_t;
185 |
186 | /*------------------------------------------------------------------------------
187 | 4. Function prototypes
188 | ------------------------------------------------------------------------------*/
189 |
190 | u32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData,
191 | macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType,
192 | u32 numRefIdxActive);
193 |
194 | u32 h264bsdNumMbPart(mbType_e mbType);
195 | u32 h264bsdNumSubMbPart(subMbType_e subMbType);
196 |
197 | subMbPartMode_e h264bsdSubMbPartMode(subMbType_e subMbType);
198 |
199 | u32 h264bsdDecodeMacroblock(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
200 | image_t *currImage, dpbStorage_t *dpb, i32 *qpY, u32 mbNum,
201 | u32 constrainedIntraPredFlag, u8* data);
202 |
203 | u32 h264bsdPredModeIntra16x16(mbType_e mbType);
204 |
205 | mbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType);
206 | #ifdef H264DEC_NEON
207 | u32 h264bsdClearMbLayer(macroblockLayer_t *pMbLayer, u32 size);
208 | #endif
209 |
210 | #endif /* #ifdef H264SWDEC_MACROBLOCK_LAYER_H */
211 |
212 |
213 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_nal_unit.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/avc/h264bsd_nal_unit.c
--------------------------------------------------------------------------------
/ems/avc/h264bsd_nal_unit.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_NAL_UNIT_H
29 | #define H264SWDEC_NAL_UNIT_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | /* macro to determine if NAL unit pointed by pNalUnit contains an IDR slice */
43 | #define IS_IDR_NAL_UNIT(pNalUnit) \
44 | ((pNalUnit)->nalUnitType == NAL_CODED_SLICE_IDR)
45 |
46 | /*------------------------------------------------------------------------------
47 | 3. Data types
48 | ------------------------------------------------------------------------------*/
49 |
50 | typedef enum {
51 | NAL_CODED_SLICE = 1,
52 | NAL_CODED_SLICE_IDR = 5,
53 | NAL_SEI = 6,
54 | NAL_SEQ_PARAM_SET = 7,
55 | NAL_PIC_PARAM_SET = 8,
56 | NAL_ACCESS_UNIT_DELIMITER = 9,
57 | NAL_END_OF_SEQUENCE = 10,
58 | NAL_END_OF_STREAM = 11,
59 | NAL_FILLER_DATA = 12,
60 | NAL_MAX_TYPE_VALUE = 31
61 | } nalUnitType_e;
62 |
63 | typedef struct
64 | {
65 | nalUnitType_e nalUnitType;
66 | u32 nalRefIdc;
67 | } nalUnit_t;
68 |
69 | /*------------------------------------------------------------------------------
70 | 4. Function prototypes
71 | ------------------------------------------------------------------------------*/
72 |
73 | u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit);
74 |
75 | #endif /* #ifdef H264SWDEC_NAL_UNIT_H */
76 |
77 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_neighbour.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_NEIGHBOUR_H
29 | #define H264SWDEC_NEIGHBOUR_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_macroblock_layer.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | typedef enum {
43 | MB_A = 0,
44 | MB_B,
45 | MB_C,
46 | MB_D,
47 | MB_CURR,
48 | MB_NA = 0xFF
49 | } neighbourMb_e;
50 |
51 | /*------------------------------------------------------------------------------
52 | 3. Data types
53 | ------------------------------------------------------------------------------*/
54 |
55 | typedef struct
56 | {
57 | neighbourMb_e mb;
58 | u8 index;
59 | } neighbour_t;
60 |
61 | /*------------------------------------------------------------------------------
62 | 4. Function prototypes
63 | ------------------------------------------------------------------------------*/
64 |
65 | void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth,
66 | u32 picSizeInMbs);
67 |
68 | mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour);
69 |
70 | u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour);
71 |
72 | const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex);
73 | const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex);
74 | const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex);
75 | const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex);
76 |
77 | #endif /* #ifdef H264SWDEC_NEIGHBOUR_H */
78 |
79 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_pic_order_cnt.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_PIC_ORDER_CNT_H
29 | #define H264SWDEC_PIC_ORDER_CNT_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_seq_param_set.h"
37 | #include "h264bsd_slice_header.h"
38 | #include "h264bsd_nal_unit.h"
39 |
40 | /*------------------------------------------------------------------------------
41 | 2. Module defines
42 | ------------------------------------------------------------------------------*/
43 |
44 |
45 | /*------------------------------------------------------------------------------
46 | 3. Data types
47 | ------------------------------------------------------------------------------*/
48 |
49 | /* structure to store information computed for previous picture, needed for
50 | * POC computation of a picture. Two first fields for POC type 0, last two
51 | * for types 1 and 2 */
52 | typedef struct
53 | {
54 | u32 prevPicOrderCntLsb;
55 | i32 prevPicOrderCntMsb;
56 | u32 prevFrameNum;
57 | u32 prevFrameNumOffset;
58 | } pocStorage_t;
59 |
60 | /*------------------------------------------------------------------------------
61 | 4. Function prototypes
62 | ------------------------------------------------------------------------------*/
63 |
64 | i32 h264bsdDecodePicOrderCnt(pocStorage_t *poc, seqParamSet_t *sps,
65 | sliceHeader_t *sliceHeader, nalUnit_t *pNalUnit);
66 |
67 | #endif /* #ifdef H264SWDEC_PIC_ORDER_CNT_H */
68 |
69 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_pic_param_set.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_PIC_PARAM_SET_H
29 | #define H264SWDEC_PIC_PARAM_SET_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | /*------------------------------------------------------------------------------
43 | 3. Data types
44 | ------------------------------------------------------------------------------*/
45 |
46 | /* data structure to store PPS information decoded from the stream */
47 | typedef struct
48 | {
49 | u32 picParameterSetId;
50 | u32 seqParameterSetId;
51 | u32 picOrderPresentFlag;
52 | u32 numSliceGroups;
53 | u32 sliceGroupMapType;
54 | u32 *runLength;
55 | u32 *topLeft;
56 | u32 *bottomRight;
57 | u32 sliceGroupChangeDirectionFlag;
58 | u32 sliceGroupChangeRate;
59 | u32 picSizeInMapUnits;
60 | u32 *sliceGroupId;
61 | u32 numRefIdxL0Active;
62 | u32 picInitQp;
63 | i32 chromaQpIndexOffset;
64 | u32 deblockingFilterControlPresentFlag;
65 | u32 constrainedIntraPredFlag;
66 | u32 redundantPicCntPresentFlag;
67 | } picParamSet_t;
68 |
69 | /*------------------------------------------------------------------------------
70 | 4. Function prototypes
71 | ------------------------------------------------------------------------------*/
72 |
73 | u32 h264bsdDecodePicParamSet(strmData_t *pStrmData,
74 | picParamSet_t *pPicParamSet);
75 |
76 | #endif /* #ifdef H264SWDEC_PIC_PARAM_SET_H */
77 |
78 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_reconstruct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_RECONSTRUCT_H
29 | #define H264SWDEC_RECONSTRUCT_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_macroblock_layer.h"
37 | #include "h264bsd_image.h"
38 |
39 | /*------------------------------------------------------------------------------
40 | 2. Module defines
41 | ------------------------------------------------------------------------------*/
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /*------------------------------------------------------------------------------
48 | 4. Function prototypes
49 | ------------------------------------------------------------------------------*/
50 | #ifndef H264DEC_OMXDL
51 | void h264bsdPredictSamples(
52 | u8 *data,
53 | mv_t *mv,
54 | image_t *refPic,
55 | u32 xA,
56 | u32 yA,
57 | u32 partX,
58 | u32 partY,
59 | u32 partWidth,
60 | u32 partHeight);
61 | #else
62 | void h264bsdPredictSamples(
63 | u8 *data,
64 | mv_t *mv,
65 | image_t *refPic,
66 | u32 colAndRow,/* packaged data | column | row |*/
67 | u32 part, /* packaged data |partX|partY|partWidth|partHeight|*/
68 | u8 *pFill);
69 | #endif
70 |
71 | void h264bsdFillBlock(
72 | u8 * ref,
73 | u8 * fill,
74 | i32 x0,
75 | i32 y0,
76 | u32 width,
77 | u32 height,
78 | u32 blockWidth,
79 | u32 blockHeight,
80 | u32 fillScanLength);
81 |
82 | void h264bsdInterpolateChromaHor(
83 | u8 *pRef,
84 | u8 *predPartChroma,
85 | i32 x0,
86 | i32 y0,
87 | u32 width,
88 | u32 height,
89 | u32 xFrac,
90 | u32 chromaPartWidth,
91 | u32 chromaPartHeight);
92 |
93 | void h264bsdInterpolateChromaVer(
94 | u8 *pRef,
95 | u8 *predPartChroma,
96 | i32 x0,
97 | i32 y0,
98 | u32 width,
99 | u32 height,
100 | u32 yFrac,
101 | u32 chromaPartWidth,
102 | u32 chromaPartHeight);
103 |
104 | void h264bsdInterpolateChromaHorVer(
105 | u8 *ref,
106 | u8 *predPartChroma,
107 | i32 x0,
108 | i32 y0,
109 | u32 width,
110 | u32 height,
111 | u32 xFrac,
112 | u32 yFrac,
113 | u32 chromaPartWidth,
114 | u32 chromaPartHeight);
115 |
116 | void h264bsdInterpolateVerHalf(
117 | u8 *ref,
118 | u8 *mb,
119 | i32 x0,
120 | i32 y0,
121 | u32 width,
122 | u32 height,
123 | u32 partWidth,
124 | u32 partHeight);
125 |
126 | void h264bsdInterpolateVerQuarter(
127 | u8 *ref,
128 | u8 *mb,
129 | i32 x0,
130 | i32 y0,
131 | u32 width,
132 | u32 height,
133 | u32 partWidth,
134 | u32 partHeight,
135 | u32 verOffset);
136 |
137 | void h264bsdInterpolateHorHalf(
138 | u8 *ref,
139 | u8 *mb,
140 | i32 x0,
141 | i32 y0,
142 | u32 width,
143 | u32 height,
144 | u32 partWidth,
145 | u32 partHeight);
146 |
147 | void h264bsdInterpolateHorQuarter(
148 | u8 *ref,
149 | u8 *mb,
150 | i32 x0,
151 | i32 y0,
152 | u32 width,
153 | u32 height,
154 | u32 partWidth,
155 | u32 partHeight,
156 | u32 horOffset);
157 |
158 | void h264bsdInterpolateHorVerQuarter(
159 | u8 *ref,
160 | u8 *mb,
161 | i32 x0,
162 | i32 y0,
163 | u32 width,
164 | u32 height,
165 | u32 partWidth,
166 | u32 partHeight,
167 | u32 horVerOffset);
168 |
169 | void h264bsdInterpolateMidHalf(
170 | u8 *ref,
171 | u8 *mb,
172 | i32 x0,
173 | i32 y0,
174 | u32 width,
175 | u32 height,
176 | u32 partWidth,
177 | u32 partHeight);
178 |
179 | void h264bsdInterpolateMidVerQuarter(
180 | u8 *ref,
181 | u8 *mb,
182 | i32 x0,
183 | i32 y0,
184 | u32 width,
185 | u32 height,
186 | u32 partWidth,
187 | u32 partHeight,
188 | u32 verOffset);
189 |
190 | void h264bsdInterpolateMidHorQuarter(
191 | u8 *ref,
192 | u8 *mb,
193 | i32 x0,
194 | i32 y0,
195 | u32 width,
196 | u32 height,
197 | u32 partWidth,
198 | u32 partHeight,
199 | u32 horOffset);
200 |
201 |
202 | void h264bsdFillRow7(
203 | u8 *ref,
204 | u8 *fill,
205 | i32 left,
206 | i32 center,
207 | i32 right);
208 |
209 | #endif /* #ifdef H264SWDEC_RECONSTRUCT_H */
210 |
211 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_seq_param_set.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_SEQ_PARAM_SET_H
29 | #define H264SWDEC_SEQ_PARAM_SET_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 | #include "h264bsd_vui.h"
38 |
39 | /*------------------------------------------------------------------------------
40 | 2. Module defines
41 | ------------------------------------------------------------------------------*/
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 | /* structure to store sequence parameter set information decoded from the
48 | * stream */
49 | typedef struct
50 | {
51 | u32 profileIdc;
52 | u32 levelIdc;
53 | u32 seqParameterSetId;
54 | u32 maxFrameNum;
55 | u32 picOrderCntType;
56 | u32 maxPicOrderCntLsb;
57 | u32 deltaPicOrderAlwaysZeroFlag;
58 | i32 offsetForNonRefPic;
59 | i32 offsetForTopToBottomField;
60 | u32 numRefFramesInPicOrderCntCycle;
61 | i32 *offsetForRefFrame;
62 | u32 numRefFrames;
63 | u32 gapsInFrameNumValueAllowedFlag;
64 | u32 picWidthInMbs;
65 | u32 picHeightInMbs;
66 | u32 frameCroppingFlag;
67 | u32 frameCropLeftOffset;
68 | u32 frameCropRightOffset;
69 | u32 frameCropTopOffset;
70 | u32 frameCropBottomOffset;
71 | u32 vuiParametersPresentFlag;
72 | vuiParameters_t *vuiParameters;
73 | u32 maxDpbSize;
74 | } seqParamSet_t;
75 |
76 | /*------------------------------------------------------------------------------
77 | 4. Function prototypes
78 | ------------------------------------------------------------------------------*/
79 |
80 | u32 h264bsdDecodeSeqParamSet(strmData_t *pStrmData,
81 | seqParamSet_t *pSeqParamSet);
82 |
83 | u32 h264bsdCompareSeqParamSets(seqParamSet_t *pSps1, seqParamSet_t *pSps2);
84 |
85 | #endif /* #ifdef H264SWDEC_SEQ_PARAM_SET_H */
86 |
87 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_slice_data.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_SLICE_DATA_H
29 | #define H264SWDEC_SLICE_DATA_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 | #include "h264bsd_cfg.h"
38 | #include "h264bsd_slice_header.h"
39 | #include "h264bsd_storage.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 h264bsdDecodeSliceData(strmData_t *pStrmData, storage_t *pStorage,
54 | image_t *currImage, sliceHeader_t *pSliceHeader);
55 |
56 | void h264bsdMarkSliceCorrupted(storage_t *pStorage, u32 firstMbInSlice);
57 |
58 | #endif /* #ifdef H264SWDEC_SLICE_DATA_H */
59 |
60 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_slice_group_map.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_SLICE_GROUP_MAP_H
29 | #define H264SWDEC_SLICE_GROUP_MAP_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_pic_param_set.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 |
43 | /*------------------------------------------------------------------------------
44 | 3. Data types
45 | ------------------------------------------------------------------------------*/
46 |
47 |
48 | /*------------------------------------------------------------------------------
49 | 4. Function prototypes
50 | ------------------------------------------------------------------------------*/
51 |
52 | void h264bsdDecodeSliceGroupMap(
53 | u32 *map,
54 | picParamSet_t *pps,
55 | u32 sliceGroupChangeCycle,
56 | u32 picWidth,
57 | u32 picHeight);
58 |
59 | #endif /* #ifdef H264SWDEC_SLICE_GROUP_MAP_H */
60 |
61 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_slice_header.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_SLICE_HEADER_H
29 | #define H264SWDEC_SLICE_HEADER_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 | #include "h264bsd_cfg.h"
38 | #include "h264bsd_seq_param_set.h"
39 | #include "h264bsd_pic_param_set.h"
40 | #include "h264bsd_nal_unit.h"
41 |
42 | /*------------------------------------------------------------------------------
43 | 2. Module defines
44 | ------------------------------------------------------------------------------*/
45 |
46 | enum {
47 | P_SLICE = 0,
48 | I_SLICE = 2
49 | };
50 |
51 | enum {NO_LONG_TERM_FRAME_INDICES = 0xFFFF};
52 |
53 | /* macro to determine if slice is an inter slice, sliceTypes 0 and 5 */
54 | #define IS_P_SLICE(sliceType) (((sliceType) == P_SLICE) || \
55 | ((sliceType) == P_SLICE + 5))
56 |
57 | /* macro to determine if slice is an intra slice, sliceTypes 2 and 7 */
58 | #define IS_I_SLICE(sliceType) (((sliceType) == I_SLICE) || \
59 | ((sliceType) == I_SLICE + 5))
60 |
61 | /*------------------------------------------------------------------------------
62 | 3. Data types
63 | ------------------------------------------------------------------------------*/
64 |
65 | /* structure to store data of one reference picture list reordering operation */
66 | typedef struct
67 | {
68 | u32 reorderingOfPicNumsIdc;
69 | u32 absDiffPicNum;
70 | u32 longTermPicNum;
71 | } refPicListReorderingOperation_t;
72 |
73 | /* structure to store reference picture list reordering operations */
74 | typedef struct
75 | {
76 | u32 refPicListReorderingFlagL0;
77 | refPicListReorderingOperation_t command[MAX_NUM_REF_PICS+1];
78 | } refPicListReordering_t;
79 |
80 | /* structure to store data of one DPB memory management control operation */
81 | typedef struct
82 | {
83 | u32 memoryManagementControlOperation;
84 | u32 differenceOfPicNums;
85 | u32 longTermPicNum;
86 | u32 longTermFrameIdx;
87 | u32 maxLongTermFrameIdx;
88 | } memoryManagementOperation_t;
89 |
90 | /* worst case scenario: all MAX_NUM_REF_PICS pictures in the buffer are
91 | * short term pictures, each one of them is first marked as long term
92 | * reference picture which is then marked as unused for reference.
93 | * Additionally, max long-term frame index is set and current picture is
94 | * marked as long term reference picture. Last position reserved for
95 | * end memory_management_control_operation command */
96 | #define MAX_NUM_MMC_OPERATIONS (2*MAX_NUM_REF_PICS+2+1)
97 |
98 | /* structure to store decoded reference picture marking data */
99 | typedef struct
100 | {
101 | u32 noOutputOfPriorPicsFlag;
102 | u32 longTermReferenceFlag;
103 | u32 adaptiveRefPicMarkingModeFlag;
104 | memoryManagementOperation_t operation[MAX_NUM_MMC_OPERATIONS];
105 | } decRefPicMarking_t;
106 |
107 | /* structure to store slice header data decoded from the stream */
108 | typedef struct
109 | {
110 | u32 firstMbInSlice;
111 | u32 sliceType;
112 | u32 picParameterSetId;
113 | u32 frameNum;
114 | u32 idrPicId;
115 | u32 picOrderCntLsb;
116 | i32 deltaPicOrderCntBottom;
117 | i32 deltaPicOrderCnt[2];
118 | u32 redundantPicCnt;
119 | u32 numRefIdxActiveOverrideFlag;
120 | u32 numRefIdxL0Active;
121 | i32 sliceQpDelta;
122 | u32 disableDeblockingFilterIdc;
123 | i32 sliceAlphaC0Offset;
124 | i32 sliceBetaOffset;
125 | u32 sliceGroupChangeCycle;
126 | refPicListReordering_t refPicListReordering;
127 | decRefPicMarking_t decRefPicMarking;
128 | } sliceHeader_t;
129 |
130 | /*------------------------------------------------------------------------------
131 | 4. Function prototypes
132 | ------------------------------------------------------------------------------*/
133 |
134 | u32 h264bsdDecodeSliceHeader(strmData_t *pStrmData,
135 | sliceHeader_t *pSliceHeader,
136 | seqParamSet_t *pSeqParamSet,
137 | picParamSet_t *pPicParamSet,
138 | nalUnit_t *pNalUnit);
139 |
140 | u32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *ppsId);
141 |
142 | u32 h264bsdCheckFrameNum(
143 | strmData_t *pStrmData,
144 | u32 maxFrameNum,
145 | u32 *frameNum);
146 |
147 | u32 h264bsdCheckIdrPicId(
148 | strmData_t *pStrmData,
149 | u32 maxFrameNum,
150 | nalUnitType_e nalUnitType,
151 | u32 *idrPicId);
152 |
153 | u32 h264bsdCheckPicOrderCntLsb(
154 | strmData_t *pStrmData,
155 | seqParamSet_t *pSeqParamSet,
156 | nalUnitType_e nalUnitType,
157 | u32 *picOrderCntLsb);
158 |
159 | u32 h264bsdCheckDeltaPicOrderCntBottom(
160 | strmData_t *pStrmData,
161 | seqParamSet_t *pSeqParamSet,
162 | nalUnitType_e nalUnitType,
163 | i32 *deltaPicOrderCntBottom);
164 |
165 | u32 h264bsdCheckDeltaPicOrderCnt(
166 | strmData_t *pStrmData,
167 | seqParamSet_t *pSeqParamSet,
168 | nalUnitType_e nalUnitType,
169 | u32 picOrderPresentFlag,
170 | i32 *deltaPicOrderCnt);
171 |
172 | u32 h264bsdCheckRedundantPicCnt(
173 | strmData_t *pStrmData,
174 | seqParamSet_t *pSeqParamSet,
175 | picParamSet_t *pPicParamSet,
176 | nalUnitType_e nalUnitType,
177 | u32 *redundantPicCnt);
178 |
179 | u32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag,
180 | const strmData_t * pStrmData,
181 | const seqParamSet_t * pSeqParamSet,
182 | const picParamSet_t * pPicParamSet,
183 | nalUnitType_e nalUnitType);
184 |
185 | #endif /* #ifdef H264SWDEC_SLICE_HEADER_H */
186 |
187 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_storage.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_STORAGE_H
29 | #define H264SWDEC_STORAGE_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_cfg.h"
37 | #include "h264bsd_seq_param_set.h"
38 | #include "h264bsd_pic_param_set.h"
39 | #include "h264bsd_macroblock_layer.h"
40 | #include "h264bsd_nal_unit.h"
41 | #include "h264bsd_slice_header.h"
42 | #include "h264bsd_seq_param_set.h"
43 | #include "h264bsd_dpb.h"
44 | #include "h264bsd_pic_order_cnt.h"
45 |
46 | /*------------------------------------------------------------------------------
47 | 2. Module defines
48 | ------------------------------------------------------------------------------*/
49 |
50 | /*------------------------------------------------------------------------------
51 | 3. Data types
52 | ------------------------------------------------------------------------------*/
53 |
54 | typedef struct
55 | {
56 | u32 sliceId;
57 | u32 numDecodedMbs;
58 | u32 lastMbAddr;
59 | } sliceStorage_t;
60 |
61 | /* structure to store parameters needed for access unit boundary checking */
62 | typedef struct
63 | {
64 | nalUnit_t nuPrev[1];
65 | u32 prevFrameNum;
66 | u32 prevIdrPicId;
67 | u32 prevPicOrderCntLsb;
68 | i32 prevDeltaPicOrderCntBottom;
69 | i32 prevDeltaPicOrderCnt[2];
70 | u32 firstCallFlag;
71 | } aubCheck_t;
72 |
73 | /* storage data structure, holds all data of a decoder instance */
74 | typedef struct
75 | {
76 | /* active paramet set ids and pointers */
77 | u32 oldSpsId;
78 | u32 activePpsId;
79 | u32 activeSpsId;
80 | picParamSet_t *activePps;
81 | seqParamSet_t *activeSps;
82 | seqParamSet_t *sps[MAX_NUM_SEQ_PARAM_SETS];
83 | picParamSet_t *pps[MAX_NUM_PIC_PARAM_SETS];
84 |
85 | /* current slice group map, recomputed for each slice */
86 | u32 *sliceGroupMap;
87 |
88 | u32 picSizeInMbs;
89 |
90 | /* this flag is set after all macroblocks of a picture successfully
91 | * decoded -> redundant slices not decoded */
92 | u32 skipRedundantSlices;
93 | u32 picStarted;
94 |
95 | /* flag to indicate if current access unit contains any valid slices */
96 | u32 validSliceInAccessUnit;
97 |
98 | /* store information needed for handling of slice decoding */
99 | sliceStorage_t slice[1];
100 |
101 | /* number of concealed macroblocks in the current image */
102 | u32 numConcealedMbs;
103 |
104 | /* picId given by application */
105 | u32 currentPicId;
106 |
107 | /* macroblock specific storages, size determined by image dimensions */
108 | mbStorage_t *mb;
109 |
110 | /* flag to store noOutputReordering flag set by the application */
111 | u32 noReordering;
112 |
113 | /* DPB */
114 | dpbStorage_t dpb[1];
115 |
116 | /* structure to store picture order count related information */
117 | pocStorage_t poc[1];
118 |
119 | /* access unit boundary checking related data */
120 | aubCheck_t aub[1];
121 |
122 | /* current processed image */
123 | image_t currImage[1];
124 |
125 | /* last valid NAL unit header is stored here */
126 | nalUnit_t prevNalUnit[1];
127 |
128 | /* slice header, second structure used as a temporary storage while
129 | * decoding slice header, first one stores last successfully decoded
130 | * slice header */
131 | sliceHeader_t sliceHeader[2];
132 |
133 | /* fields to store old stream buffer pointers, needed when only part of
134 | * a stream buffer is processed by h264bsdDecode function */
135 | u32 prevBufNotFinished;
136 | u8 *prevBufPointer;
137 | u32 prevBytesConsumed;
138 | strmData_t strm[1];
139 |
140 | /* macroblock layer structure, there is no need to store this but it
141 | * would have increased the stack size excessively and needed to be
142 | * allocated from head -> easiest to put it here */
143 | macroblockLayer_t *mbLayer;
144 |
145 | u32 pendingActivation; /* Activate parameter sets after returning
146 | HEADERS_RDY to the user */
147 | u32 intraConcealmentFlag; /* 0 gray picture for corrupted intra
148 | 1 previous frame used if available */
149 | } storage_t;
150 |
151 | /*------------------------------------------------------------------------------
152 | 4. Function prototypes
153 | ------------------------------------------------------------------------------*/
154 |
155 | void h264bsdInitStorage(storage_t *pStorage);
156 | void h264bsdResetStorage(storage_t *pStorage);
157 | u32 h264bsdIsStartOfPicture(storage_t *pStorage);
158 | u32 h264bsdIsEndOfPicture(storage_t *pStorage);
159 | u32 h264bsdStoreSeqParamSet(storage_t *pStorage, seqParamSet_t *pSeqParamSet);
160 | u32 h264bsdStorePicParamSet(storage_t *pStorage, picParamSet_t *pPicParamSet);
161 | u32 h264bsdActivateParamSets(storage_t *pStorage, u32 ppsId, u32 isIdr);
162 | void h264bsdComputeSliceGroupMap(storage_t *pStorage,
163 | u32 sliceGroupChangeCycle);
164 |
165 | u32 h264bsdCheckAccessUnitBoundary(
166 | strmData_t *strm,
167 | nalUnit_t *nuNext,
168 | storage_t *storage,
169 | u32 *accessUnitBoundaryFlag);
170 |
171 | u32 h264bsdValidParamSets(storage_t *pStorage);
172 |
173 | #endif /* #ifdef H264SWDEC_STORAGE_H */
174 |
175 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_stream.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_STREAM_H
29 | #define H264SWDEC_STREAM_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 |
37 | /*------------------------------------------------------------------------------
38 | 2. Module defines
39 | ------------------------------------------------------------------------------*/
40 |
41 | /*------------------------------------------------------------------------------
42 | 3. Data types
43 | ------------------------------------------------------------------------------*/
44 |
45 | typedef struct
46 | {
47 | u8 *pStrmBuffStart; /* pointer to start of stream buffer */
48 | u8 *pStrmCurrPos; /* current read address in stream buffer */
49 | u32 bitPosInWord; /* bit position in stream buffer byte */
50 | u32 strmBuffSize; /* size of stream buffer (bytes) */
51 | u32 strmBuffReadBits; /* number of bits read from stream buffer */
52 | } strmData_t;
53 |
54 | /*------------------------------------------------------------------------------
55 | 4. Function prototypes
56 | ------------------------------------------------------------------------------*/
57 |
58 | u32 h264bsdGetBits(strmData_t *pStrmData, u32 numBits);
59 |
60 | u32 h264bsdShowBits32(strmData_t *pStrmData);
61 |
62 | u32 h264bsdFlushBits(strmData_t *pStrmData, u32 numBits);
63 |
64 | u32 h264bsdIsByteAligned(strmData_t *);
65 |
66 | #endif /* #ifdef H264SWDEC_STREAM_H */
67 |
68 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_transform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_TRANSFORM_H
29 | #define H264SWDEC_TRANSFORM_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 |
37 | /*------------------------------------------------------------------------------
38 | 2. Module defines
39 | ------------------------------------------------------------------------------*/
40 |
41 | /*------------------------------------------------------------------------------
42 | 3. Data types
43 | ------------------------------------------------------------------------------*/
44 |
45 | /*------------------------------------------------------------------------------
46 | 4. Function prototypes
47 | ------------------------------------------------------------------------------*/
48 |
49 | u32 h264bsdProcessBlock(i32 *data, u32 qp, u32 skip, u32 coeffMap);
50 | void h264bsdProcessLumaDc(i32 *data, u32 qp);
51 | void h264bsdProcessChromaDc(i32 *data, u32 qp);
52 |
53 | #endif /* #ifdef H264SWDEC_TRANSFORM_H */
54 |
55 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_UTIL_H
29 | #define H264SWDEC_UTIL_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #ifdef _ASSERT_USED
36 | #include
37 | #endif
38 |
39 | #include "H264SwDecApi.h"
40 |
41 | #if defined(_RANGE_CHECK) || defined(_DEBUG_PRINT) || defined(_ERROR_PRINT)
42 | #include
43 | #endif
44 |
45 | #include "basetype.h"
46 | #include "h264bsd_stream.h"
47 | #include "h264bsd_image.h"
48 |
49 | /*------------------------------------------------------------------------------
50 | 2. Module defines
51 | ------------------------------------------------------------------------------*/
52 |
53 | #define HANTRO_OK 0
54 | #define HANTRO_NOK 1
55 |
56 | #define HANTRO_TRUE (1)
57 | #define HANTRO_FALSE (0)
58 |
59 | #ifndef NULL
60 | #define NULL 0
61 | #endif
62 |
63 | #define MEMORY_ALLOCATION_ERROR 0xFFFF
64 | #define PARAM_SET_ERROR 0xFFF0
65 |
66 | /* value to be returned by GetBits if stream buffer is empty */
67 | #define END_OF_STREAM 0xFFFFFFFFU
68 |
69 | #define EMPTY_RESIDUAL_INDICATOR 0xFFFFFF
70 |
71 | /* macro to mark a residual block empty, i.e. contain zero coefficients */
72 | #define MARK_RESIDUAL_EMPTY(residual) ((residual)[0] = EMPTY_RESIDUAL_INDICATOR)
73 | /* macro to check if residual block is empty */
74 | #define IS_RESIDUAL_EMPTY(residual) ((residual)[0] == EMPTY_RESIDUAL_INDICATOR)
75 |
76 | /* macro for assertion, used only if compiler flag _ASSERT_USED is defined */
77 | #ifdef _ASSERT_USED
78 | #define ASSERT(expr) assert(expr)
79 | #else
80 | #define ASSERT(expr)
81 | #endif
82 |
83 | /* macro for range checking an value, used only if compiler flag _RANGE_CHECK
84 | * is defined */
85 | #ifdef _RANGE_CHECK
86 | #define RANGE_CHECK(value, minBound, maxBound) \
87 | { \
88 | if ((value) < (minBound) || (value) > (maxBound)) \
89 | fprintf(stderr, "Warning: Value exceeds given limit(s)!\n"); \
90 | }
91 | #else
92 | #define RANGE_CHECK(value, minBound, maxBound)
93 | #endif
94 |
95 | /* macro for range checking an array, used only if compiler flag _RANGE_CHECK
96 | * is defined */
97 | #ifdef _RANGE_CHECK
98 | #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) \
99 | { \
100 | i32 i; \
101 | for (i = 0; i < (length); i++) \
102 | if ((array)[i] < (minBound) || (array)[i] > (maxBound)) \
103 | fprintf(stderr,"Warning: Value [%d] exceeds given limit(s)!\n",i); \
104 | }
105 | #else
106 | #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length)
107 | #endif
108 |
109 | /* macro for debug printing, used only if compiler flag _DEBUG_PRINT is
110 | * defined */
111 | #ifdef _DEBUG_PRINT
112 | #define DEBUG(args) printf args
113 | #else
114 | #define DEBUG(args)
115 | #endif
116 |
117 | /* macro for error printing, used only if compiler flag _ERROR_PRINT is
118 | * defined */
119 | #ifdef _ERROR_PRINT
120 | #define EPRINT(msg) fprintf(stderr,"ERROR: %s\n",msg)
121 | #else
122 | #define EPRINT(msg)
123 | #endif
124 |
125 | /* macro to get smaller of two values */
126 | #define MIN(a, b) (((a) < (b)) ? (a) : (b))
127 |
128 | /* macro to get greater of two values */
129 | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
130 |
131 | /* macro to get absolute value */
132 | // #define ABS(a) (((a) < 0) ? -(a) : (a))
133 | #define ABS(a) (abs(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 | #define CLIP3(x,y,z) (clip(x,y,z))
138 |
139 | /* macro to clip a value z, so that 0 <= z =< 255 */
140 | #define CLIP1(z) (((z) < 0) ? 0 : (((z) > 255) ? 255 : (z)))
141 |
142 | /* macro to allocate memory */
143 | #define ALLOCATE(ptr, count, type) \
144 | { \
145 | (ptr) = H264SwDecMalloc((count) * sizeof(type)); \
146 | }
147 |
148 | /* macro to free allocated memory */
149 | #define FREE(ptr) \
150 | { \
151 | H264SwDecFree((ptr)); (ptr) = NULL; \
152 | }
153 |
154 | #define ALIGN(ptr, bytePos) \
155 | (ptr + ( ((bytePos - (int)ptr) & (bytePos - 1)) / sizeof(*ptr) ))
156 |
157 | extern const u32 h264bsdQpC[52];
158 |
159 | /*------------------------------------------------------------------------------
160 | 3. Data types
161 | ------------------------------------------------------------------------------*/
162 |
163 | /*------------------------------------------------------------------------------
164 | 4. Function prototypes
165 | ------------------------------------------------------------------------------*/
166 | #ifndef H264DEC_NEON
167 | u32 h264bsdCountLeadingZeros(u32 value, u32 length);
168 | #else
169 | u32 h264bsdCountLeadingZeros(u32 value);
170 | #endif
171 | u32 h264bsdRbspTrailingBits(strmData_t *strmData);
172 |
173 | u32 h264bsdMoreRbspData(strmData_t *strmData);
174 |
175 | u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr);
176 |
177 | void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum);
178 |
179 | i32 abs(i32 a);
180 | i32 clip(i32 x, i32 y, i32 z);
181 |
182 | #endif /* #ifdef H264SWDEC_UTIL_H */
183 |
184 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_vlc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_VLC_H
29 | #define H264SWDEC_VLC_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 | #include "h264bsd_transform.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 h264bsdDecodeExpGolombUnsigned(strmData_t *pStrmData, u32 *value);
53 |
54 | u32 h264bsdDecodeExpGolombSigned(strmData_t *pStrmData, i32 *value);
55 |
56 | u32 h264bsdDecodeExpGolombMapped(strmData_t *pStrmData, u32 *value,
57 | u32 isIntra);
58 |
59 | u32 h264bsdDecodeExpGolombTruncated(strmData_t *pStrmData, u32 *value,
60 | u32 greaterThanOne);
61 |
62 | #endif /* #ifdef H264SWDEC_VLC_H */
63 |
64 |
--------------------------------------------------------------------------------
/ems/avc/h264bsd_vui.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*------------------------------------------------------------------------------
18 |
19 | Table of contents
20 |
21 | 1. Include headers
22 | 2. Module defines
23 | 3. Data types
24 | 4. Function prototypes
25 |
26 | ------------------------------------------------------------------------------*/
27 |
28 | #ifndef H264SWDEC_VUI_H
29 | #define H264SWDEC_VUI_H
30 |
31 | /*------------------------------------------------------------------------------
32 | 1. Include headers
33 | ------------------------------------------------------------------------------*/
34 |
35 | #include "basetype.h"
36 | #include "h264bsd_stream.h"
37 |
38 | /*------------------------------------------------------------------------------
39 | 2. Module defines
40 | ------------------------------------------------------------------------------*/
41 |
42 | #define MAX_CPB_CNT 32
43 |
44 | /*------------------------------------------------------------------------------
45 | 3. Data types
46 | ------------------------------------------------------------------------------*/
47 |
48 | /* enumerated sample aspect ratios, ASPECT_RATIO_M_N means M:N */
49 | enum
50 | {
51 | ASPECT_RATIO_UNSPECIFIED = 0,
52 | ASPECT_RATIO_1_1,
53 | ASPECT_RATIO_12_11,
54 | ASPECT_RATIO_10_11,
55 | ASPECT_RATIO_16_11,
56 | ASPECT_RATIO_40_33,
57 | ASPECT_RATIO_24_11,
58 | ASPECT_RATIO_20_11,
59 | ASPECT_RATIO_32_11,
60 | ASPECT_RATIO_80_33,
61 | ASPECT_RATIO_18_11,
62 | ASPECT_RATIO_15_11,
63 | ASPECT_RATIO_64_33,
64 | ASPECT_RATIO_160_99,
65 | ASPECT_RATIO_EXTENDED_SAR = 255
66 | };
67 |
68 | /* structure to store Hypothetical Reference Decoder (HRD) parameters */
69 | typedef struct
70 | {
71 | u32 cpbCnt;
72 | u32 bitRateScale;
73 | u32 cpbSizeScale;
74 | u32 bitRateValue[MAX_CPB_CNT];
75 | u32 cpbSizeValue[MAX_CPB_CNT];
76 | u32 cbrFlag[MAX_CPB_CNT];
77 | u32 initialCpbRemovalDelayLength;
78 | u32 cpbRemovalDelayLength;
79 | u32 dpbOutputDelayLength;
80 | u32 timeOffsetLength;
81 | } hrdParameters_t;
82 |
83 | /* storage for VUI parameters */
84 | typedef struct
85 | {
86 | u32 aspectRatioPresentFlag;
87 | u32 aspectRatioIdc;
88 | u32 sarWidth;
89 | u32 sarHeight;
90 | u32 overscanInfoPresentFlag;
91 | u32 overscanAppropriateFlag;
92 | u32 videoSignalTypePresentFlag;
93 | u32 videoFormat;
94 | u32 videoFullRangeFlag;
95 | u32 colourDescriptionPresentFlag;
96 | u32 colourPrimaries;
97 | u32 transferCharacteristics;
98 | u32 matrixCoefficients;
99 | u32 chromaLocInfoPresentFlag;
100 | u32 chromaSampleLocTypeTopField;
101 | u32 chromaSampleLocTypeBottomField;
102 | u32 timingInfoPresentFlag;
103 | u32 numUnitsInTick;
104 | u32 timeScale;
105 | u32 fixedFrameRateFlag;
106 | u32 nalHrdParametersPresentFlag;
107 | hrdParameters_t nalHrdParameters;
108 | u32 vclHrdParametersPresentFlag;
109 | hrdParameters_t vclHrdParameters;
110 | u32 lowDelayHrdFlag;
111 | u32 picStructPresentFlag;
112 | u32 bitstreamRestrictionFlag;
113 | u32 motionVectorsOverPicBoundariesFlag;
114 | u32 maxBytesPerPicDenom;
115 | u32 maxBitsPerMbDenom;
116 | u32 log2MaxMvLengthHorizontal;
117 | u32 log2MaxMvLengthVertical;
118 | u32 numReorderFrames;
119 | u32 maxDecFrameBuffering;
120 | } vuiParameters_t;
121 |
122 | /*------------------------------------------------------------------------------
123 | 4. Function prototypes
124 | ------------------------------------------------------------------------------*/
125 |
126 | u32 h264bsdDecodeVuiParameters(strmData_t *pStrmData,
127 | vuiParameters_t *pVuiParameters);
128 |
129 | #endif /* #ifdef H264SWDEC_VUI_H */
130 |
131 |
--------------------------------------------------------------------------------
/ems/g72x/adpcm_js.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "g72x.h"
3 |
4 | static g726_state g726State;
5 | static int initFlag = 0;
6 |
7 | int adpcmDecode(unsigned char *inBuffer, int length, unsigned char *pcmData) {
8 | if ( initFlag == 0) {
9 | initFlag = 1;
10 | g726_init_state(&g726State);
11 | }
12 |
13 | int j = 0;
14 | for(int i = 0; i < length; i++) {
15 | unsigned char code;
16 | unsigned short pcm;
17 |
18 | code = inBuffer[i] & 0x0F;
19 | pcm = g726_32_decoder(code, AUDIO_ENCODING_LINEAR, &g726State);
20 | ((unsigned short *)pcmData)[j] = pcm;
21 | j++;
22 |
23 | code = inBuffer[i] & 0xF0;
24 | code = code >> 4;
25 | pcm = g726_32_decoder(code, AUDIO_ENCODING_LINEAR, &g726State);
26 | ((unsigned short *)pcmData)[j] = pcm;
27 | j++;
28 | }
29 | return j;
30 |
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/ems/g72x/g726_16.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 | /* 16kbps version created, used 24kbps code and changing as little as possible.
27 | * G.726 specs are available from ITU's gopher or WWW site (http://www.itu.ch)
28 | * If any errors are found, please contact me at mrand@tamu.edu
29 | * -Marc Randolph
30 | */
31 |
32 | /*
33 | * g726_16.c
34 | *
35 | * Description:
36 | *
37 | * g723_16_encoder(), g723_16_decoder()
38 | *
39 | * These routines comprise an implementation of the CCITT G.726 16 Kbps
40 | * ADPCM coding algorithm. Essentially, this implementation is identical to
41 | * the bit level description except for a few deviations which take advantage
42 | * of workstation attributes, such as hardware 2's complement arithmetic.
43 | *
44 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
45 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
46 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
47 | * This coder operates on a sample-by-sample basis. Input samples may be
48 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
49 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
50 | * 4-bit quantized difference signal resulting in a compression ratio of
51 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
52 | * difference signal is 3 bits and 5 bits, respectively.
53 | *
54 | * $Revision: 1.1 $
55 | * $Author: shorne $
56 | * $Date: 2010/02/24 02:19:05 $
57 | */
58 | #include "g72x.h"
59 | #include "private.h"
60 |
61 | /*
62 | * Maps G.723_16 code word to reconstructed scale factor normalized log
63 | * magnitude values. Comes from Table 11/G.726
64 | */
65 | static short _dqlntab[4] = { 116, 365, 365, 116};
66 |
67 | /* Maps G.723_16 code word to log of scale factor multiplier.
68 | *
69 | * _witab[4] is actually {-22 , 439, 439, -22}, but FILTD wants it
70 | * as WI << 5 (multiplied by 32), so we'll do that here
71 | */
72 | static short _witab[4] = {-704, 14048, 14048, -704};
73 |
74 | /*
75 | * Maps G.723_16 code words to a set of values whose long and short
76 | * term averages are computed and then compared to give an indication
77 | * how stationary (steady state) the signal is.
78 | */
79 |
80 | /* Comes from FUNCTF */
81 | static short _fitab[4] = {0, 0xE00, 0xE00, 0};
82 |
83 | /* Comes from quantizer decision level tables (Table 7/G.726)
84 | */
85 | static int qtab_723_16[1] = {261};
86 |
87 |
88 | /*
89 | * g723_16_encoder()
90 | *
91 | * Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit code.
92 | * Returns -1 if invalid input coding value.
93 | */
94 | int
95 | g726_16_encoder(
96 | int sl,
97 | int in_coding,
98 | g726_state *state_ptr)
99 | {
100 | int sezi;
101 | int sez; /* ACCUM */
102 | int sei;
103 | int se;
104 | int d; /* SUBTA */
105 | int y; /* MIX */
106 | int i;
107 | int dq;
108 | int sr; /* ADDB */
109 | int dqsez; /* ADDC */
110 |
111 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
112 | case AUDIO_ENCODING_ALAW:
113 | sl = alaw2linear(sl) >> 2;
114 | break;
115 | case AUDIO_ENCODING_ULAW:
116 | sl = ulaw2linear(sl) >> 2;
117 | break;
118 | case AUDIO_ENCODING_LINEAR:
119 | sl >>= 2; /* sl of 14-bit dynamic range */
120 | break;
121 | default:
122 | return (-1);
123 | }
124 |
125 | sezi = predictor_zero(state_ptr);
126 | sez = sezi >> 1;
127 | sei = sezi + predictor_pole(state_ptr);
128 | se = sei >> 1; /* se = estimated signal */
129 |
130 | d = sl - se; /* d = estimation diff. */
131 |
132 | /* quantize prediction difference d */
133 | y = step_size(state_ptr); /* quantizer step size */
134 | i = quantize(d, y, qtab_723_16, 1); /* i = ADPCM code */
135 |
136 | /* Since quantize() only produces a three level output
137 | * (1, 2, or 3), we must create the fourth one on our own
138 | */
139 | if (i == 3) /* i code for the zero region */
140 | if ((d & 0x8000) == 0) /* If d > 0, i=3 isn't right... */
141 | i = 0;
142 |
143 | dq = reconstruct(i & 2, _dqlntab[i], y); /* quantized diff. */
144 |
145 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */
146 |
147 | dqsez = sr + sez - se; /* pole prediction diff. */
148 |
149 | update(2, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
150 |
151 | return (i);
152 | }
153 |
154 | /*
155 | * g723_16_decoder()
156 | *
157 | * Decodes a 2-bit CCITT G.723_16 ADPCM code and returns
158 | * the resulting 16-bit linear PCM, A-law or u-law sample value.
159 | * -1 is returned if the output coding is unknown.
160 | */
161 | int
162 | g726_16_decoder(
163 | int i,
164 | int out_coding,
165 | g726_state *state_ptr)
166 | {
167 | int sezi;
168 | int sez; /* ACCUM */
169 | int sei;
170 | int se;
171 | int y; /* MIX */
172 | int dq;
173 | int sr; /* ADDB */
174 | int dqsez;
175 |
176 | i &= 0x03; /* mask to get proper bits */
177 | sezi = predictor_zero(state_ptr);
178 | sez = sezi >> 1;
179 | sei = sezi + predictor_pole(state_ptr);
180 | se = sei >> 1; /* se = estimated signal */
181 |
182 | y = step_size(state_ptr); /* adaptive quantizer step size */
183 | dq = reconstruct(i & 0x02, _dqlntab[i], y); /* unquantize pred diff */
184 |
185 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */
186 |
187 | dqsez = sr - se + sez; /* pole prediction diff. */
188 |
189 | update(2, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
190 |
191 | switch (out_coding) {
192 | case AUDIO_ENCODING_ALAW:
193 | return (tandem_adjust_alaw(sr, se, y, i, 2, qtab_723_16));
194 | case AUDIO_ENCODING_ULAW:
195 | return (tandem_adjust_ulaw(sr, se, y, i, 2, qtab_723_16));
196 | case AUDIO_ENCODING_LINEAR:
197 | return (sr << 2); /* sr was of 14-bit dynamic range */
198 | default:
199 | return (-1);
200 | }
201 | }
202 |
203 |
--------------------------------------------------------------------------------
/ems/g72x/g726_24.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g726_24.c
29 | *
30 | * Description:
31 | *
32 | * g723_24_encoder(), g723_24_decoder()
33 | *
34 | * These routines comprise an implementation of the CCITT G.723 24 Kbps
35 | * ADPCM coding algorithm. Essentially, this implementation is identical to
36 | * the bit level description except for a few deviations which take advantage
37 | * of workstation attributes, such as hardware 2's complement arithmetic.
38 | *
39 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
40 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
41 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
42 | * This coder operates on a sample-by-sample basis. Input samples may be
43 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
44 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
45 | * 4-bit quantized difference signal resulting in a compression ratio of
46 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
47 | * difference signal is 3 bits and 5 bits, respectively.
48 | *
49 | * $Revision: 1.1 $
50 | * $Author: shorne $
51 | * $Date: 2010/02/24 02:19:05 $
52 | */
53 | #include "g72x.h"
54 | #include "private.h"
55 |
56 | /*
57 | * Maps G.723_24 code word to reconstructed scale factor normalized log
58 | * magnitude values.
59 | */
60 | static short _dqlntab[8] = {-2048, 135, 273, 373, 373, 273, 135, -2048};
61 |
62 | /* Maps G.723_24 code word to log of scale factor multiplier. */
63 | static short _witab[8] = {-128, 960, 4384, 18624, 18624, 4384, 960, -128};
64 |
65 | /*
66 | * Maps G.723_24 code words to a set of values whose long and short
67 | * term averages are computed and then compared to give an indication
68 | * how stationary (steady state) the signal is.
69 | */
70 | static short _fitab[8] = {0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0};
71 |
72 | static int qtab_723_24[3] = {8, 218, 331};
73 |
74 | /*
75 | * g723_24_encoder()
76 | *
77 | * Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit code.
78 | * Returns -1 if invalid input coding value.
79 | */
80 | int
81 | g726_24_encoder(
82 | int sl,
83 | int in_coding,
84 | g726_state *state_ptr)
85 | {
86 | int sezi;
87 | int sei;
88 | int sez; /* ACCUM */
89 | int se;
90 | int d; /* SUBTA */
91 | int y; /* MIX */
92 | int i;
93 | int dq;
94 | int sr; /* ADDB */
95 | int dqsez; /* ADDC */
96 |
97 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
98 | case AUDIO_ENCODING_ALAW:
99 | sl = alaw2linear(sl) >> 2;
100 | break;
101 | case AUDIO_ENCODING_ULAW:
102 | sl = ulaw2linear(sl) >> 2;
103 | break;
104 | case AUDIO_ENCODING_LINEAR:
105 | sl >>= 2; /* sl of 14-bit dynamic range */
106 | break;
107 | default:
108 | return (-1);
109 | }
110 |
111 | sezi = predictor_zero(state_ptr);
112 | sez = sezi >> 1;
113 | sei = sezi + predictor_pole(state_ptr);
114 | se = sei >> 1; /* se = estimated signal */
115 |
116 | d = sl - se; /* d = estimation diff. */
117 |
118 | /* quantize prediction difference d */
119 | y = step_size(state_ptr); /* quantizer step size */
120 | i = quantize(d, y, qtab_723_24, 3); /* i = ADPCM code */
121 | dq = reconstruct(i & 4, _dqlntab[i], y); /* quantized diff. */
122 |
123 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */
124 |
125 | dqsez = sr + sez - se; /* pole prediction diff. */
126 |
127 | update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
128 |
129 | return (i);
130 | }
131 |
132 | /*
133 | * g723_24_decoder()
134 | *
135 | * Decodes a 3-bit CCITT G.723_24 ADPCM code and returns
136 | * the resulting 16-bit linear PCM, A-law or u-law sample value.
137 | * -1 is returned if the output coding is unknown.
138 | */
139 | int
140 | g726_24_decoder(
141 | int i,
142 | int out_coding,
143 | g726_state *state_ptr)
144 | {
145 | int sezi;
146 | int sez; /* ACCUM */
147 | int sei;
148 | int se;
149 | int y; /* MIX */
150 | int dq;
151 | int sr; /* ADDB */
152 | int dqsez;
153 |
154 | i &= 0x07; /* mask to get proper bits */
155 | sezi = predictor_zero(state_ptr);
156 | sez = sezi >> 1;
157 | sei = sezi + predictor_pole(state_ptr);
158 | se = sei >> 1; /* se = estimated signal */
159 |
160 | y = step_size(state_ptr); /* adaptive quantizer step size */
161 | dq = reconstruct(i & 0x04, _dqlntab[i], y); /* unquantize pred diff */
162 |
163 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */
164 |
165 | dqsez = sr - se + sez; /* pole prediction diff. */
166 |
167 | update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
168 |
169 | switch (out_coding) {
170 | case AUDIO_ENCODING_ALAW:
171 | return (tandem_adjust_alaw(sr, se, y, i, 4, qtab_723_24));
172 | case AUDIO_ENCODING_ULAW:
173 | return (tandem_adjust_ulaw(sr, se, y, i, 4, qtab_723_24));
174 | case AUDIO_ENCODING_LINEAR:
175 | return (sr << 2); /* sr was of 14-bit dynamic range */
176 | default:
177 | return (-1);
178 | }
179 | }
180 |
181 |
--------------------------------------------------------------------------------
/ems/g72x/g726_32.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g726_32.c
29 | *
30 | * Description:
31 | *
32 | * g721_encoder(), g721_decoder()
33 | *
34 | * These routines comprise an implementation of the CCITT G.721 ADPCM
35 | * coding algorithm. Essentially, this implementation is identical to
36 | * the bit level description except for a few deviations which
37 | * take advantage of work station attributes, such as hardware 2's
38 | * complement arithmetic and large memory. Specifically, certain time
39 | * consuming operations such as multiplications are replaced
40 | * with lookup tables and software 2's complement operations are
41 | * replaced with hardware 2's complement.
42 | *
43 | * The deviation from the bit level specification (lookup tables)
44 | * preserves the bit level performance specifications.
45 | *
46 | * As outlined in the G.721 Recommendation, the algorithm is broken
47 | * down into modules. Each section of code below is preceded by
48 | * the name of the module which it is implementing.
49 | *
50 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
51 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
52 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
53 | * This coder operates on a sample-by-sample basis. Input samples may be
54 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
55 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
56 | * 4-bit quantized difference signal resulting in a compression ratio of
57 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
58 | * difference signal is 3 bits and 5 bits, respectively.
59 | *
60 | * $Revision: 1.1 $
61 | * $Author: shorne $
62 | * $Date: 2010/02/24 02:19:05 $
63 | */
64 | #include "g72x.h"
65 | #include "private.h"
66 |
67 | static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
68 | /*
69 | * Maps G.721 code word to reconstructed scale factor normalized log
70 | * magnitude values.
71 | */
72 | static short _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
73 | 425, 373, 323, 273, 213, 135, 4, -2048};
74 |
75 | /* Maps G.721 code word to log of scale factor multiplier. */
76 | static short _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
77 | 1122, 355, 198, 112, 64, 41, 18, -12};
78 | /*
79 | * Maps G.721 code words to a set of values whose long and short
80 | * term averages are computed and then compared to give an indication
81 | * how stationary (steady state) the signal is.
82 | */
83 | static short _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
84 | 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
85 |
86 | /*
87 | * g721_encoder()
88 | *
89 | * Encodes the input vale of linear PCM, A-law or u-law data sl and returns
90 | * the resulting code. -1 is returned for unknown input coding value.
91 | */
92 | int
93 | g726_32_encoder(
94 | int sl,
95 | int in_coding,
96 | g726_state *state_ptr)
97 | {
98 | int sezi;
99 | int sez; /* ACCUM */
100 | int se;
101 | int d; /* SUBTA */
102 | int y; /* MIX */
103 | int i;
104 | int dq;
105 | int sr; /* ADDB */
106 | int dqsez; /* ADDC */
107 |
108 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
109 | case AUDIO_ENCODING_ALAW:
110 | sl = alaw2linear(sl) >> 2;
111 | break;
112 | case AUDIO_ENCODING_ULAW:
113 | sl = ulaw2linear(sl) >> 2;
114 | break;
115 | case AUDIO_ENCODING_LINEAR:
116 | sl >>= 2; /* 14-bit dynamic range */
117 | break;
118 | default:
119 | return (-1);
120 | }
121 |
122 | sezi = predictor_zero(state_ptr);
123 | sez = sezi >> 1;
124 | se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
125 |
126 | d = sl - se; /* estimation difference */
127 |
128 | /* quantize the prediction difference */
129 | y = step_size(state_ptr); /* quantizer step size */
130 | i = quantize(d, y, qtab_721, 7); /* i = ADPCM code */
131 |
132 | dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
133 |
134 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
135 |
136 | dqsez = sr + sez - se; /* pole prediction diff. */
137 |
138 | update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
139 |
140 | return (i);
141 | }
142 |
143 | /*
144 | * g721_decoder()
145 | *
146 | * Description:
147 | *
148 | * Decodes a 4-bit code of G.721 encoded data of i and
149 | * returns the resulting linear PCM, A-law or u-law value.
150 | * return -1 for unknown out_coding value.
151 | */
152 | int
153 | g726_32_decoder(
154 | int i,
155 | int out_coding,
156 | g726_state *state_ptr)
157 | {
158 | int sezi;
159 | int sez; /* ACCUM */
160 | int sei;
161 | int se;
162 | int y; /* MIX */
163 | int dq;
164 | int sr; /* ADDB */
165 | int dqsez;
166 | long lino;
167 |
168 | i &= 0x0f; /* mask to get proper bits */
169 | sezi = predictor_zero(state_ptr);
170 | sez = sezi >> 1;
171 | sei = sezi + predictor_pole(state_ptr);
172 | se = sei >> 1; /* se = estimated signal */
173 |
174 | y = step_size(state_ptr); /* dynamic quantizer step size */
175 |
176 | dq = reconstruct(i & 0x08, _dqlntab[i], y); /* quantized diff. */
177 |
178 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : se + dq; /* reconst. signal */
179 |
180 | dqsez = sr - se + sez; /* pole prediction diff. */
181 |
182 | update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
183 |
184 | switch (out_coding) {
185 | case AUDIO_ENCODING_ALAW:
186 | return (tandem_adjust_alaw(sr, se, y, i, 8, qtab_721));
187 | case AUDIO_ENCODING_ULAW:
188 | return (tandem_adjust_ulaw(sr, se, y, i, 8, qtab_721));
189 | case AUDIO_ENCODING_LINEAR:
190 | lino = (long)sr << 2; /* this seems to overflow a short*/
191 | lino = lino > 32767 ? 32767 : lino;
192 | lino = lino < -32768 ? -32768 : lino;
193 | return lino;//(sr << 2); /* sr was 14-bit dynamic range */
194 | default:
195 | return (-1);
196 | }
197 | }
198 |
199 |
--------------------------------------------------------------------------------
/ems/g72x/g72x.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g72x.h
29 | *
30 | * Header file for CCITT conversion routines.
31 | *
32 | */
33 | #ifndef _G72X_H
34 | #define _G72X_H
35 |
36 | #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */
37 | #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */
38 | #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */
39 |
40 | /*
41 | * The following is the definition of the state structure
42 | * used by the G.721/G.723 encoder and decoder to preserve their internal
43 | * state between successive calls. The meanings of the majority
44 | * of the state structure fields are explained in detail in the
45 | * CCITT Recommendation G.721. The field names are essentially indentical
46 | * to variable names in the bit level description of the coding algorithm
47 | * included in this Recommendation.
48 | */
49 | typedef struct g726_state_s {
50 | long yl; /* Locked or steady state step size multiplier. */
51 | int yu; /* Unlocked or non-steady state step size multiplier. */
52 | int dms; /* Short term energy estimate. */
53 | int dml; /* Long term energy estimate. */
54 | int ap; /* Linear weighting coefficient of 'yl' and 'yu'. */
55 |
56 | int a[2]; /* Coefficients of pole portion of prediction filter. */
57 | int b[6]; /* Coefficients of zero portion of prediction filter. */
58 | int pk[2]; /* Signs of previous two samples of a partially
59 | * reconstructed signal. */
60 | short dq[6];/* int here fails in newupdate on encode!
61 | * Previous 6 samples of the quantized difference
62 | * signal represented in an internal floating point
63 | * format.
64 | */
65 | int sr[2]; /* Previous 2 samples of the quantized difference
66 | * signal represented in an internal floating point
67 | * format. */
68 | int td; /* delayed tone detect, new in 1988 version */
69 | } g726_state;
70 |
71 | /* External function definitions. */
72 |
73 | void g726_init_state( g726_state *);
74 |
75 | int g726_32_encoder(
76 | int sample,
77 | int in_coding,
78 | g726_state *state_ptr);
79 | int g726_32_decoder(
80 | int code,
81 | int out_coding,
82 | g726_state *state_ptr);
83 | int g726_16_encoder(
84 | int sample,
85 | int in_coding,
86 | g726_state *state_ptr);
87 | int g726_16_decoder(
88 | int code,
89 | int out_coding,
90 | g726_state *state_ptr);
91 | int g726_24_encoder(
92 | int sample,
93 | int in_coding,
94 | g726_state *state_ptr);
95 | int g726_24_decoder(
96 | int code,
97 | int out_coding,
98 | g726_state *state_ptr);
99 | int g726_40_encoder(
100 | int sample,
101 | int in_coding,
102 | g726_state *state_ptr);
103 | int g726_40_decoder(
104 | int code,
105 | int out_coding,
106 | g726_state *state_ptr);
107 |
108 | #endif /* !_G72X_H */
109 |
110 |
--------------------------------------------------------------------------------
/ems/g72x/private.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * $Revision: 1.1 $
4 | * $Author: shorne $
5 | * $Date: 2010/02/24 02:19:05 $
6 | */
7 | #if !defined G726_PRIVATE
8 | #define G726_PRIVATE
9 |
10 | int linear2ulaw(int pcm_val);
11 | int ulaw2linear(int u_val);
12 | int linear2alaw(int pcm_val);
13 | int alaw2linear(int u_val);
14 |
15 | static int fmult(int an, int srn);
16 | int predictor_zero( g726_state *state_ptr);
17 | int predictor_pole( g726_state *state_ptr);
18 | int step_size( g726_state *state_ptr);
19 | int quantize( int d, /* Raw difference signal sample */
20 | int y, /* Step size multiplier */
21 | int * table, /* quantization table */
22 | int size); /* table size of short integers */
23 | int reconstruct( int sign, /* 0 for non-negative value */
24 | int dqln, /* G.72x codeword */
25 | int y); /* Step size multiplier */
26 | void update( int code_size, /* distinguish 723_40 with others */
27 | int y, /* quantizer step size */
28 | int wi, /* scale factor multiplier */
29 | int fi, /* for long/short term energies */
30 | int dq, /* quantized prediction difference */
31 | int sr, /* reconstructed signal */
32 | int dqsez, /* difference from 2-pole predictor */
33 | g726_state *state_ptr); /* coder state pointer */
34 | int tandem_adjust_alaw(
35 | int sr, /* decoder output linear PCM sample */
36 | int se, /* predictor estimate sample */
37 | int y, /* quantizer step size */
38 | int i, /* decoder input code */
39 | int sign,
40 | int * qtab);
41 | int tandem_adjust_ulaw(
42 | int sr, /* decoder output linear PCM sample */
43 | int se, /* predictor estimate sample */
44 | int y, /* quantizer step size */
45 | int i, /* decoder input code */
46 | int sign,
47 | int * qtab);
48 |
49 | #endif // G726_PRIVATE
50 |
51 |
--------------------------------------------------------------------------------
/ems/library.js:
--------------------------------------------------------------------------------
1 | var LibraryBroadway = {
2 | broadwayOnHeadersDecoded: function () {
3 | window["_broadwayOnHeadersDecoded"]();
4 | },
5 | broadwayOnPictureDecoded: function ($buffer, width, height) {
6 | window["_broadwayOnPictureDecoded"]($buffer, width, height);
7 | }
8 | };
9 |
10 | mergeInto(LibraryManager.library, LibraryBroadway);
11 |
--------------------------------------------------------------------------------
/ems/make.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import os, sys, re, json, shutil
4 | from subprocess import Popen, PIPE, STDOUT
5 |
6 | exec(open(os.path.expanduser('~/.emscripten'), 'r').read())
7 |
8 | sys.path.append(EMSCRIPTEN_ROOT)
9 | import tools.shared as emscripten
10 |
11 | emcc_args = [
12 | '-m32',
13 | '-O2',
14 | '--llvm-opts', '2',
15 | '-s', 'CORRECT_SIGNS=1',
16 | '-s', 'CORRECT_OVERFLOWS=1',
17 | '-s', 'TOTAL_MEMORY=' + str(64*1024*1024),
18 | '-s', 'FAST_MEMORY=' + str(16*1024*1024),
19 | '-s', 'INVOKE_RUN=0',
20 | '-s', 'RELOOP=1',
21 | '-s', '''EXPORTED_FUNCTIONS=["HEAP8", "HEAP16", "HEAP32", "_get_h264bsdClip", "_main", "_broadwayGetMajorVersion", "_broadwayGetMinorVersion", "_broadwayInit", "_broadwayExit", "_broadwayCreateStream", "_broadwaySetStreamLength", "_broadwayPlayStream", "_broadwayOnHeadersDecoded", "_broadwayOnPictureDecoded", "_initRaptor", "_releaseRaptor","_pushSymbol", "_doDecode", "_getSymbol", "_buildPayload", "_adpcmDecode"]''',
22 | '--closure', '1',
23 | '--js-library', 'library.js',
24 | # '--js-transform', 'python appender.py'
25 | '--memory-init-file', '0'
26 | ]
27 |
28 | JS_DIR = "js"
29 | if not os.path.exists(JS_DIR):
30 | os.makedirs(JS_DIR)
31 |
32 | OBJ_DIR = "obj"
33 | if not os.path.exists(OBJ_DIR):
34 | os.makedirs(OBJ_DIR)
35 | os.makedirs(OBJ_DIR + "/avc")
36 | os.makedirs(OBJ_DIR + "/raptor")
37 | os.makedirs(OBJ_DIR + "/g72x")
38 |
39 | print 'build'
40 |
41 | source_files = [
42 | 'avc/h264bsd_transform.c',
43 | 'avc/h264bsd_util.c',
44 | 'avc/h264bsd_byte_stream.c',
45 | 'avc/h264bsd_seq_param_set.c',
46 | 'avc/h264bsd_pic_param_set.c',
47 | 'avc/h264bsd_slice_header.c',
48 | 'avc/h264bsd_slice_data.c',
49 | 'avc/h264bsd_macroblock_layer.c',
50 | 'avc/h264bsd_stream.c',
51 | 'avc/h264bsd_vlc.c',
52 | 'avc/h264bsd_cavlc.c',
53 | 'avc/h264bsd_nal_unit.c',
54 | 'avc/h264bsd_neighbour.c',
55 | 'avc/h264bsd_storage.c',
56 | 'avc/h264bsd_slice_group_map.c',
57 | 'avc/h264bsd_intra_prediction.c',
58 | 'avc/h264bsd_inter_prediction.c',
59 | 'avc/h264bsd_reconstruct.c',
60 | 'avc/h264bsd_dpb.c',
61 | 'avc/h264bsd_image.c',
62 | 'avc/h264bsd_deblocking.c',
63 | 'avc/h264bsd_conceal.c',
64 | 'avc/h264bsd_vui.c',
65 | 'avc/h264bsd_pic_order_cnt.c',
66 | 'avc/h264bsd_decoder.c',
67 | 'avc/H264SwDecApi.c',
68 | 'avc/Decoder.c',
69 | 'g72x/adpcm_js.c',
70 | 'g72x/g711.c',
71 | 'g72x/g726_32.c',
72 | 'g72x/g72x.c']
73 |
74 | object_files = []
75 | for file in source_files:
76 |
77 | target = file.replace('.c', '.o')
78 | if file.endswith('.cpp') :
79 | target = file.replace('.cpp', '.o')
80 |
81 | target = os.path.join('obj', target)
82 | print 'emcc %s -> %s' % (file, target)
83 | emscripten.Building.emcc(file, emcc_args + ['-Iavc-inc'], target)
84 | object_files = object_files + [ target]
85 |
86 | print 'link -> %s' % 'avc.bc'
87 | emscripten.Building.link(object_files, 'avc.bc')
88 |
89 | print 'emcc %s -> %s' % ('avc.bc', os.path.join(JS_DIR, 'module.js'))
90 | emscripten.Building.emcc('avc.bc', emcc_args, os.path.join(JS_DIR, 'module.js'))
91 |
--------------------------------------------------------------------------------
/ems/obj/avc/Decoder.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/Decoder.o
--------------------------------------------------------------------------------
/ems/obj/avc/H264SwDecApi.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/H264SwDecApi.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_byte_stream.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_byte_stream.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_cavlc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_cavlc.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_conceal.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_conceal.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_deblocking.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_deblocking.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_decoder.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_decoder.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_dpb.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_dpb.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_image.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_image.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_inter_prediction.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_inter_prediction.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_intra_prediction.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_intra_prediction.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_macroblock_layer.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_macroblock_layer.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_nal_unit.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_nal_unit.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_neighbour.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_neighbour.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_pic_order_cnt.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_pic_order_cnt.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_pic_param_set.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_pic_param_set.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_reconstruct.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_reconstruct.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_seq_param_set.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_seq_param_set.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_slice_data.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_slice_data.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_slice_group_map.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_slice_group_map.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_slice_header.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_slice_header.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_storage.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_storage.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_stream.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_stream.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_transform.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_transform.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_util.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_util.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_vlc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_vlc.o
--------------------------------------------------------------------------------
/ems/obj/avc/h264bsd_vui.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/avc/h264bsd_vui.o
--------------------------------------------------------------------------------
/ems/obj/g72x/adpcm_js.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/g72x/adpcm_js.o
--------------------------------------------------------------------------------
/ems/obj/g72x/g711.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/g72x/g711.o
--------------------------------------------------------------------------------
/ems/obj/g72x/g726_32.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/g72x/g726_32.o
--------------------------------------------------------------------------------
/ems/obj/g72x/g72x.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/ems/obj/g72x/g72x.o
--------------------------------------------------------------------------------
/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | MY_LOCAL_PATH = $(LOCAL_PATH)
3 |
4 | ###########################################################
5 | # building x264 library
6 | #
7 | include $(CLEAR_VARS)
8 | LOCAL_MODULE := libx264_pre
9 | LOCAL_SRC_FILES := x264/libx264.a
10 | include $(PREBUILT_STATIC_LIBRARY)
11 |
12 | ###########################################################
13 | # building application library
14 | #
15 | include $(CLEAR_VARS)
16 | LOCAL_MODULE := libMediaEncoder
17 | LOCAL_CPP_EXTENSION := .cc .cpp
18 | LOCAL_CPPFLAGS := -O2 -Werror -Wall
19 | LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)
20 | LOCAL_SRC_FILES := main_jni.cpp \
21 | h264encoder.cpp \
22 | g72x/g726_32.c \
23 | g72x/g711.c \
24 | g72x/g72x.c
25 |
26 | LOCAL_LDLIBS += -llog -lz
27 | LOCAL_SHARED_LIBRARIES := libcutils\
28 | libgnustl\
29 | libdl
30 |
31 | LOCAL_STATIC_LIBRARIES := libx264_pre
32 |
33 | include $(BUILD_SHARED_LIBRARY)
34 |
35 |
--------------------------------------------------------------------------------
/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_PLATFORM := android-9
2 | APP_STL := stlport_static
3 | APP_ABI := armeabi armeabi-v7a
4 |
--------------------------------------------------------------------------------
/jni/build_x264.md:
--------------------------------------------------------------------------------
1 | ## build static library for x264
2 |
3 |
4 | ```
5 | git clone git://git.videolan.org/x264.git
6 | export NDK_SYSROOT=~/opt/android-ndk-r9d/platforms/android-9/arch-arm
7 | export PATH=$PATH:~/opt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/
8 | ./configure --cross-prefix=arm-linux-androideabi- --sysroot="$NDK_SYSROOT" --host=arm-linux --enable-pic --enable-static --disable-cli
9 | make STRIP=
10 | ```
11 |
12 | reference site: http://vinsol.com/blog/2014/07/30/cross-compiling-ffmpeg-with-x264-for-android/
13 |
14 |
--------------------------------------------------------------------------------
/jni/g72x/adpcm_js.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "g72x.h"
3 |
4 | static g726_state g726State;
5 | static int initFlag = 0;
6 |
7 | int adpcmDecode(unsigned char *inBuffer, int length, unsigned char *pcmData) {
8 | if ( initFlag == 0) {
9 | initFlag = 1;
10 | g726_init_state(&g726State);
11 | }
12 |
13 | int j = 0;
14 | for(int i = 0; i < length; i++) {
15 | unsigned char code;
16 | unsigned short pcm;
17 |
18 | code = inBuffer[i] & 0x0F;
19 | pcm = g726_32_decoder(code, AUDIO_ENCODING_LINEAR, &g726State);
20 | ((unsigned short *)pcmData)[j] = pcm;
21 | j++;
22 |
23 | code = inBuffer[i] & 0xF0;
24 | code = code >> 4;
25 | pcm = g726_32_decoder(code, AUDIO_ENCODING_LINEAR, &g726State);
26 | ((unsigned short *)pcmData)[j] = pcm;
27 | j++;
28 | }
29 | return j;
30 |
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/jni/g72x/g726_16.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 | /* 16kbps version created, used 24kbps code and changing as little as possible.
27 | * G.726 specs are available from ITU's gopher or WWW site (http://www.itu.ch)
28 | * If any errors are found, please contact me at mrand@tamu.edu
29 | * -Marc Randolph
30 | */
31 |
32 | /*
33 | * g726_16.c
34 | *
35 | * Description:
36 | *
37 | * g723_16_encoder(), g723_16_decoder()
38 | *
39 | * These routines comprise an implementation of the CCITT G.726 16 Kbps
40 | * ADPCM coding algorithm. Essentially, this implementation is identical to
41 | * the bit level description except for a few deviations which take advantage
42 | * of workstation attributes, such as hardware 2's complement arithmetic.
43 | *
44 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
45 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
46 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
47 | * This coder operates on a sample-by-sample basis. Input samples may be
48 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
49 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
50 | * 4-bit quantized difference signal resulting in a compression ratio of
51 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
52 | * difference signal is 3 bits and 5 bits, respectively.
53 | *
54 | * $Revision: 1.1 $
55 | * $Author: shorne $
56 | * $Date: 2010/02/24 02:19:05 $
57 | */
58 | #include "g72x.h"
59 | #include "private.h"
60 |
61 | /*
62 | * Maps G.723_16 code word to reconstructed scale factor normalized log
63 | * magnitude values. Comes from Table 11/G.726
64 | */
65 | static short _dqlntab[4] = { 116, 365, 365, 116};
66 |
67 | /* Maps G.723_16 code word to log of scale factor multiplier.
68 | *
69 | * _witab[4] is actually {-22 , 439, 439, -22}, but FILTD wants it
70 | * as WI << 5 (multiplied by 32), so we'll do that here
71 | */
72 | static short _witab[4] = {-704, 14048, 14048, -704};
73 |
74 | /*
75 | * Maps G.723_16 code words to a set of values whose long and short
76 | * term averages are computed and then compared to give an indication
77 | * how stationary (steady state) the signal is.
78 | */
79 |
80 | /* Comes from FUNCTF */
81 | static short _fitab[4] = {0, 0xE00, 0xE00, 0};
82 |
83 | /* Comes from quantizer decision level tables (Table 7/G.726)
84 | */
85 | static int qtab_723_16[1] = {261};
86 |
87 |
88 | /*
89 | * g723_16_encoder()
90 | *
91 | * Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit code.
92 | * Returns -1 if invalid input coding value.
93 | */
94 | int
95 | g726_16_encoder(
96 | int sl,
97 | int in_coding,
98 | g726_state *state_ptr)
99 | {
100 | int sezi;
101 | int sez; /* ACCUM */
102 | int sei;
103 | int se;
104 | int d; /* SUBTA */
105 | int y; /* MIX */
106 | int i;
107 | int dq;
108 | int sr; /* ADDB */
109 | int dqsez; /* ADDC */
110 |
111 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
112 | case AUDIO_ENCODING_ALAW:
113 | sl = alaw2linear(sl) >> 2;
114 | break;
115 | case AUDIO_ENCODING_ULAW:
116 | sl = ulaw2linear(sl) >> 2;
117 | break;
118 | case AUDIO_ENCODING_LINEAR:
119 | sl >>= 2; /* sl of 14-bit dynamic range */
120 | break;
121 | default:
122 | return (-1);
123 | }
124 |
125 | sezi = predictor_zero(state_ptr);
126 | sez = sezi >> 1;
127 | sei = sezi + predictor_pole(state_ptr);
128 | se = sei >> 1; /* se = estimated signal */
129 |
130 | d = sl - se; /* d = estimation diff. */
131 |
132 | /* quantize prediction difference d */
133 | y = step_size(state_ptr); /* quantizer step size */
134 | i = quantize(d, y, qtab_723_16, 1); /* i = ADPCM code */
135 |
136 | /* Since quantize() only produces a three level output
137 | * (1, 2, or 3), we must create the fourth one on our own
138 | */
139 | if (i == 3) /* i code for the zero region */
140 | if ((d & 0x8000) == 0) /* If d > 0, i=3 isn't right... */
141 | i = 0;
142 |
143 | dq = reconstruct(i & 2, _dqlntab[i], y); /* quantized diff. */
144 |
145 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */
146 |
147 | dqsez = sr + sez - se; /* pole prediction diff. */
148 |
149 | update(2, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
150 |
151 | return (i);
152 | }
153 |
154 | /*
155 | * g723_16_decoder()
156 | *
157 | * Decodes a 2-bit CCITT G.723_16 ADPCM code and returns
158 | * the resulting 16-bit linear PCM, A-law or u-law sample value.
159 | * -1 is returned if the output coding is unknown.
160 | */
161 | int
162 | g726_16_decoder(
163 | int i,
164 | int out_coding,
165 | g726_state *state_ptr)
166 | {
167 | int sezi;
168 | int sez; /* ACCUM */
169 | int sei;
170 | int se;
171 | int y; /* MIX */
172 | int dq;
173 | int sr; /* ADDB */
174 | int dqsez;
175 |
176 | i &= 0x03; /* mask to get proper bits */
177 | sezi = predictor_zero(state_ptr);
178 | sez = sezi >> 1;
179 | sei = sezi + predictor_pole(state_ptr);
180 | se = sei >> 1; /* se = estimated signal */
181 |
182 | y = step_size(state_ptr); /* adaptive quantizer step size */
183 | dq = reconstruct(i & 0x02, _dqlntab[i], y); /* unquantize pred diff */
184 |
185 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */
186 |
187 | dqsez = sr - se + sez; /* pole prediction diff. */
188 |
189 | update(2, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
190 |
191 | switch (out_coding) {
192 | case AUDIO_ENCODING_ALAW:
193 | return (tandem_adjust_alaw(sr, se, y, i, 2, qtab_723_16));
194 | case AUDIO_ENCODING_ULAW:
195 | return (tandem_adjust_ulaw(sr, se, y, i, 2, qtab_723_16));
196 | case AUDIO_ENCODING_LINEAR:
197 | return (sr << 2); /* sr was of 14-bit dynamic range */
198 | default:
199 | return (-1);
200 | }
201 | }
202 |
203 |
--------------------------------------------------------------------------------
/jni/g72x/g726_24.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g726_24.c
29 | *
30 | * Description:
31 | *
32 | * g723_24_encoder(), g723_24_decoder()
33 | *
34 | * These routines comprise an implementation of the CCITT G.723 24 Kbps
35 | * ADPCM coding algorithm. Essentially, this implementation is identical to
36 | * the bit level description except for a few deviations which take advantage
37 | * of workstation attributes, such as hardware 2's complement arithmetic.
38 | *
39 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
40 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
41 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
42 | * This coder operates on a sample-by-sample basis. Input samples may be
43 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
44 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
45 | * 4-bit quantized difference signal resulting in a compression ratio of
46 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
47 | * difference signal is 3 bits and 5 bits, respectively.
48 | *
49 | * $Revision: 1.1 $
50 | * $Author: shorne $
51 | * $Date: 2010/02/24 02:19:05 $
52 | */
53 | #include "g72x.h"
54 | #include "private.h"
55 |
56 | /*
57 | * Maps G.723_24 code word to reconstructed scale factor normalized log
58 | * magnitude values.
59 | */
60 | static short _dqlntab[8] = {-2048, 135, 273, 373, 373, 273, 135, -2048};
61 |
62 | /* Maps G.723_24 code word to log of scale factor multiplier. */
63 | static short _witab[8] = {-128, 960, 4384, 18624, 18624, 4384, 960, -128};
64 |
65 | /*
66 | * Maps G.723_24 code words to a set of values whose long and short
67 | * term averages are computed and then compared to give an indication
68 | * how stationary (steady state) the signal is.
69 | */
70 | static short _fitab[8] = {0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0};
71 |
72 | static int qtab_723_24[3] = {8, 218, 331};
73 |
74 | /*
75 | * g723_24_encoder()
76 | *
77 | * Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit code.
78 | * Returns -1 if invalid input coding value.
79 | */
80 | int
81 | g726_24_encoder(
82 | int sl,
83 | int in_coding,
84 | g726_state *state_ptr)
85 | {
86 | int sezi;
87 | int sei;
88 | int sez; /* ACCUM */
89 | int se;
90 | int d; /* SUBTA */
91 | int y; /* MIX */
92 | int i;
93 | int dq;
94 | int sr; /* ADDB */
95 | int dqsez; /* ADDC */
96 |
97 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
98 | case AUDIO_ENCODING_ALAW:
99 | sl = alaw2linear(sl) >> 2;
100 | break;
101 | case AUDIO_ENCODING_ULAW:
102 | sl = ulaw2linear(sl) >> 2;
103 | break;
104 | case AUDIO_ENCODING_LINEAR:
105 | sl >>= 2; /* sl of 14-bit dynamic range */
106 | break;
107 | default:
108 | return (-1);
109 | }
110 |
111 | sezi = predictor_zero(state_ptr);
112 | sez = sezi >> 1;
113 | sei = sezi + predictor_pole(state_ptr);
114 | se = sei >> 1; /* se = estimated signal */
115 |
116 | d = sl - se; /* d = estimation diff. */
117 |
118 | /* quantize prediction difference d */
119 | y = step_size(state_ptr); /* quantizer step size */
120 | i = quantize(d, y, qtab_723_24, 3); /* i = ADPCM code */
121 | dq = reconstruct(i & 4, _dqlntab[i], y); /* quantized diff. */
122 |
123 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */
124 |
125 | dqsez = sr + sez - se; /* pole prediction diff. */
126 |
127 | update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
128 |
129 | return (i);
130 | }
131 |
132 | /*
133 | * g723_24_decoder()
134 | *
135 | * Decodes a 3-bit CCITT G.723_24 ADPCM code and returns
136 | * the resulting 16-bit linear PCM, A-law or u-law sample value.
137 | * -1 is returned if the output coding is unknown.
138 | */
139 | int
140 | g726_24_decoder(
141 | int i,
142 | int out_coding,
143 | g726_state *state_ptr)
144 | {
145 | int sezi;
146 | int sez; /* ACCUM */
147 | int sei;
148 | int se;
149 | int y; /* MIX */
150 | int dq;
151 | int sr; /* ADDB */
152 | int dqsez;
153 |
154 | i &= 0x07; /* mask to get proper bits */
155 | sezi = predictor_zero(state_ptr);
156 | sez = sezi >> 1;
157 | sei = sezi + predictor_pole(state_ptr);
158 | se = sei >> 1; /* se = estimated signal */
159 |
160 | y = step_size(state_ptr); /* adaptive quantizer step size */
161 | dq = reconstruct(i & 0x04, _dqlntab[i], y); /* unquantize pred diff */
162 |
163 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */
164 |
165 | dqsez = sr - se + sez; /* pole prediction diff. */
166 |
167 | update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr);
168 |
169 | switch (out_coding) {
170 | case AUDIO_ENCODING_ALAW:
171 | return (tandem_adjust_alaw(sr, se, y, i, 4, qtab_723_24));
172 | case AUDIO_ENCODING_ULAW:
173 | return (tandem_adjust_ulaw(sr, se, y, i, 4, qtab_723_24));
174 | case AUDIO_ENCODING_LINEAR:
175 | return (sr << 2); /* sr was of 14-bit dynamic range */
176 | default:
177 | return (-1);
178 | }
179 | }
180 |
181 |
--------------------------------------------------------------------------------
/jni/g72x/g726_32.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g726_32.c
29 | *
30 | * Description:
31 | *
32 | * g721_encoder(), g721_decoder()
33 | *
34 | * These routines comprise an implementation of the CCITT G.721 ADPCM
35 | * coding algorithm. Essentially, this implementation is identical to
36 | * the bit level description except for a few deviations which
37 | * take advantage of work station attributes, such as hardware 2's
38 | * complement arithmetic and large memory. Specifically, certain time
39 | * consuming operations such as multiplications are replaced
40 | * with lookup tables and software 2's complement operations are
41 | * replaced with hardware 2's complement.
42 | *
43 | * The deviation from the bit level specification (lookup tables)
44 | * preserves the bit level performance specifications.
45 | *
46 | * As outlined in the G.721 Recommendation, the algorithm is broken
47 | * down into modules. Each section of code below is preceded by
48 | * the name of the module which it is implementing.
49 | *
50 | * The ITU-T G.726 coder is an adaptive differential pulse code modulation
51 | * (ADPCM) waveform coding algorithm, suitable for coding of digitized
52 | * telephone bandwidth (0.3-3.4 kHz) speech or audio signals sampled at 8 kHz.
53 | * This coder operates on a sample-by-sample basis. Input samples may be
54 | * represented in linear PCM or companded 8-bit G.711 (m-law/A-law) formats
55 | * (i.e., 64 kbps). For 32 kbps operation, each sample is converted into a
56 | * 4-bit quantized difference signal resulting in a compression ratio of
57 | * 2:1 over the G.711 format. For 24 kbps 40 kbps operation, the quantized
58 | * difference signal is 3 bits and 5 bits, respectively.
59 | *
60 | * $Revision: 1.1 $
61 | * $Author: shorne $
62 | * $Date: 2010/02/24 02:19:05 $
63 | */
64 | #include "g72x.h"
65 | #include "private.h"
66 |
67 | static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
68 | /*
69 | * Maps G.721 code word to reconstructed scale factor normalized log
70 | * magnitude values.
71 | */
72 | static short _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
73 | 425, 373, 323, 273, 213, 135, 4, -2048};
74 |
75 | /* Maps G.721 code word to log of scale factor multiplier. */
76 | static short _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
77 | 1122, 355, 198, 112, 64, 41, 18, -12};
78 | /*
79 | * Maps G.721 code words to a set of values whose long and short
80 | * term averages are computed and then compared to give an indication
81 | * how stationary (steady state) the signal is.
82 | */
83 | static short _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
84 | 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
85 |
86 | /*
87 | * g721_encoder()
88 | *
89 | * Encodes the input vale of linear PCM, A-law or u-law data sl and returns
90 | * the resulting code. -1 is returned for unknown input coding value.
91 | */
92 | int
93 | g726_32_encoder(
94 | int sl,
95 | int in_coding,
96 | g726_state *state_ptr)
97 | {
98 | int sezi;
99 | int sez; /* ACCUM */
100 | int se;
101 | int d; /* SUBTA */
102 | int y; /* MIX */
103 | int i;
104 | int dq;
105 | int sr; /* ADDB */
106 | int dqsez; /* ADDC */
107 |
108 | switch (in_coding) { /* linearize input sample to 14-bit PCM */
109 | case AUDIO_ENCODING_ALAW:
110 | sl = alaw2linear(sl) >> 2;
111 | break;
112 | case AUDIO_ENCODING_ULAW:
113 | sl = ulaw2linear(sl) >> 2;
114 | break;
115 | case AUDIO_ENCODING_LINEAR:
116 | sl >>= 2; /* 14-bit dynamic range */
117 | break;
118 | default:
119 | return (-1);
120 | }
121 |
122 | sezi = predictor_zero(state_ptr);
123 | sez = sezi >> 1;
124 | se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
125 |
126 | d = sl - se; /* estimation difference */
127 |
128 | /* quantize the prediction difference */
129 | y = step_size(state_ptr); /* quantizer step size */
130 | i = quantize(d, y, qtab_721, 7); /* i = ADPCM code */
131 |
132 | dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
133 |
134 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
135 |
136 | dqsez = sr + sez - se; /* pole prediction diff. */
137 |
138 | update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
139 |
140 | return (i);
141 | }
142 |
143 | /*
144 | * g721_decoder()
145 | *
146 | * Description:
147 | *
148 | * Decodes a 4-bit code of G.721 encoded data of i and
149 | * returns the resulting linear PCM, A-law or u-law value.
150 | * return -1 for unknown out_coding value.
151 | */
152 | int
153 | g726_32_decoder(
154 | int i,
155 | int out_coding,
156 | g726_state *state_ptr)
157 | {
158 | int sezi;
159 | int sez; /* ACCUM */
160 | int sei;
161 | int se;
162 | int y; /* MIX */
163 | int dq;
164 | int sr; /* ADDB */
165 | int dqsez;
166 | long lino;
167 |
168 | i &= 0x0f; /* mask to get proper bits */
169 | sezi = predictor_zero(state_ptr);
170 | sez = sezi >> 1;
171 | sei = sezi + predictor_pole(state_ptr);
172 | se = sei >> 1; /* se = estimated signal */
173 |
174 | y = step_size(state_ptr); /* dynamic quantizer step size */
175 |
176 | dq = reconstruct(i & 0x08, _dqlntab[i], y); /* quantized diff. */
177 |
178 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : se + dq; /* reconst. signal */
179 |
180 | dqsez = sr - se + sez; /* pole prediction diff. */
181 |
182 | update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
183 |
184 | switch (out_coding) {
185 | case AUDIO_ENCODING_ALAW:
186 | return (tandem_adjust_alaw(sr, se, y, i, 8, qtab_721));
187 | case AUDIO_ENCODING_ULAW:
188 | return (tandem_adjust_ulaw(sr, se, y, i, 8, qtab_721));
189 | case AUDIO_ENCODING_LINEAR:
190 | lino = (long)sr << 2; /* this seems to overflow a short*/
191 | lino = lino > 32767 ? 32767 : lino;
192 | lino = lino < -32768 ? -32768 : lino;
193 | return lino;//(sr << 2); /* sr was 14-bit dynamic range */
194 | default:
195 | return (-1);
196 | }
197 | }
198 |
199 |
--------------------------------------------------------------------------------
/jni/g72x/g72x.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code is a product of Sun Microsystems, Inc. and is provided
3 | * for unrestricted use. Users may copy or modify this source code without
4 | * charge.
5 | *
6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 | *
10 | * Sun source code is provided with no support and without any obligation on
11 | * the part of Sun Microsystems, Inc. to assist in its use, correction,
12 | * modification or enhancement.
13 | *
14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
16 | * OR ANY PART THEREOF.
17 | *
18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue
19 | * or profits or other special, indirect and consequential damages, even if
20 | * Sun has been advised of the possibility of such damages.
21 | *
22 | * Sun Microsystems, Inc.
23 | * 2550 Garcia Avenue
24 | * Mountain View, California 94043
25 | */
26 |
27 | /*
28 | * g72x.h
29 | *
30 | * Header file for CCITT conversion routines.
31 | *
32 | */
33 | #ifndef _G72X_H
34 | #define _G72X_H
35 |
36 | #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */
37 | #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */
38 | #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */
39 |
40 | /*
41 | * The following is the definition of the state structure
42 | * used by the G.721/G.723 encoder and decoder to preserve their internal
43 | * state between successive calls. The meanings of the majority
44 | * of the state structure fields are explained in detail in the
45 | * CCITT Recommendation G.721. The field names are essentially indentical
46 | * to variable names in the bit level description of the coding algorithm
47 | * included in this Recommendation.
48 | */
49 | typedef struct g726_state_s {
50 | long yl; /* Locked or steady state step size multiplier. */
51 | int yu; /* Unlocked or non-steady state step size multiplier. */
52 | int dms; /* Short term energy estimate. */
53 | int dml; /* Long term energy estimate. */
54 | int ap; /* Linear weighting coefficient of 'yl' and 'yu'. */
55 |
56 | int a[2]; /* Coefficients of pole portion of prediction filter. */
57 | int b[6]; /* Coefficients of zero portion of prediction filter. */
58 | int pk[2]; /* Signs of previous two samples of a partially
59 | * reconstructed signal. */
60 | short dq[6];/* int here fails in newupdate on encode!
61 | * Previous 6 samples of the quantized difference
62 | * signal represented in an internal floating point
63 | * format.
64 | */
65 | int sr[2]; /* Previous 2 samples of the quantized difference
66 | * signal represented in an internal floating point
67 | * format. */
68 | int td; /* delayed tone detect, new in 1988 version */
69 | } g726_state;
70 |
71 | /* External function definitions. */
72 |
73 | void g726_init_state( g726_state *);
74 |
75 | int g726_32_encoder(
76 | int sample,
77 | int in_coding,
78 | g726_state *state_ptr);
79 | int g726_32_decoder(
80 | int code,
81 | int out_coding,
82 | g726_state *state_ptr);
83 | int g726_16_encoder(
84 | int sample,
85 | int in_coding,
86 | g726_state *state_ptr);
87 | int g726_16_decoder(
88 | int code,
89 | int out_coding,
90 | g726_state *state_ptr);
91 | int g726_24_encoder(
92 | int sample,
93 | int in_coding,
94 | g726_state *state_ptr);
95 | int g726_24_decoder(
96 | int code,
97 | int out_coding,
98 | g726_state *state_ptr);
99 | int g726_40_encoder(
100 | int sample,
101 | int in_coding,
102 | g726_state *state_ptr);
103 | int g726_40_decoder(
104 | int code,
105 | int out_coding,
106 | g726_state *state_ptr);
107 |
108 | #endif /* !_G72X_H */
109 |
110 |
--------------------------------------------------------------------------------
/jni/g72x/private.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * $Revision: 1.1 $
4 | * $Author: shorne $
5 | * $Date: 2010/02/24 02:19:05 $
6 | */
7 | #if !defined G726_PRIVATE
8 | #define G726_PRIVATE
9 |
10 | int linear2ulaw(int pcm_val);
11 | int ulaw2linear(int u_val);
12 | int linear2alaw(int pcm_val);
13 | int alaw2linear(int u_val);
14 |
15 | static int fmult(int an, int srn);
16 | int predictor_zero( g726_state *state_ptr);
17 | int predictor_pole( g726_state *state_ptr);
18 | int step_size( g726_state *state_ptr);
19 | int quantize( int d, /* Raw difference signal sample */
20 | int y, /* Step size multiplier */
21 | int * table, /* quantization table */
22 | int size); /* table size of short integers */
23 | int reconstruct( int sign, /* 0 for non-negative value */
24 | int dqln, /* G.72x codeword */
25 | int y); /* Step size multiplier */
26 | void update( int code_size, /* distinguish 723_40 with others */
27 | int y, /* quantizer step size */
28 | int wi, /* scale factor multiplier */
29 | int fi, /* for long/short term energies */
30 | int dq, /* quantized prediction difference */
31 | int sr, /* reconstructed signal */
32 | int dqsez, /* difference from 2-pole predictor */
33 | g726_state *state_ptr); /* coder state pointer */
34 | int tandem_adjust_alaw(
35 | int sr, /* decoder output linear PCM sample */
36 | int se, /* predictor estimate sample */
37 | int y, /* quantizer step size */
38 | int i, /* decoder input code */
39 | int sign,
40 | int * qtab);
41 | int tandem_adjust_ulaw(
42 | int sr, /* decoder output linear PCM sample */
43 | int se, /* predictor estimate sample */
44 | int y, /* quantizer step size */
45 | int i, /* decoder input code */
46 | int sign,
47 | int * qtab);
48 |
49 | #endif // G726_PRIVATE
50 |
51 |
--------------------------------------------------------------------------------
/jni/h264encoder.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "helper.h"
3 | #include "h264encoder.h"
4 |
5 | H264Encoder::H264Encoder(const int wid, const int hei) {
6 | x264_hdl_ = NULL;
7 | init_(wid, hei);
8 | }
9 |
10 | H264Encoder::~H264Encoder() {
11 | if ( x264_hdl_ == NULL) {
12 | x264_picture_clean(&x264_picin_);
13 | x264_picture_clean(&x264_picout_);
14 | x264_encoder_close(x264_hdl_);
15 | x264_hdl_ = NULL;
16 | }
17 | }
18 |
19 | void H264Encoder::init_(const int wid, const int hei) {
20 | // 0. building encoder parameters.
21 | x264_param_default_preset(&x264_opt_, "ultrafast", "zerolatency");
22 |
23 | x264_opt_.i_width = wid;
24 | x264_opt_.i_height = hei;
25 | x264_opt_.i_threads = 1;
26 | x264_opt_.b_repeat_headers = 1;
27 | x264_opt_.b_intra_refresh = 1;
28 |
29 | x264_opt_.rc.i_rc_method = X264_RC_CQP;
30 | x264_opt_.rc.i_qp_constant = 24;
31 | x264_opt_.rc.i_qp_min = 24;
32 | x264_opt_.rc.i_qp_max = 24;
33 | //x264_param_default(&opt);
34 | x264_param_apply_profile(&x264_opt_, "baseline");
35 |
36 | // 1. Prepare the output buffer and target file
37 | x264_picture_alloc(&x264_picin_, X264_CSP_NV12, x264_opt_.i_width, x264_opt_.i_height);
38 | x264_picture_alloc(&x264_picout_, X264_CSP_NV12, x264_opt_.i_width, x264_opt_.i_height);
39 |
40 | // 2. Building the encoder handler
41 | x264_hdl_ = x264_encoder_open(&x264_opt_);
42 | x264_encoder_parameters(x264_hdl_, &x264_opt_);
43 | }
44 |
45 | int H264Encoder::doEncode(const unsigned char* yuv, unsigned char* outBuffer, const int flag) {
46 | int width = x264_opt_.i_width;
47 | int height = x264_opt_.i_height;
48 | memcpy(x264_picin_.img.plane[0], yuv, width*height);
49 | memcpy(x264_picin_.img.plane[1], yuv + width*height - 1, width*height/2);
50 |
51 | if ( flag == 1) {
52 | x264_picin_.i_type = X264_TYPE_IDR;
53 | } else {
54 | x264_picin_.i_type = X264_TYPE_P;
55 | }
56 |
57 | int nals;
58 | x264_nal_t *nal_pointer;
59 | int ret = x264_encoder_encode(x264_hdl_, &nal_pointer, &nals, &x264_picin_, &x264_picout_);
60 | if ( ret <= 0) {
61 | return ret;
62 | }
63 |
64 | int outLength = 0;
65 | for ( int i = 0; i < nals; i++) {
66 | if( nal_pointer[i].i_type != 6) {
67 | x264_nal_t* nal = &nal_pointer[i];
68 | memcpy(&outBuffer[outLength], nal->p_payload, nal->i_payload);
69 | outLength += nal->i_payload;
70 | }
71 | }
72 |
73 | return outLength;
74 | }
75 |
--------------------------------------------------------------------------------
/jni/h264encoder.h:
--------------------------------------------------------------------------------
1 | #ifndef _H264ENCODER_H_
2 | #define _H264ENCODER_H_
3 |
4 | #include
5 | #include
6 |
7 | extern "C" {
8 | #include
9 | }
10 |
11 | class H264Encoder {
12 | public:
13 | H264Encoder(const int wid, const int hei);
14 | ~H264Encoder();
15 |
16 | int doEncode(const unsigned char* yuv, unsigned char* outBuffer, const int flag);
17 |
18 | private:
19 | void init_(const int wid, const int hei);
20 |
21 | x264_param_t x264_opt_;;
22 | x264_t *x264_hdl_;
23 | x264_picture_t x264_picin_;
24 | x264_picture_t x264_picout_;
25 | };
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/jni/helper.h:
--------------------------------------------------------------------------------
1 | #ifndef _HELPER_H_
2 | #define _HELPER_H_
3 |
4 | #if defined(ANDROID)
5 | #include
6 | #include
7 |
8 | #define LOG_TAG "TEAONLY"
9 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
10 |
11 | #else // endof ANDROID
12 |
13 | #define LOGD(...)
14 |
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/jni/main_jni.cpp:
--------------------------------------------------------------------------------
1 | #ifdef ANDROID
2 | #include
3 | #include "helper.h"
4 | #include "h264encoder.h"
5 | extern "C" {
6 | #include "g72x/g72x.h"
7 | };
8 |
9 | #undef JNIEXPORT
10 | #define JNIEXPORT __attribute__((visibility("default")))
11 | #define JOW(rettype, name) extern "C" rettype JNIEXPORT JNICALL \
12 | Java_teaonly_droideye_MainActivity_##name
13 |
14 | H264Encoder* myAVC = NULL;
15 | g726_state g726State;
16 |
17 | JOW(void, nativeInitMediaEncoder)(JNIEnv* env, jclass, jint width, jint height) {
18 | myAVC = new H264Encoder(width, height);
19 | g726_init_state(&g726State);
20 |
21 | return;
22 | };
23 |
24 | JOW(void, nativeReleaseMediaEncoder)(JNIEnv* env, jclass) {
25 | delete myAVC;
26 |
27 | return;
28 | };
29 |
30 | JOW(int, nativeDoVideoEncode)(JNIEnv* env, jclass, jbyteArray _yuvData, jbyteArray _nalsData, jint flag) {
31 | jboolean isCopy = JNI_TRUE;
32 | jbyte* yuvData = env->GetByteArrayElements(_yuvData, NULL);
33 | jbyte* nalsData = env->GetByteArrayElements(_nalsData, &isCopy);
34 |
35 | int ret = myAVC->doEncode((unsigned char*)yuvData, (unsigned char*)nalsData, flag);
36 |
37 | env->ReleaseByteArrayElements(_nalsData, nalsData, 0);
38 | env->ReleaseByteArrayElements(_yuvData, yuvData, JNI_ABORT);
39 |
40 | return ret;
41 | }
42 |
43 | JOW(int, nativeDoAudioEncode)(JNIEnv* env, jclass, jbyteArray pcmData, jint length, jbyteArray g726Data) {
44 | jboolean isCopy = JNI_TRUE;
45 | jbyte* audioFrame = env->GetByteArrayElements(pcmData, NULL);
46 | jbyte* audioPacket = env->GetByteArrayElements(g726Data, &isCopy);
47 |
48 | int j = 0;
49 | unsigned char byteCode = 0x00;
50 | short* pcmBuffer = (short*) audioFrame;
51 | for(int i = 0; i < length; i++) {
52 | short pcm = pcmBuffer[i];
53 | unsigned char code = g726_32_encoder(pcm, AUDIO_ENCODING_LINEAR, &g726State);
54 |
55 | if (i & 0x01) {
56 | byteCode = (code << 4) | (byteCode & 0x0f);
57 | audioPacket[j] = byteCode;
58 | j++;
59 | } else {
60 | byteCode = code;
61 | }
62 | }
63 |
64 | env->ReleaseByteArrayElements(g726Data, audioPacket, 0);
65 | env->ReleaseByteArrayElements(pcmData, audioFrame, JNI_ABORT);
66 |
67 | return j;
68 | }
69 |
70 | extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
71 | JNIEnv* jni;
72 | if (jvm->GetEnv(reinterpret_cast(&jni), JNI_VERSION_1_6) != JNI_OK)
73 | return -1;
74 | return JNI_VERSION_1_6;
75 | }
76 |
77 | extern "C" jint JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM *jvm, void *reserved) {
78 | return 0;
79 | }
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/libs/java_websocket.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/libs/java_websocket.jar
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-14
15 | #android.library.reference.1=../../bitbucket/google-play-services_lib
16 |
--------------------------------------------------------------------------------
/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/android-eye/a73596627139b38d2fb6f03dfa21ece5fe51854f/res/drawable/icon.png
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
26 |
30 |
31 |
37 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Wifi Camera
4 | Open with browser :
5 | Error: Please enable wifi
6 | Error: 8080 port is in used
7 |
8 |
--------------------------------------------------------------------------------
/src/teaonly/droideye/CameraView.java:
--------------------------------------------------------------------------------
1 | package teaonly.droideye;
2 |
3 | import android.graphics.ImageFormat;
4 | import android.graphics.PixelFormat;
5 | import android.hardware.Camera;
6 | import android.hardware.Camera.PreviewCallback;
7 | import android.hardware.Camera.PictureCallback;
8 | import android.hardware.Camera.AutoFocusCallback;
9 | import android.util.Log;
10 | import android.view.MotionEvent;
11 | import android.view.SurfaceHolder;
12 | import android.view.SurfaceHolder.Callback;
13 | import android.view.SurfaceView;
14 |
15 | import java.util.*;
16 |
17 | public class CameraView implements SurfaceHolder.Callback{
18 | public static interface CameraReadyCallback {
19 | public void onCameraReady();
20 | }
21 |
22 | private Camera camera_ = null;
23 | private SurfaceHolder surfaceHolder_ = null;
24 | private SurfaceView surfaceView_;
25 | CameraReadyCallback cameraReadyCb_ = null;
26 |
27 | private List supportedFrameRate;
28 | private List supportedSizes;
29 | private Camera.Size procSize_;
30 |
31 | public CameraView(SurfaceView sv){
32 | surfaceView_ = sv;
33 |
34 | surfaceHolder_ = surfaceView_.getHolder();
35 | surfaceHolder_.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
36 | surfaceHolder_.addCallback(this);
37 | }
38 |
39 | public List getSupportedPreviewSize() {
40 | return supportedSizes;
41 | }
42 |
43 | public int Width() {
44 | return procSize_.width;
45 | }
46 |
47 | public int Height() {
48 | return procSize_.height;
49 | }
50 |
51 | public void setCameraReadyCallback(CameraReadyCallback cb) {
52 | cameraReadyCb_ = cb;
53 | }
54 |
55 | public void StartPreview(){
56 | if ( camera_ == null)
57 | return;
58 | camera_.startPreview();
59 | }
60 |
61 | public void StopPreview(){
62 | if ( camera_ == null)
63 | return;
64 | camera_.stopPreview();
65 | }
66 |
67 | public void AutoFocus() {
68 | camera_.autoFocus(afcb);
69 | }
70 |
71 | public void Release() {
72 | if ( camera_ != null) {
73 | camera_.stopPreview();
74 | camera_.release();
75 | camera_ = null;
76 | }
77 | }
78 |
79 | public void setupCamera(int wid, int hei, int bufNumber, double fps, PreviewCallback cb) {
80 |
81 | double diff = Math.abs(supportedSizes.get(0).width*supportedSizes.get(0).height - wid*hei);
82 | int targetIndex = 0;
83 | for(int i = 1; i < supportedSizes.size(); i++) {
84 | double newDiff = Math.abs(supportedSizes.get(i).width*supportedSizes.get(i).height - wid*hei);
85 | if ( newDiff < diff) {
86 | diff = newDiff;
87 | targetIndex = i;
88 | }
89 | }
90 | procSize_.width = supportedSizes.get(targetIndex).width;
91 | procSize_.height = supportedSizes.get(targetIndex).height;
92 |
93 | diff = Math.abs(supportedFrameRate.get(0)[0] * supportedFrameRate.get(0)[1] - fps*fps*1000*1000);
94 | targetIndex = 0;
95 | for(int i = 1; i < supportedFrameRate.size(); i++) {
96 | double newDiff = Math.abs(supportedFrameRate.get(i)[0] * supportedFrameRate.get(i)[1] - fps*fps*1000*1000);
97 | if ( newDiff < diff) {
98 | diff = newDiff;
99 | targetIndex = i;
100 | }
101 | }
102 | int targetMaxFrameRate = supportedFrameRate.get(targetIndex)[0];
103 | int targetMinFrameRate = supportedFrameRate.get(targetIndex)[1];
104 |
105 | Camera.Parameters p = camera_.getParameters();
106 | p.setPreviewSize(procSize_.width, procSize_.height);
107 | p.setPreviewFormat(ImageFormat.NV21);
108 | p.setPreviewFpsRange(targetMaxFrameRate, targetMinFrameRate);
109 | camera_.setParameters(p);
110 |
111 | PixelFormat pixelFormat = new PixelFormat();
112 | PixelFormat.getPixelFormatInfo(ImageFormat.NV21, pixelFormat);
113 | int bufSize = procSize_.width * procSize_.height * pixelFormat.bitsPerPixel / 8;
114 | byte[] buffer = null;
115 | for(int i = 0; i < bufNumber; i++) {
116 | buffer = new byte[ bufSize ];
117 | camera_.addCallbackBuffer(buffer);
118 | }
119 | camera_.setPreviewCallbackWithBuffer(cb);
120 | }
121 |
122 | private void initCamera() {
123 | camera_ = Camera.open();
124 | procSize_ = camera_.new Size(0, 0);
125 | Camera.Parameters p = camera_.getParameters();
126 |
127 | supportedFrameRate = p.getSupportedPreviewFpsRange();
128 |
129 | supportedSizes = p.getSupportedPreviewSizes();
130 | procSize_ = supportedSizes.get( supportedSizes.size()/2 );
131 | p.setPreviewSize(procSize_.width, procSize_.height);
132 |
133 | camera_.setParameters(p);
134 | //camera_.setDisplayOrientation(90);
135 | try {
136 | camera_.setPreviewDisplay(surfaceHolder_);
137 | } catch ( Exception ex) {
138 | ex.printStackTrace();
139 | }
140 | camera_.setPreviewCallbackWithBuffer(null);
141 |
142 | camera_.startPreview();
143 | }
144 |
145 | private Camera.AutoFocusCallback afcb = new Camera.AutoFocusCallback() {
146 | @Override
147 | public void onAutoFocus(boolean success, Camera camera) {
148 | }
149 | };
150 |
151 | @Override
152 | public void surfaceChanged(SurfaceHolder sh, int format, int w, int h){
153 | }
154 |
155 | @Override
156 | public void surfaceCreated(SurfaceHolder sh){
157 | initCamera();
158 | if ( cameraReadyCb_ != null)
159 | cameraReadyCb_.onCameraReady();
160 | }
161 |
162 | @Override
163 | public void surfaceDestroyed(SurfaceHolder sh){
164 | Release();
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/src/teaonly/droideye/MediaBlock.java:
--------------------------------------------------------------------------------
1 | package teaonly.droideye;
2 |
3 | class MediaBlock {
4 | public int videoCount = 0;
5 |
6 | public int flag = 0;
7 |
8 | private byte[] buffer;
9 | private int bufferLength;
10 | private int currentLength;
11 |
12 | public MediaBlock (int maxSize) {
13 | super();
14 | buffer = new byte[maxSize];
15 | bufferLength = maxSize;
16 | currentLength = 0;
17 | }
18 |
19 | public void reset() {
20 | synchronized ( this) {
21 | currentLength = 0;
22 | videoCount = 0;
23 | flag = 0;
24 | }
25 | }
26 |
27 | public int length() {
28 | return currentLength;
29 | }
30 |
31 | public byte[] data() {
32 | return buffer;
33 | }
34 |
35 | public int writeVideo(byte[] data, int length) {
36 | if ( currentLength + length >= bufferLength) {
37 | return 0;
38 | }
39 |
40 | for(int i = 0; i < length; i++) {
41 | buffer[currentLength] = data[i];
42 | currentLength++;
43 | }
44 | videoCount ++;
45 | return length;
46 | }
47 |
48 | public int write(byte[] data, int length) {
49 | if ( currentLength + length >= bufferLength) {
50 | return 0;
51 | }
52 |
53 | for(int i = 0; i < length; i++) {
54 | buffer[currentLength] = data[i];
55 | currentLength++;
56 | }
57 |
58 | return length;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/teaonly/droideye/OverlayView.java:
--------------------------------------------------------------------------------
1 | package teaonly.droideye;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.graphics.Rect;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.View;
16 |
17 | public class OverlayView extends View {
18 | public static interface UpdateDoneCallback {
19 | public void onUpdateDone();
20 | }
21 |
22 | private UpdateDoneCallback updateDoneCb = null;
23 | private Bitmap targetBMP = null;
24 | private Rect targetRect = null;
25 |
26 |
27 | public OverlayView(Context c, AttributeSet attr) {
28 | super(c, attr);
29 | }
30 |
31 | public void DrawResult(Bitmap bmp) {
32 | if ( targetRect == null)
33 | targetRect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
34 | targetBMP = bmp;
35 | postInvalidate();
36 | }
37 |
38 | public void setUpdateDoneCallback(UpdateDoneCallback cb) {
39 | updateDoneCb = cb;
40 | }
41 |
42 | @Override
43 | protected void onDraw(Canvas canvas) {
44 | if ( targetBMP != null ) {
45 |
46 | canvas.drawBitmap(targetBMP, null, targetRect, null);
47 |
48 | if ( updateDoneCb != null)
49 | updateDoneCb.onUpdateDone();
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/teaonly/droideye/TeaServer.java:
--------------------------------------------------------------------------------
1 | package teaonly.droideye;
2 |
3 | import java.io.*;
4 | import java.util.*;
5 | import android.content.Context;
6 | import android.util.Log;
7 |
8 | public class TeaServer extends NanoHTTPD
9 | {
10 | static final String TAG="TEAONLY";
11 |
12 | public TeaServer(int port, Context ctx) throws IOException {
13 | super(port, ctx.getAssets());
14 | }
15 |
16 | public TeaServer(int port, String wwwroot) throws IOException {
17 | super(port, new File(wwwroot).getAbsoluteFile() );
18 | }
19 |
20 | @Override
21 | public Response serve( String uri, String method, Properties header, Properties parms, Properties files ) {
22 | Log.d(TAG, "httpd request >>" + method + " '" + uri + "' " + " " + parms);
23 |
24 | if ( uri.startsWith("/cgi/") ) {
25 | return serveCGI(uri, method, header, parms, files);
26 | } else if ( uri.startsWith("/stream/") ) {
27 | return serveStream(uri, method, header, parms, files);
28 | } else {
29 | return super.serve(uri, method, header, parms, files);
30 | }
31 | }
32 |
33 | public Response serveStream( String uri, String method, Properties header, Properties parms, Properties files ) {
34 | CommonGatewayInterface cgi = cgiEntries.get(uri);
35 | if ( cgi == null)
36 | return null;
37 |
38 | InputStream ins;
39 | ins = cgi.streaming(parms);
40 | if ( ins == null)
41 | return null;
42 |
43 | Random rnd = new Random();
44 | String etag = Integer.toHexString( rnd.nextInt() );
45 | String mime = parms.getProperty("mime");
46 | if ( mime == null)
47 | mime = "application/octet-stream";
48 | Response res = new Response( HTTP_OK, mime, ins);
49 | res.addHeader( "ETag", etag);
50 | res.isStreaming = true;
51 |
52 | return res;
53 | }
54 |
55 | public Response serveCGI( String uri, String method, Properties header, Properties parms, Properties files ) {
56 | CommonGatewayInterface cgi = cgiEntries.get(uri);
57 | if ( cgi == null)
58 | return null;
59 |
60 | String msg = cgi.run(parms);
61 | if ( msg == null)
62 | return null;
63 |
64 | Response res = new Response( HTTP_OK, MIME_PLAINTEXT, msg);
65 | return res;
66 | }
67 |
68 | @Override
69 | public void serveDone(Response r) {
70 | try{
71 | if ( r.isStreaming ) {
72 | r.data.close();
73 | }
74 | } catch(IOException ex) {
75 | }
76 | }
77 |
78 | public static interface CommonGatewayInterface {
79 | public String run(Properties parms);
80 | public InputStream streaming(Properties parms);
81 | }
82 | private HashMap cgiEntries = new HashMap();
83 | public void registerCGI(String uri, CommonGatewayInterface cgi) {
84 | if ( cgi != null)
85 | cgiEntries.put(uri, cgi);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------