Skip to content

Commit

Permalink
增加只推送音频的设置
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlong0813 committed May 11, 2017
1 parent a541bd3 commit 96bb4f9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Android/EasyRTMP/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.easydarwin.easyrtmp"
minSdkVersion 16
targetSdkVersion 22
versionCode 13
versionName "1.0.17.0504"
versionCode 6
versionName "1.0.17.0511"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AudioStream {
MediaCodec mMediaCodec;
Pusher easyPusher;
private Thread mThread = null;
String TAG = "EasyPusher";
String TAG = "AudioStream";
//final String path = Environment.getExternalStorageDirectory() + "/123450001.aac";

protected MediaCodec.BufferInfo mBufferInfo = new MediaCodec.BufferInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import java.io.InputStream;
import java.util.List;

/**
* Created by Helong on 16/4/16-12:54.
*/
public class EasyApplication extends Application {

private static EasyApplication mApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public void onClick(View v) {
}
});

CheckBox sendAudioOnly = (CheckBox) findViewById(R.id.enable_send_audio_only);
sendAudioOnly.setChecked(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_enable_send_audio_only", false));
sendAudioOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
PreferenceManager.getDefaultSharedPreferences(SettingActivity.this).edit().putBoolean("key_enable_send_audio_only", isChecked).apply();
}
});

CheckBox backgroundPushing = (CheckBox) findViewById(R.id.enable_background_camera_pushing);
backgroundPushing.setChecked(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_enable_background_camera", true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static class CODE {
* @param url RTMP服务器地址
* @param key 授权码
*/
public native long init(String url, String key, Context context, OnInitPusherCallback callback);
public native long init(String url, String key, Context context, OnInitPusherCallback callback, int fps);

/**
* 推送编码后的H264数据
Expand All @@ -75,14 +75,20 @@ public void initPush(String serverIP, String serverPort, String streamName, Cont
}

@Override
public synchronized void initPush(final String url, final Context context, final InitCallback callback) {
String key = "79397037795A36526D3430416E667059707756686B756876636D63755A57467A65575268636E64706269356C59584E35636E52746346634D5671442B6B75424859585A7062695A4359574A76633246414D6A41784E6B566863336C4559584A33615735555A5746745A57467A65513D3D";
public synchronized void initPush(final String url, final Context context, final InitCallback callback){
initPush(url, context, callback, 25);
}

@Override
public synchronized void initPush(final String url, final Context context, final InitCallback callback, int fps) {
String key = "79397037795A36526D34324171524E5A707578574A656876636D63755A57467A65575268636E64706269356C59584E35636E52746346634D5671442F7065424859585A7062695A4359574A76633246414D6A41784E6B566863336C4559584A33615735555A5746745A57467A65513D3D";
mPusherObj = init(url, key, context, new OnInitPusherCallback() {
@Override
public void onCallback(int code) {
if (callback != null)callback.onCallback(code);
}
});
},
fps);
}

public void push(byte[] data, long timestamp, int type){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public void initPush(String url, Context context, InitCallback callback) {
throw new RuntimeException("not support");
}

@Override
public void initPush(String url, Context context, InitCallback callback, int fps) {
throw new RuntimeException("not support");
}

public synchronized void push(byte[] data, int offset, int length, long timestamp, int type) {
if (mPusherObj == 0) return;
push(mPusherObj, data, offset, length, timestamp, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.easydarwin.audio.AudioStream;
import org.easydarwin.easypusher.BuildConfig;
import org.easydarwin.easypusher.EasyApplication;
import org.easydarwin.easypusher.R;
import org.easydarwin.easypusher.StreamActivity;
import org.easydarwin.easyrtmp.push.EasyRTMP;
import org.easydarwin.hw.EncoderDebugger;
import org.easydarwin.hw.NV21Convertor;
Expand Down Expand Up @@ -72,7 +74,10 @@ public MediaStream(Context context, SurfaceHolder holder) {
}

public void startStream(String url, InitCallback callback) {
mEasyPusher.initPush(url, mApplicationContext, callback);
if(PreferenceManager.getDefaultSharedPreferences(EasyApplication.getEasyApplication()).getBoolean("key_enable_send_audio_only", false))
mEasyPusher.initPush(url, mApplicationContext, callback, ~0);
else
mEasyPusher.initPush(url, mApplicationContext, callback);
pushStream = true;
}

Expand Down Expand Up @@ -242,7 +247,7 @@ public void run() {
}
if (PreferenceManager.getDefaultSharedPreferences(mApplicationContext).getBoolean("key_enable_video_overlay", false)) {
String txt = String.format("drawtext=fontfile=" + mApplicationContext.getFileStreamPath("SIMYOU.ttf") + ": text='%s%s':x=(w-text_w)/2:y=H-60 :fontcolor=white :box=1:boxcolor=0x00000000@0.3", "EasyPusher", new SimpleDateFormat("yyyy-MM-ddHHmmss").format(new Date()));
txt = "EasyPusher " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
txt = EasyApplication.getEasyApplication().getString(R.string.app_name) + " " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
overlay.overlay(data, txt);
}
int r = 0;
Expand Down Expand Up @@ -480,6 +485,12 @@ public void onPreviewFrame(byte[] data, Camera camera) {
mCamera.addCallbackBuffer(data);
return;
}

if(PreferenceManager.getDefaultSharedPreferences(EasyApplication.getEasyApplication()).getBoolean("key_enable_send_audio_only", false)){
mCamera.addCallbackBuffer(data);
return;
}

Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
if (data.length != previewSize.width * previewSize.height * 3 / 2) {
mCamera.addCallbackBuffer(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface Pusher {
public void stop() ;

public void initPush(final String serverIP, final String serverPort, final String streamName, final Context context, final InitCallback callback);
public void initPush(final String url, final Context context, final InitCallback callback, int pts);
public void initPush(final String url, final Context context, final InitCallback callback);

public void push(byte[] data, int offset, int length, long timestamp, int type);
Expand Down
9 changes: 9 additions & 0 deletions Android/EasyRTMP/app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
android:id="@+id/rtmp_url"
android:layout_height="wrap_content" />

<CheckBox
android:id="@+id/enable_send_audio_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="只推送音频" />

<CheckBox
android:id="@+id/enable_background_camera_pushing"
android:layout_width="match_parent"
Expand Down
Binary file not shown.
Binary file modified Android/EasyRTMP/app/src/rtmp/jniLibs/armeabi-v7a/libeasyrtmp.so
Binary file not shown.

0 comments on commit 96bb4f9

Please sign in to comment.