package com.ttstd.controller.webrtc;

import org.webrtc.EglBase;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoFrame;
import org.webrtc.VideoSink;

/**
 * 远端视频流渲染器，将WebRTC视频帧渲染到SurfaceViewRenderer。
 */
public class VideoRenderer implements VideoSink {

    private static final String TAG = "VideoRenderer";
    private final SurfaceViewRenderer surfaceViewRenderer;

    public VideoRenderer(SurfaceViewRenderer surfaceViewRenderer) {
        this.surfaceViewRenderer = surfaceViewRenderer;
    }

    @Override
    public void onFrame(VideoFrame frame) {
        surfaceViewRenderer.onFrame(frame);
    }

    public void init(EglBase eglBase) {
        surfaceViewRenderer.init(eglBase.getEglBaseContext(), null);
        surfaceViewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
        surfaceViewRenderer.setEnableHardwareScaler(true);
    }

    public void release() {
        surfaceViewRenderer.release();
    }
}
