1 /* 2 * Copyright (c) 2024-2024 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 HISTREAMER_NETWORK_CLIENT_H 17 #define HISTREAMER_NETWORK_CLIENT_H 18 19 #include <string> 20 #include <map> 21 #include "network/network_typs.h" 22 #include "plugin/plugin_event.h" 23 #include "meta/media_types.h" 24 #include "common/status.h" 25 #include "common/media_source.h" 26 #include "common/avsharedmemorypool.h" 27 28 namespace OHOS { 29 namespace Media { 30 namespace Plugins { 31 namespace HttpPlugin { 32 class NetworkClient { 33 public: 34 virtual ~NetworkClient() = default; 35 virtual Status Init() = 0; 36 virtual Status Open(const std::string& url, const std::map<std::string, std::string>& httpHeader, 37 int32_t timeoutMs) = 0; 38 virtual Status RequestData(long startPos, int len, const RequestInfo& sourceInfo, 39 HandleResponseCbFunc completedCb) = 0; 40 virtual Status Close(bool isAsync) = 0; 41 virtual Status Deinit() = 0; 42 virtual Status GetIp(std::string &ip); 43 static std::shared_ptr<NetworkClient> GetInstance(RxHeader headCallback, RxBody bodyCallback, void *userParam); 44 virtual void SetAppUid(int32_t appUid); 45 static std::shared_ptr<NetworkClient> GetAppInstance(RxHeader headCallback, RxBody bodyCallback, void *userParam); SetLoader(std::shared_ptr<IMediaSourceLoader> sourceLoader)46 virtual void SetLoader(std::shared_ptr<IMediaSourceLoader> sourceLoader) {} RespondHeader(int64_t uuid,const std::map<std::string,std::string> & httpHeader,std::string redirctUrl)47 virtual int32_t RespondHeader(int64_t uuid, const std::map<std::string, std::string>& httpHeader, 48 std::string redirctUrl) 49 { 50 return 0; 51 } RespondData(int64_t uuid,int64_t offset,const std::shared_ptr<AVSharedMemory> memory)52 virtual int32_t RespondData(int64_t uuid, int64_t offset, const std::shared_ptr<AVSharedMemory> memory) 53 { 54 return 0; 55 } FinishLoading(int64_t uuid,LoadingRequestError state)56 virtual int32_t FinishLoading(int64_t uuid, LoadingRequestError state) 57 { 58 return 0; 59 } SetUuid(int64_t uuid)60 virtual void SetUuid(int64_t uuid) {} 61 GetRedirectUrl()62 virtual std::string GetRedirectUrl() 63 { 64 return ""; 65 } 66 }; 67 } // namespace HttpPlugin 68 } // namespace Plugins 69 } // namespace Media 70 } // namespace OHOS 71 #endif // HISTREAMER_NETWORK_CLIENT_H