From 8c636aa199d9dbf3782da3116c17eac514f5ee3f Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 23:02:00 +0800 Subject: [PATCH 01/62] avrecorder ndk demo Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/.gitignore | 11 + .../Media/AVRecorder/AppScope/app.json5 | 24 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes code/DocsSample/Media/AVRecorder/BUILD.gn | 33 + code/DocsSample/Media/AVRecorder/Test.json | 28 + .../Media/AVRecorder/build-profile.json5 | 58 ++ .../Media/AVRecorder/entry/.gitignore | 6 + .../AVRecorder/entry/build-profile.json5 | 33 + .../Media/AVRecorder/entry/hvigorfile.ts | 15 + .../AVRecorder/entry/oh-package-lock.json5 | 18 + .../Media/AVRecorder/entry/oh-package.json5 | 26 + .../entry/src/main/cpp/CMakeLists.txt | 18 + .../src/main/cpp/avrecorder_ndk_test.cpp | 539 ++++++++++ .../entry/src/main/cpp/camera_manager.cpp | 965 ++++++++++++++++++ .../entry/src/main/cpp/camera_manager.h | 170 +++ .../entry/src/main/cpp/log_common.h | 26 + .../AVRecorder/entry/src/main/cpp/main.h | 25 + .../AVRecorder/entry/src/main/cpp/muxer.cpp | 73 ++ .../AVRecorder/entry/src/main/cpp/muxer.h | 41 + .../entry/src/main/cpp/sample_info.h | 135 +++ .../src/main/cpp/types/libentry/index.d.ts | 45 + .../main/cpp/types/libentry/oh-package.json5 | 20 + .../src/main/cpp/video_encoder_sample.cpp | 57 ++ .../entry/src/main/cpp/video_encoder_sample.h | 35 + .../src/main/ets/entryability/EntryAbility.ts | 55 + .../entry/src/main/ets/pages/Index.ets | 34 + .../AVRecorder/entry/src/main/module.json5 | 52 + .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 16 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 16 + .../main/resources/zh_CN/element/string.json | 16 + .../AVRecorder/hvigor/hvigor-config.json5 | 20 + .../DocsSample/Media/AVRecorder/hvigorfile.ts | 16 + code/DocsSample/Media/AVRecorder/hvigorw | 60 ++ code/DocsSample/Media/AVRecorder/hvigorw.bat | 63 ++ .../Media/AVRecorder/oh-package-lock.json5 | 19 + .../Media/AVRecorder/oh-package.json5 | 29 + 40 files changed, 2818 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/.gitignore create mode 100644 code/DocsSample/Media/AVRecorder/AppScope/app.json5 create mode 100644 code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json create mode 100644 code/DocsSample/Media/AVRecorder/AppScope/resources/base/media/app_icon.png create mode 100644 code/DocsSample/Media/AVRecorder/BUILD.gn create mode 100644 code/DocsSample/Media/AVRecorder/Test.json create mode 100644 code/DocsSample/Media/AVRecorder/build-profile.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/.gitignore create mode 100644 code/DocsSample/Media/AVRecorder/entry/build-profile.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts create mode 100644 code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/oh-package.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/CMakeLists.txt create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/color.json create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/icon.png create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/profile/main_pages.json create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json create mode 100644 code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5 create mode 100644 code/DocsSample/Media/AVRecorder/hvigorfile.ts create mode 100644 code/DocsSample/Media/AVRecorder/hvigorw create mode 100644 code/DocsSample/Media/AVRecorder/hvigorw.bat create mode 100644 code/DocsSample/Media/AVRecorder/oh-package-lock.json5 create mode 100644 code/DocsSample/Media/AVRecorder/oh-package.json5 diff --git a/code/DocsSample/Media/AVRecorder/.gitignore b/code/DocsSample/Media/AVRecorder/.gitignore new file mode 100644 index 0000000000..fbabf77101 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/.gitignore @@ -0,0 +1,11 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/AppScope/app.json5 b/code/DocsSample/Media/AVRecorder/AppScope/app.json5 new file mode 100644 index 0000000000..792d76e965 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.example.avrecorderndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000..5697e168db --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVRecorderNDK" + } + ] +} diff --git a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y +#include +#include +#include +#include + +#define LOG_DOMIN 0x3200 +#define LOG_TAG "MY_NDKDEMO" + +#include +#include "native_image/native_image.h" +#include "native_window/external_window.h" +#include "camera_manager.h" +#include "GLES3/gl32.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace OHOS_CAMERA_SAMPLE; +static NDKCamera *ndkCamera_ = nullptr; + +static OH_AVRecorder_Config *config; +char *previceId_ = nullptr; +char *videoSrufaceId; +int videoFrameWidth_ = 1280; +int videoFrameHeight_ = 720; + +// 设置状态回调 +void OnStateChange(OH_AVRecorder *recorder, OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, + void *userData) { + (void)recorder; + (void)userData; + const char *reasonStr = (reason == AVRECORDER_USER) ? "USER" + : (reason == AVRECORDER_BACKGROUND) ? "BACKGROUND" + : "UNKNOWN"; +} +void OnError(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg, void *userData) { + (void)recorder; + (void)userData; +} + +// 设置生成媒体文件回调(媒体库尚未提供接口) +void OnUri(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userDate) { + (void)recorder; + (void)userDate; + OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri in!"); + if (asset != nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri in!"); + auto changeRequest = OH_MediaAssetChangeRequest_Create(asset); + if (changeRequest == nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== changeRequest is null!"); + return; + } + MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; + uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_MediaAssetChangeRequest_SaveCameraPhoto result:%{public}d!", result); + OH_MediaAsset_Release(asset); + OH_MediaAssetChangeRequest_Release(changeRequest); + } else { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Received null media asset! "); + } + OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri out ! "); +} + +static napi_value createAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = AV_ERR_OK; + g_avRecorder = OH_AVRecorder_Create(); + if (g_avRecorder == nullptr) { + result = AV_ERR_UNKNOWN; + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value setPreviewSurfaceId(napi_env env, napi_callback_info info) +{ + + (void)info; + // todo + int result = AV_ERR_OK; + if (result != AV_ERR_OK) { + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static bool GetInt32Property(napi_env env, napi_value root, const char *utf8name, int32_t *res) { + napi_value property = nullptr; + auto status = napi_get_named_property(env, root, utf8name, &property); + if (status != napi_ok || property == nullptr) { + return false; + } + return (napi_get_value_int32(env, property, res) == napi_ok); +} + +static bool parseSetConfigOps(napi_env env, napi_value arg, struct OH_AVRecorder_Config &config) { + + if (env == nullptr || arg == nullptr) { + return false; + } + // Optional parameters, no need check error. + GetInt32Property(env, arg, "audioBitrate", &(config.profile.audioBitrate)); + GetInt32Property(env, arg, "audioChannels", &(config.profile.audioChannels)); + GetInt32Property(env, arg, "audioSampleRate", &(config.profile.audioSampleRate)); + + GetInt32Property(env, arg, "videoBitrate", &(config.profile.videoBitrate)); + GetInt32Property(env, arg, "videoFrameWidth", &(config.profile.videoFrameWidth)); + GetInt32Property(env, arg, "videoFrameHeight", &(config.profile.videoFrameHeight)); + GetInt32Property(env, arg, "videoFrameRate", &(config.profile.videoFrameRate)); + int32_t fileFormat = -1; + GetInt32Property(env, arg, "fileFormat", &fileFormat); + switch (fileFormat) { + case AVRECORDER_CFT_MPEG_4: + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; + break; + case AVRECORDER_CFT_MPEG_4A: + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4A; + break; + case AVRECORDER_CFT_MP3: + config.profile.fileFormat = AVRECORDER_CFT_MP3; + break; + case AVRECORDER_CFT_WAV: + config.profile.fileFormat = AVRECORDER_CFT_WAV; + break; + default: + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; + break; + } + return true; +} + +// 配置参数 +void setConfig(OH_AVRecorder_Config &config) { + config.audioSourceType = AVRECORDER_DEFAULT; + config.videoSourceType = AVRECORDER_SURFACE_YUV; + // 设置媒体属性 + config.profile.audioBitrate = 48000; + config.profile.audioChannels = 2; + config.profile.audioCodec = AVRECORDER_AUDIO_AAC; + config.profile.audioSampleRate = 48000; + + config.profile.videoBitrate = 2000000; + config.profile.videoFrameWidth = videoFrameWidth_; + config.profile.videoFrameHeight = videoFrameHeight_; + config.profile.videoFrameRate = 30; + config.profile.videoCodec = AVRECORDER_VIDEO_AVC; + config.profile.isHdr = false; + config.profile.enableTemporalScale = true; + + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; + config.fileGenerationMode = AVRECORDER_APP_CREATE; + + config.metadata.videoOrientation = (char *)malloc(2); + if (config.metadata.videoOrientation != nullptr) { + strcpy(config.metadata.videoOrientation, "0"); + } + config.metadata.location.latitude = 0; + config.metadata.location.longitude = 0; +} + +static napi_value prepareAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); + OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); + setConfig(*config); + + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); + char *fd = nullptr; + size_t typeLen = 0; + napi_get_value_string_utf8(env, args[1], nullptr, 0, &typeLen); + fd = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[1], fd, typeLen + 1, &typeLen); + config->url = fd; + + OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); + parseSetConfigOps(env, args[0], *config); + + OH_LOG_INFO(LOG_APP, "---------AVRecorder config.url = fd: %{public}s", config->url); + OH_LOG_INFO(LOG_APP, "---------AVRecorder config.profile.videoFrameWidth = fd: %{public}", + config->profile.videoFrameWidth); + OH_LOG_INFO(LOG_APP, "---------AVRecorder config.url.profile.videoFrameHeight = fd: %{public}", + config->profile.videoFrameHeight); + OH_AVRecorder_SetStateCallback(g_avRecorder, OnStateChange, nullptr); + OH_AVRecorder_SetErrorCallback(g_avRecorder, OnError, nullptr); + + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback in"); + OH_AVErrCode ret = OH_AVRecorder_SetUriCallback(g_avRecorder, OnUri, nullptr); + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback out"); + + if (ret == AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback successed"); + } else { + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback error code :%{public}d", ret); + } + + int result = AV_ERR_OK; + result = OH_AVRecorder_Prepare(g_avRecorder, config); + if (result != AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Prepare error code :%{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder out"); + return res; +} + +static napi_value createPrepareAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = AV_ERR_OK; + g_avRecorder = OH_AVRecorder_Create(); + if (g_avRecorder == nullptr) { + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Create error code :%{public}d", result); + } + OH_AVRecorder_Config *config1 = new OH_AVRecorder_Config(); + setConfig(*config1); + + // 1.1 设置url + const std::string AVRECORDER_ROOT = "/data/storage/el2/base/files/"; + int32_t outputFd = open((AVRECORDER_ROOT + "avrecorder001.mp4").c_str(), O_RDWR | O_CREAT, 0777); + std::string fileUrl = "fd://" + std::to_string(outputFd); + config1->url = const_cast(fileUrl.c_str()); + std::cout << "config1.url is:" << config->url << std::endl; + + OH_AVRecorder_SetStateCallback(g_avRecorder, OnStateChange, nullptr); + OH_AVRecorder_SetErrorCallback(g_avRecorder, OnError, nullptr); + + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback in"); + OH_AVErrCode ret = OH_AVRecorder_SetUriCallback(g_avRecorder, OnUri, nullptr); + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback out"); + + int result1 = OH_AVRecorder_Prepare(g_avRecorder, config1); + if (result1 != AV_ERR_OK || result != AV_ERR_OK) { + result = AV_ERR_UNKNOWN; + OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Prepare error code :%{public}d", result1); + } + + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value startAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Start(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Start failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value pauseAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Pause(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Pause failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value resumeAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Resume(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Resume failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value stopAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Stop(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Stop failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 7. 重置录制 +static napi_value resetAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + if (g_avRecorder == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); + napi_value res; + napi_create_int32(env, AV_ERR_INVALID_VAL, &res); + return res; + } + + int result = OH_AVRecorder_Reset(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Reset failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value releaseAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + if (g_avRecorder == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); + napi_value res; + napi_create_int32(env, AV_ERR_INVALID_VAL, &res); + return res; + } + int result = OH_AVRecorder_Release(g_avRecorder); + g_avRecorder = nullptr; + + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Release failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value getAVRecorderConfig(napi_env env, napi_callback_info info) +{ + (void)info; + + OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); + setConfig(*config); + int result = OH_AVRecorder_GetAVRecorderConfig(g_avRecorder, &config); + if (result != AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "---------NDK xts------getAVRecorderConfig error"); + } + OH_LOG_INFO(LOG_APP, "---------NDK xts------getAVRecorderConfig sucuess", config->profile.audioBitrate); + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value getAvailableEncoder(napi_env env, napi_callback_info info) +{ + (void)info; + + OH_AVRecorder_EncoderInfo *encoderInfo = nullptr; + + int32_t lengthValue = 0; + int32_t *length = &lengthValue; + + int result = OH_AVRecorder_GetAvailableEncoder(g_avRecorder, &encoderInfo, length); + + if (result != AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "---------NDK xts------getAvailableEncorder error"); + } else { + if (encoderInfo != nullptr) { + OH_LOG_INFO(LOG_APP, "Encorder Info in"); + OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", encoderInfo->mimeType); + + OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", encoderInfo->type); + // bitRate + OH_LOG_INFO(LOG_APP, "Encorder BitRate Min: %{public}d,Max :%{public}d", encoderInfo->bitRate.min, + encoderInfo->bitRate.max); + // frameRate + OH_LOG_INFO(LOG_APP, "Encorder frameRate Min: %{public}d,Max :%{public}d", encoderInfo->frameRate.min, + encoderInfo->frameRate.max); + // width + OH_LOG_INFO(LOG_APP, "Encorder width Min: %{public}d,Max :%{public}d", encoderInfo->width.min, + encoderInfo->width.max); + // height + OH_LOG_INFO(LOG_APP, "Encorder height Min: %{public}d,Max :%{public}d", encoderInfo->height.min, + encoderInfo->height.max); + // channels + OH_LOG_INFO(LOG_APP, "Encorder channels Min: %{public}d,Max :%{public}d", encoderInfo->channels.min, + encoderInfo->channels.max); + + if (encoderInfo->sampleRate != nullptr) { + for (int i = 0; i < encoderInfo->sampleRateLen; i++) { + OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", i, encoderInfo->sampleRate[i]); + } + } + } else { + OH_LOG_INFO(LOG_APP, "EncorderInfo is null"); + } + } + + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value updateRotationAVRecorder(napi_env env, napi_callback_info info) +{ + + (void)info; + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t videoRotation; + napi_get_value_int32(env, args[0], &videoRotation); + + int result = AV_ERR_OK; + result = OH_AVRecorder_UpdateRotation(g_avRecorder, videoRotation); + OH_LOG_INFO(LOG_APP, "---------AVRecorder updateRotationAVRecorder result :%{public}d", result); + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +static napi_value prepareCamera(napi_env env, napi_callback_info info) +{ + size_t argc = 8; + napi_value args[8] = {nullptr}; + size_t typeLen = 0; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t focusMode; + napi_get_value_int32(env, args[0], &focusMode); + + uint32_t cameraDeviceIndex; + napi_get_value_uint32(env, args[1], &cameraDeviceIndex); + + uint32_t sceneMode; + napi_get_value_uint32(env, args[2], &sceneMode); + + char *previewId = nullptr; + napi_get_value_string_utf8(env, args[3], nullptr, 0, &typeLen); + previewId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[3], previewId, typeLen + 1, &typeLen); + + char *photoId = nullptr; + napi_get_value_string_utf8(env, args[4], nullptr, 0, &typeLen); + photoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[4], photoId, typeLen + 1, &typeLen); + + uint32_t videoFrameWidth; + napi_get_value_uint32(env, args[6], &videoFrameWidth); + uint32_t videoFrameHeight; + napi_get_value_uint32(env, args[7], &videoFrameHeight); + + // 获取surfaceId + OHNativeWindow *window; + int resultCode = OH_AVRecorder_GetInputSurface(g_avRecorder, &window); + if (resultCode != AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare Camera error"); + } + uint64_t surfaceId; + OH_NativeWindow_GetSurfaceId(window, &surfaceId); + char videoId[30]; + OH_LOG_INFO(LOG_APP, "init Camera fouseMode : %{public}d", focusMode); + OH_LOG_INFO(LOG_APP, "init Camera cameraDeviceIndex : %{public}d", cameraDeviceIndex); + OH_LOG_INFO(LOG_APP, "init Camera sceneMode : %{public}d", sceneMode); + OH_LOG_INFO(LOG_APP, "init Camera previewId : %{public}d", previewId); + OH_LOG_INFO(LOG_APP, "init Camera photo : %{public}d", photoId); + OH_LOG_INFO(LOG_APP, "init Camera video : %{public}d", videoId); + + ndkCamera_ = new NDKCamera(focusMode, cameraDeviceIndex, sceneMode, previewId, photoId, videoId); + int result = 6; + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"createAVRecorder", nullptr, createAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"prepareAVRecorder", nullptr, prepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createPrepareAVRecorder", nullptr, createPrepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"startAVRecorder", nullptr, startAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"pauseAVRecorder", nullptr, pauseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"resumeAVRecorder", nullptr, resumeAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"stopAVRecorder", nullptr, stopAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"resetAVRecorder", nullptr, resetAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"releaseAVRecorder", nullptr, releaseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"updateRotationAVRecorder", nullptr, updateRotationAVRecorder, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"prepareCamera", nullptr, prepareCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setPreviewSurfaceId", nullptr, setPreviewSurfaceId, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAVRecorderConfig", nullptr, getAVRecorderConfig, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAvailableEncoder", nullptr, getAvailableEncoder, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "avrecorderndk", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp new file mode 100644 index 0000000000..53441ed549 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp @@ -0,0 +1,965 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "camera_manager.h" + +#define LOG_TAG "MY_NDKDEMO" +#define LOG_DOMAIN 0x3200 + +namespace OHOS_CAMERA_SAMPLE { +NDKCamera *NDKCamera::ndkCamera_ = nullptr; +std::mutex NDKCamera::mtx_; +const std::unordered_map g_int32ToCameraSceneMode = { + {1, Camera_SceneMode::NORMAL_PHOTO}, {2, Camera_SceneMode::NORMAL_VIDEO}, {12, Camera_SceneMode::SECURE_PHOTO}}; + +NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, char *previewId, char *photoId, + char *videoId) + : focusMode_(focusMode), cameraDeviceIndex_(cameraDeviceIndex), previewSurfaceId_(previewId), + photoSurfaceId_(photoId), videoSurfaceId_(videoId), cameras_(nullptr), profile_(nullptr), + cameraOutputCapability_(nullptr), captureSession_(nullptr), cameraInput_(nullptr), previewOutput_(nullptr), + photoOutput_(nullptr), videoOutput_(nullptr), isCameraMuted_(nullptr), metaDataObjectType_(nullptr), + metadataOutput_(nullptr), isExposureModeSupported_(false), isFocusModeSupported_(false), isSuccess_(false), + sceneMode_(NORMAL_PHOTO), exposureMode_(EXPOSURE_MODE_LOCKED), ret_(CAMERA_OK), size_(0), minExposureBias_(0), + maxExposureBias_(0), step_(0) { + // release camera + ReleaseCamera(); + + // create camera manager + Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager_); + if (cameraManager_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Get CameraManager failed."); + } + OH_LOG_ERROR(LOG_APP, "=====testZj2====."); + + // create capture session + ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); + if (captureSession_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); + } + OH_LOG_ERROR(LOG_APP, "=====testZj3====."); + + // look up sceneMode + auto itr1 = g_int32ToCameraSceneMode.find(sceneMode); + if (itr1 != g_int32ToCameraSceneMode.end()) { + sceneMode_ = itr1->second; + } + + // set session mode + ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); + + OH_LOG_ERROR(LOG_APP, "=====testZj4====."); + + // get capture session profile + GetSupportedCameras(); + GetSupportedOutputCapability(); + + // create preview output + CreatePreviewOutput(); + + // create camera input and register camera input callback + CreateCameraInput(); + CameraInputOpen(); + + // config and start session + SessionFlowFn(); +} + +NDKCamera::~NDKCamera() { + OH_LOG_ERROR(LOG_APP, "~NDKCamera"); + Camera_ErrorCode ret = CAMERA_OK; + + if (cameraManager_) { + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. enter"); + ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed."); + } else { + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); + } + + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. enter"); + ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete Cameras failed."); + } else { + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. ok"); + } + + ret = OH_Camera_DeleteCameraManager(cameraManager_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete CameraManager failed."); + } else { + OH_LOG_ERROR(LOG_APP, "Release OH_Camera_DeleteCameraMananger. ok"); + } + cameraManager_ = nullptr; + } + OH_LOG_ERROR(LOG_APP, "~NDKCamera exit"); +} + +Camera_ErrorCode NDKCamera::ReleaseCamera(void) { + OH_LOG_ERROR(LOG_APP, " enter ReleaseCamera"); + if (previewOutput_ && captureSession_) { + PreviewOutputStop(); + OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_); + PreviewOutputRelease(); + } + if (photoOutput_) { + PhotoOutputRelease(); + } + + if (videoOutput_) { + VideoOutputRelease(); + } + if (captureSession_) { + SessionRealese(); + } + if (cameraInput_) { + CameraInputClose(); + } + OH_LOG_ERROR(LOG_APP, " exit ReleaseCamera"); + return ret_; +} + +Camera_ErrorCode NDKCamera::ReleaseSession(void) { + OH_LOG_ERROR(LOG_APP, " enter ReleaseSession"); + PreviewOutputStop(); + PhotoOutputRelease(); + VideoOutputRelease(); + SessionRealese(); + OH_LOG_ERROR(LOG_APP, " exit ReleaseSession"); + return ret_; +} + +Camera_ErrorCode NDKCamera::SessionRealese(void) { + OH_LOG_ERROR(LOG_APP, " enter SessionRealese"); + Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); + captureSession_ = nullptr; + OH_LOG_ERROR(LOG_APP, " exit SessionRealese"); + return ret; +} +// todo + + +Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) { + Camera_FlashMode flashMode = static_cast(mode); + // Check for flashing lights + bool hasFlash = false; + Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash); + if (captureSession_ == nullptr || ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_HasFlash success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed. %d ", ret); + } + if (hasFlash) { + OH_LOG_INFO(LOG_APP, "hasFlash success."); + } else { + OH_LOG_ERROR(LOG_APP, "hasFlash hasFlash failed. %d ", hasFlash); + } + + // Check if the flash mode is supported + bool isSupported = false; + ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsFlashModeSupported success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed. %d ", ret); + } + + if (isSupported) { + OH_LOG_INFO(LOG_APP, "isSupported success."); + } else { + OH_LOG_ERROR(LOG_APP, "isSupported failed. %d ", hasFlash); + } + + // Set flash mode + ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %d ", ret); + } + ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode failed. %d ", ret); + } + return ret; +} + + +Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode) { + Camera_VideoStabilizationMode videoMode = static_cast(mode); + bool isSupported = false; + + Camera_ErrorCode ret = + OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isSupported); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported failed. %d ", ret); + } + if (isSupported) { + OH_LOG_INFO(LOG_APP, "isSupported success."); + } else { + OH_LOG_ERROR(LOG_APP, "isSupported failed. %d ", isSupported); + } + + ret = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode videoMode failed. %d ", videoMode); + } + ret = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode videoMode failed. %d ", videoMode); + } + return ret; +} + +Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) { + float zoom = float(zoomRatio); + float minZoom; + float maxZoom; + + Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom); + if (captureSession_ == nullptr || ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed. %d ", ret); + } + + // Set Zoom + ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %d ", ret); + } + + ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::SessionBegin(void) { + Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_BeginConfig success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_BeginConfig failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::SessionCommitConfig(void) { + Camera_ErrorCode ret = OH_CaptureSession_CommitConfig(captureSession_); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_CommitConfig success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_CommitConfig failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::SessionStart(void) { + bool isSupport = false; + OH_CaptureSession_IsVideoStabilizationModeSupported( + captureSession_, Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO, &isSupport); + if (isSupport) { + OH_CaptureSession_SetVideoStabilizationMode(captureSession_, + Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); + } + // Start focusing + OH_LOG_INFO(LOG_APP, "IsFocusMode start"); + OH_CaptureSession_SetFocusMode(captureSession_, Camera_FocusMode::FOCUS_MODE_AUTO); + OH_LOG_INFO(LOG_APP, "IsFocusMode success"); + + Camera_ErrorCode ret = OH_CaptureSession_Start(captureSession_); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Start success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Start failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::SessionStop(void) { + Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Stop success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Stop failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::SessionFlowFn(void) { + OH_LOG_INFO(LOG_APP, "Start SessionFlowFn IN."); + // start configuring session + OH_LOG_INFO(LOG_APP, "session beginConfig."); + Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); + // add cameraInput to the session + OH_LOG_INFO(LOG_APP, "session add Input."); + ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); + // add previewOutput to the session + OH_LOG_INFO(LOG_APP, "session add Preview Output."); + ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); + + if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + CreateVideoOutput(videoSurfaceId_); + + AddVideoOutput(); + } + // Submit configuration information + OH_LOG_INFO(LOG_APP, "session commitConfig"); + ret = OH_CaptureSession_CommitConfig(captureSession_); + // Start Session Work + OH_LOG_INFO(LOG_APP, "session start"); + SessionStart(); + OH_LOG_INFO(LOG_APP, "session success"); + OH_VideoOutput_Start(videoOutput_); + + return ret; +} + +Camera_ErrorCode NDKCamera::CreateCameraInput(void) { + OH_LOG_ERROR(LOG_APP, "enter CreateCameraInput."); + ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, &cameras_[cameraDeviceIndex_], &cameraInput_); + if (cameraInput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CreateCameraInput failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit CreateCameraInput."); + // register camera input callback + CameraInputRegisterCallback(); + return ret_; +} + +Camera_ErrorCode NDKCamera::CameraInputOpen(void) { + OH_LOG_ERROR(LOG_APP, "enter CameraInputOpen."); + ret_ = OH_CameraInput_Open(cameraInput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CameraInput_Open failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit CameraInputOpen."); + return ret_; +} + +Camera_ErrorCode NDKCamera::CameraInputClose(void) { + OH_LOG_ERROR(LOG_APP, "enter CameraInput_Close."); + ret_ = OH_CameraInput_Close(cameraInput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CameraInput_Close failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit CameraInput_Close."); + return ret_; +} + +Camera_ErrorCode NDKCamera::CameraInputRelease(void) { + ret_ = OH_CameraInput_Release(cameraInput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CameraInputRelease failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit CameraInputRelease."); + return ret_; +} + +Camera_ErrorCode NDKCamera::GetSupportedCameras(void) { + ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, &size_); + if (cameras_ == nullptr || &size_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetSupportedCaneras failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit GetSupportedCaneras."); + return ret_; +} +Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void) { + ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, &cameras_[cameraDeviceIndex_], + &cameraOutputCapability_); + if (ret_ != CAMERA_OK || cameraOutputCapability_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "GetSupportedOutputCapability failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit GetSupportedOutputCapability."); + return ret_; +} + +Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) { + profile_ = cameraOutputCapability_->previewProfiles[0]; + if (profile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "exit CreatePreviewOutput."); + profile_->size.width = videoFrameWidth_; + profile_->size.height = videoFrameHeight_; + ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_); + + if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreatePreviewOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + // register preview output callback + PreviewOutputRegisterCallback(); + return ret_; +} + +Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId) { + DRAWING_LOGD("NDKCamera::CreatePhotoOutput start!"); + profile_ = cameraOutputCapability_->photoProfiles[0]; + if (profile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed."); + return CAMERA_INVALID_ARGUMENT; + } + profile_->size.width = videoFrameWidth_; + profile_->size.height = videoFrameHeight_; + ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_); + if (photoSurfaceId == nullptr || photoOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + // register photo output callback + PhotoOutputRegisterCallback(); + return ret_; +} + +Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) { + DRAWING_LOGD("NDKCamera::CreatePhotoOutput start!"); + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput width:%{public}d", videoProfile_->size.width); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput height:%{public}d", videoProfile_->size.height); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput format:%{public}d", videoProfile_->format); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.min:%{public}d", videoProfile_->range.min); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.max:%{public}d", videoProfile_->range.max); + + profile_->size.width = videoFrameWidth_; + profile_->size.height = videoFrameHeight_; + ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_); + if (videoId == nullptr || videoOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + // register photo output callback + VideoOutputRegisterCallback(); + return ret_; +} +Camera_ErrorCode NDKCamera::AddVideoOutput(void) { + Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); + if (ret == CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::AddPhotoOutput() { + Camera_ErrorCode ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); + if (ret == CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed. %d ", ret); + } + return ret; +} + +Camera_ErrorCode NDKCamera::CreateMetadataOutput(void) { + DRAWING_LOGD("NDKCamera::CreateMetadataOutput start!"); + metaDataObjectType_ = cameraOutputCapability_->supportedMetadataObjectTypes[0]; + if (metaDataObjectType_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get CreateMetadataOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, &metadataOutput_); + if (metadataOutput_ == nullptr || ret_ == CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateMetadataOutput success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateMetadataOutput failed. %d ", ret_); + } + // register metadata output callback + MetadataOutputRegisterCallback(); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsCameraMuted(void) { + OH_LOG_ERROR(LOG_APP, "enter IsCameraMuted."); + ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, isCameraMuted_); + if (isCameraMuted_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsCameraMuted failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret_; +} + +Camera_ErrorCode NDKCamera::PreviewOutputStop(void) { + OH_LOG_ERROR(LOG_APP, "enter PreviewOutputStop."); + ret_ = OH_PreviewOutput_Stop(previewOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "PreviewOutputStop failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret_; +} + +Camera_ErrorCode NDKCamera::PreviewOutputRelease(void) { + OH_LOG_ERROR(LOG_APP, "enter PreviewOutputRelease."); + if (previewOutput_ != nullptr) { + ret_ = OH_PreviewOutput_Release(previewOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "PreviewOutputRelease failed."); + return CAMERA_INVALID_ARGUMENT; + } + previewOutput_ = nullptr; + } + return CAMERA_OK; +} + +Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) { + OH_LOG_ERROR(LOG_APP, "enter PhotoOutputRelease."); + ret_ = OH_PhotoOutput_Release(photoOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "PhotoOutputRelease failed."); + return CAMERA_INVALID_ARGUMENT; + } + photoOutput_ = nullptr; + return ret_; +} + +Camera_ErrorCode NDKCamera::VideoOutputStart(void) { + OH_LOG_ERROR(LOG_APP, "enter VideoOutputStart."); + Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "VideoOutputStart failed."); + } + return ret; +} + +Camera_ErrorCode NDKCamera::IsExposureModeSupportedFn(uint32_t mode) { + OH_LOG_ERROR(LOG_APP, "enter IsExposureModeSupportedFn."); + exposureMode_ = static_cast(mode); + ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode_, &isExposureModeSupported_); + + if (&isExposureModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode_); + + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); + + if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsMeteringPoint(int x, int y) { + OH_LOG_ERROR(LOG_APP, "enter IsMeteringPoint."); + ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); + if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + return CAMERA_INVALID_ARGUMENT; + } + Camera_Point exposurePoint; + exposurePoint.x = x; + exposurePoint.y = y; + + ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, exposurePoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetMeteringPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, &exposurePoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetMeteringPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsMeteringPoint end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias) { + OH_LOG_ERROR(LOG_APP, "enter IsExposureBiasRange."); + float exposureBiasValue = (float)exposureBias; + ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_); + if (&minExposureBias_ == nullptr || &maxExposureBias_ == nullptr || &step_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBiasValue); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetExposureBias failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBiasValue); + if (&exposureBiasValue == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetExposureBias failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusModeSupported."); + Camera_FocusMode focusMode = static_cast(mode); + ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); + if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "IsFocusModeSupported end."); + return ret_; +} +Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusMode."); + Camera_FocusMode focusMode = static_cast(mode); + ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); + if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_SetFocusMode(captureSession_, focusMode); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "IsFocusMode end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsFocusPoint(float x, float y) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); + Camera_Point focusPoint; + focusPoint.x = x; + focusPoint.y = y; + ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, focusPoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint); + if (&focusPoint == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "IsFocusPoint end."); + return ret_; +} + +int32_t NDKCamera::GetVideoFrameWidth(void) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); + return videoProfile_->size.width; +} + +int32_t NDKCamera::GetVideoFrameHeight(void) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); + return videoProfile_->size.height; +} + +int32_t NDKCamera::GetVideoFrameRate(void) { + OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + + OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); + return videoProfile_->range.min; +} + +Camera_ErrorCode NDKCamera::VideoOutputStop(void) { + OH_LOG_ERROR(LOG_APP, " VideoOutputStop into"); + ret_ = OH_VideoOutput_Stop(videoOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret_; +} + +Camera_ErrorCode NDKCamera::VideoOutputRelease(void) { + OH_LOG_ERROR(LOG_APP, " VideoOutputRelease into"); + if (videoOutput_ == nullptr) { + return CAMERA_OK; + } + ret_ = OH_VideoOutput_Release(videoOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + return CAMERA_INVALID_ARGUMENT; + } + videoOutput_ = nullptr; + return ret_; +} +Camera_ErrorCode NDKCamera::TakePicture(void) { + Camera_ErrorCode ret = CAMERA_OK; + ret = OH_PhotoOutput_Capture(photoOutput_); + OH_LOG_ERROR(LOG_APP, "takePicture OH_PhotoOutput_Capture ret = %{public}d.", ret); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret; +} + +Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photosetting) { + Camera_ErrorCode ret = CAMERA_OK; + ret = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photosetting); + OH_LOG_ERROR(LOG_APP, "takePicture OH_PhotoOutput_Capture ret = %{public}d.", ret); + OH_LOG_ERROR(LOG_APP, + "TakePictureWithPhotoSettings get uality %{public}d,roration %{public}d,mirro %{public}d," + "latitude, %{public}d, longitude %{public}d, altitude %{public}d", + photosetting.quality, photosetting.rotation, photosetting.mirror, photosetting.location->latitude, + photosetting.location->longitude, photosetting.location->altitude); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret; +} + +// CameraManager Callback +void CameraManagerStatusCallback(Camera_Manager *cameraManager, Camera_StatusInfo *status) { + OH_LOG_INFO(LOG_APP, "CameraManagerStatusCallback"); +} + +CameraManager_Callbacks *NDKCamera::GetCameraManagerListener(void) { + static CameraManager_Callbacks cameraManagerListener = {.onCameraStatus = CameraManagerStatusCallback}; + return &cameraManagerListener; +} + +Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void) { + ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraManager_RegisterCallback failed."); + } + return ret_; +} + +// CameraInput Callback +void OnCameraInputError(const Camera_Input *cameraInput, Camera_ErrorCode errorCode) { + OH_LOG_INFO(LOG_APP, "OnCameraInput errorCode = %{public}d", errorCode); +} + +CameraInput_Callbacks *NDKCamera::GetCameraInputListener(void) { + static CameraInput_Callbacks cameraInputCallbacks = {.onError = OnCameraInputError}; + return &cameraInputCallbacks; +} + +Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void) { + ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraInput_RegisterCallback failed."); + } + return ret_; +} + +// PreviewOutput Callback +void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput) { + OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart"); +} + +void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameCount) { + OH_LOG_INFO(LOG_APP, "PreviewOutput frameCount = %{public}d", frameCount); +} + +void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode) { + OH_LOG_INFO(LOG_APP, "PreviewOutput errorCode = %{public}d", errorCode); +} + +PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void) { + static PreviewOutput_Callbacks previewOutputListener = {.onFrameStart = PreviewOutputOnFrameStart, + .onFrameEnd = PreviewOutputOnFrameEnd, + .onError = PreviewOutputOnError}; + return &previewOutputListener; +} + +Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void) { + ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_RegisterCallback failed."); + } + return ret_; +} + +// PhotoOutput Callback +void PhotoOutputOnFrameStart(Camera_PhotoOutput *photoOutput) { + DRAWING_LOGD("PhotoOutputOnFrameStart start!"); + OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameStart"); +} + +void PhotoOutputOnFrameShutter(Camera_PhotoOutput *photoOutput, Camera_FrameShutterInfo *info) { + DRAWING_LOGD("PhotoOutputOnFrameShutter start!"); + OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameShutter"); +} + +void PhotoOutputOnFrameEnd(Camera_PhotoOutput *photoOutput, int32_t frameCount) { + DRAWING_LOGD("PhotoOutputOnFrameEnd start!"); + OH_LOG_INFO(LOG_APP, "PhotoOutput frameCount = %{public}d", frameCount); +} + +void PhotoOutputOnError(Camera_PhotoOutput *photoOutput, Camera_ErrorCode errorCode) { + DRAWING_LOGD("PhotoOutputOnError start!"); + OH_LOG_INFO(LOG_APP, "PhotoOutput errorCode = %{public}d", errorCode); +} + +PhotoOutput_Callbacks *NDKCamera::GetPhotoOutputListener(void) { + static PhotoOutput_Callbacks photoOutputListener = {.onFrameStart = PhotoOutputOnFrameStart, + .onFrameShutter = PhotoOutputOnFrameShutter, + .onFrameEnd = PhotoOutputOnFrameEnd, + .onError = PhotoOutputOnError}; + return &photoOutputListener; +} + +// PhotoOutput Callback +void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput) { + DRAWING_LOGD("VideoOutputOnFrameStart start!"); + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart"); +} +void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount) { + DRAWING_LOGD("VideoOutputOnFrameEnd start!"); + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameEnd frameCount = %{public}d", frameCount); +} +void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode) { + DRAWING_LOGD("VideoOutputOnError start!"); + OH_LOG_INFO(LOG_APP, "VideoOutputOnError errorCode = %{public}d", errorCode); +} + + +VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void) { + static VideoOutput_Callbacks videoOutputListener = { + .onFrameStart = VideoOutputOnFrameStart, .onFrameEnd = VideoOutputOnFrameEnd, .onError = VideoOutputOnError}; + return &videoOutputListener; +} + +Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void) { + ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + } + return ret_; +} + + +void OnMetadataObjectAvailable(Camera_MetadataOutput *metadataOutput, Camera_MetadataObject *metadataObject, + uint32_t size) { + DRAWING_LOGD("OnMetadataObjectAvailable start!"); + OH_LOG_INFO(LOG_APP, "OnMetadataObjectAvailable size = %{public}d", size); +} + +void OnMetadataOutputError(Camera_MetadataOutput *metadataOutput, Camera_ErrorCode errorCode) { + DRAWING_LOGD("OnMetadataOutputError start!"); + OH_LOG_INFO(LOG_APP, "OnMetadataOutputError errorCode = %{public}d", errorCode); +} +MetadataOutput_Callbacks *NDKCamera::GetMetadataOutputListener(void) { + static MetadataOutput_Callbacks metadataOutputListener = {.onMetadataObjectAvailable = OnMetadataObjectAvailable, + .onError = OnMetadataOutputError}; + return &metadataOutputListener; +} + +Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void) { + ret_ = OH_MetadataOutput_RegisterCallback(metadataOutput_, GetMetadataOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + } + return ret_; +} + +Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void) { + ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + } + return ret_; +} + +// Session Callback +void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState) { + OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnFocusStateChange"); + OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange"); +} + +void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode) { + OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnError"); + OH_LOG_INFO(LOG_APP, "CaptureSession errorCode = %{public}d", errorCode); +} + +CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(void) { + static CaptureSession_Callbacks captureSessionCallbacks = {.onFocusStateChange = CaptureSessionOnFocusStateChange, + .onError = CaptureSessionOnError}; + return &captureSessionCallbacks; +} + +Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void) { + ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_RegisterCallback failed."); + } + return ret_; +} +} // namespace OHOS_CAMERA_SAMPLE \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h new file mode 100644 index 0000000000..3d6203c291 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AVRECORDER_CAMERA_MANAGER_H +#define AVRECORDER_CAMERA_MANAGER_H + +#include +#include +#include + +#include "ohcamera/camera.h" +#include "ohcamera/camera_input.h" +#include "ohcamera/capture_session.h" +#include "ohcamera/photo_output.h" +#include "ohcamera/preview_output.h" +#include "ohcamera/video_output.h" +#include "ohcamera/camera_manager.h" +#include "log_common.h" +#include "multimedia/media_library/media_access_helper_capi.h" +#include "multimedia/media_library/media_asset_base_capi.h" +#include "multimedia/media_library/media_asset_capi.h" +#include "multimedia/media_library/media_asset_change_request_capi.h" +#include "multimedia/media_library/media_asset_manager_capi.h" +#include + +extern int videoFrameWidth_; +extern int videoFrameHeight_; + +namespace OHOS_CAMERA_SAMPLE { +class NDKCamera { +public: + ~NDKCamera(); + NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, char *previewId, char *photoId, + char *videoId); + + static void Destroy() { + if (ndkCamera_ != nullptr) { + delete ndkCamera_; + ndkCamera_ = nullptr; + } + } + + Camera_ErrorCode CreateCameraInput(void); + Camera_ErrorCode CameraInputOpen(void); + Camera_ErrorCode CameraInputClose(void); + Camera_ErrorCode CameraInputRelease(void); + Camera_ErrorCode GetSupportedCameras(void); + Camera_ErrorCode GetSupportedOutputCapability(void); + Camera_ErrorCode CreatePreviewOutput(void); + Camera_ErrorCode CreatePhotoOutput(char *photoId); + Camera_ErrorCode CreateVideoOutput(char *videoId); + Camera_ErrorCode CreateMetadataOutput(void); + Camera_ErrorCode IsCameraMuted(void); + + Camera_ErrorCode CreatePhotoOutputWithoutSurfaceId(); + + Camera_ErrorCode PreviewOutputStop(void); + Camera_ErrorCode PreviewOutputRelease(void); + Camera_ErrorCode PhotoOutputRelease(void); + + Camera_ErrorCode HasFlashFn(uint32_t mode); + Camera_ErrorCode IsVideoStabilizationModeSupportedFn(uint32_t mode); + Camera_ErrorCode setZoomRatioFn(uint32_t zoomRatio); + + + Camera_ErrorCode SessionFlowFn(void); + Camera_ErrorCode SessionBegin(void); + Camera_ErrorCode SessionCommitConfig(void); + Camera_ErrorCode SessionStart(void); + Camera_ErrorCode SessionStop(void); + Camera_ErrorCode StartVideo(char *videoId, char *photoId); + Camera_ErrorCode AddVideoOutput(void); + Camera_ErrorCode AddPhotoOutput(); + Camera_ErrorCode VideoOutputStart(void); + + Camera_ErrorCode StartPhoto(char *mSurfaceId); + Camera_ErrorCode IsExposureModeSupportedFn(uint32_t mode); + + Camera_ErrorCode IsMeteringPoint(int x, int y); + Camera_ErrorCode IsExposureBiasRange(int exposureBias); + Camera_ErrorCode IsFocusMode(uint32_t mode); + Camera_ErrorCode IsFocusPoint(float x, float y); + Camera_ErrorCode IsFocusModeSupported(uint32_t mode); + Camera_ErrorCode ReleaseCamera(void); + Camera_ErrorCode SessionRealese(void); + Camera_ErrorCode ReleaseSession(void); + int32_t GetVideoFrameWidth(void); + int32_t GetVideoFrameHeight(void); + int32_t GetVideoFrameRate(void); + + Camera_ErrorCode VideoOutputStop(void); + Camera_ErrorCode VideoOutputRelease(void); + Camera_ErrorCode TakePicture(void); + Camera_ErrorCode TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting); + + // callback + Camera_ErrorCode CameraManagerRegisterCallback(void); + Camera_ErrorCode CameraInputRegisterCallback(void); + Camera_ErrorCode PreviewOutputRegisterCallback(void); + Camera_ErrorCode PhotoOutputRegisterCallback(void); + Camera_ErrorCode VideoOutputRegisterCallback(void); + Camera_ErrorCode MetadataOutputRegisterCallback(void); + Camera_ErrorCode CaptureSessionRegisterCallback(void); + + // Get callback + CameraManager_Callbacks *GetCameraManagerListener(void); + CameraInput_Callbacks *GetCameraInputListener(void); + PreviewOutput_Callbacks *GetPreviewOutputListener(void); + PhotoOutput_Callbacks *GetPhotoOutputListener(void); + VideoOutput_Callbacks *GetVideoOutputListener(void); + MetadataOutput_Callbacks *GetMetadataOutputListener(void); + CaptureSession_Callbacks *GetCaptureSessionRegister(void); + +private: + NDKCamera(const NDKCamera &) = delete; + NDKCamera &operator=(const NDKCamera &) = delete; + uint32_t cameraDeviceIndex_; + Camera_Manager *cameraManager_; + Camera_CaptureSession *captureSession_ = nullptr; + Camera_Device *cameras_; + uint32_t size_; + Camera_OutputCapability *cameraOutputCapability_; + Camera_Profile *profile_; + + Camera_VideoProfile *videoProfile_ = nullptr; + Camera_PreviewOutput *previewOutput_ = nullptr; + Camera_PhotoOutput *photoOutput_ = nullptr; + Camera_VideoOutput *videoOutput_ = nullptr; + const Camera_MetadataObjectType *metaDataObjectType_; + Camera_MetadataOutput *metadataOutput_; + + Camera_Input *cameraInput_; + bool *isCameraMuted_; + Camera_Position position_; + Camera_Type type_; + char *previewSurfaceId_; + Camera_ErrorCode ret_; + + uint32_t takePictureTimes = 0; + Camera_ExposureMode exposureMode_; + bool isExposureModeSupported_; + bool isFocusModeSupported_; + float minExposureBias_; + float maxExposureBias_; + float step_; + uint32_t focusMode_; + + static NDKCamera *ndkCamera_; + static std::mutex mtx_; + volatile bool valid_; + + Camera_SceneMode sceneMode_; + char *photoSurfaceId_; + char *videoSurfaceId_; + bool isSuccess_; +}; +} // namespace OHOS_CAMERA_SAMPLE +#endif // AVRECORDER_CAMERA_MANAGER_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h new file mode 100644 index 0000000000..318e16c9ce --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef LOG_COMMON_H +#define LOG_COMMON_H +#include +#define LOG_PRINT_DOMAIN 0xFF00 +#define APP_LOG_DOMAIN 0x0001 +constexpr const char *APP_LOG_TAG = "DrawingSample"; +#define DRAWING_LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) +#define DRAWING_LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) +#define DRAWING_LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) +#define DRAWING_LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) + +#endif // LOG_COMMON_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h new file mode 100644 index 0000000000..986b291ba3 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AVRECORDER_MAIN_H +#define AVRECORDER_MAIN_H + +#include "hilog/log.h" +#include +#include + +static struct OH_AVRecorder *g_avRecorder={}; +OH_AVRecorder* InitRecorder(); +void StartRecording(OH_AVRecorder *oH_AVRecorder); +#endif //AVRECORDER_MAIN_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp new file mode 100644 index 0000000000..488b9f3fc5 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#undef LOG_TAG +#define LOG_TAG "Muxer" + +#include "sample_info.h" +#include +namespace { +constexpr int32_t VERTICAL_ANGLE = 90; +constexpr int32_t HORIZONTAL_ANGLE = 0; + +} // namespace + +Muxer::~Muxer() { Release(); } + +int32_t Muxer::Create(int32_t fd) { + muxer_ = OH_AVMuxer_Create(fd, AV_OUTPUT_FORMAT_MPEG_4); + return 0; +} +int32_t Muxer::Config(SampleInfo &sampleInfo) { + OH_LOG_INFO(LOG_APP,"==Demo== Config"); + OH_AVFormat *formatVideo = + OH_AVFormat_CreateVideoFormat(sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight); + + OH_AVFormat_SetDoubleValue(formatVideo, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetStringValue(formatVideo, OH_MD_KEY_CODEC_MIME, sampleInfo.codecMime.data()); + int32_t ret = OH_AVMuxer_AddTrack(muxer_, &videoTrackId_, formatVideo); + OH_AVFormat_Destroy(formatVideo); + return 0; +} +int32_t Muxer::Start() { + int ret = OH_AVMuxer_Start(muxer_); + return 0; +} +int32_t Muxer::WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); + ret = OH_AVMuxer_WriteSampleBuffer(muxer_, videoTrackId_, buffer); + return 0; +} +int32_t Muxer::WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); + ret = OH_AVMuxer_WriteSampleBuffer(muxer_, audioTrackId_, buffer); + return 0; +} +int32_t Muxer::Stop() { + int32_t ret = OH_AVMuxer_Stop(muxer_); + return 0; +} +int32_t Muxer::Release() { + if (muxer_ != nullptr) { + + OH_AVMuxer_Destroy(muxer_); + muxer_ = nullptr; + } + return 0; +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h new file mode 100644 index 0000000000..16fa0843ef --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MUXER_H +#define MUXER_H + +#include + +#include "sample_info.h" +#include +class Muxer{ +public: + Muxer()=default; + ~Muxer(); + + int32_t Create(int32_t fd); + int32_t Config(SampleInfo &sampleInfo); + int32_t Start(); + int32_t WriteSample(OH_AVBuffer *buffer,OH_AVCodecBufferAttr &arrt); + int32_t WriteAudioData(OH_AVBuffer *buffer,OH_AVCodecBufferAttr &arrt); + + int32_t Stop(); + int32_t Release(); +private: + OH_AVMuxer *muxer_=nullptr; + int32_t videoTrackId_ = -1; + int32_t audioTrackId_ = -1; + int32_t converTrackId_ = -1; +}; +#endif // MUER_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h new file mode 100644 index 0000000000..11386d4d5d --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AVCODEC_SAMPLE_INFO_H +#define AVCODEC_SAMPLE_INFO_H +#include "bits/alltypes.h" +#include "cstdint" +#include "map" +#include +#include +#include +#include "string" +#include "condition_variable" +#include "queue" +#include "native_buffer/native_buffer.h" + +#define ANNEXB_INPUT_ONLY 1 + +const std::string_view MIME_VIDEO_AVC = "video/avc"; +const std::string_view MIME_VIDEO_HEVC = "video/hevc"; +constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; +constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; +constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; +struct SampleInfo { + int32_t sampleId = 0; + int32_t inputFd = -1; + int32_t outFd = -1; + int64_t inputFileOffset = 0; + int64_t inputFileSize = 0; + std::string inputFilePath; + std::string outputFilePath; + std::string videoCodecMime = ""; + std::string audioCodecMime = ""; + std::string codecMime = MIME_VIDEO_AVC.data(); + int32_t videoWidth = 0; + int32_t videoHeight = 0; + double frameRate = 0.0; + int64_t bitrate = 10 * 1024 * 1024; + int64_t frameInterval = 0; + int32_t perfMode = 0; + uint32_t maxFrames = UINT32_MAX; + int32_t isHDRVivid = 0; + uint32_t repeatTimes = 1; + OH_AVPixelFormat pixlFormat = AV_PIXEL_FORMAT_NV12; + bool needDumpOutput = false; + uint32_t bitrateMode = CBR; + int32_t hevcProfile = HEVC_PROFILE_MAIN; + int32_t rotation = 0; + OHNativeWindow *window = nullptr; + + int32_t sampleRate = 44100; + int32_t channelCount = 2; + + uint32_t bufferSize = 0; + double readTime = 0; + double memcpyTime = 0; + double writeTime = 0; + void (*PlayDoneCallback)(void *context) = nullptr; + void *PlayDoneCallbackData = nullptr; +}; +struct CodecBufferInfo { + uint32_t bufferIndex = 0; + uintptr_t *buffer = nullptr; + uint8_t *bufferAddr = nullptr; + OH_AVCodecBufferAttr attr = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE}; + + CodecBufferInfo(uint8_t *addr) : bufferAddr(addr){}; + CodecBufferInfo(uint8_t *addr, int32_t bufferSize) + : bufferAddr(addr), attr({0, bufferSize, 0, AVCODEC_BUFFER_FLAGS_NONE}){}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer, OH_AVCodecBufferAttr argAttr) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)), attr(argAttr){}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)){}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) { + OH_AVBuffer_GetBufferAttr(argBuffer, &attr); + }; +}; +class AEncBufferSignal { +public: + std::mutex inMutex_; + std::mutex outMutex_; + std::mutex startMutex_; + + std::condition_variable inCond_; + std::condition_variable outCond_; + std::condition_variable startCond_; + + std::queue inQueue_; + std::queue outQueue_; + std::queue inBufferQueue_; + std::queue outBufferQueue_; + OH_AVCodecBufferAttr audioInfo = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE}; +}; +class CodecUserData { +public: + SampleInfo *sampleInfo = nullptr; + + uint32_t inputFrameCount_ = 0; + std::mutex inputMutex_; + std::condition_variable inputCond_; + std::queue inputBufferInfoQueue_; + + uint32_t outputFrameCount_ = 0; + std::mutex outputMutex_; + std::condition_variable outputCond_; + std::queue outputBufferInfoQueue_; + AEncBufferSignal *signal; + + void ClearQueue() { + { + std::unique_lock lock(inputMutex_); + auto emptyQueue = std::queue(); + inputBufferInfoQueue_.swap(emptyQueue); + } + { + std::unique_lock lock(outputMutex_); + auto emptyQueue = std::queue(); + outputBufferInfoQueue_.swap(emptyQueue); + } + } +}; + +#endif // AVCODEC_SAMPLE_INFO_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000..0b83eeec9e --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const createAVRecorder: () => number; + +export const prepareAVRecorder: (mapB: ESObject, fdNumber: String) => number; + +export const createPrepareAVRecorder: () => number; + +export const startAVRecorder: () => number; + +export const pauseAVRecorder: () => number; + +export const resumeAVRecorder: () => number; + +export const stopAVRecorder: () => number; + +export const resetAVRecorder: () => number; + +export const releaseAVRecorder: () => number; + +export const updateRotationAVRecorder: (videoRotation: number) => number; + +export const prepareCamera: (focusMode: number, cameraDeviceIndex: number, sceneMode: number, previewId: string, + photeId: string, videoId: string) => number; + +export const setPreviewSurfaceId: () => number; + +export const getAVRecorderConfig: () => number; + +export const getAvailableEncoder: () => number; + + + diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000..817e9af406 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libavrecorderndk.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp new file mode 100644 index 0000000000..57e2ef1e18 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +namespace{ +constexpr int LIMIT_LOGD_FREQUENCY = 50; +} +void SampleCallback::OnError(OH_AVCodec *codec, int32_t errorCode, void *userData){ + (void)codec; + (void)errorCode; + (void)userData; + +} +void SampleCallback::OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData){ + + (void)codec; + (void)format; + (void)userData; +} +void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData){ + + (void)codec; + (void)index; + (void)userData; + if(userData==nullptr){ + return; + } + (void )codec; + CodecUserData *codecUserData=static_cast(userData); + std::unique_lock lock(codecUserData->inputMutex_); + codecUserData->inputBufferInfoQueue_.emplace(index,buffer); + codecUserData->inputCond_.notify_all(); +} +void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData){ + if(userData==nullptr){ + return; + } + (void )codec; + CodecUserData *codecUserData=static_cast(userData); + std::unique_lock lock(codecUserData->inputMutex_); + codecUserData->outputBufferInfoQueue_.emplace(index,buffer); + codecUserData->outputCond_.notify_all(); + +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h new file mode 100644 index 0000000000..5a86b0f089 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef AVCODEC_SAMPLE_CALLBACK_H +#define AVCODEC_SAMPLE_CALLBACK_H +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "MY_NDKDEMO" +#include + +#include "sample_info.h" +#include +class SampleCallback{ +public: + SampleCallback(){} + SampleCallback(SampleCallback *p1){} + static void OnError(OH_AVCodec *codec,int32_t errorCode,void *userData); + static void OnStreamChanged(OH_AVCodec *codec,OH_AVFormat *format,void *userData); + static void OnNeedInputBuffer(OH_AVCodec *codec,uint32_t index,OH_AVBuffer *buffer,void *userData); + static void OnNewOutputBuffer(OH_AVCodec *codec,uint32_t index,OH_AVBuffer *buffer,void *userData); + + OH_AVMuxer *muxer_=nullptr; + int32_t g_videoTrackId=-1; +}; +#endif // AVCODEC_SAMPLE_CALLBACK_H \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000..3f0469db22 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000..c4270ae251 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 new file mode 100644 index 0000000000..1100b57b7f --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "wearable", + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000..3c712962da --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000..f94595515a --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/icon.png b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" +fi + +# Check hvigor wrapper script +if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then + fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" +fi + +# start hvigor-wrapper script +exec "${EXECUTABLE_NODE}" \ + "${HVIGOR_WRAPPER_SCRIPT}" "$@" diff --git a/code/DocsSample/Media/AVRecorder/hvigorw.bat b/code/DocsSample/Media/AVRecorder/hvigorw.bat new file mode 100644 index 0000000000..89f8b0cd46 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/hvigorw.bat @@ -0,0 +1,63 @@ +@rem Copyright (C) 2024 Huawei Device Co., Ltd. +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@echo off +@rem +@rem ------------------------------------------------------------------- +@rem Hvigor startup script for Windows, version 1.0.0 +@rem +@rem Required ENV vars: +@rem ------------------ +@rem NODE_HOME - location of a Node home dir +@rem or +@rem Add %NODE_HOME%/bin to the PATH environment variable +@rem ------------------------------------------------------------------- +@rem + +set DIRNAME=%~dp0 +set APP_BASE_NAME=%~n0 +set NODE_EXE_PATH="" +set APP_HOME=. +set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js +set NODE_EXE=node.exe +@rem set NODE_OPTS="--max-old-space-size=4096" + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +if not defined NODE_OPTS set NODE_OPTS="--" + +@rem Find node.exe +if defined NODE_HOME ( + set NODE_HOME=%NODE_HOME:"=% + set "PATH=%PATH%;%NODE_HOME%" + set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% +) + +%NODE_EXE% --version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" ( + "%NODE_EXE%" "%NODE_OPTS%" "%WRAPPER_MODULE_PATH%" %* +) else if exist "%NODE_EXE_PATH%" ( + "%NODE_EXE_PATH%" "%NODE_OPTS%" "%WRAPPER_MODULE_PATH%" %* +) else ( + echo. + echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. + echo. + echo Please set the NODE_HOME variable in your environment to match the + echo location of your NodeJs installation. +) + +if "%ERRORLEVEL%" == "0"( + if "%OS%" == "Windows_NT" endlocal +) else ( + exit /b %ERRORLEVEL% +) diff --git a/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 b/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 new file mode 100644 index 0000000000..fa3e42b6c9 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 @@ -0,0 +1,19 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hypium@1.0.15": "@ohos/hypium@1.0.15" + }, + "packages": { + "@ohos/hypium@1.0.15": { + "name": "@ohos/hypium", + "version": "1.0.15", + "integrity": "sha512-AhkuYX2l/IzrVARV/hKRGsJDQPtZ5bygr6Q1N2M9W15kBllNYL3khQ0dNvJwh/CIGoEPMDVcME9q6MhFGccqkw==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.15.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/oh-package.json5 b/code/DocsSample/Media/AVRecorder/oh-package.json5 new file mode 100644 index 0000000000..11f4bde973 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/oh-package.json5 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.15", +// "@ohos/hamock":"1.0.1-rc2" + }, + "author": "", + "name": "avrecorderndk", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} \ No newline at end of file -- Gitee From de1233bb03f94f53747277d187331f3f9dae7c3f Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 23:07:07 +0800 Subject: [PATCH 02/62] add new file Signed-off-by: Steven --- .../AVRecorder/entry/src/main/cpp/main.cpp | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp new file mode 100644 index 0000000000..488b9f3fc5 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#undef LOG_TAG +#define LOG_TAG "Muxer" + +#include "sample_info.h" +#include +namespace { +constexpr int32_t VERTICAL_ANGLE = 90; +constexpr int32_t HORIZONTAL_ANGLE = 0; + +} // namespace + +Muxer::~Muxer() { Release(); } + +int32_t Muxer::Create(int32_t fd) { + muxer_ = OH_AVMuxer_Create(fd, AV_OUTPUT_FORMAT_MPEG_4); + return 0; +} +int32_t Muxer::Config(SampleInfo &sampleInfo) { + OH_LOG_INFO(LOG_APP,"==Demo== Config"); + OH_AVFormat *formatVideo = + OH_AVFormat_CreateVideoFormat(sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight); + + OH_AVFormat_SetDoubleValue(formatVideo, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetStringValue(formatVideo, OH_MD_KEY_CODEC_MIME, sampleInfo.codecMime.data()); + int32_t ret = OH_AVMuxer_AddTrack(muxer_, &videoTrackId_, formatVideo); + OH_AVFormat_Destroy(formatVideo); + return 0; +} +int32_t Muxer::Start() { + int ret = OH_AVMuxer_Start(muxer_); + return 0; +} +int32_t Muxer::WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); + ret = OH_AVMuxer_WriteSampleBuffer(muxer_, videoTrackId_, buffer); + return 0; +} +int32_t Muxer::WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); + ret = OH_AVMuxer_WriteSampleBuffer(muxer_, audioTrackId_, buffer); + return 0; +} +int32_t Muxer::Stop() { + int32_t ret = OH_AVMuxer_Stop(muxer_); + return 0; +} +int32_t Muxer::Release() { + if (muxer_ != nullptr) { + + OH_AVMuxer_Destroy(muxer_); + muxer_ = nullptr; + } + return 0; +} \ No newline at end of file -- Gitee From e55fa06bf509d7d7abeabaee9365ea961d4f0523 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:19:54 +0000 Subject: [PATCH 03/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/cpp/main.cpp | 602 ++++++++++++++++-- 1 file changed, 543 insertions(+), 59 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp index 488b9f3fc5..cffdb84005 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,62 +12,546 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include -#undef LOG_TAG -#define LOG_TAG "Muxer" - -#include "sample_info.h" -#include -namespace { -constexpr int32_t VERTICAL_ANGLE = 90; -constexpr int32_t HORIZONTAL_ANGLE = 0; - -} // namespace - -Muxer::~Muxer() { Release(); } - -int32_t Muxer::Create(int32_t fd) { - muxer_ = OH_AVMuxer_Create(fd, AV_OUTPUT_FORMAT_MPEG_4); - return 0; -} -int32_t Muxer::Config(SampleInfo &sampleInfo) { - OH_LOG_INFO(LOG_APP,"==Demo== Config"); - OH_AVFormat *formatVideo = - OH_AVFormat_CreateVideoFormat(sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight); - - OH_AVFormat_SetDoubleValue(formatVideo, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); - OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); - OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); - OH_AVFormat_SetStringValue(formatVideo, OH_MD_KEY_CODEC_MIME, sampleInfo.codecMime.data()); - int32_t ret = OH_AVMuxer_AddTrack(muxer_, &videoTrackId_, formatVideo); - OH_AVFormat_Destroy(formatVideo); - return 0; -} -int32_t Muxer::Start() { - int ret = OH_AVMuxer_Start(muxer_); - return 0; -} -int32_t Muxer::WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { - int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); - ret = OH_AVMuxer_WriteSampleBuffer(muxer_, videoTrackId_, buffer); - return 0; -} -int32_t Muxer::WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { - int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); - ret = OH_AVMuxer_WriteSampleBuffer(muxer_, audioTrackId_, buffer); - return 0; -} -int32_t Muxer::Stop() { - int32_t ret = OH_AVMuxer_Stop(muxer_); - return 0; -} -int32_t Muxer::Release() { - if (muxer_ != nullptr) { - - OH_AVMuxer_Destroy(muxer_); - muxer_ = nullptr; - } - return 0; + +#include +#include "main.h" +#include "napi/native_api.h" +#include "camera_manager.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "MY_NDKDEMO" +#include + +using namespace std; +using namespace OHOS_CAMERA_SAMPLE; +static NDKCamera* ndkCamera_ = nullptr; + +// 设置视频分辨率 +int videoFrameWidth = 1280; +int videoFrameHeight = 720; + +// 配置参数,可选三种录制模式 +// Type 1: 音视频录制 +void SetConfig(OH_AVRecorder_Config &config) +{ + config.audioSourceType = AVRECORDER_MIC; + config.videoSourceType = AVRECORDER_SURFACE_YUV; + + config.profile.audioBitrate = 96000; + config.profile.audioChannels = 2; + config.profile.audioCodec = AVRECORDER_AUDIO_AAC; + config.profile.audioSampleRate = 48000; + + config.profile.videoBitrate = 2000000; + config.profile.videoFrameWidth = videoFrameWidth; + config.profile.videoFrameHeight = videoFrameHeight; + config.profile.videoFrameRate = 30; + config.profile.videoCodec = AVRECORDER_VIDEO_AVC; + config.profile.isHdr = false; + config.profile.enableTemporalScale = false; + + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; + config.fileGenerationMode = AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + config.metadata.videoOrientation = (char*)malloc(2); + if (config.metadata.videoOrientation != nullptr) { + strcpy(config.metadata.videoOrientation, "90"); + } + OH_LOG_INFO(LOG_APP, "==NDKDemo== videoOrientation: %{public}s", config.metadata.videoOrientation); + + config.metadata.location.latitude = 31.791863; + config.metadata.location.longitude = 64.574687; +} + +// Type 2: 只录音频 +void SetConfigAudio(OH_AVRecorder_Config &config) +{ + config.audioSourceType = AVRECORDER_MIC; + + config.profile.audioBitrate = 32000; + config.profile.audioChannels = 2; + config.profile.audioCodec = AVRECORDER_AUDIO_AAC; + config.profile.audioSampleRate = 8000; + + config.profile.fileFormat = AVRECORDER_CFT_AAC; + config.fileGenerationMode = AVRECORDER_APP_CREATE; + + config.metadata.location.latitude = 31.791863; + config.metadata.location.longitude = 64.574687; +} + +// Type 3: 只录视频 +void SetConfigVideo(OH_AVRecorder_Config &config) +{ + config.videoSourceType = AVRECORDER_SURFACE_YUV; + + config.profile.videoBitrate = 2000000; + config.profile.videoFrameWidth = videoFrameWidth; + config.profile.videoFrameHeight = videoFrameHeight; + config.profile.videoFrameRate = 30; + config.profile.videoCodec = AVRECORDER_VIDEO_AVC; + config.profile.isHdr = false; + config.profile.enableTemporalScale = false; + + config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; + config.fileGenerationMode = AVRECORDER_APP_CREATE; + + config.metadata.videoOrientation = (char*)malloc(2); + if (config.metadata.videoOrientation != nullptr) { + strcpy(config.metadata.videoOrientation, "90"); + } + OH_LOG_INFO(LOG_APP, "==NDKDemo== videoOrientation: %{public}s", config.metadata.videoOrientation); + + config.metadata.location.latitude = 31.791863; + config.metadata.location.longitude = 64.574687; +} + +// 设置状态回调 +void OnStateChange(OH_AVRecorder *recorder, OH_AVRecorder_State state, + OH_AVRecorder_StateChangeReason reason, void *userData) { + (void)recorder; + (void)userData; + + // 将 reason 转换为字符串表示 + const char *reasonStr = (reason == AVRECORDER_USER) ? "USER" : (reason == AVRECORDER_BACKGROUND) ? "BACKGROUND" : "UNKNOWN"; + + if (state == AVRECORDER_IDLE) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange IDLE, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_PREPARED) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange PREPARED, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_STARTED) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange STARTED, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_PAUSED) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange PAUSED, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_STOPPED) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange STOPPED, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_RELEASED) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange RELEASED, reason: %{public}s", reasonStr); + // 处理状态变更 + } + if (state == AVRECORDER_ERROR) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnStateChange ERROR, reason: %{public}s", reasonStr); + // 处理状态变更 + } +} + +// 设置错误回调 +void OnError(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg, void *userData) { + (void)recorder; + (void)userData; + OH_LOG_INFO(LOG_APP, "==NDKDemo== Recorder OnError errorCode: %{public}d, error message: %{public}s", + errorCode, errorMsg); +} + +// 设置生成媒体文件回调 +void OnUri(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData) { + (void)recorder; + (void)userData; + OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri in!"); + if (asset != nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_MediaAsset: %p", asset); + auto changeRequest = OH_MediaAssetChangeRequest_Create(asset); + OH_LOG_INFO(LOG_APP, "==NDKDemo== changeRequest: %p", changeRequest); + if (changeRequest == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== changeRequest is null!"); + return; + } + OH_LOG_INFO(LOG_APP, "==NDKDemo== changeRequest is not null!"); + MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_FILE_VIDEO; + + uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); + OH_LOG_INFO(LOG_APP, "result of OH_MediaAssetChangeRequest_SaveCameraPhoto: %d", result); + uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); + OH_LOG_INFO(LOG_APP, "result of OH_MediaAccessHelper_ApplyChanges: %d", resultChange); + OH_MediaAsset_Release(asset); + OH_MediaAssetChangeRequest_Release(changeRequest); + } else { + OH_LOG_ERROR(LOG_APP, "Received null media asset!"); + } + OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri out!"); +} + +// 1.准备录制 +static napi_value PrepareAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + OH_LOG_INFO(LOG_APP, "==NDKDemo== PrepareAVRecorder in!"); + g_avRecorder = OH_AVRecorder_Create(); + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder Create OK! g_avRecorder: %{public}p", g_avRecorder); + if (g_avRecorder == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Create failed!"); + } + OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); + + SetConfig(*config); + + // 1.1 设置URL + const std::string AVREORDER_ROOT = "/data/storage/el2/base/files/"; + int32_t outputFd = open((AVREORDER_ROOT + "avrecorder01.mp4").c_str(), O_RDWR | O_CREAT, 0777); // 设置文件名 + std::string fileUrl = "fd://" + std::to_string(outputFd); + config->url = const_cast(fileUrl.c_str()); + OH_LOG_INFO(LOG_APP, "config.url is: %s", const_cast(fileUrl.c_str())); + std::cout<< "config.url is:" << config->url << std::endl; + + // 1.2 回调 + // 状态回调 + OH_AVRecorder_SetStateCallback(g_avRecorder, OnStateChange, nullptr); + // 错误回调 + OH_AVRecorder_SetErrorCallback(g_avRecorder, OnError, nullptr); + // 生成媒体文件回调 + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_AVRecorder_SetUriCallback in!"); + OH_AVErrCode ret = OH_AVRecorder_SetUriCallback(g_avRecorder, OnUri, nullptr); + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_AVRecorder_SetUriCallback out!"); + if (ret == AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_AVRecorder_SetUriCallback succeed!"); + } else { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== Failed to set URI callback, error code: %d", ret); + } + + // 1.3 prepare接口 + int result = OH_AVRecorder_Prepare(g_avRecorder, config); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Prepare failed %{public}d", result); + } + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder enableTemporalScale:%{public}d", static_cast(config->profile.enableTemporalScale)); + + // 1.4 更新视频旋转角度 OH_AVRecorder_UpdateRotation + char *videoOrientation = config->metadata.videoOrientation; + if (videoOrientation == nullptr || videoOrientation[0] == '\0') { + OH_LOG_INFO(LOG_APP, "==NDKDemo== videoOrientation is null or empty!"); + napi_value res; + napi_create_int32(env, -1, &res); + return res; + } + // 使用 strtol 进行字符串到整数的转换,并进行错误检查 + char *end; + int32_t rotation= static_cast(strtol(videoOrientation, &end, 10)); // 基数 10 表示十进制 + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder rotation: %{public}d", rotation); + + // 检查转换是否成功 + if (end == videoOrientation || *end != '\0') { + // 转换失败,videoOrientation 包含无效的整数 + OH_LOG_INFO(LOG_APP, "Invalid rotation value: %s", videoOrientation); + } + // 选择是否更新旋转角度 + int32_t rotation = 90; + result = OH_AVRecorder_UpdateRotation(g_avRecorder, rotation); + if (result != AV_ERR_OK) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder UpdateRotation failed! ret=%{public}d", result); + } else { + OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_AVRecorder_UpdateRotation: %{public}d", rotation); + } + + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 获取实时配置参数 +static napi_value GetAVRecorderConfig(napi_env env, napi_callback_info info) +{ + (void)info; + +// OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); +// SetConfig(*config); + + OH_AVRecorder_Config *config = nullptr; + + int result = OH_AVRecorder_GetAVRecorderConfig(g_avRecorder, &config); + if (result != AV_ERR_OK || config == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== Get AVRecorder Config failed %{public}d", result); + napi_value res; + napi_create_int32(env, result, &res); + return res; + } + + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoOrientation: %{public}s", config->metadata.videoOrientation); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig audioSourceType: %{public}d", config->audioSourceType); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoSourceType: %{public}d", config->videoSourceType); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig audioBitrate: %{public}d", config->profile.audioBitrate); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig audioChannels: %{public}d", config->profile.audioChannels); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig audioCodec: %{public}d", config->profile.audioCodec); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig audioSampleRate: %{public}d", config->profile.audioSampleRate); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig fileFormat: %{public}d", config->profile.fileFormat); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoBitrate: %{public}d", config->profile.videoBitrate); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoCodec: %{public}d", config->profile.videoCodec); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoFrameWidth: %{public}d", config->profile.videoFrameWidth); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoFrameHeight: %{public}d", config->profile.videoFrameHeight); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig videoFrameRate: %{public}d", config->profile.videoFrameRate); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig latitude: %{public}.6f", config->metadata.location.latitude); + OH_LOG_INFO(LOG_APP, "==NDKDemo== GetAVRecorderConfig longitude: %{public}.6f", config->metadata.location.longitude); + + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 获取录制支持的编码信息 +static napi_value GetAvailableEncoder(napi_env env, napi_callback_info info) +{ + (void)info; + + OH_AVRecorder_EncoderInfo *encoderInfo = nullptr; + int32_t lengthValue = 0; // 定义一个实际的 int32_t 变量 + int32_t *length = &lengthValue; + + int result = OH_AVRecorder_GetAvailableEncoder(g_avRecorder, &encoderInfo, length); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== GetAvailableEncoder failed %{public}d", result); + } else { + // 打印 encoderInfo 的内容 + if (encoderInfo != nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== Encoder Info in!"); + + // 打印 mimeType (假设是一个枚举类型或可转为字符串的类型) + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder MIME Type: %{public}d", encoderInfo->mimeType); + + // 打印 type + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder Type: %{public}s", encoderInfo->type); + + // 打印 bitRate 范围 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder BitRate Min: %{public}d, Max: %{public}d", encoderInfo->bitRate.min, encoderInfo->bitRate.max); + + // 打印 frameRate 范围 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder FrameRate Min: %{public}d, Max: %{public}d", encoderInfo->frameRate.min, encoderInfo->frameRate.max); + + // 打印 width 范围 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder Width Min: %{public}d, Max: %{public}d", encoderInfo->width.min, encoderInfo->width.max); + + // 打印 height 范围 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder Height Min: %{public}d, Max: %{public}d", encoderInfo->height.min, encoderInfo->height.max); + + // 打印 channels 范围 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder Channels Min: %{public}d, Max: %{public}d", encoderInfo->channels.min, encoderInfo->channels.max); + + // 打印 sampleRate 列表和长度 + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder SampleRate Length: %{public}d", encoderInfo->sampleRateLen); + if (encoderInfo->sampleRate != nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== SampleRates: "); + for (int i = 0; i < encoderInfo->sampleRateLen; i++) { + OH_LOG_INFO(LOG_APP, " ==NDKDemo== GetAvailableEncoder SampleRate: %{public}d", i, encoderInfo->sampleRate[i]); + } + } + } else { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== EncoderInfo is null"); + } + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 2. 启动相机 +static napi_value PrepareCamera(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder PrepareCamera"); + (void)info; + + // 2.1 相机初始化(init) + + size_t argc = 6; + napi_value args[6] = {nullptr}; + size_t typeLen = 0; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t focusMode; + napi_get_value_int32(env, args[0], &focusMode); + + uint32_t cameraDeviceIndex; + napi_get_value_uint32(env, args[1], &cameraDeviceIndex); + + uint32_t sceneMode; + napi_get_value_uint32(env, args[2], &sceneMode); + + char* previewId = nullptr; + napi_get_value_string_utf8(env, args[3], nullptr, 0, &typeLen); + previewId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[3], previewId, typeLen + 1, &typeLen); + + char* photoId = nullptr; + napi_get_value_string_utf8(env, args[4], nullptr, 0, &typeLen); + photoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[4], photoId, typeLen + 1, &typeLen); + + // 获取surfaceID + OH_LOG_INFO(LOG_APP, "==NDKDemo== 000 AVRecorder window : %{public}d", 1); + OH_LOG_INFO(LOG_APP, "==NDKDemo== 000 AVRecorder g_avRecorder: %{public}p", g_avRecorder); + OHNativeWindow *window = nullptr; + OH_LOG_INFO(LOG_APP, "==NDKDemo== 111222 AVRecorder initial window address: %{public}p", window); + + int resultCode = OH_AVRecorder_GetInputSurface(g_avRecorder, &window); + if (resultCode != AV_ERR_OK || window == nullptr) { + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder GetInputSurface failed! resultCode=%{public}d, window=%{public}p", resultCode, window); + napi_value errorResult; + napi_create_int32(env, -1, &errorResult); // -1 表示错误 + return errorResult; + } else { + // 打印 window 地址以确认是否分配成功 + OH_LOG_INFO(LOG_APP, "==NDKDemo== AVRecorder GetInputSurface succeeded! window address: %{public}p", window); + } + + uint64_t surfaceId; + OH_NativeWindow_GetSurfaceId(window, &surfaceId); + char videoId[30]; + OH_LOG_ERROR(LOG_APP, "InitCamera focusMode : %{public}d", focusMode); + OH_LOG_ERROR(LOG_APP, "InitCamera cameraDeviceIndex : %{public}d", cameraDeviceIndex); + OH_LOG_ERROR(LOG_APP, "InitCamera sceneMode : %{public}d", sceneMode); + OH_LOG_ERROR(LOG_APP, "InitCamera previewId : %{public}s", previewId); + OH_LOG_ERROR(LOG_APP, "InitCamera photoId : %{public}s", photoId); + OH_LOG_ERROR(LOG_APP, "InitCamera videoId : %{public}s", videoId); + + ndkCamera_ = new NDKCamera(focusMode, cameraDeviceIndex, sceneMode, previewId, photoId, videoId); + OH_LOG_INFO(LOG_APP, "InitCamera End"); + + int result = 0; + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 3. 开始录制 +static napi_value StartAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + OH_LOG_INFO(LOG_APP, "==NDKDemo== g_avRecorder start: %{public}p", g_avRecorder); + int result = OH_AVRecorder_Start(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Start failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 4. 暂停录制 +static napi_value PauseAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Pause(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Pause failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 5. 恢复录制 +static napi_value ResumeAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + int result = OH_AVRecorder_Resume(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Resume failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 6. 停止录制 +static napi_value StopAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + OH_LOG_INFO(LOG_APP, "==NDKDemo== g_avRecorder stop: %{public}p", g_avRecorder); + int result = OH_AVRecorder_Stop(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Stop failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 7. 重置录制 +static napi_value ResetAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + // 检查 g_avRecorder 是否有效 + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 1: %{public}p", g_avRecorder); + if (g_avRecorder == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); + napi_value res; + napi_create_int32(env, AV_ERR_INVALID_VAL, &res); + return res; + } + + int result = OH_AVRecorder_Reset(g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Reset failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +// 8. 释放录制资源 +static napi_value ReleaseAVRecorder(napi_env env, napi_callback_info info) +{ + (void)info; + // 检查 g_avRecorder 是否有效 + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 2: %{public}p", g_avRecorder); + if (g_avRecorder == nullptr) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); + napi_value res; + napi_create_int32(env, AV_ERR_INVALID_VAL, &res); + return res; + } + + int result = OH_AVRecorder_Release(g_avRecorder); + g_avRecorder = nullptr; // 释放录制资源后,需要显式地将g_avRecorder指针置空 + + OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 3: %{public}p", g_avRecorder); + if (result != AV_ERR_OK) { + OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Release failed %{public}d", result); + } + napi_value res; + napi_create_int32(env, result, &res); + return res; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }, + {"prepareAVRecorder", nullptr, PrepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAVRecorderConfig", nullptr, GetAVRecorderConfig, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAvailableEncoder", nullptr, GetAvailableEncoder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"prepareCamera", nullptr, PrepareCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"startAVRecorder", nullptr, StartAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"pauseAVRecorder", nullptr, PauseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"resumeAVRecorder", nullptr, ResumeAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"stopAVRecorder", nullptr, StopAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"resetAVRecorder", nullptr, ResetAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"releaseAVRecorder", nullptr, ReleaseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); } \ No newline at end of file -- Gitee From baede49cf1635ae9dc3aa7f535c14611522f141b Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:21:49 +0000 Subject: [PATCH 04/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/cpp/main.h | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h index 986b291ba3..b77dbd1d5f 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h @@ -12,14 +12,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef AVRECORDER_MAIN_H #define AVRECORDER_MAIN_H +#include "napi/native_api.h" #include "hilog/log.h" -#include +#include "mutex" +#include "muxer.h" +#include "ohcamera/camera.h" +#include "ohcamera/camera_input.h" +#include "ohcamera/capture_session.h" +#include "ohcamera/photo_output.h" +#include "ohcamera/preview_output.h" +#include "ohcamera/video_output.h" +#include "ohcamera/camera_manager.h" +#include "native_window/external_window.h" +#include "video_encoder_sample.h" #include +#include +#include +#include +#include +#include "multimedia/player_framework/native_avcodec_videoencoder.h" +#include "multimedia/media_library/media_asset_change_request_capi.h" +#include "multimedia/media_library/media_access_helper_capi.h" +#include "multimedia/media_library/media_asset_capi.h" -static struct OH_AVRecorder *g_avRecorder={}; +static struct OH_AVRecorder *g_avRecorder = {}; OH_AVRecorder* InitRecorder(); -void StartRecording(OH_AVRecorder *oH_AVRecorder); +void StartRecording(OH_AVRecorder *recorder); + +extern int videoFrameWidth; +extern int videoFrameHeight; + #endif //AVRECORDER_MAIN_H \ No newline at end of file -- Gitee From 108104039c32cf4a262bb71d95bb0bf01d28d372 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:24:25 +0000 Subject: [PATCH 05/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp. Signed-off-by: Steven --- .../src/main/cpp/avrecorder_ndk_test.cpp | 539 ------------------ 1 file changed, 539 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp index 4a26e5dd26..e69de29bb2 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp @@ -1,539 +0,0 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "napi/native_api.h" -#include "main.h" -#include -#include -#include -#include -#include - -#define LOG_DOMIN 0x3200 -#define LOG_TAG "MY_NDKDEMO" - -#include -#include "native_image/native_image.h" -#include "native_window/external_window.h" -#include "camera_manager.h" -#include "GLES3/gl32.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace OHOS_CAMERA_SAMPLE; -static NDKCamera *ndkCamera_ = nullptr; - -static OH_AVRecorder_Config *config; -char *previceId_ = nullptr; -char *videoSrufaceId; -int videoFrameWidth_ = 1280; -int videoFrameHeight_ = 720; - -// 设置状态回调 -void OnStateChange(OH_AVRecorder *recorder, OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, - void *userData) { - (void)recorder; - (void)userData; - const char *reasonStr = (reason == AVRECORDER_USER) ? "USER" - : (reason == AVRECORDER_BACKGROUND) ? "BACKGROUND" - : "UNKNOWN"; -} -void OnError(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg, void *userData) { - (void)recorder; - (void)userData; -} - -// 设置生成媒体文件回调(媒体库尚未提供接口) -void OnUri(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userDate) { - (void)recorder; - (void)userDate; - OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri in!"); - if (asset != nullptr) { - OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri in!"); - auto changeRequest = OH_MediaAssetChangeRequest_Create(asset); - if (changeRequest == nullptr) { - OH_LOG_INFO(LOG_APP, "==NDKDemo== changeRequest is null!"); - return; - } - MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; - uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); - OH_LOG_INFO(LOG_APP, "==NDKDemo== OH_MediaAssetChangeRequest_SaveCameraPhoto result:%{public}d!", result); - OH_MediaAsset_Release(asset); - OH_MediaAssetChangeRequest_Release(changeRequest); - } else { - OH_LOG_INFO(LOG_APP, "==NDKDemo== Received null media asset! "); - } - OH_LOG_INFO(LOG_APP, "==NDKDemo== OnUri out ! "); -} - -static napi_value createAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = AV_ERR_OK; - g_avRecorder = OH_AVRecorder_Create(); - if (g_avRecorder == nullptr) { - result = AV_ERR_UNKNOWN; - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value setPreviewSurfaceId(napi_env env, napi_callback_info info) -{ - - (void)info; - // todo - int result = AV_ERR_OK; - if (result != AV_ERR_OK) { - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static bool GetInt32Property(napi_env env, napi_value root, const char *utf8name, int32_t *res) { - napi_value property = nullptr; - auto status = napi_get_named_property(env, root, utf8name, &property); - if (status != napi_ok || property == nullptr) { - return false; - } - return (napi_get_value_int32(env, property, res) == napi_ok); -} - -static bool parseSetConfigOps(napi_env env, napi_value arg, struct OH_AVRecorder_Config &config) { - - if (env == nullptr || arg == nullptr) { - return false; - } - // Optional parameters, no need check error. - GetInt32Property(env, arg, "audioBitrate", &(config.profile.audioBitrate)); - GetInt32Property(env, arg, "audioChannels", &(config.profile.audioChannels)); - GetInt32Property(env, arg, "audioSampleRate", &(config.profile.audioSampleRate)); - - GetInt32Property(env, arg, "videoBitrate", &(config.profile.videoBitrate)); - GetInt32Property(env, arg, "videoFrameWidth", &(config.profile.videoFrameWidth)); - GetInt32Property(env, arg, "videoFrameHeight", &(config.profile.videoFrameHeight)); - GetInt32Property(env, arg, "videoFrameRate", &(config.profile.videoFrameRate)); - int32_t fileFormat = -1; - GetInt32Property(env, arg, "fileFormat", &fileFormat); - switch (fileFormat) { - case AVRECORDER_CFT_MPEG_4: - config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; - break; - case AVRECORDER_CFT_MPEG_4A: - config.profile.fileFormat = AVRECORDER_CFT_MPEG_4A; - break; - case AVRECORDER_CFT_MP3: - config.profile.fileFormat = AVRECORDER_CFT_MP3; - break; - case AVRECORDER_CFT_WAV: - config.profile.fileFormat = AVRECORDER_CFT_WAV; - break; - default: - config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; - break; - } - return true; -} - -// 配置参数 -void setConfig(OH_AVRecorder_Config &config) { - config.audioSourceType = AVRECORDER_DEFAULT; - config.videoSourceType = AVRECORDER_SURFACE_YUV; - // 设置媒体属性 - config.profile.audioBitrate = 48000; - config.profile.audioChannels = 2; - config.profile.audioCodec = AVRECORDER_AUDIO_AAC; - config.profile.audioSampleRate = 48000; - - config.profile.videoBitrate = 2000000; - config.profile.videoFrameWidth = videoFrameWidth_; - config.profile.videoFrameHeight = videoFrameHeight_; - config.profile.videoFrameRate = 30; - config.profile.videoCodec = AVRECORDER_VIDEO_AVC; - config.profile.isHdr = false; - config.profile.enableTemporalScale = true; - - config.profile.fileFormat = AVRECORDER_CFT_MPEG_4; - config.fileGenerationMode = AVRECORDER_APP_CREATE; - - config.metadata.videoOrientation = (char *)malloc(2); - if (config.metadata.videoOrientation != nullptr) { - strcpy(config.metadata.videoOrientation, "0"); - } - config.metadata.location.latitude = 0; - config.metadata.location.longitude = 0; -} - -static napi_value prepareAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); - OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); - setConfig(*config); - - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); - char *fd = nullptr; - size_t typeLen = 0; - napi_get_value_string_utf8(env, args[1], nullptr, 0, &typeLen); - fd = new char[typeLen + 1]; - napi_get_value_string_utf8(env, args[1], fd, typeLen + 1, &typeLen); - config->url = fd; - - OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder in"); - parseSetConfigOps(env, args[0], *config); - - OH_LOG_INFO(LOG_APP, "---------AVRecorder config.url = fd: %{public}s", config->url); - OH_LOG_INFO(LOG_APP, "---------AVRecorder config.profile.videoFrameWidth = fd: %{public}", - config->profile.videoFrameWidth); - OH_LOG_INFO(LOG_APP, "---------AVRecorder config.url.profile.videoFrameHeight = fd: %{public}", - config->profile.videoFrameHeight); - OH_AVRecorder_SetStateCallback(g_avRecorder, OnStateChange, nullptr); - OH_AVRecorder_SetErrorCallback(g_avRecorder, OnError, nullptr); - - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback in"); - OH_AVErrCode ret = OH_AVRecorder_SetUriCallback(g_avRecorder, OnUri, nullptr); - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback out"); - - if (ret == AV_ERR_OK) { - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback successed"); - } else { - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback error code :%{public}d", ret); - } - - int result = AV_ERR_OK; - result = OH_AVRecorder_Prepare(g_avRecorder, config); - if (result != AV_ERR_OK) { - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Prepare error code :%{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare AVRecorder out"); - return res; -} - -static napi_value createPrepareAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = AV_ERR_OK; - g_avRecorder = OH_AVRecorder_Create(); - if (g_avRecorder == nullptr) { - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Create error code :%{public}d", result); - } - OH_AVRecorder_Config *config1 = new OH_AVRecorder_Config(); - setConfig(*config1); - - // 1.1 设置url - const std::string AVRECORDER_ROOT = "/data/storage/el2/base/files/"; - int32_t outputFd = open((AVRECORDER_ROOT + "avrecorder001.mp4").c_str(), O_RDWR | O_CREAT, 0777); - std::string fileUrl = "fd://" + std::to_string(outputFd); - config1->url = const_cast(fileUrl.c_str()); - std::cout << "config1.url is:" << config->url << std::endl; - - OH_AVRecorder_SetStateCallback(g_avRecorder, OnStateChange, nullptr); - OH_AVRecorder_SetErrorCallback(g_avRecorder, OnError, nullptr); - - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback in"); - OH_AVErrCode ret = OH_AVRecorder_SetUriCallback(g_avRecorder, OnUri, nullptr); - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_SetUriCallback out"); - - int result1 = OH_AVRecorder_Prepare(g_avRecorder, config1); - if (result1 != AV_ERR_OK || result != AV_ERR_OK) { - result = AV_ERR_UNKNOWN; - OH_LOG_INFO(LOG_APP, "---------AVRecorder OH_AVRecorder_Prepare error code :%{public}d", result1); - } - - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value startAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = OH_AVRecorder_Start(g_avRecorder); - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Start failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value pauseAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = OH_AVRecorder_Pause(g_avRecorder); - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Pause failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value resumeAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = OH_AVRecorder_Resume(g_avRecorder); - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Resume failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value stopAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - int result = OH_AVRecorder_Stop(g_avRecorder); - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Stop failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -// 7. 重置录制 -static napi_value resetAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - if (g_avRecorder == nullptr) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); - napi_value res; - napi_create_int32(env, AV_ERR_INVALID_VAL, &res); - return res; - } - - int result = OH_AVRecorder_Reset(g_avRecorder); - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Reset failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value releaseAVRecorder(napi_env env, napi_callback_info info) -{ - (void)info; - if (g_avRecorder == nullptr) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); - napi_value res; - napi_create_int32(env, AV_ERR_INVALID_VAL, &res); - return res; - } - int result = OH_AVRecorder_Release(g_avRecorder); - g_avRecorder = nullptr; - - if (result != AV_ERR_OK) { - OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Release failed %{public}d", result); - } - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value getAVRecorderConfig(napi_env env, napi_callback_info info) -{ - (void)info; - - OH_AVRecorder_Config *config = new OH_AVRecorder_Config(); - setConfig(*config); - int result = OH_AVRecorder_GetAVRecorderConfig(g_avRecorder, &config); - if (result != AV_ERR_OK) { - OH_LOG_INFO(LOG_APP, "---------NDK xts------getAVRecorderConfig error"); - } - OH_LOG_INFO(LOG_APP, "---------NDK xts------getAVRecorderConfig sucuess", config->profile.audioBitrate); - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value getAvailableEncoder(napi_env env, napi_callback_info info) -{ - (void)info; - - OH_AVRecorder_EncoderInfo *encoderInfo = nullptr; - - int32_t lengthValue = 0; - int32_t *length = &lengthValue; - - int result = OH_AVRecorder_GetAvailableEncoder(g_avRecorder, &encoderInfo, length); - - if (result != AV_ERR_OK) { - OH_LOG_INFO(LOG_APP, "---------NDK xts------getAvailableEncorder error"); - } else { - if (encoderInfo != nullptr) { - OH_LOG_INFO(LOG_APP, "Encorder Info in"); - OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", encoderInfo->mimeType); - - OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", encoderInfo->type); - // bitRate - OH_LOG_INFO(LOG_APP, "Encorder BitRate Min: %{public}d,Max :%{public}d", encoderInfo->bitRate.min, - encoderInfo->bitRate.max); - // frameRate - OH_LOG_INFO(LOG_APP, "Encorder frameRate Min: %{public}d,Max :%{public}d", encoderInfo->frameRate.min, - encoderInfo->frameRate.max); - // width - OH_LOG_INFO(LOG_APP, "Encorder width Min: %{public}d,Max :%{public}d", encoderInfo->width.min, - encoderInfo->width.max); - // height - OH_LOG_INFO(LOG_APP, "Encorder height Min: %{public}d,Max :%{public}d", encoderInfo->height.min, - encoderInfo->height.max); - // channels - OH_LOG_INFO(LOG_APP, "Encorder channels Min: %{public}d,Max :%{public}d", encoderInfo->channels.min, - encoderInfo->channels.max); - - if (encoderInfo->sampleRate != nullptr) { - for (int i = 0; i < encoderInfo->sampleRateLen; i++) { - OH_LOG_INFO(LOG_APP, "Encorder mimeType %{public}d", i, encoderInfo->sampleRate[i]); - } - } - } else { - OH_LOG_INFO(LOG_APP, "EncorderInfo is null"); - } - } - - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value updateRotationAVRecorder(napi_env env, napi_callback_info info) -{ - - (void)info; - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - int32_t videoRotation; - napi_get_value_int32(env, args[0], &videoRotation); - - int result = AV_ERR_OK; - result = OH_AVRecorder_UpdateRotation(g_avRecorder, videoRotation); - OH_LOG_INFO(LOG_APP, "---------AVRecorder updateRotationAVRecorder result :%{public}d", result); - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -static napi_value prepareCamera(napi_env env, napi_callback_info info) -{ - size_t argc = 8; - napi_value args[8] = {nullptr}; - size_t typeLen = 0; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - int32_t focusMode; - napi_get_value_int32(env, args[0], &focusMode); - - uint32_t cameraDeviceIndex; - napi_get_value_uint32(env, args[1], &cameraDeviceIndex); - - uint32_t sceneMode; - napi_get_value_uint32(env, args[2], &sceneMode); - - char *previewId = nullptr; - napi_get_value_string_utf8(env, args[3], nullptr, 0, &typeLen); - previewId = new char[typeLen + 1]; - napi_get_value_string_utf8(env, args[3], previewId, typeLen + 1, &typeLen); - - char *photoId = nullptr; - napi_get_value_string_utf8(env, args[4], nullptr, 0, &typeLen); - photoId = new char[typeLen + 1]; - napi_get_value_string_utf8(env, args[4], photoId, typeLen + 1, &typeLen); - - uint32_t videoFrameWidth; - napi_get_value_uint32(env, args[6], &videoFrameWidth); - uint32_t videoFrameHeight; - napi_get_value_uint32(env, args[7], &videoFrameHeight); - - // 获取surfaceId - OHNativeWindow *window; - int resultCode = OH_AVRecorder_GetInputSurface(g_avRecorder, &window); - if (resultCode != AV_ERR_OK) { - OH_LOG_INFO(LOG_APP, "---------NDK xts------prepare Camera error"); - } - uint64_t surfaceId; - OH_NativeWindow_GetSurfaceId(window, &surfaceId); - char videoId[30]; - OH_LOG_INFO(LOG_APP, "init Camera fouseMode : %{public}d", focusMode); - OH_LOG_INFO(LOG_APP, "init Camera cameraDeviceIndex : %{public}d", cameraDeviceIndex); - OH_LOG_INFO(LOG_APP, "init Camera sceneMode : %{public}d", sceneMode); - OH_LOG_INFO(LOG_APP, "init Camera previewId : %{public}d", previewId); - OH_LOG_INFO(LOG_APP, "init Camera photo : %{public}d", photoId); - OH_LOG_INFO(LOG_APP, "init Camera video : %{public}d", videoId); - - ndkCamera_ = new NDKCamera(focusMode, cameraDeviceIndex, sceneMode, previewId, photoId, videoId); - int result = 6; - napi_value res; - napi_create_int32(env, result, &res); - return res; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"createAVRecorder", nullptr, createAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"prepareAVRecorder", nullptr, prepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createPrepareAVRecorder", nullptr, createPrepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"startAVRecorder", nullptr, startAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"pauseAVRecorder", nullptr, pauseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"resumeAVRecorder", nullptr, resumeAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"stopAVRecorder", nullptr, stopAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"resetAVRecorder", nullptr, resetAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"releaseAVRecorder", nullptr, releaseAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"updateRotationAVRecorder", nullptr, updateRotationAVRecorder, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"prepareCamera", nullptr, prepareCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"setPreviewSurfaceId", nullptr, setPreviewSurfaceId, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getAVRecorderConfig", nullptr, getAVRecorderConfig, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getAvailableEncoder", nullptr, getAvailableEncoder, nullptr, nullptr, nullptr, napi_default, nullptr}, - }; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -EXTERN_C_END - -static napi_module demoModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "avrecorderndk", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file -- Gitee From 55c4d960f2faca9fc765a7a7625c3a1b059c41da Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:25:21 +0000 Subject: [PATCH 06/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h. Signed-off-by: Steven --- .../entry/src/main/cpp/camera_manager.h | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h index 3d6203c291..a4a00267b9 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,36 +16,40 @@ #ifndef AVRECORDER_CAMERA_MANAGER_H #define AVRECORDER_CAMERA_MANAGER_H -#include +#include "napi/native_api.h" +#include #include +#include #include +#include +#include +#include +#include +#include +#include "iostream" +#include "mutex" +#include "hilog/log.h" #include "ohcamera/camera.h" #include "ohcamera/camera_input.h" #include "ohcamera/capture_session.h" #include "ohcamera/photo_output.h" #include "ohcamera/preview_output.h" #include "ohcamera/video_output.h" +#include "napi/native_api.h" #include "ohcamera/camera_manager.h" #include "log_common.h" -#include "multimedia/media_library/media_access_helper_capi.h" -#include "multimedia/media_library/media_asset_base_capi.h" -#include "multimedia/media_library/media_asset_capi.h" -#include "multimedia/media_library/media_asset_change_request_capi.h" -#include "multimedia/media_library/media_asset_manager_capi.h" -#include - -extern int videoFrameWidth_; -extern int videoFrameHeight_; +#include "main.h" namespace OHOS_CAMERA_SAMPLE { class NDKCamera { -public: + public: ~NDKCamera(); - NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, char *previewId, char *photoId, - char *videoId); + NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, + char *previewId, char *photoId, char *videoId); - static void Destroy() { + static void Destroy() + { if (ndkCamera_ != nullptr) { delete ndkCamera_; ndkCamera_ = nullptr; @@ -63,18 +67,12 @@ public: Camera_ErrorCode CreateVideoOutput(char *videoId); Camera_ErrorCode CreateMetadataOutput(void); Camera_ErrorCode IsCameraMuted(void); - - Camera_ErrorCode CreatePhotoOutputWithoutSurfaceId(); - Camera_ErrorCode PreviewOutputStop(void); Camera_ErrorCode PreviewOutputRelease(void); Camera_ErrorCode PhotoOutputRelease(void); - Camera_ErrorCode HasFlashFn(uint32_t mode); Camera_ErrorCode IsVideoStabilizationModeSupportedFn(uint32_t mode); Camera_ErrorCode setZoomRatioFn(uint32_t zoomRatio); - - Camera_ErrorCode SessionFlowFn(void); Camera_ErrorCode SessionBegin(void); Camera_ErrorCode SessionCommitConfig(void); @@ -84,10 +82,8 @@ public: Camera_ErrorCode AddVideoOutput(void); Camera_ErrorCode AddPhotoOutput(); Camera_ErrorCode VideoOutputStart(void); - Camera_ErrorCode StartPhoto(char *mSurfaceId); Camera_ErrorCode IsExposureModeSupportedFn(uint32_t mode); - Camera_ErrorCode IsMeteringPoint(int x, int y); Camera_ErrorCode IsExposureBiasRange(int exposureBias); Camera_ErrorCode IsFocusMode(uint32_t mode); @@ -99,7 +95,6 @@ public: int32_t GetVideoFrameWidth(void); int32_t GetVideoFrameHeight(void); int32_t GetVideoFrameRate(void); - Camera_ErrorCode VideoOutputStop(void); Camera_ErrorCode VideoOutputRelease(void); Camera_ErrorCode TakePicture(void); @@ -123,7 +118,7 @@ public: MetadataOutput_Callbacks *GetMetadataOutputListener(void); CaptureSession_Callbacks *GetCaptureSessionRegister(void); -private: + private: NDKCamera(const NDKCamera &) = delete; NDKCamera &operator=(const NDKCamera &) = delete; uint32_t cameraDeviceIndex_; @@ -133,21 +128,18 @@ private: uint32_t size_; Camera_OutputCapability *cameraOutputCapability_; Camera_Profile *profile_; - - Camera_VideoProfile *videoProfile_ = nullptr; + Camera_VideoProfile *videoProfile_; Camera_PreviewOutput *previewOutput_ = nullptr; Camera_PhotoOutput *photoOutput_ = nullptr; Camera_VideoOutput *videoOutput_ = nullptr; const Camera_MetadataObjectType *metaDataObjectType_; Camera_MetadataOutput *metadataOutput_; - Camera_Input *cameraInput_; bool *isCameraMuted_; Camera_Position position_; Camera_Type type_; char *previewSurfaceId_; Camera_ErrorCode ret_; - uint32_t takePictureTimes = 0; Camera_ExposureMode exposureMode_; bool isExposureModeSupported_; @@ -167,4 +159,4 @@ private: bool isSuccess_; }; } // namespace OHOS_CAMERA_SAMPLE -#endif // AVRECORDER_CAMERA_MANAGER_H \ No newline at end of file +#endif //AVRECORDER_CAMERA_MANAGER_H \ No newline at end of file -- Gitee From d52158ef0e093a2fbc6542ec5e84001d79a7a5e3 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:27:29 +0000 Subject: [PATCH 07/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp. Signed-off-by: Steven --- .../entry/src/main/cpp/camera_manager.cpp | 622 ++++++++++-------- 1 file changed, 360 insertions(+), 262 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp index 53441ed549..864d34bcb8 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,24 +15,30 @@ #include "camera_manager.h" -#define LOG_TAG "MY_NDKDEMO" +#define LOG_TAG "DEMO:" #define LOG_DOMAIN 0x3200 namespace OHOS_CAMERA_SAMPLE { NDKCamera *NDKCamera::ndkCamera_ = nullptr; std::mutex NDKCamera::mtx_; const std::unordered_map g_int32ToCameraSceneMode = { - {1, Camera_SceneMode::NORMAL_PHOTO}, {2, Camera_SceneMode::NORMAL_VIDEO}, {12, Camera_SceneMode::SECURE_PHOTO}}; - -NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, char *previewId, char *photoId, - char *videoId) - : focusMode_(focusMode), cameraDeviceIndex_(cameraDeviceIndex), previewSurfaceId_(previewId), - photoSurfaceId_(photoId), videoSurfaceId_(videoId), cameras_(nullptr), profile_(nullptr), - cameraOutputCapability_(nullptr), captureSession_(nullptr), cameraInput_(nullptr), previewOutput_(nullptr), - photoOutput_(nullptr), videoOutput_(nullptr), isCameraMuted_(nullptr), metaDataObjectType_(nullptr), - metadataOutput_(nullptr), isExposureModeSupported_(false), isFocusModeSupported_(false), isSuccess_(false), - sceneMode_(NORMAL_PHOTO), exposureMode_(EXPOSURE_MODE_LOCKED), ret_(CAMERA_OK), size_(0), minExposureBias_(0), - maxExposureBias_(0), step_(0) { + {1, Camera_SceneMode::NORMAL_PHOTO}, + {2, Camera_SceneMode::NORMAL_VIDEO}, + {12, Camera_SceneMode::SECURE_PHOTO} +}; + +NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, + char *previewId, char *photoId, char *videoId) + : focusMode_(focusMode), cameraDeviceIndex_(cameraDeviceIndex), + previewSurfaceId_(previewId), photoSurfaceId_(photoId), videoSurfaceId_(videoId), + cameras_(nullptr), profile_(nullptr), cameraOutputCapability_(nullptr), captureSession_(nullptr), + cameraInput_(nullptr), previewOutput_(nullptr), photoOutput_(nullptr), videoOutput_(nullptr), + isCameraMuted_(nullptr), metaDataObjectType_(nullptr), metadataOutput_(nullptr), + isExposureModeSupported_(false), isFocusModeSupported_(false), isSuccess_(false), + sceneMode_(NORMAL_VIDEO), exposureMode_(EXPOSURE_MODE_LOCKED), ret_(CAMERA_OK), + size_(0), minExposureBias_(0), maxExposureBias_(0), step_(0) +{ + OH_LOG_ERROR(LOG_APP, "=====testZj1===="); // release camera ReleaseCamera(); @@ -41,14 +47,19 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc if (cameraManager_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Get CameraManager failed."); } - OH_LOG_ERROR(LOG_APP, "=====testZj2====."); + OH_LOG_INFO(LOG_APP, "=====testZj2===="); +// +// // register camera manager callback +// CameraManagerRegisterCallback(); +// ret = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_); + // create capture session ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); if (captureSession_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); } - OH_LOG_ERROR(LOG_APP, "=====testZj3====."); + OH_LOG_INFO(LOG_APP, "=====testZj3===="); // look up sceneMode auto itr1 = g_int32ToCameraSceneMode.find(sceneMode); @@ -58,8 +69,11 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc // set session mode ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); - - OH_LOG_ERROR(LOG_APP, "=====testZj4====."); +// DRAWING_LOGD("OH_CaptureSession_SetSessionMode sceneMode_: %{public}d!", sceneMode_); +// DRAWING_LOGD("OH_CaptureSession_SetSessionMode return with ret code: %{public}d!", ret); + OH_LOG_INFO(LOG_APP, "=====testZj4===="); + // register capture session callback +// CaptureSessionRegisterCallback(); // get capture session profile GetSupportedCameras(); @@ -70,13 +84,14 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc // create camera input and register camera input callback CreateCameraInput(); - CameraInputOpen(); + CameraInputOpen(); // 设备打开 // config and start session SessionFlowFn(); } -NDKCamera::~NDKCamera() { +NDKCamera::~NDKCamera() +{ OH_LOG_ERROR(LOG_APP, "~NDKCamera"); Camera_ErrorCode ret = CAMERA_OK; @@ -108,7 +123,8 @@ NDKCamera::~NDKCamera() { OH_LOG_ERROR(LOG_APP, "~NDKCamera exit"); } -Camera_ErrorCode NDKCamera::ReleaseCamera(void) { +Camera_ErrorCode NDKCamera::ReleaseCamera(void) +{ OH_LOG_ERROR(LOG_APP, " enter ReleaseCamera"); if (previewOutput_ && captureSession_) { PreviewOutputStop(); @@ -118,7 +134,6 @@ Camera_ErrorCode NDKCamera::ReleaseCamera(void) { if (photoOutput_) { PhotoOutputRelease(); } - if (videoOutput_) { VideoOutputRelease(); } @@ -132,7 +147,8 @@ Camera_ErrorCode NDKCamera::ReleaseCamera(void) { return ret_; } -Camera_ErrorCode NDKCamera::ReleaseSession(void) { +Camera_ErrorCode NDKCamera::ReleaseSession(void) +{ OH_LOG_ERROR(LOG_APP, " enter ReleaseSession"); PreviewOutputStop(); PhotoOutputRelease(); @@ -142,45 +158,40 @@ Camera_ErrorCode NDKCamera::ReleaseSession(void) { return ret_; } -Camera_ErrorCode NDKCamera::SessionRealese(void) { +Camera_ErrorCode NDKCamera::SessionRealese(void) +{ OH_LOG_ERROR(LOG_APP, " enter SessionRealese"); Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); captureSession_ = nullptr; OH_LOG_ERROR(LOG_APP, " exit SessionRealese"); return ret; } -// todo - -Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) { +Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) +{ Camera_FlashMode flashMode = static_cast(mode); // Check for flashing lights bool hasFlash = false; Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash); - if (captureSession_ == nullptr || ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_HasFlash success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed. %d ", ret); + if (captureSession_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed."); } if (hasFlash) { - OH_LOG_INFO(LOG_APP, "hasFlash success."); + OH_LOG_INFO(LOG_APP, "hasFlash success-----"); } else { - OH_LOG_ERROR(LOG_APP, "hasFlash hasFlash failed. %d ", hasFlash); + OH_LOG_ERROR(LOG_APP, "hasFlash fail-----"); } // Check if the flash mode is supported bool isSupported = false; ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsFlashModeSupported success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed. %d ", ret); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed."); } - if (isSupported) { - OH_LOG_INFO(LOG_APP, "isSupported success."); + OH_LOG_INFO(LOG_APP, "isFlashModeSupported success-----"); } else { - OH_LOG_ERROR(LOG_APP, "isSupported failed. %d ", hasFlash); + OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail-----"); } // Set flash mode @@ -188,60 +199,65 @@ Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) { if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret); } + + // Obtain the flash mode of the current device ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode); if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success. flashMode: %{public}d ", flashMode); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode failed. %d ", ret); } return ret; } - -Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode) { +Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode) +{ Camera_VideoStabilizationMode videoMode = static_cast(mode); + // Check if the specified video anti shake mode is supported bool isSupported = false; - Camera_ErrorCode ret = OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isSupported); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported failed. %d ", ret); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported failed."); } if (isSupported) { - OH_LOG_INFO(LOG_APP, "isSupported success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported success-----"); } else { - OH_LOG_ERROR(LOG_APP, "isSupported failed. %d ", isSupported); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported fail-----"); } + // Set video stabilization ret = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode videoMode failed. %d ", videoMode); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode failed. %{public}d ", ret); } + ret = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode); if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode success. videoMode: %{public}f ", + videoMode); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode videoMode failed. %d ", videoMode); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode failed. %{public}d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) { +Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) +{ float zoom = float(zoomRatio); + // Obtain supported zoom range float minZoom; float maxZoom; - Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom); - if (captureSession_ == nullptr || ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success."); + if (captureSession_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed. %d ", ret); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f", + minZoom, maxZoom); } // Set Zoom @@ -249,19 +265,21 @@ Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) { if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret); } + // Obtain the zoom value of the current device ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom); if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom: %{public}f ", zoom); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionBegin(void) { +Camera_ErrorCode NDKCamera::SessionBegin(void) +{ Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_BeginConfig success."); @@ -271,7 +289,8 @@ Camera_ErrorCode NDKCamera::SessionBegin(void) { return ret; } -Camera_ErrorCode NDKCamera::SessionCommitConfig(void) { +Camera_ErrorCode NDKCamera::SessionCommitConfig(void) +{ Camera_ErrorCode ret = OH_CaptureSession_CommitConfig(captureSession_); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_CommitConfig success."); @@ -281,14 +300,16 @@ Camera_ErrorCode NDKCamera::SessionCommitConfig(void) { return ret; } -Camera_ErrorCode NDKCamera::SessionStart(void) { +Camera_ErrorCode NDKCamera::SessionStart(void) +{ bool isSupport = false; - OH_CaptureSession_IsVideoStabilizationModeSupported( - captureSession_, Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO, &isSupport); + OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, + Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO, &isSupport); if (isSupport) { OH_CaptureSession_SetVideoStabilizationMode(captureSession_, - Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); + Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); } + // Start focusing OH_LOG_INFO(LOG_APP, "IsFocusMode start"); OH_CaptureSession_SetFocusMode(captureSession_, Camera_FocusMode::FOCUS_MODE_AUTO); @@ -303,7 +324,8 @@ Camera_ErrorCode NDKCamera::SessionStart(void) { return ret; } -Camera_ErrorCode NDKCamera::SessionStop(void) { +Camera_ErrorCode NDKCamera::SessionStop(void) +{ Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Stop success."); @@ -313,26 +335,40 @@ Camera_ErrorCode NDKCamera::SessionStop(void) { return ret; } -Camera_ErrorCode NDKCamera::SessionFlowFn(void) { +Camera_ErrorCode NDKCamera::SessionFlowFn(void) +{ OH_LOG_INFO(LOG_APP, "Start SessionFlowFn IN."); + // start configuring session OH_LOG_INFO(LOG_APP, "session beginConfig."); Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); + // add cameraInput to the session OH_LOG_INFO(LOG_APP, "session add Input."); ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); + // add previewOutput to the session OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); + + // create photo output and register photo output callback +// CreatePhotoOutput(photoSurfaceId_); + + // add photoOutput to the Session +// AddPhotoOutput(); if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + // create video output and register video output callback CreateVideoOutput(videoSurfaceId_); + // add videoOutput to the Session AddVideoOutput(); } + // Submit configuration information OH_LOG_INFO(LOG_APP, "session commitConfig"); ret = OH_CaptureSession_CommitConfig(captureSession_); + // Start Session Work OH_LOG_INFO(LOG_APP, "session start"); SessionStart(); @@ -342,7 +378,8 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) { return ret; } -Camera_ErrorCode NDKCamera::CreateCameraInput(void) { +Camera_ErrorCode NDKCamera::CreateCameraInput(void) +{ OH_LOG_ERROR(LOG_APP, "enter CreateCameraInput."); ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, &cameras_[cameraDeviceIndex_], &cameraInput_); if (cameraInput_ == nullptr || ret_ != CAMERA_OK) { @@ -350,12 +387,14 @@ Camera_ErrorCode NDKCamera::CreateCameraInput(void) { return CAMERA_INVALID_ARGUMENT; } OH_LOG_ERROR(LOG_APP, "exit CreateCameraInput."); + // register camera input callback CameraInputRegisterCallback(); return ret_; } -Camera_ErrorCode NDKCamera::CameraInputOpen(void) { +Camera_ErrorCode NDKCamera::CameraInputOpen(void) +{ OH_LOG_ERROR(LOG_APP, "enter CameraInputOpen."); ret_ = OH_CameraInput_Open(cameraInput_); if (ret_ != CAMERA_OK) { @@ -366,7 +405,8 @@ Camera_ErrorCode NDKCamera::CameraInputOpen(void) { return ret_; } -Camera_ErrorCode NDKCamera::CameraInputClose(void) { +Camera_ErrorCode NDKCamera::CameraInputClose(void) +{ OH_LOG_ERROR(LOG_APP, "enter CameraInput_Close."); ret_ = OH_CameraInput_Close(cameraInput_); if (ret_ != CAMERA_OK) { @@ -377,139 +417,159 @@ Camera_ErrorCode NDKCamera::CameraInputClose(void) { return ret_; } -Camera_ErrorCode NDKCamera::CameraInputRelease(void) { +Camera_ErrorCode NDKCamera::CameraInputRelease(void) +{ + OH_LOG_ERROR(LOG_APP, "enter CameraInputRelease."); ret_ = OH_CameraInput_Release(cameraInput_); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CameraInputRelease failed."); + OH_LOG_ERROR(LOG_APP, "CameraInput_Release failed."); return CAMERA_INVALID_ARGUMENT; } OH_LOG_ERROR(LOG_APP, "exit CameraInputRelease."); return ret_; } -Camera_ErrorCode NDKCamera::GetSupportedCameras(void) { +Camera_ErrorCode NDKCamera::GetSupportedCameras(void) +{ ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, &size_); if (cameras_ == nullptr || &size_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "GetSupportedCaneras failed."); + OH_LOG_ERROR(LOG_APP, "Get supported cameras failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_ERROR(LOG_APP, "exit GetSupportedCaneras."); return ret_; } -Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void) { + +Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void) +{ ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, &cameras_[cameraDeviceIndex_], &cameraOutputCapability_); - if (ret_ != CAMERA_OK || cameraOutputCapability_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "GetSupportedOutputCapability failed."); + if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetSupportedCameraOutputCapability failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_ERROR(LOG_APP, "exit GetSupportedOutputCapability."); return ret_; } -Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) { +Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) +{ + DRAWING_LOGD("NDKCamera::CreatePreviewOutput start!"); profile_ = cameraOutputCapability_->previewProfiles[0]; + if (profile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); + OH_LOG_ERROR(LOG_APP, "Get previewProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_ERROR(LOG_APP, "exit CreatePreviewOutput."); - profile_->size.width = videoFrameWidth_; - profile_->size.height = videoFrameHeight_; + + profile_->size.width = videoFrameWidth; + profile_->size.height = videoFrameHeight; ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_); if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreatePreviewOutput failed."); + OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); return CAMERA_INVALID_ARGUMENT; } + // register preview output callback PreviewOutputRegisterCallback(); return ret_; } -Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId) { +Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId) +{ DRAWING_LOGD("NDKCamera::CreatePhotoOutput start!"); profile_ = cameraOutputCapability_->photoProfiles[0]; + if (profile_ == nullptr) { OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - profile_->size.width = videoFrameWidth_; - profile_->size.height = videoFrameHeight_; + + profile_->size.width = videoFrameWidth; + profile_->size.height = videoFrameHeight ; ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_); + if (photoSurfaceId == nullptr || photoOutput_ == nullptr || ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); return CAMERA_INVALID_ARGUMENT; } + // register photo output callback PhotoOutputRegisterCallback(); return ret_; } -Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) { - DRAWING_LOGD("NDKCamera::CreatePhotoOutput start!"); +Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) +{ + DRAWING_LOGD("NDKCamera::CreateVideoOutput start!"); videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed."); + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput width:%{public}d", videoProfile_->size.width); - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput height:%{public}d", videoProfile_->size.height); - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput format:%{public}d", videoProfile_->format); - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.min:%{public}d", videoProfile_->range.min); - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.max:%{public}d", videoProfile_->range.max); - - profile_->size.width = videoFrameWidth_; - profile_->size.height = videoFrameHeight_; + + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput width:%{public}d", videoProfile_->size.width); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput height:%{public}d", videoProfile_->size.height); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput format:%{public}d", videoProfile_->format); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.min:%{public}d", videoProfile_->range.min); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput range.max:%{public}d", videoProfile_->range.max); + + videoProfile_->size.width = videoFrameWidth; + videoProfile_->size.height = videoFrameHeight; ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_); + if (videoId == nullptr || videoOutput_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput failed."); return CAMERA_INVALID_ARGUMENT; } - // register photo output callback + + // register video output callback VideoOutputRegisterCallback(); return ret_; } -Camera_ErrorCode NDKCamera::AddVideoOutput(void) { + +Camera_ErrorCode NDKCamera::AddVideoOutput(void) +{ Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_AddVideoOutput success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddVideoOutput failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::AddPhotoOutput() { +Camera_ErrorCode NDKCamera::AddPhotoOutput() +{ Camera_ErrorCode ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_AddPhotoOutput success."); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::CreateMetadataOutput(void) { - DRAWING_LOGD("NDKCamera::CreateMetadataOutput start!"); +Camera_ErrorCode NDKCamera::CreateMetadataOutput(void) +{ metaDataObjectType_ = cameraOutputCapability_->supportedMetadataObjectTypes[0]; if (metaDataObjectType_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "Get CreateMetadataOutput failed."); + OH_LOG_ERROR(LOG_APP, "Get metaDataObjectType failed."); return CAMERA_INVALID_ARGUMENT; } ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, &metadataOutput_); - if (metadataOutput_ == nullptr || ret_ == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateMetadataOutput success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateMetadataOutput failed. %d ", ret_); + if (metadataOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CreateMetadataOutput failed."); + return CAMERA_INVALID_ARGUMENT; } + // register metadata output callback MetadataOutputRegisterCallback(); return ret_; } -Camera_ErrorCode NDKCamera::IsCameraMuted(void) { - OH_LOG_ERROR(LOG_APP, "enter IsCameraMuted."); +Camera_ErrorCode NDKCamera::IsCameraMuted(void) +{ ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, isCameraMuted_); if (isCameraMuted_ == nullptr || ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "IsCameraMuted failed."); @@ -518,7 +578,8 @@ Camera_ErrorCode NDKCamera::IsCameraMuted(void) { return ret_; } -Camera_ErrorCode NDKCamera::PreviewOutputStop(void) { +Camera_ErrorCode NDKCamera::PreviewOutputStop(void) +{ OH_LOG_ERROR(LOG_APP, "enter PreviewOutputStop."); ret_ = OH_PreviewOutput_Stop(previewOutput_); if (ret_ != CAMERA_OK) { @@ -528,7 +589,8 @@ Camera_ErrorCode NDKCamera::PreviewOutputStop(void) { return ret_; } -Camera_ErrorCode NDKCamera::PreviewOutputRelease(void) { +Camera_ErrorCode NDKCamera::PreviewOutputRelease(void) +{ OH_LOG_ERROR(LOG_APP, "enter PreviewOutputRelease."); if (previewOutput_ != nullptr) { ret_ = OH_PreviewOutput_Release(previewOutput_); @@ -541,7 +603,8 @@ Camera_ErrorCode NDKCamera::PreviewOutputRelease(void) { return CAMERA_OK; } -Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) { +Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) +{ OH_LOG_ERROR(LOG_APP, "enter PhotoOutputRelease."); ret_ = OH_PhotoOutput_Release(photoOutput_); if (ret_ != CAMERA_OK) { @@ -552,211 +615,205 @@ Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) { return ret_; } -Camera_ErrorCode NDKCamera::VideoOutputStart(void) { - OH_LOG_ERROR(LOG_APP, "enter VideoOutputStart."); +Camera_ErrorCode NDKCamera::VideoOutputStart(void) +{ + OH_LOG_INFO(LOG_APP, "VideoOutputStart begin."); Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "VideoOutputStart failed."); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_Start failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::IsExposureModeSupportedFn(uint32_t mode) { - OH_LOG_ERROR(LOG_APP, "enter IsExposureModeSupportedFn."); +// exposure mode +Camera_ErrorCode NDKCamera::IsExposureModeSupportedFn(uint32_t mode) +{ + OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn start."); exposureMode_ = static_cast(mode); ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode_, &isExposureModeSupported_); - if (&isExposureModeSupported_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupported failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode_); - if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + OH_LOG_ERROR(LOG_APP, "SetExposureMode failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); - if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + OH_LOG_ERROR(LOG_APP, "GetExposureMode failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn end."); return ret_; } -Camera_ErrorCode NDKCamera::IsMeteringPoint(int x, int y) { - OH_LOG_ERROR(LOG_APP, "enter IsMeteringPoint."); +Camera_ErrorCode NDKCamera::IsMeteringPoint(int x, int y) +{ + OH_LOG_INFO(LOG_APP, "IsMeteringPoint start."); ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + OH_LOG_ERROR(LOG_APP, "GetExposureMode failed."); return CAMERA_INVALID_ARGUMENT; } Camera_Point exposurePoint; exposurePoint.x = x; exposurePoint.y = y; - ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, exposurePoint); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetMeteringPoint failed."); + OH_LOG_ERROR(LOG_APP, "SetMeteringPoint failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, &exposurePoint); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetMeteringPoint failed."); + OH_LOG_ERROR(LOG_APP, "GetMeteringPoint failed."); return CAMERA_INVALID_ARGUMENT; } OH_LOG_INFO(LOG_APP, "IsMeteringPoint end."); return ret_; } -Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias) { - OH_LOG_ERROR(LOG_APP, "enter IsExposureBiasRange."); +Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias) +{ + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); float exposureBiasValue = (float)exposureBias; ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_); if (&minExposureBias_ == nullptr || &maxExposureBias_ == nullptr || &step_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsExposureModeSupportedFn failed."); + OH_LOG_ERROR(LOG_APP, "GetExposureBiasRange failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBiasValue); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetExposureBias end."); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetExposureBias failed."); + OH_LOG_ERROR(LOG_APP, "SetExposureBias failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBiasValue); if (&exposureBiasValue == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetExposureBias failed."); + OH_LOG_ERROR(LOG_APP, "GetExposureBias failed."); return CAMERA_INVALID_ARGUMENT; } OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); return ret_; } -Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusModeSupported."); +// focus mode +Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode) +{ Camera_FocusMode focusMode = static_cast(mode); ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed."); return CAMERA_INVALID_ARGUMENT; } - - OH_LOG_INFO(LOG_APP, "IsFocusModeSupported end."); return ret_; } -Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusMode."); + +Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) +{ + OH_LOG_INFO(LOG_APP, "IsFocusMode start."); Camera_FocusMode focusMode = static_cast(mode); ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_SetFocusMode(captureSession_, focusMode); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + OH_LOG_ERROR(LOG_APP, "SetFocusMode failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode); - if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "IsFocusMode failed."); + if (&focusMode == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetFocusMode failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_INFO(LOG_APP, "IsFocusMode end."); return ret_; } -Camera_ErrorCode NDKCamera::IsFocusPoint(float x, float y) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); +Camera_ErrorCode NDKCamera::IsFocusPoint(float x, float y) +{ + OH_LOG_INFO(LOG_APP, "IsFocusPoint start."); Camera_Point focusPoint; focusPoint.x = x; focusPoint.y = y; ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, focusPoint); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFocusPoint failed."); + OH_LOG_ERROR(LOG_APP, "SetFocusPoint failed."); return CAMERA_INVALID_ARGUMENT; } - ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint); if (&focusPoint == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + OH_LOG_ERROR(LOG_APP, "GetFocusPoint failed."); return CAMERA_INVALID_ARGUMENT; } - OH_LOG_INFO(LOG_APP, "IsFocusPoint end."); return ret_; } -int32_t NDKCamera::GetVideoFrameWidth(void) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); +int32_t NDKCamera::GetVideoFrameWidth(void) +{ videoProfile_ = cameraOutputCapability_->videoProfiles[0]; if (videoProfile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - - OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); return videoProfile_->size.width; } -int32_t NDKCamera::GetVideoFrameHeight(void) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); +int32_t NDKCamera::GetVideoFrameHeight(void) +{ videoProfile_ = cameraOutputCapability_->videoProfiles[0]; if (videoProfile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - - OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); return videoProfile_->size.height; } -int32_t NDKCamera::GetVideoFrameRate(void) { - OH_LOG_ERROR(LOG_APP, "enter IsFocusPoint."); +int32_t NDKCamera::GetVideoFrameRate(void) +{ videoProfile_ = cameraOutputCapability_->videoProfiles[0]; if (videoProfile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusPoint failed."); + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - - OH_LOG_INFO(LOG_APP, "GetVideoFrameWidth end."); return videoProfile_->range.min; } -Camera_ErrorCode NDKCamera::VideoOutputStop(void) { - OH_LOG_ERROR(LOG_APP, " VideoOutputStop into"); +Camera_ErrorCode NDKCamera::VideoOutputStop(void) +{ + OH_LOG_ERROR(LOG_APP, "enter VideoOutputStop."); ret_ = OH_VideoOutput_Stop(videoOutput_); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + OH_LOG_ERROR(LOG_APP, "VideoOutputStop failed."); return CAMERA_INVALID_ARGUMENT; } return ret_; } -Camera_ErrorCode NDKCamera::VideoOutputRelease(void) { - OH_LOG_ERROR(LOG_APP, " VideoOutputRelease into"); +Camera_ErrorCode NDKCamera::VideoOutputRelease(void) +{ + OH_LOG_ERROR(LOG_APP, "enter VideoOutputRelease."); if (videoOutput_ == nullptr) { + OH_LOG_DEBUG(LOG_APP, "VideoOutputRelease videoOutput_ is already null."); return CAMERA_OK; } ret_ = OH_VideoOutput_Release(videoOutput_); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "startPhoto failed."); + OH_LOG_ERROR(LOG_APP, "VideoOutputRelease failed."); return CAMERA_INVALID_ARGUMENT; } videoOutput_ = nullptr; return ret_; } -Camera_ErrorCode NDKCamera::TakePicture(void) { + +Camera_ErrorCode NDKCamera::TakePicture(void) +{ Camera_ErrorCode ret = CAMERA_OK; ret = OH_PhotoOutput_Capture(photoOutput_); OH_LOG_ERROR(LOG_APP, "takePicture OH_PhotoOutput_Capture ret = %{public}d.", ret); @@ -767,15 +824,18 @@ Camera_ErrorCode NDKCamera::TakePicture(void) { return ret; } -Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photosetting) { +Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting) +{ Camera_ErrorCode ret = CAMERA_OK; - ret = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photosetting); - OH_LOG_ERROR(LOG_APP, "takePicture OH_PhotoOutput_Capture ret = %{public}d.", ret); - OH_LOG_ERROR(LOG_APP, - "TakePictureWithPhotoSettings get uality %{public}d,roration %{public}d,mirro %{public}d," - "latitude, %{public}d, longitude %{public}d, altitude %{public}d", - photosetting.quality, photosetting.rotation, photosetting.mirror, photosetting.location->latitude, - photosetting.location->longitude, photosetting.location->altitude); + ret = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photoSetting); + + OH_LOG_INFO(LOG_APP, + "TakePictureWithPhotoSettings get quality %{public}d, rotation %{public}d, mirror %{public}d, " + "latitude, %{public}d, longitude %{public}d, altitude %{public}d", + photoSetting.quality, photoSetting.rotation, photoSetting.mirror, photoSetting.location->latitude, + photoSetting.location->longitude, photoSetting.location->altitude); + + OH_LOG_ERROR(LOG_APP, "takePicture TakePictureWithPhotoSettings ret = %{public}d.", ret); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "startPhoto failed."); return CAMERA_INVALID_ARGUMENT; @@ -784,16 +844,19 @@ Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSett } // CameraManager Callback -void CameraManagerStatusCallback(Camera_Manager *cameraManager, Camera_StatusInfo *status) { +void CameraManagerStatusCallback(Camera_Manager *cameraManager, Camera_StatusInfo *status) +{ OH_LOG_INFO(LOG_APP, "CameraManagerStatusCallback"); } -CameraManager_Callbacks *NDKCamera::GetCameraManagerListener(void) { +CameraManager_Callbacks *NDKCamera::GetCameraManagerListener(void) +{ static CameraManager_Callbacks cameraManagerListener = {.onCameraStatus = CameraManagerStatusCallback}; return &cameraManagerListener; } -Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void) { +Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void) +{ ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener()); if (ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_CameraManager_RegisterCallback failed."); @@ -802,16 +865,19 @@ Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void) { } // CameraInput Callback -void OnCameraInputError(const Camera_Input *cameraInput, Camera_ErrorCode errorCode) { +void OnCameraInputError(const Camera_Input *cameraInput, Camera_ErrorCode errorCode) +{ OH_LOG_INFO(LOG_APP, "OnCameraInput errorCode = %{public}d", errorCode); } -CameraInput_Callbacks *NDKCamera::GetCameraInputListener(void) { +CameraInput_Callbacks *NDKCamera::GetCameraInputListener(void) +{ static CameraInput_Callbacks cameraInputCallbacks = {.onError = OnCameraInputError}; return &cameraInputCallbacks; } -Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void) { +Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void) +{ ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener()); if (ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_CameraInput_RegisterCallback failed."); @@ -820,26 +886,33 @@ Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void) { } // PreviewOutput Callback -void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput) { +void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput) +{ OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart"); } -void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameCount) { +void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameCount) +{ OH_LOG_INFO(LOG_APP, "PreviewOutput frameCount = %{public}d", frameCount); } -void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode) { +void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode) +{ OH_LOG_INFO(LOG_APP, "PreviewOutput errorCode = %{public}d", errorCode); } -PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void) { - static PreviewOutput_Callbacks previewOutputListener = {.onFrameStart = PreviewOutputOnFrameStart, - .onFrameEnd = PreviewOutputOnFrameEnd, - .onError = PreviewOutputOnError}; +PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void) +{ + static PreviewOutput_Callbacks previewOutputListener = { + .onFrameStart = PreviewOutputOnFrameStart, + .onFrameEnd = PreviewOutputOnFrameEnd, + .onError = PreviewOutputOnError + }; return &previewOutputListener; } -Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void) { +Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void) +{ ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener()); if (ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_RegisterCallback failed."); @@ -848,114 +921,139 @@ Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void) { } // PhotoOutput Callback -void PhotoOutputOnFrameStart(Camera_PhotoOutput *photoOutput) { +void PhotoOutputOnFrameStart(Camera_PhotoOutput *photoOutput) +{ DRAWING_LOGD("PhotoOutputOnFrameStart start!"); OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameStart"); } -void PhotoOutputOnFrameShutter(Camera_PhotoOutput *photoOutput, Camera_FrameShutterInfo *info) { +void PhotoOutputOnFrameShutter(Camera_PhotoOutput *photoOutput, Camera_FrameShutterInfo *info) +{ DRAWING_LOGD("PhotoOutputOnFrameShutter start!"); OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameShutter"); } -void PhotoOutputOnFrameEnd(Camera_PhotoOutput *photoOutput, int32_t frameCount) { +void PhotoOutputOnFrameEnd(Camera_PhotoOutput *photoOutput, int32_t frameCount) +{ DRAWING_LOGD("PhotoOutputOnFrameEnd start!"); OH_LOG_INFO(LOG_APP, "PhotoOutput frameCount = %{public}d", frameCount); } -void PhotoOutputOnError(Camera_PhotoOutput *photoOutput, Camera_ErrorCode errorCode) { +void PhotoOutputOnError(Camera_PhotoOutput *photoOutput, Camera_ErrorCode errorCode) +{ DRAWING_LOGD("PhotoOutputOnError start!"); OH_LOG_INFO(LOG_APP, "PhotoOutput errorCode = %{public}d", errorCode); } -PhotoOutput_Callbacks *NDKCamera::GetPhotoOutputListener(void) { - static PhotoOutput_Callbacks photoOutputListener = {.onFrameStart = PhotoOutputOnFrameStart, - .onFrameShutter = PhotoOutputOnFrameShutter, - .onFrameEnd = PhotoOutputOnFrameEnd, - .onError = PhotoOutputOnError}; +PhotoOutput_Callbacks *NDKCamera::GetPhotoOutputListener(void) +{ + static PhotoOutput_Callbacks photoOutputListener = { + .onFrameStart = PhotoOutputOnFrameStart, + .onFrameShutter = PhotoOutputOnFrameShutter, + .onFrameEnd = PhotoOutputOnFrameEnd, + .onError = PhotoOutputOnError + }; return &photoOutputListener; } -// PhotoOutput Callback -void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput) { - DRAWING_LOGD("VideoOutputOnFrameStart start!"); - OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart"); +Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void) +{ + ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + } + return ret_; } -void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount) { - DRAWING_LOGD("VideoOutputOnFrameEnd start!"); - OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameEnd frameCount = %{public}d", frameCount); + +// VideoOutput Callback +void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput) +{ + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart"); } -void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode) { - DRAWING_LOGD("VideoOutputOnError start!"); - OH_LOG_INFO(LOG_APP, "VideoOutputOnError errorCode = %{public}d", errorCode); + +void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount) +{ + OH_LOG_INFO(LOG_APP, "VideoOutput frameCount = %{public}d", frameCount); } +void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "VideoOutput errorCode = %{public}d", errorCode); +} -VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void) { +VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void) +{ static VideoOutput_Callbacks videoOutputListener = { - .onFrameStart = VideoOutputOnFrameStart, .onFrameEnd = VideoOutputOnFrameEnd, .onError = VideoOutputOnError}; + .onFrameStart = VideoOutputOnFrameStart, + .onFrameEnd = VideoOutputOnFrameEnd, + .onError = VideoOutputOnError + }; return &videoOutputListener; } -Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void) { - ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener()); +Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void) +{ + ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener()); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_RegisterCallback failed."); } return ret_; } - +// Metadata Callback void OnMetadataObjectAvailable(Camera_MetadataOutput *metadataOutput, Camera_MetadataObject *metadataObject, - uint32_t size) { - DRAWING_LOGD("OnMetadataObjectAvailable start!"); - OH_LOG_INFO(LOG_APP, "OnMetadataObjectAvailable size = %{public}d", size); + uint32_t size) +{ + OH_LOG_INFO(LOG_APP, "size = %{public}d", size); } -void OnMetadataOutputError(Camera_MetadataOutput *metadataOutput, Camera_ErrorCode errorCode) { - DRAWING_LOGD("OnMetadataOutputError start!"); - OH_LOG_INFO(LOG_APP, "OnMetadataOutputError errorCode = %{public}d", errorCode); +void OnMetadataOutputError(Camera_MetadataOutput *metadataOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "OnMetadataOutput errorCode = %{public}d", errorCode); } -MetadataOutput_Callbacks *NDKCamera::GetMetadataOutputListener(void) { - static MetadataOutput_Callbacks metadataOutputListener = {.onMetadataObjectAvailable = OnMetadataObjectAvailable, - .onError = OnMetadataOutputError}; + +MetadataOutput_Callbacks *NDKCamera::GetMetadataOutputListener(void) +{ + static MetadataOutput_Callbacks metadataOutputListener = { + .onMetadataObjectAvailable = OnMetadataObjectAvailable, + .onError = OnMetadataOutputError + }; return &metadataOutputListener; } -Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void) { +Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void) +{ ret_ = OH_MetadataOutput_RegisterCallback(metadataOutput_, GetMetadataOutputListener()); if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); - } - return ret_; -} - -Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void) { - ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener()); - if (ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + OH_LOG_ERROR(LOG_APP, "OH_MetadataOutput_RegisterCallback failed."); } return ret_; } // Session Callback -void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState) { +void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState) +{ OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnFocusStateChange"); OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange"); } -void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode) { +void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode) +{ OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnError"); OH_LOG_INFO(LOG_APP, "CaptureSession errorCode = %{public}d", errorCode); } -CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(void) { - static CaptureSession_Callbacks captureSessionCallbacks = {.onFocusStateChange = CaptureSessionOnFocusStateChange, - .onError = CaptureSessionOnError}; +CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(void) +{ + static CaptureSession_Callbacks captureSessionCallbacks = { + .onFocusStateChange = CaptureSessionOnFocusStateChange, + .onError = CaptureSessionOnError + }; return &captureSessionCallbacks; } -Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void) { +Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void) +{ ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister()); if (ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_RegisterCallback failed."); -- Gitee From 55e79e0ef159d95a22aa118f6900b2a3a4aa0a53 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:28:59 +0000 Subject: [PATCH 08/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp. Signed-off-by: Steven --- .../entry/src/main/cpp/camera_manager.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp index 864d34bcb8..ed7578c2ca 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp @@ -38,7 +38,6 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc sceneMode_(NORMAL_VIDEO), exposureMode_(EXPOSURE_MODE_LOCKED), ret_(CAMERA_OK), size_(0), minExposureBias_(0), maxExposureBias_(0), step_(0) { - OH_LOG_ERROR(LOG_APP, "=====testZj1===="); // release camera ReleaseCamera(); @@ -47,19 +46,12 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc if (cameraManager_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Get CameraManager failed."); } - OH_LOG_INFO(LOG_APP, "=====testZj2===="); -// -// // register camera manager callback -// CameraManagerRegisterCallback(); -// ret = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_); - // create capture session ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); if (captureSession_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); } - OH_LOG_INFO(LOG_APP, "=====testZj3===="); // look up sceneMode auto itr1 = g_int32ToCameraSceneMode.find(sceneMode); @@ -69,11 +61,6 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc // set session mode ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); -// DRAWING_LOGD("OH_CaptureSession_SetSessionMode sceneMode_: %{public}d!", sceneMode_); -// DRAWING_LOGD("OH_CaptureSession_SetSessionMode return with ret code: %{public}d!", ret); - OH_LOG_INFO(LOG_APP, "=====testZj4===="); - // register capture session callback -// CaptureSessionRegisterCallback(); // get capture session profile GetSupportedCameras(); @@ -351,12 +338,6 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - // create photo output and register photo output callback -// CreatePhotoOutput(photoSurfaceId_); - - // add photoOutput to the Session -// AddPhotoOutput(); - if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { // create video output and register video output callback CreateVideoOutput(videoSurfaceId_); -- Gitee From d95f192262289a56e759cb486a77c914e8560642 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:31:56 +0000 Subject: [PATCH 09/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp. Signed-off-by: Steven --- .../Media/AVRecorder/entry/src/main/cpp/main.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp index cffdb84005..93b79dbddb 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.cpp @@ -384,10 +384,7 @@ static napi_value PrepareCamera(napi_env env, napi_callback_info info) napi_get_value_string_utf8(env, args[4], photoId, typeLen + 1, &typeLen); // 获取surfaceID - OH_LOG_INFO(LOG_APP, "==NDKDemo== 000 AVRecorder window : %{public}d", 1); - OH_LOG_INFO(LOG_APP, "==NDKDemo== 000 AVRecorder g_avRecorder: %{public}p", g_avRecorder); OHNativeWindow *window = nullptr; - OH_LOG_INFO(LOG_APP, "==NDKDemo== 111222 AVRecorder initial window address: %{public}p", window); int resultCode = OH_AVRecorder_GetInputSurface(g_avRecorder, &window); if (resultCode != AV_ERR_OK || window == nullptr) { @@ -478,7 +475,6 @@ static napi_value ResetAVRecorder(napi_env env, napi_callback_info info) { (void)info; // 检查 g_avRecorder 是否有效 - OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 1: %{public}p", g_avRecorder); if (g_avRecorder == nullptr) { OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); napi_value res; @@ -500,7 +496,6 @@ static napi_value ReleaseAVRecorder(napi_env env, napi_callback_info info) { (void)info; // 检查 g_avRecorder 是否有效 - OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 2: %{public}p", g_avRecorder); if (g_avRecorder == nullptr) { OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder is nullptr!"); napi_value res; @@ -511,7 +506,6 @@ static napi_value ReleaseAVRecorder(napi_env env, napi_callback_info info) int result = OH_AVRecorder_Release(g_avRecorder); g_avRecorder = nullptr; // 释放录制资源后,需要显式地将g_avRecorder指针置空 - OH_LOG_ERROR(LOG_APP, "==NDKDemo== g_avRecorder 3: %{public}p", g_avRecorder); if (result != AV_ERR_OK) { OH_LOG_ERROR(LOG_APP, "==NDKDemo== AVRecorder Release failed %{public}d", result); } @@ -524,7 +518,6 @@ EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc[] = { - { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }, {"prepareAVRecorder", nullptr, PrepareAVRecorder, nullptr, nullptr, nullptr, napi_default, nullptr}, {"getAVRecorderConfig", nullptr, GetAVRecorderConfig, nullptr, nullptr, nullptr, napi_default, nullptr}, {"getAvailableEncoder", nullptr, GetAvailableEncoder, nullptr, nullptr, nullptr, napi_default, nullptr}, -- Gitee From 7a93250a15070609b694c4c8b3401cab81610b08 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:33:51 +0000 Subject: [PATCH 10/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts. Signed-off-by: Steven --- .../src/main/cpp/types/libentry/index.d.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts index 0b83eeec9e..863fcd134f 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts @@ -12,11 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const createAVRecorder: () => number; -export const prepareAVRecorder: (mapB: ESObject, fdNumber: String) => number; +export const prepareAVRecorder: () => number; -export const createPrepareAVRecorder: () => number; +export const getAVRecorderConfig: () => number; + +export const getAvailableEncoder: () => number; + +export const prepareCamera: (focusMode: number, cameraDeviceIndex: number, sceneMode: number, + previewId: string, photoId: string, videoId: string) => number; export const startAVRecorder: () => number; @@ -30,16 +34,5 @@ export const resetAVRecorder: () => number; export const releaseAVRecorder: () => number; -export const updateRotationAVRecorder: (videoRotation: number) => number; - -export const prepareCamera: (focusMode: number, cameraDeviceIndex: number, sceneMode: number, previewId: string, - photeId: string, videoId: string) => number; - -export const setPreviewSurfaceId: () => number; - -export const getAVRecorderConfig: () => number; - -export const getAvailableEncoder: () => number; - -- Gitee From 23761a195430723173c533fcf932fd7b8e733dfa Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:36:06 +0000 Subject: [PATCH 11/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h. Signed-off-by: Steven --- .../Media/AVRecorder/entry/src/main/cpp/log_common.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h index 318e16c9ce..42c843ccc2 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,6 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#ifndef AVRECORDER_LOG_COMMON_H +#define AVRECORDER_LOG_COMMON_H + #ifndef LOG_COMMON_H #define LOG_COMMON_H #include @@ -23,4 +27,5 @@ constexpr const char *APP_LOG_TAG = "DrawingSample"; #define DRAWING_LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) #define DRAWING_LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) -#endif // LOG_COMMON_H \ No newline at end of file +#endif // LOG_COMMON_H +#endif //AVRECORDER_LOG_COMMON_H \ No newline at end of file -- Gitee From e14ed76b993df043cfe2b9ba29fbabaea7e1dd8c Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:36:59 +0000 Subject: [PATCH 12/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h index b77dbd1d5f..8a4605c259 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/main.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 9594605b3ad9fa6633eb3d6fb228227f3c3b0556 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:39:16 +0000 Subject: [PATCH 13/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/cpp/muxer.cpp | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp index 488b9f3fc5..c0a1f0a2da 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp @@ -12,62 +12,80 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include + +#include "muxer.h" +#include "hilog/log.h" + #undef LOG_TAG #define LOG_TAG "Muxer" -#include "sample_info.h" -#include namespace { constexpr int32_t VERTICAL_ANGLE = 90; constexpr int32_t HORIZONTAL_ANGLE = 0; +} -} // namespace - -Muxer::~Muxer() { Release(); } +Muxer::~Muxer() +{ + Release(); +} -int32_t Muxer::Create(int32_t fd) { +int32_t Muxer::Create(int32_t fd) +{ muxer_ = OH_AVMuxer_Create(fd, AV_OUTPUT_FORMAT_MPEG_4); return 0; } -int32_t Muxer::Config(SampleInfo &sampleInfo) { - OH_LOG_INFO(LOG_APP,"==Demo== Config"); - OH_AVFormat *formatVideo = - OH_AVFormat_CreateVideoFormat(sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight); + +int32_t Muxer::Config(SampleInfo &sampleInfo) +{ + OH_LOG_INFO(LOG_APP, "==DEMO== Config"); + OH_AVFormat *formatVideo = OH_AVFormat_CreateVideoFormat(sampleInfo.codecMime.data(), + sampleInfo.videoWidth, sampleInfo.videoHeight); OH_AVFormat_SetDoubleValue(formatVideo, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); OH_AVFormat_SetIntValue(formatVideo, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); OH_AVFormat_SetStringValue(formatVideo, OH_MD_KEY_CODEC_MIME, sampleInfo.codecMime.data()); - int32_t ret = OH_AVMuxer_AddTrack(muxer_, &videoTrackId_, formatVideo); + + int32_t ret = OH_AVMuxer_AddTrack(muxer_, &videoTrackId_, formatVideo); // ! OH_AVFormat_Destroy(formatVideo); + + OH_LOG_INFO(LOG_APP, "==DEMO== Config End"); return 0; } -int32_t Muxer::Start() { + +int32_t Muxer::Start() +{ int ret = OH_AVMuxer_Start(muxer_); return 0; } -int32_t Muxer::WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + +int32_t Muxer::WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) +{ + OH_LOG_INFO(LOG_APP, "==DEMO== WriteSample"); int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); ret = OH_AVMuxer_WriteSampleBuffer(muxer_, videoTrackId_, buffer); return 0; } -int32_t Muxer::WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { + +int32_t Muxer::WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) +{ + OH_LOG_INFO(LOG_APP, "==DEMO== WriteAudioSample"); int32_t ret = OH_AVBuffer_SetBufferAttr(buffer, &attr); ret = OH_AVMuxer_WriteSampleBuffer(muxer_, audioTrackId_, buffer); return 0; } -int32_t Muxer::Stop() { + +int32_t Muxer::Stop() +{ int32_t ret = OH_AVMuxer_Stop(muxer_); return 0; } -int32_t Muxer::Release() { - if (muxer_ != nullptr) { +int32_t Muxer::Release() +{ + if (muxer_ != nullptr) { OH_AVMuxer_Destroy(muxer_); muxer_ = nullptr; } return 0; -} \ No newline at end of file +} -- Gitee From 52868f338ab41d59569e3e47edcc2aa411e9b628 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:39:28 +0000 Subject: [PATCH 14/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp index c0a1f0a2da..7aebe1b616 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 580a63d1e951f3393d3f3db91439c080a1d59a64 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:40:09 +0000 Subject: [PATCH 15/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/cpp/muxer.h | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h index 16fa0843ef..603cc602a3 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/muxer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,30 +12,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef MUXER_H #define MUXER_H +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "MY_NDKDEMO" #include - #include "sample_info.h" -#include -class Muxer{ -public: - Muxer()=default; +#include "multimedia/player_framework/native_avmuxer.h" + +class Muxer { +public: + Muxer() = default; ~Muxer(); - + int32_t Create(int32_t fd); int32_t Config(SampleInfo &sampleInfo); int32_t Start(); - int32_t WriteSample(OH_AVBuffer *buffer,OH_AVCodecBufferAttr &arrt); - int32_t WriteAudioData(OH_AVBuffer *buffer,OH_AVCodecBufferAttr &arrt); - + int32_t WriteSample(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr); + int32_t WriteAudioData(OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr); + int32_t Stop(); int32_t Release(); + private: - OH_AVMuxer *muxer_=nullptr; + OH_AVMuxer *muxer_ = nullptr; int32_t videoTrackId_ = -1; int32_t audioTrackId_ = -1; - int32_t converTrackId_ = -1; + int32_t coverTrackId_ = -1; }; -#endif // MUER_H \ No newline at end of file + +#endif // MUXER_H \ No newline at end of file -- Gitee From 780b9f8c4bf39993dd9e2ea56aa865e68fa193dd Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:40:44 +0000 Subject: [PATCH 16/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h. Signed-off-by: Steven --- .../entry/src/main/cpp/sample_info.h | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h index 11386d4d5d..d9a20dadaf 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/sample_info.h @@ -1,10 +1,10 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -12,28 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef AVCODEC_SAMPLE_INFO_H #define AVCODEC_SAMPLE_INFO_H -#include "bits/alltypes.h" -#include "cstdint" -#include "map" +#include +#include +#include #include +#include +#include +#include +#include #include #include -#include "string" -#include "condition_variable" -#include "queue" -#include "native_buffer/native_buffer.h" #define ANNEXB_INPUT_ONLY 1 const std::string_view MIME_VIDEO_AVC = "video/avc"; const std::string_view MIME_VIDEO_HEVC = "video/hevc"; -constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; -constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; -constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; + +constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; // 10Mbps +constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; // 20Mbps +constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; // 30Mbps + struct SampleInfo { int32_t sampleId = 0; + int32_t inputFd = -1; int32_t outFd = -1; int64_t inputFileOffset = 0; @@ -46,19 +50,21 @@ struct SampleInfo { int32_t videoWidth = 0; int32_t videoHeight = 0; double frameRate = 0.0; - int64_t bitrate = 10 * 1024 * 1024; + int64_t bitrate = 10 * 1024 * 1024; // 10Mbps; int64_t frameInterval = 0; - int32_t perfMode = 0; + int32_t perfmode = 0; + int64_t durationTime = 0; uint32_t maxFrames = UINT32_MAX; int32_t isHDRVivid = 0; uint32_t repeatTimes = 1; - OH_AVPixelFormat pixlFormat = AV_PIXEL_FORMAT_NV12; + OH_AVPixelFormat pixelFormat = AV_PIXEL_FORMAT_NV12; bool needDumpOutput = false; uint32_t bitrateMode = CBR; int32_t hevcProfile = HEVC_PROFILE_MAIN; int32_t rotation = 0; OHNativeWindow *window = nullptr; + int32_t sampleRate = 44100; int32_t channelCount = 2; @@ -67,8 +73,9 @@ struct SampleInfo { double memcpyTime = 0; double writeTime = 0; void (*PlayDoneCallback)(void *context) = nullptr; - void *PlayDoneCallbackData = nullptr; + void *playDoneCallbackData = nullptr; }; + struct CodecBufferInfo { uint32_t bufferIndex = 0; uintptr_t *buffer = nullptr; @@ -87,22 +94,22 @@ struct CodecBufferInfo { OH_AVBuffer_GetBufferAttr(argBuffer, &attr); }; }; + class AEncBufferSignal { public: std::mutex inMutex_; std::mutex outMutex_; std::mutex startMutex_; - std::condition_variable inCond_; std::condition_variable outCond_; std::condition_variable startCond_; - std::queue inQueue_; std::queue outQueue_; std::queue inBufferQueue_; std::queue outBufferQueue_; OH_AVCodecBufferAttr audioInfo = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE}; }; + class CodecUserData { public: SampleInfo *sampleInfo = nullptr; @@ -116,7 +123,7 @@ public: std::mutex outputMutex_; std::condition_variable outputCond_; std::queue outputBufferInfoQueue_; - AEncBufferSignal *signal; + AEncBufferSignal *signal_; void ClearQueue() { { -- Gitee From e897a0c9b479276f3efb420edaf5ef6a9bc11135 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:41:28 +0000 Subject: [PATCH 17/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp. Signed-off-by: Steven --- .../src/main/cpp/video_encoder_sample.cpp | 66 ++++++++++++------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp index 57e2ef1e18..aca43bbabb 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.cpp @@ -1,10 +1,10 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -12,46 +12,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include -namespace{ + +#include "video_encoder_sample.h" +#include "hilog/log.h" + +namespace { constexpr int LIMIT_LOGD_FREQUENCY = 50; } -void SampleCallback::OnError(OH_AVCodec *codec, int32_t errorCode, void *userData){ + +// 设置 OnError 回调函数 +void SampleCallback::OnError(OH_AVCodec *codec, int32_t errorCode, void *userData) { + // 回调的错误码由用户判断处理 (void)codec; (void)errorCode; (void)userData; - + OH_LOG_ERROR(LOG_APP, "On error, error code: %{public}d", errorCode); } -void SampleCallback::OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData){ - + +// 设置 OnStreamChanged 回调函数 +void SampleCallback::OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData) { +// surface模式下,该回调函数无作用 (void)codec; (void)format; (void)userData; } -void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData){ - - (void)codec; - (void)index; + +// 设置 OH_AVCodecOnNeedInputBuffer 回调函数,编码输入帧送入数据队列 +void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) { +// surface模式下,该回调函数无作用,用户通过获取的surface输入数据 + OH_LOG_INFO(LOG_APP, "==DEMO== Video OnNeedInputBuffer"); + (void)userData; - if(userData==nullptr){ + (void)index; + (void)buffer; + if (userData == nullptr) { return; } - (void )codec; - CodecUserData *codecUserData=static_cast(userData); + (void)codec; + CodecUserData *codecUserData = static_cast(userData); std::unique_lock lock(codecUserData->inputMutex_); - codecUserData->inputBufferInfoQueue_.emplace(index,buffer); + codecUserData->inputBufferInfoQueue_.emplace(index, buffer); codecUserData->inputCond_.notify_all(); } -void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData){ - if(userData==nullptr){ + +// 设置 OH_AVCodecOnNewOutputBuffer 回调函数,编码完成帧送入输出队列 +void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) { + // 完成帧buffer对应的index,送入outIndexQueue队列 + // 完成帧的数据buffer送入outBufferQueue队列 + // 数据处理,请参考: + // - 释放编码帧 + OH_LOG_INFO(LOG_APP, "==DEMO== Video OnNewOutputBuffer"); + if (userData == nullptr) { return; } - (void )codec; - CodecUserData *codecUserData=static_cast(userData); - std::unique_lock lock(codecUserData->inputMutex_); - codecUserData->outputBufferInfoQueue_.emplace(index,buffer); + (void)codec; + CodecUserData *codecUserData = static_cast(userData); + std::unique_lock lock(codecUserData->outputMutex_); + codecUserData->outputBufferInfoQueue_.emplace(index, buffer); codecUserData->outputCond_.notify_all(); - } \ No newline at end of file -- Gitee From d13bd3e3bb0add5229ad2f7ee21b6cb56ccc39d8 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:41:53 +0000 Subject: [PATCH 18/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h. Signed-off-by: Steven --- .../entry/src/main/cpp/video_encoder_sample.h | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h index 5a86b0f089..0324949f8b 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/video_encoder_sample.h @@ -1,10 +1,10 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -12,24 +12,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef AVCODEC_SAMPLE_CALLBACK_H #define AVCODEC_SAMPLE_CALLBACK_H #define LOG_DOMAIN 0x3200 #define LOG_TAG "MY_NDKDEMO" -#include #include "sample_info.h" #include -class SampleCallback{ +class SampleCallback { public: - SampleCallback(){} - SampleCallback(SampleCallback *p1){} - static void OnError(OH_AVCodec *codec,int32_t errorCode,void *userData); - static void OnStreamChanged(OH_AVCodec *codec,OH_AVFormat *format,void *userData); - static void OnNeedInputBuffer(OH_AVCodec *codec,uint32_t index,OH_AVBuffer *buffer,void *userData); - static void OnNewOutputBuffer(OH_AVCodec *codec,uint32_t index,OH_AVBuffer *buffer,void *userData); + SampleCallback() {} + SampleCallback(SampleCallback *p1) {} + static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData); + static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData); + static void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); + static void OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); - OH_AVMuxer *muxer_=nullptr; - int32_t g_videoTrackId=-1; + OH_AVMuxer *muxer_ = nullptr; + int32_t g_videoTrackId = -1; }; -#endif // AVCODEC_SAMPLE_CALLBACK_H \ No newline at end of file + +#endif //AVCODEC_SAMPLE_CALLBACK_H -- Gitee From 4e892a899bf5e6f208af598259755ef885867d48 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 3 Jun 2025 15:45:30 +0000 Subject: [PATCH 19/62] update code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets. Signed-off-by: Steven --- .../entry/src/main/ets/pages/Index.ets | 151 ++++++++++++++++-- 1 file changed, 140 insertions(+), 11 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets index c4270ae251..0ed1278e81 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,23 +12,152 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import hilog from '@ohos.hilog'; + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; +import camera from '@ohos.multimedia.camera'; +import image from '@ohos.multimedia.image'; +import media from '@ohos.multimedia.media'; +import { BusinessError } from'@kit.BasicServicesKit'; +import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; +const permissions: Array = ['ohos.permission.CAMERA']; + +const componentType_Jpeg = image.ComponentType.JPEG + @Entry @Component -struct Index { - @State message: string = 'Hello World' +export struct Index { + @State message: string = 'Hello World'; + // XComponentController + private mXComponentController: XComponentController = new XComponentController(); + public videoRecorder?: media.AVRecorder; + // surfaceID value + @State focusMode: number = 2; + @State cameraDeviceIndex: number = 0; + @State sceneMode: number = 2; + @State previewId: string = ''; + @State photoId: string = ''; + @State videoId: string = ''; + @State xComponentWidth: number = 384; + @State xComponentHeight: number = 450; build() { - Row() { Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { + XComponent({ + id: 'componentId', + type: XComponentType.SURFACE, + controller: this.mXComponentController + }) + .onLoad(async () => { + this.previewId = this.mXComponentController.getXComponentSurfaceId(); + hilog.info(0x0000, 'testTag', 'previewId: %{public}s', this.previewId); + + hilog.info(0x0000, 'testTag', 'Prepare AVRecorder %{public}d', testNapi.prepareAVRecorder()); + + hilog.info(0x0000, 'testTag', 'prepare Camera %{public}d', testNapi.prepareCamera(this.focusMode, this.cameraDeviceIndex, + this.sceneMode, this.previewId, this.photoId, this.videoId)); + }) + .onDestroy(() => { + // 组件销毁时执行的操作 + hilog.info(0x0000, 'testTag', 'Application is closing, perform cleanup.'); + testNapi.releaseAVRecorder(); + }) + .backgroundColor(Color.Black) + .width('100%') + .height('70%') + Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, + alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }) { + + // // ** 可选: 获取实时录制参数 ** + Button('GetConfig', { type: ButtonType.Circle, stateEffect: true }) + .id("Start") + .backgroundColor(0xF55A42) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Get AVRecorder Config %{public}d', testNapi.getAVRecorderConfig()); + }) + + // // ** 可选: 获取编码信息 ** + Button('GetInfo', { type: ButtonType.Circle, stateEffect: true }) + .id("Start") + .backgroundColor(0xF55A42) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Get AVRecorder EncoderInfo %{public}d', testNapi.getAvailableEncoder()); + }) + } + Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, + alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }){ + Button('Prepare', { type: ButtonType.Circle, stateEffect: true }) + .id("Prepare") + .backgroundColor(Color.Black) + .width(65) + .height(65) + .onClick(() => { + this.previewId = this.mXComponentController.getXComponentSurfaceId(); + hilog.info(0x0000, 'testTag', 'previewId: %{public}s', this.previewId); + hilog.info(0x0000, 'testTag', 'Prepare AVRecorder %{public}d', testNapi.prepareAVRecorder()); + hilog.info(0x0000, 'testTag', 'prepare Camera %{public}d', testNapi.prepareCamera(this.focusMode, this.cameraDeviceIndex, + this.sceneMode, this.previewId, this.photoId, this.videoId)); + hilog.info(0x0000, 'testTag', 'Start AVRecorder %{public}d', testNapi.startAVRecorder()); + }) + Button('Start', { type: ButtonType.Circle, stateEffect: true }) + .id("Start") + .backgroundColor(0xF55A42) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'After prepare surfaceId: %{public}s', this.videoId); + hilog.info(0x0000, 'testTag', 'Start AVRecorder %{public}d', testNapi.startAVRecorder()); + }) + Button('Pause', { type: ButtonType.Normal, stateEffect: true }) + .id("Pause") + .backgroundColor(0x4287F5) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Pause AVRecorder %{public}d', testNapi.pauseAVRecorder()); + }) + Button('Resume', { type: ButtonType.Capsule, stateEffect: true }) + .id("Resume") + .backgroundColor(0x4287F5) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Pause AVRecorder %{public}d', testNapi.resumeAVRecorder()); + }) + } + Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, + alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }){ + Button('Stop', { type: ButtonType.Capsule, stateEffect: true }) + .id("Stop") + .backgroundColor(0x4287F5) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Stop AVRecorder %{public}d', testNapi.stopAVRecorder()); + }) + Button('Reset', { type: ButtonType.Capsule, stateEffect: true }) + .id("Reset") + .backgroundColor(0x4287F5) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Reset AVRecorder %{public}d', testNapi.resetAVRecorder()); + }) + Button('Release', { type: ButtonType.Capsule, stateEffect: true }) + .id("Release") + .backgroundColor(0x4287F5) + .width(65) + .height(65) + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Release AVRecorder %{public}d', testNapi.releaseAVRecorder()); }) + } } .width('100%') - } .height('100%') } -} +} \ No newline at end of file -- Gitee From 4d9aa4da4e645d221a3fd9b43d631fc516d64e24 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 06:59:25 +0000 Subject: [PATCH 20/62] update code/DocsSample/Media/AVRecorder/AppScope/app.json5. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/AppScope/app.json5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/AppScope/app.json5 b/code/DocsSample/Media/AVRecorder/AppScope/app.json5 index 792d76e965..7e5ebd28f9 100644 --- a/code/DocsSample/Media/AVRecorder/AppScope/app.json5 +++ b/code/DocsSample/Media/AVRecorder/AppScope/app.json5 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,7 @@ */ { "app": { - "bundleName": "com.example.avrecorderndk", + "bundleName": "com.samples.avrecorder", "vendor": "example", "versionCode": 1000000, "versionName": "1.0.0", -- Gitee From 225f566dbfbf4a2806c650f5171a5097eb890240 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:02:22 +0000 Subject: [PATCH 21/62] update code/DocsSample/Media/AVRecorder/Test.json. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/Test.json | 28 ---------------------- 1 file changed, 28 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/Test.json b/code/DocsSample/Media/AVRecorder/Test.json index 6e07f8341f..e69de29bb2 100644 --- a/code/DocsSample/Media/AVRecorder/Test.json +++ b/code/DocsSample/Media/AVRecorder/Test.json @@ -1,28 +0,0 @@ -{ - "description": "Configuration for OhAudioNdk Tests", - "driver": { - "type": "OHJSUnitTest", - "test-timeout": "600000", - "shell-timeout": "600000", - "bundle-name": "com.example.avrecorderndk", - "module-name": "entry_test", - "testcase-timeout": 30000 - }, - "kits": [ - { - "test-file-name": [ - "ActsOhAVRecorderNDKMainTest.hap", - "ActsOhAVRecorderNDKTest.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - }, - { - "type": "ShellKit", - "run-command": [ - "power-shell wakeup", - "power-shell setmode 602" - ] - } - ] -} \ No newline at end of file -- Gitee From fde25a16160539f768ec4bb021f8861a3ded8529 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:05:50 +0000 Subject: [PATCH 22/62] update code/DocsSample/Media/AVRecorder/build-profile.json5. Signed-off-by: Steven --- .../Media/AVRecorder/build-profile.json5 | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/build-profile.json5 b/code/DocsSample/Media/AVRecorder/build-profile.json5 index 9ae18af1f5..35911cbabb 100644 --- a/code/DocsSample/Media/AVRecorder/build-profile.json5 +++ b/code/DocsSample/Media/AVRecorder/build-profile.json5 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,32 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -{ + + { "app": { - "signingConfigs": [ + "products": [ { "name": "default", - "material": { - "certpath": "C:/Users/admin/.ohos/config/openharmony/default_AVRecorderNDK_uCJYObN2y-WYoGmhIRMaRLdvwfh0aL2-op794Bitrag=.cer", - "storePassword": "0000001B2996983837836C755C37CF2DA1F5ACAABBAB083C160CACE2A6853CE9275C83240E507A7B0BD3AE", - "keyAlias": "debugKey", - "keyPassword": "0000001BE5BF35F489B94CFA1DAAE09B1B34B86E1D71BA7FCBBC0EB87D19FEA5BED92D1425345F75AF1880", - "profile": "C:/Users/admin/.ohos/config/openharmony/default_AVRecorderNDK_uCJYObN2y-WYoGmhIRMaRLdvwfh0aL2-op794Bitrag=.p7b", - "signAlg": "SHA256withECDSA", - "storeFile": "C:/Users/admin/.ohos/config/openharmony/default_AVRecorderNDK_uCJYObN2y-WYoGmhIRMaRLdvwfh0aL2-op794Bitrag=.p12" - } + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", } ], - "products": [ + "buildModeSet": [ { - "name": "default", - "signingConfig": "default", - //指定HarmonyOS应用/服务编译时的版本 - "compatibleSdkVersion": "4.1.0(11)", - //指定HarmonyOS应用/服务兼容的最低版本。版本号需改为"4.0.0(10)",注意使用英文.和() - "targetSdkVersion": "4.1.0(11)", - //指定HarmonyOS应用/服务目标版本。若没有设置,默认为compatibleSdkVersion - "runtimeOS": "HarmonyOS" + "name": "debug", + }, + { + "name": "release" } ] }, -- Gitee From 62544a0d810c52639c5589ae012c75d213ccbaf9 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:08:18 +0000 Subject: [PATCH 23/62] update code/DocsSample/Media/AVRecorder/build-profile.json5. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/build-profile.json5 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/build-profile.json5 b/code/DocsSample/Media/AVRecorder/build-profile.json5 index 35911cbabb..9b56cd2244 100644 --- a/code/DocsSample/Media/AVRecorder/build-profile.json5 +++ b/code/DocsSample/Media/AVRecorder/build-profile.json5 @@ -19,8 +19,12 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", + //指定HarmonyOS应用/服务编译时的版本 + "compileSdkVersion": 18, + //指定HarmonyOS应用/服务兼容的最低版本 + "compatibleSdkVersion": 18, + //指定HarmonyOS应用/服务目标版本。若没有设置,默认为compatibleSdkVersion + "runtimeOS": "OpenHarmony", } ], "buildModeSet": [ -- Gitee From a5f023244e4d60e0e7bd7a089939fe6d57cdef15 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:08:44 +0000 Subject: [PATCH 24/62] update code/DocsSample/Media/AVRecorder/build-profile.json5. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/build-profile.json5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/build-profile.json5 b/code/DocsSample/Media/AVRecorder/build-profile.json5 index 9b56cd2244..b3f905f913 100644 --- a/code/DocsSample/Media/AVRecorder/build-profile.json5 +++ b/code/DocsSample/Media/AVRecorder/build-profile.json5 @@ -20,9 +20,9 @@ "name": "default", "signingConfig": "default", //指定HarmonyOS应用/服务编译时的版本 - "compileSdkVersion": 18, + "compileSdkVersion": 19, //指定HarmonyOS应用/服务兼容的最低版本 - "compatibleSdkVersion": 18, + "compatibleSdkVersion": 19, //指定HarmonyOS应用/服务目标版本。若没有设置,默认为compatibleSdkVersion "runtimeOS": "OpenHarmony", } -- Gitee From 2821578f3ce5df65c2e10e2b478674b0749cdf53 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:14:43 +0000 Subject: [PATCH 25/62] update code/DocsSample/Media/AVRecorder/BUILD.gn. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/BUILD.gn | 33 ----------------------- 1 file changed, 33 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/BUILD.gn b/code/DocsSample/Media/AVRecorder/BUILD.gn index 1f09a61c17..e69de29bb2 100644 --- a/code/DocsSample/Media/AVRecorder/BUILD.gn +++ b/code/DocsSample/Media/AVRecorder/BUILD.gn @@ -1,33 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//test/xts/tools/build/suite.gni") - -ohos_app_assist_suite("AVRecorder_ndk_main") { - testonly = true - certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsAVRecorderMainTest" - subsystem_name = "multimedia" - part_name = "player_framework" -} - -ohos_js_app_suite("ActsAVRecorderNdkTest") { - test_hap = true - testonly = true - certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsAVRecorderNdkTest" - subsystem_name = "multimedia" - part_name = "player_framework" - deps = [ ":AVRecorder_ndk_main" ] -} -- Gitee From 04ac3fbd5fe1d622bf00062661978d41bc8031dc Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:15:46 +0000 Subject: [PATCH 26/62] update code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json. Signed-off-by: Steven --- .../AVRecorder/AppScope/resources/base/element/string.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json index 5697e168db..b4b585e972 100644 --- a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json @@ -2,7 +2,7 @@ "string": [ { "name": "app_name", - "value": "AVRecorderNDK" + "value": "AVRecorder" } ] } -- Gitee From 44720c8cc55090d867ef20f942415290141fe6a7 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:17:49 +0000 Subject: [PATCH 27/62] update code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json. Signed-off-by: Steven --- .../AVRecorder/AppScope/resources/base/element/string.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json index b4b585e972..c341df60c8 100644 --- a/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Media/AVRecorder/AppScope/resources/base/element/string.json @@ -2,7 +2,7 @@ "string": [ { "name": "app_name", - "value": "AVRecorder" + "value": "AVRecorderSample" } ] } -- Gitee From 45503d96b2de9eadd882adf6428bf73755feb638 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:18:44 +0000 Subject: [PATCH 28/62] update code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5. Signed-off-by: Steven --- .../AVRecorder/entry/oh-package-lock.json5 | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 b/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 index 9900ae2bfa..e69de29bb2 100644 --- a/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 @@ -1,18 +0,0 @@ -{ - "meta": { - "stableOrder": true - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "@types/libavrecorderndk.so@src/main/cpp/types/libentry": "@types/libavrecorderndk.so@src/main/cpp/types/libentry" - }, - "packages": { - "@types/libavrecorderndk.so@src/main/cpp/types/libentry": { - "name": "libavrecorderndk.so", - "version": "0.0.0", - "resolved": "src/main/cpp/types/libentry", - "registryType": "local" - } - } -} \ No newline at end of file -- Gitee From ba2b115d74a419da815f929579512508b1378dbf Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:21:24 +0000 Subject: [PATCH 29/62] update code/DocsSample/Media/AVRecorder/entry/oh-package.json5. Signed-off-by: Steven --- .../Media/AVRecorder/entry/oh-package.json5 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/oh-package.json5 b/code/DocsSample/Media/AVRecorder/entry/oh-package.json5 index 2b77cb1b04..a91c79fda8 100644 --- a/code/DocsSample/Media/AVRecorder/entry/oh-package.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/oh-package.json5 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,15 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + { - "license": "", - "devDependencies": { - "@types/libavrecorderndk.so": "file:./src/main/cpp/types/libentry" - }, - "author": "", "name": "entry", + "version": "1.0.0", "description": "Please describe the basic information.", "main": "", - "version": "1.0.0", - "dependencies": {} -} + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file -- Gitee From 134d8114973cf22c9e08f76a7e1f3f61747c4072 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:22:07 +0000 Subject: [PATCH 30/62] update code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts b/code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts index 24d3f52424..dbe3314801 100644 --- a/code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts +++ b/code/DocsSample/Media/AVRecorder/entry/hvigorfile.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,4 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} -- Gitee From ece9e1e437af6a6bea28e2c5dd7e4c05f5ba57c7 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:22:46 +0000 Subject: [PATCH 31/62] update code/DocsSample/Media/AVRecorder/entry/build-profile.json5. Signed-off-by: Steven --- .../AVRecorder/entry/build-profile.json5 | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/build-profile.json5 b/code/DocsSample/Media/AVRecorder/entry/build-profile.json5 index 3cf8c68bfb..d7448c43ab 100644 --- a/code/DocsSample/Media/AVRecorder/entry/build-profile.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/build-profile.json5 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,19 +12,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + { - "apiType": 'stageMode', + "apiType": "stageMode", "buildOption": { "externalNativeOptions": { "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", - "cppFlags": "" + "cppFlags": "", } }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], "targets": [ { - "name": "default", - "runtimeOS": "HarmonyOS" + "name": "default" }, { "name": "ohosTest", -- Gitee From 436d3a894e2abfd7b409703045d70bb78115828f Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:23:43 +0000 Subject: [PATCH 32/62] update code/DocsSample/Media/AVRecorder/.gitignore. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/.gitignore b/code/DocsSample/Media/AVRecorder/.gitignore index fbabf77101..d2ff20141c 100644 --- a/code/DocsSample/Media/AVRecorder/.gitignore +++ b/code/DocsSample/Media/AVRecorder/.gitignore @@ -8,4 +8,5 @@ /.clangd /.clang-format /.clang-tidy -**/.test \ No newline at end of file +**/.test +/.appanalyzer \ No newline at end of file -- Gitee From 5e772224602eb1f1af672297fb9bde2a4d5f9afa Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:25:00 +0000 Subject: [PATCH 33/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h. Signed-off-by: Steven --- .../DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h index 42c843ccc2..1440bd5059 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/log_common.h @@ -21,7 +21,7 @@ #include #define LOG_PRINT_DOMAIN 0xFF00 #define APP_LOG_DOMAIN 0x0001 -constexpr const char *APP_LOG_TAG = "DrawingSample"; +constexpr const char *APP_LOG_TAG = "AVRecorderSample"; #define DRAWING_LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) #define DRAWING_LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) #define DRAWING_LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) -- Gitee From fc21456c35d77176c9edae28bda6de7439587483 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:28:06 +0000 Subject: [PATCH 34/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp. Signed-off-by: Steven --- .../Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp index ed7578c2ca..7bed4f011e 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp @@ -83,7 +83,7 @@ NDKCamera::~NDKCamera() Camera_ErrorCode ret = CAMERA_OK; if (cameraManager_) { - OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. enter"); + OH_LOG_INFO(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. enter"); ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed."); @@ -103,7 +103,7 @@ NDKCamera::~NDKCamera() if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete CameraManager failed."); } else { - OH_LOG_ERROR(LOG_APP, "Release OH_Camera_DeleteCameraMananger. ok"); + OH_LOG_INFO(LOG_APP, "Release OH_Camera_DeleteCameraMananger. ok"); } cameraManager_ = nullptr; } -- Gitee From ff2c0550801933896b0fd960c4664ed3b63c1c19 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:30:50 +0000 Subject: [PATCH 35/62] update code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp. Signed-off-by: Steven --- .../entry/src/main/cpp/camera_manager.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp index 7bed4f011e..76240c7dfb 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/camera_manager.cpp @@ -79,7 +79,7 @@ NDKCamera::NDKCamera(uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sc NDKCamera::~NDKCamera() { - OH_LOG_ERROR(LOG_APP, "~NDKCamera"); + OH_LOG_INFO(LOG_APP, "~NDKCamera"); Camera_ErrorCode ret = CAMERA_OK; if (cameraManager_) { @@ -88,7 +88,7 @@ NDKCamera::~NDKCamera() if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed."); } else { - OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); + OH_LOG_INFO(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); } OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. enter"); @@ -96,7 +96,7 @@ NDKCamera::~NDKCamera() if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete Cameras failed."); } else { - OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. ok"); + OH_LOG_INFO(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. ok"); } ret = OH_Camera_DeleteCameraManager(cameraManager_); @@ -107,12 +107,12 @@ NDKCamera::~NDKCamera() } cameraManager_ = nullptr; } - OH_LOG_ERROR(LOG_APP, "~NDKCamera exit"); + OH_LOG_INFO(LOG_APP, "~NDKCamera exit"); } Camera_ErrorCode NDKCamera::ReleaseCamera(void) { - OH_LOG_ERROR(LOG_APP, " enter ReleaseCamera"); + OH_LOG_INFO(LOG_APP, " enter ReleaseCamera"); if (previewOutput_ && captureSession_) { PreviewOutputStop(); OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_); @@ -130,27 +130,27 @@ Camera_ErrorCode NDKCamera::ReleaseCamera(void) if (cameraInput_) { CameraInputClose(); } - OH_LOG_ERROR(LOG_APP, " exit ReleaseCamera"); + OH_LOG_INFO(LOG_APP, " exit ReleaseCamera"); return ret_; } Camera_ErrorCode NDKCamera::ReleaseSession(void) { - OH_LOG_ERROR(LOG_APP, " enter ReleaseSession"); + OH_LOG_INFO(LOG_APP, " enter ReleaseSession"); PreviewOutputStop(); PhotoOutputRelease(); VideoOutputRelease(); SessionRealese(); - OH_LOG_ERROR(LOG_APP, " exit ReleaseSession"); + OH_LOG_INFO(LOG_APP, " exit ReleaseSession"); return ret_; } Camera_ErrorCode NDKCamera::SessionRealese(void) { - OH_LOG_ERROR(LOG_APP, " enter SessionRealese"); + OH_LOG_INFO(LOG_APP, " enter SessionRealese"); Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); captureSession_ = nullptr; - OH_LOG_ERROR(LOG_APP, " exit SessionRealese"); + OH_LOG_INFO(LOG_APP, " exit SessionRealese"); return ret; } -- Gitee From 559e75f5efe6b544ec89cade6ff379184a6dc380 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:34:08 +0000 Subject: [PATCH 36/62] update code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json. Signed-off-by: Steven --- .../entry/src/main/resources/base/element/string.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json index f94595515a..b56d3c2a60 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json @@ -10,6 +10,10 @@ }, { "name": "EntryAbility_label", + "value": "AVRecorderSample" + }, + { + "name": "reason", "value": "label" } ] -- Gitee From dd5746735b69afad30904cde46525adda8a7f930 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:34:52 +0000 Subject: [PATCH 37/62] update code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json. Signed-off-by: Steven --- .../entry/src/main/resources/base/element/string.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json index b56d3c2a60..ff652817c9 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json @@ -14,7 +14,7 @@ }, { "name": "reason", - "value": "label" + "value": "AVRecorderSample" } ] } \ No newline at end of file -- Gitee From 84a3e482202f7aa870bf2af734b06a8804125ff6 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:37:45 +0000 Subject: [PATCH 38/62] update code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json. Signed-off-by: Steven --- .../entry/src/main/resources/zh_CN/element/string.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e6..f2585ecb9f 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/zh_CN/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "AVRecorderSample" } ] } \ No newline at end of file -- Gitee From 1c894363f216f827f5364880d9253c2379db62ac Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:38:48 +0000 Subject: [PATCH 39/62] update code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json. Signed-off-by: Steven --- .../entry/src/main/resources/en_US/element/string.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json index f94595515a..601ab25fe4 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/en_US/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "AVRecorderSample" } ] } \ No newline at end of file -- Gitee From a29f4d4be9e42a30d434568a80484e0e7d2e0bb2 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:39:39 +0000 Subject: [PATCH 40/62] update code/DocsSample/Media/AVRecorder/oh-package-lock.json5. Signed-off-by: Steven --- .../Media/AVRecorder/oh-package-lock.json5 | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 b/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 index fa3e42b6c9..e69de29bb2 100644 --- a/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 +++ b/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 @@ -1,19 +0,0 @@ -{ - "meta": { - "stableOrder": true - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "@ohos/hypium@1.0.15": "@ohos/hypium@1.0.15" - }, - "packages": { - "@ohos/hypium@1.0.15": { - "name": "@ohos/hypium", - "version": "1.0.15", - "integrity": "sha512-AhkuYX2l/IzrVARV/hKRGsJDQPtZ5bygr6Q1N2M9W15kBllNYL3khQ0dNvJwh/CIGoEPMDVcME9q6MhFGccqkw==", - "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.15.har", - "registryType": "ohpm" - } - } -} \ No newline at end of file -- Gitee From 8bd2b3ae64e2bf1ecfb3213f1f647d6626427640 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:43:50 +0000 Subject: [PATCH 41/62] update code/DocsSample/Media/AVRecorder/oh-package.json5. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/oh-package.json5 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/oh-package.json5 b/code/DocsSample/Media/AVRecorder/oh-package.json5 index 11f4bde973..bf39c8a7ea 100644 --- a/code/DocsSample/Media/AVRecorder/oh-package.json5 +++ b/code/DocsSample/Media/AVRecorder/oh-package.json5 @@ -17,11 +17,11 @@ "modelVersion": "5.0.0", "license": "", "devDependencies": { - "@ohos/hypium": "1.0.15", -// "@ohos/hamock":"1.0.1-rc2" + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" }, "author": "", - "name": "avrecorderndk", + "name": "AVRecorderSample", "description": "Please describe the basic information.", "main": "", "version": "1.0.0", -- Gitee From ce5a41bb063ff2a7764c6c5e6f6c9dda13cdfee2 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:45:41 +0000 Subject: [PATCH 42/62] update code/DocsSample/Media/AVRecorder/hvigorfile.ts. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/hvigorfile.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/hvigorfile.ts b/code/DocsSample/Media/AVRecorder/hvigorfile.ts index d3faa0dfe8..610bd720e2 100644 --- a/code/DocsSample/Media/AVRecorder/hvigorfile.ts +++ b/code/DocsSample/Media/AVRecorder/hvigorfile.ts @@ -12,5 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} -- Gitee From eb9e457a3d7645b91869ba0915bb2996f1e3a378 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 07:45:50 +0000 Subject: [PATCH 43/62] update code/DocsSample/Media/AVRecorder/hvigorfile.ts. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/hvigorfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/hvigorfile.ts b/code/DocsSample/Media/AVRecorder/hvigorfile.ts index 610bd720e2..cdeaf638ae 100644 --- a/code/DocsSample/Media/AVRecorder/hvigorfile.ts +++ b/code/DocsSample/Media/AVRecorder/hvigorfile.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From fef5177d33a327e562c55e2b8f53fa1ea7ee8fce Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 08:01:33 +0000 Subject: [PATCH 44/62] update code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json. Signed-off-by: Steven --- .../main/resources/base/element/string.json | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json index ff652817c9..4d2dc3eec6 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/element/string.json @@ -13,8 +13,44 @@ "value": "AVRecorderSample" }, { - "name": "reason", + "name": "sample_label", "value": "AVRecorderSample" + }, + { + "name": "GetConfig", + "value": "GetConfig" + }, + { + "name": "GetInfo", + "value": "GetInfo" + }, + { + "name": "Prepare", + "value": "Prepare" + }, + { + "name": "Start", + "value": "Start" + }, + { + "name": "Pause", + "value": "Pause" + }, + { + "name": "Resume", + "value": "Resume" + }, + { + "name": "Stop", + "value": "Stop" + }, + { + "name": "Reset", + "value": "Reset" + }, + { + "name": "Release", + "value": "Release" } ] } \ No newline at end of file -- Gitee From 3f88b56a539b01012efb4dafb0f0e99e38e3909f Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 08:04:07 +0000 Subject: [PATCH 45/62] update code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets. Signed-off-by: Steven --- .../entry/src/main/ets/pages/Index.ets | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets index 0ed1278e81..a561b00e06 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/pages/Index.ets @@ -58,7 +58,7 @@ export struct Index { this.sceneMode, this.previewId, this.photoId, this.videoId)); }) .onDestroy(() => { - // 组件销毁时执行的操作 + // 组件销毁时释放录制资源 hilog.info(0x0000, 'testTag', 'Application is closing, perform cleanup.'); testNapi.releaseAVRecorder(); }) @@ -68,9 +68,9 @@ export struct Index { Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }) { - // // ** 可选: 获取实时录制参数 ** - Button('GetConfig', { type: ButtonType.Circle, stateEffect: true }) - .id("Start") + // ** 可选: 获取实时录制参数 ** + Button($r('app.string.GetConfig'), { type: ButtonType.Circle, stateEffect: true }) + .id("GetConfig") .backgroundColor(0xF55A42) .width(65) .height(65) @@ -78,9 +78,9 @@ export struct Index { hilog.info(0x0000, 'testTag', 'Get AVRecorder Config %{public}d', testNapi.getAVRecorderConfig()); }) - // // ** 可选: 获取编码信息 ** - Button('GetInfo', { type: ButtonType.Circle, stateEffect: true }) - .id("Start") + // ** 可选: 获取编码信息 ** + Button($r('app.string.GetInfo'), { type: ButtonType.Circle, stateEffect: true }) + .id("GetInfo") .backgroundColor(0xF55A42) .width(65) .height(65) @@ -90,20 +90,20 @@ export struct Index { } Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }){ - Button('Prepare', { type: ButtonType.Circle, stateEffect: true }) + Button($r('app.string.Prepare'), { type: ButtonType.Circle, stateEffect: true }) .id("Prepare") .backgroundColor(Color.Black) .width(65) .height(65) .onClick(() => { this.previewId = this.mXComponentController.getXComponentSurfaceId(); - hilog.info(0x0000, 'testTag', 'previewId: %{public}s', this.previewId); + hilog.info(0x0000, 'testTag', 'dztdztdzt previewId: %{public}s', this.previewId); hilog.info(0x0000, 'testTag', 'Prepare AVRecorder %{public}d', testNapi.prepareAVRecorder()); hilog.info(0x0000, 'testTag', 'prepare Camera %{public}d', testNapi.prepareCamera(this.focusMode, this.cameraDeviceIndex, this.sceneMode, this.previewId, this.photoId, this.videoId)); hilog.info(0x0000, 'testTag', 'Start AVRecorder %{public}d', testNapi.startAVRecorder()); }) - Button('Start', { type: ButtonType.Circle, stateEffect: true }) + Button($r('app.string.Start'), { type: ButtonType.Circle, stateEffect: true }) .id("Start") .backgroundColor(0xF55A42) .width(65) @@ -112,7 +112,7 @@ export struct Index { hilog.info(0x0000, 'testTag', 'After prepare surfaceId: %{public}s', this.videoId); hilog.info(0x0000, 'testTag', 'Start AVRecorder %{public}d', testNapi.startAVRecorder()); }) - Button('Pause', { type: ButtonType.Normal, stateEffect: true }) + Button($r('app.string.Pause'), { type: ButtonType.Normal, stateEffect: true }) .id("Pause") .backgroundColor(0x4287F5) .width(65) @@ -120,7 +120,7 @@ export struct Index { .onClick(() => { hilog.info(0x0000, 'testTag', 'Pause AVRecorder %{public}d', testNapi.pauseAVRecorder()); }) - Button('Resume', { type: ButtonType.Capsule, stateEffect: true }) + Button($r('app.string.Resume'), { type: ButtonType.Capsule, stateEffect: true }) .id("Resume") .backgroundColor(0x4287F5) .width(65) @@ -131,7 +131,7 @@ export struct Index { } Flex({ direction: FlexDirection.Row, wrap:FlexWrap.Wrap, justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center, alignContent:FlexAlign.Center }){ - Button('Stop', { type: ButtonType.Capsule, stateEffect: true }) + Button($r('app.string.Stop'), { type: ButtonType.Capsule, stateEffect: true }) .id("Stop") .backgroundColor(0x4287F5) .width(65) @@ -139,7 +139,7 @@ export struct Index { .onClick(() => { hilog.info(0x0000, 'testTag', 'Stop AVRecorder %{public}d', testNapi.stopAVRecorder()); }) - Button('Reset', { type: ButtonType.Capsule, stateEffect: true }) + Button($r('app.string.Reset'), { type: ButtonType.Capsule, stateEffect: true }) .id("Reset") .backgroundColor(0x4287F5) .width(65) @@ -147,7 +147,7 @@ export struct Index { .onClick(() => { hilog.info(0x0000, 'testTag', 'Reset AVRecorder %{public}d', testNapi.resetAVRecorder()); }) - Button('Release', { type: ButtonType.Capsule, stateEffect: true }) + Button($r('app.string.Release'), { type: ButtonType.Capsule, stateEffect: true }) .id("Release") .backgroundColor(0x4287F5) .width(65) @@ -160,4 +160,4 @@ export struct Index { .width('100%') .height('100%') } -} \ No newline at end of file +} -- Gitee From ed7df1315b87bf20248eccecb13b19a04895b5c0 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Jun 2025 16:23:35 +0800 Subject: [PATCH 46/62] fix Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/BUILD.gn | 0 code/DocsSample/Media/AVRecorder/Test.json | 0 code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 | 0 .../Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp | 0 .../AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts | 2 +- .../entry/src/main/cpp/types/libentry/oh-package.json5 | 2 +- .../AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts | 2 +- code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 | 2 +- code/DocsSample/Media/AVRecorder/hvigorw.bat | 2 +- code/DocsSample/Media/AVRecorder/oh-package-lock.json5 | 0 10 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 code/DocsSample/Media/AVRecorder/BUILD.gn delete mode 100644 code/DocsSample/Media/AVRecorder/Test.json delete mode 100644 code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 delete mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp delete mode 100644 code/DocsSample/Media/AVRecorder/oh-package-lock.json5 diff --git a/code/DocsSample/Media/AVRecorder/BUILD.gn b/code/DocsSample/Media/AVRecorder/BUILD.gn deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/code/DocsSample/Media/AVRecorder/Test.json b/code/DocsSample/Media/AVRecorder/Test.json deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 b/code/DocsSample/Media/AVRecorder/entry/oh-package-lock.json5 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/avrecorder_ndk_test.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts index 863fcd134f..58387bb645 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 index 817e9af406..ce82a4c96b 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts index 3f0469db22..79edc91303 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 index 1100b57b7f..b8c476661d 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/code/DocsSample/Media/AVRecorder/hvigorw.bat b/code/DocsSample/Media/AVRecorder/hvigorw.bat index 89f8b0cd46..d77138670c 100644 --- a/code/DocsSample/Media/AVRecorder/hvigorw.bat +++ b/code/DocsSample/Media/AVRecorder/hvigorw.bat @@ -1,4 +1,4 @@ -@rem Copyright (C) 2024 Huawei Device Co., Ltd. +@rem Copyright (C) 2025 Huawei Device Co., Ltd. @rem Licensed under the Apache License, Version 2.0 (the "License"); @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at diff --git a/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 b/code/DocsSample/Media/AVRecorder/oh-package-lock.json5 deleted file mode 100644 index e69de29bb2..0000000000 -- Gitee From f7afb740d737b868ec892747d92cea3b26e280dc Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:15:29 +0000 Subject: [PATCH 47/62] add code/DocsSample/Media/AVRecorder/README_zh.md. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/README_zh.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/README_zh.md diff --git a/code/DocsSample/Media/AVRecorder/README_zh.md b/code/DocsSample/Media/AVRecorder/README_zh.md new file mode 100644 index 0000000000..ee49a21069 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/README_zh.md @@ -0,0 +1,68 @@ +# AVRecorder Sample + +## 介绍 +AVRecorder Sample 调用了媒体 AVRecorder 组件提供的接口能力,提供音视频录制的功能,包含: +- 音视频录制 +- 音频录制/视频录制 +- 保存录制文件到应用沙箱/图库 + +使用说明 + +1. 启动应用,首次启动需要用户授予访问相机、麦克风、保存文件的权限。 +2. 进入Demo界面,点击 Start 按钮,开始录制。 +3. 启动录制后会弹出隐私弹窗,告知用户将被录屏。 +4. 选择允许后,启动录制后会弹出录制悬浮胶囊,并显示录制时间计时,此时可以操作屏幕,屏幕上的操作过程会被录制下来。 +5. 需要停止录屏时,点击应用停止按钮或点击悬浮半透明的红色按钮,屏幕录制停止。 +6. 录屏存储的文件保存在沙箱目录。 + +## 工程目录 + +仓目录结构如下: + +``` +entry/src/main # AVRecorder demo业务代码 +│ module.json5 # 编译相关文件 +├─cpp # ndk相关文件 +│ │ CMakeLists.txt +│ │ main.cpp +│ │ main.h +│ │ camera_manager.cpp +│ │ camera_manager.h +│ │ log_common.h +│ │ sample_info.h +│ │ muxer.cpp +│ │ muxer.h +│ │ video_encoder_sample.cpp +│ │ video_encoder_sample.h +│ └─types # 映射文件 +│ +├─ets # 页面相关实现 +│ ├─entryability +│ ├─entrybackupability +│ └─pages # ets 页面实现 +│ Index.ets # 首页 +│ +└─resources # 资源文件 +``` + +## 相关权限 + +ohos.permission.MICROPHONE +ohos.permission.INTERNET +ohos.permission.CAMERA +ohos.permission.MEDIA_LOCATION +ohos.permission.KEEP_BACKGROUND_RUNNING +ohos.permission.READ_MEDIA +ohos.permission.WRITE_MEDIA + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API19版本SDK,版本号:5.1.1.62; + +3. 本示例已支持使DevEco Studio 5.0.5 Beta1(构建版本:5.0.13.100,构建于:2025年4月25日)编译运行 \ No newline at end of file -- Gitee From e0ddd17eded22d2c9a808342a966439ab80c932e Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:20:45 +0000 Subject: [PATCH 48/62] add code/DocsSample/Media/AVRecorder/ohosTest.md. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/ohosTest.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/ohosTest.md diff --git a/code/DocsSample/Media/AVRecorder/ohosTest.md b/code/DocsSample/Media/AVRecorder/ohosTest.md new file mode 100644 index 0000000000..0612ab8717 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/ohosTest.md @@ -0,0 +1,9 @@ +# AVRecorderSample测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|----------------|-----------|---------------------------------------------------------|---------------------------|------|------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | +| 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 是 | Pass | \ No newline at end of file -- Gitee From 969abaff3e2151ccdf80776420522f732fbb0c63 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:21:46 +0000 Subject: [PATCH 49/62] update code/DocsSample/Media/AVRecorder/ohosTest.md. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/ohosTest.md | 1 + 1 file changed, 1 insertion(+) diff --git a/code/DocsSample/Media/AVRecorder/ohosTest.md b/code/DocsSample/Media/AVRecorder/ohosTest.md index 0612ab8717..3eb095eb6d 100644 --- a/code/DocsSample/Media/AVRecorder/ohosTest.md +++ b/code/DocsSample/Media/AVRecorder/ohosTest.md @@ -6,4 +6,5 @@ |----------------|-----------|---------------------------------------------------------|---------------------------|------|------| | 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | | 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | +| 音频录制功能 | 进入示例应用 | 1. Demo中选择音频录制模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | | 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 是 | Pass | \ No newline at end of file -- Gitee From be1cc41bb2ad5b4d041047ab143402925f5b882f Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:22:23 +0000 Subject: [PATCH 50/62] update code/DocsSample/Media/AVRecorder/ohosTest.md. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/ohosTest.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/ohosTest.md b/code/DocsSample/Media/AVRecorder/ohosTest.md index 3eb095eb6d..d0d1a271a5 100644 --- a/code/DocsSample/Media/AVRecorder/ohosTest.md +++ b/code/DocsSample/Media/AVRecorder/ohosTest.md @@ -4,7 +4,7 @@ | 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | |----------------|-----------|---------------------------------------------------------|---------------------------|------|------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | -| 音频录制功能 | 进入示例应用 | 1. Demo中选择音频录制模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | -| 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 是 | Pass | \ No newline at end of file +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 否 | Pass | +| 音频录制功能 | 进入示例应用 | 1. Demo中选择音频录制模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 生成录制文件到沙箱 | 否 | Pass | +| 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 否 | Pass | \ No newline at end of file -- Gitee From 7699a1467bc83b9b68dc180632fdfa38180bf281 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:23:27 +0000 Subject: [PATCH 51/62] update code/DocsSample/Media/AVRecorder/ohosTest.md. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/ohosTest.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/ohosTest.md b/code/DocsSample/Media/AVRecorder/ohosTest.md index d0d1a271a5..3c0de4911d 100644 --- a/code/DocsSample/Media/AVRecorder/ohosTest.md +++ b/code/DocsSample/Media/AVRecorder/ohosTest.md @@ -4,7 +4,7 @@ | 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | |----------------|-----------|---------------------------------------------------------|---------------------------|------|------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | -| 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 否 | Pass | -| 音频录制功能 | 进入示例应用 | 1. Demo中选择音频录制模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 生成录制文件到沙箱 | 否 | Pass | -| 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 否 | Pass | \ No newline at end of file +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 音视频录制功能 | 进入示例应用 | 1. 点击Prepare
2. 点击Start
3. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | +| 音频录制功能 | 进入示例应用 | 1. Demo中选择音频录制模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 生成录制文件到沙箱 | 是 | Pass | +| 录制文件保存图库功能 | 进入示例应用 | 1. Demo中fileGenerationMode选择AUTO_CREATE模式
2. 点击Prepare
3. 点击Start
4. 一段时间后点击Stop | 视频文件保存至图库 | 是 | Pass | \ No newline at end of file -- Gitee From 2344ceff45b109f373164e42d3c3f134bc8efd65 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:26:24 +0000 Subject: [PATCH 52/62] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20entrybackupability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From 582f040927832d002abefc687028c68857c6bf67 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:27:12 +0000 Subject: [PATCH 53/62] rename EntryBackupAbility.ets. Signed-off-by: Steven --- .../ EntryBackupAbility.ets | 32 +++++++++++++++++++ .../src/main/ets/entrybackupability/.keep | 0 2 files changed, 32 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets delete mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets new file mode 100644 index 0000000000..4ee4bce7bb --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets @@ -0,0 +1,32 @@ + +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/.keep deleted file mode 100644 index e69de29bb2..0000000000 -- Gitee From 78d0c3c69119e29f463c51b5c8cc5a7bfbee3ade Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:29:15 +0000 Subject: [PATCH 54/62] update EntryBackupAbility.ets. Signed-off-by: Steven --- .../ets/entrybackupability/ EntryBackupAbility.ets | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets index 4ee4bce7bb..20b967c87b 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entrybackupability/ EntryBackupAbility.ets @@ -17,16 +17,12 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; -const DOMAIN = 0x0000; - export default class EntryBackupAbility extends BackupExtensionAbility { async onBackup() { - hilog.info(DOMAIN, 'testTag', 'onBackup ok'); - await Promise.resolve(); + hilog.info(0x0000, 'testTag', 'onBackup ok'); } async onRestore(bundleVersion: BundleVersion) { - hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); - await Promise.resolve(); + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); } -} \ No newline at end of file +} -- Gitee From 1a68d09bc7bb55a3f28f3f2799176db5aa73177e Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:32:28 +0000 Subject: [PATCH 55/62] update code/DocsSample/Media/AVRecorder/hvigorfile.ts. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/hvigorfile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/hvigorfile.ts b/code/DocsSample/Media/AVRecorder/hvigorfile.ts index cdeaf638ae..9decabcd15 100644 --- a/code/DocsSample/Media/AVRecorder/hvigorfile.ts +++ b/code/DocsSample/Media/AVRecorder/hvigorfile.ts @@ -14,9 +14,9 @@ */ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -import { hapTasks } from '@ohos/hvigor-ohos-plugin'; +import { appTasks } from '@ohos/hvigor-ohos-plugin'; export default { - system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ } -- Gitee From c46261197692228fb9e1a198c2652ff1f6ce069f Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:35:12 +0000 Subject: [PATCH 56/62] add code/DocsSample/Media/AVRecorder/local.properties. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/local.properties | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/local.properties diff --git a/code/DocsSample/Media/AVRecorder/local.properties b/code/DocsSample/Media/AVRecorder/local.properties new file mode 100644 index 0000000000..bf415406c2 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/local.properties @@ -0,0 +1,7 @@ +# This file is automatically generated by DevEco Studio. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file should *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# For customization when using a Version Control System, please read the header note. \ No newline at end of file -- Gitee From 64fadd2cbbd3e37a9a9f978bba3ac5cbf0a6aeb7 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:40:40 +0000 Subject: [PATCH 57/62] update code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5. Signed-off-by: Steven --- .../AVRecorder/hvigor/hvigor-config.json5 | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5 index 286e311388..83e32c681a 100644 --- a/code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Media/AVRecorder/hvigor/hvigor-config.json5 @@ -16,5 +16,32 @@ { "modelVersion": "5.0.0", "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + }, + "properties": { + // 配置为0,表示不启用内存缓存配置,默认为4,数值越低,内存中缓存数据越少 + "hvigor.pool.cache.capacity": 0, + // 默认配置为cpu核数-1, 包含ohos.arkCompile.maxSize4,值越小,占用内存越少 + "hvigor.pool.maxSize" : 5, + // 默认配置值为5, 值越小,占用内存越少 + "ohos.arkCompile.maxSize": 3, + // 默认配置值为true, 表示开启内存缓存,占用内存较多,配置为false,关闭内存缓存,占用内存较少 + "hvigor.enableMemoryCache": false } -} \ No newline at end of file +} -- Gitee From e87e33adcaebea54c67fa3cb9bfe13189b773f79 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:42:37 +0000 Subject: [PATCH 58/62] update code/DocsSample/Media/AVRecorder/entry/src/main/module.json5. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/module.json5 | 93 ++++++++++++++++++- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 index b8c476661d..288f6d4020 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 @@ -19,7 +19,6 @@ "description": "$string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ - "wearable", "default", "tablet" ], @@ -29,11 +28,11 @@ "abilities": [ { "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", + "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", - "icon": "$media:icon", + "icon": "$media:layered_image", "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", + "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, "skills": [ @@ -47,6 +46,92 @@ } ] } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.MICROPHONE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.INTERNET", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.CAMERA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + } ] } } \ No newline at end of file -- Gitee From 8145a7133d5238b1292f2d43e510830ffca30b88 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:45:27 +0000 Subject: [PATCH 59/62] add code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/layered_image.json. Signed-off-by: Steven --- .../entry/src/main/resources/base/media/layered_image.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000..16cf3219a2 --- /dev/null +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file -- Gitee From 47a48051834d525141bb2cdff61f1bc0b872f684 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:52:07 +0000 Subject: [PATCH 60/62] update code/DocsSample/Media/AVRecorder/entry/src/main/module.json5. Signed-off-by: Steven --- code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 index 288f6d4020..c1964ea1db 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/module.json5 @@ -32,7 +32,7 @@ "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", + "startWindowIcon": "$media:icon", "startWindowBackground": "$color:start_window_background", "exported": true, "skills": [ -- Gitee From 47440d4ae9f814ec3b5f7a91ec433135d4c88af6 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:54:10 +0000 Subject: [PATCH 61/62] rename EntryAbility.ets. Signed-off-by: Steven --- .../{EntryAbility.ts => EntryAbility.ets} | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) rename code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/{EntryAbility.ts => EntryAbility.ets} (59%) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets similarity index 59% rename from code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts rename to code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets index 79edc91303..6185ab1ccb 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,43 +12,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + let permissionNames: Array = ['ohos.permission.MEDIA_LOCATION', 'ohos.permission.READ_MEDIA', + 'ohos.permission.WRITE_MEDIA', 'ohos.permission.CAMERA', 'ohos.permission.MICROPHONE']; + globalThis.abilityWant = this.launchWant; + globalThis.abilityContext = this.context; + let atManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(globalThis.abilityContext, permissionNames).then((data) => { + hilog.info(0x0000, 'testTag', '%{public}s', 'requestPermissionsFromUser called'); + }); } - onDestroy() { + onDestroy(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); } - onWindowStageCreate(windowStage: window.WindowStage) { + onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Index', (err, data) => { + windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); } - onWindowStageDestroy() { + onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); } - onForeground() { + onForeground(): void { // Ability has brought to foreground hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); } - onBackground() { + onBackground(): void { // Ability has back to background hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); } -- Gitee From 49343c0609653d752d68d3e3bea148a0a023b5af Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Jun 2025 15:54:24 +0000 Subject: [PATCH 62/62] update code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets. Signed-off-by: Steven --- .../AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets index 6185ab1ccb..6ff5e236f7 100644 --- a/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Media/AVRecorder/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; -- Gitee