• 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 
16 #ifndef MEDIA_DATA_SOURCE_H_
17 #define MEDIA_DATA_SOURCE_H_
18 
19 #include "avsharedmemory.h"
20 
21 namespace OHOS {
22 namespace Media {
23 /**
24  * @brief Use with IMediaDataSource::ReadAt.
25  */
26 enum MediaDataSourceError : int32_t {
27     /**
28      * use with ReadAt.the resource is cut off and player will end.
29      * And the player will complete buffers and return an error.
30      */
31     SOURCE_ERROR_IO = -2,
32     /* use with ReadAt.the resource is eos and player will complete. */
33     SOURCE_ERROR_EOF = -1,
34 };
35 
36 /**
37  * @brief the mediaDataSource instance need set to player.
38  *
39  */
40 class IMediaDataSource {
41 public:
42     virtual ~IMediaDataSource() = default;
43 
44     /**
45      * @brief Player use ReadAt to tell user the desired file position and length.(length is number of Bytes)
46      * Then usr filled the mem, and return the actual length of mem.
47      * @param mem The stream mem need to fill. see avsharedmemory.h.
48      * @param length The stream length player want to get.
49      * @param pos The stream pos player want get start.
50      * The length of the filled memory must match the actual length returned.
51      * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError.
52      */
53     virtual int32_t ReadAt(const std::shared_ptr<AVSharedMemory> &mem, uint32_t length, int64_t pos = -1) = 0;
54 
55     /**
56      * @brief Get the total size of the stream.
57      * If the user does not know the length of the stream, size should be assigned -1,
58      * player will use the datasource not seekable.
59      * @param size Total size of the stream. If no size set -1.
60      * @return MSERR_OK if ok; others if failed. see media_errors.h
61      */
62     virtual int32_t GetSize(int64_t &size) = 0;
63 
64     // This interface has been deprecated
65     virtual int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0;
66     // This interface has been deprecated
67     virtual int32_t ReadAt(uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0;
68 };
69 } // namespace Media
70 } // namespace OHOS
71 #endif // MEDIA_DATA_SOURCE_H_