Loading media/codec2/components/hevc/C2SoftHevcEnc.cpp +33 −22 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -73,6 +73,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { 0u, (uint64_t)C2MemoryUsage::CPU_READ)) .build()); // matches size limits in codec library addParameter( DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE) .withDefault(new C2StreamPictureSizeInfo::input(0u, 320, 240)) Loading @@ -91,6 +92,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { Setter<decltype(*mFrameRate)>::StrictValueWithNoDeps) .build()); // matches limits in codec library addParameter( DefineParam(mBitrate, C2_PARAMKEY_BITRATE) .withDefault(new C2StreamBitrateInfo::output(0u, 64000)) Loading @@ -98,6 +100,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { .withSetter(BitrateSetter) .build()); // matches levels allowed within codec library addParameter( DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL) .withDefault(new C2StreamProfileLevelInfo::output( Loading Loading @@ -137,7 +140,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { C2P<C2StreamBitrateInfo::output>& me) { (void)mayBlock; C2R res = C2R::Ok(); if (me.v.value <= 4096) { if (me.v.value < 4096) { me.set().value = 4096; } return res; Loading Loading @@ -304,18 +307,21 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel; std::shared_ptr<C2StreamSyncFrameIntervalTuning::output> mSyncFramePeriod; }; constexpr char COMPONENT_NAME[] = "c2.android.hevc.encoder"; static size_t GetCPUCoreCount() { long cpuCoreCount = 1; long cpuCoreCount = 0; #if defined(_SC_NPROCESSORS_ONLN) cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN); #else // _SC_NPROC_ONLN must be defined... cpuCoreCount = sysconf(_SC_NPROC_ONLN); #endif CHECK(cpuCoreCount >= 1); ALOGV("Number of CPU cores: %ld", cpuCoreCount); if (cpuCoreCount < 1) cpuCoreCount = 1; return (size_t)cpuCoreCount; } Loading Loading @@ -383,7 +389,7 @@ static void fillEmptyWork(const std::unique_ptr<C2Work>& work) { c2_status_t C2SoftHevcEnc::initEncParams() { mCodecCtx = nullptr; mNumCores = MIN(GetCPUCoreCount(), CODEC_MAX_CORES); mNumCores = std::min(GetCPUCoreCount(), (size_t) CODEC_MAX_CORES); memset(&mEncParams, 0, sizeof(ihevce_static_cfg_params_t)); // default configuration Loading @@ -397,7 +403,8 @@ c2_status_t C2SoftHevcEnc::initEncParams() { mEncParams.s_src_prms.i4_width = mSize->width; mEncParams.s_src_prms.i4_height = mSize->height; mEncParams.s_src_prms.i4_frm_rate_denom = 1000; mEncParams.s_src_prms.i4_frm_rate_num = mFrameRate->value * mEncParams.s_src_prms.i4_frm_rate_denom; mEncParams.s_src_prms.i4_frm_rate_num = mFrameRate->value * mEncParams.s_src_prms.i4_frm_rate_denom; mEncParams.s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset = IHEVCE_QUALITY_P5; mEncParams.s_tgt_lyr_prms.as_tgt_params[0].ai4_tgt_bitrate[0] = mBitrate->value; Loading Loading @@ -470,7 +477,7 @@ c2_status_t C2SoftHevcEnc::setEncodeArgs(ihevce_inp_buf_t* ps_encode_ip, const C2GraphicView* const input, uint64_t timestamp) { ihevce_static_cfg_params_t* params = &mEncParams; memset(ps_encode_ip, 0, sizeof(ihevce_inp_buf_t)); memset(ps_encode_ip, 0, sizeof(*ps_encode_ip)); if (!input) { return C2_OK; Loading @@ -495,13 +502,14 @@ c2_status_t C2SoftHevcEnc::setEncodeArgs(ihevce_inp_buf_t* ps_encode_ip, int32_t uStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc; int32_t vStride = layout.planes[C2PlanarLayout::PLANE_V].rowInc; uint32_t width = mSize->width; uint32_t height = mSize->height; const uint32_t width = mSize->width; const uint32_t height = mSize->height; // width and height are always even // width and height are always even (as block size is 16x16) CHECK_EQ((width & 1u), 0u); CHECK_EQ((height & 1u), 0u); // width and height must be even if (width & 1u || height & 1u) { ALOGW("height(%u) and width(%u) must both be even", height, width); return C2_BAD_VALUE; } size_t yPlaneSize = width * height; Loading Loading @@ -650,6 +658,7 @@ void C2SoftHevcEnc::process(const std::unique_ptr<C2Work>& work, if (view->error() != C2_OK) { ALOGE("graphic view map err = %d", view->error()); mSignalledError = true; work->result = C2_CORRUPTED; return; } } Loading Loading @@ -687,8 +696,8 @@ void C2SoftHevcEnc::process(const std::unique_ptr<C2Work>& work, status = setEncodeArgs(&s_encode_ip, view.get(), timestamp); if (C2_OK != status) { mSignalledError = true; ALOGE("setEncodeArgs failed : 0x%x", status); mSignalledError = true; work->result = status; return; } Loading Loading @@ -761,8 +770,9 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { : mHelper(std::static_pointer_cast<C2ReflectorHelper>( GetCodec2PlatformComponentStore()->getParamReflector())) {} virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, std::function<void(C2Component*)> deleter) override { *component = std::shared_ptr<C2Component>( new C2SoftHevcEnc( Loading @@ -772,8 +782,9 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { return C2_OK; } virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, std::function<void(C2ComponentInterface*)> deleter) override { *interface = std::shared_ptr<C2ComponentInterface>( new SimpleInterface<C2SoftHevcEnc::IntfImpl>( Loading @@ -783,7 +794,7 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { return C2_OK; } virtual ~C2SoftHevcEncFactory() override = default; ~C2SoftHevcEncFactory() override = default; private: std::shared_ptr<C2ReflectorHelper> mHelper; Loading media/codec2/components/hevc/C2SoftHevcEnc.h +6 −6 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -17,18 +17,18 @@ #ifndef ANDROID_C2_SOFT_HEVC_ENC_H_ #define ANDROID_C2_SOFT_HEVC_ENC_H_ #include <SimpleC2Component.h> #include <algorithm> #include <map> #include <utils/Vector.h> #include <media/stagefright/foundation/ColorUtils.h> #include <SimpleC2Component.h> #include <utils/Vector.h> #include "ihevc_typedefs.h" namespace android { #define MIN(a, b) ((a) < (b)) ? (a) : (b) /** Get time */ #define GETTIME(a, b) gettimeofday(a, b); #define GETTIME(a, b) gettimeofday(a, b) /** Compute difference between start and end */ #define TIME_DIFF(start, end, diff) \ Loading @@ -55,7 +55,7 @@ struct C2SoftHevcEnc : public SimpleC2Component { const std::shared_ptr<C2BlockPool>& pool) override; protected: virtual ~C2SoftHevcEnc(); ~C2SoftHevcEnc() override; private: std::shared_ptr<IntfImpl> mIntf; Loading Loading
media/codec2/components/hevc/C2SoftHevcEnc.cpp +33 −22 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -73,6 +73,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { 0u, (uint64_t)C2MemoryUsage::CPU_READ)) .build()); // matches size limits in codec library addParameter( DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE) .withDefault(new C2StreamPictureSizeInfo::input(0u, 320, 240)) Loading @@ -91,6 +92,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { Setter<decltype(*mFrameRate)>::StrictValueWithNoDeps) .build()); // matches limits in codec library addParameter( DefineParam(mBitrate, C2_PARAMKEY_BITRATE) .withDefault(new C2StreamBitrateInfo::output(0u, 64000)) Loading @@ -98,6 +100,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { .withSetter(BitrateSetter) .build()); // matches levels allowed within codec library addParameter( DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL) .withDefault(new C2StreamProfileLevelInfo::output( Loading Loading @@ -137,7 +140,7 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { C2P<C2StreamBitrateInfo::output>& me) { (void)mayBlock; C2R res = C2R::Ok(); if (me.v.value <= 4096) { if (me.v.value < 4096) { me.set().value = 4096; } return res; Loading Loading @@ -304,18 +307,21 @@ class C2SoftHevcEnc::IntfImpl : public C2InterfaceHelper { std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel; std::shared_ptr<C2StreamSyncFrameIntervalTuning::output> mSyncFramePeriod; }; constexpr char COMPONENT_NAME[] = "c2.android.hevc.encoder"; static size_t GetCPUCoreCount() { long cpuCoreCount = 1; long cpuCoreCount = 0; #if defined(_SC_NPROCESSORS_ONLN) cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN); #else // _SC_NPROC_ONLN must be defined... cpuCoreCount = sysconf(_SC_NPROC_ONLN); #endif CHECK(cpuCoreCount >= 1); ALOGV("Number of CPU cores: %ld", cpuCoreCount); if (cpuCoreCount < 1) cpuCoreCount = 1; return (size_t)cpuCoreCount; } Loading Loading @@ -383,7 +389,7 @@ static void fillEmptyWork(const std::unique_ptr<C2Work>& work) { c2_status_t C2SoftHevcEnc::initEncParams() { mCodecCtx = nullptr; mNumCores = MIN(GetCPUCoreCount(), CODEC_MAX_CORES); mNumCores = std::min(GetCPUCoreCount(), (size_t) CODEC_MAX_CORES); memset(&mEncParams, 0, sizeof(ihevce_static_cfg_params_t)); // default configuration Loading @@ -397,7 +403,8 @@ c2_status_t C2SoftHevcEnc::initEncParams() { mEncParams.s_src_prms.i4_width = mSize->width; mEncParams.s_src_prms.i4_height = mSize->height; mEncParams.s_src_prms.i4_frm_rate_denom = 1000; mEncParams.s_src_prms.i4_frm_rate_num = mFrameRate->value * mEncParams.s_src_prms.i4_frm_rate_denom; mEncParams.s_src_prms.i4_frm_rate_num = mFrameRate->value * mEncParams.s_src_prms.i4_frm_rate_denom; mEncParams.s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset = IHEVCE_QUALITY_P5; mEncParams.s_tgt_lyr_prms.as_tgt_params[0].ai4_tgt_bitrate[0] = mBitrate->value; Loading Loading @@ -470,7 +477,7 @@ c2_status_t C2SoftHevcEnc::setEncodeArgs(ihevce_inp_buf_t* ps_encode_ip, const C2GraphicView* const input, uint64_t timestamp) { ihevce_static_cfg_params_t* params = &mEncParams; memset(ps_encode_ip, 0, sizeof(ihevce_inp_buf_t)); memset(ps_encode_ip, 0, sizeof(*ps_encode_ip)); if (!input) { return C2_OK; Loading @@ -495,13 +502,14 @@ c2_status_t C2SoftHevcEnc::setEncodeArgs(ihevce_inp_buf_t* ps_encode_ip, int32_t uStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc; int32_t vStride = layout.planes[C2PlanarLayout::PLANE_V].rowInc; uint32_t width = mSize->width; uint32_t height = mSize->height; const uint32_t width = mSize->width; const uint32_t height = mSize->height; // width and height are always even // width and height are always even (as block size is 16x16) CHECK_EQ((width & 1u), 0u); CHECK_EQ((height & 1u), 0u); // width and height must be even if (width & 1u || height & 1u) { ALOGW("height(%u) and width(%u) must both be even", height, width); return C2_BAD_VALUE; } size_t yPlaneSize = width * height; Loading Loading @@ -650,6 +658,7 @@ void C2SoftHevcEnc::process(const std::unique_ptr<C2Work>& work, if (view->error() != C2_OK) { ALOGE("graphic view map err = %d", view->error()); mSignalledError = true; work->result = C2_CORRUPTED; return; } } Loading Loading @@ -687,8 +696,8 @@ void C2SoftHevcEnc::process(const std::unique_ptr<C2Work>& work, status = setEncodeArgs(&s_encode_ip, view.get(), timestamp); if (C2_OK != status) { mSignalledError = true; ALOGE("setEncodeArgs failed : 0x%x", status); mSignalledError = true; work->result = status; return; } Loading Loading @@ -761,8 +770,9 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { : mHelper(std::static_pointer_cast<C2ReflectorHelper>( GetCodec2PlatformComponentStore()->getParamReflector())) {} virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, std::function<void(C2Component*)> deleter) override { *component = std::shared_ptr<C2Component>( new C2SoftHevcEnc( Loading @@ -772,8 +782,9 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { return C2_OK; } virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, std::function<void(C2ComponentInterface*)> deleter) override { *interface = std::shared_ptr<C2ComponentInterface>( new SimpleInterface<C2SoftHevcEnc::IntfImpl>( Loading @@ -783,7 +794,7 @@ class C2SoftHevcEncFactory : public C2ComponentFactory { return C2_OK; } virtual ~C2SoftHevcEncFactory() override = default; ~C2SoftHevcEncFactory() override = default; private: std::shared_ptr<C2ReflectorHelper> mHelper; Loading
media/codec2/components/hevc/C2SoftHevcEnc.h +6 −6 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -17,18 +17,18 @@ #ifndef ANDROID_C2_SOFT_HEVC_ENC_H_ #define ANDROID_C2_SOFT_HEVC_ENC_H_ #include <SimpleC2Component.h> #include <algorithm> #include <map> #include <utils/Vector.h> #include <media/stagefright/foundation/ColorUtils.h> #include <SimpleC2Component.h> #include <utils/Vector.h> #include "ihevc_typedefs.h" namespace android { #define MIN(a, b) ((a) < (b)) ? (a) : (b) /** Get time */ #define GETTIME(a, b) gettimeofday(a, b); #define GETTIME(a, b) gettimeofday(a, b) /** Compute difference between start and end */ #define TIME_DIFF(start, end, diff) \ Loading @@ -55,7 +55,7 @@ struct C2SoftHevcEnc : public SimpleC2Component { const std::shared_ptr<C2BlockPool>& pool) override; protected: virtual ~C2SoftHevcEnc(); ~C2SoftHevcEnc() override; private: std::shared_ptr<IntfImpl> mIntf; Loading