Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions example4/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.majorkernelpanic.example4"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:largeHeap="true"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added example4/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example4/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example4/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example4/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions example4/res/layout/main_activity_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VideoPublisherMainActivity">
</RelativeLayout>
6 changes: 6 additions & 0 deletions example4/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions example4/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
4 changes: 4 additions & 0 deletions example4/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">example4</string>
</resources>
8 changes: 8 additions & 0 deletions example4/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

</resources>
145 changes: 145 additions & 0 deletions example4/src/net/majorkernelpanic/example4/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package net.majorkernelpanic.example4;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

import net.majorkernelpanic.streaming.MediaStream;
import net.majorkernelpanic.streaming.Session;
import net.majorkernelpanic.streaming.SessionBuilder;
import net.majorkernelpanic.streaming.audio.AudioQuality;
import net.majorkernelpanic.streaming.gl.SurfaceView;
import net.majorkernelpanic.streaming.video.VideoQuality;
import net.majorkernelpanic.streaming.video.VideoStream;

public class MainActivity extends Activity implements SurfaceHolder.Callback, Session.Callback {

private static final String TAG = "example4";

// TODO: change this IP with the destination IP of the video streaming
private static final String DESTINATION_IP = "10.34.0.162";

private byte mediaCodec;

private SurfaceView surfaceView;
private Session session;
private final int BITRATE = 900000; // 1500000
private final int FRAMERATE = 15; // 30

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaCodec = MediaStream.MODE_MEDIACODEC_API;

ViewGroup root = (ViewGroup) getLayoutInflater().inflate(R.layout.main_activity_layout, null);

// create dummy surface to avoid having a preview in the server side
surfaceView = new SurfaceView(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
VideoStream.VIDEO_WIDTH_INPUT, VideoStream.VIDEO_HEIGHT_INPUT);

root.addView(surfaceView, layoutParams);
surfaceView.getHolder().addCallback(this);
surfaceView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (session.isStreaming()) {
session.stop();
Toast.makeText(MainActivity.this, "Stopping publisher", Toast.LENGTH_SHORT).show();
} else {
session.configure();
}
return false;
}
});

setContentView(root);

initializeSession();
}

private void initializeSession() {
VideoQuality quality = new VideoQuality(
VideoStream.VIDEO_WIDTH_INPUT, VideoStream.VIDEO_HEIGHT_INPUT,
FRAMERATE, BITRATE);

session = SessionBuilder.getInstance()
.setCallback(this)
.setSurfaceView(surfaceView)
.setPreviewOrientation(0)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_NONE)
.setAudioQuality(new AudioQuality(16000, 32000))
.setVideoEncoder(SessionBuilder.VIDEO_H264)
.setVideoQuality(quality)
.build();
}

private void startStreaming() {
session.setDestination(DESTINATION_IP);
session.getVideoTrack().setStreamingMethod(mediaCodec);
Log.i(TAG, "Streaming to IP: " + DESTINATION_IP);
if (!session.isStreaming()) {
Log.i(TAG, "Configure session!");
session.configure();
} else {
session.stop();
}
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
startStreaming();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
session.stop();
}

@Override
public void onBitrateUpdate(long bitrate) {

}

@Override
public void onSessionError(int reason, int streamType, Exception e) {

}

@Override
public void onPreviewStarted() {

}

@Override
public void onSessionConfigured() {
Log.i(TAG, "Session started");
Toast.makeText(this, "Starting publisher", Toast.LENGTH_SHORT).show();
session.start();
}

@Override
public void onSessionStarted() {
}

@Override
public void onSessionStopped() {
}

@Override
protected void onDestroy() {
super.onDestroy();
session.release();
}
}