1 /* 2 * Copyright (c) 2022-2022 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_HTTP_MEDIA_DOWNLOADER_H 17 #define HISTREAMER_HTTP_MEDIA_DOWNLOADER_H 18 19 #include <string> 20 #include <memory> 21 #include "foundation/utils/ring_buffer.h" 22 #include "plugin/plugins/source/http_source/download/downloader.h" 23 #include "plugin/plugins/source/http_source/media_downloader.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Plugin { 28 namespace HttpPlugin { 29 class HttpMediaDownloader : public MediaDownloader { 30 public: 31 HttpMediaDownloader() noexcept; 32 ~HttpMediaDownloader() override; 33 bool Open(const std::string& url) override; 34 void Close(bool isAsync) override; 35 void Pause() override; 36 void Resume() override; 37 bool Read(unsigned char* buff, unsigned int wantReadLength, unsigned int& realReadLength, bool& isEos) override; 38 bool Seek(int offset) override; 39 size_t GetContentLength() const override; 40 double GetDuration() const override; 41 Seekable GetSeekable() const override; 42 void SetCallback(Callback* cb) override; 43 void SetStatusCallback(StatusCallbackFunc cb) override; 44 bool GetStartedStatus() override; 45 46 private: 47 bool SaveData(uint8_t* data, uint32_t len); 48 49 private: 50 std::shared_ptr<RingBuffer> buffer_; 51 std::shared_ptr<Downloader> downloader_; 52 std::shared_ptr<DownloadRequest> downloadRequest_; 53 OSAL::Mutex mutex_; 54 OSAL::ConditionVariable cvReadWrite_; 55 Callback* callback_ {nullptr}; 56 StatusCallbackFunc statusCallback_ {nullptr}; 57 bool aboveWaterline_ {false}; 58 bool startedPlayStatus_ {false}; 59 }; 60 } 61 } 62 } 63 } 64 #endif