Skip to content

Commit

Permalink
Better wowza support. Some bug fixes. SSL server still buggy.
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Jun 3, 2013
1 parent 3cd905a commit 76a76c0
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 102 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-6.1.0.jar"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
8 changes: 4 additions & 4 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@
android:key="http_server_enabled"
android:summary="@string/settings23"
android:title="@string/settings22" />
<!-- <CheckBoxPreference
<CheckBoxPreference
android:defaultValue="false"
android:key="use_https"
android:summary="@string/settings25"
android:title="@string/settings24" /> -->
android:title="@string/settings24" />
<EditTextPreference
android:defaultValue="8080"
android:inputType="number"
android:key="http_port"
android:summary="@string/settings21"
android:title="@string/settings20" />
<!-- <EditTextPreference
<EditTextPreference
android:defaultValue="8443"
android:inputType="number"
android:key="https_port"
android:summary="@string/settings27"
android:title="@string/settings26" /> -->
android:title="@string/settings26" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings28" >
Expand Down
8 changes: 6 additions & 2 deletions src/net/majorkernelpanic/http/TinyHttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,13 @@ public void run() {
} catch (HttpException e) {
Log.e(TAG,"Unrecoverable HTTP protocol violation: " + e.getMessage());
} finally {
/*try {
try {
OutputStream sockOutOStream = socket.getOutputStream();
sockOutOStream.write(new byte[0]);
sockOutOStream.flush();
socket.close();
} catch (IOException e) {}*/
} catch (IOException e) {
}
try {
this.conn.shutdown();
} catch (Exception ignore) {}
Expand Down
7 changes: 3 additions & 4 deletions src/net/majorkernelpanic/spydroid/SpydroidApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.majorkernelpanic.streaming.SessionBuilder;
import net.majorkernelpanic.streaming.video.VideoQuality;

import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;

import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void onCreate() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);

notificationEnabled = settings.getBoolean("notification_enabled", true);

// On android 3.* AAC ADTS is not supported so we set the default encoder to AMR-NB, on android 4.* AAC is the default encoder
audioEncoder = (Integer.parseInt(android.os.Build.VERSION.SDK)<14) ? SessionBuilder.AUDIO_AMRNB : SessionBuilder.AUDIO_AAC;
audioEncoder = Integer.parseInt(settings.getString("audio_encoder", String.valueOf(audioEncoder)));
Expand Down Expand Up @@ -137,14 +136,14 @@ else if (key.equals("video_bitrate")) {
}

else if (key.equals("audio_encoder") || key.equals("stream_audio")) {
audioEncoder = Integer.parseInt(sharedPreferences.getString("audio_encoder", "0"));
audioEncoder = Integer.parseInt(sharedPreferences.getString("audio_encoder", String.valueOf(audioEncoder)));
SessionBuilder.getInstance().setAudioEncoder( audioEncoder );
if (!sharedPreferences.getBoolean("stream_audio", false))
SessionBuilder.getInstance().setAudioEncoder(0);
}

else if (key.equals("stream_video") || key.equals("video_encoder")) {
videoEncoder = Integer.parseInt(sharedPreferences.getString("video_encoder", "0"));
videoEncoder = Integer.parseInt(sharedPreferences.getString("video_encoder", String.valueOf(videoEncoder)));
SessionBuilder.getInstance().setVideoEncoder( videoEncoder );
if (!sharedPreferences.getBoolean("stream_video", true))
SessionBuilder.getInstance().setVideoEncoder(0);
Expand Down
19 changes: 11 additions & 8 deletions src/net/majorkernelpanic/spydroid/ui/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package net.majorkernelpanic.spydroid.ui;

import static net.majorkernelpanic.http.TinyHttpServer.KEY_HTTPS_ENABLED;
import static net.majorkernelpanic.http.TinyHttpServer.KEY_HTTPS_PORT;
import static net.majorkernelpanic.http.TinyHttpServer.KEY_HTTP_ENABLED;
import static net.majorkernelpanic.http.TinyHttpServer.KEY_HTTP_PORT;

Expand All @@ -37,6 +38,7 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;

@SuppressWarnings("deprecation")
public class OptionsActivity extends PreferenceActivity {
Expand All @@ -59,16 +61,15 @@ protected void onCreate(Bundle savedInstanceState){
final ListPreference videoBitrate = (ListPreference) findPreference("video_bitrate");
final ListPreference videoFramerate = (ListPreference) findPreference("video_framerate");
final CheckBoxPreference httpEnabled = (CheckBoxPreference) findPreference("http_server_enabled");
//final CheckBoxPreference httpsEnabled = (CheckBoxPreference) findPreference("use_https");
final CheckBoxPreference httpsEnabled = (CheckBoxPreference) findPreference("use_https");
final Preference httpPort = findPreference(KEY_HTTP_PORT);
//final Preference httpsPort = findPreference(KEY_HTTPS_PORT);
final Preference httpsPort = findPreference(KEY_HTTPS_PORT);

boolean videoState = settings.getBoolean("stream_video", true);
videoEncoder.setEnabled(videoState);
videoResolution.setEnabled(videoState);
videoBitrate.setEnabled(videoState);
videoFramerate.setEnabled(videoState);
audioEncoder.setEnabled(settings.getBoolean("stream_audio", true));

videoEncoder.setValue(String.valueOf(mApplication.videoEncoder));
audioEncoder.setValue(String.valueOf(mApplication.audioEncoder));
Expand All @@ -80,6 +81,8 @@ protected void onCreate(Bundle savedInstanceState){
videoFramerate.setSummary(getString(R.string.settings1)+" "+videoFramerate.getValue()+"fps");
videoBitrate.setSummary(getString(R.string.settings2)+" "+videoBitrate.getValue()+"kbps");

audioEncoder.setEnabled(settings.getBoolean("stream_audio", false));

httpEnabled.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean state = (Boolean)newValue;
Expand All @@ -93,20 +96,20 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
editor.putBoolean(KEY_HTTPS_ENABLED, false);
} else {
// HTTP/HTTPS, it's one or the other
/**if (httpsEnabled.isChecked()) {
if (httpsEnabled.isChecked()) {
editor.putBoolean(KEY_HTTPS_ENABLED, true);
editor.putBoolean(KEY_HTTP_ENABLED, false);
} else {*/
} else {
editor.putBoolean(KEY_HTTPS_ENABLED, false);
editor.putBoolean(KEY_HTTP_ENABLED, true);
//}
}
}
editor.commit();
return true;
}
});

/*httpsEnabled.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
httpsEnabled.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean state = (Boolean)newValue;
Editor editor = settings.edit();
Expand All @@ -127,7 +130,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
editor.commit();
return true;
}
});*/
});

videoResolution.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Expand Down
16 changes: 1 addition & 15 deletions src/net/majorkernelpanic/spydroid/ui/SpydroidActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onCreate(Bundle savedInstanceState) {
((LinearLayout)findViewById(R.id.adcontainer)).removeAllViews();
}

// Prevents the phone to go to sleep mode
// Prevents the phone from going to sleep mode
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "net.majorkernelpanic.spydroid.wakelock");

Expand Down Expand Up @@ -233,20 +233,6 @@ private void quitSpydroid() {
// Returns to home menu
finish();
}

private SurfaceHolder.Callback mHolderCallback = new SurfaceHolder.Callback() {

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

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

};

private ServiceConnection mRtspServiceConnection = new ServiceConnection() {

Expand Down
12 changes: 6 additions & 6 deletions src/net/majorkernelpanic/streaming/SessionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ public class SessionBuilder {
public final static String TAG = "SessionBuilder";

/** Can be used with {@link #setVideoEncoder}. */
public final static int VIDEO_NONE = 0x00;
public final static int VIDEO_NONE = 0;

/** Can be used with {@link #setVideoEncoder}. */
public final static int VIDEO_H264 = 0x01;
public final static int VIDEO_H264 = 1;

/** Can be used with {@link #setVideoEncoder}. */
public final static int VIDEO_H263 = 0x02;
public final static int VIDEO_H263 = 2;

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_NONE = 0x00;
public final static int AUDIO_NONE = 0;

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AMRNB = 0x03;
public final static int AUDIO_AMRNB = 3;

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AAC = 0x05;
public final static int AUDIO_AAC = 5;

// Default configuration
private VideoQuality mVideoQuality = VideoQuality.defaultVideoQualiy.clone();
Expand Down
22 changes: 18 additions & 4 deletions src/net/majorkernelpanic/streaming/audio/AACStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import net.majorkernelpanic.streaming.exceptions.AACNotSupportedException;
import net.majorkernelpanic.streaming.rtp.AACADTSPacketizer;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.MediaRecorder;
Expand Down Expand Up @@ -76,27 +77,40 @@ public class AACStream extends AudioStream {
private int mProfile, mSamplingRateIndex, mChannel, mConfig;
private SharedPreferences mSettings = null;

@SuppressLint("InlinedApi")
public AACStream() throws IOException {
super();

mPacketizer = new AACADTSPacketizer();

setAudioSource(MediaRecorder.AudioSource.CAMCORDER);

if (!AACStreamingSupported()) {
Log.e(TAG,"AAC ADTS not supported on this phone");
throw new AACNotSupportedException();
}

try {
Field name = MediaRecorder.OutputFormat.class.getField("AAC_ADTS");
Log.d(TAG,"AAC ADTS seems to be supported: AAC_ADTS="+name.getInt(null));
setOutputFormat(name.getInt(null));
} catch (Exception e) {
Log.e(TAG,"AAC ADTS not supported on this phone");
throw new AACNotSupportedException();
}
catch (Exception ignore) {}

setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
setAudioSamplingRate(16000);

}

private static boolean AACStreamingSupported() {
if (Integer.parseInt(android.os.Build.VERSION.SDK)<14) return false;
try {
MediaRecorder.OutputFormat.class.getField("AAC_ADTS");
return true;
} catch (Exception e) {
return false;
}
}

/**
* Some data (the actual sampling rate) needs to be stored once {@link #generateSessionDescription()} is called.
* @param prefs The SharedPreferences that will be used to store the sampling rate
Expand Down
26 changes: 13 additions & 13 deletions src/net/majorkernelpanic/streaming/rtcp/SenderReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class SenderReport {
private byte[] buffer = new byte[MTU];
private int ssrc, port = -1;
private int octetCount = 0, packetCount = 0;
private long ntp = 0;

public SenderReport() throws IOException {

Expand Down Expand Up @@ -79,6 +78,17 @@ public void send() throws IOException {
usock.send(upack);
}

/** Sends the RTCP packet over the network. */
public void send(long ntpts, long rtpts) throws IOException {
long hb = ntpts/1000000000;
long lb = ( ( ntpts - hb*1000000000 ) * 4294967296L )/1000000000;
setLong(hb, 8, 12);
setLong(lb, 12, 16);
setLong(rtpts, 16, 20);
upack.setLength(28);
usock.send(upack);
}

/**
* Updates the number of packets sent, and the total amount of data sent.
* @param length The length of the packet
Expand All @@ -97,18 +107,8 @@ public void setRtpTimestamp(long ts) {

/** Sets the NTP timestamp of the sender report. */
public void setNtpTimestamp(long ts) {
ntp = ts;
long hb = ntp/1000000000;
long lb = ( ( ntp - hb*1000000000 ) * 4294967296L )/1000000000;
setLong(hb, 8, 12);
setLong(lb, 12, 16);
}

/** Updates the NTP timestamp of the sender report. */
public void updateNtpTimestamp(long delta) {
ntp += delta;
long hb = ntp/1000000000;
long lb = ( ( ntp - hb*1000000000 ) * 4294967296L )/1000000000;
long hb = ts/1000000000;
long lb = ( ( ts - hb*1000000000 ) * 4294967296L )/1000000000;
setLong(hb, 8, 12);
setLong(lb, 12, 16);
}
Expand Down
19 changes: 7 additions & 12 deletions src/net/majorkernelpanic/streaming/rtp/AACADTSPacketizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class AACADTSPacketizer extends AbstractPacketizer implements Runnable {

private Thread t;
private int samplingRate = 8000;
private Statistics stats = new Statistics();

public AACADTSPacketizer() throws IOException {
super();
Expand Down Expand Up @@ -79,10 +78,8 @@ public void run() {
// Adts header fields that we need to parse
boolean protection;
int frameLength, sum, length, nbau, nbpk;
long oldtime = System.nanoTime(), now = oldtime, delta = 5000, measured, lastmeasured = 5000, expected, interval = 0;
long oldtime = System.nanoTime(), now = oldtime, measured = 0, lastmeasured = 5000, expected = 0;

stats.init(1024*1000000000/samplingRate);

try {
while (!Thread.interrupted()) {

Expand Down Expand Up @@ -118,11 +115,11 @@ public void run() {
socket.updateTimestamp(ts);

// We send one RTCP Sender Report every 5 secs
if (delta>5000) {
delta = 0;
report.setNtpTimestamp(now);
report.setRtpTimestamp(ts);
report.send();
if (intervalBetweenReports>0) {
if (delta>=intervalBetweenReports) {
delta = 0;
report.send(now,ts);
}
}

sum = 0;
Expand Down Expand Up @@ -161,9 +158,7 @@ public void run() {

// We wait a little to avoid sending to many packets too quickly
now = System.nanoTime();
interval = now-oldtime;
measured = interval/1000000;
stats.push(interval);
measured = (now-oldtime)/1000000;
delta += measured;
oldtime = now;
expected = nbau*1024*1000 / (nbpk*samplingRate);
Expand Down
12 changes: 6 additions & 6 deletions src/net/majorkernelpanic/streaming/rtp/AMRNBPacketizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void stop() {

public void run() {

int frameLength, frameType, delta = 10000;
int frameLength, frameType;
long now = System.nanoTime(), oldtime = now, measured;
long expected = 20, lastmeasured = 10000, intervalNs = 0;

Expand Down Expand Up @@ -115,11 +115,11 @@ public void run() {
Thread.sleep( 2*expected/3-measured );
}

if (delta>5000) {
delta = 0;
report.setNtpTimestamp(now);
report.setRtpTimestamp(ts);
report.send();
if (intervalBetweenReports>0) {
if (delta>=intervalBetweenReports) {
delta = 0;
report.send(now,ts);
}
}

send(rtphl+1+AMR_FRAME_HEADER_LENGTH+frameLength);
Expand Down
Loading

0 comments on commit 76a76c0

Please sign in to comment.