Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
0645ed1eb6 | |||
3b94303096 | |||
e6d5d3e2e5 | |||
5cc769ad2e | |||
f843700235 | |||
21a97c0307 | |||
9bcd7107b0 | |||
aff602d0fc | |||
5c2cff3c54 | |||
1b88c67ec1 | |||
e7b42528b3 | |||
a7d0cabba3 | |||
9c2b67395e | |||
ebbacf4feb | |||
3696a9cfd4 | |||
10d0f36013 | |||
5340d3b383 | |||
770f6b2476 | |||
5910c711d8 |
@@ -1,4 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ve.ucv.ciens.ccg.nxtcam"
|
||||
android:versionCode="1"
|
||||
@@ -8,16 +24,15 @@
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="19" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.wifi" android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
@@ -27,8 +42,8 @@
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
|
||||
android:screenOrientation="landscape" >
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
|
||||
<activity
|
||||
android:name="ve.ucv.ciens.ccg.nxtcam.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
@@ -48,4 +63,4 @@
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
202
LICENSE.txt
Normal file
202
LICENSE.txt
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
@@ -10,4 +26,11 @@
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".CamActivity" >
|
||||
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/previewLayout"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.47" >
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
|
@@ -1,4 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">NxtCAM</string>
|
||||
@@ -10,7 +26,7 @@
|
||||
<string name="start_button">Comenzar streaming de video</string>
|
||||
<string name="title_activity_cam">CamActivity</string>
|
||||
<string name="ipAddressLabel">Dirección IP de NxtAR</string>
|
||||
<string name="badIpToast">La dirección IP no es válida</string>
|
||||
<string name="badIpToast">No se encontró un servidor válido</string>
|
||||
<string name="emptyIpToast">Rellene el campo de dirección IP</string>
|
||||
<string name="wifi_on_title">Esta app requiere WiFi</string>
|
||||
<string name="wifi_on_msg">¿Encender el WiFi?</string>
|
||||
@@ -18,7 +34,7 @@
|
||||
<string name="wifi_on_button">Encender</string>
|
||||
<string name="wifi_on_success">El radio del WiFi está encendido</string>
|
||||
<string name="wifi_on_fail">Esta app no puede funcionar sin wifi, cerrando.</string>
|
||||
<string name= "bt_no_support">Este dispositivo no soporta Bluetooth</string>
|
||||
<string name="bt_no_support">Este dispositivo no soporta Bluetooth</string>
|
||||
<string name="bt_on_fail">Esta app no puede funcionar sin Bluetooth, cerrando</string>
|
||||
<string name="lens_icon">Ícono de lente</string>
|
||||
<string name="robot_pair_button">Conectar con el robot</string>
|
||||
@@ -29,5 +45,6 @@
|
||||
<string name="serv_wait">Por favor espere, buscando dispositivo de control</string>
|
||||
<string name="serv_connected">Conectado con el dispositivo de control</string>
|
||||
<string name="serv_fail">Falló la conexión con el dispositivo de control</string>
|
||||
<string name="cam_fail">La cámara es null!</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
|
@@ -1,4 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">NxtCAM</string>
|
||||
@@ -10,7 +26,7 @@
|
||||
<string name="get_server_button">Connect with NxtAR</string>
|
||||
<string name="start_button">Start video streaming</string>
|
||||
<string name="ipAddressLabel">NxtAR IP Address</string>
|
||||
<string name="badIpToast">Invalid IP address</string>
|
||||
<string name="badIpToast">No proper server found</string>
|
||||
<string name="emptyIpToast">Fill out the IP address field</string>
|
||||
<string name="wifi_on_title">This app requires WiFi</string>
|
||||
<string name="wifi_on_msg">Turn on the WiFi?</string>
|
||||
@@ -29,5 +45,6 @@
|
||||
<string name="serv_wait">Please wait, looking for control device</string>
|
||||
<string name="serv_connected">Connected with the control device</string>
|
||||
<string name="serv_fail">Could no connect with the control device</string>
|
||||
<string name="cam_fail">Camera is null!</string>
|
||||
|
||||
</resources>
|
@@ -1,3 +1,19 @@
|
||||
<!--
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
33
src/ve/ucv/ciens/ccg/networkdata/VideoFrameDataMessage.java
Normal file
33
src/ve/ucv/ciens/ccg/networkdata/VideoFrameDataMessage.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.networkdata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class VideoFrameDataMessage implements Serializable{
|
||||
private static final long serialVersionUID = 9989L;
|
||||
public static final int magicNumber = 0x10;
|
||||
|
||||
public int imageWidth;
|
||||
public int imageHeight;
|
||||
public byte[] data;
|
||||
|
||||
public VideoFrameDataMessage(){
|
||||
imageWidth = -1;
|
||||
imageHeight = -1;
|
||||
data = null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.networkdata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class VideoStreamingControlMessage implements Serializable{
|
||||
private static final long serialVersionUID = 8898L;
|
||||
public static final int magicNumber = 0x20;
|
||||
|
||||
public byte message;
|
||||
|
||||
public VideoStreamingControlMessage(){
|
||||
message = -1;
|
||||
}
|
||||
}
|
@@ -1,8 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtcam.camera.CameraPreview;
|
||||
import ve.ucv.ciens.ccg.nxtcam.network.ImageTransferThread;
|
||||
import ve.ucv.ciens.ccg.nxtcam.network.VideoStreamingThread;
|
||||
import ve.ucv.ciens.ccg.nxtcam.network.LCPThread;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.hardware.Camera;
|
||||
@@ -12,16 +29,18 @@ import android.support.v4.app.NavUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class CamActivity extends Activity{
|
||||
private final String TAG = "NXTCAM_CAM";
|
||||
private final String CLASS_NAME = MainActivity.class.getSimpleName();
|
||||
|
||||
private final String CLASS_NAME = CamActivity.class.getSimpleName();
|
||||
|
||||
private Camera hwCamera;
|
||||
private CameraPreview cPreview;
|
||||
private CameraSetupTask camSetupTask;
|
||||
private ImageTransferThread imThread;
|
||||
private VideoStreamingThread imThread;
|
||||
private LCPThread botThread;
|
||||
private String serverIp;
|
||||
|
||||
/*******************
|
||||
@@ -31,12 +50,12 @@ public class CamActivity extends Activity{
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
cPreview = new CameraPreview(this, hwCamera);
|
||||
setContentView(cPreview);
|
||||
|
||||
setContentView(R.layout.activity_cam);
|
||||
|
||||
Intent intent = getIntent();
|
||||
serverIp = intent.getStringExtra("address");
|
||||
imThread = new VideoStreamingThread(serverIp);
|
||||
imThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,20 +88,35 @@ public class CamActivity extends Activity{
|
||||
|
||||
camSetupTask = new CameraSetupTask();
|
||||
camSetupTask.execute();
|
||||
|
||||
imThread = new ImageTransferThread(serverIp);
|
||||
imThread.start();
|
||||
|
||||
// imThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(){
|
||||
super.onPause();
|
||||
|
||||
// TODO: Disconnect and destroy the imThread object.
|
||||
|
||||
cPreview.removePreviewCallback();
|
||||
cPreview.setCamera(null);
|
||||
releaseCamera();
|
||||
// TODO: pause the imThread and botThread objects.
|
||||
|
||||
if(cPreview != null){
|
||||
cPreview.removePreviewCallback();
|
||||
cPreview.setCamera(null);
|
||||
releaseCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
// TODO: Destroy the network threads.
|
||||
imThread = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed(){
|
||||
Intent result = new Intent();
|
||||
setResult(Activity.RESULT_OK, result);
|
||||
finish();
|
||||
}
|
||||
|
||||
/******************
|
||||
@@ -90,10 +124,16 @@ public class CamActivity extends Activity{
|
||||
******************/
|
||||
public void startCameraPreview(){
|
||||
if(hwCamera != null){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".startCameraPreview() :: Setting camera.");
|
||||
cPreview = new CameraPreview(this, hwCamera);
|
||||
cPreview.setCamera(hwCamera);
|
||||
((FrameLayout)findViewById(R.id.previewLayout)).addView(cPreview);
|
||||
Logger.log_d(TAG, CLASS_NAME + ".startCameraPreview() :: Camera and content view set.");
|
||||
}else{
|
||||
Logger.log_wtf(TAG, CLASS_NAME + ".startCameraPreview() :: CAMERA IS NULL!");
|
||||
System.exit(1);
|
||||
Intent result = new Intent();
|
||||
setResult(ProjectConstants.RESULT_CAMERA_FAILURE, result);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +150,7 @@ public class CamActivity extends Activity{
|
||||
@Override
|
||||
protected Camera doInBackground(Void... params) {
|
||||
Camera cam = null;
|
||||
Logger.log_d(TAG, CLASS_NAME + ".doInBackground() :: Opening the camera.");
|
||||
try{
|
||||
cam = Camera.open(0);
|
||||
}catch(Exception e){
|
||||
@@ -121,7 +162,7 @@ public class CamActivity extends Activity{
|
||||
@Override
|
||||
protected void onPostExecute(Camera result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
|
||||
hwCamera = result;
|
||||
if(result != null){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".onPostExecute() :: Camera successfully opened");
|
||||
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -45,6 +60,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
private final String TAG = "NXTCAM_MAIN";
|
||||
private final String CLASS_NAME = MainActivity.class.getSimpleName();
|
||||
private static final int REQUEST_ENABLE_BT = 1;
|
||||
private static final int REQUEST_CAM_ACTIVITY = 2;
|
||||
|
||||
// Gui components
|
||||
private Button startButton;
|
||||
@@ -58,6 +74,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
// Variables.
|
||||
private boolean wifiOnByMe;
|
||||
private boolean btOnByMe;
|
||||
private boolean changingActivity;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -67,6 +84,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
// Set up fields.
|
||||
wifiOnByMe = false;
|
||||
btOnByMe = false;
|
||||
changingActivity = false;
|
||||
|
||||
// Set up gui components.
|
||||
startButton = (Button)findViewById(R.id.startButton);
|
||||
@@ -100,11 +118,12 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
public void onPause(){
|
||||
super.onPause();
|
||||
|
||||
if(btManager.isBTEnabled() && btOnByMe)
|
||||
btManager.disableBT();
|
||||
|
||||
if(wifiManager.isWifiEnabled() && wifiOnByMe)
|
||||
setWifi(false);
|
||||
if(!changingActivity){
|
||||
if(btManager.isBTEnabled() && btOnByMe)
|
||||
btManager.disableBT();
|
||||
if(wifiManager.isWifiEnabled() && wifiOnByMe)
|
||||
setWifi(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,11 +146,18 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
}
|
||||
|
||||
protected void onActivityResult(int request, int result, Intent data){
|
||||
if(request == REQUEST_ENABLE_BT && result == RESULT_OK){
|
||||
if(!wifiManager.isWifiEnabled())
|
||||
enableWifi();
|
||||
}else{
|
||||
Toast.makeText(this, R.string.bt_on_fail, Toast.LENGTH_LONG).show();
|
||||
if(request == REQUEST_ENABLE_BT){
|
||||
if(result == RESULT_OK){
|
||||
if(!wifiManager.isWifiEnabled())
|
||||
enableWifi();
|
||||
}else{
|
||||
Toast.makeText(this, R.string.bt_on_fail, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}else if(request == REQUEST_CAM_ACTIVITY){
|
||||
changingActivity = false;
|
||||
if(result == ProjectConstants.RESULT_CAMERA_FAILURE){
|
||||
Toast.makeText(this, R.string.cam_fail, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,8 +171,9 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
if(serverFound){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Launching camera activity.");
|
||||
Intent intent = new Intent(this, CamActivity.class);
|
||||
changingActivity = true;
|
||||
intent.putExtra("address", ipAddress);
|
||||
startActivity(intent);
|
||||
startActivityForResult(intent, REQUEST_CAM_ACTIVITY);
|
||||
}else{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Cannot launch camera activity.");
|
||||
Toast.makeText(this, R.string.badIpToast, Toast.LENGTH_SHORT).show();
|
||||
@@ -315,7 +342,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params){
|
||||
boolean result, done = false;
|
||||
byte[] buffer = (new String("NxtAR server here!")).getBytes();
|
||||
byte[] buffer = ProjectConstants.SERVICE_DISCOVERY_MESSAGE.getBytes();
|
||||
|
||||
// Create a buffer and tell Android we want to receive multicast datagrams.
|
||||
packet = new DatagramPacket(buffer, buffer.length);
|
||||
@@ -332,13 +359,8 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Found a server at " + packet.getAddress().getHostAddress());
|
||||
String received = new String(packet.getData());
|
||||
Logger.log_d(TAG, CLASS_NAME + ".doInBackground() :: Packet payload is\n" + received);
|
||||
if(received.compareTo("NxtAR server here!") == 0)
|
||||
if(received.compareTo(ProjectConstants.SERVICE_DISCOVERY_MESSAGE) == 0)
|
||||
done = true;
|
||||
Socket client1, client2;
|
||||
client1 = new Socket(packet.getAddress(), ProjectConstants.SERVER_TCP_PORT_1);
|
||||
client1.close();
|
||||
client2 = new Socket(packet.getAddress(), ProjectConstants.SERVER_TCP_PORT_2);
|
||||
client2.close();
|
||||
}
|
||||
result = true;
|
||||
}catch(IOException io){
|
||||
@@ -367,10 +389,10 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
||||
|
||||
if(packet != null){
|
||||
showToast(R.string.serv_connected, Toast.LENGTH_SHORT);
|
||||
// startCamActivity(result, packet.getAddress().getHostAddress());
|
||||
startCamActivity(result, packet.getAddress().getHostAddress());
|
||||
}else{
|
||||
showToast(R.string.serv_fail, Toast.LENGTH_SHORT);
|
||||
// startCamActivity(false, null);
|
||||
startCamActivity(false, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.camera;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class CameraImageMonitor{
|
||||
private final String TAG = "CAM_MONITOR";
|
||||
private final String CLASS_NAME = CameraImageMonitor.class.getSimpleName();
|
||||
|
||||
private Object imageMonitor;
|
||||
private byte[] image;
|
||||
private boolean imgChanged;
|
||||
private boolean imageProduced;
|
||||
private boolean imageConsumed;
|
||||
private Rect imageSize;
|
||||
|
||||
private CameraImageMonitor(){
|
||||
imgChanged = false;
|
||||
imageProduced = false;
|
||||
imageConsumed = true;
|
||||
imageMonitor = new Object();
|
||||
imageSize = null;
|
||||
}
|
||||
|
||||
private static class SingletonHolder{
|
||||
@@ -21,34 +43,48 @@ public class CameraImageMonitor{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void setImageParameters(int width, int height){
|
||||
imageSize = new Rect(0, 0, width, height);
|
||||
}
|
||||
|
||||
public Rect getImageParameters(){
|
||||
return imageSize;
|
||||
}
|
||||
|
||||
public void setImageData(byte[] image){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Copying new image.");
|
||||
synchronized(image){
|
||||
this.image = new byte[image.length];
|
||||
System.arraycopy(image, 0, this.image, 0, image.length);
|
||||
imgChanged = true;
|
||||
image.notifyAll();
|
||||
if(imageConsumed){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Copying new image.");
|
||||
synchronized(this.imageMonitor){
|
||||
this.image = image;
|
||||
imageProduced = true;
|
||||
imageConsumed = false;
|
||||
this.imageMonitor.notifyAll();
|
||||
}
|
||||
System.gc();
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Data copy finished.");
|
||||
}else{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Old image still valid, ignoring new image.");
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Data copy finished.");
|
||||
}
|
||||
|
||||
public byte[] getImageData(){
|
||||
byte[] returnImg;
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: Entry point.");
|
||||
synchronized(image){
|
||||
while(!imgChanged){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: Waiting for new data.");
|
||||
try{ image.wait(); }catch(InterruptedException ie){}
|
||||
synchronized(imageMonitor){
|
||||
while(!imageProduced){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: Waiting for new image.");
|
||||
try{ imageMonitor.wait(); }catch(InterruptedException ie){ }
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: Retrieving new data.");
|
||||
returnImg = image.clone();
|
||||
imgChanged = false;
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: Retrieving new image.");
|
||||
returnImg = image;
|
||||
imageProduced = false;
|
||||
imageConsumed = true;
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: New data retreived.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getImageData() :: New image retrieved.");
|
||||
return returnImg;
|
||||
}
|
||||
|
||||
public synchronized boolean hasChanged(){
|
||||
return imgChanged;
|
||||
return imageConsumed;
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NOTE:
|
||||
* The getOptimalPreviewSize() function is copied and slightly modified from
|
||||
* the Android Open Source Project ApiDemos camera preview code available at
|
||||
* the following url http://goo.gl/thP1e4 from http://android.googlesource.com .
|
||||
* The ApiDemos code is Copyright (C) 2007 The Android Open Source Project also
|
||||
* avilable under the Apache License Version 2.0.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.camera;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,85 +35,97 @@ import android.os.Build;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/** A basic Camera preview class */
|
||||
@SuppressLint("ViewConstructor")
|
||||
public class CameraPreview extends ViewGroup implements SurfaceHolder.Callback, Camera.PreviewCallback {
|
||||
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Camera.PreviewCallback {
|
||||
private final String TAG = "SURFVIEW";
|
||||
private final String CLASS_NAME = CameraPreview.class.getSimpleName();
|
||||
|
||||
private Size mPreviewSize;
|
||||
private List<Size> mSupportedPreviewSizes;
|
||||
private CameraImageMonitor camMonitor;
|
||||
private CameraImageMonitor imgMonitor;
|
||||
private Activity parentActivity;
|
||||
private SurfaceView mSurfaceView;
|
||||
private SurfaceHolder mHolder;
|
||||
private Camera mCamera;
|
||||
private SurfaceHolder holder;
|
||||
private Camera camera;
|
||||
private int previewWidth;
|
||||
private int previewHeight;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public CameraPreview(Context context, Camera camera){
|
||||
super(context);
|
||||
parentActivity = (Activity)context;
|
||||
|
||||
mSurfaceView = new SurfaceView(context);
|
||||
mHolder = mSurfaceView.getHolder();
|
||||
mHolder.addCallback(this);
|
||||
// surfaceView = new SurfaceView(context);
|
||||
holder = getHolder();
|
||||
holder.addCallback(this);
|
||||
|
||||
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB)
|
||||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
}
|
||||
|
||||
public void setCamera(Camera camera){
|
||||
mCamera = camera;
|
||||
if(mCamera != null){
|
||||
camMonitor = CameraImageMonitor.getInstance();
|
||||
mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
|
||||
this.camera = camera;
|
||||
if(this.camera != null){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setCamera() :: Setting camera.");
|
||||
imgMonitor = CameraImageMonitor.getInstance();
|
||||
requestLayout();
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setCamera() :: Camera set.");
|
||||
}
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder){
|
||||
// The Surface has been created, now tell the camera where to draw the preview.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceCreated() :: Creating surface view.");
|
||||
try {
|
||||
if(mCamera != null){
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
}
|
||||
if(camera != null)
|
||||
camera.setPreviewDisplay(holder);
|
||||
} catch (IOException e) {
|
||||
Logger.log_d(TAG, "Error setting camera preview: " + e.getMessage());
|
||||
Logger.log_e(TAG, CLASS_NAME + ".surfaceCreated() :: Error creating camera: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder){
|
||||
if(mCamera != null){
|
||||
mCamera.stopPreview();
|
||||
}
|
||||
if(camera != null)
|
||||
camera.stopPreview();
|
||||
}
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h){
|
||||
if(mHolder.getSurface() == null){
|
||||
public void surfaceChanged(SurfaceHolder tmpHolder, int format, int w, int h){
|
||||
int result;
|
||||
int rotation;
|
||||
int degrees = 0;
|
||||
Camera.Parameters camParams;
|
||||
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Method started.");
|
||||
if(this.holder.getSurface() == null || camera == null){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Holder and/or camera are null.");
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
mCamera.stopPreview();
|
||||
}catch (Exception e){ }
|
||||
try{ camera.stopPreview(); }catch (Exception e){ }
|
||||
|
||||
requestLayout();
|
||||
|
||||
Camera.Parameters camParams = mCamera.getParameters();
|
||||
/*Size optimal = getOptimalPreviewSize(camParams.getSupportedPreviewSizes(), w, h);
|
||||
if(ProjectConstants.DEBUG)
|
||||
Log.d(TAG, CLASS_NAME + ".surfaceChanged() :: Preview size set at (" + optimal.width + ", " + optimal.height + ")");*/
|
||||
camParams.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
||||
mCamera.setParameters(camParams);
|
||||
camParams = camera.getParameters();
|
||||
camParams.getSupportedPreviewSizes();
|
||||
List<Size> sizes = camParams.getSupportedPreviewSizes();
|
||||
|
||||
/*for(Size size: sizes){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Supported preview size (" + size.width + ", " + size.height + ")");
|
||||
}
|
||||
|
||||
Size optimal = getOptimalPreviewSize(sizes, w, h);
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Preview size set at (" + optimal.width + ", " + optimal.height + ")");
|
||||
camParams.setPreviewSize(optimal.width, optimal.height);*/
|
||||
camParams.setPreviewSize(720, 480);
|
||||
camera.setParameters(camParams);
|
||||
/*previewWidth = optimal.width;
|
||||
previewHeight = optimal.height;*/
|
||||
previewWidth = 720;
|
||||
previewHeight = 480;
|
||||
|
||||
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
||||
android.hardware.Camera.getCameraInfo(0, info);
|
||||
int rotation = parentActivity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
rotation = parentActivity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
|
||||
int degrees = 0;
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0: degrees = 0; break;
|
||||
case Surface.ROTATION_90: degrees = 90; break;
|
||||
@@ -99,41 +133,42 @@ public class CameraPreview extends ViewGroup implements SurfaceHolder.Callback,
|
||||
case Surface.ROTATION_270: degrees = 270; break;
|
||||
}
|
||||
|
||||
int result;
|
||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||
result = (info.orientation + degrees) % 360;
|
||||
result = (360 - result) % 360; // compensate the mirror
|
||||
} else { // back-facing
|
||||
result = (info.orientation - degrees + 360) % 360;
|
||||
}
|
||||
mCamera.setDisplayOrientation(result);
|
||||
|
||||
mCamera.setPreviewCallback(this);
|
||||
camera.setDisplayOrientation(result);
|
||||
camera.setPreviewCallback(this);
|
||||
|
||||
try {
|
||||
mCamera.setPreviewDisplay(mHolder);
|
||||
mCamera.startPreview();
|
||||
|
||||
camera.setPreviewDisplay(this.holder);
|
||||
camera.startPreview();
|
||||
}catch (Exception e){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Error starting camera preview: " + e.getMessage());
|
||||
Logger.log_e(TAG, CLASS_NAME + ".surfaceChanged() :: Error starting camera preview: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewFrame(byte[] data, Camera camera){
|
||||
if(imgMonitor.hasChanged())
|
||||
imgMonitor.setImageParameters(previewWidth, previewHeight);
|
||||
Logger.log_d(TAG, CLASS_NAME + ".onPreviewFrame() :: Preview received");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".onPreviewFrame() :: Frame has" + (camMonitor.hasChanged() ? "" : " not") + " changed.");
|
||||
if(!camMonitor.hasChanged())
|
||||
camMonitor.setImageData(data);
|
||||
Logger.log_d(TAG, CLASS_NAME + ".onPreviewFrame() :: Frame has" + (imgMonitor.hasChanged() ? "" : " not") + " been consumed.");
|
||||
imgMonitor.setImageData(data);
|
||||
}
|
||||
|
||||
public void removePreviewCallback(){
|
||||
mCamera.setPreviewCallback(null);
|
||||
if(camera != null)
|
||||
camera.setPreviewCallback(null);
|
||||
}
|
||||
|
||||
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
|
||||
final double ASPECT_TOLERANCE = 0.1;
|
||||
double targetRatio = (double) w / h;
|
||||
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getOptimalPreviewSize() :: Method started.");
|
||||
if (sizes == null) return null;
|
||||
|
||||
Size optimalSize = null;
|
||||
@@ -161,45 +196,9 @@ public class CameraPreview extends ViewGroup implements SurfaceHolder.Callback,
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getOptimalPreviewSize() :: Method ended.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".getOptimalPreviewSize() :: Optimal size is: (" + Integer.toString(optimalSize.width) +
|
||||
", " + Integer.toString(optimalSize.height) + ")");
|
||||
return optimalSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
if (changed && getChildCount() > 0) {
|
||||
final View child = getChildAt(0);
|
||||
|
||||
final int width = r - l;
|
||||
final int height = b - t;
|
||||
|
||||
int previewWidth = width;
|
||||
int previewHeight = height;
|
||||
if (mPreviewSize != null) {
|
||||
previewWidth = mPreviewSize.width;
|
||||
previewHeight = mPreviewSize.height;
|
||||
}
|
||||
|
||||
// Center the child SurfaceView within the parent.
|
||||
if (width * previewHeight > height * previewWidth) {
|
||||
final int scaledChildWidth = previewWidth * height / previewHeight;
|
||||
child.layout((width - scaledChildWidth) / 2, 0,
|
||||
(width + scaledChildWidth) / 2, height);
|
||||
} else {
|
||||
final int scaledChildHeight = previewHeight * width / previewWidth;
|
||||
child.layout(0, (height - scaledChildHeight) / 2,
|
||||
width, (height + scaledChildHeight) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
|
||||
final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
|
||||
if (mSupportedPreviewSizes != null) {
|
||||
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.dialogs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.dialogs;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtcam.R;
|
||||
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@@ -1,107 +0,0 @@
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtcam.camera.CameraImageMonitor;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||
|
||||
public class ImageTransferThread extends Thread{
|
||||
private final String TAG = "IM_THREAD";
|
||||
private final String CLASS_NAME = ImageTransferThread.class.getSimpleName();
|
||||
|
||||
private boolean pause, done;
|
||||
private Object threadPauseMonitor;
|
||||
private CameraImageMonitor camMonitor;
|
||||
private Socket socket;
|
||||
private BufferedWriter writer;
|
||||
private BufferedReader reader;
|
||||
private byte[] image;
|
||||
private String serverIp;
|
||||
|
||||
public ImageTransferThread(String serverIp){
|
||||
this.serverIp = serverIp;
|
||||
pause = false;
|
||||
done = false;
|
||||
threadPauseMonitor = new Object();
|
||||
socket = null;
|
||||
writer = null;
|
||||
reader = null;
|
||||
camMonitor = CameraImageMonitor.getInstance();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
connectToServer();
|
||||
if(socket.isConnected()){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Not connected to a server. Finishing thread.");
|
||||
}else{
|
||||
while(!done){
|
||||
checkPause();
|
||||
image = camMonitor.getImageData();
|
||||
// TODO: implement image transfer protocol.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void connectToServer(){
|
||||
try{
|
||||
Logger.log_i(TAG, CLASS_NAME + ".connectToServer() :: Connecting to the server at " + serverIp);
|
||||
socket = new Socket(InetAddress.getByName(serverIp), ProjectConstants.SERVER_TCP_PORT_1);
|
||||
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
Logger.log_i(TAG, CLASS_NAME + ".connectToServer() :: Connection successful.");
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: Connection failed with message: " + io.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect(){
|
||||
if(socket != null && socket.isConnected()){
|
||||
try{
|
||||
socket.close();
|
||||
}catch (IOException io) {
|
||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: " + io.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void finish(){
|
||||
done = true;
|
||||
Logger.log_i(TAG, CLASS_NAME + ".finish() :: Finishing thread.");
|
||||
}
|
||||
|
||||
private void checkPause(){
|
||||
synchronized (threadPauseMonitor){
|
||||
while(pause){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".checkPause() :: Pause requested.");
|
||||
try{ threadPauseMonitor.wait(); }catch(InterruptedException ie){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void pauseThread(){
|
||||
pause = true;
|
||||
Logger.log_d(TAG, CLASS_NAME + ".pauseThread() :: Pausing thread.");
|
||||
}
|
||||
|
||||
public synchronized void resumeThread(){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".resumeThread() :: Resuming thread.");
|
||||
synchronized (threadPauseMonitor) {
|
||||
pause = false;
|
||||
threadPauseMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected(){
|
||||
if(socket != null && socket.isConnected())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
public class LCPThread extends Thread{
|
||||
|
341
src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java
Normal file
341
src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import ve.ucv.ciens.ccg.networkdata.VideoFrameDataMessage;
|
||||
import ve.ucv.ciens.ccg.networkdata.VideoStreamingControlMessage;
|
||||
import ve.ucv.ciens.ccg.nxtcam.camera.CameraImageMonitor;
|
||||
import ve.ucv.ciens.ccg.nxtcam.network.protocols.VideoStreamingProtocol;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.YuvImage;
|
||||
|
||||
public class VideoStreamingThread extends Thread{
|
||||
private final String TAG = "IM_THREAD";
|
||||
private final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
|
||||
|
||||
private enum ProtocolState_t {WAIT_FOR_ACK, WAIT_FOR_READY, CAN_SEND, END_STREAM};
|
||||
|
||||
private boolean pause, done;
|
||||
private Object threadPauseMonitor;
|
||||
private CameraImageMonitor camMonitor;
|
||||
private Socket socket;
|
||||
private ObjectOutputStream writer;
|
||||
private ObjectInputStream reader;
|
||||
private String serverIp;
|
||||
private ProtocolState_t protocolState;
|
||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
public VideoStreamingThread(String serverIp){
|
||||
super("Video Streaming Thread");
|
||||
this.serverIp = serverIp;
|
||||
pause = false;
|
||||
done = false;
|
||||
threadPauseMonitor = new Object();
|
||||
socket = null;
|
||||
writer = null;
|
||||
reader = null;
|
||||
camMonitor = CameraImageMonitor.getInstance();
|
||||
protocolState = ProtocolState_t.WAIT_FOR_READY;
|
||||
}
|
||||
|
||||
/*public void run(){
|
||||
byte[] image;
|
||||
Object tmpMessage;
|
||||
VideoStreamingControlMessage controlMessage;
|
||||
VideoFrameDataMessage dataMessage;
|
||||
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
connectToServer();
|
||||
|
||||
if(!socket.isConnected()){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Not connected to a server. Finishing thread.");
|
||||
return;
|
||||
}else{
|
||||
while(!done){
|
||||
// checkPause();
|
||||
switch(protocolState){
|
||||
case WAIT_FOR_READY:
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Reading message from server. State is WAIT_FOR_READY.");
|
||||
tmpMessage = readMessage();
|
||||
|
||||
if(!validateImageTransferProtocolMessage(tmpMessage)){
|
||||
// If the message received is not valid then send an UNRECOGNIZED message to the server.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received an unrecognized protocol message. State WAIT_FOR_READY.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Sending UNRECOGNIZED message to server.");
|
||||
sendUnrecognizedMessage();
|
||||
|
||||
}else{
|
||||
// Else if the message passed the validity check then proceed to the next protocol state.
|
||||
controlMessage = (VideoStreamingControlMessage)tmpMessage;
|
||||
if(controlMessage.message == VideoStreamingProtocol.FLOW_CONTROL_CONTINUE){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received FLOW_CONTROL_CONTINUE from the server.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Transitioning from WAIT_FOR_READY to CAN_SEND.");
|
||||
protocolState = ProtocolState_t.CAN_SEND;
|
||||
}else if(controlMessage.message == VideoStreamingProtocol.STREAM_CONTROL_END){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received STREAM_CONTROL_END from the server.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Transitioning from WAIT_FOR_READY to END_STREAM.");
|
||||
protocolState = ProtocolState_t.END_STREAM;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WAIT_FOR_ACK:
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Reading message from server. State is WAIT_FOR_ACK.");
|
||||
tmpMessage = readMessage();
|
||||
|
||||
if(!validateImageTransferProtocolMessage(tmpMessage)){
|
||||
// If the message received is not valid then send an UNRECOGNIZED message to the server.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received an unrecognized protocol message. State WAIT_FOR_ACK.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Sending UNRECOGNIZED message to server.");
|
||||
sendUnrecognizedMessage();
|
||||
|
||||
}else{
|
||||
// Else if the message passed the validity check then proceed to the next protocol state.
|
||||
controlMessage = (VideoStreamingControlMessage)tmpMessage;
|
||||
if(controlMessage.message == VideoStreamingProtocol.ACK_SEND_NEXT){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received ACK_SEND_NEXT from the server.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Transitioning from WAIT_FOR_ACK to CAN_SEND.");
|
||||
protocolState = ProtocolState_t.CAN_SEND;
|
||||
}else if(controlMessage.message == VideoStreamingProtocol.ACK_WAIT){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Received ACK_WAIT from the server.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Transitioning from WAIT_FOR_ACK to WAIT_FOR_READY.");
|
||||
protocolState = ProtocolState_t.WAIT_FOR_READY;
|
||||
}else if(controlMessage.message == VideoStreamingProtocol.STREAM_CONTROL_END){
|
||||
protocolState = ProtocolState_t.END_STREAM;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAN_SEND:
|
||||
// Get the image and it's parameters from the monitor.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Getting image data.");
|
||||
Rect imageSize = camMonitor.getImageParameters();
|
||||
image = camMonitor.getImageData();
|
||||
|
||||
// Compress the image as Jpeg.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Compressing image.");
|
||||
YuvImage yuvImage = new YuvImage(image, ImageFormat.NV21, imageSize.width(), imageSize.height(), null);
|
||||
yuvImage.compressToJpeg(imageSize, 90, outputStream);
|
||||
|
||||
// Prepare the message for sending.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Building message.");
|
||||
dataMessage = new VideoFrameDataMessage();
|
||||
dataMessage.imageWidth = imageSize.width();
|
||||
dataMessage.imageHeight = imageSize.height();
|
||||
dataMessage.data = outputStream.toByteArray();
|
||||
|
||||
// Send the message.
|
||||
try{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Sending message.");
|
||||
writer.writeObject(dataMessage);
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Error sending image to the server: " + io.getMessage());
|
||||
}
|
||||
|
||||
// Clean up stuff.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Cleaning.");
|
||||
yuvImage = null;
|
||||
image = null;
|
||||
outputStream.reset();
|
||||
dataMessage = null;
|
||||
imageSize = null;
|
||||
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Image data successfuly sent.");
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Transitioning from CAN_SEND to WAIT_FOR_ACK.");
|
||||
protocolState = ProtocolState_t.WAIT_FOR_ACK;
|
||||
break;
|
||||
|
||||
case END_STREAM:
|
||||
// Simply disconnect from the server.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Ending video stream.");
|
||||
disconnect();
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Thread finish reached.");
|
||||
}*/
|
||||
|
||||
public void run(){
|
||||
connectToServer();
|
||||
|
||||
if(!socket.isConnected()){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Not connected to a server. Finishing thread.");
|
||||
return;
|
||||
|
||||
}else{
|
||||
while(!done){
|
||||
sendImage();
|
||||
try{
|
||||
sleep(50L);
|
||||
}catch(InterruptedException ie){}
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Thread finish reached.");
|
||||
}
|
||||
|
||||
private void sendImage(){
|
||||
byte[] image;
|
||||
YuvImage yuvImage;
|
||||
VideoFrameDataMessage message;
|
||||
Rect imageSize;
|
||||
|
||||
image = camMonitor.getImageData();
|
||||
if(image == null){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: image is null, skipping frame.");
|
||||
return;
|
||||
}
|
||||
imageSize = camMonitor.getImageParameters();
|
||||
|
||||
// Compress the image as Jpeg.
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Compressing image.");
|
||||
yuvImage = new YuvImage(image, ImageFormat.NV21, imageSize.width(), imageSize.height(), null);
|
||||
yuvImage.compressToJpeg(imageSize, 90, outputStream);
|
||||
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Building message.");
|
||||
message = new VideoFrameDataMessage();
|
||||
message.data = outputStream.toByteArray();
|
||||
message.imageWidth = imageSize.width();
|
||||
message.imageHeight = imageSize.height();
|
||||
|
||||
try{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Sending message.");
|
||||
writer.writeObject(message);
|
||||
writer.flush();
|
||||
writer.reset();
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Message sent successfully: ");
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: Error sending image to the server: " + io.getMessage());
|
||||
|
||||
}finally{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Cleaning.");
|
||||
outputStream.reset();
|
||||
image = null;
|
||||
yuvImage = null;
|
||||
message = null;
|
||||
imageSize = null;
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
private void connectToServer(){
|
||||
try{
|
||||
Logger.log_i(TAG, CLASS_NAME + ".connectToServer() :: Connecting to the server at " + serverIp);
|
||||
socket = new Socket(InetAddress.getByName(serverIp), ProjectConstants.SERVER_TCP_PORT_1);
|
||||
writer = new ObjectOutputStream(socket.getOutputStream());
|
||||
reader = new ObjectInputStream(socket.getInputStream());
|
||||
Logger.log_i(TAG, CLASS_NAME + ".connectToServer() :: Connection successful.");
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: Connection failed with message: " + io.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect(){
|
||||
if(socket != null && socket.isConnected()){
|
||||
try{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".disconnect() :: Closing socket.");
|
||||
socket.close();
|
||||
}catch (IOException io) {
|
||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: " + io.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void finish(){
|
||||
done = true;
|
||||
Logger.log_i(TAG, CLASS_NAME + ".finish() :: Finishing thread.");
|
||||
}
|
||||
|
||||
private void checkPause(){
|
||||
synchronized (threadPauseMonitor){
|
||||
while(pause){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".checkPause() :: Pause requested.");
|
||||
try{ threadPauseMonitor.wait(); }catch(InterruptedException ie){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object readMessage(){
|
||||
Object tmpMessage;
|
||||
|
||||
// Read a message from the server stream.
|
||||
try{
|
||||
tmpMessage = reader.readObject();
|
||||
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException when reading in WAIT_FOR_READY state.");
|
||||
tmpMessage = null;
|
||||
return null;
|
||||
}catch(ClassNotFoundException cn){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: ClassNotFoundException when reading in WAIT_FOR_READY state.");
|
||||
tmpMessage = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
return tmpMessage;
|
||||
}
|
||||
|
||||
private boolean validateImageTransferProtocolMessage(Object message){
|
||||
if(message != null && message instanceof VideoStreamingControlMessage)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendUnrecognizedMessage(){
|
||||
VideoStreamingControlMessage message = new VideoStreamingControlMessage();
|
||||
message.message = VideoStreamingProtocol.UNRECOGNIZED;
|
||||
|
||||
try{
|
||||
writer.writeObject(message);
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException when writing UNRECOGNIZED in WAIT_FOR_READY state.");
|
||||
}
|
||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: UNRECOGNIZED message sent.");
|
||||
}
|
||||
|
||||
public synchronized void pauseThread(){
|
||||
pause = true;
|
||||
Logger.log_d(TAG, CLASS_NAME + ".pauseThread() :: Pausing thread.");
|
||||
}
|
||||
|
||||
public synchronized void resumeThread(){
|
||||
Logger.log_d(TAG, CLASS_NAME + ".resumeThread() :: Resuming thread.");
|
||||
synchronized (threadPauseMonitor) {
|
||||
pause = false;
|
||||
threadPauseMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected(){
|
||||
if(socket != null && socket.isConnected())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package ve.ucv.ciens.ccg.nxtcam.network.protocols;
|
||||
|
||||
|
||||
public abstract class ImageTransferProtocol{
|
||||
public static enum ProtocolState{
|
||||
SALUTE, IMG_FOLLOWS, SEND_DATA, PAUSED, WAITING, GOODBYE
|
||||
}
|
||||
|
||||
public static final byte MSG_HELLO = (byte)0x89;
|
||||
public static final byte MSG_GOODBYE = (byte)0x90;
|
||||
public static final byte MSG_IMG_DATA = (byte)0x42;
|
||||
public static final byte CMD_IMG_FOLLOWS = (byte)0x10;
|
||||
public static final byte CMD_PAUSE = (byte)0x15;
|
||||
public static final byte CMD_IMG_WAIT = (byte)0x20;
|
||||
public static final byte ACK_SEND_IMG = (byte)0x40;
|
||||
public static final byte ACK_IMG_RCVD = (byte)0x50;
|
||||
}
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network.protocols;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.network.protocols;
|
||||
|
||||
public final class VideoStreamingProtocol{
|
||||
public static final byte STREAM_CONTROL_END = 0x10;
|
||||
public static final byte ACK_SEND_NEXT = 0x20;
|
||||
public static final byte ACK_WAIT = 0x30;
|
||||
public static final byte FLOW_CONTROL_WAIT = 0x40;
|
||||
public static final byte FLOW_CONTROL_CONTINUE = 0x50;
|
||||
public static final byte IMAGE_DATA = 0x60;
|
||||
public static final byte UNRECOGNIZED = (byte)0xFF;
|
||||
|
||||
public static boolean checkValidityOfMessage(byte message){
|
||||
boolean validity;
|
||||
|
||||
switch(message){
|
||||
case STREAM_CONTROL_END:
|
||||
case ACK_SEND_NEXT:
|
||||
case ACK_WAIT:
|
||||
case FLOW_CONTROL_WAIT:
|
||||
case FLOW_CONTROL_CONTINUE:
|
||||
case IMAGE_DATA:
|
||||
case UNRECOGNIZED:
|
||||
validity = true;
|
||||
break;
|
||||
default:
|
||||
validity = false;
|
||||
}
|
||||
|
||||
return validity;
|
||||
}
|
||||
}
|
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
@@ -1,14 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtcam.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
public abstract class ProjectConstants {
|
||||
// Network related constants.
|
||||
public static final int SERVER_UDP_PORT = 8889;
|
||||
public static final int SERVER_TCP_PORT_1 = 9989;
|
||||
public static final int SERVER_TCP_PORT_2 = 9990;
|
||||
public static final UUID SERIAL_PORT_SERVICE_CLASS_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
|
||||
public static final String OUI_LEGO = "00:16:53";
|
||||
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
||||
public static final String SERVICE_DISCOVERY_MESSAGE = "NxtAR server here!";
|
||||
|
||||
public static final boolean DEBUG = true;
|
||||
// Activity results.
|
||||
public static final int RESULT_CAMERA_FAILURE = Activity.RESULT_FIRST_USER + 1;
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user