• 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 
16 #ifndef AVSOURCE_H
17 #define AVSOURCE_H
18 
19 #include <vector>
20 #include <memory>
21 #include <string>
22 #include "avcodec_common.h"
23 #include "format.h"
24 
25 namespace OHOS {
26 namespace MediaAVCodec {
27 class AVSource {
28 public:
29     virtual ~AVSource() = default;
30 
31     /**
32      * @brief Get the format info of source.
33      * @param format The Format handle pointer to get format info.
34      * @return Returns {@link Format} if success; returns nullptr otherwise.
35      * @since 4.0
36      * @version 4.0
37      */
38     virtual int32_t GetSourceFormat(Format &format) = 0;
39 
40     /**
41      * @brief Gets the parameters of the source.
42      * @param format The Format handle pointer to get format info.
43      * @param trackIndex The track index to get format.
44      * @return Returns {@link Format} if success; returns nullptr otherwise.
45      * @since 4.0
46      * @version 4.0
47      */
48     virtual int32_t GetTrackFormat(Format &format, uint32_t trackIndex) = 0;
49 
50     /**
51      * @brief Gets the address of the source.
52      * @return Returns {@link Format} if success; returns nullptr otherwise.
53      * @since 4.0
54      * @version 4.0
55      */
56     virtual int32_t GetSourceAddr(uintptr_t &addr) = 0;
57 
58     std::string sourceUri;
59 };
60 
61 class __attribute__((visibility("default"))) AVSourceFactory {
62 public:
63 #ifdef UNSUPPORT_SOURCE
CreateWithURI(const std::string & uri)64     static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri)
65     {
66         (void)uri;
67         return nullptr;
68     }
69 
CreateWithFD(int32_t fd,int64_t offset,int64_t size)70     static std::shared_ptr<AVSource> CreateWithFD(int32_t fd, int64_t offset, int64_t size)
71     {
72         (void)uri;
73         return nullptr;
74     }
75 
76 #else
77     /**
78      * @brief Instantiate the preferred source of the uri.
79      * @param uri The file's uri.
80      * @return Returns the preferred source.
81      * @since 4.0
82      * @version 4.0
83      */
84     static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri);
85 
86     /**
87      * @brief Instantiate the preferred source of the fd.
88      * @param fd The fileDescriptor data source.
89      * @param offset The offset into the file to start reading.
90      * @param size the length in bytes to read.
91      * @return Returns the preferred source.
92      * @since 4.0
93      * @version 4.0
94      */
95     static std::shared_ptr<AVSource> CreateWithFD(int32_t fd, int64_t offset, int64_t size);
96 
97 #endif
98 private:
99     AVSourceFactory() = default;
100     ~AVSourceFactory() = default;
101 };
102 } // namespace MediaAVCodec
103 } // namespace OHOS
104 #endif // AVSOURCE_H
105 
106