• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MEDIA_SOURCE_LOADING_REQUEST_H
17 #define HISTREAMER_MEDIA_SOURCE_LOADING_REQUEST_H
18 
19 #include <string>
20 #include "osal/task/mutex.h"
21 #include "plugin/plugin_buffer.h"
22 #include "common/media_source.h"
23 #include "app_client.h"
24 
25 namespace OHOS {
26 namespace Media {
27 namespace Plugins {
28 namespace HttpPlugin {
29 
30 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" };
31 
32 class LoadingRequestElements {
33 public:
LoadingRequestElements(int64_t uuid,const std::shared_ptr<NetworkClient> & client)34     LoadingRequestElements(int64_t uuid, const std::shared_ptr<NetworkClient> &client) : uuid_(uuid),
35         client_(client) {}
36     ~LoadingRequestElements();
37 
38     int32_t RespondData(int64_t uuid, int64_t offset, const std::shared_ptr<AVSharedMemory> &data);
39 
40     int32_t RespondHeader(int64_t uuid, std::map<std::string, std::string> header, std::string redirectUrl);
41 
42     int32_t FinishLoading(int64_t uuid, LoadingRequestError state);
43 
44     int64_t uuid_ {0};
45     std::shared_ptr<NetworkClient> client_ {};
46 };
47 
48 class MediaSourceLoadingRequest : public IMediaSourceLoadingRequest {
49 public:
50     int64_t Open(int64_t uuid, const std::shared_ptr<NetworkClient> &client);
51 
52     int32_t Close(int64_t uuid);
53 
54     ~MediaSourceLoadingRequest() override;
55 
56     int32_t RespondData(int64_t uuid, int64_t offset, const std::shared_ptr<AVSharedMemory> &data) override;
57 
58     int32_t RespondHeader(int64_t uuid, std::map<std::string, std::string> header, std::string redirectUrl) override;
59 
60     int32_t FinishLoading(int64_t uuid, LoadingRequestError state) override;
61 
62 private:
63     std::map<int64_t, std::shared_ptr<LoadingRequestElements>> requestMap_ {};
64     FairMutex clientMutex_{};
65 };
66 
67 class MediaSourceLoaderCombinations {
68 public:
MediaSourceLoaderCombinations(std::shared_ptr<IMediaSourceLoader> loader)69     explicit MediaSourceLoaderCombinations(std::shared_ptr<IMediaSourceLoader> loader) : loader_(loader) {}
70 
71     int64_t Open(const std::string &url, const std::map<std::string, std::string> &header,
72                  std::shared_ptr<NetworkClient> &client);
73 
74     int32_t Close(int64_t uuid);
75 
76     std::shared_ptr<MediaSourceLoadingRequest> request_ {nullptr};
77     std::shared_ptr<IMediaSourceLoader> loader_  {nullptr};
78 };
79 }
80 }
81 }
82 }
83 #endif