// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/telegram/VideosManager.h" #include "td/telegram/AuthManager.h" #include "td/telegram/Document.h" #include "td/telegram/DocumentsManager.h" #include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/Global.h" #include "td/telegram/secret_api.h" #include "td/telegram/Td.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include namespace td { VideosManager::VideosManager(Td *td) : td_(td) { } VideosManager::~VideosManager() { Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), videos_); } int32 VideosManager::get_video_duration(FileId file_id) const { auto video = get_video(file_id); CHECK(video != nullptr); return video->duration; } const string &VideosManager::get_video_mime_type(FileId file_id) const { auto video = get_video(file_id); CHECK(video != nullptr); return video->mime_type; } td_api::object_ptr VideosManager::get_video_object(FileId file_id, const vector &alternative_file_ids) const { if (!file_id.is_valid()) { return nullptr; } auto video = get_video(file_id); CHECK(video != nullptr); auto thumbnail = get_thumbnail_object(td_->file_manager_.get(), video->thumbnail, video->animated_thumbnail); auto duration = video->duration; if ((duration == 0 || thumbnail == nullptr) && !alternative_file_ids.empty()) { int32 common_duration = 0; for (auto alternative_file_id : alternative_file_ids) { auto alternative_video = get_video(alternative_file_id); CHECK(alternative_video != nullptr); if (alternative_video->duration > 0) { if (common_duration == 0) { common_duration = alternative_video->duration; } else if (common_duration != alternative_video->duration) { common_duration = -1; } } if (thumbnail == nullptr) { thumbnail = get_thumbnail_object(td_->file_manager_.get(), alternative_video->thumbnail, alternative_video->animated_thumbnail); } } if (duration == 0 && common_duration > 0) { duration = common_duration; } } return td_api::make_object(duration, video->dimensions.width, video->dimensions.height, video->file_name, video->mime_type, video->has_stickers, video->supports_streaming, get_minithumbnail_object(video->minithumbnail), std::move(thumbnail), td_->file_manager_->get_file_object(file_id)); } td_api::object_ptr VideosManager::get_story_video_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } auto video = get_video(file_id); CHECK(video != nullptr); auto thumbnail = get_thumbnail_object(td_->file_manager_.get(), video->thumbnail, video->animated_thumbnail); return td_api::make_object( video->precise_duration, video->dimensions.width, video->dimensions.height, video->has_stickers, video->is_animation, get_minithumbnail_object(video->minithumbnail), std::move(thumbnail), video->preload_prefix_size, video->start_ts, td_->file_manager_->get_file_object(file_id)); } td_api::object_ptr VideosManager::get_alternative_video_object( FileId file_id, const vector &hls_file_ids) const { auto video = get_video(file_id); CHECK(video != nullptr); auto file_view = td_->file_manager_->get_file_view(file_id); const auto *full_remote_location = file_view.get_full_remote_location(); CHECK(full_remote_location != nullptr); CHECK(full_remote_location->is_document()); int64 document_id = full_remote_location->get_id(); auto name = PSTRING() << "mtproto:" << document_id; for (const auto &hls_file_id : hls_file_ids) { if (td_->documents_manager_->get_document_file_name(hls_file_id) == name) { return td_api::make_object( document_id, video->dimensions.width, video->dimensions.height, video->codec, td_->file_manager_->get_file_object(hls_file_id), td_->file_manager_->get_file_object(file_id)); } } return nullptr; } FileId VideosManager::on_get_video(unique_ptr