Support waveform for video notes.

This commit is contained in:
levlam 2022-10-20 23:23:40 +03:00
parent 14b80ecd6f
commit 0d05683771
6 changed files with 32 additions and 9 deletions

View File

@ -320,9 +320,9 @@ sticker set_id:int64 width:int32 height:int32 emoji:string format:StickerFormat
video duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool supports_streaming:Bool minithumbnail:minithumbnail thumbnail:thumbnail video:file = Video;
//@description Describes a video note. The video must be equal in width and height, cropped to a circle, and stored in MPEG4 format @duration Duration of the video, in seconds; as defined by the sender
//@length Video width and height; as defined by the sender @minithumbnail Video minithumbnail; may be null
//@waveform A waveform representation of the video note's audio in 5-bit format; may be empty if unknown @length Video width and height; as defined by the sender @minithumbnail Video minithumbnail; may be null
//@thumbnail Video thumbnail in JPEG format; as defined by the sender; may be null @speech_recognition_result Result of speech recognition in the video note; may be null @video File containing the video
videoNote duration:int32 length:int32 minithumbnail:minithumbnail thumbnail:thumbnail speech_recognition_result:SpeechRecognitionResult video:file = VideoNote;
videoNote duration:int32 waveform:bytes length:int32 minithumbnail:minithumbnail thumbnail:thumbnail speech_recognition_result:SpeechRecognitionResult video:file = VideoNote;
//@description Describes a voice note. The voice note must be encoded with the Opus codec, and stored inside an OGG container. Voice notes can have only a single audio channel
//@duration Duration of the voice note, in seconds; as defined by the sender @waveform A waveform representation of the voice note in 5-bit format
@ -2259,7 +2259,7 @@ inputMessageVideo video:InputFile thumbnail:inputThumbnail added_sticker_file_id
//@description A video note message @video_note Video note to be sent @thumbnail Video thumbnail; pass null to skip thumbnail uploading @duration Duration of the video, in seconds @length Video width and height; must be positive and not greater than 640
inputMessageVideoNote video_note:InputFile thumbnail:inputThumbnail duration:int32 length:int32 = InputMessageContent;
//@description A voice note message @voice_note Voice note to be sent @duration Duration of the voice note, in seconds @waveform Waveform representation of the voice note, in 5-bit format @caption Voice note caption; pass null to use an empty caption; 0-GetOption("message_caption_length_max") characters
//@description A voice note message @voice_note Voice note to be sent @duration Duration of the voice note, in seconds @waveform Waveform representation of the voice note in 5-bit format @caption Voice note caption; pass null to use an empty caption; 0-GetOption("message_caption_length_max") characters
inputMessageVoiceNote voice_note:InputFile duration:int32 waveform:bytes caption:formattedText = InputMessageContent;
//@description A message with a location @location Location to be sent @live_period Period for which the location can be updated, in seconds; must be between 60 and 86400 for a live location and 0 otherwise

View File

@ -122,6 +122,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
}
}
int32 video_duration = 0;
string video_waveform;
if (video != nullptr) {
video_duration = video->duration_;
auto video_dimensions = get_dimensions(video->w_, video->h_, "documentAttributeVideo");
@ -131,6 +132,11 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
}
dimensions = video_dimensions;
}
if (audio != nullptr) {
video_waveform = audio->waveform_.as_slice().str();
type_attributes--;
audio = nullptr;
}
if (animated != nullptr) {
type_attributes--;
@ -514,7 +520,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
break;
case Document::Type::VideoNote:
td_->video_notes_manager_->create_video_note(file_id, std::move(minithumbnail), std::move(thumbnail),
video_duration, dimensions, !is_web);
video_duration, dimensions, std::move(video_waveform), !is_web);
break;
case Document::Type::VoiceNote: {
int32 duration = 0;

View File

@ -1961,7 +1961,7 @@ static Result<InputMessageContent> create_input_message_content(
}
td->video_notes_manager_->create_video_note(file_id, string(), thumbnail, input_video_note->duration_,
get_dimensions(length, length, nullptr), false);
get_dimensions(length, length, nullptr), string(), false);
content = make_unique<MessageVideoNote>(file_id, false);
break;

View File

@ -52,7 +52,8 @@ tl_object_ptr<td_api::videoNote> VideoNotesManager::get_video_note_object(FileId
? nullptr
: video_note->transcription_info->get_speech_recognition_result_object();
return make_tl_object<td_api::videoNote>(
video_note->duration, video_note->dimensions.width, get_minithumbnail_object(video_note->minithumbnail),
video_note->duration, video_note->waveform, video_note->dimensions.width,
get_minithumbnail_object(video_note->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), video_note->thumbnail, PhotoFormat::Jpeg),
std::move(speech_recognition_result), td_->file_manager_->get_file_object(file_id));
}
@ -66,10 +67,12 @@ FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note
v = std::move(new_video_note);
} else if (replace) {
CHECK(v->file_id == new_video_note->file_id);
if (v->duration != new_video_note->duration || v->dimensions != new_video_note->dimensions) {
if (v->duration != new_video_note->duration || v->dimensions != new_video_note->dimensions ||
v->waveform != new_video_note->waveform) {
LOG(DEBUG) << "Video note " << file_id << " info has changed";
v->duration = new_video_note->duration;
v->dimensions = new_video_note->dimensions;
v->waveform = std::move(new_video_note->waveform);
}
if (v->minithumbnail != new_video_note->minithumbnail) {
v->minithumbnail = std::move(new_video_note->minithumbnail);
@ -119,6 +122,7 @@ FileId VideoNotesManager::dup_video_note(FileId new_id, FileId old_id) {
new_video_note->file_id = new_id;
new_video_note->duration = old_video_note->duration;
new_video_note->dimensions = old_video_note->dimensions;
new_video_note->waveform = old_video_note->waveform;
new_video_note->minithumbnail = old_video_note->minithumbnail;
new_video_note->thumbnail = old_video_note->thumbnail;
new_video_note->thumbnail.file_id = td_->file_manager_->dup_file_id(new_video_note->thumbnail.file_id);
@ -146,7 +150,7 @@ void VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id) {
}
void VideoNotesManager::create_video_note(FileId file_id, string minithumbnail, PhotoSize thumbnail, int32 duration,
Dimensions dimensions, bool replace) {
Dimensions dimensions, string waveform, bool replace) {
auto v = make_unique<VideoNote>();
v->file_id = file_id;
v->duration = max(duration, 0);
@ -155,6 +159,7 @@ void VideoNotesManager::create_video_note(FileId file_id, string minithumbnail,
} else {
LOG(INFO) << "Receive wrong video note dimensions " << dimensions;
}
v->waveform = std::move(waveform);
if (!td_->auth_manager_->is_bot()) {
v->minithumbnail = std::move(minithumbnail);
}

View File

@ -41,7 +41,7 @@ class VideoNotesManager final : public Actor {
tl_object_ptr<td_api::videoNote> get_video_note_object(FileId file_id) const;
void create_video_note(FileId file_id, string minithumbnail, PhotoSize thumbnail, int32 duration,
Dimensions dimensions, bool replace);
Dimensions dimensions, string waveform, bool replace);
void register_video_note(FileId video_note_file_id, FullMessageId full_message_id, const char *source);
@ -78,6 +78,7 @@ class VideoNotesManager final : public Actor {
public:
int32 duration = 0;
Dimensions dimensions;
string waveform;
string minithumbnail;
PhotoSize thumbnail;
unique_ptr<TranscriptionInfo> transcription_info;

View File

@ -25,11 +25,13 @@ void VideoNotesManager::store_video_note(FileId file_id, StorerT &storer) const
bool has_minithumbnail = !video_note->minithumbnail.empty();
bool has_thumbnail = video_note->thumbnail.file_id.is_valid();
bool is_transcribed = video_note->transcription_info != nullptr && video_note->transcription_info->is_transcribed();
bool has_waveform = !video_note->waveform.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_duration);
STORE_FLAG(has_minithumbnail);
STORE_FLAG(has_thumbnail);
STORE_FLAG(is_transcribed);
STORE_FLAG(has_waveform);
END_STORE_FLAGS();
if (has_duration) {
store(video_note->duration, storer);
@ -44,6 +46,9 @@ void VideoNotesManager::store_video_note(FileId file_id, StorerT &storer) const
if (is_transcribed) {
store(video_note->transcription_info, storer);
}
if (has_waveform) {
store(video_note->waveform, storer);
}
store(file_id, storer);
}
@ -54,18 +59,21 @@ FileId VideoNotesManager::parse_video_note(ParserT &parser) {
bool has_minithumbnail;
bool has_thumbnail;
bool is_transcribed;
bool has_waveform;
if (parser.version() >= static_cast<int32>(Version::AddVideoNoteFlags)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_duration);
PARSE_FLAG(has_minithumbnail);
PARSE_FLAG(has_thumbnail);
PARSE_FLAG(is_transcribed);
PARSE_FLAG(has_waveform);
END_PARSE_FLAGS();
} else {
has_duration = true;
has_minithumbnail = parser.version() >= static_cast<int32>(Version::SupportMinithumbnails);
has_thumbnail = true;
is_transcribed = false;
has_waveform = false;
}
if (has_duration) {
parse(video_note->duration, parser);
@ -80,6 +88,9 @@ FileId VideoNotesManager::parse_video_note(ParserT &parser) {
if (is_transcribed) {
parse(video_note->transcription_info, parser);
}
if (has_waveform) {
parse(video_note->waveform, parser);
}
parse(video_note->file_id, parser);
if (parser.get_error() != nullptr || !video_note->file_id.is_valid()) {
return FileId();