1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/telegram/files/FileId.h"
10 #include "td/telegram/Photo.h"
11 #include "td/telegram/SecretInputMedia.h"
12 #include "td/telegram/td_api.h"
13 #include "td/telegram/telegram_api.h"
14 
15 #include "td/utils/buffer.h"
16 #include "td/utils/common.h"
17 
18 #include <unordered_map>
19 
20 namespace td {
21 
22 class Td;
23 
24 class VideosManager {
25  public:
26   explicit VideosManager(Td *td);
27 
28   int32 get_video_duration(FileId file_id) const;
29 
30   tl_object_ptr<td_api::video> get_video_object(FileId file_id) const;
31 
32   void create_video(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail,
33                     bool has_stickers, vector<FileId> &&sticker_file_ids, string file_name, string mime_type,
34                     int32 duration, Dimensions dimensions, bool supports_streaming, bool replace);
35 
36   tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
37                                                           tl_object_ptr<telegram_api::InputFile> input_file,
38                                                           tl_object_ptr<telegram_api::InputFile> input_thumbnail,
39                                                           int32 ttl) const;
40 
41   SecretInputMedia get_secret_input_media(FileId video_file_id,
42                                           tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
43                                           const string &caption, BufferSlice thumbnail) const;
44 
45   FileId get_video_thumbnail_file_id(FileId file_id) const;
46 
47   FileId get_video_animated_thumbnail_file_id(FileId file_id) const;
48 
49   void delete_video_thumbnail(FileId file_id);
50 
51   FileId dup_video(FileId new_id, FileId old_id);
52 
53   void merge_videos(FileId new_id, FileId old_id, bool can_delete_old);
54 
55   template <class StorerT>
56   void store_video(FileId file_id, StorerT &storer) const;
57 
58   template <class ParserT>
59   FileId parse_video(ParserT &parser);
60 
61   string get_video_search_text(FileId file_id) const;
62 
63  private:
64   class Video {
65    public:
66     string file_name;
67     string mime_type;
68     int32 duration = 0;
69     Dimensions dimensions;
70     string minithumbnail;
71     PhotoSize thumbnail;
72     AnimationSize animated_thumbnail;
73 
74     bool supports_streaming = false;
75 
76     bool has_stickers = false;
77     vector<FileId> sticker_file_ids;
78 
79     FileId file_id;
80   };
81 
82   const Video *get_video(FileId file_id) const;
83 
84   FileId on_get_video(unique_ptr<Video> new_video, bool replace);
85 
86   Td *td_;
87   std::unordered_map<FileId, unique_ptr<Video>, FileIdHash> videos_;
88 };
89 
90 }  // namespace td
91