mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-23 15:00:51 +00:00
回退修改网络能力代码
Signed-off-by: 徐松涛 <xusongtao3@huawei.com>
This commit is contained in:
parent
dae3220dbe
commit
9145922d85
10
bundle.json
10
bundle.json
@ -67,12 +67,11 @@
|
||||
"ffmpeg",
|
||||
"lame",
|
||||
"libxml2",
|
||||
"video_processing_engine",
|
||||
"curl",
|
||||
"openssl"
|
||||
"video_processing_engine"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function"
|
||||
"curl",
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
@ -115,9 +114,6 @@
|
||||
"header_base": "//foundation/multimedia/av_codec/interfaces/inner_api/native"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "//foundation/multimedia/av_codec/services/media_engine/plugins/source/http_source:media_plugin_HttpSource_static"
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/multimedia/av_codec/interfaces/kits/c:capi_packages",
|
||||
|
@ -30,7 +30,6 @@ declare_args() {
|
||||
defined(global_parts_info.multimedia_video_processing_engine)) {
|
||||
av_codec_support_video_processing_engine = true
|
||||
}
|
||||
av_codec_support_libcurl = true
|
||||
av_codec_support_hidumper = false
|
||||
}
|
||||
av_codec_sanitize = {
|
||||
|
@ -29,9 +29,6 @@ group("av_codec_media_engine_plugins") {
|
||||
"source:media_plugin_DataStreamSource",
|
||||
"source:media_plugin_FileFdSource",
|
||||
"source:media_plugin_FileSource",
|
||||
"source/http_source:media_plugin_HttpSource_static",
|
||||
"source/http_source:media_plugin_HttpSource",
|
||||
]
|
||||
if (av_codec_support_libcurl) {
|
||||
deps += [ "source/http_source:media_plugin_HttpSource" ]
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ config("http_source_plugin_config") {
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wno-sign-compare",
|
||||
"-fno-exceptions",
|
||||
"-fno-common",
|
||||
"-fstack-protector-all",
|
||||
@ -47,6 +48,8 @@ config("http_source_plugin_config") {
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include/mpd_parser",
|
||||
"//third_party/curl/include",
|
||||
"//third_party/openssl/include",
|
||||
]
|
||||
}
|
||||
|
||||
@ -60,25 +63,6 @@ ohos_shared_library("media_plugin_HttpSource") {
|
||||
"$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":media_plugin_HttpSource_static",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/network_client:http_curl_client",
|
||||
]
|
||||
|
||||
relative_install_dir = "media/media_plugins"
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "av_codec"
|
||||
}
|
||||
|
||||
ohos_static_library("media_plugin_HttpSource_static") {
|
||||
stack_protector_ret = true
|
||||
sanitize = av_codec_sanitize
|
||||
|
||||
configs = [
|
||||
":http_source_plugin_config",
|
||||
"$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"base64/base64_utils.cpp",
|
||||
"dash/dash_media_downloader.cpp",
|
||||
@ -108,6 +92,7 @@ ohos_static_library("media_plugin_HttpSource_static") {
|
||||
"dash/mpd_parser/i_dash_mpd_node.cpp",
|
||||
"dash/mpd_parser/sidx_box_parser.cpp",
|
||||
"download/downloader.cpp",
|
||||
"download/http_curl_client.cpp",
|
||||
"hls/hls_media_downloader.cpp",
|
||||
"hls/hls_playlist_downloader.cpp",
|
||||
"hls/hls_tags.cpp",
|
||||
@ -121,9 +106,13 @@ ohos_static_library("media_plugin_HttpSource_static") {
|
||||
"xml/xml_parser.cpp",
|
||||
]
|
||||
|
||||
deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]
|
||||
deps = [
|
||||
"$av_codec_root_dir/services/dfx:av_codec_service_dfx",
|
||||
"//third_party/curl:curl_shared",
|
||||
"//third_party/openssl:libcrypto_shared",
|
||||
]
|
||||
|
||||
public_external_deps = [
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"ffmpeg:libohosffmpeg",
|
||||
"graphic_surface:surface",
|
||||
@ -132,10 +121,11 @@ ohos_static_library("media_plugin_HttpSource_static") {
|
||||
"ipc:ipc_single",
|
||||
"libxml2:libxml2",
|
||||
"media_foundation:media_foundation",
|
||||
"openssl:libcrypto_shared",
|
||||
"safwk:system_ability_fwk",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
]
|
||||
|
||||
relative_install_dir = "media/media_plugins"
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "av_codec"
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "avcodec_trace.h"
|
||||
#include "downloader.h"
|
||||
#include "http_curl_client.h"
|
||||
#include "osal/utils/steady_clock.h"
|
||||
#include "securec.h"
|
||||
#include "plugin/plugin_time.h"
|
||||
@ -235,7 +236,7 @@ Downloader::Downloader(const std::string& name) noexcept : name_(std::move(name)
|
||||
{
|
||||
shouldStartNextRequest = true;
|
||||
|
||||
client_ = NetworkClient::GetInstance(&RxHeaderData, &RxBodyData, this);
|
||||
client_ = std::make_shared<HttpCurlClient>(&RxHeaderData, &RxBodyData, this);
|
||||
client_->Init();
|
||||
requestQue_ = std::make_shared<BlockingQueue<std::shared_ptr<DownloadRequest>>>(name_ + "RequestQue",
|
||||
REQUEST_QUEUE_SIZE);
|
||||
@ -258,7 +259,6 @@ Downloader::~Downloader()
|
||||
client_->Deinit();
|
||||
client_ = nullptr;
|
||||
}
|
||||
MEDIA_LOG_I("%{public}p ~Downloader", this);
|
||||
}
|
||||
|
||||
bool Downloader::Download(const std::shared_ptr<DownloadRequest>& request, int32_t waitMs)
|
||||
@ -411,6 +411,7 @@ bool Downloader::BeginDownload()
|
||||
MEDIA_LOG_I("BeginDownload");
|
||||
std::string url = currentRequest_->url_;
|
||||
std::map<std::string, std::string> httpHeader = currentRequest_->httpHeader_;
|
||||
|
||||
int32_t timeoutMs = currentRequest_->mediaSouce_.timeoutMs;
|
||||
FALSE_RETURN_V(!url.empty(), false);
|
||||
if (client_) {
|
||||
@ -463,35 +464,31 @@ void Downloader::RequestData()
|
||||
{
|
||||
MediaAVCodec::AVCodecTrace trace("Downloader::HttpDownloadLoop, startPos: "
|
||||
+ std::to_string(currentRequest_->startPos_) + ", reqSize: " + std::to_string(currentRequest_->requestSize_));
|
||||
NetworkClientErrorCode clientCode = NetworkClientErrorCode::ERROR_UNKNOWN;
|
||||
NetworkServerErrorCode serverCode = 0;
|
||||
int64_t startPos = currentRequest_->startPos_;
|
||||
if (currentRequest_->requestWholeFile_ && currentRequest_->shouldSaveData_) {
|
||||
startPos = -1;
|
||||
}
|
||||
std::string url = currentRequest_->url_;
|
||||
std::map<std::string, std::string> httpHeader = currentRequest_->httpHeader_;
|
||||
|
||||
auto handleResponseCb = [this](NetworkClientErrorCode clientCode, NetworkServerErrorCode serverCode, Status ret) {
|
||||
currentRequest_->clientError_ = clientCode;
|
||||
currentRequest_->serverError_ = serverCode;
|
||||
if (isDestructor_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ret == Status::OK) {
|
||||
HandleRetOK();
|
||||
} else {
|
||||
PauseLoop(true);
|
||||
MEDIA_LOG_E("Client request data failed. ret = " PUBLIC_LOG_D32 ", clientCode = " PUBLIC_LOG_D32
|
||||
",request queue size: " PUBLIC_LOG_U64,
|
||||
static_cast<int32_t>(ret), static_cast<int32_t>(clientCode),
|
||||
static_cast<int64_t>(requestQue_->Size()));
|
||||
std::shared_ptr<Downloader> unused;
|
||||
currentRequest_->statusCallback_(DownloadStatus::PARTTAL_DOWNLOAD, unused, currentRequest_);
|
||||
}
|
||||
};
|
||||
MEDIA_LOG_I("RequestData enter.");
|
||||
client_->RequestData(startPos, currentRequest_->requestSize_, url, httpHeader, handleResponseCb);
|
||||
MEDIA_LOG_I("RequestData end.");
|
||||
Status ret = client_->RequestData(startPos, currentRequest_->requestSize_,
|
||||
serverCode, clientCode);
|
||||
currentRequest_->clientError_ = clientCode;
|
||||
currentRequest_->serverError_ = serverCode;
|
||||
if (isDestructor_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ret == Status::OK) {
|
||||
HandleRetOK();
|
||||
} else {
|
||||
PauseLoop(true);
|
||||
MEDIA_LOG_E("Client request data failed. ret = " PUBLIC_LOG_D32 ", clientCode = " PUBLIC_LOG_D32
|
||||
",request queue size: " PUBLIC_LOG_U64,
|
||||
static_cast<int32_t>(ret), static_cast<int32_t>(clientCode),
|
||||
static_cast<int64_t>(requestQue_->Size()));
|
||||
std::shared_ptr<Downloader> unused;
|
||||
currentRequest_->statusCallback_(DownloadStatus::PARTTAL_DOWNLOAD, unused, currentRequest_);
|
||||
}
|
||||
}
|
||||
|
||||
void Downloader::HandlePlayingFinish()
|
||||
@ -516,7 +513,7 @@ void Downloader::HandleRetOK()
|
||||
PauseLoop(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int64_t remaining = 0;
|
||||
if (currentRequest_->endPos_ <= 0) {
|
||||
remaining = static_cast<int64_t>(currentRequest_->headerInfo_.fileContentLen) -
|
||||
@ -525,7 +522,7 @@ void Downloader::HandleRetOK()
|
||||
remaining = currentRequest_->endPos_ - currentRequest_->startPos_ + 1;
|
||||
}
|
||||
if (currentRequest_->headerInfo_.fileContentLen > 0 && remaining <= 0) { // 检查是否播放结束
|
||||
MEDIA_LOG_I("http transfer reach end, startPos_ " PUBLIC_LOG_D64, currentRequest_->startPos_);
|
||||
MEDIA_LOG_D("http transfer reach end, startPos_ " PUBLIC_LOG_D64, currentRequest_->startPos_);
|
||||
currentRequest_->isEos_ = true;
|
||||
HandlePlayingFinish();
|
||||
return;
|
||||
@ -660,7 +657,7 @@ size_t Downloader::RxBodyData(void* buffer, size_t size, size_t nitems, void* us
|
||||
if (!mediaDownloader->currentRequest_->isDownloading_) {
|
||||
mediaDownloader->currentRequest_->isDownloading_ = true;
|
||||
}
|
||||
if (!mediaDownloader->currentRequest_->saveData_(static_cast<uint8_t *>(buffer), static_cast<uint32_t>(dataLen))) {
|
||||
if (!mediaDownloader->currentRequest_->saveData_(static_cast<uint8_t *>(buffer), dataLen)) {
|
||||
MEDIA_LOG_W("Save data failed.");
|
||||
return 0; // save data failed, make perform finished.
|
||||
}
|
||||
|
@ -21,10 +21,9 @@
|
||||
#include <string>
|
||||
#include "osal/task/task.h"
|
||||
#include "osal/task/mutex.h"
|
||||
#include "osal/task/condition_variable.h"
|
||||
#include "osal/task/blocking_queue.h"
|
||||
#include "osal/utils/util.h"
|
||||
#include "network/network_client.h"
|
||||
#include "network_client.h"
|
||||
#include <chrono>
|
||||
#include "securec.h"
|
||||
|
||||
|
@ -69,7 +69,7 @@ std::string InsertCharBefore(std::string input, char from, char preChar, char ne
|
||||
std::string str(arr, strSize);
|
||||
std::size_t pos = output.find(from);
|
||||
std::size_t length = output.length();
|
||||
while (pos >= 0 && length >= 1 && pos <= length - 1 && pos != std::string::npos) {
|
||||
while (pos >= 0 && pos <= length - 1 && pos != std::string::npos) {
|
||||
char nextCharTemp = pos >= length ? '\0' : output[pos + 1];
|
||||
if (nextChar == '\0' || nextCharTemp == '\0' || nextCharTemp != nextChar) {
|
||||
output.replace(pos, 1, str);
|
||||
@ -91,7 +91,7 @@ std::string Trim(std::string str)
|
||||
if (str.empty()) {
|
||||
return str;
|
||||
}
|
||||
while (str.size() >= 1 && std::isspace(str[str.size() - 1])) {
|
||||
while (std::isspace(str[str.size() - 1])) {
|
||||
str.erase(str.size() - 1, 1);
|
||||
}
|
||||
return str;
|
||||
@ -178,11 +178,6 @@ void GetHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions)
|
||||
exclusions = ToString(httpProxy.GetExclusionList());
|
||||
}
|
||||
|
||||
std::shared_ptr<NetworkClient> NetworkClient::GetInstance(RxHeader headCallback, RxBody bodyCallback, void *userParam)
|
||||
{
|
||||
return std::make_shared<HttpCurlClient>(headCallback, bodyCallback, userParam);
|
||||
}
|
||||
|
||||
HttpCurlClient::HttpCurlClient(RxHeader headCallback, RxBody bodyCallback, void *userParam)
|
||||
: rxHeader_(headCallback), rxBody_(bodyCallback), userParam_(userParam)
|
||||
{
|
||||
@ -396,8 +391,8 @@ void HttpCurlClient::HandleUserAgent()
|
||||
// Open, Close, Deinit run in other thread.
|
||||
// Should call Open before start HttpDownload thread.
|
||||
// Should Pause HttpDownload thread then Close, Deinit.
|
||||
Status HttpCurlClient::RequestData(long startPos, int len, const std::string& url,
|
||||
const std::map<std::string, std::string>& httpHeader, HandleResponseCbFunc completedCb)
|
||||
Status HttpCurlClient::RequestData(long startPos, int len, NetworkServerErrorCode& serverCode,
|
||||
NetworkClientErrorCode& clientCode)
|
||||
{
|
||||
FALSE_RETURN_V(easyHandle_ != nullptr, Status::ERROR_NULL_POINTER);
|
||||
CheckRequestRange(startPos, len);
|
||||
@ -410,16 +405,15 @@ Status HttpCurlClient::RequestData(long startPos, int len, const std::string& ur
|
||||
}
|
||||
curl_easy_setopt(easyHandle_, CURLOPT_HTTPHEADER, headerList_);
|
||||
MEDIA_LOG_D("RequestData: startPos " PUBLIC_LOG_D32 ", len " PUBLIC_LOG_D32, static_cast<int>(startPos), len);
|
||||
AutoLock lock(mutex_);
|
||||
FALSE_RETURN_V(easyHandle_ != nullptr, Status::ERROR_NULL_POINTER);
|
||||
mutex_.lock();
|
||||
CURLcode returnCode = curl_easy_perform(easyHandle_);
|
||||
std::set <CURLcode> notRetrySet = {
|
||||
CURLE_COULDNT_RESOLVE_HOST, CURLE_GOT_NOTHING, CURLE_SSL_CONNECT_ERROR,
|
||||
CURLE_SSL_CERTPROBLEM, CURLE_SSL_CACERT, CURLE_SSL_CACERT_BADFILE, CURLE_PEER_FAILED_VERIFICATION,
|
||||
CURLE_HTTP_RETURNED_ERROR, CURLE_READ_ERROR, CURLE_HTTP_POST_ERROR};
|
||||
NetworkClientErrorCode clientCode = NetworkClientErrorCode::ERROR_OK;
|
||||
NetworkServerErrorCode serverCode = 0;
|
||||
Status ret = Status::OK;
|
||||
clientCode = NetworkClientErrorCode::ERROR_OK;
|
||||
serverCode = 0;
|
||||
if (returnCode != CURLE_OK) {
|
||||
MEDIA_LOG_E("Curl error " PUBLIC_LOG_D32, returnCode);
|
||||
if (notRetrySet.find(returnCode) != notRetrySet.end()) {
|
||||
@ -429,20 +423,18 @@ Status HttpCurlClient::RequestData(long startPos, int len, const std::string& ur
|
||||
} else {
|
||||
clientCode = NetworkClientErrorCode::ERROR_UNKNOWN;
|
||||
}
|
||||
ret = Status::ERROR_CLIENT;
|
||||
return Status::ERROR_CLIENT;
|
||||
} else {
|
||||
int64_t httpCode = 0;
|
||||
curl_easy_getinfo(easyHandle_, CURLINFO_RESPONSE_CODE, &httpCode);
|
||||
if (httpCode >= 400) { // 400
|
||||
MEDIA_LOG_E("Http error " PUBLIC_LOG_D64, httpCode);
|
||||
serverCode = httpCode;
|
||||
ret = Status::ERROR_SERVER;
|
||||
return Status::ERROR_SERVER;
|
||||
}
|
||||
SetIp();
|
||||
}
|
||||
mutex_.unlock();
|
||||
completedCb(clientCode, serverCode, ret);
|
||||
return ret;
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status HttpCurlClient::SetIp()
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "network/network_client.h"
|
||||
#include "network_client.h"
|
||||
#include "curl/curl.h"
|
||||
#include "osal/task/mutex.h"
|
||||
#include "syspara/parameter.h"
|
||||
@ -47,8 +47,8 @@ public:
|
||||
Status Open(const std::string& url, const std::map<std::string, std::string>& httpHeader,
|
||||
int32_t timeoutMs) override;
|
||||
|
||||
Status RequestData(long startPos, int len, const std::string& url,
|
||||
const std::map<std::string, std::string>& httpHeader, HandleResponseCbFunc completedCb) override;
|
||||
Status RequestData(long startPos, int len, NetworkServerErrorCode& serverCode,
|
||||
NetworkClientErrorCode& clientCode) override;
|
||||
|
||||
Status Close() override;
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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_NETWORK_CLIENT_H
|
||||
#define HISTREAMER_NETWORK_CLIENT_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "network_typs.h"
|
||||
#include "plugin/plugin_event.h"
|
||||
#include "meta/media_types.h"
|
||||
#include "common/status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class NetworkClient {
|
||||
public:
|
||||
virtual ~NetworkClient() = default;
|
||||
virtual Status Init() = 0;
|
||||
virtual Status Open(const std::string& url, const std::map<std::string, std::string>& httpHeader,
|
||||
int32_t timeoutMs) = 0;
|
||||
virtual Status RequestData(long startPos, int len, NetworkServerErrorCode& serverCode,
|
||||
NetworkClientErrorCode& clientCode) = 0;
|
||||
virtual Status Close() = 0;
|
||||
virtual Status Deinit() = 0;
|
||||
virtual Status GetIp(std::string &ip) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,68 +0,0 @@
|
||||
# Copyright (c) 2024-2024 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.
|
||||
#
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
config("http_curl_client_config") {
|
||||
defines = [
|
||||
"HST_ANY_WITH_NO_RTTI",
|
||||
"MEDIA_OHOS",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wno-sign-compare",
|
||||
"-fno-exceptions",
|
||||
"-fno-common",
|
||||
"-fstack-protector-all",
|
||||
"-Wshadow",
|
||||
"-FPIC",
|
||||
"-FS",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
"-Wformat=2",
|
||||
"-Wdate-time",
|
||||
]
|
||||
|
||||
cflags_cc = [
|
||||
"-std=c++17",
|
||||
"-fno-rtti",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("http_curl_client") {
|
||||
stack_protector_ret = true
|
||||
sanitize = av_codec_sanitize
|
||||
|
||||
configs = [
|
||||
":http_curl_client_config",
|
||||
"$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
|
||||
]
|
||||
|
||||
sources = [ "http_curl_client.cpp" ]
|
||||
|
||||
deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"curl:curl_shared",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"media_foundation:media_foundation",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"openssl:libcrypto_shared",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "av_codec"
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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_NETWORK_TYPES_H
|
||||
#define HISTREAMER_NETWORK_TYPES_H
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
using RxBody = size_t(*)(void* buffer, size_t size, size_t nitems, void* userParam);
|
||||
using RxHeader = size_t(*)(void* buffer, size_t size, size_t nitems, void* userParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -36,7 +36,7 @@ constexpr uint32_t DECRYPT_COPY_LEN = 128;
|
||||
constexpr int MIN_WITDH = 480;
|
||||
constexpr int SECOND_WITDH = 720;
|
||||
constexpr int THIRD_WITDH = 1080;
|
||||
constexpr uint64_t MAX_BUFFER_SIZE = 20 * 1024 * 1024;
|
||||
constexpr uint64_t MAX_BUFFER_SIZE = 19 * 1024 * 1024;
|
||||
constexpr uint32_t SAMPLE_INTERVAL = 1000; // Sampling time interval: ms
|
||||
constexpr int MAX_RECORD_COUNT = 10;
|
||||
constexpr int START_PLAY_WATER_LINE = 512 * 1024;
|
||||
@ -54,7 +54,7 @@ constexpr int64_t SECOND_TO_MILLIONSECOND = 1000;
|
||||
constexpr int UPDATE_CACHE_STEP = 5 * 1024;
|
||||
constexpr int SEEK_STATUS_RETRY_TIMES = 100;
|
||||
constexpr int SEEK_STATUS_SLEEP_TIME = 50;
|
||||
constexpr uint64_t CURRENT_BIT_RATE = 1 * 1024 * 1024;
|
||||
constexpr uint64_t CURRENT_BIT_RATE = 1 * 1024 * 1024; // bps
|
||||
constexpr int32_t ONE_SECONDS = 1000;
|
||||
constexpr int32_t TEN_MILLISECONDS = 10;
|
||||
}
|
||||
@ -655,7 +655,6 @@ void HlsMediaDownloader::OnWriteRingBuffer(uint32_t len)
|
||||
totalBits_ += writeBits;
|
||||
lastWriteBit_ += writeBits;
|
||||
dataUsage_ += writeBits;
|
||||
|
||||
if ((totalBits_ > START_PLAY_WATER_LINE) && (playDelayTime_ == 0)) {
|
||||
auto startPlayTime = steadyClock_.ElapsedMilliseconds();
|
||||
playDelayTime_ = startPlayTime - openTime_;
|
||||
|
@ -226,7 +226,9 @@ void M3U8::GetExtInf(const std::shared_ptr<Tag>& tag, double& duration) const
|
||||
if (item == nullptr) {
|
||||
return;
|
||||
}
|
||||
duration = item ->GetAttributeByName("DURATION")->FloatingPoint();
|
||||
if (item->GetAttributeByName("DURATION")) {
|
||||
duration = item->GetAttributeByName("DURATION")->FloatingPoint();
|
||||
}
|
||||
}
|
||||
|
||||
double M3U8::GetDuration() const
|
||||
|
@ -30,7 +30,7 @@ constexpr int RING_BUFFER_SIZE = 5 * 48 * 1024;
|
||||
constexpr int WATER_LINE = RING_BUFFER_SIZE / 30; // 30 WATER_LINE:8192
|
||||
#else
|
||||
constexpr int RING_BUFFER_SIZE = 5 * 1024 * 1024;
|
||||
constexpr int MAX_BUFFER_SIZE = 20 * 1024 * 1024;
|
||||
constexpr int MAX_BUFFER_SIZE = 19 * 1024 * 1024;
|
||||
constexpr int WATER_LINE = 8192; // WATER_LINE:8192
|
||||
constexpr int CURRENT_BIT_RATE = 1 * 1024 * 1024;
|
||||
#endif
|
||||
|
@ -132,7 +132,6 @@ private:
|
||||
std::atomic<bool> isHitSeeking_ {false};
|
||||
std::atomic<bool> isNeedDropData_ {false};
|
||||
std::atomic<bool> isServerAcceptRange_ {false};
|
||||
|
||||
size_t waterLineAbove_ {0};
|
||||
bool isInterrupt_ {false};
|
||||
bool isBuffering_ {false};
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "avcodec_trace.h"
|
||||
#include "http_source_plugin.h"
|
||||
#include "download/http_curl_client.h"
|
||||
#include "common/log.h"
|
||||
#include "hls/hls_media_downloader.h"
|
||||
#include "dash/dash_media_downloader.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "media_downloader.h"
|
||||
#include "meta/media_types.h"
|
||||
#include "plugin/source_plugin.h"
|
||||
#include "download/http_curl_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
@ -27,7 +27,10 @@ namespace {
|
||||
constexpr int RETRY_THRESHOLD = 1;
|
||||
constexpr int SERVER_ERROR_THRESHOLD = 500;
|
||||
constexpr int32_t READ_LOG_FEQUENCE = 50;
|
||||
constexpr int64_t MICROSECONDS_TO_MILLISECOND = 1000;
|
||||
constexpr int64_t RETRY_SEG = 50;
|
||||
}
|
||||
|
||||
DownloadMonitor::DownloadMonitor(std::shared_ptr<MediaDownloader> downloader) noexcept
|
||||
: downloader_(std::move(downloader))
|
||||
{
|
||||
@ -54,7 +57,7 @@ int64_t DownloadMonitor::HttpMonitorLoop()
|
||||
if (task.request && task.function) {
|
||||
task.function();
|
||||
}
|
||||
return 50 * 1000; // retry after 50ms
|
||||
return RETRY_SEG * MICROSECONDS_TO_MILLISECOND; // retry after 50ms
|
||||
}
|
||||
|
||||
bool DownloadMonitor::Open(const std::string& url, const std::map<std::string, std::string>& httpHeader)
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
bool SelectBitRate(uint32_t bitRate) override;
|
||||
void SetIsTriggerAutoMode(bool isAuto) override;
|
||||
void SetReadBlockingFlag(bool isReadBlockingAllowed) override;
|
||||
|
||||
void SetDemuxerState(int32_t streamId) override;
|
||||
void SetPlayStrategy(const std::shared_ptr<PlayStrategy>& playStrategy) override;
|
||||
void SetInterruptState(bool isInterruptNeeded) override;
|
||||
|
@ -92,7 +92,8 @@ bool CacheMediaChunkBufferImpl::Init(uint64_t totalBuffSize, uint32_t chunkSize)
|
||||
}
|
||||
|
||||
double newFragmentInitChunkNum = NEW_FRAGMENT_INIT_CHUNK_NUM;
|
||||
int64_t chunkNum = static_cast<int64_t>((totalBuffSize + chunkSize - 1) / chunkSize) + 1; // 1
|
||||
int64_t chunkNum = totalBuffSize + chunkSize >= 1 ?
|
||||
static_cast<int64_t>((totalBuffSize + chunkSize - 1) / chunkSize) + 1 : 1; // 1
|
||||
if ((chunkNum - static_cast<int64_t>(newFragmentInitChunkNum)) < 0) {
|
||||
return false;
|
||||
}
|
||||
@ -123,7 +124,7 @@ bool CacheMediaChunkBufferImpl::Init(uint64_t totalBuffSize, uint32_t chunkSize)
|
||||
freeChunks_.push_back(chunkInfo);
|
||||
temp += sizePerChunk;
|
||||
}
|
||||
chunkMaxNum_ = static_cast<uint32_t>(chunkNum) - 1; // -1
|
||||
chunkMaxNum_ = chunkNum >= 1 ? static_cast<uint32_t>(chunkNum) - 1 : 0; // -1
|
||||
totalBuffSize_ = totalBuffSize;
|
||||
chunkSize_ = chunkSize;
|
||||
initReadSizeFactor_ = newFragmentInitChunkNum / (chunkMaxNum_ - newFragmentInitChunkNum);
|
||||
|
@ -45,7 +45,7 @@ hls_test_sources = [
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/i_dash_mpd_node.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/downloader.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/network_client/http_curl_client.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/hls/hls_media_downloader.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/hls/hls_playlist_downloader.cpp",
|
||||
"$av_codec_root_dir/services/media_engine/plugins/source/http_source/hls/hls_tags.cpp",
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "download/downloader.h"
|
||||
#include "download/network_client/http_curl_client.h"
|
||||
#include "download/http_curl_client.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace std;
|
||||
|
Loading…
Reference in New Issue
Block a user