• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef AVCODEC_COMMOM_H
16 #define AVCODEC_COMMOM_H
17 
18 #include <vector>
19 #include <string>
20 #include "av_common.h"
21 #include "format.h"
22 
23 namespace OHOS {
24 namespace MediaAVCodec {
25 /**
26  * @brief Error type of AVCodec
27  *
28  * @since 3.1
29  * @version 3.1
30  */
31 enum AVCodecErrorType : int32_t {
32     /* internal errors, error code passed by the errorCode, and definition see "AVCodecServiceErrCode" */
33     AVCODEC_ERROR_INTERNAL,
34     /* extend error start. The extension error code agreed upon by the plug-in and
35        the application will be transparently transmitted by the service. */
36     AVCODEC_ERROR_EXTEND_START = 0X10000,
37 };
38 
39 enum AVCodecBufferFlag : uint32_t {
40     AVCODEC_BUFFER_FLAG_NONE = 0,
41     /* This signals the end of stream */
42     AVCODEC_BUFFER_FLAG_EOS = 1 << 0,
43     /* This indicates that the buffer contains the data for a sync frame */
44     AVCODEC_BUFFER_FLAG_SYNC_FRAME = 1 << 1,
45     /* This indicates that the buffer only contains part of a frame */
46     AVCODEC_BUFFER_FLAG_PARTIAL_FRAME = 1 << 2,
47     /* This indicated that the buffer contains codec specific data */
48     AVCODEC_BUFFER_FLAG_CODEC_DATA = 1 << 3,
49 };
50 
51 struct AVCodecBufferInfo {
52     /* The presentation timestamp in microseconds for the buffer */
53     int64_t presentationTimeUs = 0;
54     /* The amount of data (in bytes) in the buffer */
55     int32_t size = 0;
56     /* The start-offset of the data in the buffer */
57     int32_t offset = 0;
58 };
59 
60 class AVCodecCallback {
61 public:
62     virtual ~AVCodecCallback() = default;
63     /**
64      * Called when an error occurred.
65      *
66      * @param errorType Error type. For details, see {@link AVCodecErrorType}.
67      * @param errorCode Error code.
68      * @since 3.1
69      * @version 3.1
70      */
71     virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0;
72 
73     /**
74      * Called when the output format has changed.
75      *
76      * @param format The new output format.
77      * @since 3.1
78      * @version 3.1
79      */
80     virtual void OnOutputFormatChanged(const Format &format) = 0;
81 
82     /**
83      * Called when an input buffer becomes available.
84      *
85      * @param index The index of the available input buffer.
86      * @param buffer A {@link AVSharedMemory} object for a input buffer index that contains the data.
87      * @since 3.1
88      * @version 4.0
89      */
90     virtual void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) = 0;
91 
92     /**
93      * Called when an output buffer becomes available.
94      *
95      * @param index The index of the available output buffer.
96      * @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo}
97      * @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag}
98      * @param buffer A {@link AVSharedMemory} object for a output buffer index that contains the data.
99      * @since 3.1
100      * @version 4.0
101      */
102     virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
103                                          std::shared_ptr<AVSharedMemory> buffer) = 0;
104 };
105 
106 class SurfaceBufferExtratDataKey {
107 public:
108     /**
109      * Key for timeStamp in surface's extraData, value type is int64
110      */
111     static constexpr std::string_view ED_KEY_TIME_STAMP = "timeStamp";
112 
113     /**
114      * Key for endOfStream in surface's extraData, value type is bool
115      */
116     static constexpr std::string_view ED_KEY_END_OF_STREAM = "endOfStream";
117 
118 private:
119     SurfaceBufferExtratDataKey() = delete;
120     ~SurfaceBufferExtratDataKey() = delete;
121 };
122 
123 class AVSourceFormat {
124 public:
125     static constexpr std::string_view SOURCE_TITLE         = "title";            // string
126     static constexpr std::string_view SOURCE_ARTIST        = "artist";           // std::string, artist
127     static constexpr std::string_view SOURCE_ALBUM         = "album";            // std::string, album
128     static constexpr std::string_view SOURCE_ALBUM_ARTIST  = "album_artist";     // std::string, album artist
129     static constexpr std::string_view SOURCE_DATE          = "date";             // std::string, media date,
130                                                                                  // format: YYYY-MM-DD
131     static constexpr std::string_view SOURCE_COMMENT       = "comment";          // std::string, comment
132     static constexpr std::string_view SOURCE_GENRE         = "genre";            // std::string, genre
133     static constexpr std::string_view SOURCE_COPYRIGHT     = "copyright";        // std::string, copyright
134     static constexpr std::string_view SOURCE_LANGUAGE      = "language";         // std::string, language
135     static constexpr std::string_view SOURCE_DESCRIPTION   = "description";      // std::string, description
136     static constexpr std::string_view SOURCE_LYRICS        = "lyrics";           // std::string, cyrics
137 private:
138     AVSourceFormat() = delete;
139     ~AVSourceFormat() = delete;
140 };
141 
142 enum VideoBitStreamFormat {
143     UNKNOWN = 0,
144     AVCC,
145     HVCC,
146     ANNEXB
147 };
148 } // namespace MediaAVCodec
149 } // namespace OHOS
150 #endif // AVCODEC_COMMOM_H
151