• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 FOUNDATION_ACE_COMPONENT_EXT_MOVINGPHOTO__UTILS_H
17 #define FOUNDATION_ACE_COMPONENT_EXT_MOVINGPHOTO__UTILS_H
18 
19 #include <memory>
20 #include <unistd.h>
21 
22 namespace OHOS::Ace {
23 
24 // movingphoto playback mode
25 enum class PlaybackMode {
26     NONE = 0,
27     AUTO,
28     REPEAT
29 };
30 
31 // movingphoto pixelmap format
32 enum class MovingPhotoFormat {
33     UNKNOWN = 0,
34     RGBA_8888 = 1,
35     NV21 = 2,
36     RGBA_1010102 = 3,
37     YCBCR_P010 = 4,
38     YCRCB_P010 = 5
39 };
40 
41 class SharedFd final {
42 public:
43     SharedFd() = default;
44 
SharedFd(int fd)45     explicit SharedFd(int fd)
46     {
47         Reset(fd);
48     }
49 
50     SharedFd& operator=(int fd)
51     {
52         return Reset(fd);
53     }
54 
GetValue()55     int GetValue() const
56     {
57         return (intptr_t)fd_.get();
58     }
59 private:
Reset(int fd)60     SharedFd& Reset(int fd)
61     {
62         fd_.reset((void*)(intptr_t)fd, fd == -1 ? [](void*) {} : [](void* fd) { close((intptr_t)fd); });
63         return *this;
64     }
65 
66     std::shared_ptr<void> fd_{(void*)(intptr_t)-1, [](void*) {}};
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_COMPONENT_EXT_MOVINGPHOTO__UTILS_H
72