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 CAST_DATA_SOURCE_H_ 17 #define CAST_DATA_SOURCE_H_ 18 19 #include "cast_shared_memory.h" 20 #include "iremote_broker.h" 21 22 namespace OHOS { 23 namespace CastEngine { 24 /** 25 * @brief Use with IMediaDataSource::ReadAt. 26 */ 27 enum CastDataSourceError : 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 the mediaDataSource instance need set to player. 39 * 40 */ 41 class ICastDataSource { 42 public: 43 virtual ~ICastDataSource() = default; 44 45 /** 46 * @brief Player use ReadAt to tell user the desired file position and length.(length is number of Bytes) 47 * Then usr filled the mem, and return the actual length of mem. 48 * @param mem The stream mem need to fill. see cast_shared_memory.h. 49 * @param length The stream length player want to get. 50 * @param pos The stream pos player want get start. 51 * The length of the filled memory must match the actual length returned. 52 * @return The actual length of stream mem filled, if failed or no mem return CastSharedMemory. 53 */ 54 virtual int32_t ReadAt(const std::shared_ptr<CastSharedMemory> &mem, uint32_t length, int64_t pos = -1) = 0; 55 56 /** 57 * @brief Get the total size of the stream. 58 * If the user does not know the length of the stream, size should be assigned -1, 59 * player will use the datasource not seekable. 60 * @param size Total size of the stream. If no size set -1. 61 * @return MSERR_OK if ok; others if failed. see media_errors.h 62 */ 63 virtual int32_t GetSize(int64_t &size) = 0; 64 }; 65 66 } // namespace CastEngine 67 } // namespace OHOS 68 #endif // CAST_DATA_SOURCE_H_