File: gap_video_index_creator.c

package info (click to toggle)
gimp-gap 2.6.0%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,656 kB
  • ctags: 7,358
  • sloc: ansic: 119,801; sh: 3,890; makefile: 932; lisp: 97; pascal: 55
file content (1632 lines) | stat: -rw-r--r-- 49,732 bytes parent folder | download | duplicates (4)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
/*  gap_video_index_creator.c
 *  utility plug-in for explicite creation of a video index for list of videofiles.
 *  plug-in by Wolfgang Hofer 2007/04/02
 *
 */

/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* Revision history
 *  (2007/04/02)  v1.0       hof: created
 */

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

#include "gap_libgapbase.h"
#include "gap_arr_dialog.h"
#include "gap_story_file.h"
#include "gap_story_syntax.h"
#include "gap_libgimpgap.h"

#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
/* Includes for GAP Video API */
#include <gap_vid_api.h>
#endif

#include "gap-intl.h"

/* Defines */
#define PLUG_IN_NAME        "plug_in_gap_video_index_creator"
#define PLUG_IN_HELP_ID     "plug-in-gap-video-index-creator"
#define PLUG_IN_PRINT_NAME  "Video Index Creator"
#define PLUG_IN_AUTHOR      "Wolfgang Hofer (hof@gimp.org)"
#define PLUG_IN_COPYRIGHT   "Wolfgang Hofer"


int gap_debug = 0;  /* 1 == print debug infos , 0 dont print debug infos */


#define QICK_MODE     0
#define SMART_MODE    1
#define FULLSCAN_MODE 2

#define GAP_VINDEX_PROGRESS_PLUG_IN_PROC  "plug_in_gap_vindex_creation_progress"
#define PROCESSING_STATUS_STRING "@@@PROCESSING"
#define DEFAULT_SMART_PERCENTAGE 15.0

typedef struct {
  gint32  seltrack;
  gchar   videofile[4000];
  gchar   preferred_decoder[100];
  gint32  mode;
  gdouble percentage_smart_mode;   /* range 1.0 upto 100.0 percent */
} VindexValues;


typedef struct GapVideoIndexCreatorProgressParams {  /* nickname vipp */
  GtkWidget    *shell_window;
  GtkListStore     *store;
  GtkWidget        *tv;
  GtkTreeSelection *sel;

  GtkWidget    *progress_bar_master;
  GtkWidget    *progress_bar_sub;
  gboolean      cancel_video_api;
  gboolean      cancel_immedeiate_request;
  gboolean      cancel_enabled_smart;
  gboolean      processing_finished;
  VindexValues *val_ptr;
  GapStoryVideoFileRef  *vref;
  GapStoryVideoFileRef  *vref_list;
  gint32        timertag;
  t_GVA_Handle  *gvahand;
  GTimeVal      startTime;
  GTimeVal      endTime;
  
  gint32        numberOfVideos;
  gint32        numberOfValidVideos;
  gint32        countVideos;

  gdouble       breakPercentage;
  gint32        breakFrames;
  
} GapVideoIndexCreatorProgressParams;

static VindexValues glob_vindex_vals =
{
    1               /* seltrack */
 , "Test.mpg"       /* videofile */
 , "libavformat"    /* preferred_decoder*/
 , FULLSCAN_MODE    /* mode */
 , DEFAULT_SMART_PERCENTAGE             /* percentage_smart_mode */
};


static void  query (void);
static void  run (const gchar *name,          /* name of plugin */
     gint nparams,               /* number of in-paramters */
     const GimpParam * param,    /* in-parameters */
     gint *nreturn_vals,         /* number of out-parameters */
     GimpParam ** return_vals);  /* out-parameters */

static void      p_do_processing (GapVideoIndexCreatorProgressParams *vipp);
static gboolean  p_check_videofile(const char *filename, gint32 seltrack
                                     , const char *preferred_decoder);
static void      p_create_video_index(const char *filename, gint32 seltrack
                                     , const char *preferred_decoder
                                     , GapVideoIndexCreatorProgressParams *vipp);
static void      p_set_vref_userdata(GapStoryVideoFileRef  *vref, const char *userdata);
static void      p_set_userdata_processingstatus_check_videofile(GapStoryVideoFileRef  *vref
                                     , GapVideoIndexCreatorProgressParams *vipp);

static void      p_make_all_video_index(const char *filename, gint32 seltrack
                                     , const char *preferred_decoder
                                     ,GapVideoIndexCreatorProgressParams *vipp
                                     );

static gint      p_vindex_dialog (VindexValues *val_ptr);

static void      p_vipp_dlg_destroy (GtkWidget *widget,
                    GapVideoIndexCreatorProgressParams *vipp_1);
static void      p_cancel_button_cb (GtkWidget *w,
                    GapVideoIndexCreatorProgressParams *vipp);

static void      p_elapsedTimeToString (GapVideoIndexCreatorProgressParams *vipp, char *timeString, gint sizeOfTimeString);
static void      p_print_vref_list (GapVideoIndexCreatorProgressParams *vipp, GapStoryVideoFileRef  *vref_list);


static void      p_tree_fill (GapVideoIndexCreatorProgressParams *vipp, GapStoryVideoFileRef  *vref_list);
static void      p_create_video_list_widget(GapVideoIndexCreatorProgressParams *vipp, GtkWidget *vbox);
static void      p_create_progress_window(GapVideoIndexCreatorProgressParams *vipp);
static void      on_timer_start(GapVideoIndexCreatorProgressParams *vipp);
static gboolean  p_vid_progress_callback(gdouble progress
                                  ,gpointer user_data
                                  );



/* Global Variables */
GimpPlugInInfo PLUG_IN_INFO =
{
  NULL,   /* init_proc  */
  NULL,   /* quit_proc  */
  query,  /* query_proc */
  run     /* run_proc   */
};

static GimpParamDef in_args[] = {
                  { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive"},
                  { GIMP_PDB_STRING,   "videofile", "name of videofile. this file can be a video or textfile containing"
                                                    " names of videofiles or a storyboard file containing references to videclips"},
                  { GIMP_PDB_INT32,    "seltrack", "selected video track number >= 1 (most videos have only one track)"},
                  { GIMP_PDB_STRING,   "preferred_decoder", "name of the decoder (libavformat or libmpeg3) "},
                  { GIMP_PDB_INT32,    "mode", "0 .. QICK_MODE, 1 .. SMART_MODE, 2 .. FULLSCAN_MODE"},
                  { GIMP_PDB_FLOAT,    "percentage_smart_mode", "1 to 100.0 perceent. stop verifying timecodes after the specidfeid percentage is scanned"
                                                   " and no critical errors were found so far. (only relevant in SMART_MODE)"}
  };


static gint global_number_in_args = G_N_ELEMENTS (in_args);


/* Functions */

MAIN ()

static void query (void)
{

  gimp_plugin_domain_register (GETTEXT_PACKAGE, LOCALEDIR);


  /* the actual installation of the adjust plugin */
  gimp_install_procedure (PLUG_IN_NAME,
                          "Create video index for videofile(s)",
                          "This plug-in creates a video index for the specified videofile, "
                          "index creation is skipped if a valid vide index already exists. "
                          "the specified videofilename may refere to a textfile that contains "
                          "a list of videofiles (one videofilename per line)."
                          "in this case all referred vidofiles are processed.",
                          PLUG_IN_AUTHOR,
                          PLUG_IN_COPYRIGHT,
                          GAP_VERSION_WITH_DATE,
                          N_("Video Index Creation..."),
                          NULL,
                          GIMP_PLUGIN,
                          global_number_in_args,
                          0,
                          in_args,
                          NULL);

  {
    /* Menu names */
    const char *menupath_toolbox_video_split = N_("<Toolbox>/Xtns/");

    //gimp_plugin_menu_branch_register("<Toolbox>", "Video");
    gimp_plugin_menu_register (PLUG_IN_NAME, menupath_toolbox_video_split);
  }
}  /* end query */

static void
run (const gchar *name,          /* name of plugin */
     gint nparams,               /* number of in-paramters */
     const GimpParam * param,    /* in-parameters */
     gint *nreturn_vals,         /* number of out-parameters */
     GimpParam ** return_vals)   /* out-parameters */
{
  const gchar *l_env;


  /* Get the runmode from the in-parameters */
  GimpRunMode run_mode = param[0].data.d_int32;

  /* status variable, use it to check for errors in invocation usualy only
     during non-interactive calling */
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;

  /* always return at least the status to the caller. */
  static GimpParam values[2];

  INIT_I18N();

  l_env = g_getenv("GAP_DEBUG");
  if(l_env != NULL)
  {
    if((*l_env != 'n') && (*l_env != 'N')) gap_debug = 1;
  }

  if(gap_debug) fprintf(stderr, "\n\nDEBUG: run %s\n", name);

  /* initialize the return of the status */
  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = status;
  values[1].type = GIMP_PDB_DRAWABLE;
  values[1].data.d_drawable = -1;
  *nreturn_vals = 1;
  *return_vals = values;


  /* how are we running today? */
  switch (run_mode)
  {
    case GIMP_RUN_INTERACTIVE:
      /* Possibly retrieve data from a previous run */
      gimp_get_data (PLUG_IN_NAME, &glob_vindex_vals);

      /* Get information from the dialog */
      if (p_vindex_dialog(&glob_vindex_vals) != 0)
                return;
      break;

    case GIMP_RUN_NONINTERACTIVE:
      /* check to see if invoked with the correct number of parameters */
      if (nparams == global_number_in_args)
      {

          if(param[1].data.d_string != NULL)
          {
            g_snprintf(glob_vindex_vals.videofile, sizeof(glob_vindex_vals.videofile)
                       , "%s"
                       , param[1].data.d_string
                       );
          }
          glob_vindex_vals.seltrack    = (gint) param[2].data.d_int32;
          if(param[3].data.d_string != NULL)
          {
            g_snprintf(glob_vindex_vals.preferred_decoder, sizeof(glob_vindex_vals.preferred_decoder)
                       , "%s"
                       , param[3].data.d_string
                       );
          }
          glob_vindex_vals.mode                     = (gint) param[4].data.d_int32;
          glob_vindex_vals.percentage_smart_mode    = (gint) param[5].data.d_float;
      }
      else
      {
        status = GIMP_PDB_CALLING_ERROR;
      }

      break;

    case GIMP_RUN_WITH_LAST_VALS:
      /* Possibly retrieve data from a previous run */
      gimp_get_data (PLUG_IN_NAME, &glob_vindex_vals);

      break;

    default:
      break;
  }

  if (status == GIMP_PDB_SUCCESS)
  {
    GapVideoIndexCreatorProgressParams vip_struct;
    GapVideoIndexCreatorProgressParams *vipp;
    
    vipp = &vip_struct;
    vipp->vref = NULL;
    vipp->vref_list = NULL;
    vipp->shell_window = NULL;
    vipp->gvahand = NULL;
    vipp->tv = NULL;
    vipp->progress_bar_master = NULL;
    vipp->progress_bar_sub = NULL;
    vipp->cancel_video_api = FALSE;
    vipp->timertag = -1;
    vipp->cancel_immedeiate_request = FALSE;

    vipp->val_ptr = &glob_vindex_vals;
    
    /* Store variable states for next run */
    if (run_mode == GIMP_RUN_INTERACTIVE)
    {
      gimp_set_data (PLUG_IN_NAME, &glob_vindex_vals, sizeof (VindexValues));
    }
    if (run_mode == GIMP_RUN_NONINTERACTIVE)
    {
      /* Run the main processing */
      p_do_processing(vipp);
    }
    else
    {
      /* creaate and open the progress dialog window
       + (dferred start main processing from the progres dialog)
       */
      p_create_progress_window(vipp);
    }
  }
  values[0].data.d_status = status;
}       /* end run */


/* ---------------
 * p_do_processing
 * ---------------
 */
static void
p_do_processing (GapVideoIndexCreatorProgressParams *vipp)
{
  p_make_all_video_index(vipp->val_ptr->videofile
                        ,vipp->val_ptr->seltrack
                        ,vipp->val_ptr->preferred_decoder
                        ,vipp
                        );
}       /* end p_do_processing */


/* --------------------------------
 * p_check_videofile
 * --------------------------------
 * check if specified filename is a videofile.
 *
 * return FALSE if specified video filename could not be opened as videofile.
 *
 */
static gboolean
p_check_videofile(const char *filename, gint32 seltrack
  , const char *preferred_decoder)
{
  t_GVA_Handle  *gvahand;

  /* first check the filename for known video extensions (.avi, .mpeg ...)
   * before attempt to open as video.
   * Note that the check_sig call of the gap_vid_api_gimp.c API implementation
   * allows access to anim frames via the videoapi.
   * But it does not make sense to detect anim frame images as video here, where
   * video index creation makes no sense and therefore is not supported.
   */

  if(gap_story_filename_is_videofile_by_ext(filename))
  {
    gvahand =  GVA_open_read_pref(filename
                                  , seltrack
                                  , 1 /* aud_track */
                                  , preferred_decoder
                                  , FALSE  /* use MMX if available (disable_mmx == FALSE) */
                                  );
    if(gvahand)
    {
      GVA_close(gvahand);
      return(TRUE);
    }
  }

  return(FALSE);

}  /* end p_check_videofile */


/* --------------------------------
 * p_is_valid_vindex_available
 * --------------------------------
 */
static gboolean
p_is_valid_vindex_available(t_GVA_Handle  *gvahand)
{
  gboolean    l_have_valid_vindex;

  l_have_valid_vindex = FALSE;
  if(gvahand->vindex)
  {
    if(gvahand->vindex->total_frames > 0)
    {
      l_have_valid_vindex = TRUE;
    }
  }
  
  return (l_have_valid_vindex);
}

/* --------------------------------
 * p_create_video_index
 * --------------------------------
 * check if specified filename is a videofile and if there is
 * a valid video index available for that videofile.
 * In case there is no valid video index, this procedure
 * will create the video index.
 *
 * return FALSE if specified video filename could not be opened as videofile.
 *
 */
static void
p_create_video_index(const char *filename, gint32 seltrack
  , const char *preferred_decoder,GapVideoIndexCreatorProgressParams *vipp)
{
  char *vindex_file;
  gboolean    l_have_valid_vindex;
  t_GVA_Handle  *gvahand;

  vipp->cancel_enabled_smart = FALSE;

  vindex_file = NULL;
  l_have_valid_vindex = FALSE;

  gvahand =  GVA_open_read_pref(filename
                                  , seltrack
                                  , 1 /* aud_track */
                                  , preferred_decoder
                                  , FALSE  /* use MMX if available (disable_mmx == FALSE) */
                                  );



  if(gvahand)
  {
    vipp->gvahand = gvahand;
    
    /* gvahand->emulate_seek = TRUE; */
    gvahand->do_gimp_progress = FALSE;

    gvahand->progress_cb_user_data = vipp;
    gvahand->fptr_progress_callback = p_vid_progress_callback;
    
    if ((vipp->val_ptr->mode == QICK_MODE)
    || (vipp->val_ptr->mode == SMART_MODE))
    {
      t_GVA_SeekSupport seekSupp;

      seekSupp = GVA_check_seek_support(gvahand);
      if (seekSupp == GVA_SEEKSUPP_NATIVE)
      {
        if(gap_debug)
        {
          printf("NATIVE SEEK seems to work for video:%s\n  SKIPPING video index creation due to QUICK mode.\n"
             , filename
             );
        }
        if (vipp->val_ptr->mode == QICK_MODE)
        {
          vipp->gvahand = NULL;
          GVA_close(gvahand);
          p_set_vref_userdata(vipp->vref, _("NO vindex created (QUICK)"));

          return;
        }
        vipp->cancel_enabled_smart = TRUE;
      }
    }
    
    /* get video index name */
    {
      t_GVA_DecoderElem *dec_elem;

      dec_elem = (t_GVA_DecoderElem *)gvahand->dec_elem;
      if(dec_elem->decoder_name)
      {
        vindex_file = GVA_build_videoindex_filename(filename
                                             ,seltrack  /* track */
                                             ,dec_elem->decoder_name
                                             );
      }
    }

    l_have_valid_vindex = p_is_valid_vindex_available(gvahand);

    if (vindex_file == NULL)
    {
      vindex_file = g_strdup("<null>");
    }

    if (l_have_valid_vindex)
    {
      p_set_vref_userdata(vipp->vref, _("vindex already OK"));
      if(gap_debug)
      {
        printf("VALID VIDEO INDEX found for video:%s\n  (index:%s)\n"
           , filename
           , vindex_file
           );
      }
    }
    else
    {
      if(gap_debug)
      {
        printf("CREATING VIDEO INDEX for video:%s\n  (index:%s)\n"
           , filename
           , vindex_file
           );
      }

      gvahand->create_vindex = TRUE;
      GVA_count_frames(gvahand);      /* here we CRREATE the vindex */

      if ((vipp->cancel_video_api != TRUE)
      && (TRUE == p_is_valid_vindex_available(gvahand)))
      {
        p_set_vref_userdata(vipp->vref, _("vindex created (FULLSCAN OK)"));
      }
      else
      {
        char *usrdata;
        if (vipp->val_ptr->mode == SMART_MODE)
        {
          if(g_file_test(vindex_file, G_FILE_TEST_EXISTS))
          {
            if(gap_debug)
            {
              printf("DELETE uncomplete vindex:%s\n", vindex_file);
            }
            g_remove(vindex_file);
          }

          usrdata = g_strdup_printf(_("NO vindex created (SMART %.1f%% %d frames)")
                                   ,(float)vipp->breakPercentage
                                   ,(int)vipp->breakFrames
                                   );
        }
        else
        {
          usrdata = g_strdup_printf(_("incomplete vindex created (%d frames)")
                                   ,(int)gvahand->frame_counter
                                   );
        }
        p_set_vref_userdata(vipp->vref, usrdata);
        g_free(usrdata);
      }
    }


    if (vindex_file != NULL)
    {
      g_free(vindex_file);
    }

    vipp->gvahand = NULL;
    GVA_close(gvahand);
  }


}  /* end p_create_video_index */

/* -----------------------------------------------
 * p_set_vref_userdata
 * -----------------------------------------------
 */
static void
p_set_vref_userdata(GapStoryVideoFileRef  *vref, const char *userdata)
{
  if(vref)
  {
    if(vref->userdata != NULL)
    {
      g_free(vref->userdata);
    }
    vref->userdata = NULL;
    if(userdata != NULL)
    {
      vref->userdata = g_strdup(userdata);
    }
  }

}  /* end p_set_vref_userdata */

/* -----------------------------------------------
 * p_set_userdata_processingstatus_check_videofile
 * -----------------------------------------------
 * set userdata to NULL for files that are NO videofiles
 * (vref elements with userdata NULL are skipped at further processing
 * but show up in the tv widget list)
 *
 * Videofiles that could be opened successfully get
 * the string "unprocessed" as userdata attribute.
 */
static void
p_set_userdata_processingstatus_check_videofile(GapStoryVideoFileRef  *vref_list, GapVideoIndexCreatorProgressParams *vipp)
{
  gboolean l_file_is_videofile;
  gint32  numberOfFiles;
  gint32  filesCount;
  GapStoryVideoFileRef  *vref;
  
  
  numberOfFiles = 0;
  vipp->numberOfVideos = 0;
  for(vref = vref_list; vref != NULL; vref = vref->next)
  {
    numberOfFiles++;
    vipp->numberOfVideos++;

  }

  filesCount = 0;
  for(vref = vref_list; vref != NULL; vref = vref->next)
  {
     if(gap_debug)
     {
        printf("filesCount:%d numberOfFiles:%d\n"
          ,(int)filesCount
          ,(int)numberOfFiles
          );
     }

    if(vipp->progress_bar_sub)
    {
      gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vipp->progress_bar_sub), _("counting and checking videofiles"));
      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_sub)
                                    , CLAMP(((gdouble)filesCount / (gdouble)numberOfFiles), 0.0, 1.0)
                                    );
      while(g_main_context_iteration(NULL, FALSE));
      
      
      if(vipp->cancel_immedeiate_request == TRUE)
      {
        p_vipp_dlg_destroy(NULL, vipp);
        return;
      }
      
    }
    filesCount++;
    
    l_file_is_videofile = FALSE;
    if(g_file_test(vref->videofile, G_FILE_TEST_EXISTS))
    {
      l_file_is_videofile = p_check_videofile(vref->videofile, vref->seltrack, vref->preferred_decoder);

      if(gap_debug)
      {
        printf("FILE_EXISTS:%s\n .. is_vieofile:%d\n"
          , vref->videofile
          , (int)l_file_is_videofile
          );
      }
    }

    if (l_file_is_videofile)
    {
      p_set_vref_userdata(vref, _("unprocessed"));
      vipp->numberOfValidVideos++;
    }
    else
    {
      p_set_vref_userdata(vref, NULL);
    }
  }


}  /* end p_set_userdata_processingstatus_check_videofile */



/* --------------------------------
 * p_make_all_video_index
 * --------------------------------
 * the specified filename shall be the name of a single videofile
 * or the name of a textfile containing names of videofiles
 * (one name per line)
 * This procedure processes all the specified videofilenames
 * by creating a videoindex for all videofiles that
 * do not yet have a valid videoindex.
 */
static void
p_make_all_video_index(const char *filename, gint32 seltrack
         , const char *preferred_decoder, GapVideoIndexCreatorProgressParams *vipp)
{
#define BUF_SIZE 4000
  FILE     *l_fp;
  char      l_buf[BUF_SIZE];
  gboolean  l_file_is_videofile;
  gint      l_video_count;
  
  GapStoryVideoFileRef  *vref_list;
  GapStoryVideoFileRef  *vref;

  vipp->numberOfVideos = 0;
  vipp->numberOfValidVideos = 0;
  vref_list = NULL;

 
  /* check if filename is a single viedeofile */
  l_file_is_videofile = p_check_videofile(filename, seltrack, preferred_decoder);
  if (l_file_is_videofile)
  {
    vipp->numberOfVideos = 1;
    vipp->numberOfValidVideos = 1;
    vref_list = p_new_GapStoryVideoFileRef(filename, seltrack, preferred_decoder
                                           , 1  /* max_ref_framenr */
                                           );
    p_set_vref_userdata(vref_list, _("unprocessed"));
  }
  else
  {
    /* 2nd attempt: if the filename does not directly refere to a videofile
     * it may be a textfile containing a list of videofile names.
     */
    l_fp = g_fopen(filename, "r");
    if(l_fp)
    {
      while(NULL != fgets(l_buf, BUF_SIZE-1, l_fp))
      {
        l_buf[BUF_SIZE-1] = '\0';


        /* chop trailing newline and whitespace */
        gap_file_chop_trailingspace_and_nl(&l_buf[0]);

        if((l_buf[0] == '\0')
        || (l_buf[0] == '#'))
        {
          continue;
        }

        if(gap_debug)
        {
          printf("LINE scanned:%s\n", &l_buf[0]);
        }
        
        if((strcmp(&l_buf[0], GAP_STBKEY_STB_HEADER) == 0)
        || (strcmp(&l_buf[0], GAP_STBKEY_CLIP_HEADER) == 0))
        {
          break;
        }

        vref = p_new_GapStoryVideoFileRef(&l_buf[0], seltrack, preferred_decoder
                                       , 1  /* max_ref_framenr */
                                       );
        /* add new elem at begin of list */
        vref->next =  vref_list;
        vref_list = vref;
      }

      fclose(l_fp);
      p_set_userdata_processingstatus_check_videofile(vref_list, vipp);
    }

  }

  
  if ((vref_list == NULL)
  || (vipp->numberOfValidVideos == 0))
  {
    GapStoryBoard *stb;
    
    /* 3rd attempt: check if file is a storyboard file that contains movie clip references
     * it may be a textfile containing a list of videofile names.
     */
    stb = gap_story_parse(filename);
    vref_list = gap_story_get_video_file_ref_list(stb);
    p_set_userdata_processingstatus_check_videofile(vref_list, vipp);
  }

  if (vipp->tv != NULL)
  {
    p_tree_fill (vipp, vref_list);
  }
  
  vipp->vref_list = vref_list;
  l_video_count = 0;
  for(vref = vref_list; (vref != NULL && vipp->numberOfVideos > 0); vref = vref->next)
  {
    vipp->cancel_video_api = FALSE;
    vipp->vref = vref;
    
    
    if(gap_debug)
    {
      printf("vref->videofile: %s\n  seltrack:%d preferred_decoder:%s"
             , vref->videofile
             , (int)vref->seltrack
             , vref->preferred_decoder
             );
    }


    if(vipp->progress_bar_master)
    {
      gchar  *message;
      gchar  *suffix;
      char timeString[20];

      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_master)
                                    , CLAMP(((gdouble)l_video_count / (gdouble)vipp->numberOfVideos), 0.0, 1.0)
                                    );
      g_get_current_time(&vipp->endTime);
      p_elapsedTimeToString (vipp, &timeString[0], sizeof(timeString));
      
      l_video_count++;
      
      suffix = g_strdup_printf(_("  %s (%d of %d)")
         ,timeString
         ,(int)l_video_count
         ,(int)vipp->numberOfVideos
         );

      message = gap_base_shorten_filename(NULL   /* prefix */
                        ,vref->videofile        /* filenamepart */
                        ,suffix                 /* suffix */
                        ,90                     /* l_max_chars */
                        );

      
      gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vipp->progress_bar_master), message);
      g_free(suffix);
      g_free(message);

    }

    if(vref->userdata != NULL)
    {
      p_set_vref_userdata(vref, PROCESSING_STATUS_STRING);
      if (vipp->tv != NULL)
      {
        p_tree_fill (vipp, vref_list);
      }
      p_create_video_index(vref->videofile, vref->seltrack, vref->preferred_decoder, vipp);
      if (vipp->tv != NULL)
      {
        p_tree_fill (vipp, vref_list);
      }
      if (vipp->cancel_immedeiate_request == TRUE)
      {
        if(gap_debug)
        {
          printf("CANCEL_IMMEDEIATE_REQUEST  vref->videofile: %s\n  seltrack:%d preferred_decoder:%s  userdata:%s"
                 , vref->videofile
                 , (int)vref->seltrack
                 , vref->preferred_decoder
                 , vref->userdata
                 );
        }
        vipp->processing_finished = TRUE;
        return;
      }
    }


    if(vipp->progress_bar_master)
    {
       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_master)
                                    , CLAMP(((gdouble)l_video_count / (gdouble)vipp->numberOfVideos), 0.0, 1.0)
                                    );
    }
  }
  
}  /* end p_make_all_video_index */


/* ------------------
 * p_vindex_dialog
 * ------------------
 * initial dialog to specify parameters.
 *
 *   return  0 .. OK
 *          -1 .. in case of Error or cancel
 */
static gint
p_vindex_dialog(VindexValues *val_ptr)
{
#define VR_DIALOG_ARGC 7
#define VR_DECODERS_SIZE 2
#define MODE_SIZE 3
  static GapArrArg  argv[VR_DIALOG_ARGC];
  gint ii;
  gint ii_seltrack;
  gint ii_preferred_decoder;
  gint ii_mode;
  gint ii_percentage_smart_mode;
  static char *radio_modes[VR_DECODERS_SIZE]  = {"libavformat", "libmpeg3" };
  static char *mode_args[MODE_SIZE]    = { "QUICK", "SMART", "FULLSCAN" };
  static char *mode_help[MODE_SIZE]    = { N_("Conditional video index creation, "
                                              " based on a few quick timcode probereads.\n"
                                              "Skip index creation if native seek seems possible\n"
                                              "\nWARNING: positioning via native seek may not work exact in case critical "
                                              "timecode steps were not detected in the quick test)")
                                         , N_("Conditional video index creation, "
                                              "based on probereads for the specified percentage of frames.\n"
                                              "Skip index creation if native seek seems possible "
                                              "and no critical timecode steps are detected in the probereads so far.\n"
                                              "\nWARNING: positioning via native seek may not work exact in case critical "
                                              "timecode steps were not detected in the probereads.")
                                         , N_("Create video index. Requires unconditional full scann of all frames."
                                              "Native seek is enabled only in case all timecodes are OK.")
                                         };

  gimp_ui_init ("vindex_progress", FALSE);
  
  
  ii=0;
  gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_FILESEL);
  argv[ii].label_txt = _("Videofile:");
  argv[ii].help_txt  = _("Name of a videofile to create a videoindex for."
                        " You also can enter the name of a textfile containing a list"
                        " of videofile names (one name per line) to create all videoindexes at once."
                        " a video index enables fast and exact positioning in the videofile.");
  argv[ii].text_buf_len = sizeof(val_ptr->videofile);
  argv[ii].text_buf_ret = &val_ptr->videofile[0];
  argv[ii].entry_width = 400;



  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_OPT_ENTRY); ii_preferred_decoder = ii;
  argv[ii].label_txt = _("Decoder:");
  argv[ii].help_txt  = _("Create video index based on the specified decoder library");
  argv[ii].radio_argc  = VR_DECODERS_SIZE;
  argv[ii].radio_argv = radio_modes;
  argv[ii].radio_ret  = 0;
  argv[ii].has_default = TRUE;
  argv[ii].radio_default = 0;
  argv[ii].text_buf_ret = &val_ptr->preferred_decoder[0];
  argv[ii].text_buf_len = sizeof(val_ptr->preferred_decoder);
  argv[ii].text_buf_default = g_strdup("libavformat\0");


  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_INT); ii_seltrack = ii;
  argv[ii].constraint = TRUE;
  argv[ii].label_txt = _("Track:");
  argv[ii].help_txt  = _("Select video track");
  argv[ii].int_min   = (gint)1;
  argv[ii].int_max   = (gint)100;
  argv[ii].int_ret   = (gint)glob_vindex_vals.seltrack;
  argv[ii].entry_width = 60;
  argv[ii].has_default = TRUE;
  argv[ii].int_default = 1;


  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_RADIO); ii_mode = ii;
  argv[ii].constraint = TRUE;
  argv[ii].label_txt = _("Mode:");
  argv[ii].help_txt  = _("operation mode");
  argv[ii].radio_argc  = (gint)MODE_SIZE;
  argv[ii].radio_argv   = mode_args;
  argv[ii].radio_help_argv = mode_help;
  argv[ii].radio_ret   = (gint)glob_vindex_vals.mode;
  argv[ii].has_default = TRUE;
  argv[ii].radio_default  = FULLSCAN_MODE;

  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_FLT); ii_percentage_smart_mode = ii;
  argv[ii].constraint = TRUE;
  argv[ii].label_txt = _("Percentage:");
  argv[ii].help_txt  = _("stop scann after percentage reached and no unplausible timecode was detected so far (only relevant in smart mode)");
  argv[ii].flt_min   =  1.0;
  argv[ii].flt_max   = (gint)100.0;
  argv[ii].flt_step  =  1.0;
  argv[ii].flt_ret   = (gint)glob_vindex_vals.percentage_smart_mode;
  argv[ii].entry_width = 60;
  argv[ii].has_default = TRUE;
  argv[ii].flt_default = DEFAULT_SMART_PERCENTAGE;



  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_DEFAULT_BUTTON);
  argv[ii].label_txt = _("Default");
  argv[ii].help_txt  = _("Reset all parameters to default values");

  ii++; gap_arr_arg_init(&argv[ii], GAP_ARR_WGT_HELP_BUTTON);
  argv[ii].help_id = PLUG_IN_HELP_ID;

  if(TRUE == gap_arr_ok_cancel_dialog(_("Video Index Creation"),
                            _("Settings :"),
                            VR_DIALOG_ARGC, argv))
  {
      val_ptr->seltrack = (gint)(argv[ii_seltrack].int_ret);
      val_ptr->mode = (gint)(argv[ii_mode].int_ret);
      val_ptr->percentage_smart_mode = (gdouble)(argv[ii_percentage_smart_mode].flt_ret);
      
      if(gap_debug)
      {
        printf("p_vindex_dialog: PRAMETERS entered via dialog:\n");
        printf("  videofile: %s\n", &val_ptr->videofile[0]);
        printf("  decoder: %s\n", &val_ptr->preferred_decoder[0]);
        printf("  seltrack: %d\n", (int)val_ptr->seltrack);
        printf("  mode: %d\n", (int)val_ptr->mode);
        printf("  percentage_smart_mode: %f\n", (float)val_ptr->percentage_smart_mode);
      }
      return 0;
  }
  else
  {
      return -1;
  }
}               /* end p_vindex_dialog */


/* ========================================== progress dialog procedures ===================== */

/* ---------------------------------
 * p_vipp_dlg_destroy
 * ---------------------------------
 */
static void
p_vipp_dlg_destroy (GtkWidget *widget,
                 GapVideoIndexCreatorProgressParams *vipp_1)
{
  GtkWidget *dialog;
  GapVideoIndexCreatorProgressParams *vipp;

  dialog = NULL;
  
  if(vipp_1 != NULL)
  {
    vipp = vipp_1;
  }
  else
  {
    vipp = (GapVideoIndexCreatorProgressParams *)g_object_get_data(G_OBJECT(widget), "vipp");
  }
  
  
  if(vipp)
  {
    dialog = vipp->shell_window;
    if(dialog)
    {
      vipp->shell_window = NULL;
      vipp->tv = NULL;
      vipp->progress_bar_master = NULL;
      vipp->progress_bar_sub = NULL;
      vipp->cancel_video_api = TRUE;
      vipp->cancel_immedeiate_request = TRUE;
      gtk_widget_destroy (dialog);
    }
  }

  gtk_main_quit ();

}  /* end p_vipp_dlg_destroy */

/* -----------------------------
 * p_cancel_button_cb
 * -----------------------------
 */
static void
p_cancel_button_cb (GtkWidget *w,
                    GapVideoIndexCreatorProgressParams *vipp)
{

  if(gap_debug)
  {
    printf("VINDEX-PROGRESS-CANCEL BUTTON clicked\n");
  }

  if(vipp)
  {
    vipp->cancel_immedeiate_request = TRUE;
    if (vipp->processing_finished)
    {
      p_vipp_dlg_destroy(NULL, vipp);
    }
  }

}  /* end p_cancel_button_cb */


/* ----------------------------
 * p_elapsedTimeToString
 * ----------------------------
 */
static void
p_elapsedTimeToString (GapVideoIndexCreatorProgressParams *vipp, char *timeString, gint sizeOfTimeString)
{
  glong  secondsElapsed;
  glong  microSecondsElapsed;
  gint32 tmsec;

  secondsElapsed = vipp->endTime.tv_sec - vipp->startTime.tv_sec;
  microSecondsElapsed = vipp->endTime.tv_usec - vipp->startTime.tv_usec;
  tmsec = secondsElapsed * 1000 + ((microSecondsElapsed /1000) % 1000);
  gap_timeconv_msecs_to_timestr(tmsec, timeString, sizeOfTimeString);
}  /* end  p_elapsedTimeToString */


/* ----------------------------
 * p_print_vref_list
 * ----------------------------
 * print the vref_list to stdout
 */
static void
p_print_vref_list (GapVideoIndexCreatorProgressParams *vipp, GapStoryVideoFileRef  *vref_list)
{
  gint          count_elem;
  GapStoryVideoFileRef  *vref;

  printf("\n\n----------------------------------------------\n");
  printf("Video index creation processing results:\n");
  printf("----------------------------------------------\n");

  count_elem = 0;
  for(vref = vref_list; vref != NULL; vref = (GapStoryVideoFileRef *) vref->next)
  {
     gchar *label;
     gchar *video_filename;
     gchar *processing_status;

     label = g_strdup_printf("%3d.", (int)count_elem +1);
     video_filename = gap_base_shorten_filename(NULL   /* prefix */
                        ,vref->videofile        /* filenamepart */
                        ,NULL                   /* suffix */
                        ,90                     /* l_max_chars */
                        );
     if (vref->userdata == NULL)
     {
       processing_status = g_strdup(_(" ** no video **"));
     }
     else
     {
       if (strcmp(PROCESSING_STATUS_STRING, vref->userdata) == 0)
       {
         processing_status = g_strdup(_("processing not finished"));
        }
       else
       {
         processing_status = g_strdup(vref->userdata);
       }
     }

     printf("%3s %-90.90s %s\n"
            , label             /* visible number starting at 1 */
            , video_filename
            , processing_status
            );


     g_free (label);
     g_free (video_filename);
     g_free (processing_status);
     
     count_elem++;
  }

  {
    char timeString[20];

    p_elapsedTimeToString (vipp, &timeString[0], sizeof(timeString));
    
    printf("\nElapsed Time  %s\n", &timeString[0]);
    printf("----------------------------------------------\n");
  }
}  /* end p_print_vref_list */


/* ----------------------------
 * p_tree_fill
 * ----------------------------
 * fill videofile names into the treeview
 */
static void
p_tree_fill (GapVideoIndexCreatorProgressParams *vipp, GapStoryVideoFileRef  *vref_list)
{
  GtkTreeIter   iter;
  GtkTreePath  *treePathCurrent;
  GapStoryVideoFileRef  *vref;
  gint          count_elem;


  vipp->store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
  gtk_tree_view_set_model (GTK_TREE_VIEW (vipp->tv)
                          ,GTK_TREE_MODEL (vipp->store)
                          );
  g_object_unref (vipp->store);

  count_elem = 0;
  treePathCurrent = NULL;
  for(vref = vref_list; vref != NULL; vref = (GapStoryVideoFileRef *) vref->next)
  {
     gchar *numtxt;
     gchar *label;
     gchar *video_filename;
     gchar *processing_status;
     gboolean      currentFlag;

     currentFlag = FALSE;

     label = g_strdup_printf("%3d.", (int)count_elem +1);
     numtxt = g_strdup_printf("%d", (int)count_elem);
     video_filename = gap_base_shorten_filename(NULL   /* prefix */
                        ,vref->videofile        /* filenamepart */
                        ,NULL                   /* suffix */
                        ,90                     /* l_max_chars */
                        );
     if (vref->userdata == NULL)
     {
       processing_status = g_strdup(_(" ** no video **"));
     }
     else
     {
       if (strcmp(PROCESSING_STATUS_STRING, vref->userdata) == 0)
       {
         processing_status = g_strdup(_("processing in progress"));
         currentFlag = TRUE;
        }
       else
       {
         processing_status = g_strdup(vref->userdata);
       }
     }

     gtk_list_store_append (vipp->store, &iter);
     gtk_list_store_set (vipp->store, &iter
                        ,0, numtxt            /* internal invisible number starting at 0 */
                        ,1, label             /* visible number starting at 1 */
                        ,2, video_filename
                        ,3, processing_status
                        ,-1);

     if(currentFlag == TRUE)
     {
         treePathCurrent = gtk_tree_model_get_path (GTK_TREE_MODEL (vipp->store), &iter);
     }

     g_free (numtxt);
     g_free (label);
     g_free (video_filename);
     g_free (processing_status);
     
     count_elem++;
  }

  if (count_elem == 0)
  {
    gtk_list_store_append (vipp->store, &iter);

    gtk_list_store_set (vipp->store, &iter
                       ,0, "-1"
                       ,1, " "
                       ,2, _("** Empty **")
                       ,3, " "
                       ,-1);
  }

  gtk_tree_model_get_iter_first (GTK_TREE_MODEL (vipp->store), &iter);
  gtk_tree_selection_select_iter (vipp->sel, &iter);
  
  gtk_tree_selection_unselect_all(vipp->sel);
  if(treePathCurrent != NULL)
  {
     gtk_tree_view_set_cursor(vipp->tv
                             ,treePathCurrent
                             ,NULL    /* focus_column */
                             ,FALSE   /* start_editing */
                             );

  }
}  /* end p_tree_fill */


/* -----------------------------
 * p_create_video_list_widget
 * -----------------------------
 */
void
p_create_video_list_widget(GapVideoIndexCreatorProgressParams *vipp, GtkWidget *vbox)
{
  GtkWidget       *scrolled_window;
  GtkCellRenderer *renderer;

  /* list : list in a scrolled_win */

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
                                       GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_ALWAYS);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);

  vipp->tv = gtk_tree_view_new ();

  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_renderer_text_set_fixed_height_from_font
    (GTK_CELL_RENDERER_TEXT (renderer), 1);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vipp->tv),
                                               -1, _("Nr"),
                                               renderer,
                                               "text", 1,
                                               NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vipp->tv),
                                               -1, _("videofile"),
                                               renderer,
                                               "text", 2,
                                               NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vipp->tv),
                                               -1, _("Status"),
                                               renderer,
                                               "text", 3,
                                               NULL);
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (vipp->tv), TRUE);

  gtk_widget_set_size_request (vipp->tv, 840 /*WIDTH*/, 250 /*HEIGHT*/);
  gtk_container_add (GTK_CONTAINER (scrolled_window), vipp->tv);
  gtk_widget_show (vipp->tv);


  vipp->sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (vipp->tv));
//   g_signal_connect (vipp->sel, "changed",
//                     G_CALLBACK (p_procedure_select_callback), vipp);


}  /* end p_create_video_list_widget */


/* -----------------------------
 * p_create_progress_window
 * -----------------------------
 */
static void
p_create_progress_window(GapVideoIndexCreatorProgressParams *vipp)
{
  GtkWidget *dialog;
  GtkWidget  *vbox;
  GtkWidget  *hbox;

  /* Init UI  */
  gimp_ui_init ("vindex_progress", FALSE);
  gap_stock_init();


  /*  The Storyboard dialog  */
  vipp->progress_bar_master = NULL;
  vipp->progress_bar_sub = NULL;



  /*  The dialog and main vbox  */
  /* the help_id is passed as NULL to avoid creation of the HELP button
   * (the Help Button would be the only button in the action area and results
   *  in creating an extra row
   *  additional note: the Storyboard dialog provides
   *  Help via Menu-Item
   */
  dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (dialog), _("Video Index Creation Progress"));
  gtk_window_set_role (GTK_WINDOW (dialog), "vindex-creator-progress");

  g_object_set_data (G_OBJECT (dialog), "vipp"
                         , (gpointer)vipp);

  g_signal_connect (dialog, "destroy",
                    G_CALLBACK (p_vipp_dlg_destroy),
                    vipp);

  gimp_help_connect (dialog, gimp_standard_help_func, GAP_VINDEX_PROGRESS_PLUG_IN_PROC, NULL);

  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (dialog), vbox);
  gtk_widget_show (vbox);


  vipp->shell_window = dialog;

  p_create_video_list_widget(vipp, vbox);

  /* the hbox */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  /*  The Video ProgressBar */
  {
    GtkWidget *button;
    GtkWidget *progress_bar;
    GtkWidget *vbox_progress;

    vbox_progress = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (vbox_progress);

    progress_bar = gtk_progress_bar_new ();
    vipp->progress_bar_master = progress_bar;
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), " ");
    gtk_widget_show (progress_bar);
    gtk_box_pack_start (GTK_BOX (vbox_progress), progress_bar, TRUE, TRUE, 0);

    progress_bar = gtk_progress_bar_new ();
    vipp->progress_bar_sub = progress_bar;
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), " ");
    gtk_widget_show (progress_bar);
    gtk_box_pack_start (GTK_BOX (vbox_progress), progress_bar, TRUE, TRUE, 0);


    gtk_box_pack_start (GTK_BOX (hbox), vbox_progress, TRUE, TRUE, 0);



    button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
    gtk_widget_show (button);
    gimp_help_set_help_data (button
                   , _("Cancel video access if in progress and disable automatic videothumbnails")
                   , NULL);
    g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (p_cancel_button_cb),
                    vipp);
  }



  vipp->timertag = (gint32) g_timeout_add(200  /* millisecs*/
                                     , (GtkFunction)on_timer_start, vipp);


  gtk_widget_show (dialog);


  gtk_main ();
  gdk_flush ();

}  /* end p_create_progress_window */


/* -----------------------------
 * on_timer_start
 * -----------------------------
 * This procedure triggers processing start
 * in interactive run modes.
 */
static void
on_timer_start(GapVideoIndexCreatorProgressParams *vipp)
{
  if(gap_debug)
  {
    printf("on_timer_start\n");
  }

  
  if(vipp)
  {
    if(vipp->timertag >= 0)
    {
      g_source_remove(vipp->timertag);
      vipp->timertag = -1;
    }
    vipp->processing_finished = FALSE;
    if (vipp->cancel_immedeiate_request == TRUE)
    {
      if(gap_debug)
      {
        printf("pending CANCEL_IMMEDEIATE_REQUEST\n");
      }
    }
    else
    {
      g_get_current_time(&vipp->startTime);
      p_do_processing(vipp);
      g_get_current_time(&vipp->endTime);
    }
    if(vipp->progress_bar_master)
    {
       if(vipp->cancel_immedeiate_request != TRUE)
       {
         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_master), 1.0);
       }
    }
    if(vipp->progress_bar_sub)
    {
       if(vipp->cancel_immedeiate_request == TRUE)
       {
         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vipp->progress_bar_sub), _("processing cancelled"));
       }
       else
       {
         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vipp->progress_bar_sub), _("processing finished"));
         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_sub), 1.0);
       }
    }
    vipp->processing_finished = TRUE;
    
    if(vipp->vref_list != NULL)
    {
      p_print_vref_list(vipp, vipp->vref_list);
    }
    
  }
}  /* end on_timer_start */

/* --------------------------------
 * p_vid_progress_callback
 * --------------------------------
 * return: TRUE: cancel videoapi immediate
 *         FALSE: continue
 */
static gboolean
p_vid_progress_callback(gdouble progress
                       ,gpointer user_data
                       )
{
  GapVideoIndexCreatorProgressParams *vipp;
  gboolean critical_timecode_found;
  gdouble currentPercentageLimit;
  
  

  vipp = (GapVideoIndexCreatorProgressParams *)user_data;
  if(vipp == NULL) { return (TRUE); }
  
  critical_timecode_found = FALSE;
  
  if (vipp->gvahand != NULL)
  {
    critical_timecode_found = vipp->gvahand->critical_timecodesteps_found;
  }
  
  if(vipp->progress_bar_sub != NULL)
  {
    char *message;
    
    if(gap_debug)
    {
      printf("p_vid_progress_callback progress:%f\n", progress);
    }
    
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vipp->progress_bar_sub), CLAMP(progress, 0.0, 1.0));
    switch (vipp->val_ptr->mode)
    {
      case QICK_MODE:
        message = g_strdup_printf(_("Quick check %0.3f %%"), progress * 100.0);
        break;
      case SMART_MODE:
        if (critical_timecode_found == TRUE)
        {
          currentPercentageLimit = 100.0;
        }
        else
        {
          currentPercentageLimit = vipp->val_ptr->percentage_smart_mode;
        }
        message = g_strdup_printf(_("Smart check %0.3f %% (of %0.3f %%)")
                                , progress * 100.0
                                , currentPercentageLimit
                                );
        break;
      case FULLSCAN_MODE:
        message = g_strdup_printf(_("Creating video index %0.3f %%"), progress * 100.0);
        break;
      default:
        message = g_strdup_printf("%0.3f %%", progress * 100.0);
        break;  
       
    }
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vipp->progress_bar_sub), message);
    g_free(message);
  }
  
  if ((vipp->val_ptr->mode == SMART_MODE)
  && (vipp->cancel_enabled_smart == TRUE))
  {
    if ((progress * 100.0 > vipp->val_ptr->percentage_smart_mode)
    && (critical_timecode_found == FALSE))
    {
      if(gap_debug)
      {
        printf("SMART_MODE cancel at progress: %.3f, (limit: %.3f)\n"
          ,(float)progress
          ,(float)vipp->val_ptr->percentage_smart_mode
          );
      }
      vipp->cancel_video_api = TRUE;
      vipp->breakPercentage = progress * 100.0;
      vipp->breakFrames = vipp->gvahand->frame_counter;
    }
  }


  /* g_main_context_iteration makes sure that
   *  gtk does refresh widgets,  and react on events while the videoapi
   *  is busy with searching for the next frame.
   */
  while(g_main_context_iteration(NULL, FALSE));

  return(vipp->cancel_video_api || vipp->cancel_immedeiate_request);

  /* return (TRUE); */ /* cancel video api if playback was stopped */

}  /* end p_vid_progress_callback */