• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 <string>
19 #include "av_common.h"
20 #include "format.h"
21 
22 namespace OHOS {
23 namespace Media {
24 /**
25  * @brief Error type of AVCodec
26  *
27  * @since 3.1
28  * @version 3.1
29  */
30 enum AVCodecErrorType : int32_t {
31     /* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */
32     AVCODEC_ERROR_INTERNAL,
33     /* extend error start. The extension error code agreed upon by the plug-in and
34        the application will be transparently transmitted by the service. */
35     AVCODEC_ERROR_EXTEND_START = 0X10000,
36 };
37 
38 enum AVCodecBufferFlag : uint32_t {
39     AVCODEC_BUFFER_FLAG_NONE = 0,
40     /* This signals the end of stream */
41     AVCODEC_BUFFER_FLAG_EOS = 1 << 0,
42     /* This indicates that the buffer contains the data for a sync frame */
43     AVCODEC_BUFFER_FLAG_SYNC_FRAME = 1 << 1,
44     /* This indicates that the buffer only contains part of a frame */
45     AVCODEC_BUFFER_FLAG_PARTIAL_FRAME = 1 << 2,
46     /* This indicated that the buffer contains codec specific data */
47     AVCODEC_BUFFER_FLAG_CODEC_DATA = 1 << 3,
48 };
49 
50 struct AVCodecBufferInfo {
51     /* The presentation timestamp in microseconds for the buffer */
52     int64_t presentationTimeUs = 0;
53     /* The amount of data (in bytes) in the buffer */
54     int32_t size = 0;
55     /* The start-offset of the data in the buffer */
56     int32_t offset = 0;
57 };
58 
59 class AVCodecCallback {
60 public:
61     virtual ~AVCodecCallback() = default;
62     /**
63      * Called when an error occurred.
64      *
65      * @param errorType Error type. For details, see {@link AVCodecErrorType}.
66      * @param errorCode Error code.
67      * @since 3.1
68      * @version 3.1
69      */
70     virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0;
71 
72     /**
73      * Called when the output format has changed.
74      *
75      * @param format The new output format.
76      * @since 3.1
77      * @version 3.1
78      */
79     virtual void OnOutputFormatChanged(const Format &format) = 0;
80 
81     /**
82      * Called when an input buffer becomes available.
83      *
84      * @param index The index of the available input buffer.
85      * @since 3.1
86      * @version 3.1
87      */
88     virtual void OnInputBufferAvailable(uint32_t index) = 0;
89 
90     /**
91      * Called when an output buffer becomes available.
92      *
93      * @param index The index of the available output buffer.
94      * @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo}
95      * @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag}
96      * @since 3.1
97      * @version 3.1
98      */
99     virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
100 };
101 
102 class SurfaceBufferExtratDataKey {
103 public:
104     /**
105      * Key for timeStamp in surface's extraData, value type is int64
106      */
107     static constexpr std::string_view ED_KEY_TIME_STAMP = "timeStamp";
108 
109     /**
110      * Key for endOfStream in surface's extraData, value type is bool
111      */
112     static constexpr std::string_view ED_KEY_END_OF_STREAM = "endOfStream";
113 
114 private:
115     SurfaceBufferExtratDataKey() = delete;
116     ~SurfaceBufferExtratDataKey() = delete;
117 };
118 } // namespace Media
119 } // namespace OHOS
120 #endif // AVCODEC_COMMOM_H
121