calls_group_call.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "base/weak_ptr.h"
  9. #include "base/timer.h"
  10. #include "base/bytes.h"
  11. #include "mtproto/sender.h"
  12. #include "mtproto/mtproto_auth_key.h"
  13. #include "webrtc/webrtc_device_common.h"
  14. #include "webrtc/webrtc_device_resolver.h"
  15. class History;
  16. namespace tgcalls {
  17. class GroupInstanceCustomImpl;
  18. struct GroupLevelsUpdate;
  19. struct GroupNetworkState;
  20. struct GroupParticipantDescription;
  21. class VideoCaptureInterface;
  22. } // namespace tgcalls
  23. namespace base {
  24. class GlobalShortcutManager;
  25. class GlobalShortcutValue;
  26. } // namespace base
  27. namespace Webrtc {
  28. class MediaDevices;
  29. class VideoTrack;
  30. enum class VideoState;
  31. } // namespace Webrtc
  32. namespace Data {
  33. struct LastSpokeTimes;
  34. struct GroupCallParticipant;
  35. class GroupCall;
  36. } // namespace Data
  37. namespace Calls {
  38. namespace Group {
  39. struct MuteRequest;
  40. struct VolumeRequest;
  41. struct ParticipantState;
  42. struct JoinInfo;
  43. struct RejoinEvent;
  44. struct RtmpInfo;
  45. enum class VideoQuality;
  46. enum class Error;
  47. } // namespace Group
  48. enum class MuteState {
  49. Active,
  50. PushToTalk,
  51. Muted,
  52. ForceMuted,
  53. RaisedHand,
  54. };
  55. [[nodiscard]] inline auto MapPushToTalkToActive() {
  56. return rpl::map([=](MuteState state) {
  57. return (state == MuteState::PushToTalk) ? MuteState::Active : state;
  58. });
  59. }
  60. [[nodiscard]] bool IsGroupCallAdmin(
  61. not_null<PeerData*> peer,
  62. not_null<PeerData*> participantPeer);
  63. struct LevelUpdate {
  64. uint32 ssrc = 0;
  65. float value = 0.;
  66. bool voice = false;
  67. bool me = false;
  68. };
  69. enum class VideoEndpointType {
  70. Camera,
  71. Screen,
  72. };
  73. struct VideoEndpoint {
  74. VideoEndpoint() = default;
  75. VideoEndpoint(
  76. VideoEndpointType type,
  77. not_null<PeerData*> peer,
  78. std::string id)
  79. : type(type)
  80. , peer(peer)
  81. , id(std::move(id)) {
  82. }
  83. VideoEndpointType type = VideoEndpointType::Camera;
  84. PeerData *peer = nullptr;
  85. std::string id;
  86. [[nodiscard]] bool rtmp() const noexcept;
  87. [[nodiscard]] bool empty() const noexcept {
  88. Expects(id.empty() || peer != nullptr);
  89. return id.empty();
  90. }
  91. [[nodiscard]] explicit operator bool() const noexcept {
  92. return !empty();
  93. }
  94. };
  95. inline bool operator==(
  96. const VideoEndpoint &a,
  97. const VideoEndpoint &b) noexcept {
  98. return (a.id == b.id);
  99. }
  100. inline bool operator!=(
  101. const VideoEndpoint &a,
  102. const VideoEndpoint &b) noexcept {
  103. return !(a == b);
  104. }
  105. inline bool operator<(
  106. const VideoEndpoint &a,
  107. const VideoEndpoint &b) noexcept {
  108. return (a.peer < b.peer)
  109. || (a.peer == b.peer && a.id < b.id);
  110. }
  111. inline bool operator>(
  112. const VideoEndpoint &a,
  113. const VideoEndpoint &b) noexcept {
  114. return (b < a);
  115. }
  116. inline bool operator<=(
  117. const VideoEndpoint &a,
  118. const VideoEndpoint &b) noexcept {
  119. return !(b < a);
  120. }
  121. inline bool operator>=(
  122. const VideoEndpoint &a,
  123. const VideoEndpoint &b) noexcept {
  124. return !(a < b);
  125. }
  126. struct VideoStateToggle {
  127. VideoEndpoint endpoint;
  128. bool value = false;
  129. };
  130. struct VideoQualityRequest {
  131. VideoEndpoint endpoint;
  132. Group::VideoQuality quality = Group::VideoQuality();
  133. };
  134. struct ParticipantVideoParams;
  135. [[nodiscard]] std::shared_ptr<ParticipantVideoParams> ParseVideoParams(
  136. const tl::conditional<MTPGroupCallParticipantVideo> &camera,
  137. const tl::conditional<MTPGroupCallParticipantVideo> &screen,
  138. const std::shared_ptr<ParticipantVideoParams> &existing);
  139. [[nodiscard]] const std::string &GetCameraEndpoint(
  140. const std::shared_ptr<ParticipantVideoParams> &params);
  141. [[nodiscard]] const std::string &GetScreenEndpoint(
  142. const std::shared_ptr<ParticipantVideoParams> &params);
  143. [[nodiscard]] bool IsCameraPaused(
  144. const std::shared_ptr<ParticipantVideoParams> &params);
  145. [[nodiscard]] bool IsScreenPaused(
  146. const std::shared_ptr<ParticipantVideoParams> &params);
  147. [[nodiscard]] uint32 GetAdditionalAudioSsrc(
  148. const std::shared_ptr<ParticipantVideoParams> &params);
  149. class GroupCall final
  150. : public base::has_weak_ptr
  151. , private Webrtc::CaptureMuteTracker {
  152. public:
  153. class Delegate {
  154. public:
  155. virtual ~Delegate() = default;
  156. virtual void groupCallFinished(not_null<GroupCall*> call) = 0;
  157. virtual void groupCallFailed(not_null<GroupCall*> call) = 0;
  158. virtual void groupCallRequestPermissionsOrFail(
  159. Fn<void()> onSuccess) = 0;
  160. enum class GroupCallSound {
  161. Started,
  162. Connecting,
  163. AllowedToSpeak,
  164. Ended,
  165. };
  166. virtual void groupCallPlaySound(GroupCallSound sound) = 0;
  167. virtual auto groupCallGetVideoCapture(const QString &deviceId)
  168. -> std::shared_ptr<tgcalls::VideoCaptureInterface> = 0;
  169. [[nodiscard]] virtual FnMut<void()> groupCallAddAsyncWaiter() = 0;
  170. };
  171. using GlobalShortcutManager = base::GlobalShortcutManager;
  172. struct VideoTrack;
  173. [[nodiscard]] static not_null<PeerData*> TrackPeer(
  174. const std::unique_ptr<VideoTrack> &track);
  175. [[nodiscard]] static not_null<Webrtc::VideoTrack*> TrackPointer(
  176. const std::unique_ptr<VideoTrack> &track);
  177. [[nodiscard]] static rpl::producer<QSize> TrackSizeValue(
  178. const std::unique_ptr<VideoTrack> &track);
  179. GroupCall(
  180. not_null<Delegate*> delegate,
  181. Group::JoinInfo info,
  182. const MTPInputGroupCall &inputCall);
  183. ~GroupCall();
  184. [[nodiscard]] CallId id() const {
  185. return _id;
  186. }
  187. [[nodiscard]] not_null<PeerData*> peer() const {
  188. return _peer;
  189. }
  190. [[nodiscard]] not_null<PeerData*> joinAs() const {
  191. return _joinAs.current();
  192. }
  193. [[nodiscard]] rpl::producer<not_null<PeerData*>> joinAsValue() const {
  194. return _joinAs.value();
  195. }
  196. [[nodiscard]] bool showChooseJoinAs() const;
  197. [[nodiscard]] TimeId scheduleDate() const {
  198. return _scheduleDate;
  199. }
  200. [[nodiscard]] bool scheduleStartSubscribed() const;
  201. [[nodiscard]] bool rtmp() const;
  202. [[nodiscard]] bool listenersHidden() const;
  203. [[nodiscard]] bool emptyRtmp() const;
  204. [[nodiscard]] rpl::producer<bool> emptyRtmpValue() const;
  205. [[nodiscard]] int rtmpVolume() const;
  206. [[nodiscard]] Group::RtmpInfo rtmpInfo() const;
  207. void setRtmpInfo(const Group::RtmpInfo &value);
  208. [[nodiscard]] Data::GroupCall *lookupReal() const;
  209. [[nodiscard]] rpl::producer<not_null<Data::GroupCall*>> real() const;
  210. void start(TimeId scheduleDate, bool rtmp);
  211. void hangup();
  212. void discard();
  213. void rejoinAs(Group::JoinInfo info);
  214. void rejoinWithHash(const QString &hash);
  215. void join(const MTPInputGroupCall &inputCall);
  216. void handleUpdate(const MTPUpdate &update);
  217. void handlePossibleCreateOrJoinResponse(const MTPDupdateGroupCall &data);
  218. void handlePossibleCreateOrJoinResponse(
  219. const MTPDupdateGroupCallConnection &data);
  220. void changeTitle(const QString &title);
  221. void toggleRecording(
  222. bool enabled,
  223. const QString &title,
  224. bool video,
  225. bool videoPortrait);
  226. [[nodiscard]] bool recordingStoppedByMe() const {
  227. return _recordingStoppedByMe;
  228. }
  229. void startScheduledNow();
  230. void toggleScheduleStartSubscribed(bool subscribed);
  231. void setNoiseSuppression(bool enabled);
  232. bool emitShareScreenError();
  233. bool emitShareCameraError();
  234. [[nodiscard]] rpl::producer<Group::Error> errors() const {
  235. return _errors.events();
  236. }
  237. void addVideoOutput(
  238. const std::string &endpoint,
  239. not_null<Webrtc::VideoTrack*> track);
  240. void setMuted(MuteState mute);
  241. void setMutedAndUpdate(MuteState mute);
  242. [[nodiscard]] MuteState muted() const {
  243. return _muted.current();
  244. }
  245. [[nodiscard]] rpl::producer<MuteState> mutedValue() const {
  246. return _muted.value();
  247. }
  248. [[nodiscard]] auto otherParticipantStateValue() const
  249. -> rpl::producer<Group::ParticipantState>;
  250. enum State {
  251. Creating,
  252. Waiting,
  253. Joining,
  254. Connecting,
  255. Joined,
  256. FailedHangingUp,
  257. Failed,
  258. HangingUp,
  259. Ended,
  260. };
  261. [[nodiscard]] State state() const {
  262. return _state.current();
  263. }
  264. [[nodiscard]] rpl::producer<State> stateValue() const {
  265. return _state.value();
  266. }
  267. enum class InstanceState {
  268. Disconnected,
  269. TransitionToRtc,
  270. Connected,
  271. };
  272. [[nodiscard]] InstanceState instanceState() const {
  273. return _instanceState.current();
  274. }
  275. [[nodiscard]] rpl::producer<InstanceState> instanceStateValue() const {
  276. return _instanceState.value();
  277. }
  278. [[nodiscard]] rpl::producer<LevelUpdate> levelUpdates() const {
  279. return _levelUpdates.events();
  280. }
  281. [[nodiscard]] auto videoStreamActiveUpdates() const
  282. -> rpl::producer<VideoStateToggle> {
  283. return _videoStreamActiveUpdates.events();
  284. }
  285. [[nodiscard]] auto videoStreamShownUpdates() const
  286. -> rpl::producer<VideoStateToggle> {
  287. return _videoStreamShownUpdates.events();
  288. }
  289. void requestVideoQuality(
  290. const VideoEndpoint &endpoint,
  291. Group::VideoQuality quality);
  292. [[nodiscard]] bool videoEndpointPinned() const {
  293. return _videoEndpointPinned.current();
  294. }
  295. [[nodiscard]] rpl::producer<bool> videoEndpointPinnedValue() const {
  296. return _videoEndpointPinned.value();
  297. }
  298. void pinVideoEndpoint(VideoEndpoint endpoint);
  299. void showVideoEndpointLarge(VideoEndpoint endpoint);
  300. [[nodiscard]] const VideoEndpoint &videoEndpointLarge() const {
  301. return _videoEndpointLarge.current();
  302. }
  303. [[nodiscard]] auto videoEndpointLargeValue() const
  304. -> rpl::producer<VideoEndpoint> {
  305. return _videoEndpointLarge.value();
  306. }
  307. [[nodiscard]] auto activeVideoTracks() const
  308. -> const base::flat_map<VideoEndpoint, std::unique_ptr<VideoTrack>> & {
  309. return _activeVideoTracks;
  310. }
  311. [[nodiscard]] auto shownVideoTracks() const
  312. -> const base::flat_set<VideoEndpoint> & {
  313. return _shownVideoTracks;
  314. }
  315. [[nodiscard]] rpl::producer<Group::RejoinEvent> rejoinEvents() const {
  316. return _rejoinEvents.events();
  317. }
  318. [[nodiscard]] rpl::producer<> allowedToSpeakNotifications() const {
  319. return _allowedToSpeakNotifications.events();
  320. }
  321. [[nodiscard]] rpl::producer<> titleChanged() const {
  322. return _titleChanged.events();
  323. }
  324. static constexpr auto kSpeakLevelThreshold = 0.2;
  325. [[nodiscard]] bool mutedByAdmin() const;
  326. [[nodiscard]] bool canManage() const;
  327. [[nodiscard]] rpl::producer<bool> canManageValue() const;
  328. [[nodiscard]] bool videoIsWorking() const {
  329. return _videoIsWorking.current();
  330. }
  331. [[nodiscard]] rpl::producer<bool> videoIsWorkingValue() const {
  332. return _videoIsWorking.value();
  333. }
  334. [[nodiscard]] bool isSharingScreen() const;
  335. [[nodiscard]] rpl::producer<bool> isSharingScreenValue() const;
  336. [[nodiscard]] bool isScreenPaused() const;
  337. [[nodiscard]] const std::string &screenSharingEndpoint() const;
  338. [[nodiscard]] bool isSharingCamera() const;
  339. [[nodiscard]] rpl::producer<bool> isSharingCameraValue() const;
  340. [[nodiscard]] bool isCameraPaused() const;
  341. [[nodiscard]] const std::string &cameraSharingEndpoint() const;
  342. [[nodiscard]] QString screenSharingDeviceId() const;
  343. [[nodiscard]] bool screenSharingWithAudio() const;
  344. void toggleVideo(bool active);
  345. void toggleScreenSharing(
  346. std::optional<QString> uniqueId,
  347. bool withAudio = false);
  348. [[nodiscard]] bool hasVideoWithFrames() const;
  349. [[nodiscard]] rpl::producer<bool> hasVideoWithFramesValue() const;
  350. void toggleMute(const Group::MuteRequest &data);
  351. void changeVolume(const Group::VolumeRequest &data);
  352. std::variant<int, not_null<UserData*>> inviteUsers(
  353. const std::vector<not_null<UserData*>> &users);
  354. std::shared_ptr<GlobalShortcutManager> ensureGlobalShortcutManager();
  355. void applyGlobalShortcutChanges();
  356. void pushToTalk(bool pressed, crl::time delay);
  357. void setNotRequireARGB32();
  358. [[nodiscard]] rpl::lifetime &lifetime() {
  359. return _lifetime;
  360. }
  361. private:
  362. class LoadPartTask;
  363. class MediaChannelDescriptionsTask;
  364. class RequestCurrentTimeTask;
  365. using GlobalShortcutValue = base::GlobalShortcutValue;
  366. using Error = Group::Error;
  367. struct SinkPointer;
  368. static constexpr uint32 kDisabledSsrc = uint32(-1);
  369. struct LoadingPart {
  370. std::shared_ptr<LoadPartTask> task;
  371. mtpRequestId requestId = 0;
  372. };
  373. enum class FinishType {
  374. None,
  375. Ended,
  376. Failed,
  377. };
  378. enum class InstanceMode {
  379. None,
  380. Rtc,
  381. Stream,
  382. };
  383. enum class SendUpdateType {
  384. Mute = 0x01,
  385. RaiseHand = 0x02,
  386. CameraStopped = 0x04,
  387. CameraPaused = 0x08,
  388. ScreenPaused = 0x10,
  389. };
  390. enum class JoinAction {
  391. None,
  392. Joining,
  393. Leaving,
  394. };
  395. struct JoinState {
  396. uint32 ssrc = 0;
  397. JoinAction action = JoinAction::None;
  398. bool nextActionPending = false;
  399. void finish(uint32 updatedSsrc = 0) {
  400. action = JoinAction::None;
  401. ssrc = updatedSsrc;
  402. }
  403. };
  404. friend inline constexpr bool is_flag_type(SendUpdateType) {
  405. return true;
  406. }
  407. void broadcastPartStart(std::shared_ptr<LoadPartTask> task);
  408. void broadcastPartCancel(not_null<LoadPartTask*> task);
  409. void mediaChannelDescriptionsStart(
  410. std::shared_ptr<MediaChannelDescriptionsTask> task);
  411. void mediaChannelDescriptionsCancel(
  412. not_null<MediaChannelDescriptionsTask*> task);
  413. void requestCurrentTimeStart(
  414. std::shared_ptr<RequestCurrentTimeTask> task);
  415. void requestCurrentTimeCancel(
  416. not_null<RequestCurrentTimeTask*> task);
  417. [[nodiscard]] int64 approximateServerTimeInMs() const;
  418. [[nodiscard]] bool mediaChannelDescriptionsFill(
  419. not_null<MediaChannelDescriptionsTask*> task,
  420. Fn<bool(uint32)> resolved = nullptr);
  421. void checkMediaChannelDescriptions(Fn<bool(uint32)> resolved = nullptr);
  422. void handlePossibleCreateOrJoinResponse(const MTPDgroupCall &data);
  423. void handlePossibleDiscarded(const MTPDgroupCallDiscarded &data);
  424. void handleUpdate(const MTPDupdateGroupCall &data);
  425. void handleUpdate(const MTPDupdateGroupCallParticipants &data);
  426. bool tryCreateController();
  427. void destroyController();
  428. bool tryCreateScreencast();
  429. void destroyScreencast();
  430. void emitShareCameraError(Error error);
  431. void emitShareScreenError(Error error);
  432. void setState(State state);
  433. void finish(FinishType type);
  434. void maybeSendMutedUpdate(MuteState previous);
  435. void sendSelfUpdate(SendUpdateType type);
  436. void updateInstanceMuteState();
  437. void updateInstanceVolumes();
  438. void updateInstanceVolume(
  439. const std::optional<Data::GroupCallParticipant> &was,
  440. const Data::GroupCallParticipant &now);
  441. void applyMeInCallLocally();
  442. void rejoin();
  443. void leave();
  444. void rejoin(not_null<PeerData*> as);
  445. void setJoinAs(not_null<PeerData*> as);
  446. void saveDefaultJoinAs(not_null<PeerData*> as);
  447. void subscribeToReal(not_null<Data::GroupCall*> real);
  448. void setScheduledDate(TimeId date);
  449. void rejoinPresentation();
  450. void leavePresentation();
  451. void checkNextJoinAction();
  452. void audioLevelsUpdated(const tgcalls::GroupLevelsUpdate &data);
  453. void setInstanceConnected(tgcalls::GroupNetworkState networkState);
  454. void setInstanceMode(InstanceMode mode);
  455. void setScreenInstanceConnected(tgcalls::GroupNetworkState networkState);
  456. void setScreenInstanceMode(InstanceMode mode);
  457. void checkLastSpoke();
  458. void pushToTalkCancel();
  459. void checkGlobalShortcutAvailability();
  460. void checkJoined();
  461. void checkFirstTimeJoined();
  462. void notifyAboutAllowedToSpeak();
  463. void playConnectingSound();
  464. void stopConnectingSound();
  465. void playConnectingSoundOnce();
  466. void updateRequestedVideoChannels();
  467. void updateRequestedVideoChannelsDelayed();
  468. void fillActiveVideoEndpoints();
  469. void editParticipant(
  470. not_null<PeerData*> participantPeer,
  471. bool mute,
  472. std::optional<int> volume);
  473. void applyParticipantLocally(
  474. not_null<PeerData*> participantPeer,
  475. bool mute,
  476. std::optional<int> volume);
  477. void applyQueuedSelfUpdates();
  478. void sendPendingSelfUpdates();
  479. void applySelfUpdate(const MTPDgroupCallParticipant &data);
  480. void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data);
  481. void captureMuteChanged(bool mute) override;
  482. rpl::producer<Webrtc::DeviceResolvedId> captureMuteDeviceId() override;
  483. void setupMediaDevices();
  484. void setupOutgoingVideo();
  485. void setScreenEndpoint(std::string endpoint);
  486. void setCameraEndpoint(std::string endpoint);
  487. void addVideoOutput(const std::string &endpoint, SinkPointer sink);
  488. void setVideoEndpointLarge(VideoEndpoint endpoint);
  489. void markEndpointActive(
  490. VideoEndpoint endpoint,
  491. bool active,
  492. bool paused);
  493. void markTrackPaused(const VideoEndpoint &endpoint, bool paused);
  494. void markTrackShown(const VideoEndpoint &endpoint, bool shown);
  495. [[nodiscard]] int activeVideoSendersCount() const;
  496. [[nodiscard]] MTPInputGroupCall inputCall() const;
  497. const not_null<Delegate*> _delegate;
  498. not_null<PeerData*> _peer; // Can change in legacy group migration.
  499. rpl::event_stream<PeerData*> _peerStream;
  500. not_null<History*> _history; // Can change in legacy group migration.
  501. MTP::Sender _api;
  502. rpl::event_stream<not_null<Data::GroupCall*>> _realChanges;
  503. rpl::variable<State> _state = State::Creating;
  504. base::flat_set<uint32> _unresolvedSsrcs;
  505. rpl::event_stream<Error> _errors;
  506. bool _recordingStoppedByMe = false;
  507. bool _requestedVideoChannelsUpdateScheduled = false;
  508. MTP::DcId _broadcastDcId = 0;
  509. base::flat_map<not_null<LoadPartTask*>, LoadingPart> _broadcastParts;
  510. base::flat_set<
  511. std::shared_ptr<MediaChannelDescriptionsTask>,
  512. base::pointer_comparator<
  513. MediaChannelDescriptionsTask>> _mediaChannelDescriptionses;
  514. base::flat_set<
  515. std::shared_ptr<RequestCurrentTimeTask>,
  516. base::pointer_comparator<
  517. RequestCurrentTimeTask>> _requestCurrentTimes;
  518. mtpRequestId _requestCurrentTimeRequestId = 0;
  519. rpl::variable<not_null<PeerData*>> _joinAs;
  520. std::vector<not_null<PeerData*>> _possibleJoinAs;
  521. QString _joinHash;
  522. int64 _serverTimeMs = 0;
  523. crl::time _serverTimeMsGotAt = 0;
  524. QString _rtmpUrl;
  525. QString _rtmpKey;
  526. rpl::variable<MuteState> _muted = MuteState::Muted;
  527. rpl::variable<bool> _canManage = false;
  528. rpl::variable<bool> _videoIsWorking = false;
  529. rpl::variable<bool> _emptyRtmp = false;
  530. bool _initialMuteStateSent = false;
  531. bool _acceptFields = false;
  532. rpl::event_stream<Group::ParticipantState> _otherParticipantStateValue;
  533. std::vector<MTPGroupCallParticipant> _queuedSelfUpdates;
  534. CallId _id = 0;
  535. CallId _accessHash = 0;
  536. JoinState _joinState;
  537. JoinState _screenJoinState;
  538. std::string _cameraEndpoint;
  539. std::string _screenEndpoint;
  540. TimeId _scheduleDate = 0;
  541. base::flat_set<uint32> _mySsrcs;
  542. mtpRequestId _createRequestId = 0;
  543. mtpRequestId _selfUpdateRequestId = 0;
  544. rpl::variable<InstanceState> _instanceState
  545. = InstanceState::Disconnected;
  546. bool _instanceTransitioning = false;
  547. InstanceMode _instanceMode = InstanceMode::None;
  548. std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
  549. base::has_weak_ptr _instanceGuard;
  550. std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
  551. rpl::variable<Webrtc::VideoState> _cameraState;
  552. rpl::variable<bool> _isSharingCamera = false;
  553. base::flat_map<std::string, SinkPointer> _pendingVideoOutputs;
  554. rpl::variable<InstanceState> _screenInstanceState
  555. = InstanceState::Disconnected;
  556. InstanceMode _screenInstanceMode = InstanceMode::None;
  557. std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
  558. base::has_weak_ptr _screenInstanceGuard;
  559. std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
  560. rpl::variable<Webrtc::VideoState> _screenState;
  561. rpl::variable<bool> _isSharingScreen = false;
  562. QString _screenDeviceId;
  563. bool _screenWithAudio = false;
  564. base::flags<SendUpdateType> _pendingSelfUpdates;
  565. bool _requireARGB32 = true;
  566. rpl::event_stream<LevelUpdate> _levelUpdates;
  567. rpl::event_stream<VideoStateToggle> _videoStreamActiveUpdates;
  568. rpl::event_stream<VideoStateToggle> _videoStreamPausedUpdates;
  569. rpl::event_stream<VideoStateToggle> _videoStreamShownUpdates;
  570. base::flat_map<
  571. VideoEndpoint,
  572. std::unique_ptr<VideoTrack>> _activeVideoTracks;
  573. base::flat_set<VideoEndpoint> _shownVideoTracks;
  574. rpl::variable<VideoEndpoint> _videoEndpointLarge;
  575. rpl::variable<bool> _videoEndpointPinned = false;
  576. crl::time _videoLargeTillTime = 0;
  577. base::flat_map<uint32, Data::LastSpokeTimes> _lastSpoke;
  578. rpl::event_stream<Group::RejoinEvent> _rejoinEvents;
  579. rpl::event_stream<> _allowedToSpeakNotifications;
  580. rpl::event_stream<> _titleChanged;
  581. base::Timer _lastSpokeCheckTimer;
  582. base::Timer _checkJoinedTimer;
  583. crl::time _lastSendProgressUpdate = 0;
  584. Fn<void(Webrtc::DeviceResolvedId)> _setDeviceIdCallback;
  585. Webrtc::DeviceResolver _playbackDeviceId;
  586. Webrtc::DeviceResolver _captureDeviceId;
  587. Webrtc::DeviceResolver _cameraDeviceId;
  588. std::shared_ptr<GlobalShortcutManager> _shortcutManager;
  589. std::shared_ptr<GlobalShortcutValue> _pushToTalk;
  590. base::Timer _pushToTalkCancelTimer;
  591. base::Timer _connectingSoundTimer;
  592. bool _hadJoinedState = false;
  593. bool _listenersHidden = false;
  594. bool _rtmp = false;
  595. bool _reloadedStaleCall = false;
  596. int _rtmpVolume = 0;
  597. rpl::lifetime _lifetime;
  598. };
  599. } // namespace Calls