Skip to content

Commit bf1bcb1

Browse files
committed
[*] refactor
1 parent 3bc5ba2 commit bf1bcb1

File tree

7 files changed

+66
-191
lines changed

7 files changed

+66
-191
lines changed

lib/video-editor/src/export/exporter.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,34 @@ impl Mp4Exporter {
481481
Ok(stream.index())
482482
}
483483

484+
// Generate AudioSpecificConfig for AAC in MP4
485+
// Format: [AOT (5 bits) | freq_index (4 bits) | channel_config (4 bits) | ...]
486+
fn generate_audio_specific_config(sample_rate: u32, channels: u16) -> Vec<u8> {
487+
let audio_object_type = 2; // AAC-LC
488+
let freq_index = Self::sample_rate_index(sample_rate);
489+
let byte1 = (audio_object_type << 3) | (freq_index >> 1);
490+
let byte2 = ((freq_index & 0x1) << 7) | ((channels as u8) << 3);
491+
vec![byte1, byte2]
492+
}
493+
494+
fn sample_rate_index(sample_rate: u32) -> u8 {
495+
match sample_rate {
496+
96000 => 0,
497+
88200 => 1,
498+
64000 => 2,
499+
48000 => 3,
500+
44100 => 4,
501+
32000 => 5,
502+
24000 => 6,
503+
22050 => 7,
504+
16000 => 8,
505+
12000 => 9,
506+
11025 => 10,
507+
8000 => 11,
508+
_ => 4, // Default to 44100
509+
}
510+
}
511+
484512
fn add_audio_stream(
485513
&self,
486514
octx: &mut ffmpeg_next::format::context::Output,
@@ -511,6 +539,16 @@ impl Mp4Exporter {
511539
);
512540
(*codec_par).format = 8; // AV_SAMPLE_FMT_FLTP (planar float, typically used by AAC)
513541
(*codec_par).bit_rate = self.config.audio_bitrate as i64;
542+
543+
// Add AudioSpecificConfig as extradata for AAC decoder configuration
544+
let asc = Self::generate_audio_specific_config(sample_rate, channels);
545+
(*codec_par).extradata = ffmpeg_next::ffi::av_malloc(asc.len()) as *mut _;
546+
(*codec_par).extradata_size = asc.len() as i32;
547+
std::ptr::copy_nonoverlapping(
548+
asc.as_ptr() as *const _,
549+
(*codec_par).extradata as *mut _,
550+
asc.len(),
551+
);
514552
}
515553
}
516554

wayshot/src/logic/video_editor/project.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ pub fn init(ui: &AppWindow) {
113113

114114
logic_cb!(video_editor_update_ui_state, ui);
115115
logic_cb!(video_editor_show_new_project_dialog, ui);
116-
logic_cb!(video_editor_new_project, ui, config);
117116
logic_cb!(video_editor_init_recent, ui);
118117
logic_cb!(video_editor_show_recent_dialog, ui);
119118
logic_cb!(video_editor_open_recent_project, ui, index);
@@ -228,38 +227,32 @@ fn video_editor_update_ui_state(ui: &AppWindow) {
228227
}
229228

230229
fn video_editor_show_new_project_dialog(ui: &AppWindow) {
231-
global_store!(ui).set_video_editor_is_show_new_project_dialog(true);
232-
}
233-
234-
fn video_editor_new_project(ui: &AppWindow, config: UIVideoEditorNewProjectConfig) {
235230
let ui_weak = ui.as_weak();
236-
global_store!(ui).set_video_editor_is_show_new_project_dialog(false);
237-
238-
let preview_config: VideoEditorPreviewConfig = config.preview_config.clone().into();
239-
db_update_preview_config(ui.as_weak(), preview_config);
231+
let ui_preview_config = global_store!(ui)
232+
.get_video_editor_new_project_config()
233+
.preview_config;
234+
let preview_config: ProjectPreviewConfig = ui_preview_config.clone().into();
240235

241236
tokio::spawn(async move {
242-
let Some(dir) = picker_directory(ui_weak.clone(), &tr("Choose project directory"), "")
243-
else {
237+
let Some(mut path) = picker_save_file(
238+
ui_weak.clone(),
239+
&tr("New Project"),
240+
&tr("Wayshot Project"),
241+
&[PROJECT_EXT],
242+
&format!("untitled_{}", chrono::Utc::now().format("%Y%m%d_%H%M%S")),
243+
) else {
244244
return;
245245
};
246246

247-
let project_name_trimmed = config.name.trim().to_string();
248-
if project_name_trimmed.is_empty() {
249-
toast::async_toast_warn(
250-
ui_weak.clone(),
251-
tr("Project name cannot be empty or whitespace only").into(),
252-
);
253-
return;
247+
if path.extension().is_none() {
248+
path.set_extension(PROJECT_EXT);
254249
}
255250

256-
let mut path = dir.join(&project_name_trimmed);
257-
path.set_extension(PROJECT_EXT);
258251
let project_name = path
259-
.file_name()
260-
.map(|f| f.to_string_lossy().to_string())
261-
.unwrap_or_else(|| project_name_trimmed.clone());
262-
let preview_config: ProjectPreviewConfig = config.preview_config.clone().into();
252+
.file_stem()
253+
.and_then(|s| s.to_str())
254+
.unwrap_or("Untitled")
255+
.to_string();
263256

264257
let (manager, playlist) = {
265258
let mut state = PROJECT_STATE.lock().unwrap();
@@ -290,8 +283,8 @@ fn video_editor_new_project(ui: &AppWindow, config: UIVideoEditorNewProjectConfi
290283
global_store!(ui).set_video_editor_is_unsaved(false);
291284
global_store!(ui).set_video_editor_new_project_config(
292285
UIVideoEditorNewProjectConfig {
293-
name: project_name_trimmed.into(),
294-
preview_config: preview_config.into(),
286+
name: project_name.clone().into(),
287+
preview_config: ui_preview_config,
295288
},
296289
);
297290
crate::toast_success!(ui, format!("New project created: {}", project_name));

wayshot/ui/logic.slint

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
AudioChannels,
3535
AudioSampleRate,
3636
AudioFormat,
37-
VideoEditorNewProjectConfig,
3837
VideoEditorRecentEntry,
3938
VideoEditorPreviewConfig,
4039
VideoPreviewSize,
@@ -272,7 +271,6 @@ export global Logic {
272271

273272
callback video-editor-update-ui-state();
274273
callback video-editor-show-new-project-dialog();
275-
callback video-editor-new-project(config: VideoEditorNewProjectConfig);
276274
callback video-editor-init-recent();
277275
callback video-editor-show-recent-dialog();
278276
callback video-editor-open-recent-project(index: int);

wayshot/ui/panel/desktop/home.slint

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ export component Home inherits VerticalLayout {
3838
}
3939
}
4040

41-
// if Store.current-tab-index == TabIndex.Transcribe: TranscribePanel {
42-
// height: parent.height;
43-
//
44-
// init => {
45-
// Logic.startup-transcribe-init();
46-
// }
47-
// }
41+
if Store.current-tab-index == TabIndex.Transcribe: TranscribePanel {
42+
height: parent.height;
43+
44+
init => {
45+
Logic.startup-transcribe-init();
46+
}
47+
}
48+
4849
//
4950
// if Store.current-tab-index == TabIndex.ShareScreen: ShareScreenPanel {
5051
// width: parent.width;

wayshot/ui/panel/desktop/video-editor/new-project.slint

Lines changed: 0 additions & 142 deletions
This file was deleted.

wayshot/ui/panel/desktop/video-editor/video-editor.slint

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Header } from "header.slint";
1616
import { Tracks } from "tracks/tracks.slint";
1717
import { LeftPanel } from "left-panel/left-panel.slint";
1818
import { RightPanel } from "right-panel/right-panel.slint";
19-
import { NewProject } from "new-project.slint";
2019
import { RecentDialog } from "recent-dialog.slint";
2120
import { MetadataDialog } from "metadata-dialog.slint";
2221
import { RecordAudioDialog } from "record-audio-dialog.slint";
@@ -247,26 +246,15 @@ export component VideoEditor inherits Rectangle {
247246
}
248247
}
249248

250-
if Store.video-editor-is-show-new-project-dialog || Store.video-editor-is-show-unsave-change-dialog || Store.video-editor-is-show-recovery-dialog || Store.video-editor-is-show-preview-setting-dialog || Store.video-editor-is-show-preference-setting-dialog: Blanket {
249+
if Store.video-editor-is-show-unsave-change-dialog || Store.video-editor-is-show-recovery-dialog || Store.video-editor-is-show-preview-setting-dialog || Store.video-editor-is-show-preference-setting-dialog: Blanket {
251250
clicked => {
252-
Store.video-editor-is-show-new-project-dialog = false;
253251
Store.video-editor-is-show-unsave-change-dialog = false;
254252
Store.video-editor-is-show-recovery-dialog = false;
255253
Store.video-editor-is-show-preview-setting-dialog = false;
256254
Store.video-editor-is-show-preference-setting-dialog = false;
257255
}
258256
}
259257

260-
if Store.video-editor-is-show-new-project-dialog: NewProject {
261-
width: Math.min(Theme.dialog-max-width * Theme.golden-ratio, root.width * Theme.golden-ratio);
262-
inner-height: Math.max(root.height * Theme.golden-ratio, Theme.dialog-inner-height);
263-
264-
escape => {
265-
Store.video-editor-is-show-new-project-dialog = false;
266-
fs.focus();
267-
}
268-
}
269-
270258
if Store.video-editor-is-show-preview-setting-dialog: PreviewSettingDialog {
271259
width: Math.min(Theme.dialog-max-width * Theme.golden-ratio, root.width * Theme.golden-ratio);
272260
inner-height: Math.max(root.height * Theme.golden-ratio, Theme.dialog-inner-height);

wayshot/ui/store.slint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ export global Store {
757757
in-out property <[SelectedTrackIndex]> video-editor-selected-tracks-index: [];
758758
in-out property <[SelectedSegmentIndex]> video-editor-selected-segments-index: [];
759759
in-out property <KeyboardModifiers> video-editor-keyboard-modifiers;
760-
in-out property <bool> video-editor-is-show-new-project-dialog;
761760
in-out property <bool> video-editor-is-show-unsave-change-dialog;
762761
in-out property <bool> video-editor-is-show-recovery-dialog;
763762
in-out property <VideoEditorRecoveryInfo> video-editor-recovery-info;

0 commit comments

Comments
 (0)