org.webrtc.MediaCodecVideoEncoder Java Examples

The following examples show how to use org.webrtc.MediaCodecVideoEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Mp4Recorder.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void onEncodedFrame(final MediaCodecVideoEncoder.OutputBufferInfo frame,
        final MediaCodec.BufferInfo bufferInfo) {
    boolean configFrame = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0;
    if (!configFrame) {
        mMediaMuxer.writeSampleData(mTrackIndex, frame.buffer(), bufferInfo);
    }
}
 
Example #2
Source File: HwAvcEncoder.java    From VideoCRE with MIT License 5 votes vote down vote up
public HwAvcEncoder(final VideoConfig videoConfig, final MediaCodecCallback... callbacks) {
    mVideoConfig = videoConfig;
    mMediaCodecThread = new HandlerThread("HwAvcEncoderThread");
    mMediaCodecThread.start();
    mMediaCodecHandler = new Handler(mMediaCodecThread.getLooper());
    mVideoEncoder = new MediaCodecVideoEncoder();
    mMediaCodecCallbacks = Arrays.asList(callbacks);
}
 
Example #3
Source File: HwAvcEncoder.java    From VideoCRE with MIT License 5 votes vote down vote up
public void start(final EglBase eglBase) {
    mMediaCodecHandler.post(new Runnable() {
        @Override
        public void run() {
            mVideoEncoder.initEncode(MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_H264,
                    MediaCodecVideoEncoder.H264Profile.CONSTRAINED_BASELINE.getValue(),
                    mVideoConfig.outputWidth(), mVideoConfig.outputHeight(),
                    mVideoConfig.outputBitrate(), mVideoConfig.fps(),
                    eglBase.getEglBaseContext(), HwAvcEncoder.this);
        }
    });
}
 
Example #4
Source File: HwAvcEncoder.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void onEncodedFrame(final MediaCodecVideoEncoder.OutputBufferInfo frame,
        final MediaCodec.BufferInfo bufferInfo) {
    for (int i = 0, n = mMediaCodecCallbacks.size(); i < n; i++) {
        mMediaCodecCallbacks.get(i).onEncodedFrame(frame, bufferInfo);
    }
}
 
Example #5
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
private void createMediaConstraintsInternal() {
    // Create peer connection constraints.
    pcConstraints = new MediaConstraints();
    // Enable DTLS for normal calls and disable for loopback calls.
    if (peerConnectionParameters.loopback) {
        pcConstraints.optional.add(
                new KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT, "false"));
    } else {
        pcConstraints.optional.add(
                new KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT, "true"));
    }

    // Check if there is a camera on device and disable video call if not.
    numberOfCameras = CameraEnumerationAndroid.getDeviceCount();
    if (numberOfCameras == 0) {
        Log.w(TAG, "No camera on device. Switch to audio only call.");
        videoCallEnabled = false;
    }
    // Create video constraints if video call is enabled.
    if (videoCallEnabled) {
        videoConstraints = new MediaConstraints();
        int videoWidth = peerConnectionParameters.videoWidth;
        int videoHeight = peerConnectionParameters.videoHeight;

        // If VP8 HW video encoder is supported and video resolution is not
        // specified force it to HD.
        if ((videoWidth == 0 || videoHeight == 0)
                && peerConnectionParameters.videoCodecHwAcceleration
                && MediaCodecVideoEncoder.isVp8HwSupported()) {
            videoWidth = HD_VIDEO_WIDTH;
            videoHeight = HD_VIDEO_HEIGHT;
        }

        // Add video resolution constraints.
        if (videoWidth > 0 && videoHeight > 0) {
            videoWidth = Math.min(videoWidth, MAX_VIDEO_WIDTH);
            videoHeight = Math.min(videoHeight, MAX_VIDEO_HEIGHT);
            videoConstraints.mandatory.add(new KeyValuePair(
                    MIN_VIDEO_WIDTH_CONSTRAINT, Integer.toString(videoWidth)));
            videoConstraints.mandatory.add(new KeyValuePair(
                    MAX_VIDEO_WIDTH_CONSTRAINT, Integer.toString(videoWidth)));
            videoConstraints.mandatory.add(new KeyValuePair(
                    MIN_VIDEO_HEIGHT_CONSTRAINT, Integer.toString(videoHeight)));
            videoConstraints.mandatory.add(new KeyValuePair(
                    MAX_VIDEO_HEIGHT_CONSTRAINT, Integer.toString(videoHeight)));
        }

        // Add fps constraints.
        int videoFps = peerConnectionParameters.videoFps;
        if (videoFps > 0) {
            videoFps = Math.min(videoFps, MAX_VIDEO_FPS);
            videoConstraints.mandatory.add(new KeyValuePair(
                    MIN_VIDEO_FPS_CONSTRAINT, Integer.toString(videoFps)));
            videoConstraints.mandatory.add(new KeyValuePair(
                    MAX_VIDEO_FPS_CONSTRAINT, Integer.toString(videoFps)));
        }
    }

    // Create audio constraints.
    audioConstraints = new MediaConstraints();
    // added for audio performance measurements
    if (peerConnectionParameters.noAudioProcessing) {
        Log.d(TAG, "Disabling audio processing");
        audioConstraints.mandatory.add(new KeyValuePair(
                AUDIO_ECHO_CANCELLATION_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new KeyValuePair(
                AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new KeyValuePair(
                AUDIO_HIGH_PASS_FILTER_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new KeyValuePair(
                AUDIO_NOISE_SUPPRESSION_CONSTRAINT, "false"));
    }
    // Create SDP constraints.
    sdpMediaConstraints = new MediaConstraints();
    sdpMediaConstraints.mandatory.add(new KeyValuePair(
            "OfferToReceiveAudio", "true"));
    if (videoCallEnabled || peerConnectionParameters.loopback) {
        sdpMediaConstraints.mandatory.add(new KeyValuePair(
                "OfferToReceiveVideo", "true"));
    } else {
        sdpMediaConstraints.mandatory.add(new KeyValuePair(
                "OfferToReceiveVideo", "false"));
    }
}
 
Example #6
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 4 votes vote down vote up
void createMediaConstraints() {
    // Create peer connection constraints.
    pcConstraints = new MediaConstraints();

    // Enable DTLS for normal calls and disable for loopback calls.
    if (peerConnectionParameters.loopback) {
        pcConstraints.optional.add(new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT, "false"));
    } else {
        pcConstraints.optional.add(new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT, "true"));
    }

    pcConstraints.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));

    // Check if there is a camera on device and disable video call if not.
    if (numberOfCameras == 0) {
        Log.w(TAG, "No camera on device. Switch to audio only call.");
        videoCallEnabled = false;
    }
    // Create video constraints if video call is enabled.
    if (videoCallEnabled) {
        videoConstraints = new MediaConstraints();
        int videoWidth = peerConnectionParameters.videoWidth;
        int videoHeight = peerConnectionParameters.videoHeight;
        // If VP8 HW video encoder is supported and video resolution is not
        // specified force it to HD.
        if ((videoWidth == 0 || videoHeight == 0) && peerConnectionParameters.videoCodecHwAcceleration && MediaCodecVideoEncoder.isVp8HwSupported()) {
            videoWidth = HD_VIDEO_WIDTH;
            videoHeight = HD_VIDEO_HEIGHT;
        }
        // Add video resolution constraints.
        if (videoWidth > 0 && videoHeight > 0) {
            videoWidth = Math.min(videoWidth, MAX_VIDEO_WIDTH);
            videoHeight = Math.min(videoHeight, MAX_VIDEO_HEIGHT);
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MIN_VIDEO_WIDTH_CONSTRAINT, Integer.toString(videoWidth)));
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MAX_VIDEO_WIDTH_CONSTRAINT, Integer.toString(videoWidth)));
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MIN_VIDEO_HEIGHT_CONSTRAINT, Integer.toString(videoHeight)));
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MAX_VIDEO_HEIGHT_CONSTRAINT, Integer.toString(videoHeight)));
        }
        // Add fps constraints.
        int videoFps = peerConnectionParameters.videoFps;
        if (videoFps > 0) {
            videoFps = Math.min(videoFps, MAX_VIDEO_FPS);
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MIN_VIDEO_FPS_CONSTRAINT, Integer.toString(videoFps)));
            videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair(MAX_VIDEO_FPS_CONSTRAINT, Integer.toString(videoFps)));
        }
    }
    // Create audio constraints.
    audioConstraints = new MediaConstraints();
    // added for audio performance measurements
    if (peerConnectionParameters.noAudioProcessing) {
        Log.d(TAG, "Disabling audio processing");
        audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair(AUDIO_ECHO_CANCELLATION_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair(AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair(AUDIO_HIGH_PASS_FILTER_CONSTRAINT, "false"));
        audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair(AUDIO_NOISE_SUPPRESSION_CONSTRAINT, "false"));
    }
    // Create SDP constraints.
    sdpMediaConstraints = new MediaConstraints();
    sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    if (videoCallEnabled || peerConnectionParameters.loopback) {
        sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
    } else {
        sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "false"));
    }

    sdpMediaConstraints.optional.add(new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT, "true"));
    sdpMediaConstraints.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));
}
 
Example #7
Source File: MediaCodecCallback.java    From VideoCRE with MIT License 2 votes vote down vote up
/**
 * must consume it synchronously.
 */
void onEncodedFrame(MediaCodecVideoEncoder.OutputBufferInfo frame,
        MediaCodec.BufferInfo bufferInfo);