Skip to content

Commit 48f7a3c

Browse files
1 parent 09d53dc commit 48f7a3c

3 files changed

Lines changed: 39 additions & 38 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ public void onCaptureVideoFrame(byte[] data, int frameType, int width, int heigh
371371
Log.e(TAG, "onCaptureVideoFrame0");
372372
if(blur)
373373
{return;}
374-
Bitmap bmp = YUVUtils.blur(getContext(), YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride), 10);
374+
Bitmap bmp = YUVUtils.blur(getContext(), YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride), 4);
375375
System.arraycopy(YUVUtils.bitmapToI420(width, height, bmp), 0, data, 0, bufferLength);
376376
}
377377

378378
@Override
379379
public void onRenderVideoFrame(int uid, byte[] data, int frameType, int width, int height, int bufferLength, int yStride, int uStride, int vStride, int rotation, long renderTimeMs) {
380380
if(blur)
381381
{return;}
382-
Bitmap bmp = YUVUtils.blur(getContext(), YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride), 10);
382+
Bitmap bmp = YUVUtils.blur(getContext(), YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride), 4);
383383
System.arraycopy(YUVUtils.bitmapToI420(width, height, bmp), 0, data, 0, bufferLength);
384384
}
385385

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="agora_app_id" translatable="false">YOUR APP ID</string>
4-
<string name="agora_access_token" translatable="false">YOUR ACCESS TOKEN</string>
3+
<!-- <string name="agora_app_id" translatable="false">YOUR APP ID</string>-->
4+
<!-- <string name="agora_access_token" translatable="false">YOUR ACCESS TOKEN</string>-->
5+
<!-- <string name="agora_app_id" translatable="false">266819b117a042a9aa188a67b5daabfb</string>-->
6+
<!-- <string name="agora_access_token" translatable="false">006266819b117a042a9aa188a67b5daabfbIACsl0GIdXKqEvmBYWQvl9Anbl3fLGpb298X8JoqA1BJWJzywRwAAAAAEAB65KjRe0LfXgEAAQB7Qt9e</string>-->
7+
<string name="agora_app_id" translatable="false">aab8b8f5a8cd4469a63042fcfafe7063</string>
8+
<string name="agora_access_token" translatable="false"></string>
59
</resources>

Android/APIExample/lib-raw-data/src/main/java/io/agora/advancedvideo/rawdata/MediaDataObserverPlugin.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import java.io.IOException;
1515
import java.nio.ByteBuffer;
1616
import java.util.ArrayList;
17+
import java.util.HashMap;
1718
import java.util.Iterator;
19+
import java.util.Map;
1820
import java.util.concurrent.CopyOnWriteArrayList;
1921

2022
/**
@@ -35,7 +37,7 @@ public class MediaDataObserverPlugin implements MediaPreProcessing.ProgressCallb
3537
public ByteBuffer byteBufferBeforeAudioMix = ByteBuffer.allocateDirect(AUDIO_DEFAULT_BUFFER_SIZE);
3638
public ByteBuffer byteBufferAudioMix = ByteBuffer.allocateDirect(AUDIO_DEFAULT_BUFFER_SIZE);
3739

38-
private final ArrayList<DecodeDataBuffer> decodeBufferList = new ArrayList<>();
40+
private final Map<Integer, ByteBuffer> decodeBufferList = new HashMap<>();
3941

4042
private static MediaDataObserverPlugin myAgent = null;
4143

@@ -85,24 +87,18 @@ public void saveRenderVideoSnapshot(String filePath, int uid) {
8587

8688
public void addDecodeBuffer(int uid) {
8789
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(VIDEO_DEFAULT_BUFFER_SIZE);
88-
decodeBufferList.add(new DecodeDataBuffer(uid, byteBuffer));
90+
decodeBufferList.put(uid, byteBuffer);
8991
MediaPreProcessing.setVideoDecodeByteBuffer(uid, byteBuffer);
9092
}
9193

9294
public void removeDecodeBuffer(int uid) {
93-
Iterator<DecodeDataBuffer> it = decodeBufferList.iterator();
94-
while (it.hasNext()) {
95-
DecodeDataBuffer buffer = it.next();
96-
if (buffer.getUid() == uid) {
97-
it.remove();
98-
}
99-
}
95+
decodeBufferList.remove(uid);
10096

10197
MediaPreProcessing.setVideoDecodeByteBuffer(uid, null);
10298
}
10399

104100
public void removeAllBuffer() {
105-
decodeBufferList.removeAll(decodeBufferList);
101+
decodeBufferList.clear();
106102
releaseBuffer();
107103
}
108104

@@ -130,26 +126,23 @@ public void onCaptureVideoFrame(int videoFrameType, int width, int height, int b
130126
@Override
131127
public void onRenderVideoFrame(int uid, int videoFrameType, int width, int height, int bufferLength, int yStride, int uStride, int vStride, int rotation, long renderTimeMs) {
132128
for (MediaDataVideoObserver observer : videoObserverList) {
133-
Iterator<DecodeDataBuffer> it = decodeBufferList.iterator();
134-
while (it.hasNext()) {
135-
DecodeDataBuffer tmp = it.next();
136-
if (tmp.getUid() == uid) {
137-
byte[] buf = new byte[bufferLength];
138-
tmp.getByteBuffer().limit(bufferLength);
139-
tmp.getByteBuffer().get(buf);
140-
tmp.getByteBuffer().flip();
141-
142-
observer.onRenderVideoFrame(uid, buf, videoFrameType, width, height, bufferLength, yStride, uStride, vStride, rotation, renderTimeMs);
143-
144-
tmp.getByteBuffer().put(buf);
145-
tmp.getByteBuffer().flip();
146-
147-
if (beRenderVideoShot) {
148-
if (uid == renderVideoShotUid) {
149-
beRenderVideoShot = false;
150-
151-
getVideoSnapshot(width, height, rotation, bufferLength, buf, renderFilePath, yStride, uStride, vStride);
152-
}
129+
ByteBuffer tmp = decodeBufferList.get(uid);
130+
if (tmp != null) {
131+
byte[] buf = new byte[bufferLength];
132+
tmp.limit(bufferLength);
133+
tmp.get(buf);
134+
tmp.flip();
135+
136+
observer.onRenderVideoFrame(uid, buf, videoFrameType, width, height, bufferLength, yStride, uStride, vStride, rotation, renderTimeMs);
137+
138+
tmp.put(buf);
139+
tmp.flip();
140+
141+
if (beRenderVideoShot) {
142+
if (uid == renderVideoShotUid) {
143+
beRenderVideoShot = false;
144+
145+
getVideoSnapshot(width, height, rotation, bufferLength, buf, renderFilePath, yStride, uStride, vStride);
153146
}
154147
}
155148
}
@@ -237,7 +230,8 @@ private void getVideoSnapshot(int width, int height, int rotation, int bufferLen
237230
byte[] bytes = baos.toByteArray();
238231
try {
239232
baos.close();
240-
} catch (IOException e) {
233+
}
234+
catch (IOException e) {
241235
e.printStackTrace();
242236
}
243237
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
@@ -253,14 +247,16 @@ private void getVideoSnapshot(int width, int height, int rotation, int bufferLen
253247

254248
try {
255249
file.createNewFile();
256-
} catch (IOException e) {
250+
}
251+
catch (IOException e) {
257252
e.printStackTrace();
258253
}
259254

260255
FileOutputStream fos = null;
261256
try {
262257
fos = new FileOutputStream(file);
263-
} catch (FileNotFoundException e) {
258+
}
259+
catch (FileNotFoundException e) {
264260
e.printStackTrace();
265261
}
266262

@@ -271,7 +267,8 @@ private void getVideoSnapshot(int width, int height, int rotation, int bufferLen
271267

272268
try {
273269
fos.close();
274-
} catch (IOException e) {
270+
}
271+
catch (IOException e) {
275272
e.printStackTrace();
276273
}
277274
}

0 commit comments

Comments
 (0)