Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 46df1fc

Browse files
authored
Renable hevc support for android (#80)
1 parent b9e7538 commit 46df1fc

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static org.webrtc.MediaCodecUtils.EXYNOS_PREFIX;
1414
import static org.webrtc.MediaCodecUtils.INTEL_PREFIX;
1515
import static org.webrtc.MediaCodecUtils.QCOM_PREFIX;
16+
import static org.webrtc.MediaCodecUtils.HISI_PREFIX;
1617

1718
import android.media.MediaCodecInfo;
1819
import android.media.MediaCodecList;
@@ -213,6 +214,8 @@ private boolean isHardwareSupportedInCurrentSdkVp8(MediaCodecInfo info) {
213214
String name = info.getName();
214215
// QCOM Vp8 encoder is supported in KITKAT or later.
215216
return (name.startsWith(QCOM_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
217+
// Hisi VP8 encoder seems to be supported. Needs more testing.
218+
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
216219
// Exynos VP8 encoder is supported in M or later.
217220
|| (name.startsWith(EXYNOS_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
218221
// Intel Vp8 encoder is supported in LOLLIPOP or later, with the intel encoder enabled.
@@ -222,7 +225,7 @@ private boolean isHardwareSupportedInCurrentSdkVp8(MediaCodecInfo info) {
222225

223226
private boolean isHardwareSupportedInCurrentSdkVp9(MediaCodecInfo info) {
224227
String name = info.getName();
225-
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX))
228+
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX))
226229
// Both QCOM and Exynos VP9 encoders are supported in N or later.
227230
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
228231
}
@@ -246,7 +249,9 @@ private boolean isHardwareSupportedInCurrentSdkH265(MediaCodecInfo info) {
246249
return (name.startsWith(QCOM_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
247250
// Exynos H265 encoder is supported in LOLLIPOP or later.
248251
|| (name.startsWith(EXYNOS_PREFIX)
249-
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
252+
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
253+
// Hisi VP8 encoder seems to be supported. Needs more testing.
254+
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
250255
}
251256

252257
private boolean isMediaCodecAllowed(MediaCodecInfo info) {

sdk/android/src/java/org/webrtc/MediaCodecUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MediaCodecUtils {
2828
static final String INTEL_PREFIX = "OMX.Intel.";
2929
static final String NVIDIA_PREFIX = "OMX.Nvidia.";
3030
static final String QCOM_PREFIX = "OMX.qcom.";
31+
static final String HISI_PREFIX = "OMX.hisi.";
3132
static final String[] SOFTWARE_IMPLEMENTATION_PREFIXES = {"OMX.google.", "OMX.SEC."};
3233

3334
// NV12 color format supported by QCOM codec, but not declared in MediaCodec -

sdk/android/src/jni/video_encoder_wrapper.cc

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <utility>
1414

1515
#include "common_video/h264/h264_common.h"
16+
#ifndef DISABLE_H265
17+
#include "common_video/h265/h265_common.h"
18+
#endif
1619
#include "modules/video_coding/include/video_codec_interface.h"
1720
#include "modules/video_coding/include/video_error_codes.h"
1821
#include "modules/video_coding/utility/vp8_header_parser.h"
@@ -322,19 +325,8 @@ int32_t VideoEncoderWrapper::HandleReturnCode(JNIEnv* jni,
322325
RTPFragmentationHeader VideoEncoderWrapper::ParseFragmentationHeader(
323326
rtc::ArrayView<const uint8_t> buffer) {
324327
RTPFragmentationHeader header;
325-
#ifndef DISABLE_H265
326-
if (codec_settings_.codecType == kVideoCodecH264
327-
|| codec_settings_.codecType == kVideoCodecH265) {
328-
if (codec_settings_.codecType == kVideoCodecH264) {
329-
h264_bitstream_parser_.ParseBitstream(buffer.data(), buffer.size());
330-
} else if (codec_settings_.codecType == kVideoCodecH265) {
331-
h265_bitstream_parser_.ParseBitstream(buffer.data(), buffer.size());
332-
}
333-
#else
334328
if (codec_settings_.codecType == kVideoCodecH264) {
335-
h264_bitstream_parser_.ParseBitstream(buffer.data(), buffer.size());
336-
#endif
337-
329+
h264_bitstream_parser_.ParseBitstream(buffer.data(), buffer.size());
338330
// For H.264 search for start codes.
339331
const std::vector<H264::NaluIndex> nalu_idxs =
340332
H264::FindNaluIndices(buffer.data(), buffer.size());
@@ -349,7 +341,27 @@ RTPFragmentationHeader VideoEncoderWrapper::ParseFragmentationHeader(
349341
header.fragmentationOffset[i] = nalu_idxs[i].payload_start_offset;
350342
header.fragmentationLength[i] = nalu_idxs[i].payload_size;
351343
}
352-
} else {
344+
}
345+
#ifndef DISABLE_H265
346+
else if (codec_settings_.codecType == kVideoCodecH265) {
347+
h265_bitstream_parser_.ParseBitstream(buffer.data(), buffer.size());
348+
// For H.265 search for start codes.
349+
const std::vector<H265::NaluIndex> nalu_idxs =
350+
H265::FindNaluIndices(buffer.data(), buffer.size());
351+
if (nalu_idxs.empty()) {
352+
RTC_LOG(LS_ERROR) << "Start code is not found!";
353+
RTC_LOG(LS_ERROR) << "Data:" << buffer[0] << " " << buffer[1] << " "
354+
<< buffer[2] << " " << buffer[3] << " " << buffer[4]
355+
<< " " << buffer[5];
356+
}
357+
header.VerifyAndAllocateFragmentationHeader(nalu_idxs.size());
358+
for (size_t i = 0; i < nalu_idxs.size(); i++) {
359+
header.fragmentationOffset[i] = nalu_idxs[i].payload_start_offset;
360+
header.fragmentationLength[i] = nalu_idxs[i].payload_size;
361+
}
362+
}
363+
#endif
364+
else {
353365
// Generate a header describing a single fragment.
354366
header.VerifyAndAllocateFragmentationHeader(1);
355367
header.fragmentationOffset[0] = 0;

0 commit comments

Comments
 (0)