1 /*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef NATIVE_LPP_COMMON_H
17 #define NATIVE_LPP_COMMON_H
18
19 #include <memory>
20 #include <mutex>
21 #include <refbase.h>
22 #include <securec.h>
23
24 #include "media_log.h"
25 #include "media_errors.h"
26 #include "native_averrors.h"
27 #include "native_mfmagic.h"
28 #include "native_player_magic.h"
29 #include "lpp_audio_streamer.h"
30 #include "native_averrors.h"
31 #include "lowpower_audio_sink.h"
32 #include "lowpower_video_sink.h"
33 #include "lowpower_avsink_base.h"
34 #include "native_avbuffer.h"
35 #include "lpp_video_streamer.h"
36 #include "lpp_common.h"
37 #include "native_window.h"
38
39 namespace OHOS {
40 namespace Media {
41
42 const std::map<MediaServiceExtErrCodeAPI9, OH_AVErrCode> MSERREXT_TO_OHAVERR_MAP = {
43 {MSERR_EXT_API9_OK, AV_ERR_OK},
44 {MSERR_EXT_API9_NO_PERMISSION, AV_ERR_OPERATE_NOT_PERMIT},
45 {MSERR_EXT_API9_PERMISSION_DENIED, AV_ERR_OPERATE_NOT_PERMIT},
46 {MSERR_EXT_API9_INVALID_PARAMETER, AV_ERR_INVALID_VAL},
47 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, AV_ERR_OPERATE_NOT_PERMIT},
48 {MSERR_EXT_API9_NO_MEMORY, AV_ERR_NO_MEMORY},
49 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, AV_ERR_OPERATE_NOT_PERMIT},
50 {MSERR_EXT_API9_IO, AV_ERR_IO},
51 {MSERR_EXT_API9_TIMEOUT, AV_ERR_TIMEOUT},
52 {MSERR_EXT_API9_SERVICE_DIED, AV_ERR_SERVICE_DIED},
53 {MSERR_EXT_API9_UNSUPPORT_FORMAT, AV_ERR_UNSUPPORT},
54 {MSERR_EXT_API9_AUDIO_INTERRUPTED, AV_ERR_OPERATE_NOT_PERMIT},
55 {MSERR_EXT_API20_HARDWARE_FAILED, AV_ERR_HARDWARE_FAILED},
56 };
57
LppMsErrToOHAvErr(int32_t code)58 inline __attribute__((visibility("default"))) OH_AVErrCode LppMsErrToOHAvErr(int32_t code)
59 {
60 MediaServiceExtErrCodeAPI9 errCode = MSErrorToExtErrorAPI9(static_cast<MediaServiceErrCode>(code));
61 if (MSERREXT_TO_OHAVERR_MAP.find(errCode) != MSERREXT_TO_OHAVERR_MAP.end()) {
62 return MSERREXT_TO_OHAVERR_MAP.at(errCode);
63 }
64 return AV_ERR_IO;
65 }
66
67 struct AVSamplesBufferObject : public OH_AVSamplesBuffer {
AVSamplesBufferObjectAVSamplesBufferObject68 explicit AVSamplesBufferObject(OHOS::sptr<LppDataPacket> &lppDataPacket) : lppDataPacket_(lppDataPacket)
69 {}
70 ~AVSamplesBufferObject() = default;
71
72 OHOS::sptr<LppDataPacket> lppDataPacket_ = nullptr;
73 };
74
75 struct LowPowerAudioSinkObject : public OH_LowPowerAudioSink {
LowPowerAudioSinkObjectLowPowerAudioSinkObject76 explicit LowPowerAudioSinkObject(
77 const std::shared_ptr<AudioStreamer> &audioStreamer, AVSamplesBufferObject *framePacket)
78 : audioStreamer_(audioStreamer), framePacket_(framePacket)
79 {}
80 ~LowPowerAudioSinkObject() = default;
81
82 const std::shared_ptr<AudioStreamer> audioStreamer_ = nullptr;
83 AVSamplesBufferObject *framePacket_ = nullptr;
84 };
85
86 struct LowPowerVideoSinkObject : public OH_LowPowerVideoSink {
LowPowerVideoSinkObjectLowPowerVideoSinkObject87 explicit LowPowerVideoSinkObject(
88 const std::shared_ptr<VideoStreamer> &videoStreamer, AVSamplesBufferObject *framePacket)
89 : videoStreamer_(videoStreamer), framePacket_(framePacket)
90 {}
91 ~LowPowerVideoSinkObject() = default;
92
93 const std::shared_ptr<VideoStreamer> videoStreamer_ = nullptr;
94 AVSamplesBufferObject *framePacket_ = nullptr;
95 };
96 } // namespace Media
97 } // namespace OHOS
98 #endif // NATIVE_LPP_COMMON_H