Skip to content

Commit

Permalink
chore: modify code comment & add LICENSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
hide committed Jun 15, 2021
1 parent 85072ac commit 4b6cecb
Show file tree
Hide file tree
Showing 8 changed files with 868 additions and 20 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions LINCENSE_CN

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

- [x] 1. encode with x264.
- [x] 2. push into RTMP server.
- [ ] 3. encode with openh264.
- [ ] 4. echo cancellation in software. Maybe need libspeex, currently has a scheme which is hardware scheme in **VOICE_COMMUNICATION**.
- [x] 3. encode with openh264.
- [ ] 4. echo cancellation in software. Maybe need libspeex.


## Building & Testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by wei on 16-11-27.
* Created by bruce on 16-11-27.
*
* It is used to manager picture to be encode, and transfer encoded data to server in {@link ExecutorService}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.brucewind.softcodec;

/**
* Created by wei on 16-11-24.
* Created by bruce on 16-11-24.
* It is used to connect server and push stream.
*/
class StreamHelper {
Expand All @@ -21,12 +21,12 @@ class StreamHelper {
/**
* x264 function
* @param encoder
* @param NV12
* @param NV12size
* @param H264
* @param I420
* @param I420Size
* @param H264, it is unused.
* @return
*/
public native int compressBuffer(long encoder, byte[] NV12, int NV12size, byte[] H264);
public native int compressBuffer(long encoder, byte[] I420, int I420Size, byte[] H264);

public native long compressBegin(int width, int height, int bitrate, int fps);

Expand Down
21 changes: 11 additions & 10 deletions openh264-codec/src/main/jni/softcodec/h264Encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ int handle_sps_pps(int NAL_type, unsigned char *buffer, int len) {
ALOGE("buffer format is wrong.");
return -1;
}
if (NAL_type == 7) {
if (NAL_type == NAL_SPS) {
sps = buffer;
sps_len = len;
print_hex("SPS", sps, sps_len);
} else if (NAL_type == 8) {
} else if (NAL_type == NAL_PPS) {
pps = buffer;
pps_len = len;
send_video_sps_pps(sps, sps_len, pps, pps_len);
Expand Down Expand Up @@ -63,16 +63,16 @@ Java_io_github_brucewind_softcodec_StreamHelper_compressBegin(JNIEnv *env,
encoder->GetDefaultParams(
&param);//call InitializeExt must have a extension parameter with this default.
param.iUsageType = CAMERA_VIDEO_REAL_TIME; //tell openH264 steam type is LIVE.
param.iRCMode = RC_QUALITY_MODE;
param.iRCMode = RC_BITRATE_MODE;
param.fMaxFrameRate = fps; //fps
param.iPicWidth = width;
param.iPicHeight = height;
param.iTargetBitrate = bitrate * 1024; //the input parameter need to * 1024
// param.iInputCsp = videoFormatI420; //it is stable YUV format for openh264
param.bEnableDenoise = 1; //enable eliminating noisy.
// param.bEnableDenoise = 1; //enable eliminating noisy.
param.iSpatialLayerNum = 1;
//if (sliceMode != SM_SINGLE_SLICE && sliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now
// param.iMultipleThreadIdc = 2;
param.iMultipleThreadIdc = 2;
for (int i = 0; i < param.iSpatialLayerNum; i++) {
param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i);
param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i);
Expand Down Expand Up @@ -199,7 +199,7 @@ extern "C" JNIEXPORT jint Java_io_github_brucewind_softcodec_StreamHelper_compr
ALOGW("skip this frame");
return 0;
} else {
ALOGD("foreach NAL type : %d., laytype is %d.", info.sLayerInfo[i].eFrameType,
ALOGD("FrameType : %d, layertype: %d.", info.sLayerInfo[i].eFrameType,
info.sLayerInfo[i].uiLayerType);
}

Expand All @@ -209,9 +209,8 @@ extern "C" JNIEXPORT jint Java_io_github_brucewind_softcodec_StreamHelper_compr
* transmit serveral NALUs to RTMP server.
* Two NAL types : SPS & PPS are very important.
*/
for (i = 0; i < info.iLayerNum; i++) {//iLayerNum is the count of NALUs.
// int type = info.sLayerInfo[i].eFrameType;//it is NON_VIDEO_CODING_LAYER
//
for (i = 0; i < info.iLayerNum; i++) {
// int fType = info.sLayerInfo[i].eFrameType;//it is NON_VIDEO_CODING_LAYER
// if (info.sLayerInfo[i].uiLayerType == NON_VIDEO_CODING_LAYER) {//this NAL type is SPS.
// }
const SLayerBSInfo layerInfo = info.sLayerInfo[i];
Expand All @@ -236,7 +235,9 @@ extern "C" JNIEXPORT jint Java_io_github_brucewind_softcodec_StreamHelper_compr
ALOGE("start code not found.");
}
}
if (NAL_type == 7 || NAL_type == 8) {
ALOGD("NAL type : %d.",NAL_type);
//begin to handle one of NALs.
if (NAL_type == NAL_SPS || NAL_type == NAL_PPS) {
buffer += start_len;
handle_sps_pps(NAL_type, buffer, buf_len - start_len);
buffer+=(buf_len - start_len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by wei on 16-11-27.
* Created by bruce on 16-11-27.
*
* It is used to manager picture to be encode, and transfer encoded data to server in {@link ExecutorService}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.brucewind.softcodec;

/**
* Created by wei on 16-11-24.
* Created by bruce on 16-11-24.
* It is used to connect server and push stream.
*/
class StreamHelper {
Expand Down

0 comments on commit 4b6cecb

Please sign in to comment.