Support video recording in group calls.

This commit is contained in:
levlam 2021-08-23 15:29:03 +03:00
parent d61b1d9348
commit 2045c131a9
5 changed files with 46 additions and 23 deletions

View File

@ -4854,7 +4854,8 @@ inviteGroupCallParticipants group_call_id:int32 user_ids:vector<int32> = Ok;
getGroupCallInviteLink group_call_id:int32 can_self_unmute:Bool = HttpUrl; getGroupCallInviteLink group_call_id:int32 can_self_unmute:Bool = HttpUrl;
//@description Starts recording of an active group call. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier @title Group call recording title; 0-64 characters //@description Starts recording of an active group call. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier @title Group call recording title; 0-64 characters
startGroupCallRecording group_call_id:int32 title:string = Ok; //@record_video Pass true to record a video file instead of an audio file @use_portrait_orientation Pass true to use portrait orientation for video instead of landscape one
startGroupCallRecording group_call_id:int32 title:string record_video:Bool use_portrait_orientation:Bool = Ok;
//@description Ends recording of an active group call. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier //@description Ends recording of an active group call. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier
endGroupCallRecording group_call_id:int32 = Ok; endGroupCallRecording group_call_id:int32 = Ok;

View File

@ -637,7 +637,8 @@ class ToggleGroupCallRecordQuery final : public Td::ResultHandler {
explicit ToggleGroupCallRecordQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit ToggleGroupCallRecordQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(InputGroupCallId input_group_call_id, bool is_enabled, const string &title) { void send(InputGroupCallId input_group_call_id, bool is_enabled, const string &title, bool record_video,
bool use_portrait_orientation) {
int32 flags = 0; int32 flags = 0;
if (is_enabled) { if (is_enabled) {
flags |= telegram_api::phone_toggleGroupCallRecord::START_MASK; flags |= telegram_api::phone_toggleGroupCallRecord::START_MASK;
@ -645,8 +646,12 @@ class ToggleGroupCallRecordQuery final : public Td::ResultHandler {
if (!title.empty()) { if (!title.empty()) {
flags |= telegram_api::phone_toggleGroupCallRecord::TITLE_MASK; flags |= telegram_api::phone_toggleGroupCallRecord::TITLE_MASK;
} }
if (record_video) {
flags |= telegram_api::phone_toggleGroupCallRecord::VIDEO_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::phone_toggleGroupCallRecord( send_query(G()->net_query_creator().create(telegram_api::phone_toggleGroupCallRecord(
flags, false /*ignored*/, false /*ignored*/, input_group_call_id.get_input_group_call(), title, false))); flags, false /*ignored*/, false /*ignored*/, input_group_call_id.get_input_group_call(), title,
use_portrait_orientation)));
} }
void on_result(uint64 id, BufferSlice packet) final { void on_result(uint64 id, BufferSlice packet) final {
@ -871,6 +876,8 @@ struct GroupCallManager::GroupCall {
bool have_pending_record_start_date = false; bool have_pending_record_start_date = false;
int32 pending_record_start_date = 0; int32 pending_record_start_date = 0;
string pending_record_title; string pending_record_title;
bool pending_record_record_video = false;
bool pending_record_use_portrait_orientation = false;
uint64 toggle_recording_generation = 0; uint64 toggle_recording_generation = 0;
}; };
@ -3413,6 +3420,7 @@ void GroupCallManager::get_group_call_invite_link(GroupCallId group_call_id, boo
} }
void GroupCallManager::toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, void GroupCallManager::toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title,
bool record_video, bool use_portrait_orientation,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
if (G()->close_flag()) { if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted")); return promise.set_error(Status::Error(500, "Request aborted"));
@ -3422,17 +3430,18 @@ void GroupCallManager::toggle_group_call_recording(GroupCallId group_call_id, bo
auto *group_call = get_group_call(input_group_call_id); auto *group_call = get_group_call(input_group_call_id);
if (group_call == nullptr || !group_call->is_inited) { if (group_call == nullptr || !group_call->is_inited) {
reload_group_call(input_group_call_id, reload_group_call(
PromiseCreator::lambda( input_group_call_id,
[actor_id = actor_id(this), group_call_id, is_enabled, title, promise = std::move(promise)]( PromiseCreator::lambda(
Result<td_api::object_ptr<td_api::groupCall>> &&result) mutable { [actor_id = actor_id(this), group_call_id, is_enabled, title, record_video, use_portrait_orientation,
if (result.is_error()) { promise = std::move(promise)](Result<td_api::object_ptr<td_api::groupCall>> &&result) mutable {
promise.set_error(result.move_as_error()); if (result.is_error()) {
} else { promise.set_error(result.move_as_error());
send_closure(actor_id, &GroupCallManager::toggle_group_call_recording, group_call_id, } else {
is_enabled, std::move(title), std::move(promise)); send_closure(actor_id, &GroupCallManager::toggle_group_call_recording, group_call_id, is_enabled,
} std::move(title), record_video, use_portrait_orientation, std::move(promise));
})); }
}));
return; return;
} }
if (!group_call->is_active || !group_call->can_be_managed) { if (!group_call->is_active || !group_call->can_be_managed) {
@ -3448,24 +3457,29 @@ void GroupCallManager::toggle_group_call_recording(GroupCallId group_call_id, bo
// there is no reason to save promise; we will send an update with actual value anyway // there is no reason to save promise; we will send an update with actual value anyway
if (!group_call->have_pending_record_start_date) { if (!group_call->have_pending_record_start_date) {
send_toggle_group_call_recording_query(input_group_call_id, is_enabled, title, toggle_recording_generation_ + 1); send_toggle_group_call_recording_query(input_group_call_id, is_enabled, title, record_video,
use_portrait_orientation, toggle_recording_generation_ + 1);
} }
group_call->have_pending_record_start_date = true; group_call->have_pending_record_start_date = true;
group_call->pending_record_start_date = is_enabled ? G()->unix_time() : 0; group_call->pending_record_start_date = is_enabled ? G()->unix_time() : 0;
group_call->pending_record_title = std::move(title); group_call->pending_record_title = std::move(title);
group_call->pending_record_record_video = record_video;
group_call->pending_record_use_portrait_orientation = use_portrait_orientation;
group_call->toggle_recording_generation = ++toggle_recording_generation_; group_call->toggle_recording_generation = ++toggle_recording_generation_;
send_update_group_call(group_call, "toggle_group_call_recording"); send_update_group_call(group_call, "toggle_group_call_recording");
promise.set_value(Unit()); promise.set_value(Unit());
} }
void GroupCallManager::send_toggle_group_call_recording_query(InputGroupCallId input_group_call_id, bool is_enabled, void GroupCallManager::send_toggle_group_call_recording_query(InputGroupCallId input_group_call_id, bool is_enabled,
const string &title, uint64 generation) { const string &title, bool record_video,
bool use_portrait_orientation, uint64 generation) {
auto promise = auto promise =
PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id, generation](Result<Unit> result) { PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id, generation](Result<Unit> result) {
send_closure(actor_id, &GroupCallManager::on_toggle_group_call_recording, input_group_call_id, generation, send_closure(actor_id, &GroupCallManager::on_toggle_group_call_recording, input_group_call_id, generation,
std::move(result)); std::move(result));
}); });
td_->create_handler<ToggleGroupCallRecordQuery>(std::move(promise))->send(input_group_call_id, is_enabled, title); td_->create_handler<ToggleGroupCallRecordQuery>(std::move(promise))
->send(input_group_call_id, is_enabled, title, record_video, use_portrait_orientation);
} }
void GroupCallManager::on_toggle_group_call_recording(InputGroupCallId input_group_call_id, uint64 generation, void GroupCallManager::on_toggle_group_call_recording(InputGroupCallId input_group_call_id, uint64 generation,
@ -3484,7 +3498,9 @@ void GroupCallManager::on_toggle_group_call_recording(InputGroupCallId input_gro
if (group_call->toggle_recording_generation != generation && group_call->can_be_managed) { if (group_call->toggle_recording_generation != generation && group_call->can_be_managed) {
// need to send another request // need to send another request
send_toggle_group_call_recording_query(input_group_call_id, group_call->pending_record_start_date != 0, send_toggle_group_call_recording_query(input_group_call_id, group_call->pending_record_start_date != 0,
group_call->pending_record_title, group_call->toggle_recording_generation); group_call->pending_record_title, group_call->pending_record_record_video,
group_call->pending_record_use_portrait_orientation,
group_call->toggle_recording_generation);
return; return;
} }

View File

@ -95,7 +95,8 @@ class GroupCallManager final : public Actor {
void get_group_call_invite_link(GroupCallId group_call_id, bool can_self_unmute, Promise<string> &&promise); void get_group_call_invite_link(GroupCallId group_call_id, bool can_self_unmute, Promise<string> &&promise);
void toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, Promise<Unit> &&promise); void toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, bool record_video,
bool use_portrait_orientation, Promise<Unit> &&promise);
void set_group_call_participant_is_speaking(GroupCallId group_call_id, int32 audio_source, bool is_speaking, void set_group_call_participant_is_speaking(GroupCallId group_call_id, int32 audio_source, bool is_speaking,
Promise<Unit> &&promise, int32 date = 0); Promise<Unit> &&promise, int32 date = 0);
@ -310,7 +311,8 @@ class GroupCallManager final : public Actor {
Result<Unit> &&result); Result<Unit> &&result);
void send_toggle_group_call_recording_query(InputGroupCallId input_group_call_id, bool is_enabled, void send_toggle_group_call_recording_query(InputGroupCallId input_group_call_id, bool is_enabled,
const string &title, uint64 generation); const string &title, bool record_video, bool use_portrait_orientation,
uint64 generation);
void on_toggle_group_call_recording(InputGroupCallId input_group_call_id, uint64 generation, Result<Unit> &&result); void on_toggle_group_call_recording(InputGroupCallId input_group_call_id, uint64 generation, Result<Unit> &&result);

View File

@ -6081,13 +6081,14 @@ void Td::on_request(uint64 id, td_api::startGroupCallRecording &request) {
CLEAN_INPUT_STRING(request.title_); CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
group_call_manager_->toggle_group_call_recording(GroupCallId(request.group_call_id_), true, std::move(request.title_), group_call_manager_->toggle_group_call_recording(GroupCallId(request.group_call_id_), true, std::move(request.title_),
request.record_video_, request.use_portrait_orientation_,
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::endGroupCallRecording &request) { void Td::on_request(uint64 id, const td_api::endGroupCallRecording &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
group_call_manager_->toggle_group_call_recording(GroupCallId(request.group_call_id_), false, string(), group_call_manager_->toggle_group_call_recording(GroupCallId(request.group_call_id_), false, string(), false, false,
std::move(promise)); std::move(promise));
} }

View File

@ -2854,8 +2854,11 @@ class CliClient final : public Actor {
} else if (op == "sgcr") { } else if (op == "sgcr") {
string chat_id; string chat_id;
string title; string title;
get_args(args, chat_id, title); bool record_video;
send_request(td_api::make_object<td_api::startGroupCallRecording>(as_group_call_id(chat_id), title)); bool use_portrait_orientation;
get_args(args, chat_id, title, record_video, use_portrait_orientation);
send_request(td_api::make_object<td_api::startGroupCallRecording>(as_group_call_id(chat_id), title, record_video,
use_portrait_orientation));
} else if (op == "egcr") { } else if (op == "egcr") {
string chat_id = args; string chat_id = args;
send_request(td_api::make_object<td_api::endGroupCallRecording>(as_group_call_id(chat_id))); send_request(td_api::make_object<td_api::endGroupCallRecording>(as_group_call_id(chat_id)));