1 /*
2  * Copyright (C) 2023 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_MFMAGIC_H
17 #define NATIVE_MFMAGIC_H
18 
19 #include <refbase.h>
20 #include "buffer/avbuffer.h"
21 #include "buffer/avsharedmemory.h"
22 #include "meta/format.h"
23 
24 #define MF_MAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0))
25 
26 enum class MFMagic {
27     MFMAGIC_UNKNOWN = 0,
28     MFMAGIC_AVBUFFER = MF_MAGIC('B', 'B', 'U', 'F'),
29     MFMAGIC_FORMAT = MF_MAGIC('F', 'R', 'M', 'T'),
30     MFMAGIC_SHARED_MEMORY = MF_MAGIC('S', 'M', 'E', 'M'),
31 };
32 
33 struct MFObjectMagic : public OHOS::RefBase {
MFObjectMagicMFObjectMagic34     explicit MFObjectMagic(enum MFMagic m) : magic_(m) {}
35     virtual ~MFObjectMagic() = default;
36     enum MFMagic magic_;
37 };
38 
39 struct OH_AVBuffer : public MFObjectMagic {
40     explicit OH_AVBuffer(const std::shared_ptr<OHOS::Media::AVBuffer> &buf);
41     virtual ~OH_AVBuffer();
42     bool IsEqualBuffer(const std::shared_ptr<OHOS::Media::AVBuffer> &buf);
43     std::shared_ptr<OHOS::Media::AVBuffer> buffer_;
44     bool isUserCreated = false;
45 };
46 
47 struct OH_AVMemory : public MFObjectMagic {
48     explicit OH_AVMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem);
49     ~OH_AVMemory() override;
50     bool IsEqualMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem);
51     std::shared_ptr<OHOS::Media::AVSharedMemory> memory_;
52     bool isUserCreated = false;
53 };
54 
55 struct OH_AVFormat : public MFObjectMagic {
56     OH_AVFormat();
57     explicit OH_AVFormat(const OHOS::Media::Format &fmt);
58     ~OH_AVFormat() override;
59     OHOS::Media::Format format_;
60     char *outString_ = nullptr;
61     char *dumpInfo_ = nullptr;
62 };
63 #endif // NATIVE_MFMAGIC_H