zhangzengfei
2022-01-10 4496b59ab27d569df1da7ef634e02273b3a9618a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.basic.security.utils.yuv.pull.client;
 
import java.io.ByteArrayOutputStream;
import java.util.LinkedList;
 
public class ImageBuffer {
 
    private final int mFrameLength;
    byte[] data11 = new byte[460800];
    private int mTotalLength = 0;
    private ByteArrayOutputStream mByteArrayOutputStream;
 
    public ImageBuffer(int frameLength, int width, int height) {
        mByteArrayOutputStream = new ByteArrayOutputStream();
        mFrameLength = frameLength;
    }
 
    public int fillBuffer(byte[] data, int off, int len, LinkedList<byte[]> YUVQueue) {
        mTotalLength += len;
//        mByteArrayOutputStream.write(data, off, len);
 
        if (mTotalLength == mFrameLength) {
 
            synchronized (YUVQueue) {
                System.arraycopy(data, off, data11, 0, data11.length);
                YUVQueue.add(data11);
//                YUVQueue.add(mByteArrayOutputStream.toByteArray());
//                mByteArrayOutputStream.reset();
            }
 
            mTotalLength = 0;
//            System.out.println("received file");
        }
 
        return 0;
    }
}