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-07-13 10:40:26 +02:00
|
|
|
import javax.annotation.Nullable;
|
2018-05-21 13:45:51 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
2018-03-22 13:32:44 +01:00
|
|
|
|
2018-07-13 10:40:26 +02:00
|
|
|
/** Helper class that combines HW and SW decoders. */
|
2017-11-10 13:15:04 +01:00
|
|
|
public class DefaultVideoDecoderFactory implements VideoDecoderFactory {
|
2018-07-13 10:40:26 +02:00
|
|
|
private final VideoDecoderFactory hardwareVideoDecoderFactory;
|
|
|
|
|
private final VideoDecoderFactory softwareVideoDecoderFactory = new SoftwareVideoDecoderFactory();
|
2017-11-10 13:15:04 +01:00
|
|
|
|
2018-07-13 10:40:26 +02:00
|
|
|
/** Create decoder factory using default hardware decoder factory. */
|
2017-11-10 13:15:04 +01:00
|
|
|
public DefaultVideoDecoderFactory(EglBase.Context eglContext) {
|
2018-07-13 10:40:26 +02:00
|
|
|
this.hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory(eglContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Create decoder factory using explicit hardware decoder factory. */
|
|
|
|
|
DefaultVideoDecoderFactory(VideoDecoderFactory hardwareVideoDecoderFactory) {
|
|
|
|
|
this.hardwareVideoDecoderFactory = hardwareVideoDecoderFactory;
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2018-03-22 13:32:44 +01:00
|
|
|
public @Nullable VideoDecoder createDecoder(String codecType) {
|
2018-07-13 10:40:26 +02:00
|
|
|
final VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType);
|
|
|
|
|
final VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType);
|
|
|
|
|
if (hardwareDecoder != null && softwareDecoder != null) {
|
|
|
|
|
// Both hardware and software supported, wrap it in a software fallback
|
|
|
|
|
return new VideoDecoderFallback(
|
|
|
|
|
/* fallback= */ softwareDecoder, /* primary= */ hardwareDecoder);
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
2018-07-13 10:40:26 +02:00
|
|
|
return hardwareDecoder != null ? hardwareDecoder : softwareDecoder;
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|
2018-05-21 13:45:51 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public VideoCodecInfo[] getSupportedCodecs() {
|
|
|
|
|
LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<VideoCodecInfo>();
|
|
|
|
|
|
|
|
|
|
supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs()));
|
|
|
|
|
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs()));
|
|
|
|
|
|
|
|
|
|
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
|
|
|
|
|
}
|
2017-11-10 13:15:04 +01:00
|
|
|
}
|