Skip to content

Commit

Permalink
Merge pull request #124 from lgcast-dev/master
Browse files Browse the repository at this point in the history
Initial LG Cast Integration
  • Loading branch information
jonghenhan authored Jan 24, 2022
2 parents 2aab785 + 9ca9efd commit 520e72d
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 13 deletions.
5 changes: 3 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
android:versionCode="8"
android:versionName="1.4.2" >

<application>
<receiver android:name=".ScreenOnOffReceiver">
<application android:usesCleartextTraffic="true">
<receiver android:name=".ScreenOnOffReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Connect SDK Core (Android)
# Connect SDK Core (Android)
The Connect SDK Core contains all of the core classes required for basic operation of Connect SDK. The core also includes support for some select protocols which do not have any heavy and/or external dependencies. These protocols include:
- Apple TV
- DIAL
Expand All @@ -7,13 +7,20 @@ The Connect SDK Core contains all of the core classes required for basic operati
- LG webOS
- Roku

##General Information
## General Information
For more information about Connect SDK, visit the [main repository](https://github.com/ConnectSDK/Connect-SDK-Android).

##Setup
## Setup
Unless you are doing very specialized work to extend the SDK, you should not need to make direct use of this repository. Instead, clone the [main repository](https://github.com/ConnectSDK/Connect-SDK-Android), which includes this repository as a submodule.

##License
## External libraries

libgstreamer_android.so is shared object library and links dynamically GStreamer open-source multimedia framework that is licensed under Lesser General Public License.

You can download and rebuild libgstreamer_android.so at [libgstreamer_android.tar](https://github.com/ConnectSDK/Connect-SDK-Android-Core/blob/master/jniLibs/libgstreamer_android.tar)


## License
Copyright (c) 2013-2015 LG Electronics.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 21
compileSdkVersion 31
buildToolsVersion '30.0.3'

packagingOptions {
exclude 'LICENSE.txt'
Expand All @@ -40,6 +41,7 @@ android {
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['jniLibs']
}
androidTest {
java.srcDirs = [
Expand All @@ -54,17 +56,18 @@ android {
}
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
minSdkVersion 24
targetSdkVersion 31
}

useLibrary 'org.apache.http.legacy'
}

dependencies {
implementation files('libs/Java-WebSocket-1.3.7.jar')
implementation files('libs/javax.jmdns_3.4.1-patch2.jar')
implementation 'com.android.support:support-v4:21.0.3'
implementation 'com.android.support:mediarouter-v7:21.0.3'
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation files('libs/lgcast_sdk_v2.1.1.aar')
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.gms:play-services-cast:19.0.0'
implementation 'com.googlecode.plist:dd-plist:1.23'
implementation group: 'net.i2p.crypto', name: 'eddsa', version: '0.3.0'
Expand Down
Binary file added jniLibs/arm64-v8a/libc++_shared.so
Binary file not shown.
Binary file added jniLibs/arm64-v8a/libgstreamer-appcast.so
Binary file not shown.
Binary file added jniLibs/arm64-v8a/libgstreamer_android.so
Binary file not shown.
Binary file added jniLibs/armeabi-v7a/libc++_shared.so
Binary file not shown.
Binary file added jniLibs/armeabi-v7a/libgstreamer-appcast.so
Binary file not shown.
Binary file added jniLibs/armeabi-v7a/libgstreamer_android.so
Binary file not shown.
Binary file added jniLibs/libgstreamer_android.tar
Binary file not shown.
Binary file added libs/lgcast_sdk_v2.1.1.aar
Binary file not shown.
62 changes: 61 additions & 1 deletion src/com/connectsdk/service/WebOSTVService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
package com.connectsdk.service;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.PointF;

import androidx.annotation.NonNull;
import android.util.Log;

Expand All @@ -34,6 +37,8 @@
import com.connectsdk.discovery.DiscoveryFilter;
import com.connectsdk.discovery.DiscoveryManager;
import com.connectsdk.discovery.DiscoveryManager.PairingLevel;
import com.connectsdk.service.capability.LGCastControl;
import com.connectsdk.service.lgcast.screenmirroring.ScreenMirroringApi;
import com.connectsdk.service.capability.CapabilityMethods;
import com.connectsdk.service.capability.ExternalInputControl;
import com.connectsdk.service.capability.KeyControl;
Expand All @@ -57,6 +62,7 @@
import com.connectsdk.service.config.ServiceConfig;
import com.connectsdk.service.config.ServiceDescription;
import com.connectsdk.service.config.WebOSTVServiceConfig;
import com.connectsdk.service.lgcast.screenmirroring.ScreenMirroringHelper;
import com.connectsdk.service.sessions.LaunchSession;
import com.connectsdk.service.sessions.LaunchSession.LaunchSessionType;
import com.connectsdk.service.sessions.WebAppSession;
Expand All @@ -68,6 +74,7 @@
import com.connectsdk.service.webos.WebOSTVServiceSocketClient;
import com.connectsdk.service.webos.WebOSTVServiceSocketClient.WebOSTVServiceSocketClientListener;

import com.lge.lgcast.common.utils.XmlUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -88,7 +95,7 @@
import javax.xml.parsers.DocumentBuilderFactory;

@SuppressLint("DefaultLocale")
public class WebOSTVService extends WebOSTVDeviceService implements Launcher, MediaPlayer, PlaylistControl, VolumeControl, TVControl, ToastControl, ExternalInputControl, MouseControl, KeyControl, TextInputControl, WebAppLauncher {
public class WebOSTVService extends WebOSTVDeviceService implements Launcher, MediaPlayer, PlaylistControl, VolumeControl, TVControl, ToastControl, ExternalInputControl, MouseControl, KeyControl, TextInputControl, WebAppLauncher, LGCastControl {

public static final String ID = "webOS TV";
private static final String MEDIA_PLAYER_ID = "MediaPlayer";
Expand Down Expand Up @@ -2448,6 +2455,16 @@ protected void updateCapabilities() {
capabilities.add(MediaPlayer.Loop);
}

String locationXML = serviceDescription.getLocationXML();
String appCasting = (locationXML != null) ? XmlUtil.findElement(locationXML, "appCasting") : null;
String appCastingFeature = (locationXML != null) ? XmlUtil.findElement(locationXML, "appCastingFeature") : null;

if (appCastingFeature != null) {
if (appCastingFeature.contains("mirroring")) capabilities.add(LGCastControl.ScreenMirroring);
if (appCastingFeature.contains("camera")) capabilities.add(LGCastControl.RemoteCamera);
} else if (appCasting != null) {
if ("support".equals(appCasting)) capabilities.add(LGCastControl.ScreenMirroring);
}
}

setCapabilities(capabilities);
Expand Down Expand Up @@ -2552,4 +2569,47 @@ public void sendPairingKey(String pairingKey) {
public static interface ServiceInfoListener extends ResponseListener<JSONArray> { }

public static interface SystemInfoListener extends ResponseListener<JSONObject> { }

/**********************************************************************************************
* LG CAST - SCREEN MIRRORING
*********************************************************************************************/
@Override
public void startScreenMirroring(Context context, Intent projectionData, ScreenMirroringStartListener listener) {
startScreenMirroring(context, projectionData, null, listener);
}

@Override
public void startScreenMirroring(Context context, Intent projectionData, Class secondScreenClass, ScreenMirroringStartListener listener) {
try {
if (hasCapability(LGCastControl.ScreenMirroring) == false) throw new Exception("This device does not support LG Cast");
if (ScreenMirroringHelper.isOsCompatible() == false) throw new Exception("Incompatible OS version (LG Cast is compatible from Android Q).");
if (ScreenMirroringHelper.isRunning(context) == true) throw new Exception("Screen Mirroring is already running");
ScreenMirroringApi.getInstance().startMirroring(context, projectionData, getServiceDescription().getIpAddress(), secondScreenClass, listener);
} catch (Exception e) {
listener.onError(new ServiceCommandError(LGCastControl.SCREEN_MIRRORING_ERROR_GENERIC, e.getMessage()));
}
}

@Override
public void stopScreenMirroring(Context context, ScreenMirroringStopListener listener) {
try {
if (ScreenMirroringHelper.isRunning(context) == false) throw new Exception("Screen Mirroring is not running");
ScreenMirroringApi.getInstance().stopMirroring(context, listener);
} catch (Exception e) {
listener.onError(new ServiceCommandError(e.getMessage()));
}
}

/**********************************************************************************************
* LG CAST - REMOTE CAMERA
*********************************************************************************************/
@Override
public void startRemoteCamera() {
// TODO
}

@Override
public void stopRemoteCamera() {
// TODO
}
}
56 changes: 56 additions & 0 deletions src/com/connectsdk/service/capability/LGCastControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* ScreenMirroringApi
* Connect SDK
*
* Copyright (c) 2020 LG Electronics.
*
* 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 com.connectsdk.service.capability;

import android.content.Context;
import android.content.Intent;
import com.connectsdk.service.capability.listeners.ResponseListener;
import com.connectsdk.service.lgcast.screenmirroring.SecondScreen;

public interface LGCastControl extends CapabilityMethods {
String Any = "LGCast.Any";
String ScreenMirroring = "LGCast.ScreenMirroring";
String RemoteCamera = "LGCast.RemoteCamera";

String[] Capabilities = {
ScreenMirroring,
RemoteCamera,
};

int SCREEN_MIRRORING_ERROR_GENERIC = 0;
int SCREEN_MIRRORING_ERROR_CONNECTION_CLOSED = 1;
int SCREEN_MIRRORING_ERROR_DEVICE_SHUTDOWN = 2;
int SCREEN_MIRRORING_ERROR_RENDERER_TERMINATED = 3;
int SCREEN_MIRRORING_ERROR_STOPPED_BY_NOTIFICATION = 4;

void startScreenMirroring(Context context, Intent projectionData, ScreenMirroringStartListener listener);
void startScreenMirroring(Context context, Intent projectionData, Class secondScreenClass, ScreenMirroringStartListener listener);
void stopScreenMirroring(Context context, ScreenMirroringStopListener listener);

void startRemoteCamera();
void stopRemoteCamera();

interface ScreenMirroringStartListener extends ResponseListener<SecondScreen> {
void onPairing();
}

interface ScreenMirroringStopListener extends ResponseListener<String> {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* RemoteCameraApi
* Connect SDK
*
* Copyright (c) 2020 LG Electronics.
*
* 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 com.connectsdk.service.lgcast.remotecamera;

import android.app.ActivityManager;
import android.content.Context;
import android.view.Surface;
import com.lge.lgcast.remotecamera.service.RemoteCameraService;
import com.lge.lgcast.remotecamera.service.RemoteCameraServiceIF;
import com.lge.lgcast.common.utils.AppUtil;

public class RemoteCameraApi {
private Context mContext;

public RemoteCameraApi(Context context) {
mContext = context;
}

public void startRemoteCamera(Surface previewSurface) {
RemoteCameraServiceIF.requestStart(mContext, previewSurface);
}

public void stopRemoteCamera() {
RemoteCameraServiceIF.requestStop(mContext);
}

public boolean isRunning() {
ActivityManager.RunningServiceInfo serviceInfo = AppUtil.getServiceInfo(mContext, RemoteCameraService.class.getName());
return (serviceInfo != null) ? serviceInfo.foreground : false;
}
}
Loading

0 comments on commit 520e72d

Please sign in to comment.