• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef HISTREAMER_HTTP_SOURCE_PLUGIN_H
16 #define HISTREAMER_HTTP_SOURCE_PLUGIN_H
17 
18 #include "http_lite_manager.h"
19 #include "plugin/common/plugin_types.h"
20 #include "plugin/interface/source_plugin.h"
21 #include "foundation/osal/thread/scoped_lock.h"
22 
23 namespace OHOS {
24 namespace Media {
25 namespace Plugin {
26 namespace HttpLitePlugin {
27 class HttpSourceAllocator : public Allocator {
28 public:
29     HttpSourceAllocator() = default;
30     ~HttpSourceAllocator() override = default;
31 
32     void *Alloc(size_t size) override;
33     void Free(void *ptr) override;
34 };
35 
36 class HttpSourcePlugin : public SourcePlugin {
37 public:
38     explicit HttpSourcePlugin(const std::string name) noexcept;
39     ~HttpSourcePlugin();
40     Status Init() override;
41     Status Deinit() override;
42     Status Prepare() override;
43     Status Reset() override;
44     Status Start() override;
45     Status Stop() override;
46     bool   IsParameterSupported(Tag tag) override;
47     Status GetParameter(Tag tag, ValueType &value) override;
48     Status SetParameter(Tag tag, const ValueType &value) override;
49     std::shared_ptr<Allocator> GetAllocator() override;
50     Status SetCallback(Callback* cb) override;
51     Status SetSource(std::shared_ptr<MediaSource> source) override;
52     Status Read(std::shared_ptr<Buffer> &buffer, size_t expectedLen) override;
53     Status GetSize(size_t &size) override;
54     bool   IsSeekable() override;
55     Status SeekTo(uint64_t offset) override;
56     static void OnError(int httpError, int localError, void *param, int support_retry);
57     Status OnHttpEvent(void *priv, int errorType, int32_t errorCode);
58 
59 private:
60     std::string url_;
61     std::string certFile_;
62     bool needExit_;
63     bool isSeekable_;
64     uint32_t bufferSize_;
65     unsigned int position_;
66     uint32_t waterline_;
67     size_t   fileSize_;
68     Callback* callback_ {};
69     std::shared_ptr<HttpLiteManager> httpHandle_;
70     std::shared_ptr<HttpSourceAllocator> mAllocator_;
71     mutable OSAL::Mutex httpMutex_ {};
72     Status OpenUri(std::string &url);
73     void CloseUri();
74 };
75 } // namespace HttpLitePlugin
76 } // namespace Plugin
77 } // namespace Media
78 } // namespace OHOS
79 
80 #endif