11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/LiveMultimedia.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Copyright 2015 Constant Innovations Inc
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | LiveMultimedia
2 | ==============
3 |
4 | The purpose of this app is to build an SDK over the low level Android media APIs to decode video live from the Android camera into a stream ready format! Hopefully people will find it usefull in their own apps. The sample app works on Android 4.3 and up for the Nexus 5, Samsung Note 2 and Samsung S3 and probaly many others. It does not work on HTC M8 which is under investigation. The code may work on Android 4.1 and up but this varies by device because it is dependant on the hardware codec built into its GPU.
5 | The sample app is very basic, it allow you to pick the front or back camera and then press record. Several seconds of vieo and audio will be saved into the memory of the device. Then the video and audio will be encoded into H264/AAC format. I will use the MediaMuxer class to create a MPEG-4 file streamable file that I save in the device SD card under "/Movies". You built in video player on your device should be able to play it. If not I recommend VLC excellant beta Android video player.
6 | I will then start a web server on your device and attempt to stream the Mp4 file there.
7 | This project is under active development so expect a rough ride initially. Please only install on developer phones unless you like having an app lock up your mobile device.
8 | Most Android smartphones use Qualcomm's hardware encoder and the software will work on those devices as that is what my Nexus 5 has and that it what the software is being debugged on. I gone to great length to break up the functionality into clasees that do one thing and one thing only making reuse possible Still some of the file are many hundreds of lines long. The possibilities are endless with this technology, basically anything you can dream up with Video and Audio on Android can be done by enhancing this app. I plan to add video filters soon. The audio recording currently not work and I still implemeneting the streaming bit.
9 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | android {
3 | compileSdkVersion 25
4 | buildToolsVersion '25.0.0'
5 |
6 | repositories {
7 | jcenter()
8 | }
9 |
10 | defaultConfig {
11 | applicationId "com.constantinnovationsinc.livemultimedia"
12 | minSdkVersion 19
13 | targetSdkVersion 25
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 | }
18 | compileOptions {
19 | sourceCompatibility JavaVersion.VERSION_1_7
20 | targetCompatibility JavaVersion.VERSION_1_7
21 | }
22 |
23 | sourceSets {
24 | instrumentTest {
25 | java.srcDirs = ['src/androidTest/java']
26 | }
27 | main {
28 | manifest.srcFile 'src/main/AndroidManifest.xml'
29 | java.srcDirs = ['src/main/java']
30 | res.srcDirs = ['src/main/res']
31 | }
32 | }
33 | }
34 | dependencies {
35 | testCompile 'org.mockito:mockito-core:1.9.5'
36 | androidTestCompile 'junit:junit:4.12'
37 | androidTestCompile('com.android.support.test:testing-support-lib:0.1') {
38 | exclude group: 'junit' // junit:junit-dep conflicts with junit:unit
39 | }
40 | compile 'com.android.support:support-v4:25.0.1'
41 | compile 'com.android.support:support-annotations:25.0.1'
42 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com.constantinnovationsinc.livemultimedia.test/activities/MultimediaActivityTest.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.test.activities;
2 |
3 |
4 | import android.test.ActivityInstrumentationTestCase2;
5 | import android.test.suitebuilder.annotation.LargeTest;
6 | import com.constantinnovationsinc.livemultimedia.activities.LiveMultimediaActivity;
7 | import android.support.test.runner.AndroidJUnit4;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | @RunWith(AndroidJUnit4.class)
12 | @LargeTest
13 | public class MultimediaActivityTest
14 | extends ActivityInstrumentationTestCase2 {
15 |
16 | @SuppressWarnings("all")
17 | public MultimediaActivityTest() {
18 | super(LiveMultimediaActivity.class);
19 | }
20 |
21 | @Test
22 | public void testOnCreate() throws Exception {
23 | assertNotNull(null);
24 | }
25 |
26 | @Test
27 | public void testOnDestroy() throws Exception {
28 | assertNotNull(null);
29 | }
30 |
31 | @Test
32 | public void testOnLowMemory() throws Exception {
33 | assertNotNull(null);
34 | }
35 |
36 | @Test
37 | public void testOnPause() throws Exception {
38 | assertNotNull(null);
39 | }
40 |
41 | @Test
42 | public void testOnResume() throws Exception {
43 | assertNotNull(null);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com.constantinnovationsinc.livemultimedia.test/app/MultimediaAppTest.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.test.app;
2 |
3 | import android.test.ApplicationTestCase;
4 | import android.support.test.runner.AndroidJUnit4;
5 | import android.test.suitebuilder.annotation.SmallTest;
6 | import org.junit.After;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import com.constantinnovationsinc.livemultimedia.app.MultimediaApp;
11 |
12 |
13 | @RunWith(AndroidJUnit4.class)
14 | @SmallTest
15 | public class MultimediaAppTest extends ApplicationTestCase {
16 | MultimediaApp mApplication = null;
17 | public MultimediaAppTest() {
18 | super(MultimediaApp.class);
19 | }
20 |
21 | @Before
22 | public void setUp() throws Exception {
23 | super.setUp();
24 | createApplication();
25 | mApplication = getApplication();
26 | }
27 |
28 | @After
29 | public void tearDown() throws Exception {
30 | }
31 |
32 | @Test
33 | public void SaveAudioData() throws Exception {
34 | assertNotNull(null);
35 | }
36 |
37 | @Test
38 | public void PullAudioData() throws Exception {
39 | assertNotNull(null);
40 | }
41 |
42 | @Test
43 | public void Capacity() throws Exception {
44 | assertNotNull(null);
45 | }
46 |
47 | @Test
48 | public void OnCreate() throws Exception {
49 | assertNotNull(null);
50 | }
51 |
52 | @Test
53 | public void OnLowMemory() throws Exception {
54 | assertNotNull(null);
55 | }
56 |
57 | @Test
58 | public void RegisterComponentCallbacks() throws Exception {
59 | assertNotNull(null);
60 | }
61 |
62 | @Test
63 | public void OnTerminate() throws Exception {
64 | assertNotNull(null);
65 | }
66 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com.constantinnovationsinc.livemultimedia.test/suite/AndroidTestSuite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014, 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 | package com.constantinnovationsinc.livemultimedia.test.suite;
17 | import org.junit.runner.RunWith;
18 | import org.junit.runners.Suite;
19 |
20 | /**
21 | * Test suite that runs all tests, unit + instrumentation tests.
22 | */
23 | @RunWith(Suite.class)
24 | @Suite.SuiteClasses({UnitTestSuite.class, InstrumentationTestSuite.class})
25 | public class AndroidTestSuite {}
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com.constantinnovationsinc.livemultimedia.test/suite/InstrumentationTestSuite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014, 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 | package com.constantinnovationsinc.livemultimedia.test.suite;
18 | import com.constantinnovationsinc.livemultimedia.test.app.MultimediaAppTest;
19 | import com.constantinnovationsinc.livemultimedia.test.activities.MultimediaActivityTest;
20 | import org.junit.runner.RunWith;
21 | import org.junit.runners.Suite;
22 |
23 | @RunWith(Suite.class)
24 | @Suite.SuiteClasses({MultimediaAppTest.class, MultimediaActivityTest.class})
25 | public class InstrumentationTestSuite {}
--------------------------------------------------------------------------------
/app/src/androidTest/java/com.constantinnovationsinc.livemultimedia.test/suite/UnitTestSuite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014, 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 | package com.constantinnovationsinc.livemultimedia.test.suite;
17 |
18 | import com.constantinnovationsinc.livemultimedia.test.activities.MultimediaActivityTest;
19 | import com.constantinnovationsinc.livemultimedia.test.app.MultimediaAppTest;
20 |
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.Suite;
23 |
24 | /**
25 | * Runs all unit tests.
26 | */
27 | @RunWith(Suite.class)
28 | @Suite.SuiteClasses({MultimediaAppTest.class, MultimediaActivityTest.class})
29 | public class UnitTestSuite {}
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
40 |
45 |
46 |
47 |
48 |
49 |
50 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/activities/LiveMultimediaActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.activities;
17 | import android.os.Bundle;
18 | import android.view.Menu;
19 | import android.view.MenuItem;
20 | import android.util.Log;
21 | import android.support.v4.app.Fragment;
22 | import android.support.v4.app.FragmentTransaction;
23 | import android.support.v4.app.FragmentActivity;
24 | import com.constantinnovationsinc.livemultimedia.R;
25 | import com.constantinnovationsinc.livemultimedia.fragments.Camera2VideoFragment;
26 |
27 | /********************************************************************
28 | * LiveMMultimediaActivity
29 | * Us this Activity class to load the CameraFragment class
30 | * that encapsulates the custom view that does all the heavy lifting
31 | ********************************************************************/
32 | public class LiveMultimediaActivity extends FragmentActivity {
33 | private static final String TAG = LiveMultimediaActivity.class.getCanonicalName();
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_hwbroadcasting);
38 | if (savedInstanceState != null) {
39 | return;
40 | }
41 | if (findViewById(R.id.fragment_container) != null) {
42 | Log.d(TAG, "Creating the fragment contains the video fragment.");
43 | Fragment fragment = new Camera2VideoFragment();
44 | fragment.setArguments( getIntent().getExtras() );
45 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
46 | transaction.add(R.id.fragment_container, fragment, "CameraFrag");
47 | transaction.addToBackStack( "CameraFrag" );
48 | transaction.commit();
49 | }
50 | }
51 |
52 | @Override
53 | public boolean onCreateOptionsMenu(Menu menu) {
54 | // Inflate the menu; this adds items to the action bar if it is present.
55 | getMenuInflater().inflate(R.menu.hwbroadcasting, menu);
56 | return true;
57 | }
58 |
59 | @Override
60 | public boolean onOptionsItemSelected(MenuItem item) {
61 | // Handle action bar item clicks here. The action bar will
62 | // automatically handle clicks on the Home/Up button, so long
63 | // as you specify a parent activity in AndroidManifest.xml.
64 | int id = item.getItemId();
65 | return id == R.id.action_settings || super.onOptionsItemSelected(item);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/adapters/CameraDetailAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.adapters;
17 | import android.content.Context;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.TextView;
22 | import android.widget.ArrayAdapter;
23 | import com.constantinnovationsinc.livemultimedia.R;
24 | import java.util.ArrayList;
25 |
26 | public class CameraDetailAdapter extends ArrayAdapter {
27 | private Context mContext;
28 |
29 |
30 | // Provide a suitable constructor (depends on the kind of dataset)
31 | public CameraDetailAdapter(Context context, ArrayList items) {
32 | super(context, 0, items);
33 | mContext = context;
34 | }
35 |
36 | public View getView(int position, View convertView, ViewGroup parent) {
37 | View view = convertView;
38 | if (view == null) {
39 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
40 | view = inflater.inflate(R.layout.fragment_camera_detail, parent);
41 | }
42 | return view;
43 | }
44 |
45 | public static class ViewHolder {
46 | public TextView mTextView;
47 | public ViewHolder(TextView v) {
48 | mTextView = v;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/app/MultimediaApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.app;
17 | import android.app.Application;
18 | import android.util.Log;
19 | import java.nio.ByteBuffer;
20 | import java.util.concurrent.ArrayBlockingQueue;
21 |
22 | /*****************************************************
23 | * I use the App Object to store Audio sampling data
24 | *****************************************************/
25 | public class MultimediaApp extends Application {
26 | private static final String TAG = MultimediaApp.class.getCanonicalName();
27 | public ArrayBlockingQueue mSavedAudioData = null;
28 |
29 | public synchronized void saveAudioData(ByteBuffer data) {
30 | mSavedAudioData.add(data);
31 | }
32 |
33 | public synchronized ByteBuffer pullAudioData() {
34 | return mSavedAudioData.poll();
35 | }
36 |
37 | public synchronized int capacity() {
38 | return mSavedAudioData.remainingCapacity();
39 | }
40 |
41 | @Override
42 | public void onCreate() {
43 | super.onCreate();
44 | mSavedAudioData = new ArrayBlockingQueue<>(150);
45 | }
46 |
47 | @Override
48 | public void onLowMemory() {
49 | super.onLowMemory();
50 | Log.e(TAG, "Low Memory Warning!");
51 | }
52 |
53 | @Override
54 | public void onTerminate() {
55 | super.onTerminate();
56 | Log.e(TAG, "App terminating!");
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/callbacks/FrameCatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.callbacks;
17 | import android.graphics.Bitmap;
18 | import android.graphics.BitmapFactory;
19 | import android.graphics.ImageFormat;
20 | import android.graphics.Rect;
21 | import android.graphics.YuvImage;
22 | import android.hardware.Camera;
23 | import android.os.Environment;
24 | import android.util.Log;
25 | import com.constantinnovationsinc.livemultimedia.utilities.ColorSpaceManager;
26 | import com.constantinnovationsinc.livemultimedia.utilities.SharedVideoMemory;
27 | import java.io.ByteArrayOutputStream;
28 | import java.io.File;
29 | import java.io.FileOutputStream;
30 | import java.io.IOException;
31 | import java.util.Random;
32 |
33 |
34 | /**************************************************
35 | * FrameCatcher works for pre-Lollipop API
36 | * This class wrap the Camera Preview Window CallBack
37 | * so that every image is captured in this class.
38 | *****************************************************/
39 | @SuppressWarnings("deprecation")
40 | public class FrameCatcher implements Camera.PreviewCallback {
41 | private static final String TAG = FrameCatcher.class.getCanonicalName();
42 | private final long mExpectedSize;
43 | public Boolean mRecording = false;
44 | public Boolean mStoringVideoFrames = false;
45 | public SharedVideoMemory mVideoBuffer = null;
46 | public int mNumFramesToBuffer = 210;
47 | public int mNumFramesBeforeStartingEncoders = 210;
48 | public int mWidth = -1;
49 | public int mHeight = -1;
50 | public FramesReadyCallback callback;
51 | public String mImageFormat;
52 |
53 | public FrameCatcher(long width, long height, String imageFormat, FramesReadyCallback receiver) {
54 | Log.d(TAG, "Passing width,height to FrameCacther: " + String.valueOf(width) + "," + String.valueOf(height));
55 | mExpectedSize = (width * height * 3 / 2);
56 | mWidth = (int) width;
57 | mHeight = (int) height;
58 | mImageFormat = imageFormat;
59 | callback = receiver;
60 | }
61 |
62 |
63 | /**********************************************************************
64 | * onPreviewFrame receives each frame video frame.
65 | * The frame will be color corrected and then stored in shared memory.
66 | * Both image formats of NV21 or YU12 is supported
67 | *******************************************************************/
68 | @SuppressWarnings("deprecation")
69 | @Override
70 | public void onPreviewFrame(byte[] data, Camera camera) {
71 | if (data == null) {
72 | Log.e(TAG, "Received null video frame data!");
73 | return;
74 | }
75 | if (mExpectedSize != data.length) {
76 | Log.e(TAG, "Bad frame size, got " + data.length + " expected " + mExpectedSize);
77 | return;
78 | }
79 | byte[] value = new byte[data.length];
80 | System.arraycopy(data, 0, value, 0, data.length);
81 | camera.addCallbackBuffer(data);
82 | if (mRecording) {
83 | try {
84 | if (mVideoBuffer == null) {
85 | if (callback != null) {
86 | callback.playLazerSound();
87 | }
88 | mVideoBuffer = new SharedVideoMemory("video", data.length, data.length * mNumFramesToBuffer);
89 | mVideoBuffer.lockMemory();
90 | Log.w(TAG, "Write out first video frame to shared memory!");
91 | if (mImageFormat != null && !mImageFormat.equalsIgnoreCase("UNKNOWN")) {
92 | if ( mImageFormat.equalsIgnoreCase("NV21")) {
93 | ColorSpaceManager.NV21toYUV420SemiPlanar(data, value, mWidth, mHeight);
94 | } else if ( mImageFormat.equalsIgnoreCase("YV12")) {
95 | ColorSpaceManager.YV12toYUV420PackedSemiPlanar(data, value, mWidth, mHeight);
96 | }
97 | }
98 | mVideoBuffer.writeBytes(value, 0, 0, value.length);
99 | mStoringVideoFrames = true;
100 | } else {
101 | if (mVideoBuffer.getFrameCount() == mNumFramesBeforeStartingEncoders) {
102 | startEncodingVideo();
103 | } else if (mVideoBuffer.getFrameCount() <= mNumFramesToBuffer) {
104 | try {
105 | ColorSpaceManager.YV12toYUV420PackedSemiPlanar(data, value, mWidth, mHeight);
106 | mVideoBuffer.writeBytes(value, 0, ((mVideoBuffer.getFrameCount() - 1) * value.length), value.length);
107 | Log.w(TAG, " Frame " + mVideoBuffer.getFrameCount() + "color corrected!");
108 | Log.w(TAG, "Written " + mVideoBuffer.getFrameCount() + " frames written out to shared memory file!");
109 | } catch (IndexOutOfBoundsException e) {
110 | Log.e(TAG, e.toString());
111 | Log.e(TAG, "Error writing out frame number " + mVideoBuffer.getFrameCount());
112 | }
113 | } else {
114 | Log.w(TAG, "Finished writing out video frames!");
115 | mRecording = false;
116 | mStoringVideoFrames = false;
117 | }
118 | }
119 | } catch (IOException e) {
120 | Log.e(TAG, e.getMessage());
121 | }
122 | }
123 | }
124 |
125 | public synchronized SharedVideoMemory getSharedMemFile() {
126 | return mVideoBuffer;
127 | }
128 |
129 | public synchronized void setRecordingState(Boolean state) {
130 | mRecording = state;
131 | if (mRecording) {
132 | Log.e(TAG, "Recording set to true in FrameCatcher, Runthe encoders!");
133 | }
134 | }
135 |
136 | public synchronized Boolean getRecordingState() {
137 | return mRecording;
138 | }
139 |
140 | public synchronized Boolean isSavingVideoFrames() {
141 | return mStoringVideoFrames;
142 | }
143 |
144 | /**********************************************************************
145 | * getBitmapImageFromYUV returns a bitmap from an image captured in
146 | * the camera in YUV12 format. Image formats and video formats are not
147 | * the same thing.
148 | *******************************************************************/
149 | public static Bitmap getBitmapImageFromYUV(byte[] data, int width, int height) {
150 | YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, width, height, null);
151 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
152 | yuvimage.compressToJpeg(new Rect(0, 0, width, height), 80, baos);
153 | byte[] jdata = baos.toByteArray();
154 | BitmapFactory.Options bitmapFatoryOptions = new BitmapFactory.Options();
155 | bitmapFatoryOptions.inPreferredConfig = Bitmap.Config.RGB_565;
156 | return BitmapFactory.decodeByteArray(jdata, 0, jdata.length, bitmapFatoryOptions);
157 | }
158 |
159 | /**********************************************************************
160 | * saveBitmap() was used to debug the code and to save each captured
161 | * video frame into a JPEG bitmap on your mobile device
162 | * use with caution as it will flood your mobile device /Picture dir
163 | *******************************************************************/
164 | public void saveBitmap(Bitmap finalBitmap) throws IllegalStateException {
165 | String root = Environment.getExternalStorageDirectory().toString() + "/Pictures";
166 | Random generator = new Random();
167 | int n = 10000;
168 | n = generator.nextInt(n);
169 | String fname = "Image-" + n + ".jpg";
170 | File file = new File(root, fname);
171 | if (file.exists()) {
172 | boolean status = file.delete();
173 | if (!status) throw new IllegalStateException("Unable to delete File");
174 | }
175 | try {
176 | FileOutputStream out = new FileOutputStream(file);
177 | finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
178 | out.flush();
179 | out.close();
180 | } catch (IOException e) {
181 | Log.e(TAG, e.getMessage());
182 | }
183 | }
184 |
185 | /**********************************************************************
186 | * startEncodingVideo - start the encoding by wraps its classes from
187 | * the catcher as its an implementation detail
188 | *******************************************************************/
189 | public synchronized void startEncodingVideo() {
190 | mRecording = false;
191 | mStoringVideoFrames = false;
192 | if (callback != null) {
193 | callback.startVideoEncoder();
194 | }
195 | }
196 |
197 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/callbacks/FramesReadyCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.callbacks;
17 |
18 | public interface FramesReadyCallback {
19 | void recordAudio();
20 | void startVideoEncoder();
21 | void playLazerSound();
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/cameras/AndroidCamera.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.cameras;
2 | import android.annotation.TargetApi;
3 | import android.content.Context;
4 | import android.graphics.SurfaceTexture;
5 | import android.hardware.Camera;
6 | import android.os.Build;
7 | import android.util.Log;
8 |
9 | import com.constantinnovationsinc.livemultimedia.previews.VideoPreview;
10 | import com.constantinnovationsinc.livemultimedia.exceptions.CameraException;
11 | import com.constantinnovationsinc.livemultimedia.views.CameraView;
12 |
13 | public class AndroidCamera {
14 | public static final int PHOTO = 1;
15 | public static final int VIDEO = 2;
16 | public static final int BOTH = 3;
17 | private static final String TAG = AndroidCamera.class.getCanonicalName();
18 | private boolean mCameraSetup = false;
19 | private boolean mCameraOpen = false;
20 | private Context mContext = null;
21 | private BaseCamera mCamera = null;
22 | private boolean mUseLegecyApi = false;
23 | private boolean mUseLimitedApi = false;
24 | private boolean mUseFullApi = false;
25 | private int mCameraMode = 0;
26 | private int mCurrentApiVersion = -1;
27 |
28 | public AndroidCamera() {
29 | Log.w(TAG, "Android Camera default constructor!");
30 | }
31 |
32 | public AndroidCamera(Context context) {
33 | mContext = context;
34 | }
35 |
36 | public AndroidCamera(Context context, int mode) {
37 | mContext = context;
38 | mCameraMode = mode;
39 | setupCamera(mCameraMode, null);
40 | }
41 |
42 | public AndroidCamera(Context context, int mode, CameraView view) {
43 | mContext = context;
44 | mCameraMode = mode;
45 | setupCamera(mCameraMode, view);
46 | }
47 |
48 | public void setupCamera(int mode, CameraView view) {
49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
50 | useLegacyCameraApi();
51 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
52 | useCamera2Api(view);
53 | }
54 | mCameraMode = mode;
55 | if (mCameraMode == VIDEO) {
56 | BaseCamera.VIDEO_MODE = true;
57 | mCamera.setVideoPreview(view);
58 | } else if (mCameraMode == PHOTO) {
59 | BaseCamera.PHOTO_MODE = true;
60 | } else if (mCameraMode == BOTH) {
61 | BaseCamera.BOTH_MODE = true;
62 | }
63 | mCameraSetup = true;
64 | }
65 |
66 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
67 | public void setupVideoCapture() {
68 | ((LollipopCamera)mCamera).setupVideoCapture();
69 | }
70 |
71 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
72 | public synchronized void openCamera(int width, int height) {
73 | ((LollipopCamera)mCamera).openCamera(width, height);
74 | }
75 |
76 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
77 | public void configureTransform(int width, int height) {
78 | ((LollipopCamera)mCamera).configureTransform(width, height);
79 | }
80 |
81 | public void stopCamera() {
82 | Log.d(TAG, "Camera released and SurfaceTextureListener is not null!");
83 | if (mUseLimitedApi || mUseFullApi ) {
84 | ((LollipopCamera)mCamera).closeCamera();
85 | mCamera = null;
86 | }
87 | }
88 |
89 | public synchronized AndroidCamera startBackCamera() throws IllegalStateException {
90 | try {
91 | if (mUseLegecyApi) {
92 | mCamera = ((JellyBeanCamera) mCamera).startBackCamera();
93 | } else if (mUseLimitedApi || mUseFullApi ) {
94 | mCamera = ((LollipopCamera) mCamera).startFrontCamera();
95 | }
96 | } catch (IllegalStateException state) {
97 | Log.e(TAG, state.getMessage());
98 | }
99 | return this;
100 | }
101 |
102 | public synchronized AndroidCamera startFrontCamera() throws CameraException{
103 | try {
104 | if (mUseLegecyApi) {
105 | mCamera = ((JellyBeanCamera) mCamera).startFrontCamera();
106 | } else if (mUseLimitedApi || mUseFullApi ) {
107 | mCamera = ((LollipopCamera) mCamera).startFrontCamera();
108 | }
109 | } catch (IllegalStateException state) {
110 | throw new CameraException(state.getMessage());
111 | }
112 | return this;
113 | }
114 |
115 | private void useLegacyCameraApi() {
116 | mCamera = new JellyBeanCamera(mContext);
117 | mUseLegecyApi = true;
118 | mUseLimitedApi = false;
119 | mUseFullApi = false;
120 | }
121 |
122 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
123 | private void useCamera2Api(CameraView view) {
124 | mCamera = new LollipopCamera(mContext, view);
125 | mUseLegecyApi = false;
126 | // see what mode the camera is reporting
127 | String support;
128 | support = ((LollipopCamera)mCamera).getCapabilities(BaseCamera.FRONT_CAMERA);
129 | if (support != null) {
130 | if (support.contentEquals(BaseCamera.LEGACY)) {
131 | Log.e(TAG, "_________________________________________________________________________");
132 | Log.e(TAG,"Legacy Camera api is supported but Android version is Lollipop or better!!");
133 | Log.e(TAG, "_________________________________________________________________________");
134 | mUseLegecyApi = true;
135 | } else if (support.contentEquals(BaseCamera.LIMITED)) {
136 | Log.d(TAG,"_________________________________________________________________________");
137 | Log.d(TAG, "LIMITED Camera api is supported for Android version is Lollipop or better!!");
138 | Log.d(TAG,"_________________________________________________________________________");
139 | mUseLimitedApi = true;
140 | } else if (support.contentEquals(BaseCamera.FULL)) {
141 | Log.d(TAG,"_________________________________________________________________________");
142 | Log.d(TAG, "FULL Camera api is supported for Android version is Lollipop or better!!");
143 | Log.d(TAG,"_________________________________________________________________________");
144 | mUseFullApi = true;
145 | }
146 | }
147 | }
148 |
149 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/cameras/BaseCamera.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.cameras;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.constantinnovationsinc.livemultimedia.previews.VideoPreview;
7 | import com.constantinnovationsinc.livemultimedia.views.CameraView;
8 |
9 | public class BaseCamera {
10 | private static final String TAG = BaseCamera.class.getCanonicalName();
11 | protected static final String NULL_IN_START_FRONT_CAMERA = "Camera is Null in startFrontCamera()";
12 | protected static final String NULL_IN_START_BACK_CAMERA = "Camera is Null in startBackCamera()";
13 | protected static final String NULL_IN_GET_PARAMETERS = "Camera object is Null in getParameters()";
14 | protected static final String NULL_IN_GET_SHARED_MEM_FILE = "FramesReadyCallback is Null in getSharedMemFile()";
15 | protected static final String NULL_IN_SET_RECORDING_STATE = "FramesReadyCallback is Null in setRecordingState()";
16 | protected static final String NULL_IN_GET_RECORDING_STATE = "FramesReadyCallback is Null in getRecordingState()";
17 | protected static final String NULL_IN_SET_RECORD_HINT = "Camera.Parameters is Null in SetRecordHint()";
18 | protected static final String ARGUMENT_NULL_IN_SET_ONFRAMES_READY_CALLBACK = "Passing Null for a callback in setOnFramesReadyCallBack()";
19 | protected static final String NULL_IN_SET_ONFRAMES_READY_CALLBACK = "FramesReadyCallback is Null in setOnFramesReadyCallBack()";
20 | protected static final String LEGACY = "LEGACY";
21 | protected static final String LIMITED = "LIMITED";
22 | protected static final String FULL = "FULL";
23 | protected static final int ENCODING_WIDTH = 1280;
24 | protected static final int ENCODING_HEIGHT = 720;
25 | protected static final int BITRATE = 6000000;
26 | protected static final int NUM_CAMERA_PREVIEW_BUFFERS = 2;
27 | protected int mBitRate = -1;
28 | protected int mEncodingWidth = -1;
29 | protected int mEncodingHeight = -1;
30 | protected long mPreviewWidth = -1;
31 | protected long mPreviewHeight = -1;
32 | protected int mImageFormat = -1;
33 | protected CameraView mVideoPreview = null;
34 | protected static boolean VIDEO_MODE = false;
35 | protected static boolean PHOTO_MODE = false;
36 | protected static boolean BOTH_MODE = false;
37 | private Context mContext = null;
38 | public static final int BACK_CAMERA = 0;
39 | public static final int FRONT_CAMERA = 1;
40 |
41 |
42 | public BaseCamera() {
43 | Log.w(TAG, "Android Camera constructor!");
44 | }
45 |
46 | public BaseCamera(Context context) {
47 | mContext = context;
48 | }
49 |
50 | protected Context getContext() {
51 | return mContext;
52 | }
53 |
54 | public void setVideoPreview(CameraView preview) {
55 | mVideoPreview = preview;
56 | }
57 | public CameraView getVideoPreview() {
58 | return mVideoPreview;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/exceptions/CameraException.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.exceptions;
2 | import android.util.Log;
3 |
4 | public class CameraException extends Exception{
5 | private static final String TAG = CameraException.class.getCanonicalName();
6 |
7 | public CameraException() {
8 | super();
9 | }
10 | public CameraException(String detailMessage) {
11 | super(detailMessage);
12 | }
13 |
14 | public CameraException(String detailMessage, Throwable throwable) {
15 | super(detailMessage, throwable);
16 | Log.e(TAG, detailMessage);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/fragments/Camera2VideoFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.fragments;
17 | import android.app.Activity;
18 | import android.app.AlertDialog;
19 | import android.content.res.Configuration;
20 | import android.hardware.Camera;
21 | import android.os.Build;
22 | import android.support.v4.app.Fragment;
23 | import android.os.Bundle;
24 | import android.util.Log;
25 | import android.view.Gravity;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.widget.FrameLayout;
30 | import android.widget.Button;
31 | import com.constantinnovationsinc.livemultimedia.previews.VideoPreview;
32 | import com.constantinnovationsinc.livemultimedia.views.CameraView;
33 | import com.constantinnovationsinc.livemultimedia.R;
34 |
35 |
36 | public class Camera2VideoFragment extends Fragment implements View.OnClickListener {
37 | private static final String TAG = Camera2VideoFragment.class.getCanonicalName();
38 | private FrameLayout mVideoPreviewFrame;
39 | private Boolean mRecording = false;
40 | private CameraView mCameraView = null; // for new api
41 | private VideoPreview mVideoPreview = null; // for legacy api
42 | private final static int mCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
43 | public static Camera2VideoFragment newInstance() {
44 | Camera2VideoFragment fragment = new Camera2VideoFragment();
45 | fragment.setRetainInstance(true);
46 | return fragment;
47 | }
48 |
49 | @Override
50 | public void onDestroyView() {
51 | super.onDestroyView();
52 | destroyVideoPreviewWindow();
53 | }
54 |
55 | @Override
56 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
57 | Bundle savedInstanceState) {
58 | Log.d(TAG, "onCreateView for Camera2VideoFragment");
59 | View view = inflater.inflate(R.layout.fragment_camera2_video, container, false);
60 |
61 | if (mVideoPreviewFrame != null) {
62 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
63 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
64 | createVideoPreviewWindow(Camera.CameraInfo.CAMERA_FACING_BACK);
65 | }
66 | if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
67 | createVideoPreviewWindowEnhanced();
68 | }
69 | }
70 |
71 | return view;
72 | }
73 |
74 | @Override
75 | public void onViewCreated(final View view, Bundle savedInstanceState) {
76 | Button mButtonBackCamera = (Button) view.findViewById(R.id.backcamera);
77 | Button mButtonFrontCamera = (Button) view.findViewById(R.id.frontcamera);
78 | Button mButtonRecordVideo = (Button) view.findViewById(R.id.recordvideo);
79 | Button mButtonExit = (Button) view.findViewById(R.id.exit);
80 | if (mButtonRecordVideo != null) {
81 | mButtonRecordVideo.setOnClickListener(this);
82 | }
83 | if (mButtonExit != null) {
84 | mButtonExit.setOnClickListener(this);
85 | }
86 | if (mButtonBackCamera != null) {
87 | mButtonBackCamera.setOnClickListener(this);
88 | }
89 | if (mButtonFrontCamera != null) {
90 | mButtonFrontCamera.setOnClickListener(this);
91 | }
92 | view.findViewById(R.id.info).setOnClickListener(this);
93 | mCameraView = (CameraView) view.findViewById(R.id.texture);
94 | }
95 |
96 | @Override
97 | public void onResume() {
98 | super.onResume();
99 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
100 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
101 | if (mVideoPreview != null) {
102 | mVideoPreview.prepare();
103 | }
104 | }
105 | if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
106 | if(mCameraView != null) {
107 | mCameraView.startBackgroundThread();
108 | if (mCameraView.isAvailable()) {
109 | mCameraView.openCamera(mCameraView.getWidth(), mCameraView.getHeight());
110 | } else {
111 | // mCameraView.setSurfaceTextureListener(mSurfaceTextureListener);
112 | }
113 | mCameraView.prepare();
114 | }
115 | }
116 | }
117 |
118 | @Override
119 | public void onPause() {
120 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
121 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
122 | if (mVideoPreview != null) {
123 | mVideoPreview.halt();
124 | }
125 | }
126 | if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
127 | mCameraView.halt();
128 | mCameraView.stopBackgroundThread();
129 | }
130 | super.onPause();
131 | }
132 |
133 | @SuppressWarnings("deprecation")
134 | @Override
135 | public void onClick(View view) {
136 | switch (view.getId()) {
137 | case R.id.backcamera: {
138 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
139 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
140 | createNewVideoPreview(Camera.CameraInfo.CAMERA_FACING_BACK);
141 | }
142 | if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
143 | createNewVideoPreviewEnchanced(0);
144 | }
145 | }
146 | break;
147 | case R.id.frontcamera: {
148 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
149 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
150 | createNewVideoPreview(Camera.CameraInfo.CAMERA_FACING_FRONT);
151 | }
152 | if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
153 | createNewVideoPreviewEnchanced(1);
154 | }
155 | }
156 | break;
157 | case R.id.recordvideo: {
158 | mRecording = !mRecording;
159 | Button mButtonRecordVideo = (Button) view.findViewById(R.id.recordvideo);
160 | if (mRecording) {
161 | mButtonRecordVideo.setText("Stop");
162 | } else {
163 | mButtonRecordVideo.setText("Record");
164 | }
165 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
166 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
167 | mVideoPreview.setRecordingState(mRecording);
168 | }
169 | }
170 | break;
171 | case R.id.exit: {
172 | if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
173 | mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) {
174 | destroyVideoPreviewWindow();
175 | }
176 | Activity activity = getActivity();
177 | if (activity != null) {
178 | activity.finish();
179 | }
180 | }
181 | break;
182 | case R.id.info: {
183 | Activity activity = getActivity();
184 | if (activity != null) {
185 | new AlertDialog.Builder(activity)
186 | .setMessage(R.string.intro_message)
187 | .setPositiveButton(android.R.string.ok, null)
188 | .show();
189 | }
190 | break;
191 | }
192 | }
193 | }
194 |
195 | private void createNewVideoPreview(int cameraId) {
196 | if (mVideoPreviewFrame != null && mVideoPreview != null) {
197 | destroyVideoPreviewWindow();
198 | }
199 | if (mVideoPreviewFrame != null && mVideoPreview == null) {
200 | createVideoPreviewWindow(cameraId);
201 | }
202 | }
203 |
204 | private void createNewVideoPreviewEnchanced(int cameraId) {
205 | if (mVideoPreviewFrame != null && mCameraView != null) {
206 | destroyVideoPreviewWindowEnhanced();
207 | }
208 | if (mVideoPreviewFrame != null && mCameraView == null) {
209 | createVideoPreviewWindowEnhanced();
210 | }
211 | }
212 |
213 | private void destroyVideoPreviewWindow() {
214 | if (mVideoPreview != null) {
215 | mVideoPreview.halt();
216 | mVideoPreviewFrame.removeAllViews();
217 | mVideoPreview = null;
218 | }
219 | }
220 |
221 | private void destroyVideoPreviewWindowEnhanced() {
222 | if (mCameraView != null) {
223 | mCameraView.halt();
224 | mVideoPreviewFrame.removeAllViews();
225 | mCameraView = null;
226 | }
227 | }
228 |
229 | private void createVideoPreviewWindowEnhanced( ) {
230 | if (mCameraView != null) {
231 | mCameraView.mRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
232 | mCameraView.prepare();
233 | }
234 | }
235 |
236 | private void createVideoPreviewWindow(int activeCam) {
237 | Log.d(TAG, "Creating initial VideoPreview!");
238 | previewWindowSetup(activeCam);
239 | mVideoPreviewFrame.addView(mVideoPreview);
240 | }
241 |
242 | private void previewWindowSetup(int activeCam) {
243 | int mEncodingWidth = 1280;
244 | int mEncodingHeight = 720;
245 | // add surface listeners
246 | mVideoPreview = new VideoPreview(getActivity());
247 | mVideoPreview.prepare();
248 | mVideoPreview.setActiveCamera(activeCam);
249 | // set camera rotation
250 | mVideoPreview.mRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
251 | // set layout
252 | if (mVideoPreview.getPreviewSizeHeight() == mEncodingHeight &&
253 | mVideoPreview.getPreviewSizeWidth() == mEncodingWidth) {
254 | mVideoPreview.setLayoutParams(new FrameLayout.LayoutParams(
255 | mVideoPreview.getPreviewSizeWidth(),
256 | mVideoPreview.getPreviewSizeHeight(),
257 | Gravity.CENTER));
258 | } else {
259 | mVideoPreview.setLayoutParams(new FrameLayout.LayoutParams(
260 | mEncodingWidth,
261 | mEncodingHeight,
262 | Gravity.CENTER));
263 | }
264 | if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
265 | mVideoPreview.setAspectRatio(16, 9);
266 | }
267 | }
268 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/handlers/AudioEncoderHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.handlers;
17 | import android.os.Handler;
18 | import android.os.Looper;
19 | import android.os.Message;
20 | import android.os.Bundle;
21 |
22 | public class AudioEncoderHandler extends Handler {
23 | public AudioEncoderHandler(Looper myLooper) {
24 | super(myLooper );
25 | }
26 | public void handleMessage(Message msg) {
27 | if (msg != null) {
28 | Bundle bundle = msg.getData();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/handlers/CameraHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.handlers;
17 | import android.os.Bundle;
18 | import android.os.Handler;
19 | import android.os.Looper;
20 | import android.os.Message;
21 |
22 | public class CameraHandler extends Handler {
23 | public CameraHandler(Looper myLooper) {
24 | super(myLooper);
25 | }
26 | public void handleMessage(Message msg) {
27 | if (msg != null) {
28 | Bundle bundle = msg.getData();
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/handlers/VideoEncoderHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.handlers;
17 | import android.os.Bundle;
18 | import android.os.Handler;
19 | import android.os.Looper;
20 | import android.os.Message;
21 |
22 | public class VideoEncoderHandler extends Handler {
23 | public VideoEncoderHandler(Looper myLooper) {
24 | super(myLooper);
25 | }
26 | public void handleMessage(Message msg) {
27 | if (msg != null) {
28 | Bundle bundle = msg.getData();
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/receivers/NetworkStateReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.receivers;
17 | import android.content.BroadcastReceiver;
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.util.Log;
21 | import android.net.ConnectivityManager;
22 | import android.net.NetworkInfo;
23 |
24 | public class NetworkStateReceiver extends BroadcastReceiver {
25 |
26 | public NetworkStateReceiver() {
27 | }
28 |
29 | @Override
30 | public void onReceive(Context context, Intent intent) {
31 | Log.d("app","Network connectivity change");
32 | if(intent.getExtras()!=null) {
33 | final ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
34 | final NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
35 | if(ni != null && ni.isConnectedOrConnecting()) {
36 | Log.i("app", "Network " + ni.getTypeName() + " connected");
37 | }
38 | if (ni != null && ni.isAvailable()) {
39 | Log.i("app", "Network " + ni.getTypeName() + " is avaialable");
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/recorders/AVRecorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.recorders;
17 | import android.content.Context;
18 | import android.media.MediaFormat;
19 | import android.util.Log;
20 | import android.app.Activity;
21 | import android.os.Environment;
22 | import android.media.SoundPool;
23 | import android.media.AudioManager;
24 | import com.constantinnovationsinc.livemultimedia.app.MultimediaApp;
25 | import com.constantinnovationsinc.livemultimedia.encoders.GPUEncoder;
26 | import com.constantinnovationsinc.livemultimedia.encoders.AudioEncoder;
27 | import com.constantinnovationsinc.livemultimedia.utilities.DeviceNetwork;
28 | import com.constantinnovationsinc.livemultimedia.utilities.SharedVideoMemory;
29 | import com.constantinnovationsinc.livemultimedia.utilities.HttpFileUpload;
30 | import com.constantinnovationsinc.livemultimedia.R;
31 | import java.io.File;
32 | import java.nio.ByteBuffer;
33 | import java.util.HashMap;
34 | import java.io.FileInputStream;
35 | import java.io.FileNotFoundException;
36 |
37 | public class AVRecorder implements Runnable{
38 | private static final String TAG = AVRecorder.class.getCanonicalName();
39 | private static final String ENCODING_THREAD_NAME = "AVEncodingThread";
40 | private static final String START_CAPTURE_FRAMES_SOUND = "StartCaptureSound";
41 | private static final String START_ENCODERS_SOUND = "StartEncodersSound";
42 | private static final String MP4_FILE_WRITTEN_SOUND = "MP4FileWrittenSound";
43 |
44 | /**
45 | * How long to wait for the next buffer to become available.
46 | */
47 | private static final int TIMEOUT_USEC = 10000;
48 | /**
49 | * Where to output the test files.
50 | */
51 | private static final int FRAME_RATE = 30;
52 | private static final File OUTPUT_FILENAME_DIR = Environment.getExternalStorageDirectory();
53 | // parameters for the video encoder
54 | private static final String OUTPUT_VIDEO_MIME_TYPE = "video/avc"; // H.264 Advanced Video Coding
55 |
56 | private static Boolean mAudioRecordingStopped = false;
57 | /** Context */
58 | private Context mContext = null;
59 | /** Encoders */
60 | private GPUEncoder mVideoEncoder = null;
61 | private AudioEncoder mAudioEncoder = null;
62 | /** Encoder status */
63 | private Boolean mEncodingStarted = false;
64 |
65 | /** SharedVideoMemory that holds all video buffers */
66 | private Boolean mSoundLoaded = false;
67 | private HashMap soundPoolMap;
68 | private int soundID = 1;
69 | private int mProcessAudioFrames = 0;
70 | /**
71 | * Width of the output frames.
72 | */
73 | private int mWidth = -1;
74 | /**
75 | * Height of the output frames.
76 | */
77 | private int mHeight = -1;
78 | /**
79 | * The destination file for the encoded output.
80 | */
81 | public SharedVideoMemory mSharedMemFile = null;
82 | public SoundPool soundPool = null;
83 | public int mEncodingWidth = 0;
84 | public int mEncodingHeight = 0;
85 |
86 |
87 | private AVRecorder() {
88 |
89 | }
90 |
91 | @Override
92 | public void run() {
93 | prepare();
94 | }
95 |
96 | /*********************************************************************
97 | * Constructor
98 | * @param context - the context associated with this encoding thread
99 | *********************************************************************/
100 | public AVRecorder(Context context) {
101 | mContext = context;
102 | mEncodingStarted = false;
103 | }
104 |
105 | @SuppressWarnings("unused")
106 | public synchronized void setSharedMemFile(SharedVideoMemory mem){
107 | if (mem == null) {
108 | Log.e(TAG,"SharedMemoryFile is Null passed to AVRecorder!");
109 | }
110 | mSharedMemFile = mem;
111 | }
112 |
113 | public synchronized void prepare() {
114 | if (!mEncodingStarted) {
115 | Log.w(TAG, "AVRecorder prepare executing....");
116 | try {
117 | mVideoEncoder = new GPUEncoder((MultimediaApp)mContext.getApplicationContext(), this, mWidth, mHeight);
118 | mAudioEncoder = new AudioEncoder((MultimediaApp) mContext.getApplicationContext());
119 | mVideoEncoder.prepare();
120 | mAudioEncoder.prepare();
121 | } catch (Exception e) {
122 | Log.e(TAG, e.toString());
123 | }
124 | }
125 | }
126 |
127 |
128 | public synchronized void uploadFile() {
129 | Thread uploadThread = new Thread(new Runnable() {
130 | @Override
131 | public void run() {
132 | try {
133 | // Set your file path here
134 | FileInputStream fstrm = new FileInputStream(Environment.getExternalStorageDirectory().toString() + "/Movies/EncodedAV-1280x720.mp4");
135 | // Set your server page url (and the file title/description)
136 | String url = "http://" + DeviceNetwork.getLocalIpAddress() + ":8080";
137 | HttpFileUpload hfu = new HttpFileUpload(url, "Video file", "Recorded file");
138 | hfu.Send_Now(fstrm);
139 | } catch (FileNotFoundException e) {
140 | Log.e(TAG, e.toString());
141 | }
142 | }
143 | });
144 | uploadThread.start();
145 | }
146 |
147 | @SuppressWarnings("deprecation")
148 | public synchronized void playSound(String sound) {
149 | soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
150 | soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
151 | @Override
152 | public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
153 | mSoundLoaded = true;
154 | Activity activity = (Activity)mContext;
155 | if (activity != null) {
156 | AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
157 | float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
158 | float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
159 | audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int)maxVolume, 0);
160 | float leftVolume = 1f;
161 | float rightVolume = 1f;
162 | int priority = 1;
163 | int no_loop = 0;
164 | float normal_playback_rate = 1f;
165 | int soundSuccess = soundPool.play(soundID, leftVolume, rightVolume, priority, no_loop, normal_playback_rate);
166 | if (soundSuccess == 0) {
167 | Log.e(TAG, "Sound failed to play");
168 | }
169 | }
170 | }
171 | });
172 | if (sound.equalsIgnoreCase( START_CAPTURE_FRAMES_SOUND )) {
173 | soundID = soundPool.load(mContext, R.raw.powerup, 1);
174 | } else if (sound.equalsIgnoreCase( START_ENCODERS_SOUND )) {
175 | soundID = soundPool.load(mContext, R.raw.powerup, 1);
176 | } else if (sound.equalsIgnoreCase(MP4_FILE_WRITTEN_SOUND)) {
177 | soundID = soundPool.load(mContext, R.raw.mp4written, 1);
178 | }
179 | }
180 |
181 |
182 | public synchronized void release() {
183 | Log.w(TAG, "Performaing cleanup of AVRecorder");
184 | mVideoEncoder.release();
185 | mAudioEncoder.release();
186 | }
187 |
188 | public synchronized ByteBuffer getNextAudioFrame() {
189 | ByteBuffer audioFrame = null;
190 | int audioFramesLeft = mAudioEncoder.getRemainingAudioFramesCount();
191 | if (audioFramesLeft > 0) {
192 | audioFrame = mAudioEncoder.getNextAudioFrame();
193 | }
194 | return audioFrame;
195 | }
196 |
197 | public synchronized AudioEncoder getAudioEncoder() {
198 | return mAudioEncoder;
199 | }
200 |
201 | public synchronized GPUEncoder getVideoEncoder() {
202 | return mVideoEncoder;
203 | }
204 |
205 | public synchronized MediaFormat getAudioFormat() {
206 | return mAudioEncoder.getAudioFormat();
207 | }
208 |
209 | /*********************************
210 | * Sets the desired frame size.
211 | *********************************/
212 | public synchronized void setSize(int width, int height) {
213 | if ((width % 16) != 0 || (height % 16) != 0) {
214 | Log.w(TAG, "WARNING: width or height not multiple of 16");
215 | }
216 | mWidth = width;
217 | mHeight = height;
218 | }
219 |
220 | public synchronized void setEncodingWidth(int width) {
221 | mEncodingWidth = width;
222 | }
223 |
224 | public synchronized void setEncodingHeight( int height) {
225 | mEncodingHeight = height;
226 | }
227 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/renders/TextureRender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.constantinnovationsinc.livemultimedia.renders;
18 |
19 | import android.graphics.SurfaceTexture;
20 | import android.opengl.GLES11Ext;
21 | import android.opengl.GLES20;
22 | import android.opengl.Matrix;
23 | import android.util.Log;
24 |
25 | import java.nio.ByteBuffer;
26 | import java.nio.ByteOrder;
27 | import java.nio.FloatBuffer;
28 |
29 | /**
30 | * Code for rendering a texture onto a surface using OpenGL ES 2.0.
31 | */
32 | public class TextureRender {
33 | private static final String TAG = TextureRender.class.getCanonicalName();
34 |
35 | private static final int FLOAT_SIZE_BYTES = 4;
36 | private static final int TRIANGLE_VERTICES_DATA_STRIDE_BYTES = 5 * FLOAT_SIZE_BYTES;
37 | private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0;
38 | private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3;
39 |
40 | private FloatBuffer mTriangleVertices;
41 |
42 | private static final String VERTEX_SHADER =
43 | "uniform mat4 uMVPMatrix;\n" +
44 | "uniform mat4 uSTMatrix;\n" +
45 | "attribute vec4 aPosition;\n" +
46 | "attribute vec4 aTextureCoord;\n" +
47 | "varying vec2 vTextureCoord;\n" +
48 | "void main() {\n" +
49 | " gl_Position = uMVPMatrix * aPosition;\n" +
50 | " vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
51 | "}\n";
52 |
53 | private static final String FRAGMENT_SHADER =
54 | "#extension GL_OES_EGL_image_external : require\n" +
55 | "precision mediump float;\n" + // highp here doesn't seem to matter
56 | "varying vec2 vTextureCoord;\n" +
57 | "uniform samplerExternalOES sTexture;\n" +
58 | "void main() {\n" +
59 | " gl_FragColor = texture2D(sTexture, vTextureCoord);\n" +
60 | "}\n";
61 |
62 | private float[] mMVPMatrix = new float[16];
63 | private float[] mSTMatrix = new float[16];
64 |
65 | private int mProgram;
66 | private int mTextureID = -12345;
67 | private int muMVPMatrixHandle;
68 | private int muSTMatrixHandle;
69 | private int maPositionHandle;
70 | private int maTextureHandle;
71 |
72 | public TextureRender() {
73 | final float[] mTriangleVerticesData = {
74 | // X, Y, Z, U, V
75 | -1.0f, -1.0f, 0, 0.f, 0.f,
76 | 1.0f, -1.0f, 0, 1.f, 0.f,
77 | -1.0f, 1.0f, 0, 0.f, 1.f,
78 | 1.0f, 1.0f, 0, 1.f, 1.f,
79 | };
80 |
81 | mTriangleVertices = ByteBuffer.allocateDirect(
82 | mTriangleVerticesData.length * FLOAT_SIZE_BYTES)
83 | .order(ByteOrder.nativeOrder()).asFloatBuffer();
84 | mTriangleVertices.put(mTriangleVerticesData).position(0);
85 |
86 | Matrix.setIdentityM(mSTMatrix, 0);
87 | }
88 |
89 | public int getTextureId() {
90 | return mTextureID;
91 | }
92 |
93 | public void drawFrame(SurfaceTexture st) {
94 | checkGlError("onDrawFrame start");
95 | st.getTransformMatrix(mSTMatrix);
96 |
97 | GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
98 | GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
99 |
100 | GLES20.glUseProgram(mProgram);
101 | checkGlError("glUseProgram");
102 |
103 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
104 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
105 |
106 | mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
107 | GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
108 | TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
109 | checkGlError("glVertexAttribPointer maPosition");
110 | GLES20.glEnableVertexAttribArray(maPositionHandle);
111 | checkGlError("glEnableVertexAttribArray maPositionHandle");
112 |
113 | mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
114 | GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
115 | TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
116 | checkGlError("glVertexAttribPointer maTextureHandle");
117 | GLES20.glEnableVertexAttribArray(maTextureHandle);
118 | checkGlError("glEnableVertexAttribArray maTextureHandle");
119 |
120 | Matrix.setIdentityM(mMVPMatrix, 0);
121 | GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
122 | GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
123 |
124 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
125 | checkGlError("glDrawArrays");
126 | GLES20.glFinish();
127 | }
128 |
129 | /**
130 | * Initializes GL state. Call this after the EGL surface has been created and made current.
131 | */
132 | public void surfaceCreated() {
133 | mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
134 | if (mProgram == 0) {
135 | throw new RuntimeException("failed creating program");
136 | }
137 | maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
138 | checkGlError("glGetAttribLocation aPosition");
139 | if (maPositionHandle == -1) {
140 | throw new RuntimeException("Could not get attrib location for aPosition");
141 | }
142 | maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
143 | checkGlError("glGetAttribLocation aTextureCoord");
144 | if (maTextureHandle == -1) {
145 | throw new RuntimeException("Could not get attrib location for aTextureCoord");
146 | }
147 |
148 | muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
149 | checkGlError("glGetUniformLocation uMVPMatrix");
150 | if (muMVPMatrixHandle == -1) {
151 | throw new RuntimeException("Could not get attrib location for uMVPMatrix");
152 | }
153 |
154 | muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
155 | checkGlError("glGetUniformLocation uSTMatrix");
156 | if (muSTMatrixHandle == -1) {
157 | throw new RuntimeException("Could not get attrib location for uSTMatrix");
158 | }
159 |
160 |
161 | int[] textures = new int[1];
162 | GLES20.glGenTextures(1, textures, 0);
163 |
164 | mTextureID = textures[0];
165 | GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
166 | checkGlError("glBindTexture mTextureID");
167 |
168 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
169 | GLES20.GL_NEAREST);
170 | GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
171 | GLES20.GL_LINEAR);
172 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S,
173 | GLES20.GL_CLAMP_TO_EDGE);
174 | GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T,
175 | GLES20.GL_CLAMP_TO_EDGE);
176 | checkGlError("glTexParameter");
177 | }
178 |
179 | /**
180 | * Replaces the fragment shader.
181 | */
182 | public void changeFragmentShader(String fragmentShader) {
183 | GLES20.glDeleteProgram(mProgram);
184 | mProgram = createProgram(VERTEX_SHADER, fragmentShader);
185 | if (mProgram == 0) {
186 | throw new RuntimeException("failed creating program");
187 | }
188 | }
189 |
190 | private int loadShader(int shaderType, String source) {
191 | int shader = GLES20.glCreateShader(shaderType);
192 | checkGlError("glCreateShader type=" + shaderType);
193 | GLES20.glShaderSource(shader, source);
194 | GLES20.glCompileShader(shader);
195 | int[] compiled = new int[1];
196 | GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
197 | if (compiled[0] == 0) {
198 | Log.e(TAG, "Could not compile shader " + shaderType + ":");
199 | Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
200 | GLES20.glDeleteShader(shader);
201 | shader = 0;
202 | }
203 | return shader;
204 | }
205 |
206 | private int createProgram(String vertexSource, String fragmentSource) {
207 | int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
208 | if (vertexShader == 0) {
209 | return 0;
210 | }
211 | int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
212 | if (pixelShader == 0) {
213 | return 0;
214 | }
215 |
216 | int program = GLES20.glCreateProgram();
217 | checkGlError("glCreateProgram");
218 | if (program == 0) {
219 | Log.e(TAG, "Could not create program");
220 | }
221 | GLES20.glAttachShader(program, vertexShader);
222 | checkGlError("glAttachShader");
223 | GLES20.glAttachShader(program, pixelShader);
224 | checkGlError("glAttachShader");
225 | GLES20.glLinkProgram(program);
226 | int[] linkStatus = new int[1];
227 | GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
228 | if (linkStatus[0] != GLES20.GL_TRUE) {
229 | Log.e(TAG, "Could not link program: ");
230 | Log.e(TAG, GLES20.glGetProgramInfoLog(program));
231 | GLES20.glDeleteProgram(program);
232 | program = 0;
233 | }
234 | return program;
235 | }
236 |
237 | public void checkGlError(String op) {
238 | int error = GLES20.glGetError();
239 | if (error != GLES20.GL_NO_ERROR) {
240 | Log.e(TAG, op + ": glError " + error);
241 | throw new RuntimeException(op + ": glError " + error);
242 | }
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/servers/InternalRewrite.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Paul S. Hawke (paul.hawke@gmail.com)
3 | * On: 9/15/13 at 2:52 PM
4 | */
5 | package com.constantinnovationsinc.livemultimedia.servers;
6 | import static com.constantinnovationsinc.livemultimedia.servers.NanoHTTPD.Response;
7 | import java.util.Map;
8 |
9 | public class InternalRewrite extends Response {
10 | private final String uri;
11 | private final Map headers;
12 |
13 | public InternalRewrite(Map headers, String uri) {
14 | super(null);
15 | this.headers = headers;
16 | this.uri = uri;
17 | }
18 |
19 | public String getUri() {
20 | return uri;
21 | }
22 |
23 | public Map getHeaders() {
24 | return headers;
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/servers/ServerRunner.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.servers;
2 | import java.io.IOException;
3 |
4 | public class ServerRunner {
5 | public static void run(Class serverClass) {
6 | try {
7 | executeInstance((NanoHTTPD) serverClass.newInstance());
8 | } catch (Exception e) {
9 | e.printStackTrace();
10 | }
11 | }
12 |
13 | public static void executeInstance(NanoHTTPD server) {
14 | try {
15 | server.start();
16 | } catch (IOException ioe) {
17 | System.err.println("Couldn't start server:\n" + ioe);
18 | System.exit(-1);
19 | }
20 |
21 | System.out.println("Server started, Hit Enter to stop.\n");
22 |
23 | try {
24 | System.in.read();
25 | } catch (Throwable ignored) {
26 | }
27 |
28 | server.stop();
29 | System.out.println("Server stopped.\n");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/servers/VideoServer.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.servers;
2 |
3 | import android.os.Environment;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import com.constantinnovationsinc.livemultimedia.servers.NanoHTTPD.Response.Status;
7 | import android.util.Log;
8 |
9 | public class VideoServer extends NanoHTTPD {
10 |
11 | public VideoServer(String hostname, int port) {
12 | super(hostname, 8080);
13 | }
14 |
15 | @Override
16 | public Response serve(IHTTPSession session) {
17 | FileInputStream fis = null;
18 | try {
19 | fis = new FileInputStream(Environment.getExternalStorageDirectory()
20 | + "/Movies/EncodedAV-1280x720.mp4");
21 | } catch (FileNotFoundException e) {
22 | Log.e("VideoServer: ", e.toString() );
23 | }
24 | return new NanoHTTPD.Response(Status.OK, "video/mp4", fis);
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/servers/WebServerPlugin.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.servers;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 | import com.constantinnovationsinc.livemultimedia.servers.NanoHTTPD.IHTTPSession;
6 |
7 | /**
8 | * @author Paul S. Hawke (paul.hawke@gmail.com)
9 | * On: 9/14/13 at 8:09 AM
10 | */
11 | public interface WebServerPlugin {
12 |
13 | void initialize(Map commandLineOptions);
14 |
15 | boolean canServeUri(String uri, File rootDir);
16 |
17 | NanoHTTPD.Response serveFile(String uri, Map headers, IHTTPSession session, File file, String mimeType);
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/servers/WebServerPluginInfo.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.servers;
2 | /**
3 | * @author Paul S. Hawke (paul.hawke@gmail.com)
4 | * On: 9/14/13 at 8:09 AM
5 | */
6 | public interface WebServerPluginInfo {
7 | String[] getMimeTypes();
8 |
9 | String[] getIndexFilesForMimeType(String mime);
10 |
11 | WebServerPlugin getWebServerPlugin(String mimeType);
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/surfaces/InputSurface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.constantinnovationsinc.livemultimedia.surfaces;
17 | import android.opengl.EGL14;
18 | import android.opengl.EGLExt;
19 | import android.opengl.EGLConfig;
20 | import android.opengl.EGLContext;
21 | import android.opengl.EGLDisplay;
22 | import android.opengl.EGLSurface;
23 | import android.util.Log;
24 | import android.view.Surface;
25 |
26 | /**
27 | * Holds state associated with a Surface used for MediaCodec encoder input.
28 | *
29 | * The constructor takes a Surface obtained from MediaCodec.createInputSurface(), and uses that
30 | * to create an EGL window surface. Calls to eglSwapBuffers() cause a frame of data to be sent
31 | * to the video encoder.
32 | */
33 | public class InputSurface {
34 | private static final String TAG = InputSurface.class.getCanonicalName();
35 | private static final boolean VERBOSE = false;
36 |
37 | private static final int EGL_RECORDABLE_ANDROID = 0x3142;
38 | private static final int EGL_OPENGL_ES2_BIT = 4;
39 |
40 | private EGLDisplay mEGLDisplay;
41 | private EGLContext mEGLContext;
42 | private EGLSurface mEGLSurface;
43 |
44 | private Surface mSurface;
45 |
46 | /**
47 | * Creates an InputSurface from a Surface.
48 | */
49 | public InputSurface(Surface surface) {
50 | if (surface == null) {
51 | throw new NullPointerException();
52 | }
53 | mSurface = surface;
54 |
55 | eglSetup();
56 | }
57 |
58 | /**
59 | * Prepares EGL. We want a GLES 2.0 context and a surface that supports recording.
60 | */
61 | private void eglSetup() {
62 | mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
63 | if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
64 | throw new RuntimeException("unable to get EGL14 display");
65 | }
66 | int[] version = new int[2];
67 | if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
68 | mEGLDisplay = null;
69 | throw new RuntimeException("unable to initialize EGL14");
70 | }
71 |
72 | // Configure EGL for pbuffer and OpenGL ES 2.0. We want enough RGB bits
73 | // to be able to tell if the frame is reasonable.
74 | int[] attribList = {
75 | EGL14.EGL_RED_SIZE, 8,
76 | EGL14.EGL_GREEN_SIZE, 8,
77 | EGL14.EGL_BLUE_SIZE, 8,
78 | EGL14.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
79 | EGL_RECORDABLE_ANDROID, 1,
80 | EGL14.EGL_NONE
81 | };
82 | EGLConfig[] configs = new EGLConfig[1];
83 | int[] numConfigs = new int[1];
84 | if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
85 | numConfigs, 0)) {
86 | throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
87 | }
88 |
89 | // Configure context for OpenGL ES 2.0.
90 | int[] attrib_list = {
91 | EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
92 | EGL14.EGL_NONE
93 | };
94 | mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
95 | attrib_list, 0);
96 | checkEglError("eglCreateContext");
97 | if (mEGLContext == null) {
98 | throw new RuntimeException("null context");
99 | }
100 |
101 | // Create a window surface, and attach it to the Surface we received.
102 | int[] surfaceAttribs = {
103 | EGL14.EGL_NONE
104 | };
105 | mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
106 | surfaceAttribs, 0);
107 | checkEglError("eglCreateWindowSurface");
108 | if (mEGLSurface == null) {
109 | throw new RuntimeException("surface was null");
110 | }
111 | }
112 |
113 | /**
114 | * Discard all resources held by this class, notably the EGL context. Also releases the
115 | * Surface that was passed to our constructor.
116 | */
117 | public void release() {
118 | if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
119 | // Clear the current context and surface to ensure they are discarded immediately.
120 | EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
121 | EGL14.EGL_NO_CONTEXT);
122 | }
123 | EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
124 | EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
125 | //EGL14.eglTerminate(mEGLDisplay);
126 |
127 | mSurface.release();
128 |
129 | // null everything out so future attempts to use this object will cause an NPE
130 | mEGLDisplay = null;
131 | mEGLContext = null;
132 | mEGLSurface = null;
133 |
134 | mSurface = null;
135 | }
136 |
137 | /**
138 | * Makes our EGL context and surface current.
139 | */
140 | public void makeCurrent() {
141 | if (!EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
142 | throw new RuntimeException("eglMakeCurrent failed");
143 | }
144 | }
145 |
146 | /**
147 | * Calls eglSwapBuffers. Use this to "publish" the current frame.
148 | */
149 | @SuppressWarnings("unused")
150 | public boolean swapBuffers() {
151 | return EGL14.eglSwapBuffers(mEGLDisplay, mEGLSurface);
152 | }
153 |
154 | /**
155 | * Returns the Surface that the MediaCodec receives buffers from.
156 | */
157 | public Surface getSurface() {
158 | return mSurface;
159 | }
160 |
161 | /**
162 | * Sends the presentation time stamp to EGL. Time is expressed in nanoseconds.
163 | */
164 | public void setPresentationTime(long nsecs) {
165 | EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, nsecs);
166 | }
167 |
168 | /**
169 | * Checks for EGL errors.
170 | */
171 | private void checkEglError(String msg) {
172 | boolean failed = false;
173 | int error;
174 | while ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
175 | Log.e(TAG, msg + ": EGL error: 0x" + Integer.toHexString(error));
176 | failed = true;
177 | }
178 | if (failed) {
179 | throw new RuntimeException("EGL error encountered (see log)");
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/surfaces/OutputSurface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.constantinnovationsinc.livemultimedia.surfaces;
17 | import android.graphics.SurfaceTexture;
18 | import android.opengl.EGL14;
19 | import android.util.Log;
20 | import android.view.Surface;
21 |
22 | import javax.microedition.khronos.egl.EGL10;
23 | import javax.microedition.khronos.egl.EGLConfig;
24 | import javax.microedition.khronos.egl.EGLContext;
25 | import javax.microedition.khronos.egl.EGLDisplay;
26 | import javax.microedition.khronos.egl.EGLSurface;
27 | import com.constantinnovationsinc.livemultimedia.renders.TextureRender;
28 |
29 |
30 | /**
31 | * Holds state associated with a Surface used for MediaCodec decoder output.
32 | *
33 | * The (width,height) constructor for this class will prepare GL, create a SurfaceTexture,
34 | * and then create a Surface for that SurfaceTexture. The Surface can be passed to
35 | * MediaCodec.configure() to receive decoder output. When a frame arrives, we latch the
36 | * texture with updateTexImage, then render the texture with GL to a pbuffer.
37 | *
38 | * The no-arg constructor skips the GL preparation step and doesn't allocate a pbuffer.
39 | * Instead, it just creates the Surface and SurfaceTexture, and when a frame arrives
40 | * we just draw it on whatever surface is current.
41 | *
42 | * By default, the Surface will be using a BufferQueue in asynchronous mode, so we
43 | * can potentially drop frames.
44 | */
45 | public class OutputSurface implements SurfaceTexture.OnFrameAvailableListener {
46 | private static final String TAG = OutputSurface.class.getCanonicalName();
47 | private static final boolean VERBOSE = false;
48 |
49 | private static final int EGL_OPENGL_ES2_BIT = 4;
50 |
51 | private EGL10 mEGL;
52 | private EGLDisplay mEGLDisplay;
53 | private EGLContext mEGLContext;
54 | private EGLSurface mEGLSurface;
55 |
56 | private SurfaceTexture mSurfaceTexture;
57 | private Surface mSurface;
58 |
59 | private Object mFrameSyncObject = new Object(); // guards mFrameAvailable
60 | private boolean mFrameAvailable;
61 |
62 | private TextureRender mTextureRender;
63 |
64 | /**
65 | * Creates an OutputSurface backed by a pbuffer with the specifed dimensions. The new
66 | * EGL context and surface will be made current. Creates a Surface that can be passed
67 | * to MediaCodec.configure().
68 | */
69 | public OutputSurface(int width, int height) {
70 | if (width <= 0 || height <= 0) {
71 | throw new IllegalArgumentException();
72 | }
73 |
74 | eglSetup(width, height);
75 | makeCurrent();
76 |
77 | setup();
78 | }
79 |
80 | /**
81 | * Creates an OutputSurface using the current EGL context. Creates a Surface that can be
82 | * passed to MediaCodec.configure().
83 | */
84 | public OutputSurface() {
85 | setup();
86 | }
87 |
88 | /**
89 | * Creates instances of TextureRender and SurfaceTexture, and a Surface associated
90 | * with the SurfaceTexture.
91 | */
92 | private void setup() {
93 | mTextureRender = new TextureRender();
94 | mTextureRender.surfaceCreated();
95 |
96 | // Even if we don't access the SurfaceTexture after the constructor returns, we
97 | // still need to keep a reference to it. The Surface doesn't retain a reference
98 | // at the Java level, so if we don't either then the object can get GCed, which
99 | // causes the native finalizer to run.
100 | if (VERBOSE) Log.d(TAG, "textureID=" + mTextureRender.getTextureId());
101 | mSurfaceTexture = new SurfaceTexture(mTextureRender.getTextureId());
102 |
103 | // This doesn't work if OutputSurface is created on the thread that CTS started for
104 | // these test cases.
105 | //
106 | // The CTS-created thread has a Looper, and the SurfaceTexture constructor will
107 | // create a Handler that uses it. The "frame available" message is delivered
108 | // there, but since we're not a Looper-based thread we'll never see it. For
109 | // this to do anything useful, OutputSurface must be created on a thread without
110 | // a Looper, so that SurfaceTexture uses the main application Looper instead.
111 | //
112 | // Java language note: passing "this" out of a constructor is generally unwise,
113 | // but we should be able to get away with it here.
114 | mSurfaceTexture.setOnFrameAvailableListener(this);
115 |
116 | mSurface = new Surface(mSurfaceTexture);
117 | }
118 |
119 | /**
120 | * Prepares EGL. We want a GLES 2.0 context and a surface that supports pbuffer.
121 | */
122 | private void eglSetup(int width, int height) {
123 | mEGL = (EGL10)EGLContext.getEGL();
124 | mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
125 | if (!mEGL.eglInitialize(mEGLDisplay, null)) {
126 | throw new RuntimeException("unable to initialize EGL10");
127 | }
128 |
129 | // Configure EGL for pbuffer and OpenGL ES 2.0. We want enough RGB bits
130 | // to be able to tell if the frame is reasonable.
131 | int[] attribList = {
132 | EGL10.EGL_RED_SIZE, 8,
133 | EGL10.EGL_GREEN_SIZE, 8,
134 | EGL10.EGL_BLUE_SIZE, 8,
135 | EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
136 | EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
137 | EGL10.EGL_NONE
138 | };
139 | EGLConfig[] configs = new EGLConfig[1];
140 | int[] numConfigs = new int[1];
141 | if (!mEGL.eglChooseConfig(mEGLDisplay, attribList, configs, 1, numConfigs)) {
142 | throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
143 | }
144 |
145 | // Configure context for OpenGL ES 2.0.
146 | int[] attrib_list = {
147 | EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
148 | EGL10.EGL_NONE
149 | };
150 | mEGLContext = mEGL.eglCreateContext(mEGLDisplay, configs[0], EGL10.EGL_NO_CONTEXT,
151 | attrib_list);
152 | checkEglError("eglCreateContext");
153 | if (mEGLContext == null) {
154 | throw new RuntimeException("null context");
155 | }
156 |
157 | // Create a pbuffer surface. By using this for output, we can use glReadPixels
158 | // to test values in the output.
159 | int[] surfaceAttribs = {
160 | EGL10.EGL_WIDTH, width,
161 | EGL10.EGL_HEIGHT, height,
162 | EGL10.EGL_NONE
163 | };
164 | mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs);
165 | checkEglError("eglCreatePbufferSurface");
166 | if (mEGLSurface == null) {
167 | throw new RuntimeException("surface was null");
168 | }
169 | }
170 |
171 | /**
172 | * Discard all resources held by this class, notably the EGL context.
173 | */
174 | public void release() {
175 | if (mEGL != null) {
176 | if (mEGL.eglGetCurrentContext().equals(mEGLContext)) {
177 | // Clear the current context and surface to ensure they are discarded immediately.
178 | mEGL.eglMakeCurrent(mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
179 | EGL10.EGL_NO_CONTEXT);
180 | }
181 | mEGL.eglDestroySurface(mEGLDisplay, mEGLSurface);
182 | mEGL.eglDestroyContext(mEGLDisplay, mEGLContext);
183 | //mEGL.eglTerminate(mEGLDisplay);
184 | }
185 |
186 | mSurface.release();
187 |
188 | // this causes a bunch of warnings that appear harmless but might confuse someone:
189 | // W BufferQueue: [unnamed-3997-2] cancelBuffer: BufferQueue has been abandoned!
190 | //mSurfaceTexture.release();
191 |
192 | // null everything out so future attempts to use this object will cause an NPE
193 | mEGLDisplay = null;
194 | mEGLContext = null;
195 | mEGLSurface = null;
196 | mEGL = null;
197 |
198 | mTextureRender = null;
199 | mSurface = null;
200 | mSurfaceTexture = null;
201 | }
202 |
203 | /**
204 | * Makes our EGL context and surface current.
205 | */
206 | public void makeCurrent() {
207 | if (mEGL == null) {
208 | throw new RuntimeException("not configured for makeCurrent");
209 | }
210 | checkEglError("before makeCurrent");
211 | if (!mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
212 | throw new RuntimeException("eglMakeCurrent failed");
213 | }
214 | }
215 |
216 | /**
217 | * Returns the Surface that we draw onto.
218 | */
219 | public Surface getSurface() {
220 | return mSurface;
221 | }
222 |
223 | /**
224 | * Replaces the fragment shader.
225 | */
226 | public void changeFragmentShader(String fragmentShader) {
227 | mTextureRender.changeFragmentShader(fragmentShader);
228 | }
229 |
230 | /**
231 | * Latches the next buffer into the texture. Must be called from the thread that created
232 | * the OutputSurface object, after the onFrameAvailable callback has signaled that new
233 | * data is available.
234 | */
235 | public void awaitNewImage() {
236 | final int TIMEOUT_MS = 500;
237 |
238 | synchronized (mFrameSyncObject) {
239 | while (!mFrameAvailable) {
240 | try {
241 | // Wait for onFrameAvailable() to signal us. Use a timeout to avoid
242 | // stalling the test if it doesn't arrive.
243 | mFrameSyncObject.wait(TIMEOUT_MS);
244 | if (!mFrameAvailable) {
245 | // TODO: if "spurious wakeup", continue while loop
246 | throw new RuntimeException("Surface frame wait timed out");
247 | }
248 | } catch (InterruptedException ie) {
249 | // shouldn't happen
250 | throw new RuntimeException(ie);
251 | }
252 | }
253 | mFrameAvailable = false;
254 | }
255 |
256 | // Latch the data.
257 | mTextureRender.checkGlError("before updateTexImage");
258 | mSurfaceTexture.updateTexImage();
259 | }
260 |
261 | /**
262 | * Draws the data from SurfaceTexture onto the current EGL surface.
263 | */
264 | public void drawImage() {
265 | mTextureRender.drawFrame(mSurfaceTexture);
266 | }
267 |
268 | @Override
269 | public void onFrameAvailable(SurfaceTexture st) {
270 | if (VERBOSE) Log.d(TAG, "new frame available");
271 | synchronized (mFrameSyncObject) {
272 | if (mFrameAvailable) {
273 | throw new RuntimeException("mFrameAvailable already set, frame could be dropped");
274 | }
275 | mFrameAvailable = true;
276 | mFrameSyncObject.notifyAll();
277 | }
278 | }
279 |
280 | /**
281 | * Checks for EGL errors.
282 | */
283 | private void checkEglError(String msg) {
284 | boolean failed = false;
285 | int error;
286 | while ((error = mEGL.eglGetError()) != EGL10.EGL_SUCCESS) {
287 | Log.e(TAG, msg + ": EGL error: 0x" + Integer.toHexString(error));
288 | failed = true;
289 | }
290 | if (failed) {
291 | throw new RuntimeException("EGL error encountered (see log)");
292 | }
293 | }
294 | }
295 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/threads/AudioEncoderThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.threads;
17 |
18 | import android.util.Log;
19 | import android.os.Process;
20 | import android.os.HandlerThread;
21 |
22 | public class AudioEncoderThread extends HandlerThread {
23 | private final static String TAG = AudioEncoderThread.class.getCanonicalName();
24 |
25 | public AudioEncoderThread(String name) {
26 | super(name, Process.THREAD_PRIORITY_AUDIO);
27 | }
28 |
29 | @Override
30 | public void run() {
31 | super.run();
32 | Log.d(TAG, "Running AudioEncoderThread");
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/threads/CameraThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.threads;
17 | import android.graphics.SurfaceTexture;
18 | import android.os.HandlerThread;
19 | import android.util.Log;
20 | import com.constantinnovationsinc.livemultimedia.cameras.JellyBeanCamera;
21 | import java.io.IOException;
22 |
23 | public class CameraThread extends HandlerThread {
24 | private static final String TAG = CameraThread.class.getCanonicalName();
25 | private JellyBeanCamera mCamera = null;
26 | private SurfaceTexture mTexture = null;
27 | private static final int NO_CAMERA = 0;
28 | private static final int ONE_CAMERA = 1;
29 | private static final int TWO_CAMERA = 2;
30 | public int mActiveCameraId = -1;
31 |
32 | public CameraThread(String name) {
33 | super(name);
34 | }
35 |
36 | public synchronized void setCamera(JellyBeanCamera camera) {
37 | mCamera = camera;
38 | }
39 |
40 | public synchronized void setCameraTexture(SurfaceTexture texture) {
41 | mTexture = texture;
42 | }
43 |
44 | public synchronized void setActiveCameraId(int cameraId) {
45 | mActiveCameraId = cameraId;
46 | }
47 |
48 | @SuppressWarnings("deprecation")
49 | @Override
50 | protected void onLooperPrepared() {
51 | Log.d(TAG, "onLooperPrepared!");
52 | try {
53 | if (mCamera == null) {
54 | throw new IllegalStateException("Camera object is null, leaving...");
55 | }
56 | int camCount = mCamera.getNumberOfCameras();
57 | Log.d(TAG, "Number of Camera reported: " + camCount);
58 |
59 | if (camCount == NO_CAMERA || camCount < NO_CAMERA) {
60 | Log.e(TAG, "No Cameras found, exiting!");
61 | throw new IllegalStateException("Unable to open camera");
62 | } else if (camCount == ONE_CAMERA && mActiveCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
63 | mCamera.startFrontCamera();
64 | } else if (camCount == ONE_CAMERA && mActiveCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK) {
65 | mCamera.startFrontCamera();
66 | } else if (camCount == TWO_CAMERA && mActiveCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
67 | mCamera.startFrontCamera();
68 | } else if (camCount == TWO_CAMERA && mActiveCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK) {
69 | mCamera.startBackCamera();
70 | } else {
71 | Log.e(TAG, "Serious error, active cam not set!");
72 | Thread.currentThread().interrupt();
73 | return;
74 | }
75 | Log.d(TAG, "Settingup the Preview Window");
76 | mCamera.setupPreviewWindow();
77 | mCamera.setupVideoCaptureMethod();
78 | mCamera.setPreviewTexture(mTexture);
79 | Log.d(TAG, "Starting the camera preview..");
80 | mCamera.startVideoPreview();
81 | } catch (IOException | IllegalArgumentException | IllegalStateException e) {
82 | Log.e(TAG, "--------------------------------------------");
83 | Log.e(TAG, "Error when starting PreviewWindow!!");
84 | Log.e(TAG, e.toString());
85 | Log.e(TAG, "--------------------------------------------");
86 | }
87 | }
88 |
89 | @Override
90 | public void run() {
91 | Log.d(TAG, "CameraThread Running!");
92 | super.run();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/threads/ImageSaverThread.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.threads;
2 |
3 | import android.media.Image;
4 | import android.media.ImageReader;
5 | import java.io.File;
6 | import java.io.FileNotFoundException;
7 | import java.io.FileOutputStream;
8 | import java.io.IOException;
9 | import java.nio.ByteBuffer;
10 |
11 | public class ImageSaverThread implements Runnable {
12 | /**
13 | * The JPEG image
14 | */
15 | private final Image mImage;
16 | /**
17 | * The file we save the image into.
18 | */
19 | private final File mFile;
20 |
21 | public ImageSaverThread(Image image, File file) {
22 | mImage = image;
23 | mFile = file;
24 | }
25 |
26 | @Override
27 | public void run() {
28 | ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
29 | byte[] bytes = new byte[buffer.remaining()];
30 | buffer.get(bytes);
31 | FileOutputStream output = null;
32 | try {
33 | output = new FileOutputStream(mFile);
34 | output.write(bytes);
35 | } catch (FileNotFoundException e) {
36 | e.printStackTrace();
37 | } catch (IOException e) {
38 | e.printStackTrace();
39 | } finally {
40 | mImage.close();
41 | if (null != output) {
42 | try {
43 | output.close();
44 | } catch (IOException e) {
45 | e.printStackTrace();
46 | }
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/threads/VideoEncoderThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.threads;
17 | import android.os.HandlerThread;
18 |
19 | public class VideoEncoderThread extends HandlerThread {
20 |
21 | public VideoEncoderThread(String name) {
22 | super(name);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/utilities/ColorSpaceManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.utilities;
17 |
18 | public class ColorSpaceManager {
19 |
20 | public static byte[] NV21toYUV420Planar(byte[] input, byte[] output, int width, int height) {
21 | final int frameSize = width * height;
22 | final int qFrameSize = frameSize/4;
23 |
24 | System.arraycopy(input, 0, output, 0, frameSize); // Y
25 |
26 | byte v, u;
27 |
28 | for (int i = 0; i < qFrameSize; i++) {
29 | v = input[frameSize + i*2];
30 | u = input[frameSize + i*2 + 1];
31 |
32 | output[frameSize + i + qFrameSize] = v;
33 | output[frameSize + i] = u;
34 | }
35 |
36 | return output;
37 | }
38 |
39 | @SuppressWarnings("unused")
40 | public static byte[] NV21toYUV420SemiPlanar(byte[] input, byte[] output, int width, int height) {
41 | final int frameSize = width * height;
42 | final int qFrameSize = frameSize/4;
43 |
44 | System.arraycopy(input, 0, output, 0, frameSize); // Y
45 |
46 | byte v, u;
47 |
48 | for (int i = 0; i < qFrameSize; i++) {
49 | v = input[frameSize + i*2];
50 | u = input[frameSize + i*2 + 1];
51 |
52 | output[frameSize + i*2] = u;
53 | output[frameSize + i*2 + 1] = v;
54 | }
55 |
56 | return output;
57 | }
58 |
59 | @SuppressWarnings("unused")
60 | public synchronized static byte[] YV12toYUV420PackedSemiPlanar(final byte[] input, final byte[] output, final int width, final int height) {
61 | /*
62 | * COLOR_TI_FormatYUV420PackedSemiPlanar is YV12
63 | * We convert by putting the corresponding U and V bytes together (interleaved).
64 | */
65 | final int frameSize = width * height;
66 | final int qFrameSize = frameSize / 4;
67 | for (int i = 0; i < (qFrameSize); i++) {
68 | output[frameSize + i * 2] = (input[frameSize + qFrameSize + i]);
69 | output[frameSize + i * 2 + 1] = (input[frameSize + i]);
70 | }
71 | return output;
72 | }
73 |
74 | public static void YUV_NV21_TO_RGB(int[] argb, byte[] yuv, int width, int height) {
75 | final int frameSize = width * height;
76 |
77 | final int ii = 0;
78 | final int ij = 0;
79 | final int di = +1;
80 | final int dj = +1;
81 |
82 | int a = 0;
83 | for (int i = 0, ci = ii; i < height; ++i, ci += di) {
84 | for (int j = 0, cj = ij; j < width; ++j, cj += dj) {
85 | int y = (0xff & ((int) yuv[ci * width + cj]));
86 | int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0]));
87 | int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1]));
88 | y = y < 16 ? 16 : y;
89 |
90 | int r = (int) (1.164f * (y - 16) + 1.596f * (v - 128));
91 | int g = (int) (1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128));
92 | int b = (int) (1.164f * (y - 16) + 2.018f * (u - 128));
93 |
94 | r = r < 0 ? 0 : (r > 255 ? 255 : r);
95 | g = g < 0 ? 0 : (g > 255 ? 255 : g);
96 | b = b < 0 ? 0 : (b > 255 ? 255 : b);
97 |
98 | argb[a++] = 0xff000000 | (r << 16) | (g << 8) | b;
99 | }
100 | }
101 | }
102 |
103 | public static byte[] swapYV12toI420(byte[] yv12bytes, int width, int height) {
104 | byte[] i420bytes = new byte[yv12bytes.length];
105 | for (int i = 0; i < width * height; i++)
106 | i420bytes[i] = yv12bytes[i];
107 | for (int i = width * height; i < width * height + (width / 2 * height / 2); i++)
108 | i420bytes[i] = yv12bytes[i + (width / 2 * height / 2)];
109 | for (int i = width * height + (width / 2 * height / 2); i < width * height + 2 * (width / 2 * height / 2); i++)
110 | i420bytes[i] = yv12bytes[i - (width / 2 * height / 2)];
111 | return i420bytes;
112 | }
113 |
114 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/utilities/CompareSizesByArea.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.utilities;
2 |
3 | import android.annotation.TargetApi;
4 | import android.os.Build;
5 | import android.util.Size;
6 |
7 | import java.util.Comparator;
8 | /**
9 | * Compares two {@code Size}s based on their areas.
10 | */
11 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
12 | public class CompareSizesByArea implements Comparator {
13 |
14 | @Override
15 | public int compare(Size lhs, Size rhs) {
16 | // We cast here to ensure the multiplications won't overflow
17 | return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
18 | (long) rhs.getWidth() * rhs.getHeight());
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/utilities/DeviceNetwork.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.utilities;
17 | import android.util.Log;
18 |
19 | import java.net.InetAddress;
20 | import java.io.*;
21 | import java.net.*;
22 | import java.util.*;
23 |
24 | public class DeviceNetwork {
25 | private static final String TAG = DeviceNetwork.class.getCanonicalName();
26 | /**
27 | * Convert byte array to hex string
28 | * @param bytes the byte to convert
29 | * @return HexString
30 | */
31 | public static String bytesToHex(byte[] bytes) {
32 | StringBuilder sbuf = new StringBuilder();
33 | for(int idx: bytes) {
34 | int intVal = bytes[idx] & 0xff;
35 | if (intVal < 0x10) sbuf.append("0");
36 | sbuf.append(Integer.toHexString(intVal).toUpperCase());
37 | }
38 | return sbuf.toString();
39 | }
40 |
41 | /**
42 | * Get utf8 byte array.
43 | * @param str to convert
44 | * @return array of NULL if error was found
45 | */
46 | public static byte[] getUTF8Bytes(String str) {
47 | try { return str.getBytes("UTF-8"); } catch (Exception ex) { return null; }
48 | }
49 |
50 | /**
51 | * Load UTF8withBOM or any ansi text file.
52 | * @param filename as string
53 | * @return String
54 | * @throws java.io.IOException
55 | */
56 | public static String loadFileAsString(String filename) throws java.io.IOException {
57 | final int BUFLEN=1024;
58 | BufferedInputStream is = new BufferedInputStream(new FileInputStream(filename), BUFLEN);
59 | try {
60 | ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFLEN);
61 | byte[] bytes = new byte[BUFLEN];
62 | boolean isUTF8=false;
63 | int read,count=0;
64 | while((read=is.read(bytes)) != -1) {
65 | if (count==0 && bytes[0]==(byte)0xEF && bytes[1]==(byte)0xBB && bytes[2]==(byte)0xBF ) {
66 | isUTF8=true;
67 | baos.write(bytes, 3, read-3); // drop UTF8 bom marker
68 | } else {
69 | baos.write(bytes, 0, read);
70 | }
71 | count+=read;
72 | }
73 | return isUTF8 ? new String(baos.toByteArray(), "UTF-8") : new String(baos.toByteArray());
74 | } finally {
75 | try {
76 | is.close();
77 | } catch(Exception ex){
78 | Log.e(TAG, ex.getMessage());
79 | }
80 | }
81 | }
82 |
83 | /**
84 | * Returns MAC address of the given interface name.
85 | * @param interfaceName eth0, wlan0 or NULL=use first interface
86 | * @return mac address or empty string
87 | */
88 | public static String getMACAddress(String interfaceName) {
89 | try {
90 | List interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
91 | for (NetworkInterface intf : interfaces) {
92 | if (interfaceName != null) {
93 | if (!intf.getName().equalsIgnoreCase(interfaceName)) continue;
94 | }
95 | byte[] mac = intf.getHardwareAddress();
96 | if (mac == null) return "";
97 | StringBuilder buf = new StringBuilder();
98 | for (int idx : mac) {
99 | buf.append(String.format("%02X:", mac[idx]));
100 | }
101 | if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1);
102 | return buf.toString();
103 | }
104 | } catch (SocketException ex) {
105 | Log.e(TAG, ex.getMessage());
106 | }
107 | return "";
108 | }
109 |
110 |
111 | public static String getLocalIpAddress() {
112 | try {
113 | for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
114 | NetworkInterface intf = en.nextElement();
115 | for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
116 | InetAddress inetAddress = enumIpAddr.nextElement();
117 | if (!inetAddress.isLoopbackAddress()) {
118 | return inetAddress.getHostAddress().toString();
119 | }
120 | }
121 | }
122 | } catch (SocketException ex) {
123 | Log.e(TAG, ex.toString());
124 | }
125 | return null;
126 | }
127 |
128 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/utilities/HttpFileUpload.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.utilities;
17 | import java.io.DataOutputStream;
18 | import java.io.FileInputStream;
19 | import java.io.IOException;
20 | import java.net.HttpURLConnection;
21 | import java.net.MalformedURLException;
22 | import java.net.URL;
23 | import android.util.Log;
24 |
25 | public class HttpFileUpload {
26 | URL connectURL;
27 | String responseString;
28 | String Title;
29 | String Description;
30 | byte[ ] dataToServer;
31 | FileInputStream fileInputStream = null;
32 |
33 | public HttpFileUpload(String urlString, String vTitle, String vDesc){
34 | try{
35 | connectURL = new URL(urlString);
36 | Title= vTitle;
37 | Description = vDesc;
38 | }catch(Exception ex){
39 | Log.i("HttpFileUpload","URL Malformatted");
40 | }
41 | }
42 |
43 | public synchronized void Send_Now(FileInputStream fStream){
44 | fileInputStream = fStream;
45 | Sending();
46 | }
47 |
48 | public synchronized void Sending(){
49 | String iFileName = "ovicam_temp_vid.mp4";
50 | String lineEnd = "\r\n";
51 | String twoHyphens = "--";
52 | String boundary = "*****";
53 | String Tag="fSnd";
54 | try
55 | {
56 | Log.e(Tag,"Starting Http File Sending to URL");
57 |
58 | // Open a HTTP connection to the URL
59 | HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
60 |
61 | // Allow Inputs
62 | conn.setDoInput(true);
63 |
64 | // Allow Outputs
65 | conn.setDoOutput(true);
66 |
67 | // Don't use a cached copy.
68 | conn.setUseCaches(false);
69 |
70 | // Use a post method.
71 | conn.setRequestMethod("POST");
72 |
73 | conn.setRequestProperty("Connection", "Keep-Alive");
74 |
75 | conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
76 |
77 | DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
78 |
79 | dos.writeBytes(twoHyphens + boundary + lineEnd);
80 | dos.writeBytes("Content-Disposition: form-data; name=\"title\""+ lineEnd);
81 | dos.writeBytes(lineEnd);
82 | dos.writeBytes(Title);
83 | dos.writeBytes(lineEnd);
84 | dos.writeBytes(twoHyphens + boundary + lineEnd);
85 |
86 | dos.writeBytes("Content-Disposition: form-data; name=\"description\""+ lineEnd);
87 | dos.writeBytes(lineEnd);
88 | dos.writeBytes(Description);
89 | dos.writeBytes(lineEnd);
90 | dos.writeBytes(twoHyphens + boundary + lineEnd);
91 |
92 | dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + iFileName +"\"" + lineEnd);
93 | dos.writeBytes(lineEnd);
94 |
95 | Log.e(Tag,"Headers are written");
96 |
97 | // create a buffer of maximum size
98 | int bytesAvailable = fileInputStream.available();
99 |
100 | int maxBufferSize = 1024;
101 | int bufferSize = Math.min(bytesAvailable, maxBufferSize);
102 | byte[ ] buffer = new byte[bufferSize];
103 |
104 | // read file and write it into form...
105 | int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
106 |
107 | while (bytesRead > 0)
108 | {
109 | dos.write(buffer, 0, bufferSize);
110 | bytesAvailable = fileInputStream.available();
111 | bufferSize = Math.min(bytesAvailable,maxBufferSize);
112 | bytesRead = fileInputStream.read(buffer, 0,bufferSize);
113 | }
114 | dos.writeBytes(lineEnd);
115 | dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
116 |
117 | // close streams
118 | fileInputStream.close();
119 |
120 | dos.flush();
121 |
122 | //Log.e(Tag,"File Sent, Response: "+String.valueOf(conn.getResponseCode()));
123 |
124 | //InputStream is = conn.getInputStream();
125 |
126 | // retrieve the response from server
127 | //int ch;
128 |
129 | //StringBuffer b =new StringBuffer();
130 | //while( ( ch = is.read() ) != -1 ){ b.append( (char)ch ); }
131 | //String s=b.toString();
132 | //Log.i("Response",s);
133 | dos.close();
134 | }
135 | catch (MalformedURLException ex)
136 | {
137 | Log.e(Tag, "URL error: " + ex.getMessage(), ex);
138 | }
139 |
140 | catch (IOException ioe)
141 | {
142 | Log.e(Tag, "IO error: " + ioe.getMessage(), ioe);
143 | }
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/utilities/SharedVideoMemory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.utilities;
17 | import android.os.MemoryFile;
18 | import android.util.Log;
19 | import java.io.IOException;
20 |
21 | public class SharedVideoMemory {
22 | public int sharedVideoFramesBuffer = 0;
23 | public MemoryFile mSharedMemFile = null;
24 | /**
25 | * MemoryFile is a wrapper for the Linux ashmem driver.
26 | * MemoryFiles are backed by shared memory, which can be optionally
27 | * set to be purgeable.
28 | * Purgeable files may have their contents reclaimed by the kernel
29 | * in low memory conditions (only if allowPurging is set to true).
30 | * After a file is purged, attempts to read or write the file will
31 | * cause an IOException to be thrown.
32 | */
33 | private static String TAG = "MemoryFile";
34 | private int mFrameCount = 0;
35 | private int mProcessedFrames = 0;
36 | private int mFrameSize = -1;
37 |
38 | /**
39 | * Allocates a new ashmem region. The region is initially not purgable.
40 | *
41 | * @param name optional name for the file (can be null).
42 | * @param frameSize how many frame to store
43 | * @param length of the memory file in bytes.
44 | * @throws IOException if the memory file could not be created.
45 | */
46 | public SharedVideoMemory(String name, int frameSize, int length) throws IOException {
47 | mSharedMemFile = new MemoryFile(name, length);
48 | mFrameSize = frameSize;
49 | }
50 |
51 | /**
52 | * Closes the memory file. If there are no other open references to the memory
53 | * file, it will be deleted.
54 | */
55 | public void close() {
56 | mSharedMemFile.close();
57 | }
58 |
59 | public boolean isEmpty() {
60 | return (mSharedMemFile.length() == 0);
61 | }
62 |
63 | public int getFrameCount() {
64 | return mFrameCount;
65 | }
66 |
67 | public int getProcessFramesCount() {
68 | return mProcessedFrames;
69 | }
70 |
71 | public int getFrameSize() {
72 | return mFrameSize;
73 | }
74 |
75 | public synchronized void lockMemory() {
76 | try {
77 | if (mSharedMemFile != null) {
78 | mSharedMemFile.allowPurging(false);
79 | }
80 | } catch (IOException e) {
81 | Log.e(TAG, e.getMessage());
82 | }
83 | }
84 |
85 | public synchronized void clearMemory() {
86 | try {
87 | if (mSharedMemFile != null) {
88 | mSharedMemFile.allowPurging(true);
89 | }
90 | } catch (IOException e) {
91 | Log.e(TAG, e.getMessage());
92 | }
93 | }
94 | @SuppressWarnings("unused")
95 | public boolean getNextFrame(int frameNum, byte[] buffer) {
96 | Boolean mFlag = false;
97 | if (buffer == null) {
98 | Log.e(TAG, "Cannot return video frame into a null buffer that was passed to getNextFrame()");
99 | return false;
100 | }
101 | if (frameNum == mFrameCount) {
102 | Log.e(TAG, "You have now read to the end of sharedMemory file");
103 | return false;
104 | }
105 | try {
106 | Log.d(TAG, "About to read from shared file for frame:framesize is: " + frameNum + "," + mFrameSize);
107 | int readBytes = mSharedMemFile.readBytes(buffer, frameNum * mFrameSize, 0, mFrameSize);
108 | if (readBytes == mFrameSize) {
109 | mFlag = true;
110 | mProcessedFrames++;
111 | } else {
112 | Log.e(TAG, "bytes read are mot the same as frame size!");
113 | }
114 | } catch (IndexOutOfBoundsException | IOException e) {
115 | Log.e(TAG, e.getMessage());
116 | mFlag = false;
117 | }
118 | return mFlag;
119 | }
120 |
121 | /**
122 | * Write bytes to the memory file.
123 | * Will throw an IOException if the file has been purged.
124 | *
125 | * @param buffer byte array to write bytes from.
126 | * @param srcOffset offset into the byte array buffer to write from.
127 | * @param destOffset offset into the memory file to write to.
128 | * @param count number of bytes to write.
129 | * @throws IOException if the memory file has been purged or deactivated.
130 | */
131 | public void writeBytes(byte[] buffer, int srcOffset, int destOffset, int count) {
132 | try {
133 | mSharedMemFile.writeBytes(buffer, srcOffset, destOffset, count);
134 | mFrameCount++;
135 | } catch (IOException e) {
136 | Log.e(TAG, e.getMessage());
137 | }
138 | }
139 |
140 | public Boolean isLastFrame() {
141 | return (mFrameCount == mProcessedFrames);
142 | }
143 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/views/AutoFitTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Constant Innovations Inc
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 | package com.constantinnovationsinc.livemultimedia.views;
17 |
18 | import android.content.Context;
19 | import android.util.AttributeSet;
20 | import android.view.TextureView;
21 | //import com.constantinnovationsinc.livemultimedia.previews.VideoPreview;
22 |
23 | public class AutoFitTextureView extends TextureView {
24 |
25 | private int mRatioWidth = 0;
26 | private int mRatioHeight = 0;
27 |
28 | public AutoFitTextureView(Context context) {
29 | this(context, null);
30 | }
31 |
32 | public AutoFitTextureView(Context context, AttributeSet attrs) {
33 | this(context, attrs, 0);
34 | }
35 |
36 | public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) {
37 | super(context, attrs, defStyle);
38 | }
39 |
40 | /**
41 | * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
42 | * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
43 | * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
44 | *
45 | * @param width Relative horizontal size
46 | * @param height Relative vertical size
47 | */
48 | public void setAspectRatio(int width, int height) {
49 | if (width < 0 || height < 0) {
50 | throw new IllegalArgumentException("Size cannot be negative.");
51 | }
52 | mRatioWidth = width;
53 | mRatioHeight = height;
54 | requestLayout();
55 | }
56 |
57 | @Override
58 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
59 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
60 | int width = MeasureSpec.getSize(widthMeasureSpec);
61 | int height = MeasureSpec.getSize(heightMeasureSpec);
62 | if (0 == mRatioWidth || 0 == mRatioHeight) {
63 | setMeasuredDimension(width, height);
64 | } else {
65 | if (width < height * mRatioWidth / mRatioHeight) {
66 | setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
67 | } else {
68 | setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
69 | }
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/constantinnovationsinc/livemultimedia/views/CameraView.java:
--------------------------------------------------------------------------------
1 | package com.constantinnovationsinc.livemultimedia.views;
2 | import android.content.Context;
3 | import android.graphics.SurfaceTexture;
4 | import android.os.Build;
5 | import android.os.Handler;
6 | import android.os.HandlerThread;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.util.AttributeSet;
9 | import android.util.Log;
10 | import android.view.TextureView;
11 | import com.constantinnovationsinc.livemultimedia.callbacks.FramesReadyCallback;
12 | import com.constantinnovationsinc.livemultimedia.cameras.AndroidCamera;
13 | import com.constantinnovationsinc.livemultimedia.recorders.AVRecorder;
14 |
15 |
16 | public class CameraView extends TextureView implements FramesReadyCallback{
17 | private static final String TAG = CameraView.class.getCanonicalName();
18 | private static final String START_CAPTURE_FRAMES_SOUND = "StartCaptureSound";
19 | private static final String START_ENCODERS_SOUND = "StartEncodersSound";
20 | private AVRecorder mAVRecorder = null;
21 | private Context mContext = null;
22 | private FragmentActivity mActivity = null;
23 | private AndroidCamera mCamera = null;
24 | private int mRatioWidth = -1;
25 | private int mRatioHeight = -1;
26 | public int mRotation = -1;
27 | private HandlerThread mBackgroundThread;
28 | private Handler mBackgroundHandler;
29 | private TextureView.SurfaceTextureListener mSurfaceTextureListener = null;
30 |
31 | public CameraView(Context context) {
32 | super(context);
33 | mContext = context;
34 | mActivity = (FragmentActivity)mContext;
35 | }
36 |
37 | public CameraView(Context context, AttributeSet attrs) {
38 | this(context, attrs, 0);
39 | mContext = context;
40 | mActivity = (FragmentActivity)mContext;
41 | }
42 |
43 | public CameraView(Context context, AttributeSet attrs, int defStyle) {
44 | super(context, attrs, defStyle);
45 | mContext = context;
46 | mActivity = (FragmentActivity)mContext;
47 | }
48 |
49 | public void prepare() {
50 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
51 | mCamera = new AndroidCamera(mContext, AndroidCamera.VIDEO, this);
52 | setupSurfaceTexureListener();
53 | setupVideoCapture();
54 | }
55 | }
56 |
57 | public void startBackgroundThread() {
58 | mBackgroundThread = new HandlerThread("CameraBackground");
59 | mBackgroundThread.start();
60 | mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
61 | }
62 |
63 | public void stopBackgroundThread() {
64 | mBackgroundThread.quitSafely();
65 | try {
66 | mBackgroundThread.join();
67 | mBackgroundThread = null;
68 | mBackgroundHandler = null;
69 | } catch (InterruptedException e) {
70 | e.printStackTrace();
71 | }
72 | }
73 |
74 | public void openCamera(int width, int height ) {
75 | mCamera.openCamera(width,height);
76 | }
77 |
78 | public void halt() {
79 | Log.d(TAG, "Camera released and SurfaceTextureListener is not null!");
80 | setSurfaceTextureListener(null);
81 | if (mCamera != null) {
82 | mCamera.stopCamera();
83 | mCamera = null;
84 | }
85 | }
86 |
87 | public int getVideoWidth() {
88 | return 1920;
89 | }
90 |
91 | public int getVideoHeight() {
92 | return 1080;
93 | }
94 |
95 |
96 |
97 | /**
98 | * **********************************************************************************************
99 | * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
100 | * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
101 | * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
102 | *
103 | * @param width Relative horizontal size
104 | * @param height Relative vertical size
105 | ***********************************************************************************************/
106 | public void setAspectRatio(int width, int height) {
107 | if (width < 0 || height < 0) {
108 | throw new IllegalArgumentException("Size cannot be negative.");
109 | }
110 | mRatioWidth = width;
111 | mRatioHeight = height;
112 | requestLayout();
113 | }
114 |
115 |
116 |
117 | @Override
118 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
119 | Log.d(TAG, "VideoPreview Window being measured!");
120 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
121 | int width = MeasureSpec.getSize(widthMeasureSpec);
122 | int height = MeasureSpec.getSize(heightMeasureSpec);
123 | if (0 == mRatioWidth || 0 == mRatioHeight) {
124 | setMeasuredDimension(width, height);
125 | } else {
126 | if (width < (height * (mRatioWidth / mRatioHeight))) {
127 | setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
128 | } else {
129 | setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
130 | }
131 | }
132 | }
133 |
134 | public void setupVideoCapture() {
135 | mCamera.setupVideoCapture();
136 | }
137 |
138 | public void setupSurfaceTexureListener() {
139 | if (mSurfaceTextureListener != null)
140 | return;
141 | mSurfaceTextureListener = new TextureView.SurfaceTextureListener() {
142 | @Override
143 | public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture,
144 | int width, int height) {
145 | Log.d(TAG, "onSurfaceTextureAvailable() about to open the camera with width,height "
146 | + String.valueOf(width) + "," + String.valueOf(height));
147 | mCamera.openCamera(width, height);
148 | }
149 |
150 | @Override
151 | public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture,
152 | int width, int height) {
153 | Log.d(TAG, "onSurfaceTextureSizeChanged() width width,height "
154 | + String.valueOf(width) + "," + String.valueOf(height));
155 | mCamera.configureTransform(width, height);
156 | }
157 |
158 | @Override
159 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
160 | Log.d(TAG, "onSurfaceTextureDestroyed() ");
161 | return true;
162 | }
163 |
164 | @Override
165 | public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
166 | Log.d(TAG, "onSurfaceTextureUpdated() ");
167 | }
168 |
169 | };
170 | }
171 |
172 | @Override
173 | public void recordAudio() {
174 |
175 | }
176 |
177 | @Override
178 | public void startVideoEncoder() {
179 |
180 | }
181 |
182 | @Override
183 | public void playLazerSound() {
184 |
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-hdpi/ic_action_info.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/tile.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-hdpi/tile.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-mdpi/ic_action_info.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-xhdpi/ic_action_info.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-xxhdpi/ic_action_info.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/fragment_camera2_video.xml:
--------------------------------------------------------------------------------
1 |
16 |
19 |
26 |
34 |
35 |
43 |
44 |
52 |
57 |
65 |
70 |
78 |
83 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-xlarge/fragment_camera2_video.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
13 |
20 |
26 |
27 |
33 |
34 |
40 |
41 |
49 |
50 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_camera_detail.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_hwbroadcasting.xml:
--------------------------------------------------------------------------------
1 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_live_multimedia.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_camera2_video.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
16 |
17 |
18 |
25 |
26 |
27 |
33 |
34 |
40 |
41 |
47 |
48 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_camera_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_live_multimedia.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/camera_detail.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/hwbroadcasting.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/live_multimedia.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/mp4written.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/raw/mp4written.ogg
--------------------------------------------------------------------------------
/app/src/main/res/raw/powerup.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tonyconstantinides/LiveMultimedia/47a40291616b8318611e170fbca6340de9846d54/app/src/main/res/raw/powerup.ogg
--------------------------------------------------------------------------------
/app/src/main/res/values-sw600dp/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | @dimen/margin_huge
22 | @dimen/margin_medium
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values-sw600dp/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/base-strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 | LiveMultimedia
22 |
23 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello world!
5 | Settings
6 | LiveMultimedia
7 | Front Camstring>
8 | Back Camstring>
9 | Record
10 | Stop
11 | Exit
12 | Info
13 | CameraDetailActivity
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | 4dp
22 | 8dp
23 | 16dp
24 | 32dp
25 | 64dp
26 |
27 |
28 |
29 | @dimen/margin_medium
30 | @dimen/margin_medium
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
29 |
30 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0-alpha1'
9 | }
10 | }
11 |
12 |
13 | allprojects {
14 | repositories {
15 | jcenter()
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------