Check-in [f27d22789e]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add exit handler to tkvlc
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f27d22789ebb7f3368872fbf127c0d5a7305a597
User & Date: chw 2019-03-13 09:10:55
References
2019-03-14
04:55
more tear down tweaks for [64ef0979ba] and [f27d22789e] check-in: 222bf6cb1c user: chw tags: trunk
Context
2019-03-13
09:12
some tear down tweaks when using RPI/KMSDRM video drivers check-in: 64ef0979ba user: chw tags: trunk
09:10
add exit handler to tkvlc check-in: f27d22789e user: chw tags: trunk
01:14
proper handle InputOnly windows in sdltk check-in: f50d38a336 user: chw tags: trunk
Changes

Changes to undroid/tkvlc/generic/tkvlc.c.

93
94
95
96
97
98
99

100
101
102
103
104
105
106
...
389
390
391
392
393
394
395



396
397
398
399
400
401
402
...
470
471
472
473
474
475
476



477
478
479
480
481
482
483
...
557
558
559
560
561
562
563



564
565
566
567
568
569
570
....
1116
1117
1118
1119
1120
1121
1122




























1123
1124
1125
1126
1127
1128
1129
....
1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
....
1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186
....
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
typedef struct libVLCData {
  libvlc_instance_t *vlc_inst;		/* libvlc library instance data. */
  Tcl_Interp *interp;			/* Associated Tcl interpreter. */
  Tcl_Command cmd;			/* Tcl command token. */
  libvlc_media_player_t *media_player;	/* libvlc media player. */
  int repeat;				/* If true, replay media. */
  int tk_checked;			/* True when Tk available. */

  Tcl_WideInt window_id;		/* Platform handle, if photo unused. */
  Tcl_Obj *file_name;			/* Filename of last opened media. */
  Tcl_Obj *photo_name;			/* Name of photo image or NULL. */
  int width, height;			/* Width and height for photo image. */
  Tcl_ThreadId tid;			/* Thread identifier of interpreter. */
  Tcl_Mutex ev_lock;			/* Mutex for ev_queue. */
  libVLCEvent *ev_queue;		/* Queued events minus frame events. */
................................................................................

static void libVLChandler(const struct libvlc_event_t *ev, void *clientData)
{
  libVLCData *p = (libVLCData *) clientData;
  libVLCEvent *e;
  int type;




  if (p->media_player == NULL) {
    return;
  }
  switch (ev->type) {
    case libvlc_MediaPlayerMediaChanged:
      type = EV_MEDIA_CHANGED;
      break;
................................................................................
  int docb = 0;

  if (f == NULL) {
    /* about to tear down media player */
    return 1;
  }
  p = f->p;



  interp = p->interp;
  photo = Tk_FindPhoto(interp, Tcl_GetString(p->photo_name));
  if (photo == NULL) {
    libvlc_media_player_stop(p->media_player);
  } else if (libvlc_media_player_is_playing(p->media_player) == 1) {
    Tk_PhotoImageBlock blk;

................................................................................

static void libVLCdisplay(void *clientData, void *picture)
{
  libVLCData *p = (libVLCData *) clientData;
  libVLCFrame *f = (libVLCFrame *) picture;
  libVLCEvent *e;




  if ((f == &p->frames[0] && p->frames[1].busy) ||
      (f == &p->frames[1] && p->frames[0].busy)) {
    /* other frame buffer still in use, drop frame */
    return;
  }
  e = (libVLCEvent *) ckalloc(sizeof(*e));
  e->header.proc = libVLCready;
................................................................................
  Tcl_MutexFinalize(&p->ev_lock);
  ckfree(p);
}

/*
 *----------------------------------------------------------------------
 *




























 * libVLCObjCmdDeleted --
 *
 *	Destructor of libvlc media player object and command.
 *
 * Results:
 *	None.
 *
................................................................................
 *	Resources are released.
 *
 *----------------------------------------------------------------------
 */

static void libVLCObjCmdDeleted(ClientData clientData)
{

  Tcl_EventuallyFree((char *) clientData, FreeData);
}

/*
 *----------------------------------------------------------------------
 *
 * TKVLC_INIT --
................................................................................
  }
  p = (libVLCData *) ckalloc(sizeof(*p));
  p->vlc_inst = NULL;
  p->interp = interp;
  p->media_player = NULL;
  p->repeat = 0;
  p->tk_checked = 0;

  p->window_id = 0;
  p->file_name = NULL;
  p->photo_name = NULL;
  p->width = p->height = 0;
  p->tid = Tcl_GetCurrentThread();
  p->ev_lock = NULL;
  p->ev_queue = NULL;
................................................................................
    libvlc_event_attach(em, libvlc_MediaPlayerUnmuted, libVLChandler, p);
    libvlc_event_attach(em, libvlc_MediaPlayerAudioVolume, libVLChandler, p);
    libvlc_event_attach(em, libvlc_MediaPlayerAudioDevice, libVLChandler, p);
  }
  zArg = Tcl_GetStringFromObj(objv[1], 0);
  p->cmd = Tcl_CreateObjCommand(interp, zArg, libVLCObjCmd, (ClientData) p,
				libVLCObjCmdDeleted);

  return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tkvlc_Init --







>







 







>
>
>







 







>
>
>







 







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>







 







>







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
....
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
....
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
....
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
....
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
typedef struct libVLCData {
  libvlc_instance_t *vlc_inst;		/* libvlc library instance data. */
  Tcl_Interp *interp;			/* Associated Tcl interpreter. */
  Tcl_Command cmd;			/* Tcl command token. */
  libvlc_media_player_t *media_player;	/* libvlc media player. */
  int repeat;				/* If true, replay media. */
  int tk_checked;			/* True when Tk available. */
  int exit_called;			/* True when finalizing. */
  Tcl_WideInt window_id;		/* Platform handle, if photo unused. */
  Tcl_Obj *file_name;			/* Filename of last opened media. */
  Tcl_Obj *photo_name;			/* Name of photo image or NULL. */
  int width, height;			/* Width and height for photo image. */
  Tcl_ThreadId tid;			/* Thread identifier of interpreter. */
  Tcl_Mutex ev_lock;			/* Mutex for ev_queue. */
  libVLCEvent *ev_queue;		/* Queued events minus frame events. */
................................................................................

static void libVLChandler(const struct libvlc_event_t *ev, void *clientData)
{
  libVLCData *p = (libVLCData *) clientData;
  libVLCEvent *e;
  int type;

  if (p->exit_called == NULL) {
    return;
  }
  if (p->media_player == NULL) {
    return;
  }
  switch (ev->type) {
    case libvlc_MediaPlayerMediaChanged:
      type = EV_MEDIA_CHANGED;
      break;
................................................................................
  int docb = 0;

  if (f == NULL) {
    /* about to tear down media player */
    return 1;
  }
  p = f->p;
  if (p->exit_called) {
    return 1;
  }
  interp = p->interp;
  photo = Tk_FindPhoto(interp, Tcl_GetString(p->photo_name));
  if (photo == NULL) {
    libvlc_media_player_stop(p->media_player);
  } else if (libvlc_media_player_is_playing(p->media_player) == 1) {
    Tk_PhotoImageBlock blk;

................................................................................

static void libVLCdisplay(void *clientData, void *picture)
{
  libVLCData *p = (libVLCData *) clientData;
  libVLCFrame *f = (libVLCFrame *) picture;
  libVLCEvent *e;

  if (p->exit_called) {
    return;
  }
  if ((f == &p->frames[0] && p->frames[1].busy) ||
      (f == &p->frames[1] && p->frames[0].busy)) {
    /* other frame buffer still in use, drop frame */
    return;
  }
  e = (libVLCEvent *) ckalloc(sizeof(*e));
  e->header.proc = libVLCready;
................................................................................
  Tcl_MutexFinalize(&p->ev_lock);
  ckfree(p);
}

/*
 *----------------------------------------------------------------------
 *
 * libVLCExitHandler --
 *
 *	Called on exit of process.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets a flag to invalidate further event handling.
 *
 *----------------------------------------------------------------------
 */

static void libVLCExitHandler(ClientData clientData)
{
  libVLCData *p = (libVLCData *) clientData;

  if (!p->exit_called) {
    p->exit_called = 1;
    if (p->media_player) {
      libvlc_media_player_stop(p->media_player);
    }
  }
}

/*
 *----------------------------------------------------------------------
 *
 * libVLCObjCmdDeleted --
 *
 *	Destructor of libvlc media player object and command.
 *
 * Results:
 *	None.
 *
................................................................................
 *	Resources are released.
 *
 *----------------------------------------------------------------------
 */

static void libVLCObjCmdDeleted(ClientData clientData)
{
  Tcl_DeleteExitHandler(libVLCExitHandler, clientData);
  Tcl_EventuallyFree((char *) clientData, FreeData);
}

/*
 *----------------------------------------------------------------------
 *
 * TKVLC_INIT --
................................................................................
  }
  p = (libVLCData *) ckalloc(sizeof(*p));
  p->vlc_inst = NULL;
  p->interp = interp;
  p->media_player = NULL;
  p->repeat = 0;
  p->tk_checked = 0;
  p->exit_called = 0;
  p->window_id = 0;
  p->file_name = NULL;
  p->photo_name = NULL;
  p->width = p->height = 0;
  p->tid = Tcl_GetCurrentThread();
  p->ev_lock = NULL;
  p->ev_queue = NULL;
................................................................................
    libvlc_event_attach(em, libvlc_MediaPlayerUnmuted, libVLChandler, p);
    libvlc_event_attach(em, libvlc_MediaPlayerAudioVolume, libVLChandler, p);
    libvlc_event_attach(em, libvlc_MediaPlayerAudioDevice, libVLChandler, p);
  }
  zArg = Tcl_GetStringFromObj(objv[1], 0);
  p->cmd = Tcl_CreateObjCommand(interp, zArg, libVLCObjCmd, (ClientData) p,
				libVLCObjCmdDeleted);
  Tcl_CreateExitHandler(libVLCExitHandler, (ClientData) p);
  return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tkvlc_Init --