2017-11-10 13:15:04 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.webrtc;
|
|
|
|
|
|
2018-12-10 12:30:46 +01:00
|
|
|
import android.support.annotation.Nullable;
|
2017-11-10 13:15:04 +01:00
|
|
|
import java.util.Arrays;
|
2017-11-16 15:44:14 +01:00
|
|
|
import java.util.LinkedHashSet;
|
2017-11-10 13:15:04 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2018-07-13 10:40:26 +02:00
|
|
|
/** Helper class that combines HW and SW encoders. */
|
2017-11-10 13:15:04 +01:00
|
|
|
public class DefaultVideoEncoderFactory implements VideoEncoderFactory {
|
|
|
|
|
private final VideoEncoderFactory hardwareVideoEncoderFactory;
|
2018-07-13 10:40:26 +02:00
|
|
|
private final VideoEncoderFactory softwareVideoEncoderFactory = new SoftwareVideoEncoderFactory();
|
2017-11-10 13:15:04 +01:00
|
|
|
|
2018-07-13 10:40:26 +02:00
|
|
|
/** Create encoder factory using default hardware encoder factory. */
|
2017-11-10 13:15:04 +01:00
|
|
|
public DefaultVideoEncoderFactory(
|
|
|
|
|
EglBase.Context eglContext, boolean enableIntelVp8Encoder, boolean enableH264HighProfile) {
|
2018-07-13 10:40:26 +02:00
|
|
|
this.hardwareVideoEncoderFactory =
|
2018-06-11 14:57:07 +02:00
|
|
|
new HardwareVideoEncoderFactory(eglContext, enableIntelVp8Encoder, enableH264HighProfile);
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-13 10:40:26 +02:00
|
|
|
/** Create encoder factory using explicit hardware encoder factory. */
|
2017-11-10 13:15:04 +01:00
|
|
|
DefaultVideoEncoderFactory(VideoEncoderFactory hardwareVideoEncoderFactory) {
|
|
|
|
|
this.hardwareVideoEncoderFactory = hardwareVideoEncoderFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 13:32:44 +01:00
|
|
|
@Nullable
|
2017-11-10 13:15:04 +01:00
|
|
|
@Override
|
|
|
|
|
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
2018-07-13 10:40:26 +02:00
|
|
|
final VideoEncoder softwareEncoder = softwareVideoEncoderFactory.createEncoder(info);
|
|
|
|
|
final VideoEncoder hardwareEncoder = hardwareVideoEncoderFactory.createEncoder(info);
|
|
|
|
|
if (hardwareEncoder != null && softwareEncoder != null) {
|
|
|
|
|
// Both hardware and software supported, wrap it in a software fallback
|
|
|
|
|
return new VideoEncoderFallback(
|
|
|
|
|
/* fallback= */ softwareEncoder, /* primary= */ hardwareEncoder);
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
2018-07-13 10:40:26 +02:00
|
|
|
return hardwareEncoder != null ? hardwareEncoder : softwareEncoder;
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public VideoCodecInfo[] getSupportedCodecs() {
|
2017-11-16 15:44:14 +01:00
|
|
|
LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<VideoCodecInfo>();
|
2017-11-10 13:15:04 +01:00
|
|
|
|
|
|
|
|
supportedCodecInfos.addAll(Arrays.asList(softwareVideoEncoderFactory.getSupportedCodecs()));
|
2017-11-16 15:44:14 +01:00
|
|
|
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoEncoderFactory.getSupportedCodecs()));
|
2017-11-10 13:15:04 +01:00
|
|
|
|
|
|
|
|
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
|
|
|
|
|
}
|
|
|
|
|
}
|