Skip to content

Commit

Permalink
- Renamed FFmpeg library module
Browse files Browse the repository at this point in the history
- Minor code refactors
  • Loading branch information
sravan953 committed Jul 16, 2016
1 parent c5cda2d commit b42cbb8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gopro_gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.biryanistudio.goprogateway"
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
Expand All @@ -22,7 +22,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.+'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile project(':FFmpegLibrary')
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
import android.util.Log;

import com.biryanistudio.goprogateway.UDPService;
import com.github.hiteshsondhi88.libffmpeg.FFmpeg;
import com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException;
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException;
import com.biryanistudio.FFmpegLibrary.FFmpeg;
import com.biryanistudio.FFmpegLibrary.FFmpegExecuteResponseHandler;
import com.biryanistudio.FFmpegLibrary.LoadBinaryResponseHandler;
import com.biryanistudio.FFmpegLibrary.exceptions.FFmpegCommandAlreadyRunningException;
import com.biryanistudio.FFmpegLibrary.exceptions.FFmpegNotSupportedException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;

/**
* Created by Sravan on 10-Jul-16.
Expand All @@ -35,30 +33,34 @@ public class FFmpegStreamer {
final private String TAG = getClass().getSimpleName();
final private Context mContext;
private FFmpeg mFFmpeg;
private boolean mFFmpegLoaded = false;
private Network mWifiNetwork;
private boolean mWifiBound = false;
private boolean mCellularBound = false;
final private Intent mUDPIntent;

final private String YOUTUBE_KEY = "";
final private String YOUTUBE_KEY = "x5v1-uqey-h9qf-1fa3";
private String[] cmd = {"-i", "udp://10.5.5.9:8554", "-codec:v:0", "copy", "-codec:a:1", "copy",
"-ar", "44100", "-preset", "veryfast", "-f", "flv", "rtmp://a.rtmp.youtube.com/live2/" + YOUTUBE_KEY};
"-ar", "44100", "-f", "flv", "rtmp://a.rtmp.youtube.com/live2/" + YOUTUBE_KEY};

public FFmpegStreamer(Context context) {
mContext = context;
mUDPIntent = new Intent(mContext, UDPService.class);
loadFFMPEG();
}

public void start() {
if(!mFFmpegLoaded)
if(mWifiBound && mCellularBound) {
new RequestStreamTask().execute();
} else {
bindPortOnWifi();
else
new RequestStreamTask2().execute();
setCellularAsDefault();
}
}

public void stop() {
Log.i(TAG, "FFmpeg killRunningProcess");
mFFmpeg.killRunningProcesses();
mContext.stopService(mUDPIntent);
Log.i(TAG, "ffmpeg killRunningProcesses");
}

private void bindPortOnWifi() {
Expand All @@ -70,16 +72,12 @@ private void bindPortOnWifi() {
public void onAvailable (Network network) {
try {
Log.i(TAG, "WIFI AVAILABLE");
mWifiBound = true;
mWifiNetwork = network;
DatagramSocket datagramSocket = new DatagramSocket();
network.bindSocket(datagramSocket);
datagramSocket.connect(InetAddress.getByName("10.5.5.9"), 8554);
Log.i(TAG, "PORT: "+ datagramSocket.getLocalPort());
setCellularAsDefault();
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
Log.i(TAG, "DatagramSocket PORT: "+ datagramSocket.getLocalPort());
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -96,12 +94,11 @@ private void setCellularAsDefault() {
final ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkRequest cellularNetworkReq = new NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).build();
connectivityManager.requestNetwork(cellularNetworkReq, new ConnectivityManager.NetworkCallback() {
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onAvailable (Network network) {
Log.i(TAG, "CELLULAR AVAILABLE");
mCellularBound = true;
connectivityManager.bindProcessToNetwork(network);
loadFFMPEG();
}

@Override
Expand All @@ -116,24 +113,22 @@ public void loadFFMPEG() {
mFFmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {
Log.i(TAG, "ffmpeg loadBinary onStart");
Log.i(TAG, "FFmpeg loadBinary onStart");
}

@Override
public void onFailure() {
Log.i(TAG, "ffmpeg loadBinary onFailure");
Log.i(TAG, "FFmpeg loadBinary onFailure");
}

@Override
public void onSuccess() {
Log.i(TAG, "ffmpeg loadBinary onSuccess");
Log.i(TAG, "FFmpeg loadBinary onSuccess");
}

@Override
public void onFinish() {
Log.i(TAG, "ffmpeg loadBinary onFinish");
mFFmpegLoaded = true;
new RequestStreamTask2().execute();
Log.i(TAG, "FFmpeg loadBinary onFinish");
}
});
} catch (FFmpegNotSupportedException e) {
Expand All @@ -146,7 +141,7 @@ private void executeCmd() {
mFFmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
@Override
public void onStart() {
Log.i(TAG, "ffmpeg execute onStart");
Log.i(TAG, "FFmpeg execute onStart");
}

@Override
Expand All @@ -166,15 +161,15 @@ public void onSuccess(String message) {

@Override
public void onFinish() {
Log.i(TAG, "ffmpeg execute onFinish");
Log.i(TAG, "FFmpeg execute onFinish");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
}

private class RequestStreamTask2 extends AsyncTask<Void, Void, String> {
private class RequestStreamTask extends AsyncTask<Void, Void, String> {
final private String GOPRO_STREAM_URL = "http://10.5.5.9/gp/gpControl/execute?p1=gpStream&a1=proto_v2&c1=restart";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import android.os.Bundle;
import android.security.NetworkSecurityPolicy;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.biryanistudio.goprogateway.Fragment.WifiFragment;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

// See README for documentation about NetworkSecurityPolicy
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getFragmentManager().beginTransaction().replace(R.id.container, new WifiFragment()).commit();

// See README for documentation on this issue
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();
NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();

Log.i("TAG", Arrays.asList(Build.SUPPORTED_ABIS).toString());
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':gopro_gateway'
include ':gopro_gateway', ':FFmpegLibrary'

0 comments on commit b42cbb8

Please sign in to comment.