Skip to content

Commit d146eb1

Browse files
author
zhaoyongqiang
committed
Merge branch 'dev/4.0.1' of github.com:AgoraIO/API-Examples into dev/4.0.1
2 parents 3f6d8bc + 08fffd8 commit d146eb1

13 files changed

Lines changed: 843 additions & 195 deletions

File tree

.github/ci/build/build_android.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ rm ./$unzip_name/commits
6767
rm ./$unzip_name/package_size_report.txt
6868
mkdir ./$unzip_name/samples
6969
mkdir ./$unzip_name/samples/API-example
70-
cp -rf ./Android/APIExample/** ./$unzip_name/samples/API-example
70+
71+
cp -rf ./Android/APIExample$(echo $sdk_url | cut -d "/" -f 9 | grep audio_only | cut -d "_" -f 1 | sed -e 's/a/-A/g')/** ./$unzip_name/samples/API-example
72+
7173
7za a -tzip result.zip -r $unzip_name
7274
cp result.zip $WORKSPACE/withAPIExample_$zip_name

.github/ci/build/build_ios.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,18 @@ rm ./$unzip_name/package_size_report.txt
6565
mkdir ./$unzip_name/samples
6666
mkdir ./$unzip_name/samples/API-Example
6767
cp -rf ./iOS/** ./$unzip_name/samples/API-Example
68-
rm -rf ./$unzip_name/samples/API-Example/APIExample-Audio
69-
mv ./$unzip_name/samples/API-Example/APIExample ./$unzip_name/samples/APIExample
68+
if [[ ./$unzip_name =~ "VOICE" ]]
69+
then
70+
echo "包含"
71+
rm -rf ./$unzip_name/samples/API-Example/APIExample
72+
mv ./$unzip_name/samples/API-Example/APIExample-Audio ./$unzip_name/samples/APIExample-Audio
73+
else
74+
echo "不包含"
75+
echo $unzip_name
76+
rm -rf ./$unzip_name/samples/API-Example/APIExample-Audio
77+
mv ./$unzip_name/samples/API-Example/APIExample ./$unzip_name/samples/APIExample
78+
fi
79+
7080
rm -rf ./$unzip_name/samples/API-Example
7181
mv ./$unzip_name/samples/APIExample/sdk.podspec ./$unzip_name/
7282
sed -i "s|pod 'sdk', :path => 'sdk.podspec'|pod 'sdk', :path => '../../sdk.podspec'|" ./$unzip_name/samples/APIExample/Podfile

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MultiVideoSourceTracks.java

Lines changed: 456 additions & 0 deletions
Large diffs are not rendered by default.

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PushExternalVideoYUV.java

Lines changed: 13 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@
2323
import com.yanzhenjie.permission.AndPermission;
2424
import com.yanzhenjie.permission.runtime.Permission;
2525

26-
import java.io.IOException;
27-
import java.io.InputStream;
28-
2926
import io.agora.api.example.MainApplication;
3027
import io.agora.api.example.R;
3128
import io.agora.api.example.annotation.Example;
3229
import io.agora.api.example.common.BaseFragment;
3330
import io.agora.api.example.utils.CommonUtil;
3431
import io.agora.api.example.utils.TokenUtils;
35-
import io.agora.base.JavaI420Buffer;
36-
import io.agora.base.VideoFrame;
32+
import io.agora.api.example.utils.VideoFileReader;
3733
import io.agora.rtc2.ChannelMediaOptions;
3834
import io.agora.rtc2.Constants;
3935
import io.agora.rtc2.IRtcEngineEventHandler;
@@ -53,24 +49,14 @@
5349
public class PushExternalVideoYUV extends BaseFragment implements View.OnClickListener {
5450
private static final String TAG = PushExternalVideoYUV.class.getSimpleName();
5551

56-
private final String RAW_VIDEO_PATH = "sample.yuv";
57-
private final int RAW_VIDEO_WIDTH = 320;
58-
private final int RAW_VIDEO_HEIGHT = 180;
59-
private final int RAW_VIDEO_FRAME_SIZE = RAW_VIDEO_WIDTH * RAW_VIDEO_HEIGHT / 2 * 3;
60-
private final int RAW_VIDEO_FRAME_RATE = 15;
61-
private final long RAW_VIDEO_FRAME_INTERVAL_NS = 1000 * 1000 * 1000 / RAW_VIDEO_FRAME_RATE;
62-
6352
private FrameLayout fl_local, fl_remote;
6453
private Button join;
6554
private EditText et_channel;
6655
private RtcEngineEx engine;
6756
private int myUid;
6857
private volatile boolean joined = false;
6958

70-
private Thread pushingThread;
71-
private volatile boolean pushing = false;
72-
73-
private InputStream inputStream;
59+
private VideoFileReader videoFileReader;
7460

7561
@Nullable
7662
@Override
@@ -143,15 +129,8 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
143129

144130
@Override
145131
public void onDestroy() {
146-
pushing = false;
147-
if (pushingThread != null) {
148-
try {
149-
pushingThread.join();
150-
} catch (InterruptedException e) {
151-
e.printStackTrace();
152-
} finally {
153-
pushingThread = null;
154-
}
132+
if(videoFileReader != null){
133+
videoFileReader.stop();
155134
}
156135

157136
/**leaveChannel and Destroy the RtcEngine instance*/
@@ -206,15 +185,8 @@ public void onClick(View v) {
206185
} else {
207186
joined = false;
208187
join.setText(getString(R.string.join));
209-
pushing = false;
210-
if (pushingThread != null) {
211-
try {
212-
pushingThread.join();
213-
} catch (InterruptedException e) {
214-
e.printStackTrace();
215-
} finally {
216-
pushingThread = null;
217-
}
188+
if(videoFileReader != null){
189+
videoFileReader.stop();
218190
}
219191
fl_remote.removeAllViews();
220192
fl_local.removeAllViews();
@@ -339,11 +311,14 @@ public void run() {
339311
join.setEnabled(true);
340312
join.setText(getString(R.string.leave));
341313

342-
pushing = true;
343-
if (pushingThread == null) {
344-
pushingThread = new Thread(new PushingTask());
345-
pushingThread.start();
314+
if (videoFileReader == null) {
315+
videoFileReader = new VideoFileReader(requireContext(), videoFrame -> {
316+
if(joined && engine != null){
317+
engine.pushExternalVideoFrame(videoFrame);
318+
}
319+
});
346320
}
321+
videoFileReader.start();
347322

348323
}
349324
});
@@ -407,51 +382,4 @@ public void run() {
407382
}
408383
};
409384

410-
private class PushingTask implements Runnable {
411-
412-
@Override
413-
public void run() {
414-
try {
415-
inputStream = getContext().getAssets().open(RAW_VIDEO_PATH);
416-
} catch (IOException e) {
417-
e.printStackTrace();
418-
}
419-
420-
byte[] buffer = new byte[RAW_VIDEO_FRAME_SIZE];
421-
while (pushing) {
422-
long start = System.nanoTime();
423-
try {
424-
int read = inputStream.read(buffer);
425-
while (read < 0) {
426-
inputStream.reset();
427-
read = inputStream.read(buffer);
428-
}
429-
} catch (IOException e) {
430-
e.printStackTrace();
431-
}
432-
JavaI420Buffer i420Buffer = JavaI420Buffer.allocate(RAW_VIDEO_WIDTH, RAW_VIDEO_HEIGHT);
433-
i420Buffer.getDataY().put(buffer, 0, i420Buffer.getDataY().limit());
434-
i420Buffer.getDataU().put(buffer, i420Buffer.getDataY().limit(), i420Buffer.getDataU().limit());
435-
i420Buffer.getDataV().put(buffer, i420Buffer.getDataY().limit() + i420Buffer.getDataU().limit(), i420Buffer.getDataV().limit());
436-
engine.pushExternalVideoFrame(new VideoFrame(i420Buffer, 0, System.nanoTime()));
437-
long consume = System.nanoTime() - start;
438-
439-
try {
440-
Thread.sleep(Math.max(0, (RAW_VIDEO_FRAME_INTERVAL_NS - consume) / 1000 / 1000));
441-
} catch (InterruptedException e) {
442-
e.printStackTrace();
443-
}
444-
}
445-
446-
if (inputStream != null) {
447-
try {
448-
inputStream.close();
449-
} catch (IOException e) {
450-
e.printStackTrace();
451-
} finally {
452-
inputStream = null;
453-
}
454-
}
455-
}
456-
}
457385
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.agora.api.example.examples.advanced;
22

3-
import static io.agora.api.example.common.model.Examples.ADVANCED;
43
import static io.agora.rtc2.video.VideoCanvas.RENDER_MODE_HIDDEN;
54
import static io.agora.rtc2.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
65
import static io.agora.rtc2.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
@@ -42,7 +41,6 @@
4241

4342
import io.agora.api.example.MainApplication;
4443
import io.agora.api.example.R;
45-
import io.agora.api.example.annotation.Example;
4644
import io.agora.api.example.common.BaseFragment;
4745
import io.agora.api.example.utils.CommonUtil;
4846
import io.agora.api.example.utils.TokenUtils;
@@ -61,13 +59,13 @@
6159
* This example demonstrates how video can be flexibly switched between the camera stream and the
6260
* screen share stream during an audio-video call.
6361
*/
64-
@Example(
65-
index = 10,
66-
group = ADVANCED,
67-
name = R.string.item_cameraorscreen,
68-
actionId = R.id.action_mainFragment_to_SwitchCameraScreenShare,
69-
tipsId = R.string.switchcamerascreen
70-
)
62+
//@Example(
63+
// index = 10,
64+
// group = ADVANCED,
65+
// name = R.string.item_cameraorscreen,
66+
// actionId = R.id.action_mainFragment_to_SwitchCameraScreenShare,
67+
// tipsId = R.string.switchcamerascreen
68+
//)
7169
public class SwitchCameraScreenShare extends BaseFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
7270
private static final String TAG = SwitchCameraScreenShare.class.getSimpleName();
7371
private static final int DEFAULT_SHARE_FRAME_RATE = 15;

0 commit comments

Comments
 (0)