• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #ifndef HISTREAMER_FFMPEG_UTILS_H
17 #define HISTREAMER_FFMPEG_UTILS_H
18 
19 #include <string>
20 #include <type_traits>
21 #include "utils/type_define.h"
22 #include "plugin/common/plugin_audio_tags.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 #include "libavutil/error.h"
28 #include "libavutil/frame.h"
29 #include "libavcodec/avcodec.h"
30 #ifdef __cplusplus
31 };
32 #endif
33 
34 namespace OHOS {
35 namespace Media {
36 namespace Plugin {
37 namespace Ffmpeg {
38 std::string AVStrError(int errnum);
39 
40 /**
41  * Convert time from ffmpeg to time in HST_TIME_BASE.
42  * @param pts ffmpeg time
43  * @param base ffmpeg time_base
44  * @return time in HST_TIME_BASE
45  */
46 uint64_t ConvertTimeFromFFmpeg(int64_t pts, AVRational base);
47 
48 /**
49  * Convert time in HST_TIME_BASE to ffmpeg time.
50  * @param time time in HST_TIME_BASE
51  * @param base ffmpeg time_base
52  * @return time in ffmpeg.
53  */
54 int64_t ConvertTimeToFFmpeg(int64_t timestampUs, AVRational base);
55 
56 /*
57  * Fill in pointers in an AVFrame, aligned by 4 (required by X).
58  */
59 int FillAVPicture(AVFrame* picture, uint8_t* ptr, enum AVPixelFormat pixFmt, int width, int height);
60 
61 /*
62  * Get the size of an picture
63  */
64 int GetAVPictureSize(int pixFmt, int width, int height);
65 
66 void RemoveDelimiter(char delimiter, std::string& str);
67 
68 std::string RemoveDelimiter(const char* str, char delimiter);
69 
70 void ReplaceDelimiter(const std::string& delmiters, char newDelimiter, std::string& str);
71 
72 std::vector<std::string> SplitString(const char* str, char delimiter);
73 
74 std::vector<std::string> SplitString(const std::string& string, char delimiter);
75 
76 AudioSampleFormat Trans2Format(AVSampleFormat sampleFormat);
77 
78 AVSampleFormat Trans2FFmepgFormat(AudioSampleFormat sampleFormat);
79 
80 AudioChannelLayout ConvertChannelLayoutFromFFmpeg(int channels, uint64_t ffChannelLayout);
81 
82 uint64_t ConvertChannelLayoutToFFmpeg(AudioChannelLayout channelLayout);
83 
84 bool FindAvMetaNameByTag(Tag tag, std::string& metaName);
85 bool FindTagByAvMetaName(const std::string& metaName, Tag& tag);
86 
87 AudioAacProfile ConvAacProfileFromFfmpeg (int32_t ffmpegProfile);
88 int32_t ConvAacProfileToFfmpeg (AudioAacProfile profile);
89 } // namespace Ffmpeg
90 } // namespace Plugin
91 } // namespace Media
92 } // namespace OHOS
93 #endif // HISTREAMER_FFMPEG_UTILS_H
94