• 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 If the size of the datasource is greater than 0, provide the implementation of this interface.
46      * Player use ReadAt to tell the position and length of mem want get.(length is number of Bytes)
47      * Then usr filled the mem, and return the actual length of mem.
48      * @param pos The stream pos player want get start.
49      * @param length Stream length player want to get.
50      * @param mem Stream mem need to fill. see avsharedmemory.h.
51      * The memory length is greater than or equal to the length.
52      * The length of the filled memory must match the actual length returned.
53      * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError.
54      */
55     virtual int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0;
56 
57     /**
58      * @brief One-to-one use with getMem.
59      * If the size of the datasource is -1, provide the implementation of this interface.
60      * Player use ReadAt to tell the length of mem want get.(length is number of Bytes)
61      * Then usr filled the mem, and return the actual length of mem.
62      * @param length Stream length player want to get.
63      * @param mem Stream mem need to fill.see avsharedmemory.h.
64      * The memory length is greater than or equal to the length.
65      * The length of the filled memory must match the actual length returned.
66      * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError.
67      */
68     virtual int32_t ReadAt(uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0;
69 
70     /**
71      * @brief Get the total size of the stream.
72      * If the stream does not have the length, return -1. With -1, player will use the datasource not seekable.
73      * @param size Total size of the stream. If no size set -1.
74      * @return MSERR_OK if ok; others if failed. see media_errors.h
75      */
76     virtual int32_t GetSize(int64_t &size) = 0;
77 };
78 } // namespace Media
79 } // namespace OHOS
80 #endif // MEDIA_DATA_SOURCE_H_