summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/mpeg_client/para.cpp
blob: 40307c30f9bbc9886043900700a0e6b61c725c84 (plain)
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
/* $Id$ */

/* Copyright (c) 1995 Oregon Graduate Institute of Science and Technology
 * P.O.Box 91000-1000, Portland, OR 97291, USA;
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its 
 * documentation for any purpose is hereby granted without fee, provided that 
 * the above copyright notice appear in all copies and that both that 
 * copyright notice and this permission notice appear in supporting 
 * documentation, and that the name of O.G.I. not be used in advertising or 
 * publicity pertaining to distribution of the software without specific, 
 * written prior permission.  O.G.I. makes no representations about the 
 * suitability of this software for any purpose.  It is provided "as is" 
 * without express or implied warranty.
 * 
 * O.G.I. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
 * O.G.I. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author: Shanwei Cen
 *         Department of Computer Science and Engineering
 *         email: scen@cse.ogi.edu
 */

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "video.h"
#include <X11/Intrinsic.h>
#include <Xm/DialogS.h>
#include <Xm/List.h>
#include <Xm/Frame.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Label.h>
#include "include/common.h"
#include "newproto.h"
#include "global.h"

ACE_RCSID(mpeg_client, para, "$Id$")

#define NUM_LIST_ITEMS 25
#define PARAMETER_FILE "~/.vcr/vcrParameters"
#define BANNER "Virtual VCR Parameter File, version 2.0  ** Do not Edit **"
#ifdef XmFONTLIST_DEFAULT_TAG
#define XmStringTag XmFONTLIST_DEFAULT_TAG
#else
#define XmStringTag XmSTRING_DEFAULT_CHARSET
#endif
#define STRING_SIZE 64
#define ITEMS sizeof(shared->config)/4

static Widget parashell, wparalist, wparafield;

static int * config;
static float *fconfig;

static struct
{
  char * title;
  int float_tag;  /* 0 - integer, 1 - floating point */
}
para[] =
{
  {"Real time (audio on)(tag)", 0},
  {"Video max frames-per-second", 0},
  {"Audio max sampels-per-second", 0},
  {"FF frames-per-second", 0},
  {"Rewind frames-per-second", 0},
  {"Feedback delay (msec)", 0},
  {"Audio output mask", 0},
  {"Audio_para.encodeType", 0},
  {"Audio_para.channels", 0},
  {"Audio_para.samplesPerSecond", 0},
  {"Audio_para.bytesPerSamples", 0},
  {"Audio timer interval (millisec)", 0},
  {"Audio buffered intervals", 0},
  {"Frames per audio play", 0},
  {"Audio forward (samples)", 0},
  {"VS work-ahead (milliseconds)", 0},
  {"frame rate limit (fps, float)", 1},
  {"collect statistics(tag)", 0},
  {"collect video structure info(tag)", 0},
  {"Sync effective(tag)", 0},
  {"QoS effective(tag)", 0},
  {"Audio offset(samples)", 0},
  {"Filter parameter(1/R or nsamples)", 0},
  {"Max send pattern frames", 0},
  {"Reliable byte-stream audio (tag)", 0},
  {"Reliable byte-stream video (tag)", 0},
  {"Verbose message(tag)", 0},
  {"", 0} /* this empty string is needed for testing the size of para */
};

#define Fgets(s) {if (feof(fp) || fgets(s, STRING_SIZE, fp) == NULL) break;  s[strlen(s)-1] = 0; }

#define Fputs(s) {fputs(s, fp); fputc('\n', fp);}

static void InitBuf(void)
{
  FILE * fp;
  char buf[256];
  int i;

  config = (int *)&(shared->config);
  fconfig = (float *)&(shared->config);

  get_full_path(PARAMETER_FILE, buf, 256);
  fp = fopen(buf, "r");
  if (fp == NULL)
  {
    fprintf(stderr, "Warning: %s not found, use default parameter value\n",
	    PARAMETER_FILE);
  InitBuf_exit1:
    return;
  }
  if (fgets(buf, 100, fp) == NULL)
  {
    fclose(fp);
    goto InitBuf_exit1;
  }
  buf[strlen(buf)-1] = 0;
  if (strcmp(buf, BANNER))
  {
    fprintf(stderr, "BANNER in %s not expected, use default parameter value\n",
	    PARAMETER_FILE);
    fclose(fp);
    goto InitBuf_exit1;
  }
  for(i = 0; i < ITEMS; i++)
  {
    Fgets(buf);
    if (para[i].float_tag)
      sscanf(buf, "%f", &fconfig[i]);
    else
      sscanf(buf, "%d", &config[i]);
  }
  fclose(fp);
}

static void SaveBuf(void)
{
  int i;
  FILE * fp;
  char buf[256];
  get_full_path(PARAMETER_FILE, buf, 256);
  fp = fopen(buf, "w");
  if (fp == NULL)
  {
    fprintf(stderr, "Fail to open %s for saving para", buf);
    perror("");
    return;
  }
  Fputs(BANNER);
  for (i = 0; i < ITEMS; i++)
    if (para[i].float_tag)
      fprintf(fp, "%f\n", fconfig[i]);
    else
      fprintf(fp, "%d\n", config[i]);
  fclose(fp);
}


static int curListPos(void)
{
  int * poses, count;
  
  if (XmListGetSelectedPos(wparalist, &poses, &count))
  {
    count = poses[0];
    XtFree((char*)poses);
    /*
    fprintf(stderr, "curListPos: current pos = %d\n", count);
    */
    return count - 1;
  }
  return -1;
}

static void modifyCB(Widget w, XtPointer closure, XtPointer call_data)
{
  int i, value;
  XmString item;
  char buf[100], * valptr;
  i = curListPos();
  if (i == -1) { beep(); return;}
  valptr = XmTextGetString(wparafield);
  if (para[i].float_tag)
    sscanf(valptr, "%f", &fconfig[i]);
  else
    sscanf(valptr, "%d", &config[i]);
  XtFree(valptr);
  if (para[i].float_tag)
    sprintf(buf, "%s: %f", para[i].title, fconfig[i]);
  else
    sprintf(buf, "%s: %d", para[i].title, config[i]);
  item = (XmString)XmStringCreateLtoR(buf, XmStringTag);
  XmListReplaceItemsPos(wparalist, &item, 1, i+1);
  XmListSelectPos(wparalist, i+1, 0);
  XmStringFree(item);
  SaveBuf();
  /*
  XtManageChild(parashell);
  */
  return;
}

static void dismissCB(Widget W, XtPointer closure, XtPointer call_data)
{
  
  XtUnrealizeWidget(parashell);
  /*
  XtUnmanageChild(parashell);
  */
}

Widget CreateParameterWindow(Widget parent)
{
  Arg   	args[20];
  int		n;
  Widget 	wform, frame1, frame2, wlabel,
                wmodify, wdismiss;
  XmFontList fontlist;
  XFontStruct * font;
  XmStringCharSet cset = XmSTRING_DEFAULT_CHARSET;

  InitBuf();

  n = 0;
  XtSetArg(args[n], XmNtitle, "Virtual VCR Parameter List"); n++;
  XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING);n++;
  XtSetArg(args[n], XmNkeyboardFocusPolicy, XmPOINTER); n++;
  XtSetArg(args[n], XmNwidth, 350); n++;
  XtSetArg(args[n], XmNheight, 400); n++;
  XtSetArg(args[n], XmNminWidth, 250); n++;
  XtSetArg(args[n], XmNminHeight, 150); n++;
  
  parashell = XtAppCreateShell("Parameter List", "virtual_vcr",
			       topLevelShellWidgetClass, display, args, n);
  /*
  parashell = XmCreateDialogShell(parent, "virtual_vcr", args, n);
  */

  font = XLoadQueryFont (XtDisplay (parashell), "courB14");
  fontlist = XmStringCreateFontList (font, cset);

  n = 0;
  XtSetArg(args[n], XmNtitle, "Virtual Parameter List"); n++;
  wform  = XmCreateForm(parashell, "Parameters", args, n);
  XtManageChild(wform);
  /*
  parashell = wform  = XmCreateForm(parashell, "Parameters", args, n);
  */
  
  n = 0;
  wmodify = XmCreatePushButton (wform, "Update", args, n);
  XtManageChild(wmodify);
  XtAddCallback (wmodify, XmNactivateCallback, (XtCallbackProc)modifyCB, NULL);
  wdismiss = XmCreatePushButton (wform, "Dismiss", args, n);
  XtManageChild(wdismiss);
  XtAddCallback (wdismiss, XmNactivateCallback, (XtCallbackProc)dismissCB, NULL);

  n=0;
  XtSetArg (args[n], XmNwidth, 60); n++;
  XtSetArg (args[n], XmNheight, 28); n++;
  XtSetArg (args[n], XmNleftOffset, 20); n++;
  XtSetArg (args[n], XmNbottomOffset, 5); n++;
  XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  XtSetValues (wmodify, args, n);

  n = 0;
  XtSetArg(args[n], XmNcolumns, 10); n++;
  XtSetArg (args[n], XmNleftOffset, 90); n++;
  XtSetArg (args[n], XmNbottomOffset, 5); n++;
  XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  wparafield = XmCreateTextField(wform, "updata_text", args, n);
  XtManageChild(wparafield);
  
  n=0;
  XtSetArg (args[n], XmNwidth, 60); n++;
  XtSetArg (args[n], XmNheight, 28); n++;
  XtSetArg (args[n], XmNrightOffset, 20); n++;
  XtSetArg (args[n], XmNbottomOffset, 5); n++;
  XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  XtSetValues (wdismiss, args, n);

  n = 0;
  XtSetArg (args[n], XmNtopOffset, 5); n++;
  XtSetArg (args[n], XmNleftOffset, 5); n++;
  XtSetArg (args[n], XmNbottomOffset, 45); n++;
  XtSetArg (args[n], XmNrightOffset, 5); n++;
  XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  XtSetArg(args[n], XmNfontList,  fontlist); n++;
  XtSetArg(args[n], XmNvisibleItemCount,  NUM_LIST_ITEMS); n++;

  {
    int items;
    XmString * item;
    int i;
    /*
    fprintf(stderr, "Total parameter items: %d\n", items);
    */
    for (items = 0; para[items].title[0] != 0; items ++);
    if (items > ITEMS)
      items = ITEMS;
    else if (items < ITEMS)
    {
      fprintf(stderr, "Error in para.c: fewer titles than parameters, %d out of %d.\n",
	      items, ITEMS);
      exit(1);
    }
    item = (XmString *)malloc(sizeof(*item) * items);
    if (item == NULL)
    {
      perror("UI allocate parameter list item(XmString)");
      exit(1);
    }
    for (i = 0; i < items; i ++)
    {
      char buf[100];
      if (para[i].float_tag)
        sprintf(buf, "%s: %f", para[i].title, fconfig[i]);
      else
        sprintf(buf, "%s: %d", para[i].title, config[i]);
      item[i] = (XmString)XmStringCreateLtoR(buf, XmStringTag);
    }
    XtSetArg(args[n], XmNitems, item); n++;
    XtSetArg(args[n], XmNitemCount, items); n++;
    XtSetArg(args[n], XmNselectedItems,  item); n++;
    XtSetArg(args[n], XmNselectedItemCount,  1); n++;
    wparalist = XmCreateScrolledList(wform, "ParameterList", args, n);
    XtManageChild(wparalist);
    for (i = 0; i < items; i++)
      XmStringFree(item[i]);
    free(item);
  }
  XmFontListFree(fontlist);

  n=0;
  XtSetArg (args[n], XmNtopOffset, 5); n++;
  XtSetArg (args[n], XmNleftOffset, 5); n++;
  XtSetArg (args[n], XmNbottomOffset, 45); n++;
  XtSetArg (args[n], XmNrightOffset, 5); n++;
  XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  frame2 = XmCreateFrame (wform, "frame", args, n);
  XtManageChild(frame2);

  n=0;
  XtSetArg (args[n], XmNtopOffset, 0); n++;
  XtSetArg (args[n], XmNleftOffset, 0); n++;
  XtSetArg (args[n], XmNbottomOffset, 0); n++;
  XtSetArg (args[n], XmNrightOffset, 0); n++;
  XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  frame1 = XmCreateFrame (wform, "frame", args, n);
  XtManageChild(frame1);
  
  return parashell;
}