Skip to content

Commit e7f44f8

Browse files
committed
avcodec/ohdec: Add h264/hevc OpenHarmony decoders
1 parent fbda5ff commit e7f44f8

File tree

7 files changed

+908
-1
lines changed

7 files changed

+908
-1
lines changed

configure

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,8 @@ h264_mf_encoder_deps="mediafoundation"
34113411
h264_mmal_decoder_deps="mmal"
34123412
h264_nvenc_encoder_deps="nvenc"
34133413
h264_nvenc_encoder_select="atsc_a53"
3414+
h264_oh_decoder_deps="ohcodec"
3415+
h264_oh_decoder_select="h264_mp4toannexb_bsf"
34143416
h264_omx_encoder_deps="omx"
34153417
h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
34163418
h264_qsv_encoder_select="atsc_a53 qsvenc"
@@ -3433,6 +3435,8 @@ hevc_mediacodec_encoder_select="extract_extradata_bsf hevc_metadata"
34333435
hevc_mf_encoder_deps="mediafoundation"
34343436
hevc_nvenc_encoder_deps="nvenc"
34353437
hevc_nvenc_encoder_select="atsc_a53"
3438+
hevc_oh_decoder_deps="ohcodec"
3439+
hevc_oh_decoder_select="hevc_mp4toannexb_bsf"
34363440
hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
34373441
hevc_qsv_encoder_select="hevcparse qsvenc"
34383442
hevc_rkmpp_decoder_deps="rkmpp"

libavcodec/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ OBJS-$(CONFIG_H264_MEDIACODEC_ENCODER) += mediacodecenc.o
428428
OBJS-$(CONFIG_H264_MF_ENCODER) += mfenc.o mf_utils.o
429429
OBJS-$(CONFIG_H264_MMAL_DECODER) += mmaldec.o
430430
OBJS-$(CONFIG_H264_NVENC_ENCODER) += nvenc_h264.o nvenc.o
431+
OBJS-$(CONFIG_H264_OH_DECODER) += ohcodec.o ohdec.o
431432
OBJS-$(CONFIG_H264_OMX_ENCODER) += omx.o
432433
OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec.o
433434
OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o
@@ -456,6 +457,7 @@ OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
456457
OBJS-$(CONFIG_HEVC_MEDIACODEC_ENCODER) += mediacodecenc.o
457458
OBJS-$(CONFIG_HEVC_MF_ENCODER) += mfenc.o mf_utils.o
458459
OBJS-$(CONFIG_HEVC_NVENC_ENCODER) += nvenc_hevc.o nvenc.o
460+
OBJS-$(CONFIG_HEVC_OH_DECODER) += ohcodec.o ohdec.o
459461
OBJS-$(CONFIG_HEVC_QSV_DECODER) += qsvdec.o
460462
OBJS-$(CONFIG_HEVC_QSV_ENCODER) += qsvenc_hevc.o hevc/ps_enc.o
461463
OBJS-$(CONFIG_HEVC_RKMPP_DECODER) += rkmppdec.o
@@ -1314,6 +1316,7 @@ SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec_common.h mediacodec_surf
13141316
SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION) += mf_utils.h
13151317
SKIPHEADERS-$(CONFIG_NVDEC) += nvdec.h
13161318
SKIPHEADERS-$(CONFIG_NVENC) += nvenc.h
1319+
SKIPHEADERS-$(CONFIG_OHCODEC) += ohcodec.h
13171320
SKIPHEADERS-$(CONFIG_QSV) += qsv.h qsv_internal.h
13181321
SKIPHEADERS-$(CONFIG_QSVENC) += qsvenc.h
13191322
SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_decode.h vaapi_hevc.h vaapi_encode.h

libavcodec/allcodecs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ extern const FFCodec ff_h264_amf_decoder;
860860
extern const FFCodec ff_h264_cuvid_decoder;
861861
extern const FFCodec ff_h264_mf_encoder;
862862
extern const FFCodec ff_h264_nvenc_encoder;
863+
extern const FFCodec ff_h264_oh_decoder;
863864
extern const FFCodec ff_h264_omx_encoder;
864865
extern const FFCodec ff_h264_qsv_encoder;
865866
extern const FFCodec ff_h264_v4l2m2m_encoder;
@@ -874,6 +875,7 @@ extern const FFCodec ff_hevc_mediacodec_decoder;
874875
extern const FFCodec ff_hevc_mediacodec_encoder;
875876
extern const FFCodec ff_hevc_mf_encoder;
876877
extern const FFCodec ff_hevc_nvenc_encoder;
878+
extern const FFCodec ff_hevc_oh_decoder;
877879
extern const FFCodec ff_hevc_qsv_encoder;
878880
extern const FFCodec ff_hevc_v4l2m2m_encoder;
879881
extern const FFCodec ff_hevc_vaapi_encoder;

libavcodec/ohcodec.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This file is part of FFmpeg.
3+
*
4+
* Copyright (c) 2025 Zhao Zhili <[email protected]>
5+
*
6+
* FFmpeg is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2.1 of the License, or (at your option) any later version.
10+
*
11+
* FFmpeg is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with FFmpeg; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "ohcodec.h"
22+
23+
#include "libavutil/error.h"
24+
25+
int ff_oh_err_to_ff_err(OH_AVErrCode err)
26+
{
27+
switch (err) {
28+
case AV_ERR_OK:
29+
return 0;
30+
case AV_ERR_NO_MEMORY:
31+
return AVERROR(ENOMEM);
32+
case AV_ERR_OPERATE_NOT_PERMIT:
33+
return AVERROR(EPERM);
34+
case AV_ERR_INVALID_VAL:
35+
return AVERROR(EINVAL);
36+
case AV_ERR_IO:
37+
return AVERROR(EIO);
38+
case AV_ERR_TIMEOUT:
39+
return AVERROR(ETIMEDOUT);
40+
case AV_ERR_UNKNOWN:
41+
return AVERROR_UNKNOWN;
42+
case AV_ERR_SERVICE_DIED:
43+
return AVERROR_EXTERNAL;
44+
case AV_ERR_INVALID_STATE:
45+
return AVERROR(EINVAL);
46+
case AV_ERR_UNSUPPORT:
47+
return AVERROR(ENOTSUP);
48+
default:
49+
return AVERROR_EXTERNAL;
50+
}
51+
}
52+
53+
static const struct {
54+
OH_AVPixelFormat oh_pix;
55+
enum AVPixelFormat pix;
56+
} oh_pix_map[] = {
57+
{AV_PIXEL_FORMAT_NV12, AV_PIX_FMT_NV12},
58+
{AV_PIXEL_FORMAT_NV21, AV_PIX_FMT_NV21},
59+
{AV_PIXEL_FORMAT_YUVI420, AV_PIX_FMT_YUV420P},
60+
{AV_PIXEL_FORMAT_SURFACE_FORMAT, AV_PIX_FMT_OHCODEC},
61+
};
62+
63+
enum AVPixelFormat ff_oh_pix_to_ff_pix(OH_AVPixelFormat oh_pix)
64+
{
65+
for (size_t i = 0; i < FF_ARRAY_ELEMS(oh_pix_map); i++)
66+
if (oh_pix_map[i].oh_pix == oh_pix)
67+
return oh_pix_map[i].pix;
68+
69+
return AV_PIX_FMT_NONE;
70+
}
71+

libavcodec/ohcodec.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of FFmpeg.
3+
*
4+
* Copyright (c) 2025 Zhao Zhili <[email protected]>
5+
*
6+
* FFmpeg is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2.1 of the License, or (at your option) any later version.
10+
*
11+
* FFmpeg is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with FFmpeg; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#ifndef AVCODEC_OHCODEC_H
22+
#define AVCODEC_OHCODEC_H
23+
24+
#include <multimedia/player_framework/native_avbuffer.h>
25+
#include <multimedia/player_framework/native_avcodec_base.h>
26+
#include <multimedia/player_framework/native_averrors.h>
27+
#include <multimedia/player_framework/native_avformat.h>
28+
29+
#include "libavutil/pixfmt.h"
30+
31+
#include "codec_id.h"
32+
33+
typedef struct OHBufferQueueItem {
34+
uint32_t index;
35+
OH_AVBuffer *buffer;
36+
} OHBufferQueueItem;
37+
38+
int ff_oh_err_to_ff_err(OH_AVErrCode err);
39+
40+
static inline const char *ff_oh_mime(enum AVCodecID codec_id, void *log)
41+
{
42+
switch (codec_id) {
43+
case AV_CODEC_ID_H264:
44+
return OH_AVCODEC_MIMETYPE_VIDEO_AVC;
45+
case AV_CODEC_ID_HEVC:
46+
return OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
47+
default:
48+
av_log(log, AV_LOG_ERROR, "Unsupported codec %s\n",
49+
avcodec_get_name(codec_id));
50+
return NULL;
51+
}
52+
}
53+
54+
enum AVPixelFormat ff_oh_pix_to_ff_pix(OH_AVPixelFormat oh_pix);
55+
56+
#endif

0 commit comments

Comments
 (0)