/* * Copyright (c) 2022-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HISTREAMER_STREAMING_EXECUTOR_H #define HISTREAMER_STREAMING_EXECUTOR_H #include #include #include "client_factory.h" #include "ring_buffer.h" #include "network_client.h" #include "osal/thread/task.h" #include "plugin/interface/plugin_base.h" namespace OHOS { namespace Media { namespace Plugin { namespace HttpPlugin { struct HeaderInfo { char contentType[32]; // 32 chars size_t fileContentLen; long contentLen; bool isChunked {false}; }; class StreamingExecutor { public: StreamingExecutor() noexcept; virtual ~StreamingExecutor(); bool Open(const std::string &url); void Close(); bool Read(unsigned char *buff, unsigned int wantReadLength, unsigned int &realReadLength, bool &isEos); bool Seek(int offset); size_t GetContentLength() const; bool IsStreaming() const; void SetCallback(Callback* cb); private: void HttpDownloadThread(); static size_t RxBodyData(void *buffer, size_t size, size_t nitems, void *userParam); static size_t RxHeaderData(void *buffer, size_t size, size_t nitems, void *userParam); private: std::shared_ptr buffer_; std::shared_ptr factory_; std::shared_ptr client_; bool isEos_ {false}; // file download finished int64_t startPos_; HeaderInfo headerInfo_; std::shared_ptr task_; bool isDownloading_; int requestSize_; Callback* callback_ {nullptr}; bool aboveWaterline_ {false}; }; } } } } #endif