/
gui_main.cpp
2125 lines (1932 loc) · 64.2 KB
/
gui_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
\file gtk_gui.cpp
\brief Main UI even loop
copyright : (C) 2001-2009 by mean, fixounet@free.fr
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "ADM_cpp.h"
#include "ADM_default.h"
#include <math.h>
#include <errno.h>
#include <sstream>
#include "fourcc.h"
#include "DIA_fileSel.h"
#include "DIA_coreToolkit.h"
#include "gui_action.hxx"
#include "gtkgui.h"
#include "prefs.h"
#include "ADM_render/GUI_render.h"
#include "ADM_commonUI/GUI_ui.h"
#include "DIA_working.h"
#include "DIA_factory.h"
#include "ADM_vidMisc.h"
#include "ADM_preview.h"
#include "ADM_coreVideoEncoder.h"
#include "ADM_videoEncoderApi.h"
#include "ADM_muxerProto.h"
#include "ADM_coreVideoFilterFunc.h"
#include "ADM_audioFilter/include/ADM_audioFilterInterface.h"
#include "avi_vars.h"
#include "prototype.h" // FIXME
#include "ADM_script2/include/ADM_script.h"
#include "ADM_edScriptGenerator.h"
#include "ADM_edAudioTrackExternal.h"
#include "ADM_threads.h"
#include "ADM_muxerProto.h"
#include "ADM_filterChain.h"
static admMutex singleThread("actionHandlerMutex");
static int cutsNotOnIntraWarned;
#include "DIA_audioTracks.h"
//***********************************
//******** A Function ***************
//***********************************
#include "A_functions.h"
//***********************************
//******** GUI Function**************
//***********************************
extern const char * GUI_getCustomJsScript(uint32_t nb);
extern const char * GUI_getCustomPyScript(uint32_t nb);
extern const char * GUI_getAutoPyScript(uint32_t nb);
extern void call_scriptEngine(const char *scriptFile);
extern int GUI_handleVFilter (void);
extern int GUI_handleVPartialFilter (void);
// Debug functions
void GUI_showCurrentFrameHex(void);
void GUI_showSize(void);
void GUI_avsProxy(void);
uint8_t GUI_close(void);
extern bool GUI_GoToTime(uint64_t time);
extern bool GUI_infiniteForward(uint64_t pts);
//***********************************
//******** DIA Function**************
//***********************************
extern uint8_t DIA_about( void );
extern void DIA_properties( void);
extern uint8_t DIA_Preferences(void);
extern uint8_t DIA_builtin(void);
extern uint8_t DIA_pluginsInfo(void);
extern void DIA_ScriptShortcutConfig(void);
static void ReSync (void);
static void A_RunScript(const char *a);
void cleanUp (void);
void updateLoaded (bool resetMarker=true);
extern void GUI_OpenApplicationLog();
extern void GUI_OpenApplicationDataFolder();
//extern bool ADM_mux_configure(int index);
void brokenAct(void);
//
// Sub gui files...
//
void HandleAction (Action action);
void HandleAction_Navigate(Action action);
void HandleAction_Save(Action action);
void HandleAction_Staged(Action action);
extern void call_scriptEngine(const char *scriptFile);
static std::string getDefaultSettingsFilePath(void);
static std::string getLastSessionFilePath(void);
static std::string getCrashRecoveryFilePath(void);
static bool parseScript(IScriptEngine *engine, const char *name, IScriptEngine::RunMode mode);
// Hacky functions because we currently don't have versatile
// file dialogs
static IScriptEngine *tempEngine;
static void RunScript(const char *name)
{
parseScript(tempEngine, name, IScriptEngine::DebugOnError);
A_Resync();
}
static void DebugScript(const char *name)
{
parseScript(tempEngine, name, IScriptEngine::Debug);
}
static void SaveScript(const char *name)
{
A_saveScript(tempEngine, name);
}
//
//
/**
\fn HandleAction
\brief serialization of user event through gui
*/
typedef const char * (*getName)(uint32_t nb);
bool getScriptName(int action, int base,getName name,const char *ext,string &out )
{
if(action<base) return false;
action=action-base;
const char *p=name(action);
if(!p) return false;
out=string(p)+string(".")+string(ext);
return true;
}
void HandleAction (Action action)
{
admScopedMutex autolock(&singleThread); // make sure only one thread at a time calls this
ADM_warning("************ %s **************\n",getActionName(action));
// handle out of band actions
// independant load not loaded
//------------------------------------------------
if(action==ACT_RUN_SCRIPT)
{
GUI_FileSelRead(QT_TRANSLATE_NOOP("adm","Select script/project to run"), A_RunScript);
return;
}
if(action==ACT_SaveAsDefault)
{
A_saveDefaultSettings();
return;
}
if(action==ACT_LoadDefault)
{
A_loadDefaultSettings();
return;
}
if (action >= ACT_SCRIPT_ENGINE_FIRST && action < ACT_SCRIPT_ENGINE_LAST)
{
int engineIndex = (action - ACT_SCRIPT_ENGINE_FIRST) / 3;
int actionId = (action - ACT_SCRIPT_ENGINE_FIRST) % 3;
tempEngine = getScriptEngines()[engineIndex];
std::string ext=tempEngine->defaultFileExtension();
switch (actionId)
{
case 0:
GUI_FileSelReadExtension(QT_TRANSLATE_NOOP("adm","Select script to run"), ext.c_str(), RunScript);
break;
case 1:
GUI_FileSelReadExtension(QT_TRANSLATE_NOOP("adm","Select script to debug"), ext.c_str(), DebugScript);
break;
case 2:
GUI_FileSelWriteExtension(QT_TRANSLATE_NOOP("adm","Select script to save"), ext.c_str(), SaveScript);
UI_refreshCustomMenu();
break;
}
return;
}
if (action >= ACT_SCRIPT_ENGINE_SHELL_FIRST && action < ACT_SCRIPT_ENGINE_SHELL_LAST)
{
IScriptEngine *shellEngine = getScriptEngines()[action - ACT_SCRIPT_ENGINE_SHELL_FIRST];
if ((shellEngine->capabilities() & IScriptEngine::DebuggerShell) == IScriptEngine::DebuggerShell)
{
shellEngine->openDebuggerShell();
}
else
{
interactiveScript(shellEngine);
}
return;
}
switch (action)
{
case ACT_TimeShift:
A_TimeShift();
return;
case ACT_Goto:
brokenAct();
return;
case ACT_AVS_PROXY:
GUI_avsProxy();
return;
case ACT_BUILT_IN:
DIA_builtin();
return;
case ACT_RECENT0:
case ACT_RECENT1:
case ACT_RECENT2:
case ACT_RECENT3:
{
std::vector<std::string>name;
int rank;
name=prefs->get_lastfiles();
rank=(int)action-ACT_RECENT0;
ADM_assert(name[rank].size());
A_openVideo (name[rank].c_str());
return;
}
case ACT_RECENT_PROJECT0:
case ACT_RECENT_PROJECT1:
case ACT_RECENT_PROJECT2:
case ACT_RECENT_PROJECT3:
{
std::vector<std::string>name = prefs->get_lastprojectfiles();
int rank = (int)action - ACT_RECENT_PROJECT0;
ADM_assert(name[rank].size());
call_scriptEngine(name[rank].c_str());
A_Resync();
return;
}
case ACT_CLEAR_RECENT:
{
if(GUI_Question(QT_TRANSLATE_NOOP("adm","You are about to clear the list of recent files and projects. This can't be undone. Proceed?")))
{
prefs->clear_lastfiles();
prefs->clear_lastprojects();
prefs->save();
UI_updateRecentProjectMenu();
UI_updateRecentMenu(); // the order matters here
if(ADM_fileExist(getLastSessionFilePath().c_str()))
{
if(!ADM_eraseFile(getLastSessionFilePath().c_str()))
ADM_warning("Could not delete last editing state %s\n", getLastSessionFilePath().c_str());
}
}
return;
}
case ACT_VIDEO_CODEC_CONFIGURE:
videoEncoder6Configure();
return;
case ACT_ContainerConfigure:
{
if(!ADM_mx_getNbMuxers()) return;
int index=UI_GetCurrentFormat();
ADM_mux_configure(index);
return;
}
case ACT_ScriptShortcutConfig:
{
DIA_ScriptShortcutConfig();
UI_refreshCustomMenu();
return;
}
case ACT_VIDEO_CODEC_CHANGED:
{
int nw=UI_getCurrentVCodec();
videoEncoder6_SetCurrentEncoder(nw);
return;
}
case ACT_AUDIO_CODEC_CHANGED:
{
int nw=UI_getCurrentACodec();
audioCodecSetByIndex(0,nw);
return;
}
case ACT_PLUGIN_INFO:
DIA_pluginsInfo();
return;
case ACT_OPEN_APP_LOG:
GUI_OpenApplicationLog();
return;
case ACT_OPEN_APP_FOLDER:
GUI_OpenApplicationDataFolder();
return;
case ACT_ABOUT :
DIA_about( );
return;
case ACT_AUDIO_CODEC_CONFIGURE:
audioCodecConfigure(0);
return;
case ACT_AUDIO_FILTERS:
{
EditableAudioTrack *ed=video_body->getDefaultEditableAudioTrack();
if(ed)
{
double tempoHint = 1.0;
if(UI_getCurrentVCodec())
{
ADM_videoFilterChain *videoChain=createVideoFilterChain(0,ADM_NO_PTS);
ADM_coreVideoFilter * videoFilter=(*videoChain)[0];
FilterInfo *info=videoFilter->getInfo();
tempoHint = info->totalDuration;
int nb=videoChain->size();
videoFilter=(*videoChain)[nb-1];
info=videoFilter->getInfo();
tempoHint /= info->totalDuration;
destroyVideoFilterChain(videoChain);
//printf("[audioFilterConfigure] tempo hint: %f\n",tempoHint);
}
ed->audioEncodingConfig.audioFilterConfigure(tempoHint);
UI_setTimeShift(ed->audioEncodingConfig.shiftEnabled,ed->audioEncodingConfig.shiftInMs);
}
}
return;
case ACT_PREFERENCES:
if(playing) return;
if(DIA_Preferences())
{
ADM_info("Saving prefs\n");
prefs->save ();
UI_applySettings();
}
return;
case ACT_SavePref:
prefs->save ();
return;
case ACT_EXIT:
if(playing)
{
ADM_info("Stopping playback...\n");
GUI_PlayAvi(true);
}
ADM_info("Closing ui\n");
UI_closeGui();
if(video_body && avifileinfo)
A_saveSession();
if(video_body && video_body->canUndo())
video_body->clearUndoQueue();
return;
case ACT_RESTORE_SESSION:
if(playing) break;
A_checkSavedSession(true);
return;
default:
break;
}
if (playing) // only allow some action
{
switch (action)
{
case ACT_PlayAvi:
case ACT_StopAvi:
break;
default:
return;
}
}
// not playing,
// restict disabled uncoded actions
if ((int) action >= ACT_DUMMY)
{
GUI_Error_HIG (QT_TRANSLATE_NOOP("adm","Not coded in this version"), NULL);
return;
}
// allow only if avi loaded
if (!avifileinfo)
{
switch (action)
{
case ACT_JOG:
break;
case ACT_OPEN_VIDEO:
GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File..."), (SELFILE_CB *)A_openVideo);
break;
default:
break;
}
return;
}
// Dispatch actions, we have a file loaded
if(action>ACT_NAVIGATE_BEGIN && action < ACT_NAVIGATE_END)
{
return HandleAction_Navigate(action);
}
if(action>ACT_SAVE_BEGIN && action < ACT_SAVE_END)
{
return HandleAction_Save(action);
}
if(action > ACT_STAGED_BEGIN && action < ACT_STAGED_END)
{
return HandleAction_Staged(action);
}
switch (action)
{
case ACT_SAVE_PY_SCRIPT:
{
IScriptEngine *engine=getPythonScriptEngine();
if(!engine)
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","No engine"),QT_TRANSLATE_NOOP("adm","tinyPy script is not enabled in this build"));
break;
}
char fileName[1024];
if(FileSel_SelectWrite("Saving tinypy project",fileName,1000, NULL))
{
int l=strlen(fileName);
if(l>3)
{
char *tail=fileName+l-3;
if(tail[0]!='.'|| tail[1]!='p'|| tail[2]!='y')
strcat(fileName,".py");
}
A_saveScript(engine, fileName);
}
break;
}
break;
case ACT_JOG:
A_jog();
break;
case ACT_CLOSE:
GUI_close();
break;
case ACT_ZOOM_1_4:
case ACT_ZOOM_1_2:
case ACT_ZOOM_1_1:
case ACT_ZOOM_2_1:
//case ACT_ZOOM_4_1:
{
float currentZoom=(float)(2<<(action-ACT_ZOOM_1_4))/8;
UI_setBlockZoomChangesFlag(true);
admPreview::changePreviewZoom(currentZoom);
UI_setBlockZoomChangesFlag(false);
UI_resetZoomThreshold();
admPreview::samePicture();
break;
}
case ACT_ZOOM_FIT_IN:
UI_setZoomToFitIntoWindow();
break;
case ACT_AUDIO_SELECT_TRACK:
A_audioTrack();
break;
case ACT_OPEN_VIDEO:
GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File..."),(SELFILE_CB *) A_openVideo);
break;
case ACT_APPEND_VIDEO:
GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File to Append..."),(SELFILE_CB *) A_appendVideo);
break;
case ACT_VIDEO_PROPERTIES:
DIA_properties ();
break;
case ACT_PlayAvi:
GUI_PlayAvi ();
break;
#define TOGGLE_PREVIEW ADM_PREVIEW_OUTPUT
case ACT_PreviewChanged:
{
ADM_PREVIEW_MODE oldpreview = admPreview::getPreviewMode(),newpreview=(ADM_PREVIEW_MODE)UI_getCurrentPreview();
printf("Old preview %d, New preview mode : %d\n",oldpreview,newpreview);
if(oldpreview==newpreview)
{
return;
}
admPreview::stop();
admPreview::setPreviewMode(newpreview);
admPreview::start();
// admPreview::update(curframe);
}
break;
case ACT_StopAvi:
if (playing)
GUI_PlayAvi ();
break;
case ACT_MarkA:
case ACT_MarkB:
{
bool swapit = false;
uint64_t pts,markA,markB;
pts = admPreview::getCurrentPts();
if(!prefs->get(FEATURES_SWAP_IF_A_GREATER_THAN_B, &swapit))
swapit = true;
markA = video_body->getMarkerAPts();
markB = video_body->getMarkerBPts();
if(action == ACT_MarkA)
markA=pts;
else
markB=pts;
if(markA > markB)
{
if(swapit) // auto swap
{
uint64_t y = markA;
markA = markB;
markB = y;
}else
{
if(action == ACT_MarkA)
markB = video_body->getVideoDuration(); // reset B
else
markA = 0; // reset A
}
}
video_body->addToUndoQueue();
video_body->setMarkerAPts(markA);
video_body->setMarkerBPts(markB);
UI_setMarkers (markA, markB);
break;
}
case ACT_ResetMarkerA:
if(0 == video_body->getMarkerAPts())
break;
video_body->addToUndoQueue();
video_body->setMarkerAPts(0);
UI_setMarkers(0, video_body->getMarkerBPts());
break;
case ACT_ResetMarkerB:
{
uint64_t end = video_body->getVideoDuration();
if(end == video_body->getMarkerBPts())
break;
video_body->addToUndoQueue();
video_body->setMarkerBPts(end);
UI_setMarkers(video_body->getMarkerAPts(), end);
break;
}
case ACT_ResetMarkers:
{
if(!video_body->getMarkerAPts() && video_body->getMarkerBPts()==video_body->getVideoDuration())
break; // do nothing if the markers were not moved
video_body->addToUndoQueue();
A_ResetMarkers();
break;
}
case ACT_Copy:
{
uint64_t markA,markB;
markA=video_body->getMarkerAPts();
markB=video_body->getMarkerBPts();
if(markA>markB)
{
uint64_t p=markA;
markA=markB;
markB=p;
}
video_body->copyToClipBoard (markA,markB);
break;
}
case ACT_Paste:
{
uint64_t currentPts=video_body->getCurrentFramePts();
uint64_t d=video_body->getVideoDuration();
uint64_t markA,markB;
markA=video_body->getMarkerAPts();
markB=video_body->getMarkerBPts();
if(markA>markB)
{
uint64_t p=markA;
markA=markB;
markB=p;
}
video_body->addToUndoQueue();
// Special case if we are at the last frame
bool lastFrame=false;
uint64_t pts=video_body->getLastKeyFramePts();
if(pts!=ADM_NO_PTS && currentPts>=pts) // save time if we are not at or beyond the last keyframe
{
GUI_infiniteForward(pts);
uint64_t lastFramePts=video_body->getCurrentFramePts();
if(currentPts==lastFramePts) lastFrame=true;
}
if(lastFrame)
{
video_body->appendFromClipBoard();
}else
{
video_body->pasteFromClipBoard(currentPts);
}
ADM_cutPointType chk=ADM_EDITOR_CUT_POINT_KEY;
if(!UI_getCurrentVCodec())
chk=video_body->checkCutsAreOnIntra();
if(cutsNotOnIntraWarned!=(int)chk && chk!=ADM_EDITOR_CUT_POINT_KEY)
{
const char *alert;
bool ask=true;
switch(chk)
{
case ADM_EDITOR_CUT_POINT_NON_KEY:
alert=QT_TRANSLATE_NOOP("adm","The cut points of the pasted video are not on keyframes.\n"
"Video saved in copy mode will be corrupted at these points.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_BAD_POC:
alert=QT_TRANSLATE_NOOP("adm","This video uses non-IDR recovery points instead of IDR as keyframes. "
"Picture reordering information in the video stream is not reset at non-IDR frames. "
"The cut points of the pasted selection may result in playback interruption "
"due to reversed display order of frames if saved in copy mode.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_MISMATCH:
alert=QT_TRANSLATE_NOOP("adm","Codec or codec settings across a cut point of the pasted video do not match.\n"
"Playback of the video saved in copy mode may stop at this point.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_UNCHECKED:
alert=QT_TRANSLATE_NOOP("adm","Cut points of the pasted video could not be checked. "
"This indicates an issue with a source video, the state of editing or a bug in the program. "
"Please check the application log file or console output for details.\n"
"Try anyway?");
default:
ask=false; break;
}
if(ask && !GUI_Question(alert))
{
video_body->undo();
cutsNotOnIntraWarned=-1;
break;
}
cutsNotOnIntraWarned=(int)chk;
}
video_body->getVideoInfo (avifileinfo);
d=video_body->getVideoDuration()-d;
if(markA>currentPts)
{
markA+=d;
markB+=d;
}
if(markA<=currentPts && currentPts<=markB)
{
markB+=d;
}
video_body->setMarkerAPts(markA);
video_body->setMarkerBPts(markB);
A_Resync();
if(!lastFrame)
currentPts+=d;
if(!video_body->goToTimeVideo(currentPts))
{
// If seek fails, we may crash in admPreview::samePicture()
// due to _currentSegment and _currentPts going out of sync.
// Rewind to get on firm ground again.
A_Rewind();
}else
{
admPreview::samePicture();
GUI_setCurrentFrameAndTime();
}
}
break;
case ACT_Undo:
case ACT_Redo:
if (avifileinfo)
{
uint64_t currentPts=video_body->getCurrentFramePts();
bool r=false;
if(action==ACT_Undo)
{
r=video_body->undo();
}else
{
r=video_body->redo();
}
if(r)
{
video_body->getVideoInfo(avifileinfo);
A_Resync();
A_Rewind();
if(currentPts<=video_body->getVideoDuration())
r = GUI_GoToTime(currentPts);
else
r = false;
EditableAudioTrack *ed=video_body->getDefaultEditableAudioTrack();
if(ed && ed->edTrack)
ed->edTrack->goToTime(r? currentPts : 0); // update audio segment
}
}
break;
case ACT_ResetSegments:
if(avifileinfo)
if(GUI_Question(QT_TRANSLATE_NOOP("adm","Are you sure?")))
{
video_body->clearUndoQueue();
video_body->resetSeg();
video_body->getVideoInfo (avifileinfo);
A_Resync();
A_Rewind();
A_ResetMarkers();
// forget last project file
video_body->setProjectName("");
}
break;
case ACT_Delete:
case ACT_Cut:
{
uint64_t a=video_body->getMarkerAPts();
uint64_t b=video_body->getMarkerBPts();
uint64_t current=video_body->getCurrentFramePts();
uint64_t before=video_body->getVideoDuration();
if(a>b)
{
uint64_t p=a;
a=b;
b=p;
}
// Special case of B being beyond the last frame
bool lastFrame=false;
if(b==before)
{
lastFrame=true;
}else
{
uint64_t pts=video_body->getLastKeyFramePts();
if(pts!=ADM_NO_PTS && b>=pts) // don't waste time if B is before the last keyframe
{
GUI_infiniteForward(pts);
uint64_t lastFramePts=video_body->getCurrentFramePts();
if(b > lastFramePts) lastFrame=true; // B is beyond the last frame
}
}
if(!a && lastFrame)
{
if(action==ACT_Cut)
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cutting"),
QT_TRANSLATE_NOOP("adm","It is impossible to cut out the entire video. Please recheck the position of markers A and B."));
}else
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Deleting"),
QT_TRANSLATE_NOOP("adm","It is impossible to delete the entire video. Please recheck the position of markers A and B."));
}
break;
}
if(action==ACT_Cut)
{
video_body->copyToClipBoard(a,b);
}
video_body->addToUndoQueue();
bool result=false;
if(lastFrame)
result= video_body->truncate(a);
else
result= video_body->remove(a,b);
if(!result)
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cutting"),QT_TRANSLATE_NOOP("adm","Error while cutting out."));
break;
}
ADM_cutPointType chk=ADM_EDITOR_CUT_POINT_KEY;
if(!lastFrame && !UI_getCurrentVCodec())
chk=video_body->checkCutIsOnIntra(a);
if(cutsNotOnIntraWarned!=(int)chk && chk!=ADM_EDITOR_CUT_POINT_KEY)
{
const char *alert;
bool ask=true;
switch(chk)
{
case ADM_EDITOR_CUT_POINT_NON_KEY:
if(action==ACT_Cut)
alert=QT_TRANSLATE_NOOP("adm","The end point of the cut is not on a keyframe.\n"
"Video saved in copy mode will be corrupted at this point.\n"
"Proceed anyway?");
else
alert=QT_TRANSLATE_NOOP("adm","The end point of the deletion is not on a keyframe.\n"
"Video saved in copy mode will be corrupted at this point.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_BAD_POC:
if(action==ACT_Cut)
alert=QT_TRANSLATE_NOOP("adm","This video uses non-IDR recovery points instead of IDR as keyframes. "
"Picture reordering information in the video stream is not reset at non-IDR frames. "
"The chosen start and end points of the cut may result in playback interruption "
"due to reversed display order of frames if saved in copy mode.\n"
"Proceed anyway?");
else
alert=QT_TRANSLATE_NOOP("adm","This video uses non-IDR recovery points instead of IDR as keyframes. "
"Picture reordering information in the video stream is not reset at non-IDR frames. "
"The chosen start and end points of the deletion may result in playback interruption "
"due to reversed display order of frames if saved in copy mode.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_MISMATCH:
if(action==ACT_Cut)
alert=QT_TRANSLATE_NOOP("adm","Codec or codec settings across the cut do not match. "
"Playback of the video saved in copy mode may stop at this point.\n"
"Proceed anyway?");
else
alert=QT_TRANSLATE_NOOP("adm","Codec or codec settings across the deletion do not match. "
"Playback of the video saved in copy mode may stop at this point.\n"
"Proceed anyway?");
break;
case ADM_EDITOR_CUT_POINT_UNCHECKED:
alert=QT_TRANSLATE_NOOP("adm","Cut points could not be checked.\n"
"This indicates an issue with a source video, the state of editing or a bug in the program. "
"Please check the application log file or console output for details.\n"
"Proceed anyway?");
break;
default: ask=false; break;
}
if(ask && !GUI_Question(alert))
{
video_body->undo();
cutsNotOnIntraWarned=-1;
break;
}
cutsNotOnIntraWarned=(int)chk;
}
A_ResetMarkers();
A_Resync(); // total duration & stuff
// If A was at the first frame of a segment with start time in ref = 0 and ref video
// not starting at zero, the part of the segment before the first frame got deleted too,
// even if we didn't ask for that explicitely. We must adjust timestamps accordingly
// to avoid seek errors. This is not relevant for truncating.
uint64_t after=video_body->getVideoDuration();
uint64_t c=0;
if(!lastFrame)
c=before-after+a-b;
if(current>=a) // else current is before A, so nothing to do
{
if(current<b) // current is between A & B => A
{
current=a-c;
}else // current is after the removed chunk, adjust
{
current-=b-a+c;
}
}
if(current>=after) // the current frame is gone
{
// Can we go to the last keyframe before the cut?
current=after;
// current equal segment duration does not belong to this segment or
// to any segment, when it matches video duration, triggering rewind.
if(current && current != ADM_NO_PTS)
current--;
if(!video_body->getPKFramePTS(¤t))
{ // nope
A_Rewind();
break;
}
}
if(!video_body->goToTimeVideo(current))
{
// If seek fails, we may crash in admPreview::samePicture()
// due to _currentSegment and _currentPts going out of sync.
// Rewind to get on firm ground again.
A_Rewind();
}else
{
admPreview::samePicture();
GUI_setCurrentFrameAndTime();
}
}
break;
// set decoder option (post processing ...)
case ACT_DecoderOption:
video_body->setDecodeParam ( admPreview::getCurrentPts());
break;
case ACT_VIDEO_FILTERS:
GUI_handleVFilter();
break;
case ACT_VIDEO_PARTIAL_FILTERS:
GUI_handleVPartialFilter();
break;
case ACT_HEX_DUMP:
GUI_showCurrentFrameHex();
break;
case ACT_SIZE_DUMP:
GUI_showSize();
break;
case ACT_TimeShift:
A_TimeShift();
break;
default:
printf ("\n unhandled action %d\n", action);
ADM_assert (0);
return;
}
}
//_____________________________________________________________
//
// Open AVI File
// mode 0: normal
// mode 1: Suspicious
//_____________________________________________________________
/**
\fn A_openVideo
\brief Open (replace mode) a video
*/
int A_openVideo (const char *name)
{
uint8_t res;
char *longname;
uint32_t magic[4];
uint32_t id = 0;
cutsNotOnIntraWarned = false;
if (playing)
return 0;
/// check if name exists
FILE *fd;
fd = ADM_fopen(name, "rb");
if (!fd)
{
if (errno == EACCES)
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "Permission error"), QT_TRANSLATE_NOOP("adm", "Cannot open \"%s\"."), name);
}
if (errno == ENOENT)
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "File error"), QT_TRANSLATE_NOOP("adm", "\"%s\" does not exist."), name);
}
return 0;
}
if (4 == fread(magic, 4, 4, fd))
id = R32(magic[0]);
fclose(fd);
GUI_close(); // Cleanup
// DIA_StartBusy ();
/*
** we may get a relative path by cmdline
*/
longname = ADM_PathCanonize(name);
// check if avisynth input is given
if (fourCC::check(id, (uint8_t *) "ADAP"))
res = video_body->addFile(AVS_PROXY_DUMMY_FILE);
else
res = video_body->addFile(longname);
// forget last project file
video_body->setProjectName("");
if (res != ADM_OK) // an error occured
{
delete[] longname;
if (ADM_IGN == res)
{
return 0;
}
if (fourCC::check(id, (uint8_t *) "//AD"))