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
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# doc
1 change: 1 addition & 0 deletions livestream-to-earn-android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions livestream-to-earn-android/app/broadcaster/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions livestream-to-earn-android/app/broadcaster/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "25.0.1"

defaultConfig {
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'net.butterflytv.utils:rtmp-client:3.1.0'
implementation 'com.android.support:support-annotations:25.3.1'
implementation 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
Empty file.
17 changes: 17 additions & 0 deletions livestream-to-earn-android/app/broadcaster/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/mekya/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.psudoanon.broadcaster

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.psudoanon.broadcaster.test", appContext.packageName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.psudoanon.broadcaster">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.psudoanon.broadcaster;

import android.media.AudioFormat;
import android.media.MediaRecorder;
import android.os.Message;
import android.util.Log;

import com.psudoanon.broadcaster.encoder.AudioHandler;

/**
* Created by mekya on 28/03/2017.
*/

class AudioRecorderThread extends Thread {

private static final String TAG = AudioRecorderThread.class.getSimpleName();
private final int mSampleRate;
private final long startTime;
private volatile boolean stopThread = false;

private android.media.AudioRecord audioRecord;
private AudioHandler audioHandler;

public AudioRecorderThread(int sampleRate, long recordStartTime, AudioHandler audioHandler) {
this.mSampleRate = sampleRate;
this.startTime = recordStartTime;
this.audioHandler = audioHandler;
}


@Override
public void run() {
//Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);

int bufferSize = android.media.AudioRecord
.getMinBufferSize(mSampleRate,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
byte[][] audioData;
int bufferReadResult;

audioRecord = new android.media.AudioRecord(MediaRecorder.AudioSource.MIC,
mSampleRate, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize);

// divide byte buffersize to 2 to make it short buffer
audioData = new byte[1000][bufferSize];

audioRecord.startRecording();

int i = 0;
byte[] data;
while ((bufferReadResult = audioRecord.read(audioData[i], 0, audioData[i].length)) > 0) {

data = audioData[i];

Message msg = Message.obtain(audioHandler, AudioHandler.RECORD_AUDIO, data);
msg.arg1 = bufferReadResult;
msg.arg2 = (int)(System.currentTimeMillis() - startTime);
audioHandler.sendMessage(msg);


i++;
if (i == 1000) {
i = 0;
}
if (stopThread) {
break;
}
}

Log.d(TAG, "AudioThread Finished, release audioRecord");

}

public void stopAudioRecording() {

if (audioRecord != null && audioRecord.getRecordingState() == android.media.AudioRecord.RECORDSTATE_RECORDING) {
stopThread = true;
audioRecord.stop();
audioRecord.release();
audioRecord = null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.psudoanon.broadcaster;

/**
* Created by faraklit on 17.02.2016.
*/

import android.graphics.SurfaceTexture;
import android.os.Handler;
import android.os.Message;
import android.util.Log;


import java.lang.ref.WeakReference;

/**
* Handles camera operation requests from other threads. Necessary because the Camera
* must only be accessed from one thread.
* <p>
* The object is created on the UI thread, and all handlers run there. Messages are
* sent from other threads, using sendMessage().
*/
public class CameraHandler extends Handler {
private static final String TAG = CameraHandler.class.getSimpleName();

public static final int MSG_SET_SURFACE_TEXTURE = 0;


public interface ICameraViewer {

void handleSetSurfaceTexture(SurfaceTexture st);
}


// Weak reference to the Activity; only access this from the UI thread.
private WeakReference<ICameraViewer> cameraViewerWeakReference;

public CameraHandler(ICameraViewer cameraViewer) {
cameraViewerWeakReference = new WeakReference<ICameraViewer>(cameraViewer);
}

/**
* Drop the reference to the activity. Useful as a paranoid measure to ensure that
* attempts to access a stale Activity through a handler are caught.
*/
public void invalidateHandler() {
cameraViewerWeakReference.clear();
}

@Override // runs on UI thread
public void handleMessage(Message inputMessage) {
int what = inputMessage.what;
Log.d(TAG, "CameraHandler [" + this + "]: what=" + what);

ICameraViewer cameraViewer = cameraViewerWeakReference.get();
if (cameraViewer == null) {
Log.w(TAG, "CameraHandler.handleMessage: cameraViewer is null");
return;
}

switch (what) {
case MSG_SET_SURFACE_TEXTURE:
cameraViewer.handleSetSurfaceTexture((SurfaceTexture) inputMessage.obj);
break;
default:
throw new RuntimeException("unknown msg " + what);
}
}
}
Loading