• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include "loading_request_impl.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_PLAYER, "LoadingRequestImpl" };
22 static std::atomic<uint64_t> g_uniqueRequestID = 0;
23 }
24 
25 namespace OHOS {
26 namespace Media {
LoadingRequestImpl(const std::shared_ptr<IMediaSourceLoadingRequest> & loadingRequest,std::string url,std::map<std::string,std::string> header)27 LoadingRequestImpl::LoadingRequestImpl(const std::shared_ptr<IMediaSourceLoadingRequest> &loadingRequest,
28     std::string url, std::map<std::string, std::string> header)
29     : loadingRequestCallback_(loadingRequest), url_(url), header_(header)
30 {
31     MEDIA_LOGD("LoadingRequestImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
32     uniqueId_ = g_uniqueRequestID.fetch_add(1, std::memory_order_relaxed);
33 }
34 
~LoadingRequestImpl()35 LoadingRequestImpl::~LoadingRequestImpl()
36 {
37     MEDIA_LOGD("LoadingRequestImpl:0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
38 }
39 
RespondData(int64_t uuid,int64_t offset,const std::shared_ptr<AVSharedMemory> & mem)40 int32_t LoadingRequestImpl::RespondData(int64_t uuid, int64_t offset, const std::shared_ptr<AVSharedMemory> &mem)
41 {
42     CHECK_AND_RETURN_RET_LOG(loadingRequestCallback_ != nullptr, MSERR_INVALID_VAL,
43         "loadingRequestCallback_ not exist");
44     return loadingRequestCallback_->RespondData(uuid, offset, mem);
45 }
46 
RespondHeader(int64_t uuid,std::map<std::string,std::string> header,std::string redirectUrl)47 int32_t LoadingRequestImpl::RespondHeader(int64_t uuid,
48     std::map<std::string, std::string> header, std::string redirectUrl)
49 {
50     CHECK_AND_RETURN_RET_LOG(loadingRequestCallback_ != nullptr, MSERR_INVALID_VAL,
51         "loadingRequestCallback_ not exist");
52     return loadingRequestCallback_->RespondHeader(uuid, header, redirectUrl);
53 }
54 
FinishLoading(int64_t uuid,int32_t requestedError)55 int32_t LoadingRequestImpl::FinishLoading(int64_t uuid, int32_t requestedError)
56 {
57     CHECK_AND_RETURN_RET_LOG(loadingRequestCallback_ != nullptr, MSERR_INVALID_VAL,
58         "loadingRequestCallback_ not exist");
59     return loadingRequestCallback_->FinishLoading(uuid, static_cast<LoadingRequestError>(requestedError));
60 }
61 
GetUniqueId()62 uint64_t LoadingRequestImpl::GetUniqueId()
63 {
64     return uniqueId_;
65 }
66 
GetUrl()67 std::string LoadingRequestImpl::GetUrl()
68 {
69     return url_;
70 }
71 
GetHeader()72 std::map<std::string, std::string> LoadingRequestImpl::GetHeader()
73 {
74     return header_;
75 }
76 } // namespace Media
77 } // namespace OHOS