Skip to content

Commit

Permalink
Merge pull request #1 from begeekmyfriend/master
Browse files Browse the repository at this point in the history
2019 update
  • Loading branch information
TommyTeaVee authored Jun 28, 2019
2 parents 9136499 + f5fcc76 commit 720e5bb
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 48 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ Yet Another Stream Encoder for Android
**Yasea** is an Android streaming client. It encodes YUV and PCM data from
camera and microphone to H.264/AAC, encapsulates in FLV and transmits over RTMP.

Branch
------

[non-gpuimage](https://github.com/begeekmyfriend/yasea/tree/non-gpuimage) for Android without GL ES library like development board.

[android-16](https://github.com/begeekmyfriend/yasea/tree/android-16) for Android API 16+.

[aac-hev2](https://github.com/begeekmyfriend/yasea/tree/aac-hev2) for Youtube live broadcast that is not compatible with conventional flash media players.

Feature
-------

- [x] Android mini API 16.
- [x] Android mini API 21.
- [x] H.264/AAC hard encoding.
- [x] H.264 soft encoding.
- [x] RTMP streaming with state callback handler.
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "net.ossrs.yasea.demo"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "2.6"
ndk {
abiFilters "armeabi-v7a", "x86"
abiFilters "armeabi-v7a", "arm64-v8a", "x86"
}
}
buildTypes {
Expand All @@ -25,6 +25,6 @@ android {
dependencies {
compile fileTree(dir: 'libx264.libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:26.1.0'
compile project(path: ':library')
}
42 changes: 39 additions & 3 deletions app/src/main/java/net/ossrs/yasea/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
private Button btnSwitchCamera;
private Button btnRecord;
private Button btnSwitchEncoder;
private Button btnPause;

private SharedPreferences sp;
private String rtmpUrl = "rtmp://ossrs.net/" + getRandomAlphaString(3) + '/' + getRandomAlphaDigitString(5);
Expand Down Expand Up @@ -66,15 +67,27 @@ protected void onCreate(Bundle savedInstanceState) {
btnSwitchCamera = (Button) findViewById(R.id.swCam);
btnRecord = (Button) findViewById(R.id.record);
btnSwitchEncoder = (Button) findViewById(R.id.swEnc);

mPublisher = new SrsPublisher((SrsCameraView) findViewById(R.id.glsurfaceview_camera));
btnPause = (Button) findViewById(R.id.pause);
btnPause.setEnabled(false);
mCameraView = (SrsCameraView) findViewById(R.id.glsurfaceview_camera);

mPublisher = new SrsPublisher(mCameraView);
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
mPublisher.setRtmpHandler(new RtmpHandler(this));
mPublisher.setRecordHandler(new SrsRecordHandler(this));
mPublisher.setPreviewResolution(640, 360);
mPublisher.setOutputResolution(360, 640);
mPublisher.setVideoHDMode();
mPublisher.startCamera();

mCameraView.setCameraCallbacksHandler(new SrsCameraView.CameraCallbacksHandler(){
@Override
public void onCameraParameters(Camera.Parameters params) {
//params.setFocusMode("custom-focus");
//params.setWhiteBalance("custom-balance");
//etc...
}
});

btnPublish.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -95,20 +108,34 @@ public void onClick(View v) {
}
btnPublish.setText("stop");
btnSwitchEncoder.setEnabled(false);
btnPause.setEnabled(true);
} else if (btnPublish.getText().toString().contentEquals("stop")) {
mPublisher.stopPublish();
mPublisher.stopRecord();
btnPublish.setText("publish");
btnRecord.setText("record");
btnSwitchEncoder.setEnabled(true);
btnPause.setEnabled(false);
}
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(btnPause.getText().toString().equals("Pause")){
mPublisher.pausePublish();
btnPause.setText("resume");
}else{
mPublisher.resumePublish();
btnPause.setText("Pause");
}
}
});

btnSwitchCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPublisher.switchCameraFace((mPublisher.getCamraId() + 1) % Camera.getNumberOfCameras());
mPublisher.switchCameraFace((mPublisher.getCameraId() + 1) % Camera.getNumberOfCameras());
}
});

Expand Down Expand Up @@ -215,6 +242,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
protected void onStart() {
super.onStart();
if(mPublisher.getCamera() == null){
//if the camera was busy and available again
mPublisher.startCamera();
}
}

@Override
protected void onResume() {
super.onResume();
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:id="@+id/pause"
android:layout_above="@+id/publish"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "2.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "x86"
abiFilters "armeabi-v7a", "arm64-v8a", "x86"
}
}
buildTypes {
Expand All @@ -33,6 +33,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:26.1.0'
testCompile 'junit:junit:4.12'
}
4 changes: 2 additions & 2 deletions library/src/main/cpp/Application.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-19
APP_ABI := armeabi-v7a arm64-v8a x86
APP_PLATFORM := android-21
2 changes: 0 additions & 2 deletions library/src/main/cpp/libenc/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ LOCAL_CFLAGS :=
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libyuv/include $(LOCAL_PATH)/../libx264
LOCAL_STATIC_LIBRARIES := libx264
LOCAL_SHARED_LIBRARIES := libyuv
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true

include $(BUILD_SHARED_LIBRARY)
4 changes: 4 additions & 0 deletions library/src/main/cpp/libx264/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_SRC_FILES := libs/armeabi-v7a/libx264.a
endif

ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
LOCAL_SRC_FILES := libs/arm64-v8a/libx264.a
endif

ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_SRC_FILES := libs/x86/libx264.a
endif
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/cpp/libx264/android_build_armeabi_v7a.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

ANDROID_NDK=$HOME/Android/Sdk/ndk-bundle
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-arm
SYSROOT=$ANDROID_NDK/platforms/android-21/arch-arm
CROSS_PREFIX=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon -D__ANDROID__ -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__"
EXTRA_LDFLAGS="-nostdlib"
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/cpp/libx264/android_build_x86.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

ANDROID_NDK=$HOME/Android/Sdk/ndk-bundle
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-x86
SYSROOT=$ANDROID_NDK/platforms/android-21/arch-x86
CROSS_PREFIX=$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
EXTRA_CFLAGS="-D__ANDROID__ -D__i686__"
EXTRA_LDFLAGS="-nostdlib"
Expand Down
Binary file not shown.
Binary file modified library/src/main/cpp/libx264/libs/armeabi-v7a/libx264.a
Binary file not shown.
Binary file modified library/src/main/cpp/libx264/libs/x86/libx264.a
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void handshake(InputStream in, OutputStream out) throws IOException {
handshake.readS0(in);
handshake.readS1(in);
handshake.writeC2(out);
out.flush();
handshake.readS2(in);
}

Expand Down Expand Up @@ -525,9 +526,7 @@ private void handleRxPacketLoop() throws IOException {
UserControl user = (UserControl) rtmpPacket;
switch (user.getType()) {
case STREAM_BEGIN:
if (currentStreamId != user.getFirstEventData()) {
mHandler.notifyRtmpIllegalStateException(new IllegalStateException("Current stream ID error!"));
}
Log.d(TAG, "handleRxPacketLoop(): Receive STREAM_BEGIN");
break;
case PING_REQUEST:
ChunkStreamInfo channelInfo = rtmpSessionInfo.getChunkStreamInfo(ChunkStreamInfo.RTMP_CID_PROTOCOL_CONTROL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public final void readS1(InputStream in) throws IOException {

/** Generates and writes the third handshake packet (C2) */
public final void writeC2(OutputStream out) throws IOException {
Log.d(TAG, "readC2");
Log.d(TAG, "writeC2");
// C2 is an echo of S1
if (s1 == null) {
throw new IllegalStateException("C2 cannot be written without S1 being read first");
Expand Down
Loading

0 comments on commit 720e5bb

Please sign in to comment.