tdlight/td/telegram/VideosManager.hpp

98 lines
3.0 KiB
C++
Raw Normal View History

//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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)
//
#pragma once
#include "td/telegram/VideosManager.h"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/Photo.hpp"
#include "td/telegram/Version.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void VideosManager::store_video(FileId file_id, StorerT &storer) const {
2022-08-03 22:23:32 +02:00
const Video *video = get_video(file_id);
CHECK(video != nullptr);
bool has_animated_thumbnail = video->animated_thumbnail.file_id.is_valid();
2023-05-19 13:57:57 +02:00
bool has_preload_prefix_size = video->preload_prefix_size != 0;
2023-06-05 13:33:00 +02:00
bool has_precise_duration = video->precise_duration != 0 && video->precise_duration != video->duration;
BEGIN_STORE_FLAGS();
STORE_FLAG(video->has_stickers);
STORE_FLAG(video->supports_streaming);
STORE_FLAG(has_animated_thumbnail);
2023-05-19 13:57:57 +02:00
STORE_FLAG(has_preload_prefix_size);
2023-06-05 13:33:00 +02:00
STORE_FLAG(has_precise_duration);
END_STORE_FLAGS();
store(video->file_name, storer);
store(video->mime_type, storer);
store(video->duration, storer);
store(video->dimensions, storer);
store(video->minithumbnail, storer);
store(video->thumbnail, storer);
store(file_id, storer);
if (video->has_stickers) {
store(video->sticker_file_ids, storer);
}
if (has_animated_thumbnail) {
store(video->animated_thumbnail, storer);
}
2023-05-19 13:57:57 +02:00
if (has_preload_prefix_size) {
store(video->preload_prefix_size, storer);
}
2023-06-05 13:33:00 +02:00
if (has_precise_duration) {
store(video->precise_duration, storer);
}
}
template <class ParserT>
FileId VideosManager::parse_video(ParserT &parser) {
auto video = make_unique<Video>();
bool has_animated_thumbnail;
2023-05-19 13:57:57 +02:00
bool has_preload_prefix_size;
2023-06-05 13:33:00 +02:00
bool has_precise_duration;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(video->has_stickers);
PARSE_FLAG(video->supports_streaming);
PARSE_FLAG(has_animated_thumbnail);
2023-05-19 13:57:57 +02:00
PARSE_FLAG(has_preload_prefix_size);
2023-06-05 13:33:00 +02:00
PARSE_FLAG(has_precise_duration);
END_PARSE_FLAGS();
parse(video->file_name, parser);
parse(video->mime_type, parser);
parse(video->duration, parser);
parse(video->dimensions, parser);
if (parser.version() >= static_cast<int32>(Version::SupportMinithumbnails)) {
parse(video->minithumbnail, parser);
}
parse(video->thumbnail, parser);
parse(video->file_id, parser);
if (video->has_stickers) {
parse(video->sticker_file_ids, parser);
}
if (has_animated_thumbnail) {
parse(video->animated_thumbnail, parser);
}
2023-05-19 13:57:57 +02:00
if (has_preload_prefix_size) {
parse(video->preload_prefix_size, parser);
}
2023-06-05 13:33:00 +02:00
if (has_precise_duration) {
parse(video->precise_duration, parser);
} else {
video->precise_duration = video->duration;
}
if (parser.get_error() != nullptr || !video->file_id.is_valid()) {
return FileId();
}
return on_get_video(std::move(video), false);
}
} // namespace td