Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to v4.2.4-10883 #194

Merged
merged 1 commit into from
Jun 29, 2017
Merged
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
Binary file removed demo/assets/KSYResource/0_skinColor.png
Binary file not shown.
Binary file added demo/assets/KSYResource/10_sunshine_night.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 demo/assets/KSYResource/11_ruddy.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 demo/assets/KSYResource/12_sunshine.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 demo/assets/KSYResource/7_sakura.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 demo/assets/KSYResource/8_sakura_night.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 demo/assets/KSYResource/9_ruddy_night.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 demo/assets/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/libs/arm64-v8a/libksylive.so
Binary file not shown.
Binary file modified demo/libs/armeabi-v7a/libksylive.so
Binary file not shown.
Binary file modified demo/libs/armeabi/libksylive.so
Binary file not shown.
Binary file modified demo/libs/ksylive.jar
Binary file not shown.
Binary file modified demo/libs/libksyplayer.jar
Binary file not shown.
Binary file modified demo/libs/x86/libksylive.so
Binary file not shown.
6 changes: 6 additions & 0 deletions demo/res/layout/camera_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true" />

<com.lht.paintview.PaintView
android:id="@+id/view_paint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>

<include
android:id="@+id/actionbar"
android:layout_width="match_parent"
Expand Down
28 changes: 28 additions & 0 deletions demo/res/layout/camera_bottombar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@
android:textSize="@dimen/font_size_28px">
</TextView>

<CheckBox
android:id="@+id/paint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#11123456"
android:checked="false"
android:text="手绘"
android:textColor="@color/font_color_35"
android:textSize="@dimen/font_size_28px">
</CheckBox>

<CheckBox
android:id="@+id/bg_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#11123456"
android:checked="false"
android:text="背景图推流"
android:textColor="@color/font_color_35"
android:textSize="@dimen/font_size_28px">
</CheckBox>

</LinearLayout>

<LinearLayout
Expand Down
139 changes: 116 additions & 23 deletions demo/src/com/ksyun/media/streamer/demo/CameraActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import com.ksyun.media.player.IMediaPlayer;
import com.ksyun.media.streamer.capture.CameraCapture;
import com.ksyun.media.streamer.capture.ViewCapture;
import com.ksyun.media.streamer.capture.camera.CameraTouchHelper;
import com.ksyun.media.streamer.filter.audio.AudioFilterBase;
import com.ksyun.media.streamer.filter.audio.AudioReverbFilter;
Expand All @@ -57,6 +58,7 @@
import com.ksyun.media.streamer.kit.StreamerConstants;
import com.ksyun.media.streamer.logstats.StatsLogReport;
import com.ksyun.media.streamer.util.gles.GLRender;
import com.lht.paintview.PaintView;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -84,6 +86,7 @@ public class CameraActivity extends Activity implements
private GLSurfaceView mCameraPreviewView;
//private TextureView mCameraPreviewView;
private CameraHintView mCameraHintView;
private PaintView mPaintView;
private Chronometer mChronometer;
private View mDeleteView;
private View mSwitchCameraView;
Expand All @@ -104,6 +107,8 @@ public class CameraActivity extends Activity implements
private CheckBox mFrontMirrorCheckBox;
private TextView mUrlTextView;
private TextView mDebugInfoTextView;
private CheckBox mPaintCheckBox;
private CheckBox mBgImageCheckBox;

private View mBeautyChooseView;
private AppCompatSpinner mBeautySpinner;
Expand All @@ -123,6 +128,7 @@ public class CameraActivity extends Activity implements
private ButtonObserver mObserverButton;
private CheckBoxObserver mCheckBoxObserver;

private ViewCapture mPaintViewCapture;
private KSYStreamer mStreamer;
private Handler mMainHandler;
private Timer mTimer;
Expand All @@ -137,6 +143,7 @@ public class CameraActivity extends Activity implements
private String mDebugInfo = "";
private String mBgmPath = "/sdcard/test.mp3";
private String mLogoPath = "file:///sdcard/test.png";
private String mBgImagePath = "assets://bg.jpg";
private String mRecordUrl = "/sdcard/rec_test.mp4";

private boolean mHWEncoderUnsupported;
Expand Down Expand Up @@ -210,6 +217,7 @@ protected void onCreate(Bundle savedInstanceState) {
mUrlTextView = (TextView) findViewById(R.id.url);
mChronometer = (Chronometer) findViewById(R.id.chronometer);
mDebugInfoTextView = (TextView) findViewById(R.id.debuginfo);
mPaintView = (PaintView) findViewById(R.id.view_paint);

mObserverButton = new ButtonObserver();
mShootingText = (TextView) findViewById(R.id.click_to_shoot);
Expand Down Expand Up @@ -248,6 +256,10 @@ protected void onCreate(Bundle savedInstanceState) {
mAudioOnlyCheckBox.setOnCheckedChangeListener(mCheckBoxObserver);
mAudioLDCheckBox = (CheckBox) findViewById(R.id.audio_ld);
mAudioLDCheckBox.setOnCheckedChangeListener(mCheckBoxObserver);
mPaintCheckBox = (CheckBox) findViewById(R.id.paint);
mPaintCheckBox.setOnCheckedChangeListener(mCheckBoxObserver);
mBgImageCheckBox = (CheckBox) findViewById(R.id.bg_image);
mBgImageCheckBox.setOnCheckedChangeListener(mCheckBoxObserver);

mBeautyChooseView = findViewById(R.id.beauty_choose);
mBeautySpinner = (AppCompatSpinner) findViewById(R.id.beauty_spin);
Expand Down Expand Up @@ -328,8 +340,8 @@ public void onOrientationChanged(int orientation) {
Log.d(TAG, "Rotation changed " + mLastRotation + "->" + rotation);
mIsLandscape = (rotation % 180) != 0;
mStreamer.setRotateDegrees(rotation);
hideWaterMark();
if (mWaterMarkCheckBox.isChecked()) {
hideWaterMark();
showWaterMark();
}
mLastRotation = rotation;
Expand Down Expand Up @@ -393,19 +405,16 @@ public void onError(ImgTexFilterBase filter, int errno) {
// set CameraHintView to show focus rect and zoom ratio
cameraTouchHelper.setCameraHintView(mCameraHintView);

startCameraPreviewWithPermCheck();
startCameraPreviewWithPermCheck(true);
if (mWaterMarkCheckBox.isChecked()) {
showWaterMark();
}
if (mAutoStart) {
startStream();
}
}

private void initBeautyUI() {
String[] items = new String[]{"DISABLE", "BEAUTY_SOFT", "SKIN_WHITEN", "BEAUTY_ILLUSION",
"BEAUTY_DENOISE", "BEAUTY_SMOOTH", "BEAUTY_PRO", "DEMO_FILTER", "GROUP_FILTER",
"ToneCurve", "复古", "胶片"};
"BEAUTY_DENOISE", "BEAUTY_SMOOTH", "BEAUTY_PRO", "BEAUTY_PRO2", "BEAUTY_PRO3",
"BEAUTY_PRO4", "DEMO_FILTER", "GROUP_FILTER", "ToneCurve", "复古", "胶片"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Expand All @@ -426,9 +435,18 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
mStreamer.getImgTexFilterMgt().setFilter(mStreamer.getGLRender(),
ImgTexFilterMgt.KSY_FILTER_BEAUTY_PRO);
} else if (position == 7) {
mStreamer.getImgTexFilterMgt().setFilter(mStreamer.getGLRender(),
ImgTexFilterMgt.KSY_FILTER_BEAUTY_PRO2);
} else if (position == 8) {
mStreamer.getImgTexFilterMgt().setFilter(mStreamer.getGLRender(),
ImgTexFilterMgt.KSY_FILTER_BEAUTY_PRO3);
} else if (position == 9) {
mStreamer.getImgTexFilterMgt().setFilter(mStreamer.getGLRender(),
ImgTexFilterMgt.KSY_FILTER_BEAUTY_PRO4);
} else if (position == 10) {
mStreamer.getImgTexFilterMgt().setFilter(
new DemoFilter(mStreamer.getGLRender()));
} else if (position == 8) {
} else if (position == 11) {
List<ImgFilterBase> groupFilter = new LinkedList<>();
groupFilter.add(new DemoFilter2(mStreamer.getGLRender()));
groupFilter.add(new DemoFilter3(mStreamer.getGLRender()));
Expand All @@ -437,19 +455,19 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
CameraActivity.this,
ImgBeautySpecialEffectsFilter.KSY_SPECIAL_EFFECT_BLUE));
mStreamer.getImgTexFilterMgt().setFilter(groupFilter);
} else if (position == 9) {
} else if (position == 12) {
ImgBeautyToneCurveFilter acvFilter = new ImgBeautyToneCurveFilter(mStreamer.getGLRender());
acvFilter.setFromCurveFileInputStream(
CameraActivity.this.getResources().openRawResource(R.raw.tone_cuver_sample));

mStreamer.getImgTexFilterMgt().setFilter(acvFilter);
} else if (position == 10) {
} else if (position == 13) {
ImgBeautyToneCurveFilter acvFilter = new ImgBeautyToneCurveFilter(mStreamer.getGLRender());
acvFilter.setFromCurveFileInputStream(
CameraActivity.this.getResources().openRawResource(R.raw.fugu));

mStreamer.getImgTexFilterMgt().setFilter(acvFilter);
} else if (position == 11) {
} else if (position == 14) {
ImgBeautyToneCurveFilter acvFilter = new ImgBeautyToneCurveFilter(mStreamer.getGLRender());
acvFilter.setFromCurveFileInputStream(
CameraActivity.this.getResources().openRawResource(R.raw.jiaopian));
Expand Down Expand Up @@ -532,8 +550,10 @@ public void onResume() {
mStreamer.onResume();
mCameraHintView.hideAll();

// camera may be occupied by other app in background
startCameraPreviewWithPermCheck();
if (!mBgImageCheckBox.isChecked()) {
// camera may be occupied by other app in background
startCameraPreviewWithPermCheck(false);
}

// re-enable audio low delay in foreground
if (mAudioLDCheckBox.isChecked()) {
Expand All @@ -558,6 +578,8 @@ public void onPause() {
@Override
public void onDestroy() {
super.onDestroy();
// stop paint view capture if needed
stopPaintViewCapture();
if (mMainHandler != null) {
mMainHandler.removeCallbacksAndMessages(null);
mMainHandler = null;
Expand Down Expand Up @@ -629,6 +651,7 @@ private void stopChronometer() {
}

private void stopStream() {
// stop stream
mStreamer.stopStream();
mShootingText.setText(START_STRING);
mShootingText.postInvalidate();
Expand Down Expand Up @@ -1070,14 +1093,7 @@ public boolean onError(IMediaPlayer iMediaPlayer, int what, int extra) {
}

private void onAudioPreviewChecked(boolean isChecked) {
if(isChecked != mStreamer.isAudioPreviewing()) {
// 若没有插入耳机,该接口会设置失败,因此设置完毕后需要判断一下,进行状态复归
mStreamer.setEnableAudioPreview(isChecked);
if (isChecked != mStreamer.isAudioPreviewing()) {
Toast.makeText(this, "设置耳返失败,您需要插入耳机", Toast.LENGTH_SHORT).show();
mAudioPreviewCheckBox.setChecked(mStreamer.isAudioPreviewing());
}
}
mStreamer.setEnableAudioPreview(isChecked);
}

private void onMuteChecked(boolean isChecked) {
Expand All @@ -1103,6 +1119,69 @@ private void onAudioLDChecked(boolean isChecked) {
mStreamer.setEnableAudioLowDelay(isChecked);
}

private void onPaintChecked(boolean isChecked) {
if (isChecked) {
// config paint view
mPaintView.setVisibility(View.VISIBLE);
mPaintView.setColor(Color.RED);
mPaintView.setBgColor(Color.TRANSPARENT);
mPaintView.setStrokeWidth(4);
mPaintView.setGestureEnable(false);

if (mPaintViewCapture == null) {
mPaintViewCapture = new ViewCapture(mStreamer.getGLRender());
// connect to the empty last sink pin of graph mixer
mPaintViewCapture.getSrcPin().connect(mStreamer.getImgTexMixer().getSinkPin(7));
// set render position relative to the video
mStreamer.getImgTexMixer().setRenderRect(7, 0, 0, 1, 1, 1);

// restart PaintViewCapture while view layout changed
mPaintView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
int oldW = oldRight - oldLeft;
int oldH = oldBottom - oldTop;
if (mPaintCheckBox.isChecked() && (oldW * oldH != 0)) {
stopPaintViewCapture();
startPaintViewCapture();
}
}
});
}
startPaintViewCapture();
} else {
stopPaintViewCapture();
mPaintView.clear();
mPaintView.setVisibility(View.GONE);
}
}

private void onBgImageChecked(boolean isChecked) {
if (isChecked) {
mStreamer.stopCameraPreview();
mStreamer.startImageCapture(mBgImagePath);
} else {
mStreamer.stopImageCapture();
mStreamer.startCameraPreview();
}
}

private void startPaintViewCapture() {
if (mPaintViewCapture != null) {
mPaintViewCapture.setTargetResolution(mStreamer.getTargetWidth(),
mStreamer.getTargetHeight());
mPaintViewCapture.setUpdateFps(mStreamer.getTargetFps());
mPaintViewCapture.start(mPaintView);
}
}

private void stopPaintViewCapture() {
if (mPaintViewCapture != null) {
mPaintViewCapture.stop();
}
}

private void onCaptureScreenShotClick() {
mStreamer.requestScreenShot(new GLRender.ScreenShotListener() {
@Override
Expand Down Expand Up @@ -1202,18 +1281,24 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
case R.id.audio_ld:
onAudioLDChecked(isChecked);
break;
case R.id.paint:
onPaintChecked(isChecked);
break;
case R.id.bg_image:
onBgImageChecked(isChecked);
break;
default:
break;
}
}
}

private void startCameraPreviewWithPermCheck() {
private void startCameraPreviewWithPermCheck(boolean request) {
int cameraPerm = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
int audioPerm = ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
if (cameraPerm != PackageManager.PERMISSION_GRANTED ||
audioPerm != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !request) {
Log.e(TAG, "No CAMERA or AudioRecord permission, please check");
Toast.makeText(this, "No CAMERA or AudioRecord permission, please check",
Toast.LENGTH_LONG).show();
Expand All @@ -1226,6 +1311,10 @@ private void startCameraPreviewWithPermCheck() {
}
} else {
mStreamer.startCameraPreview();
if (mAutoStart) {
mAutoStart = false;
startStream();
}
}
}

Expand All @@ -1238,6 +1327,10 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String permissi
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mStreamer.startCameraPreview();
if (mAutoStart) {
mAutoStart = false;
startStream();
}
} else {
Log.e(TAG, "No CAMERA or AudioRecord permission");
Toast.makeText(this, "No CAMERA or AudioRecord permission",
Expand Down
6 changes: 5 additions & 1 deletion demo/src/com/ksyun/media/streamer/demo/DemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ private void setEnableRadioGroup(RadioGroup radioGroup, boolean enable) {
private void updateUI() {
if (mHWButton.isChecked() || mEncodeWithH265.isChecked()) {
setEnableRadioGroup(mSceneGroup, false);
setEnableRadioGroup(mProfileGroup, false);
if (mEncodeWithH265.isChecked()) {
setEnableRadioGroup(mProfileGroup, false);
} else {
setEnableRadioGroup(mProfileGroup, true);
}
} else {
setEnableRadioGroup(mSceneGroup, true);
setEnableRadioGroup(mProfileGroup, true);
Expand Down
Loading