mirror of
https://github.com/fastogt/fastocloud.git
synced 2025-03-09 23:18:50 +00:00
Init FastoCloud on Github
This commit is contained in:
parent
d0d234101d
commit
d0d6551903
359 changed files with 32676 additions and 23 deletions
99
src/base/amazon_kinesis/amazon_kinesis.cpp
Normal file
99
src/base/amazon_kinesis/amazon_kinesis.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/amazon_kinesis/amazon_kinesis.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#define AMAZON_KINESIS_STREAM_NAME_FIELD "stream_name"
|
||||
#define AMAZON_KINESIS_SECRET_KEY_FIELD "secret_key"
|
||||
#define AMAZON_KINESIS_ACCESS_KEY_FIELD "access_key"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace amazon_kinesis {
|
||||
|
||||
AmazonKinesis::AmazonKinesis() : AmazonKinesis(std::string(), std::string(), std::string()) {}
|
||||
|
||||
AmazonKinesis::AmazonKinesis(const std::string& stream_name,
|
||||
const std::string& secret_key,
|
||||
const std::string& access_key)
|
||||
: stream_name_(stream_name), secret_key_(secret_key), access_key_(access_key) {}
|
||||
|
||||
bool AmazonKinesis::Equals(const AmazonKinesis& aws) const {
|
||||
return aws.stream_name_ == stream_name_ && aws.secret_key_ == secret_key_ && aws.access_key_ == access_key_;
|
||||
}
|
||||
|
||||
common::Optional<AmazonKinesis> AmazonKinesis::MakeAmazonKinesis(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<AmazonKinesis>();
|
||||
}
|
||||
|
||||
AmazonKinesis res;
|
||||
common::Value* stream_name_field = hash->Find(AMAZON_KINESIS_STREAM_NAME_FIELD);
|
||||
std::string stream_name;
|
||||
if (stream_name_field && stream_name_field->GetAsBasicString(&stream_name)) {
|
||||
res.stream_name_ = stream_name;
|
||||
}
|
||||
|
||||
common::Value* secret_key_field = hash->Find(AMAZON_KINESIS_SECRET_KEY_FIELD);
|
||||
std::string secret_key;
|
||||
if (secret_key_field && secret_key_field->GetAsBasicString(&secret_key)) {
|
||||
res.secret_key_ = secret_key;
|
||||
}
|
||||
|
||||
common::Value* access_key_field = hash->Find(AMAZON_KINESIS_ACCESS_KEY_FIELD);
|
||||
std::string access_key;
|
||||
if (access_key_field && access_key_field->GetAsBasicString(&access_key)) {
|
||||
res.access_key_ = access_key;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error AmazonKinesis::DoDeSerialize(json_object* serialized) {
|
||||
AmazonKinesis res;
|
||||
json_object* jstream_name = nullptr;
|
||||
json_bool jstream_name_exists =
|
||||
json_object_object_get_ex(serialized, AMAZON_KINESIS_STREAM_NAME_FIELD, &jstream_name);
|
||||
if (jstream_name_exists) {
|
||||
res.stream_name_ = json_object_get_string(jstream_name);
|
||||
}
|
||||
|
||||
json_object* jsecret_key = nullptr;
|
||||
json_bool jsecret_key_exists = json_object_object_get_ex(serialized, AMAZON_KINESIS_SECRET_KEY_FIELD, &jsecret_key);
|
||||
if (jsecret_key_exists) {
|
||||
res.secret_key_ = json_object_get_string(jsecret_key);
|
||||
}
|
||||
|
||||
json_object* jaccess_key = nullptr;
|
||||
json_bool jaccess_key_exists = json_object_object_get_ex(serialized, AMAZON_KINESIS_ACCESS_KEY_FIELD, &jaccess_key);
|
||||
if (jaccess_key_exists) {
|
||||
res.access_key_ = json_object_get_string(jaccess_key);
|
||||
}
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error AmazonKinesis::SerializeFields(json_object* out) const {
|
||||
json_object_object_add(out, AMAZON_KINESIS_STREAM_NAME_FIELD, json_object_new_string(stream_name_.c_str()));
|
||||
json_object_object_add(out, AMAZON_KINESIS_SECRET_KEY_FIELD, json_object_new_string(secret_key_.c_str()));
|
||||
json_object_object_add(out, AMAZON_KINESIS_ACCESS_KEY_FIELD, json_object_new_string(access_key_.c_str()));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace amazon_kinesis
|
||||
} // namespace fastocloud
|
||||
45
src/base/amazon_kinesis/amazon_kinesis.h
Normal file
45
src/base/amazon_kinesis/amazon_kinesis.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace amazon_kinesis {
|
||||
|
||||
class AmazonKinesis : public common::serializer::JsonSerializer<AmazonKinesis> {
|
||||
public:
|
||||
AmazonKinesis();
|
||||
AmazonKinesis(const std::string& stream_name, const std::string& secret_key, const std::string& access_key);
|
||||
|
||||
bool Equals(const AmazonKinesis& aws) const;
|
||||
|
||||
static common::Optional<AmazonKinesis> MakeAmazonKinesis(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
std::string stream_name_;
|
||||
std::string secret_key_;
|
||||
std::string access_key_;
|
||||
};
|
||||
|
||||
} // namespace amazon_kinesis
|
||||
} // namespace fastocloud
|
||||
92
src/base/channel_stats.cpp
Normal file
92
src/base/channel_stats.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
|
||||
#include <common/time.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
ChannelStats::ChannelStats() : ChannelStats(0) {}
|
||||
|
||||
ChannelStats::ChannelStats(fastotv::channel_id_t cid)
|
||||
: id_(cid),
|
||||
last_update_time_(0),
|
||||
total_bytes_(0),
|
||||
prev_total_bytes_(0),
|
||||
bytes_per_second_(0),
|
||||
desire_bytes_per_second_() {}
|
||||
|
||||
fastotv::channel_id_t ChannelStats::GetID() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
fastotv::timestamp_t ChannelStats::GetLastUpdateTime() const {
|
||||
return last_update_time_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetLastUpdateTime(fastotv::timestamp_t t) {
|
||||
last_update_time_ = t;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetTotalBytes() const {
|
||||
return total_bytes_;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetPrevTotalBytes() const {
|
||||
return prev_total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetPrevTotalBytes(size_t bytes) {
|
||||
prev_total_bytes_ = bytes;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetDiffTotalBytes() const {
|
||||
return total_bytes_ - prev_total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::UpdateBps(size_t sec) {
|
||||
if (!sec) {
|
||||
return;
|
||||
}
|
||||
|
||||
bytes_per_second_ = GetDiffTotalBytes() / sec;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetBps() const {
|
||||
return bytes_per_second_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetBps(size_t bps) {
|
||||
bytes_per_second_ = bps;
|
||||
}
|
||||
|
||||
void ChannelStats::UpdateCheckPoint() {
|
||||
prev_total_bytes_ = total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetTotalBytes(size_t bytes) {
|
||||
total_bytes_ = bytes;
|
||||
last_update_time_ = common::time::current_utc_mstime();
|
||||
}
|
||||
|
||||
void ChannelStats::SetDesireBytesPerSecond(const common::media::DesireBytesPerSec& bps) {
|
||||
desire_bytes_per_second_ = bps;
|
||||
}
|
||||
|
||||
common::media::DesireBytesPerSec ChannelStats::GetDesireBytesPerSecond() const {
|
||||
return desire_bytes_per_second_;
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
||||
61
src/base/channel_stats.h
Normal file
61
src/base/channel_stats.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/media/bandwidth_estimation.h>
|
||||
|
||||
#include <fastotv/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
class ChannelStats { // only compile time size fields
|
||||
public:
|
||||
ChannelStats();
|
||||
explicit ChannelStats(fastotv::channel_id_t cid);
|
||||
|
||||
fastotv::channel_id_t GetID() const;
|
||||
|
||||
fastotv::timestamp_t GetLastUpdateTime() const;
|
||||
void SetLastUpdateTime(fastotv::timestamp_t t);
|
||||
|
||||
size_t GetTotalBytes() const;
|
||||
void SetTotalBytes(size_t bytes);
|
||||
|
||||
size_t GetPrevTotalBytes() const;
|
||||
void SetPrevTotalBytes(size_t bytes);
|
||||
|
||||
size_t GetDiffTotalBytes() const;
|
||||
|
||||
void UpdateBps(size_t sec);
|
||||
size_t GetBps() const;
|
||||
void SetBps(size_t bps);
|
||||
|
||||
void UpdateCheckPoint();
|
||||
|
||||
void SetDesireBytesPerSecond(const common::media::DesireBytesPerSec& bps);
|
||||
common::media::DesireBytesPerSec GetDesireBytesPerSecond() const;
|
||||
|
||||
private:
|
||||
fastotv::channel_id_t id_;
|
||||
|
||||
fastotv::timestamp_t last_update_time_; // up_time
|
||||
size_t total_bytes_; // received bytes
|
||||
size_t prev_total_bytes_; // checkpoint received bytes
|
||||
size_t bytes_per_second_; // bps
|
||||
|
||||
common::media::DesireBytesPerSec desire_bytes_per_second_;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
||||
15
src/base/config_fields.cpp
Normal file
15
src/base/config_fields.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/config_fields.h"
|
||||
65
src/base/config_fields.h
Normal file
65
src/base/config_fields.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define FEEDBACK_DIR_FIELD "feedback_directory" // required
|
||||
#define DATA_DIR_FIELD "data_directory"
|
||||
#define LOG_LEVEL_FIELD "log_level"
|
||||
#define ID_FIELD "id" // required
|
||||
#define TYPE_FIELD "type" // required
|
||||
#define PYFASTOSTREAM_PATH_FIELD "pyfastostream_path"
|
||||
#define AUTO_EXIT_TIME_FIELD "auto_exit_time"
|
||||
|
||||
#define INPUT_FIELD "input" // required
|
||||
#define OUTPUT_FIELD "output"
|
||||
#define HAVE_VIDEO_FIELD "have_video"
|
||||
#define HAVE_AUDIO_FIELD "have_audio"
|
||||
#define HAVE_SUBTITLE_FIELD "have_subtitle"
|
||||
#define DEINTERLACE_FIELD "deinterlace"
|
||||
#define FRAME_RATE_FIELD "frame_rate"
|
||||
#define AUDIO_CHANNELS_FIELD "audio_channels"
|
||||
#define VOLUME_FIELD "volume"
|
||||
#define VIDEO_PARSER_FIELD "video_parser"
|
||||
#define AUDIO_PARSER_FIELD "audio_parser"
|
||||
#define VIDEO_CODEC_FIELD "video_codec"
|
||||
#define AUDIO_CODEC_FIELD "audio_codec"
|
||||
#define AUDIO_SELECT_FIELD "audio_select"
|
||||
#define TIMESHIFT_DIR_FIELD "timeshift_dir" // requeired in timeshift mode
|
||||
#define TIMESHIFT_CHUNK_LIFE_TIME_FIELD "timeshift_chunk_life_time"
|
||||
#define TIMESHIFT_DELAY_FIELD "timeshift_delay"
|
||||
#define TIMESHIFT_CHUNK_DURATION_FIELD "timeshift_chunk_duration"
|
||||
#define CLEANUP_TS_FIELD "cleanup_ts"
|
||||
#define LOGO_FIELD "logo"
|
||||
#define RSVG_LOGO_FIELD "rsvg_logo"
|
||||
#define LOOP_FIELD "loop"
|
||||
#define RESTART_ATTEMPTS_FIELD "restart_attempts"
|
||||
#define DELAY_TIME_FIELD "delay_time"
|
||||
#define SIZE_FIELD "size"
|
||||
#define VIDEO_BIT_RATE_FIELD "video_bitrate"
|
||||
#define AUDIO_BIT_RATE_FIELD "audio_bitrate"
|
||||
#define ASPECT_RATIO_FIELD "aspect_ratio"
|
||||
#define RELAY_AUDIO_FIELD "relay_audio"
|
||||
#define RELAY_VIDEO_FIELD "relay_video"
|
||||
|
||||
#define DECKLINK_VIDEO_MODE_FIELD "decklink_video_mode"
|
||||
|
||||
#if defined(MACHINE_LEARNING)
|
||||
#define DEEP_LEARNING_FIELD "deep_learning"
|
||||
#define DEEP_LEARNING_OVERLAY_FIELD "deep_learning_overlay"
|
||||
#endif
|
||||
|
||||
#if defined(AMAZON_KINESIS)
|
||||
#define AMAZON_KINESIS_FIELD "amazon_kinesis"
|
||||
#endif
|
||||
15
src/base/constants.cpp
Normal file
15
src/base/constants.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/constants.h"
|
||||
33
src/base/constants.h
Normal file
33
src/base/constants.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#define DEFAULT_VOLUME 1.0
|
||||
#define DEFAULT_DECKLINK_VIDEO_MODE 1
|
||||
|
||||
#define DEFAULT_TIMESHIFT_CHUNK_DURATION 120
|
||||
#define DEFAULT_CHUNK_LIFE_TIME 12 * 3600
|
||||
|
||||
#define DEFAULT_LOOP false
|
||||
|
||||
#define TEST_URL "test"
|
||||
#define DISPLAY_URL "display"
|
||||
#define FAKE_URL "fake"
|
||||
|
||||
#define LOGS_FILE_NAME "logs"
|
||||
|
||||
#define KILL_STREAM_SIGNAL SIGTERM
|
||||
27
src/base/gst_constants.cpp
Normal file
27
src/base/gst_constants.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/gst_constants.h"
|
||||
|
||||
const std::array<const char*, SUPPORTED_VIDEO_PARSERS_COUNT> kSupportedVideoParsers = {
|
||||
{TS_PARSE, H264_PARSE, H265_PARSE}};
|
||||
|
||||
const std::array<const char*, SUPPORTED_AUDIO_PARSERS_COUNT> kSupportedAudioParsers = {
|
||||
{MPEG_AUDIO_PARSE, AAC_PARSE, AC3_PARSE, RAW_AUDIO_PARSE}};
|
||||
|
||||
const std::array<const char*, SUPPORTED_VIDEO_ENCODERS_COUNT> kSupportedVideoEncoders = {
|
||||
{EAVC_ENC, OPEN_H264_ENC, X264_ENC, NV_H264_ENC, NV_H265_ENC, VAAPI_H264_ENC, VAAPI_MPEG2_ENC, MFX_H264_ENC,
|
||||
X265_ENC, MSDK_H264_ENC}};
|
||||
const std::array<const char*, SUPPORTED_AUDIO_ENCODERS_COUNT> kSupportedAudioEncoders = {
|
||||
{LAME_MP3_ENC, FAAC, VOAAC_ENC}};
|
||||
158
src/base/gst_constants.h
Normal file
158
src/base/gst_constants.h
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#define DECODEBIN "decodebin"
|
||||
#define FAKE_SINK "fakesink"
|
||||
#define TEST_SINK "testsink"
|
||||
#define VIDEO_TEST_SRC "videotestsrc"
|
||||
#define AUDIO_TEST_SRC "audiotestsrc"
|
||||
#define DISPLAY_SRC "ximagesrc"
|
||||
#define VIDEO_SCREEN_SINK "autovideosink"
|
||||
#define AUDIO_SCREEN_SINK "autoaudiosink"
|
||||
#define QUEUE "queue"
|
||||
#define QUEUE2 "queue2"
|
||||
#define H264_PARSE "h264parse"
|
||||
#define H265_PARSE "h265parse"
|
||||
#define MPEG_VIDEO_PARSE "mpegvideoparse"
|
||||
#define AAC_PARSE "aacparse"
|
||||
#define AC3_PARSE "ac3parse"
|
||||
#define MPEG_AUDIO_PARSE "mpegaudioparse"
|
||||
#define RAW_AUDIO_PARSE "rawaudioparse"
|
||||
#define TEE "tee"
|
||||
#define MP4_MUX "mp4mux"
|
||||
#define QT_MUX "qtmux"
|
||||
#define FLV_MUX "flvmux"
|
||||
#define MPEGTS_MUX "mpegtsmux"
|
||||
#define FILE_SINK "filesink"
|
||||
#define RTP_MUX "rtpmux"
|
||||
#define RTP_MPEG2_PAY "rtpmp2tpay"
|
||||
#define RTP_H264_PAY "rtph264pay"
|
||||
#define RTP_H265_PAY "rtph265pay"
|
||||
#define RTP_AAC_PAY "rtpmp4apay"
|
||||
#define RTP_AC3_PAY "rtpac3pay"
|
||||
#define RTP_MPEG2_DEPAY "rtpmp2tdepay"
|
||||
#define RTP_H264_DEPAY "rtph264depay"
|
||||
#define RTP_H265_DEPAY "rtph265depay"
|
||||
#define RTP_AAC_DEPAY "rtpmp4adepay"
|
||||
#define RTP_AC3_DEPAY "rtpac3depay"
|
||||
#define V4L2_SRC "v4l2src"
|
||||
#define SPLIT_MUX_SINK "splitmuxsink"
|
||||
#define ALSA_SRC "alsasrc"
|
||||
#define MULTIFILE_SRC "multifilesrc"
|
||||
#define APP_SRC "appsrc"
|
||||
#define FILE_SRC "filesrc"
|
||||
#define IMAGE_FREEZE "imagefreeze"
|
||||
#define CAPS_FILTER "capsfilter"
|
||||
#define AUDIO_CONVERT "audioconvert"
|
||||
#define RG_VOLUME "rgvolume"
|
||||
#define VOLUME "volume"
|
||||
#define FAAC "faac"
|
||||
#define VOAAC_ENC "voaacenc"
|
||||
#define AUDIO_RESAMPLE "audioresample"
|
||||
#define LAME_MP3_ENC "lamemp3enc"
|
||||
#define VIDEO_CONVERT "videoconvert"
|
||||
#define AV_DEINTERLACE "avdeinterlace"
|
||||
#define DEINTERLACE "deinterlace"
|
||||
#define ASPECT_RATIO "aspectratiocrop"
|
||||
#define UDP_SINK "udpsink"
|
||||
#define TCP_SERVER_SINK "tcpserversink"
|
||||
#define RTMP_SINK "rtmpsink"
|
||||
#define HLS_SINK "hlssink"
|
||||
#define SOUP_HTTP_SRC "souphttpsrc"
|
||||
#define DVB_SRC "dvbsrc"
|
||||
#define VIDEO_SCALE "videoscale"
|
||||
#define VIDEO_RATE "videorate"
|
||||
#define MULTIFILE_SINK "multifilesink"
|
||||
#define KVS_SINK "kvssink"
|
||||
|
||||
#define NV_H264_ENC "nvh264enc"
|
||||
|
||||
#define NV_H265_ENC "nvh265enc"
|
||||
|
||||
#define MSDK_H264_ENC "msdkh264enc"
|
||||
|
||||
#define X264_ENC "x264enc"
|
||||
|
||||
#define X265_ENC "x265enc"
|
||||
#define MPEG2_ENC "mpeg2enc"
|
||||
|
||||
#define EAVC_ENC "eavcenc"
|
||||
|
||||
#define OPEN_H264_ENC "openh264enc"
|
||||
|
||||
#define UDP_SRC "udpsrc"
|
||||
#define RTMP_SRC "rtmpsrc"
|
||||
#define RTSP_SRC "rtspsrc"
|
||||
#define TCP_SERVER_SRC "tcpserversrc"
|
||||
|
||||
#define VAAPI_H264_ENC "vaapih264enc"
|
||||
|
||||
#define VAAPI_MPEG2_ENC "vaapimpeg2enc"
|
||||
#define VAAPI_DECODEBIN "vaapidecodebin"
|
||||
#define VAAPI_POST_PROC "vaapipostproc"
|
||||
|
||||
#define GDK_PIXBUF_OVERLAY "gdkpixbufoverlay"
|
||||
#define RSVG_OVERLAY "rsvgoverlay"
|
||||
#define VIDEO_BOX "videobox"
|
||||
#define VIDEO_MIXER "videomixer"
|
||||
#define AUDIO_MIXER "audiomixer"
|
||||
#define INTERLEAVE "interleave"
|
||||
#define DEINTERLEAVE "deinterleave"
|
||||
#define CAIRO_OVERLAY "cairooverlay"
|
||||
#define TEXT_OVERLAY "textoverlay"
|
||||
#define VIDEO_CROP "videocrop"
|
||||
#define SPECTRUM "spectrum"
|
||||
#define LEVEL "level"
|
||||
#define HLS_DEMUX "hlsdemux"
|
||||
#define VIDEO_DECK_SINK "decklinkvideosink"
|
||||
#define AUDIO_DECK_SINK "decklinkaudiosink"
|
||||
#define INTERLACE "interlace"
|
||||
#define AUTO_VIDEO_CONVERT "autovideoconvert"
|
||||
#define TS_PARSE "tsparse"
|
||||
#define AVDEC_H264 "avdec_h264"
|
||||
#define TS_DEMUX "tsdemux"
|
||||
|
||||
#define AVDEC_AC3 "avdec_ac3"
|
||||
#define AVDEC_AC3_FIXED "avdec_ac3_fixed"
|
||||
#define AVDEC_AAC "avdec_aac"
|
||||
#define AVDEC_AAC_FIXED "avdec_aac_fixed"
|
||||
#define SOUP_HTTP_CLIENT_SINK "souphttpclientsink"
|
||||
|
||||
#define MFX_H264_ENC "mfxh264enc"
|
||||
#define MFX_VPP "mfxvpp"
|
||||
#define MFX_H264_DEC "mfxh264dec"
|
||||
|
||||
#define SRT_SRC "srtsrc"
|
||||
#define SRT_SINK "srtsink"
|
||||
|
||||
// deep learning
|
||||
#define TINY_YOLOV2 "tinyyolov2"
|
||||
#define TINY_YOLOV3 "tinyyolov3"
|
||||
#define DETECTION_OVERLAY "detectionoverlay"
|
||||
|
||||
#define SUPPORTED_VIDEO_PARSERS_COUNT 3
|
||||
#define SUPPORTED_AUDIO_PARSERS_COUNT 4
|
||||
|
||||
extern const std::array<const char*, SUPPORTED_VIDEO_PARSERS_COUNT> kSupportedVideoParsers;
|
||||
extern const std::array<const char*, SUPPORTED_AUDIO_PARSERS_COUNT> kSupportedAudioParsers;
|
||||
|
||||
#define SUPPORTED_VIDEO_ENCODERS_COUNT 10
|
||||
#define SUPPORTED_AUDIO_ENCODERS_COUNT 3
|
||||
|
||||
extern const std::array<const char*, SUPPORTED_VIDEO_ENCODERS_COUNT> kSupportedVideoEncoders;
|
||||
extern const std::array<const char*, SUPPORTED_AUDIO_ENCODERS_COUNT> kSupportedAudioEncoders;
|
||||
23
src/base/link_generator/ilink_generator.cpp
Normal file
23
src/base/link_generator/ilink_generator.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/link_generator/ilink_generator.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
ILinkGenerator::~ILinkGenerator() {}
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
||||
29
src/base/link_generator/ilink_generator.h
Normal file
29
src/base/link_generator/ilink_generator.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fastotv/types/input_uri.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
class ILinkGenerator {
|
||||
public:
|
||||
virtual bool Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const WARN_UNUSED_RESULT = 0;
|
||||
virtual ~ILinkGenerator();
|
||||
};
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
||||
126
src/base/link_generator/pyfastostream.cpp
Normal file
126
src/base/link_generator/pyfastostream.cpp
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/link_generator/pyfastostream.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#include "base/platform_macros.h"
|
||||
#include "base/utils.h"
|
||||
|
||||
namespace {
|
||||
static const char* kStreams[9] = {"best", "1080p60", "720p60", "720p", "480p", "360p", "240p", "144p", "worst"};
|
||||
|
||||
bool GetTrueUrl(const std::string& path,
|
||||
const common::uri::GURL& url,
|
||||
const fastotv::PyFastoStream& link,
|
||||
common::uri::GURL* generated_url,
|
||||
size_t rec = 0) {
|
||||
if (rec >= SIZEOFMASS(kStreams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!generated_url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cmd_line = path + " --url";
|
||||
const auto http = link.GetHttp();
|
||||
if (http) {
|
||||
cmd_line += " --http-proxy=" + http->spec();
|
||||
}
|
||||
|
||||
const auto https = link.GetHttps();
|
||||
if (https) {
|
||||
cmd_line += " --https-proxy=" + https->spec();
|
||||
}
|
||||
|
||||
std::string raw_url = url.spec();
|
||||
common::Optional<std::string> audio_master;
|
||||
if (url.SchemeIsFile() && url.has_query()) {
|
||||
audio_master = fastocloud::GetAudioMasterUrlFromQuery(url.query());
|
||||
if (audio_master) {
|
||||
raw_url = *audio_master;
|
||||
}
|
||||
}
|
||||
|
||||
cmd_line += common::MemSPrintf(" \'%s\' --quality %s --prefer %d", raw_url, kStreams[rec], link.GetPrefer());
|
||||
FILE* fp = popen(cmd_line.c_str(), "r");
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char true_url[1024] = {0};
|
||||
char* res = fgets(true_url, sizeof(true_url) - 1, fp);
|
||||
int closed = pclose(fp);
|
||||
if (WIFEXITED(closed)) {
|
||||
if (WEXITSTATUS(closed) == EXIT_FAILURE) {
|
||||
return GetTrueUrl(path, url, link, generated_url, ++rec);
|
||||
}
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ln = strlen(true_url) - 1;
|
||||
if (true_url[ln] == '\n') {
|
||||
true_url[ln] = 0;
|
||||
}
|
||||
|
||||
if (audio_master) {
|
||||
*generated_url = common::uri::GURL("file://" + url.path() + "?audio=" + true_url);
|
||||
return true;
|
||||
}
|
||||
|
||||
*generated_url = common::uri::GURL(true_url);
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
PyFastoPyFastoStreamGenerator::PyFastoPyFastoStreamGenerator(
|
||||
const common::file_system::ascii_file_string_path& script_path)
|
||||
: script_path_(script_path) {}
|
||||
|
||||
bool PyFastoPyFastoStreamGenerator::Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const {
|
||||
if (!out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto str = src.GetPyFastoStream();
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!script_path_.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
common::uri::GURL gen;
|
||||
if (!GetTrueUrl(script_path_.GetPath(), src.GetUrl(), *str, &gen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = src;
|
||||
out->SetUrl(gen);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
||||
36
src/base/link_generator/pyfastostream.h
Normal file
36
src/base/link_generator/pyfastostream.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
|
||||
#include "base/link_generator/ilink_generator.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
class PyFastoPyFastoStreamGenerator : public ILinkGenerator {
|
||||
public:
|
||||
typedef common::Optional<common::uri::GURL> http_proxy_t;
|
||||
explicit PyFastoPyFastoStreamGenerator(const common::file_system::ascii_file_string_path& script_path);
|
||||
|
||||
bool Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const override WARN_UNUSED_RESULT;
|
||||
|
||||
private:
|
||||
const common::file_system::ascii_file_string_path script_path_;
|
||||
};
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
||||
158
src/base/machine_learning/deep_learning.cpp
Normal file
158
src/base/machine_learning/deep_learning.cpp
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/machine_learning/deep_learning.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#define DEEP_LEARNING_BACKEND_FIELD "backend"
|
||||
#define DEEP_LEARNING_MODEL_PATH_FIELD "model_path"
|
||||
#define DEEP_LEARNING_PROPERTIES_FIELD "properties"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
DeepLearning::DeepLearning() : backend_(fastoml::TENSORFLOW), model_path_(), properties_() {}
|
||||
|
||||
DeepLearning::DeepLearning(fastoml::SupportedBackends backend, const file_path_t& model_path, const properties_t& prop)
|
||||
: backend_(backend), model_path_(model_path), properties_(prop) {}
|
||||
|
||||
DeepLearning::file_path_t DeepLearning::GetModelPath() const {
|
||||
return model_path_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetModelPath(const file_path_t& path) {
|
||||
model_path_ = path;
|
||||
}
|
||||
|
||||
DeepLearning::properties_t DeepLearning::GetProperties() const {
|
||||
return properties_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetProperties(const properties_t& prop) {
|
||||
properties_ = prop;
|
||||
}
|
||||
|
||||
fastoml::SupportedBackends DeepLearning::GetBackend() const {
|
||||
return backend_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetBackend(fastoml::SupportedBackends backend) {
|
||||
backend_ = backend;
|
||||
}
|
||||
|
||||
bool DeepLearning::Equals(const DeepLearning& learn) const {
|
||||
return learn.backend_ == backend_ && learn.model_path_ == model_path_;
|
||||
}
|
||||
|
||||
common::Optional<DeepLearning> DeepLearning::MakeDeepLearning(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
|
||||
DeepLearning res;
|
||||
common::Value* learning_backend_field = hash->Find(DEEP_LEARNING_BACKEND_FIELD);
|
||||
int backend;
|
||||
if (!learning_backend_field || !learning_backend_field->GetAsInteger(&backend)) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
res.SetBackend(static_cast<fastoml::SupportedBackends>(backend));
|
||||
|
||||
std::string model_path_str;
|
||||
common::Value* model_path_field = hash->Find(DEEP_LEARNING_MODEL_PATH_FIELD);
|
||||
if (!model_path_field || !model_path_field->GetAsBasicString(&model_path_str)) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
res.SetModelPath(file_path_t(model_path_str));
|
||||
|
||||
common::Value* properties_field = hash->Find(DEEP_LEARNING_PROPERTIES_FIELD);
|
||||
common::ArrayValue* arr = nullptr;
|
||||
if (properties_field && properties_field->GetAsList(&arr)) {
|
||||
properties_t properties;
|
||||
for (size_t i = 0; i < arr->GetSize(); ++i) {
|
||||
common::Value* prop = nullptr;
|
||||
if (arr->Get(i, &prop)) {
|
||||
common::HashValue* hprop = nullptr;
|
||||
if (prop->GetAsHash(&hprop)) {
|
||||
for (auto it = hprop->begin(); it != hprop->end(); ++it) {
|
||||
std::string value_str;
|
||||
if (it->second->GetAsBasicString(&value_str)) {
|
||||
BackendProperty pr = {it->first.as_string(), value_str};
|
||||
properties.push_back(pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.SetProperties(properties);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error DeepLearning::DoDeSerialize(json_object* serialized) {
|
||||
DeepLearning res;
|
||||
json_object* jbackend = nullptr;
|
||||
json_bool jbackend_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_BACKEND_FIELD, &jbackend);
|
||||
if (!jbackend_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetBackend(static_cast<fastoml::SupportedBackends>(json_object_get_int(jbackend)));
|
||||
|
||||
json_object* jmodel_path = nullptr;
|
||||
json_bool jmodel_path_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_MODEL_PATH_FIELD, &jmodel_path);
|
||||
if (!jmodel_path_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetModelPath(file_path_t(json_object_get_string(jmodel_path)));
|
||||
|
||||
json_object* jproperties = nullptr;
|
||||
json_bool jproperties_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_PROPERTIES_FIELD, &jproperties);
|
||||
if (jproperties_exists) {
|
||||
properties_t properties;
|
||||
size_t len = json_object_array_length(jproperties);
|
||||
// [{"input_layer" : "1234"}, {"output_layer" : "321"}]
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
json_object* jproperty = json_object_array_get_idx(jproperties, i);
|
||||
json_object_object_foreach(jproperty, key, val) { properties.push_back({key, json_object_get_string(val)}); }
|
||||
}
|
||||
res.SetProperties(properties);
|
||||
}
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error DeepLearning::SerializeFields(json_object* out) const {
|
||||
json_object_object_add(out, DEEP_LEARNING_BACKEND_FIELD, json_object_new_int64(backend_));
|
||||
const std::string model_path_str = model_path_.GetPath();
|
||||
json_object_object_add(out, DEEP_LEARNING_MODEL_PATH_FIELD, json_object_new_string(model_path_str.c_str()));
|
||||
|
||||
json_object* jproperties = json_object_new_array();
|
||||
for (size_t i = 0; i < properties_.size(); ++i) {
|
||||
json_object* jproperty = json_object_new_object();
|
||||
json_object_object_add(jproperty, properties_[i].property.c_str(),
|
||||
json_object_new_string(properties_[i].value.c_str()));
|
||||
json_object_array_add(jproperties, jproperty);
|
||||
}
|
||||
json_object_object_add(out, DEEP_LEARNING_PROPERTIES_FIELD, jproperties);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
||||
68
src/base/machine_learning/deep_learning.h
Normal file
68
src/base/machine_learning/deep_learning.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
#include <fastoml/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
struct BackendProperty {
|
||||
std::string property;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class DeepLearning : public common::serializer::JsonSerializer<DeepLearning> {
|
||||
public:
|
||||
typedef common::file_system::ascii_file_string_path file_path_t;
|
||||
typedef std::vector<BackendProperty> properties_t;
|
||||
|
||||
DeepLearning();
|
||||
DeepLearning(fastoml::SupportedBackends backend,
|
||||
const file_path_t& model_path,
|
||||
const properties_t& prop = properties_t());
|
||||
|
||||
bool Equals(const DeepLearning& learn) const;
|
||||
|
||||
properties_t GetProperties() const;
|
||||
void SetProperties(const properties_t& prop);
|
||||
|
||||
fastoml::SupportedBackends GetBackend() const;
|
||||
void SetBackend(fastoml::SupportedBackends backend);
|
||||
|
||||
file_path_t GetModelPath() const;
|
||||
void SetModelPath(const file_path_t& path);
|
||||
|
||||
static common::Optional<DeepLearning> MakeDeepLearning(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
fastoml::SupportedBackends backend_;
|
||||
file_path_t model_path_;
|
||||
properties_t properties_;
|
||||
};
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
||||
78
src/base/machine_learning/deep_learning_overlay.cpp
Normal file
78
src/base/machine_learning/deep_learning_overlay.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/machine_learning/deep_learning_overlay.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#define DEEP_LEARNING_LABELS_PATH_FIELD "labels_path"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
DeepLearningOverlay::DeepLearningOverlay() : labels_path_() {}
|
||||
|
||||
DeepLearningOverlay::DeepLearningOverlay(const file_path_t& labels_path) : labels_path_(labels_path) {}
|
||||
|
||||
DeepLearningOverlay::file_path_t DeepLearningOverlay::GetLabelsPath() const {
|
||||
return labels_path_;
|
||||
}
|
||||
|
||||
void DeepLearningOverlay::SetLabelsPath(const file_path_t& path) {
|
||||
labels_path_ = path;
|
||||
}
|
||||
|
||||
bool DeepLearningOverlay::Equals(const DeepLearningOverlay& learn) const {
|
||||
return learn.labels_path_ == labels_path_;
|
||||
}
|
||||
|
||||
common::Optional<DeepLearningOverlay> DeepLearningOverlay::MakeDeepLearningOverlay(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<DeepLearningOverlay>();
|
||||
}
|
||||
|
||||
DeepLearningOverlay res;
|
||||
common::Value* paths_field = hash->Find(DEEP_LEARNING_LABELS_PATH_FIELD);
|
||||
std::string paths;
|
||||
if (!paths_field || !paths_field->GetAsBasicString(&paths)) {
|
||||
return common::Optional<DeepLearningOverlay>();
|
||||
}
|
||||
res.SetLabelsPath(file_path_t(paths));
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error DeepLearningOverlay::DoDeSerialize(json_object* serialized) {
|
||||
DeepLearningOverlay res;
|
||||
json_object* jlabels_path = nullptr;
|
||||
json_bool jlabels_path_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_LABELS_PATH_FIELD, &jlabels_path);
|
||||
if (!jlabels_path_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetLabelsPath(file_path_t(json_object_get_string(jlabels_path)));
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error DeepLearningOverlay::SerializeFields(json_object* out) const {
|
||||
const std::string labels_path_str = labels_path_.GetPath();
|
||||
json_object_object_add(out, DEEP_LEARNING_LABELS_PATH_FIELD, json_object_new_string(labels_path_str.c_str()));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
||||
52
src/base/machine_learning/deep_learning_overlay.h
Normal file
52
src/base/machine_learning/deep_learning_overlay.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
#include <fastoml/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
class DeepLearningOverlay : public common::serializer::JsonSerializer<DeepLearningOverlay> {
|
||||
public:
|
||||
typedef common::file_system::ascii_file_string_path file_path_t;
|
||||
|
||||
DeepLearningOverlay();
|
||||
explicit DeepLearningOverlay(const file_path_t& labels_path);
|
||||
|
||||
bool Equals(const DeepLearningOverlay& learn) const;
|
||||
|
||||
file_path_t GetLabelsPath() const;
|
||||
void SetLabelsPath(const file_path_t& path);
|
||||
|
||||
static common::Optional<DeepLearningOverlay> MakeDeepLearningOverlay(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
file_path_t labels_path_;
|
||||
};
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
||||
27
src/base/platform_macros.h
Normal file
27
src/base/platform_macros.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#ifndef WIFEXITED
|
||||
#define WIFEXITED(S) (((S)&0xff) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(S) (((S)&0xff00) >> 8)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
370
src/base/stream_config.cpp
Normal file
370
src/base/stream_config.cpp
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/config_fields.h"
|
||||
#include "base/utils.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
|
||||
#include <common/convert2string.h>
|
||||
#include <common/file_system/file_system.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace {
|
||||
|
||||
bool ConvertFromString(common::ArrayValue* output_urls, fastocloud::output_t* out) {
|
||||
if (!output_urls || !out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fastocloud::output_t output;
|
||||
for (size_t i = 0; i < output_urls->GetSize(); ++i) {
|
||||
common::Value* url = nullptr;
|
||||
common::HashValue* url_hash = nullptr;
|
||||
if (output_urls->Get(i, &url) && url->GetAsHash(&url_hash)) {
|
||||
const auto murl = fastotv::OutputUri::Make(url_hash);
|
||||
if (murl) {
|
||||
output.push_back(*murl);
|
||||
}
|
||||
}
|
||||
}
|
||||
*out = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertFromString(common::ArrayValue* input_urls, fastocloud::input_t* out) {
|
||||
if (!input_urls || !out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fastocloud::input_t input;
|
||||
for (size_t i = 0; i < input_urls->GetSize(); ++i) {
|
||||
common::Value* url = nullptr;
|
||||
common::HashValue* url_hash = nullptr;
|
||||
if (input_urls->Get(i, &url) && url->GetAsHash(&url_hash)) {
|
||||
const auto murl = fastotv::InputUri::Make(url_hash);
|
||||
if (murl) {
|
||||
input.push_back(*murl);
|
||||
}
|
||||
}
|
||||
}
|
||||
*out = input;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
common::Optional<input_t> ReadInput(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
common::Value* input_field = config->Find(INPUT_FIELD);
|
||||
common::ArrayValue* input_hash = nullptr;
|
||||
if (!input_field || !input_field->GetAsList(&input_hash)) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
input_t linput;
|
||||
if (!ConvertFromString(input_hash, &linput)) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
return common::Optional<input_t>(linput);
|
||||
}
|
||||
|
||||
common::Optional<output_t> ReadOutput(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
common::Value* output_field = config->Find(OUTPUT_FIELD);
|
||||
common::ArrayValue* output_hash = nullptr;
|
||||
if (!output_field || !output_field->GetAsList(&output_hash)) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
output_t loutput;
|
||||
if (!ConvertFromString(output_hash, &loutput)) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
return common::Optional<output_t>(loutput);
|
||||
}
|
||||
|
||||
common::Optional<fastotv::stream_id_t> GetSid(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<fastotv::stream_id_t>();
|
||||
}
|
||||
|
||||
common::Value* id_field = config->Find(ID_FIELD);
|
||||
fastotv::stream_id_t lsid;
|
||||
if (id_field && id_field->GetAsBasicString(&lsid)) {
|
||||
return common::Optional<fastotv::stream_id_t>(lsid);
|
||||
}
|
||||
|
||||
return common::Optional<fastotv::stream_id_t>();
|
||||
}
|
||||
|
||||
common::Optional<fastotv::StreamTTL> GetTTL(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<fastotv::StreamTTL>();
|
||||
}
|
||||
|
||||
common::HashValue* ttl_hash = nullptr;
|
||||
common::Value* frame_field = config->Find(AUTO_EXIT_TIME_FIELD);
|
||||
if (frame_field && frame_field->GetAsHash(&ttl_hash)) {
|
||||
return fastotv::StreamTTL::Make(ttl_hash);
|
||||
}
|
||||
|
||||
return common::Optional<fastotv::StreamTTL>();
|
||||
}
|
||||
|
||||
common::ErrnoError MakeStreamInfo(const StreamConfig& config,
|
||||
bool check_folders,
|
||||
StreamInfo* sha,
|
||||
std::string* feedback_dir,
|
||||
std::string* data_dir,
|
||||
common::logging::LOG_LEVEL* logs_level) {
|
||||
if (!sha || !data_dir || !feedback_dir || !logs_level) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
auto sid = GetSid(config);
|
||||
if (!sid) {
|
||||
return common::make_errno_error("Define " ID_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
StreamInfo lsha;
|
||||
lsha.id = *sid;
|
||||
|
||||
int64_t type;
|
||||
common::Value* type_field = config->Find(TYPE_FIELD);
|
||||
if (!type_field || !type_field->GetAsInteger64(&type)) {
|
||||
return common::make_errno_error("Define " TYPE_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.type = static_cast<fastotv::StreamType>(type);
|
||||
|
||||
if (lsha.type == fastotv::PROXY || lsha.type == fastotv::VOD_PROXY) {
|
||||
return common::make_errno_error("Proxy streams not handled for now", EINVAL);
|
||||
}
|
||||
|
||||
std::string lfeedback_dir;
|
||||
common::Value* feedback_field = config->Find(FEEDBACK_DIR_FIELD);
|
||||
if (!feedback_field || !feedback_field->GetAsBasicString(&lfeedback_dir)) {
|
||||
return common::make_errno_error("Define " FEEDBACK_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
std::string ldata_dir;
|
||||
common::Value* data_field = config->Find(DATA_DIR_FIELD);
|
||||
if (!data_field || !data_field->GetAsBasicString(&ldata_dir)) {
|
||||
return common::make_errno_error("Define " DATA_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
int64_t llogs_level;
|
||||
common::Value* log_level_field = config->Find(LOG_LEVEL_FIELD);
|
||||
if (!log_level_field || !log_level_field->GetAsInteger64(&llogs_level)) {
|
||||
llogs_level = common::logging::LOG_LEVEL_DEBUG;
|
||||
}
|
||||
|
||||
common::ErrnoError errn = CreateAndCheckDir(lfeedback_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
errn = CreateAndCheckDir(ldata_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
const auto input = ReadInput(config);
|
||||
if (!input) {
|
||||
return common::make_errno_error("Define " INPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.input = *input;
|
||||
|
||||
if (check_folders) {
|
||||
bool is_timeshift_rec = type == fastotv::TIMESHIFT_RECORDER; // no outputs
|
||||
if (is_timeshift_rec || type == fastotv::CATCHUP) {
|
||||
std::string timeshift_dir;
|
||||
common::Value* timeshift_dir_field = config->Find(TIMESHIFT_DIR_FIELD);
|
||||
if (!timeshift_dir_field || !timeshift_dir_field->GetAsBasicString(×hift_dir)) {
|
||||
return common::make_errno_error("Define " TIMESHIFT_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
errn = CreateAndCheckDir(timeshift_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_timeshift_rec) {
|
||||
const auto output = ReadOutput(config);
|
||||
if (!output) {
|
||||
return common::make_errno_error("Define " OUTPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
for (const auto& out_uri : *output) {
|
||||
auto ouri = out_uri.GetUrl();
|
||||
if (ouri.SchemeIsHTTPOrHTTPS()) {
|
||||
if (out_uri.IsHls()) {
|
||||
const auto http_root = out_uri.GetHttpRoot();
|
||||
if (!http_root) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string http_root_str = http_root->GetPath();
|
||||
common::ErrnoError errn = CreateAndCheckDir(http_root_str);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
} else if (ouri.SchemeIsFile()) {
|
||||
const auto file_path = common::file_system::ascii_file_string_path(ouri.path());
|
||||
if (!file_path.IsValid()) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string file_root_str = file_path.GetDirectory();
|
||||
common::ErrnoError errn = CreateAndCheckDir(file_root_str);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
lsha.output.push_back(out_uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*logs_level = static_cast<common::logging::LOG_LEVEL>(llogs_level);
|
||||
*feedback_dir = lfeedback_dir;
|
||||
*data_dir = ldata_dir;
|
||||
*sha = lsha;
|
||||
return common::ErrnoError();
|
||||
}
|
||||
|
||||
common::ErrnoError CleanStream(const StreamConfig& config) {
|
||||
auto sid = GetSid(config);
|
||||
if (!sid) {
|
||||
return common::make_errno_error("Define " ID_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
StreamInfo lsha;
|
||||
lsha.id = *sid;
|
||||
|
||||
int64_t type;
|
||||
common::Value* type_field = config->Find(TYPE_FIELD);
|
||||
if (!type_field || !type_field->GetAsInteger64(&type)) {
|
||||
return common::make_errno_error("Define " TYPE_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.type = static_cast<fastotv::StreamType>(type);
|
||||
|
||||
if (lsha.type == fastotv::PROXY || lsha.type == fastotv::VOD_PROXY) {
|
||||
return common::make_errno_error("Proxy streams not handled for now", EINVAL);
|
||||
}
|
||||
|
||||
std::string lfeedback_dir;
|
||||
common::Value* feedback_field = config->Find(FEEDBACK_DIR_FIELD);
|
||||
if (!feedback_field || !feedback_field->GetAsBasicString(&lfeedback_dir)) {
|
||||
return common::make_errno_error("Define " FEEDBACK_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
std::string ldata_dir;
|
||||
common::Value* data_field = config->Find(DATA_DIR_FIELD);
|
||||
if (!data_field || !data_field->GetAsBasicString(&ldata_dir)) {
|
||||
return common::make_errno_error("Define " DATA_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
int64_t llogs_level;
|
||||
common::Value* log_level_field = config->Find(LOG_LEVEL_FIELD);
|
||||
if (!log_level_field || !log_level_field->GetAsInteger64(&llogs_level)) {
|
||||
llogs_level = common::logging::LOG_LEVEL_DEBUG;
|
||||
}
|
||||
|
||||
common::ErrnoError errn = common::file_system::remove_directory(lfeedback_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
errn = common::file_system::remove_directory(ldata_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
const auto input = ReadInput(config);
|
||||
if (!input) {
|
||||
return common::make_errno_error("Define " INPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.input = *input;
|
||||
|
||||
bool is_timeshift_rec = type == fastotv::TIMESHIFT_RECORDER; // no outputs
|
||||
if (is_timeshift_rec || type == fastotv::CATCHUP) {
|
||||
std::string timeshift_dir;
|
||||
common::Value* timeshift_dir_field = config->Find(TIMESHIFT_DIR_FIELD);
|
||||
if (!timeshift_dir_field || !timeshift_dir_field->GetAsBasicString(×hift_dir)) {
|
||||
return common::make_errno_error("Define " TIMESHIFT_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
errn = common::file_system::remove_directory(timeshift_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_timeshift_rec) {
|
||||
const auto output = ReadOutput(config);
|
||||
if (!output) {
|
||||
return common::make_errno_error("Define " OUTPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
for (const auto& out_uri : *output) {
|
||||
auto ouri = out_uri.GetUrl();
|
||||
if (ouri.SchemeIsHTTPOrHTTPS()) {
|
||||
if (out_uri.IsHls()) {
|
||||
const auto http_root = out_uri.GetHttpRoot();
|
||||
if (!http_root) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string http_root_str = http_root->GetPath();
|
||||
common::ErrnoError errn = common::file_system::remove_directory(http_root_str, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
} else if (ouri.SchemeIsFile()) {
|
||||
const auto file_path = common::file_system::ascii_file_string_path(ouri.path());
|
||||
if (!file_path.IsValid()) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string file_root_str = file_path.GetDirectory();
|
||||
common::ErrnoError errn = common::file_system::remove_directory(file_root_str, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
lsha.output.push_back(out_uri);
|
||||
}
|
||||
}
|
||||
|
||||
return common::ErrnoError();
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
||||
42
src/base/stream_config.h
Normal file
42
src/base/stream_config.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
#include <fastotv/types/stream_ttl.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef std::shared_ptr<common::HashValue> StreamConfig;
|
||||
|
||||
common::Optional<fastotv::stream_id_t> GetSid(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<fastotv::StreamTTL> GetTTL(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<input_t> ReadInput(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<output_t> ReadOutput(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError MakeStreamInfo(const StreamConfig& config,
|
||||
bool check_folders,
|
||||
StreamInfo* sha,
|
||||
std::string* feedback_dir,
|
||||
std::string* data_dir,
|
||||
common::logging::LOG_LEVEL* logs_level) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError CleanStream(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
|
||||
} // namespace fastocloud
|
||||
188
src/base/stream_config_parse.cpp
Normal file
188
src/base/stream_config_parse.cpp
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_config_parse.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
|
||||
namespace {
|
||||
common::Value* MakeValueFromJson(json_object* obj) {
|
||||
json_type obj_type = json_object_get_type(obj);
|
||||
if (obj_type == json_type_null) {
|
||||
return common::Value::CreateNullValue();
|
||||
} else if (obj_type == json_type_boolean) {
|
||||
return common::Value::CreateBooleanValue(json_object_get_boolean(obj));
|
||||
} else if (obj_type == json_type_double) {
|
||||
return common::Value::CreateDoubleValue(json_object_get_double(obj));
|
||||
} else if (obj_type == json_type_int) {
|
||||
int64_t jint = json_object_get_int64(obj);
|
||||
return common::Value::CreateInteger64Value(jint);
|
||||
} else if (obj_type == json_type_string) {
|
||||
return common::Value::CreateStringValueFromBasicString(json_object_get_string(obj));
|
||||
} else if (obj_type == json_type_object) {
|
||||
common::HashValue* result = common::Value::CreateHashValue();
|
||||
json_object_object_foreach(obj, key, val) {
|
||||
json_type val_type = json_object_get_type(val);
|
||||
common::Value* value = nullptr;
|
||||
switch (val_type) {
|
||||
case json_type_null:
|
||||
value = common::Value::CreateNullValue();
|
||||
break;
|
||||
case json_type_boolean:
|
||||
value = common::Value::CreateBooleanValue(json_object_get_boolean(val));
|
||||
break;
|
||||
case json_type_double:
|
||||
value = common::Value::CreateDoubleValue(json_object_get_double(val));
|
||||
break;
|
||||
case json_type_int:
|
||||
value = common::Value::CreateInteger64Value(json_object_get_int64(val));
|
||||
break;
|
||||
case json_type_string:
|
||||
value = common::Value::CreateStringValueFromBasicString(json_object_get_string(val));
|
||||
break;
|
||||
case json_type_object:
|
||||
value = MakeValueFromJson(val);
|
||||
break;
|
||||
case json_type_array:
|
||||
common::ArrayValue* arr = common::Value::CreateArrayValue();
|
||||
for (size_t i = 0; i < json_object_array_length(val); i++) {
|
||||
json_object* item = json_object_array_get_idx(val, i);
|
||||
arr->Append(MakeValueFromJson(item));
|
||||
}
|
||||
value = arr;
|
||||
break;
|
||||
}
|
||||
|
||||
result->Insert(key, value);
|
||||
}
|
||||
return result;
|
||||
} else if (obj_type == json_type_array) {
|
||||
common::ArrayValue* arr = common::Value::CreateArrayValue();
|
||||
for (size_t i = 0; i < json_object_array_length(obj); i++) {
|
||||
json_object* item = json_object_array_get_idx(obj, i);
|
||||
arr->Append(MakeValueFromJson(item));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
DNOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
json_object* MakeJson(const common::Value* value) {
|
||||
const common::Value::Type type = value->GetType();
|
||||
if (type == common::Value::TYPE_NULL) {
|
||||
return nullptr;
|
||||
} else if (type == common::Value::TYPE_BOOLEAN) {
|
||||
bool rbool;
|
||||
if (value->GetAsBoolean(&rbool)) {
|
||||
return json_object_new_boolean(rbool);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_DOUBLE) {
|
||||
double rdouble;
|
||||
if (value->GetAsDouble(&rdouble)) {
|
||||
return json_object_new_double(rdouble);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_INTEGER64) {
|
||||
int64_t rint;
|
||||
if (value->GetAsInteger64(&rint)) {
|
||||
return json_object_new_int64(rint);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_STRING) {
|
||||
common::Value::string_t rstring;
|
||||
if (value->GetAsString(&rstring)) {
|
||||
const std::string r = rstring.as_string();
|
||||
return json_object_new_string(r.c_str());
|
||||
}
|
||||
} else if (type == common::Value::TYPE_HASH) {
|
||||
json_object* result = json_object_new_object();
|
||||
const common::HashValue* hash = nullptr;
|
||||
if (value->GetAsHash(&hash)) {
|
||||
for (auto it = hash->begin(); it != hash->end(); ++it) {
|
||||
const common::Value::string_t key = it->first;
|
||||
const std::string key_str = key.as_string();
|
||||
const common::Value* value = it->second;
|
||||
ignore_result(common::serializer::json_set_object(result, key_str.c_str(), MakeJson(value)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else if (type == common::Value::TYPE_ARRAY) {
|
||||
json_object* arr = json_object_new_array();
|
||||
const common::ArrayValue* arr_value = nullptr;
|
||||
if (value->GetAsList(&arr_value)) {
|
||||
for (size_t i = 0; i < arr_value->GetSize(); ++i) {
|
||||
const common::Value* val = nullptr;
|
||||
if (arr_value->Get(i, &val)) {
|
||||
json_object* obj = MakeJson(val);
|
||||
json_object_array_add(arr, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
DNOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(const std::string& json) {
|
||||
if (json.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
json_object* obj = json_tokener_parse(json.c_str());
|
||||
if (!obj) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<common::HashValue> res = MakeConfigFromJson(obj);
|
||||
json_object_put(obj);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(json_object* obj) {
|
||||
json_type obj_type = json_object_get_type(obj);
|
||||
if (obj_type == json_type_object) {
|
||||
return std::unique_ptr<common::HashValue>(static_cast<common::HashValue*>(MakeValueFromJson(obj)));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MakeJsonFromConfig(std::shared_ptr<common::HashValue> config, std::string* json) {
|
||||
if (!config || !json) {
|
||||
return false;
|
||||
}
|
||||
|
||||
json_object* jobj = MakeJson(config.get());
|
||||
if (!jobj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*json = json_object_get_string(jobj);
|
||||
json_object_put(jobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
||||
32
src/base/stream_config_parse.h
Normal file
32
src/base/stream_config_parse.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/value.h>
|
||||
|
||||
#include <json-c/json_types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(const std::string& json);
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(json_object* obj);
|
||||
|
||||
bool MakeJsonFromConfig(std::shared_ptr<common::HashValue> config, std::string* json);
|
||||
|
||||
} // namespace fastocloud
|
||||
17
src/base/stream_info.cpp
Normal file
17
src/base/stream_info.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
namespace fastocloud {} // namespace fastocloud
|
||||
34
src/base/stream_info.h
Normal file
34
src/base/stream_info.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
#include "base/types.h"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef std::vector<ChannelStats> input_channels_info_t;
|
||||
typedef std::vector<ChannelStats> output_channels_info_t;
|
||||
|
||||
struct StreamInfo {
|
||||
fastotv::stream_id_t id;
|
||||
fastotv::StreamType type;
|
||||
input_t input;
|
||||
output_t output;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
||||
98
src/base/stream_struct.cpp
Normal file
98
src/base/stream_struct.cpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_struct.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/time.h>
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
|
||||
namespace common {
|
||||
|
||||
std::string ConvertToString(fastocloud::StreamStatus st) {
|
||||
static const std::string kStreamStatuses[] = {
|
||||
"New", "Inited", "Started", "Ready", "Playing", "Frozen", "Waiting",
|
||||
};
|
||||
|
||||
return kStreamStatuses[st];
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
namespace {
|
||||
output_channels_info_t make_outputs(const std::vector<fastotv::OutputUri>& output) {
|
||||
output_channels_info_t res;
|
||||
for (auto out : output) {
|
||||
res.push_back(ChannelStats(out.GetID()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
input_channels_info_t make_inputs(const std::vector<fastotv::InputUri>& input) {
|
||||
input_channels_info_t res;
|
||||
for (auto in : input) {
|
||||
res.push_back(ChannelStats(in.GetID()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
StreamStruct::StreamStruct() : StreamStruct(StreamInfo()) {}
|
||||
|
||||
StreamStruct::StreamStruct(const StreamInfo& sha) : StreamStruct(sha, common::time::current_utc_mstime(), 0, 0) {}
|
||||
|
||||
StreamStruct::StreamStruct(const StreamInfo& sha,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest)
|
||||
: StreamStruct(sha.id, sha.type, NEW, make_inputs(sha.input), make_outputs(sha.output), start_time, lst, rest) {}
|
||||
|
||||
StreamStruct::StreamStruct(fastotv::stream_id_t sid,
|
||||
fastotv::StreamType type,
|
||||
StreamStatus status,
|
||||
input_channels_info_t input,
|
||||
output_channels_info_t output,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest)
|
||||
: id(sid),
|
||||
type(type),
|
||||
start_time(start_time),
|
||||
loop_start_time(lst),
|
||||
idle_time(0),
|
||||
restarts(rest),
|
||||
status(status),
|
||||
input(input),
|
||||
output(output) {}
|
||||
|
||||
bool StreamStruct::IsValid() const {
|
||||
return !id.empty();
|
||||
}
|
||||
|
||||
StreamStruct::~StreamStruct() {}
|
||||
|
||||
void StreamStruct::ResetDataWait() {
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
input[i].UpdateCheckPoint();
|
||||
}
|
||||
for (size_t i = 0; i < output.size(); ++i) {
|
||||
output[i].UpdateCheckPoint();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
||||
62
src/base/stream_struct.h
Normal file
62
src/base/stream_struct.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
enum StreamStatus { NEW = 0, INIT = 1, STARTED = 2, READY = 3, PLAYING = 4, FROZEN = 5, WAITING = 6 };
|
||||
|
||||
struct StreamStruct {
|
||||
StreamStruct();
|
||||
explicit StreamStruct(const StreamInfo& sha);
|
||||
StreamStruct(const StreamInfo& sha, fastotv::timestamp_t start_time, fastotv::timestamp_t lst, size_t rest);
|
||||
StreamStruct(fastotv::stream_id_t sid,
|
||||
fastotv::StreamType type,
|
||||
StreamStatus status,
|
||||
input_channels_info_t input,
|
||||
output_channels_info_t output,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
~StreamStruct();
|
||||
|
||||
void ResetDataWait();
|
||||
|
||||
fastotv::stream_id_t id;
|
||||
fastotv::StreamType type;
|
||||
|
||||
fastotv::timestamp_t start_time;
|
||||
fastotv::timestamp_t loop_start_time;
|
||||
fastotv::timestamp_t idle_time;
|
||||
size_t restarts;
|
||||
StreamStatus status;
|
||||
|
||||
input_channels_info_t input;
|
||||
output_channels_info_t output;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
||||
|
||||
namespace common {
|
||||
std::string ConvertToString(fastocloud::StreamStatus st);
|
||||
}
|
||||
17
src/base/types.cpp
Normal file
17
src/base/types.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/types.h"
|
||||
|
||||
namespace fastocloud {} // namespace fastocloud
|
||||
40
src/base/types.h
Normal file
40
src/base/types.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/optional.h>
|
||||
|
||||
#include <fastotv/types/input_uri.h>
|
||||
#include <fastotv/types/output_uri.h>
|
||||
|
||||
#define TS_EXTENSION "ts"
|
||||
#define M3U8_EXTENSION "m3u8"
|
||||
#define DASH_EXTENSION "mpd"
|
||||
#define M3U8_CHUNK_MARKER "#EXTINF"
|
||||
#define CHUNK_EXT "." TS_EXTENSION
|
||||
|
||||
#define DUMP_FILE_NAME "dump.html"
|
||||
#define CONFIG_FILE_NAME "config.json"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef common::Optional<double> volume_t;
|
||||
typedef double alpha_t;
|
||||
typedef common::Optional<int> bit_rate_t;
|
||||
|
||||
typedef std::vector<fastotv::InputUri> input_t;
|
||||
typedef std::vector<fastotv::OutputUri> output_t;
|
||||
|
||||
} // namespace fastocloud
|
||||
159
src/base/utils.cpp
Normal file
159
src/base/utils.cpp
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/utils.h"
|
||||
|
||||
#include <common/file_system/file_system.h>
|
||||
#include <common/file_system/string_path_utils.h>
|
||||
#include <common/sprintf.h>
|
||||
#include <common/uri/gurl.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
common::Optional<common::net::HostAndPort> GetHostAndPortFromGurl(const common::uri::GURL& url) {
|
||||
if (!url.is_valid()) {
|
||||
return common::Optional<common::net::HostAndPort>();
|
||||
}
|
||||
|
||||
return common::net::HostAndPort(url.host(), url.IntPort());
|
||||
}
|
||||
|
||||
common::ErrnoError CreateAndCheckDir(const std::string& directory_path) {
|
||||
if (!common::file_system::is_directory_exist(directory_path)) {
|
||||
common::ErrnoError errn = common::file_system::create_directory(directory_path, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
return common::file_system::node_access(directory_path);
|
||||
}
|
||||
|
||||
void RemoveFilesByExtension(const common::file_system::ascii_directory_string_path& dir, const char* ext) {
|
||||
if (!dir.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string path = dir.GetPath();
|
||||
|
||||
DIR* dirp = opendir(path.c_str());
|
||||
if (!dirp) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG() << "Started clean up folder: " << path;
|
||||
struct dirent* dent;
|
||||
while ((dent = readdir(dirp)) != nullptr) {
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* pch = strstr(dent->d_name, ext);
|
||||
if (pch) {
|
||||
std::string file_path = common::MemSPrintf("%s%s", path, dent->d_name);
|
||||
time_t mtime;
|
||||
common::ErrnoError err = common::file_system::get_file_time_last_modification(file_path, &mtime);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't get timestamp file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
err = common::file_system::remove_file(file_path);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't remove file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
DEBUG_LOG() << "File path: " << file_path << " removed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
DEBUG_LOG() << "Finished clean up folder: " << path;
|
||||
}
|
||||
|
||||
void RemoveOldFilesByTime(const common::file_system::ascii_directory_string_path& dir,
|
||||
common::utctime_t max_life_secs,
|
||||
const char* pattern,
|
||||
bool recursive) {
|
||||
if (!dir.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string path = dir.GetPath();
|
||||
DIR* dirp = opendir(path.c_str());
|
||||
if (!dirp) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG() << "Started clean up folder: " << path;
|
||||
struct dirent* dent;
|
||||
while ((dent = readdir(dirp)) != nullptr) {
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef OS_WIN
|
||||
const std::string dir_str = common::file_system::make_path(path, dent->d_name);
|
||||
common::tribool is_dir_tr = common::file_system::is_directory(dir_str);
|
||||
if (is_dir_tr == common::INDETERMINATE) {
|
||||
continue;
|
||||
}
|
||||
bool is_dir = is_dir_tr == common::SUCCESS;
|
||||
#else
|
||||
bool is_dir = dent->d_type == DT_DIR;
|
||||
#endif
|
||||
|
||||
if (!is_dir) {
|
||||
if (common::MatchPattern(dent->d_name, pattern)) {
|
||||
std::string file_path = common::MemSPrintf("%s%s", path, dent->d_name);
|
||||
common::utctime_t mtime;
|
||||
common::ErrnoError err = common::file_system::get_file_time_last_modification(file_path, &mtime);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't get timestamp file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
if (mtime < max_life_secs) {
|
||||
err = common::file_system::remove_file(file_path);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't remove file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
DEBUG_LOG() << "File path: " << file_path << " removed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recursive) {
|
||||
auto folder = dir.MakeDirectoryStringPath(dent->d_name);
|
||||
if (folder) {
|
||||
RemoveOldFilesByTime(*folder, max_life_secs, pattern, recursive);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
DEBUG_LOG() << "Finished clean up folder: " << path;
|
||||
}
|
||||
|
||||
common::Optional<std::string> GetAudioMasterUrlFromQuery(const std::string& query_str) {
|
||||
common::uri::Component key, value;
|
||||
common::uri::Component query(0, query_str.length());
|
||||
while (common::uri::ExtractQueryKeyValue(query_str.c_str(), &query, &key, &value)) {
|
||||
std::string key_string(query_str.substr(key.begin, key.len));
|
||||
std::string param_text(query_str.substr(value.begin, value.len));
|
||||
if (common::EqualsASCII(key_string, "audio", false)) {
|
||||
return common::Optional<std::string>(param_text);
|
||||
}
|
||||
}
|
||||
|
||||
return common::Optional<std::string>();
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
||||
37
src/base/utils.h
Normal file
37
src/base/utils.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/error.h>
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/net/types.h>
|
||||
#include <common/uri/gurl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
common::Optional<common::net::HostAndPort> GetHostAndPortFromGurl(const common::uri::GURL& url);
|
||||
|
||||
common::ErrnoError CreateAndCheckDir(const std::string& directory_path) WARN_UNUSED_RESULT;
|
||||
void RemoveOldFilesByTime(const common::file_system::ascii_directory_string_path& dir,
|
||||
common::utctime_t max_life_secs,
|
||||
const char* pattern,
|
||||
bool recursive = false);
|
||||
void RemoveFilesByExtension(const common::file_system::ascii_directory_string_path& dir, const char* ext);
|
||||
|
||||
common::Optional<std::string> GetAudioMasterUrlFromQuery(const std::string& query);
|
||||
|
||||
} // namespace fastocloud
|
||||
Loading…
Add table
Add a link
Reference in a new issue