projects
/
rtmpclient.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
679195d
)
fix some bug
author
Peng Li
<seudut@gmail.com>
Wed, 23 May 2018 08:50:41 +0000
(16:50 +0800)
committer
Peng Li
<seudut@gmail.com>
Wed, 23 May 2018 08:50:41 +0000
(16:50 +0800)
app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
patch
|
blob
|
history
app/src/main/java/ai/suanzi/rtmpclient/MyService.java
patch
|
blob
|
history
app/src/main/java/ai/suanzi/rtmpclient/UsbMonitor.java
patch
|
blob
|
history
diff --git
a/app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
b/app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
index
1ad33b4
..
16322c6
100644
(file)
--- a/
app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
+++ b/
app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
@@
-43,9
+43,9
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private NetworkMonitor networkMonitor;
private UsbMonitor mUsbMonitor;
private ServiceHealthMonitor mServiceHealthMonitor;
private NetworkMonitor networkMonitor;
private UsbMonitor mUsbMonitor;
private ServiceHealthMonitor mServiceHealthMonitor;
- private static final int INTERVAL =
2
* 60; // seconds
+ private static final int INTERVAL =
3
* 60; // seconds
- boolean mBounded;
+ boolean mBounded
= false
;
MyService mServer;
Intent mIntent;
MyService mServer;
Intent mIntent;
@@
-98,7
+98,6
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(mUsbMonitor.hasUsbCamera()){
doBindService();
}
if(mUsbMonitor.hasUsbCamera()){
doBindService();
}
-
}
}, this);
}
}, this);
@@
-135,7
+134,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
gLogger.error("onNotHealthy, in " + INTERVAL + " seconds, the publishing may stopped or have error ");
doUnbindService();
doBindService();
gLogger.error("onNotHealthy, in " + INTERVAL + " seconds, the publishing may stopped or have error ");
doUnbindService();
doBindService();
-
+ //restartApplication();
}
});
mServiceHealthMonitor.setInterval(INTERVAL); // 5 minutes
}
});
mServiceHealthMonitor.setInterval(INTERVAL); // 5 minutes
@@
-162,7
+161,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(mServer.setRtmpUrl(UserInfo.getConfig().toUrl(mMacAddr))){
mServer.startPreview(mHolder);
}
if(mServer.setRtmpUrl(UserInfo.getConfig().toUrl(mMacAddr))){
mServer.startPreview(mHolder);
}
- gLogger.debug("onServiceConnected - start health monitor thread, interval " + INTERVAL);
+
}
};
}
};
@@
-170,6
+169,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private void doBindService(){
gLogger.debug("doBindService");
if(!mBounded && canStartService()) {
private void doBindService(){
gLogger.debug("doBindService");
if(!mBounded && canStartService()) {
+ gLogger.debug("Start service --------->");
bindService(mIntent, mConnection, BIND_AUTO_CREATE);
}
}
bindService(mIntent, mConnection, BIND_AUTO_CREATE);
}
}
@@
-177,6
+177,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private void doUnbindService() {
gLogger.debug("doUnbindService");
if(mBounded){
private void doUnbindService() {
gLogger.debug("doUnbindService");
if(mBounded){
+ gLogger.debug("Stop service <---------");
unbindService(mConnection);
mBounded = false;
}
unbindService(mConnection);
mBounded = false;
}
@@
-193,10
+194,8
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(NetworkMonitor.isNetworkAvailable(this) && mUsbMonitor.hasUsbCamera()){
gLogger.error("Current network is available");
doBindService();
if(NetworkMonitor.isNetworkAvailable(this) && mUsbMonitor.hasUsbCamera()){
gLogger.error("Current network is available");
doBindService();
-
-
} else {
} else {
- gLogger.error("Current network
is NOT available
");
+ gLogger.error("Current network
NOT available or no USB Camera connected
");
}
mBtnStart.setText("start");
}
mBtnStart.setText("start");
@@
-205,16
+204,13
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
public void onClick(View view){
gLogger.error("----------> onClick");
saveConfig();
public void onClick(View view){
gLogger.error("----------> onClick");
saveConfig();
-
- //unbindService(mConnection);
- bindService(mIntent, mConnection, BIND_AUTO_CREATE);
- //doUnbindService();
- //doBindService();
+ doUnbindService();
+ doBindService();
}
});
if(!mServiceHealthMonitor.isAlive()) {
}
});
if(!mServiceHealthMonitor.isAlive()) {
- gLogger.debug("mServiceHealthMonitor start
"
);
+ gLogger.debug("mServiceHealthMonitor start
, interval " + INTERVAL
);
mServiceHealthMonitor.start();
}
}
mServiceHealthMonitor.start();
}
}
@@
-246,7
+242,9
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
@Override
protected void onDestroy(){
super.onDestroy();
@Override
protected void onDestroy(){
super.onDestroy();
+ mUsbMonitor.unregisterReceiver();
unregisterReceiver(networkMonitor);
unregisterReceiver(networkMonitor);
+ unbindService(mConnection);
gLogger.debug("onDestroy --------->");
}
gLogger.debug("onDestroy --------->");
}
@@
-320,7
+318,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
public void onCameraError(String msg){
gLogger.error("onCameraEvent " + msg);
if(mUsbMonitor.hasUsbCamera()){
public void onCameraError(String msg){
gLogger.error("onCameraEvent " + msg);
if(mUsbMonitor.hasUsbCamera()){
- mServer.reopenCamera();
+
//
mServer.reopenCamera();
}
}
}
}
@@
-334,4
+332,10
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
gLogger.error("onPublishing: " + msg);
mServiceHealthMonitor.record();
}
gLogger.error("onPublishing: " + msg);
mServiceHealthMonitor.record();
}
+
+ private void restartApplication() {
+ final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ }
}
}
diff --git
a/app/src/main/java/ai/suanzi/rtmpclient/MyService.java
b/app/src/main/java/ai/suanzi/rtmpclient/MyService.java
index
2d49e9c
..
d448064
100644
(file)
--- a/
app/src/main/java/ai/suanzi/rtmpclient/MyService.java
+++ b/
app/src/main/java/ai/suanzi/rtmpclient/MyService.java
@@
-71,7
+71,8
@@
public class MyService extends Service implements Camera.PreviewCallback, Camer
}
if(frontId != -1) camerId = frontId;
else if(backId != -1) camerId = backId;
}
if(frontId != -1) camerId = frontId;
else if(backId != -1) camerId = backId;
- mCamera = Camera.open(camerId);
+ gLogger.debug("openCameraOriginal - camera id " + camerId);
+ mCamera = Camera.open(1);
} catch (Exception e) {
gLogger.error("openCameraOriginal - camera is not available. error: " + e.getMessage());
if(mListener != null) mListener.onCameraError("openCamera - error: " + e.getMessage());
} catch (Exception e) {
gLogger.error("openCameraOriginal - camera is not available. error: " + e.getMessage());
if(mListener != null) mListener.onCameraError("openCamera - error: " + e.getMessage());
@@
-148,8
+149,14
@@
public class MyService extends Service implements Camera.PreviewCallback, Camer
gLogger.error( "onDestroy --------->");
Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
if(mCamera != null){
gLogger.error( "onDestroy --------->");
Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
if(mCamera != null){
- mCamera.stopPreview();
- mCamera.release();
+ try {
+ mCamera.stopPreview();
+ mCamera.release();
+ mCamera = null;
+ } catch (Exception e){
+ gLogger.error("onDestroy - error " + e.getMessage());
+ e.printStackTrace();
+ }
}
}
}
}
@@
-197,16
+204,21
@@
public class MyService extends Service implements Camera.PreviewCallback, Camer
}
public void reopenCamera() {
}
public void reopenCamera() {
+ gLogger.debug("reopenCamera");
if(mCamera != null){
mCamera.stopPreview();
mCamera.release();
if(mCamera != null){
mCamera.stopPreview();
mCamera.release();
+ mCamera = null;
}
openCameraOriginal();
}
public boolean setRtmpUrl (String url){
//this.rtmpUrl = url;
}
openCameraOriginal();
}
public boolean setRtmpUrl (String url){
//this.rtmpUrl = url;
- if(mCamera == null) return false;
+ if(mCamera == null){
+ gLogger.error("setRtmpUrl, error mCamera is null");
+ return false;
+ }
gLogger.error("setRtmpUrl - size: " + width + "x" + height + ". url: " + url);
int ret = FfmpegHelper.initEncoder(width, height, url);
if(ret != 0){
gLogger.error("setRtmpUrl - size: " + width + "x" + height + ". url: " + url);
int ret = FfmpegHelper.initEncoder(width, height, url);
if(ret != 0){
diff --git
a/app/src/main/java/ai/suanzi/rtmpclient/UsbMonitor.java
b/app/src/main/java/ai/suanzi/rtmpclient/UsbMonitor.java
index
61481ee
..
c862ff0
100644
(file)
--- a/
app/src/main/java/ai/suanzi/rtmpclient/UsbMonitor.java
+++ b/
app/src/main/java/ai/suanzi/rtmpclient/UsbMonitor.java
@@
-47,6
+47,11
@@
public class UsbMonitor {
//mUsbManager.requestPermission(device, mPermissionIntent);
}
//mUsbManager.requestPermission(device, mPermissionIntent);
}
+ public void unregisterReceiver (){
+ mContext.unregisterReceiver(mUsbReceiver);
+
+ }
+
private boolean isUvcCamera(UsbDevice device){
return (device.getDeviceProtocol() == 1 && device.getProductName().contains("Camera"));
}
private boolean isUvcCamera(UsbDevice device){
return (device.getDeviceProtocol() == 1 && device.getProductName().contains("Camera"));
}
@@
-88,7
+93,7
@@
public class UsbMonitor {
gLogger.error(device.toString());
if(isUvcCamera(device)) {
mUsbCameraList.remove(device);
gLogger.error(device.toString());
if(isUvcCamera(device)) {
mUsbCameraList.remove(device);
- mListener.onCamera
C
onnected();
+ mListener.onCamera
Disc
onnected();
}
}
} else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
}
}
} else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
@@
-97,7
+102,7
@@
public class UsbMonitor {
gLogger.error(device.toString());
if(isUvcCamera(device)) {
mUsbCameraList.add(device);
gLogger.error(device.toString());
if(isUvcCamera(device)) {
mUsbCameraList.add(device);
- mListener.onCamera
Disc
onnected();
+ mListener.onCamera
C
onnected();
}
}
}
}
}
}