Implement equals() and hashCode() for VideoCodecInfo.
To be able to compare VideoCodecInfos in a nice way in Java and still use the correct criteria for comparing H264 codec infos. A similar thing was done for Obj-C here: https://webrtc-review.googlesource.com/c/src/+/4383 Bug: webrtc:7925 Change-Id: I43f532d4efa557fc8fe25a82eebc35072b91e6db Reviewed-on: https://webrtc-review.googlesource.com/23240 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20716}
This commit is contained in:

committed by
Commit Bot

parent
4d85e8a78c
commit
1e1dd77604
@ -10,8 +10,8 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultVideoEncoderFactory implements VideoEncoderFactory {
|
||||
@ -33,38 +33,20 @@ public class DefaultVideoEncoderFactory implements VideoEncoderFactory {
|
||||
|
||||
@Override
|
||||
public VideoEncoder createEncoder(VideoCodecInfo info) {
|
||||
List<VideoCodecInfo> hardwareSupportedCodecs =
|
||||
Arrays.asList(hardwareVideoEncoderFactory.getSupportedCodecs());
|
||||
if (containsSameCodec(hardwareSupportedCodecs, info)) {
|
||||
return hardwareVideoEncoderFactory.createEncoder(info);
|
||||
} else {
|
||||
return softwareVideoEncoderFactory.createEncoder(info);
|
||||
final VideoEncoder videoEncoder = hardwareVideoEncoderFactory.createEncoder(info);
|
||||
if (videoEncoder != null) {
|
||||
return videoEncoder;
|
||||
}
|
||||
return softwareVideoEncoderFactory.createEncoder(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoCodecInfo[] getSupportedCodecs() {
|
||||
List<VideoCodecInfo> supportedCodecInfos = new ArrayList<>();
|
||||
LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<VideoCodecInfo>();
|
||||
|
||||
supportedCodecInfos.addAll(Arrays.asList(softwareVideoEncoderFactory.getSupportedCodecs()));
|
||||
|
||||
for (VideoCodecInfo info : hardwareVideoEncoderFactory.getSupportedCodecs()) {
|
||||
if (!containsSameCodec(supportedCodecInfos, info)) {
|
||||
supportedCodecInfos.add(info);
|
||||
}
|
||||
}
|
||||
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoEncoderFactory.getSupportedCodecs()));
|
||||
|
||||
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
|
||||
}
|
||||
|
||||
private static boolean containsSameCodec(List<VideoCodecInfo> infos, VideoCodecInfo info) {
|
||||
for (VideoCodecInfo otherInfo : infos) {
|
||||
if (isSameCodec(info, otherInfo)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static native boolean isSameCodec(VideoCodecInfo info1, VideoCodecInfo info2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user