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 "buffer/avsharedmemory.h" 20 #include "buffer/avbuffer.h" 21 22 namespace OHOS { 23 namespace Media { 24 /** 25 * @brief Use with IMediaDataSource::ReadAt. 26 */ 27 enum MediaDataSourceError : int32_t { 28 /** 29 * use with ReadAt.the resource is cut off and player will end. 30 * And the player will complete buffers and return an error. 31 */ 32 SOURCE_ERROR_IO = -2, 33 /* use with ReadAt.the resource is eos and player will complete. */ 34 SOURCE_ERROR_EOF = -1, 35 }; 36 37 /** 38 * @brief Use with AudioDataSource::ReadAt. 39 */ 40 enum class AudioDataSourceReadAtActionState : int32_t { 41 /** 42 * use with ReadAt. Sync audio and skip log. 43 */ 44 OK = 0, 45 SKIP_WITHOUT_LOG = 1, 46 RETRY_IN_INTERVAL = 2, 47 RETRY_SKIP = 3, 48 INVALID = -1, 49 }; 50 51 /** 52 * @brief the mediaDataSource instance need set to player. 53 * 54 */ 55 class IMediaDataSource { 56 public: 57 virtual ~IMediaDataSource() = default; 58 59 /** 60 * @brief Player use ReadAt to tell user the desired file position and length.(length is number of Bytes) 61 * Then usr filled the mem, and return the actual length of mem. 62 * @param mem The stream mem need to fill. see avsharedmemory.h. 63 * @param length The stream length player want to get. 64 * @param pos The stream pos player want get start. 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(const std::shared_ptr<AVSharedMemory> &mem, uint32_t length, int64_t pos = -1) = 0; 69 70 /** 71 * @brief Get the total size of the stream. 72 * If the user does not know the length of the stream, size should be assigned -1, 73 * player will use the datasource not seekable. 74 * @param size Total size of the stream. If no size set -1. 75 * @return MSERR_OK if ok; others if failed. see media_errors.h 76 */ 77 virtual int32_t GetSize(int64_t &size) = 0; 78 79 // This interface has been deprecated 80 virtual int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0; 81 // This interface has been deprecated 82 virtual int32_t ReadAt(uint32_t length, const std::shared_ptr<AVSharedMemory> &mem) = 0; 83 }; 84 85 class IAudioDataSource { 86 public: 87 virtual ~IAudioDataSource() = default; 88 89 /** 90 * @brief use ReadAt to tell Screen capture the audio av buffer and length.(length is number of Bytes) 91 * @param buffer The Av buffer mem need to fill. see avsharedmemory.h. 92 * @param length The stream length. 93 * The length of the filled memory must match the actual length returned. 94 * @return The action audio data source filter need to do. 95 */ 96 virtual AudioDataSourceReadAtActionState ReadAt(std::shared_ptr<AVBuffer> buffer, uint32_t length) = 0; 97 98 /** 99 * @brief Get the total size of the stream. 100 * If the user does not know the length of the stream, size should be assigned -1, 101 * @param size Total size of the stream. If no size set -1. 102 * @return 0 if ok; others if failed. see media_errors.h 103 */ 104 virtual int32_t GetSize(int64_t& size) = 0; 105 106 /** 107 * @brief Set FirstFramePts to AudoDataSource. 108 * @param firstFramePts First video Frame Pts. 109 */ 110 virtual void SetVideoFirstFramePts(int64_t firstFramePts) = 0; 111 }; 112 113 } // namespace Media 114 } // namespace OHOS 115 #endif // MEDIA_DATA_SOURCE_H_