summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/include/common.h
blob: 140ba26e82c51abef8b3c71df374093d4d71bc56 (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
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
/* $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
 */
#ifndef _MPEG_COMMON_H
#define _MPEG_COMMON_H

#include "ace/OS.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

extern int gethostname (char*, size_t);

#define VERSION 200   /* version 2.00 */

#ifdef LITTLE_ENDIAN
#define NeedByteOrderConversion
#elif !defined(BIG_ENDIAN)
#if (defined(vax) || defined(i386) || defined(i486)) && !defined(NeedByteOrderConversion)
#define NeedByteOrderConversion
#endif
#endif

/*following is defined so that debuging information is printed out for only
  specific user (usually software developer), LOG_DIR is also defined */

/*
#define LOG_DIR "/home/shanweic/log/"
#define DEVELOPER_UID   8640
*/

/* %% this is where the logging is done.." */
#define LOG_DIR "./"
#define DEVELOPER_UID   1735

#define SFprintf        if ((!getuid()) || getuid() == DEVELOPER_UID) fprintf
#define Fprintf         if (shared->config.verbose) fprintf

#define VCR_TCP_PORT    7101
#define VCR_UNIX_PORT   "/tmp/vcr_unix_port01"
#define VCR_ATM_PORT    "3005"

#define SPEEDUP_INV_SCALE 5  /* VS fast starts at 5/(5-1) normal speed */

#define AB_BUF_SIZE (64 * 1024)   /* size of client AB buffer */

#if 0
#define VB_BUF_SIZE (256 * 1024)  /* Size of client VB buffer */
#endif

#define VB_BUF_SIZE (1024 * 1024)  /* Size of client VB buffer */

#define VD_BUF_SIZE (1024 * 1024)  /* Size of client VD buffer */

#define PATH_SIZE       256
#define PATTERN_SIZE    100
#define MAX_FRAMES      54000  /* half hour video at 30FPS */
#define MAX_VDQUEUE_SIZE 20
#define MAX_FB_PACKETS  20  /* max number of feedback packet info collected. */
#define POSITION_RANGE  100
#define MSGGAP_MIN      -10  /* these are used for recording stat of
                                msgs received by VB */
#define MSGGAP_MAX      50

#define INET_SOCKET_BUFFER_SIZE 1400

/* audio type constants */

#define AudioTypeMuLaw 0
#define AudioTypeALaw 1
#define AudioTypeRIFF 2
#define AudioTypeLiner16 3
#define AudioTypeLiner8  4
#define AudioTypeLiner8Offset 5

/* Video and audio compression format */

#define VIDEO_MPEG1     0
#define VIDEO_MPEG2     1
#define VIDEO_JPEG      3
#define VIDEO_SIF       4

#define AUDIO_RAW       10
#define AUDIO_MPEG1     11
#define AUDIO_MPEG2     12


/* system configuration default values */

#define DEFAULT_maxFPS 60
#define DEFAULT_maxSPS 16000
#define DEFAULT_ffFPS 150
#define DEFAULT_fbFPS 150
#define DEFAULT_feedBackDelay 2000
#define DEFAULT_audioMask 0x1
#define DEFAULT_encodeType AudioTypeMuLaw
#define DEFAULT_channels 1
#define DEFAULT_samplesPerSecond 8000
#define DEFAULT_bytesPerSample 1
#define DEFAULT_audioTimerDuration 500
#define DEFAULT_audioBufferedIntervals 2
#define DEFAULT_framesPerAudioPlay  4
#define DEFAULT_audioForward   800
#define DEFAULT_filterPara  50
#define DEFAULT_maxSPframes 60
#define DEFAULT_VStimeAdvance 100

#define DEFAULT_volume 0

/* audio parameter data structure */

typedef struct
{
  int   encodeType;
  int   channels;
  int   samplesPerSecond;
  int   bytesPerSample;
} AudioParameter;

/* client processes shared data structure definition */

typedef struct
{
  int VDframeNumber;
  int VBbufId, VDbufId;
  char * VBbufAddr, * VDbufAddr;
  int pixelValid;
  unsigned char pixel[256];  /* for transfering pixel value from VP to VD */

  /* command and status   */
  int cmd;
  int cmdsn;
  int cmdBusy;

  int loopBack;

  int framesPerSecond;   /* Frames per second */
  int usecPerFrame;    /* micro-seconds per frame, actual video speed */
  int samplesPerSecond;   /* Samples per second */
  int usecPerSample;   /* micro-seconds per sample, actual audio speed */

  int volumePosition;
  int balancePosition;
  int speedPosition;
  int locationPosition;
  struct hostent audioHost;
  char audioPath[PATH_SIZE];
  struct hostent videoHost;
  char videoPath[PATH_SIZE];

  int live;  /* non-zero if any of the video/audio streams are live source */
  int videoFormat;
  int audioFormat;

  /*  video channel parameters  */
  int totalFrames;
  int totalGroups;
  int totalHeaders;
  int averageFrameSize;
  double  pictureRate;
  int horizontalSize;
  int verticalSize;
  int pelAspectRatio;
  int vbvBufferSize;
  int firstGopFrames;
  int patternSize;
  char pattern[PATTERN_SIZE];
  int IframeGap;
  int VStimeAdvance;

  int lastIframeDecoded;
  int sendPatternGops;
  char sendPattern[PATTERN_SIZE];
  float frameRateLimit;
  int framesDropped;
  int qosRecomputes;

  /*  video channel status  */
  int currentGroup;
  int currentFrame;
  int currentDisplay;
  int nextFrame;
  int nextGroup;

  /* audio channel parameters  */
  int totalSamples;
  AudioParameter audioPara;

  /* audio channel status  */
  int nextSample;   /* played by AP */

  /* AudioFile device parameter */
  AudioParameter AFPara;

  int currentUPF;
  int rtplay;           /* realtime tag, -- VD needs to drop frames when needed */
  int collectStat;  /* to indicate if statistics should be collected or not */
  int VBheadFrame;      /* ID of last frame put to VBbuffer by VB */
  int needHeader;   /* VD requests resending of systerm Header */
  int playRoundTripDelay; /* play round trip time (from issuing play/FF/FB
                             command to first Decoded frame showup in
                             VD buffer) estimated by CTR start_timer() */
  int audioMaxPktSize;  /* 0 -- reliable byte stream,
                           >0 - non-discard mode packet stream,
                           <0 - discard mode packet stream */
  int videoMaxPktSize;

  /* System configuration parameters */
  struct
  {
    int rt;             /* play as fast as possible without dropping frames,
                           and audio turned off when this tag is set to 0 (zero)
                                   */
    int maxFPS;         /* maximum PLAY frames-per-second, this play speed is used
                           during playback when speed scale is set to 100 */
    int maxSPS;         /* similar to maxFPS, used when audio is played without
                           corresponding video
                           */
    int ffFPS;          /* play speed when Fast forward */
    int fbFPS;          /* play speed when fast rewind */
    int feedBackDelay;  /* msec, delay of feedback when AB, VB received first
                           packet, 0 (zero) default to adaptive */
    int audioMask; /* mask for audio output device */
    AudioParameter audioPara; /* default audio parameter by system */
    int audioTimerDuration; /* for audio-only case, miliseconds */
    int audioBufferedIntervals; /* for audio-only case,
                                   audioTimerDuration * audioBufferedIntervals
                                   milliseconds of audio samples will be buffered
                                   in AF buffer
                                   */
    int framesPerAudioPlay;   /* for audio-video case, each time, samples corresponding
                                 to this number of video frames will be played */
    int audioForward;    /* forward value for audio channel, in AFTime unit
                            (number of samples), audio channel is played ahead of video
                            by this number of samples. This is introduce to compensate
                            the dely to AF in audio channel, and usually should be less
                            than 1 (one) second, but greater than zero.
                          */
    int VStimeAdvance;  /* target VB buffer level to be mentained (micro-seconds). This
                           is sent in INIT message to VS, to decide how many frames to
                           be maintained in VB buffer
                          */
    float frameRateLimit; /* playback frame rate limit (frames per second) */
    int collectStat;    /* tag to collect statistics to file 'stat.n' when set */
    int collectFrameInfo; /* collect MPEG frame info to file 'stat.n' when set*/
    int syncEffective;  /* tag to make sync mechanism effective when set */
    int qosEffective;   /* tag to make QoS control effective when set */
    int audioOffset;    /* offset added to audio channel 'nextSample' when play().
                           usually audio and video are not recorded strictly
                           synchronized. This parameter is to compensate it. The
                           value can be any integer value.
                         */
    int filterPara;     /* 1/R of Median, nsamples of Mean and Average */
    int maxSPframes;    /* max number of frame in a sendPattern */
    int audioConn;      /* tag for connection oriented audio data channel */
    int videoConn;      /* tag for connection oriented video data channel */
    int verbose;
  } config;

#ifdef STAT
  struct
  {
    unsigned VBmaxBytes;        /* max fill level (bytes) in VB */
    unsigned VBdroppedFrames;   /* accumulative total number of frames dropped by VB
                                   because VB buffer full */
    unsigned VBemptyTimes;      /* number of time VD fail to get a frame from VB
                                   immediately */
    unsigned VDnoRef;            /* # of frames without reference */
    unsigned VDagainstSendPattern; /* # of frames against send pattern */
    unsigned VDtooLateI;         /* # of I frames dropped 'cause too late */
    unsigned VDtooLateP;         /* # of P frames dropped 'cause too late */
    unsigned VDtooLateB;         /* # of B frames dropped 'cause too late */
    unsigned VDlastFrameDecoded;        /* ID of last frame decoded by VD */
    unsigned CTRdropLate;
    unsigned CTRdropOutOrder;
    unsigned CTRdispOnTime;
    unsigned CTRdispLate;
    unsigned fbPacketNumber;    /* # packets sent by feedback mechanism */
    struct {
      int frameId;
      int addUsecPerFrame;
      int addFrames;
      int frames;
      int framesDropped;
      float frameRateLimit;
      int advance;
    } fbPackets[MAX_FB_PACKETS];        /* recording FB packet contents */
    unsigned VDqueue[MAX_VDQUEUE_SIZE]; /* record number of frames with VD queue
                                           length of index number */
    int  VBmsgGaps[MSGGAP_MAX + 1 - MSGGAP_MIN]; /* # of ind-sized gaps between msgs */
    char VBframesReceived[(MAX_FRAMES + 7)/8];  /* bit array for frames received by VB */
    char VDframesDecoded[(MAX_FRAMES + 7)/8];   /* bit array for frames decoded by VD */
    char VPframesDisplayed[(MAX_FRAMES + 7)/8]; /* bit array for frames displayed by VP */
    short VBfillLevel[MAX_FRAMES];      /* VB buffer fill level (frames) recorded by CTR */
  } stat;
#endif
} SharedData;

/* command and reply: GUI-CTR, CTR-VS, CTR-AS */

/* GUI to CTR, (and also CTR to VS and/or AS) */

#define CmdINIT 0    /* followed by: videoHost, videoPath, audioHost, audioPath
                        each item is passed as a string (without 0), led with length(int) */
#define CmdINITaudio    1   /* for CTR-AS */
#define CmdINITvideo    2   /* for CTR-VS */
#define CmdSTOP 3
#define CmdFF   4
#define CmdFB   5
#define CmdSTEP 6
#define CmdPLAY 7
#define CmdREF  20              /* this is for sending REFerence frame by VS
                                   for CmdSTEP and CmdPLAY */
#define CmdPOSITION     8         /* followed by position */
#define CmdPOSITIONrelease      9 /* followed by position */
#define CmdVOLUME       10        /* followed by position */
#define CmdBALANCE      11        /* followed by position */
#define CmdSPEED        12        /* followed by position */
#define CmdLOOPenable   13
#define CmdLOOPdisable  14
#define CmdSTATstream   23   /* reply with { | type(byte) | size(int) }+ | */
#define CmdSTATsent     24   /* reply with { | byte }+ | */
#define CmdCLOSE        18
#define CmdFAIL         19   /* followed by a string */

#define CmdDONE         15      /* CTR to GUI:
                                   replay for accptance and execution of Above Cmd */

#define CmdVPinitScreen 30    /* CTR to VP(GUI), audio-only screen clearning */
#define CmdVPdisplayFrame 31  /* CTR to VP(GUI) to display the single frame in buffer */
#define CmdVPclearScreen 32   /* CTR to VP(GUI), to clear all images in VD buffer */
#define CmdVPaudioPosition 33 /* CTR to VP(GUI), in audio-only case, set position bar */

// to terminate the event loop
#define CmdExit  34

// cmd sent by Java GUI to Controller process
#define CmdJINIT 35

/* CTR-VS */

/* CmdINITvideo: followd by parameters of a fixed structure of 3 integers
   reply with CmdINITvideo followed by reply or CmdFAIL followed by a string,
*/
typedef struct
{
  int sn;
  int version;
  int nameLength;    /* the length of the video file */
  /* this structure is followed by a zero-terminated file name as follows:
      char videoFile[];
   */
} INITvideoPara;

typedef struct
{
  int live;
  int format;

  int totalHeaders;
  int totalFrames;
  int totalGroups;
  int horizontalSize;
  int verticalSize;
  int pelAspectRatio;
  int pictureRate1000;
  int vbvBufferSize;
  int sizeIFrame;
  int sizePFrame;
  int sizeBFrame;
  int sizeSystemHeader;
  int sizeGop;
  int averageFrameSize;
  int firstGopFrames;
  int patternSize;
  char pattern[PATTERN_SIZE];
} INITvideoReply;

/* CmdPOSITION, CmdPOSITIONrelease: followed by following parameter */
typedef struct
{
  int sn;
  int nextGroup;
} POSITIONpara;

/* CmdSTEP: followed by following parameter */
typedef struct
{
  int sn;
  int nextFrame;
} STEPpara;

/* CmdFF, CmdFB: followed by following parameter */
typedef struct
{
  int sn;
  int nextGroup;
  int usecPerFrame;
  int framesPerSecond;
  int VStimeAdvance;
} FFpara;

/*CmdPLAY: followed by following parameter */
typedef struct
{
  int sn;
  int collectStat;
  int nextFrame;
  int usecPerFrame;
  int framesPerSecond;
  int frameRateLimit1000;
  int VStimeAdvance;
  int sendPatternGops;
  char sendPattern[PATTERN_SIZE];
} PLAYpara;

/* CmdSPEED: parameter */
typedef struct
{
  int sn;
  int usecPerFrame;
  int framesPerSecond;
  int frameRateLimit1000;
  int sendPatternGops;
  char sendPattern[PATTERN_SIZE];
} SPEEDpara;

/* CmdLOOPenabe, CmdLOOPdisable, CmdSTOP: following by SN */


/* video channel data packet structure */

typedef struct
{
  int cmd;
  int cmdsn;
  int sh;
  int gop;
  int frame;
  int display;  /* display frame number */
  int future;
  int past;
  int currentUPF;
  int dataBytes;
} VideoPacket;


/* video channel data message structure */

typedef struct
{
  int packetsn;
  int packetSize;
  int msgsn;
  int msgOffset;
  int msgSize;
} VideoMessage;


/* Feedback parameter structure */

typedef struct
{
  int cmdsn;
  int needHeader;
  int addUsecPerFrame;
  int addFrames;
  int frameRateLimit1000;
  int sendPatternGops;
  int sendPattern[PATTERN_SIZE];
} VideoFeedBackPara;



/* audio channel commands and parameters */

/* CmdINITaudio parameter of fixed structure of 3 integers and a AudioPara,
   replys with CmdINITaudio followed by reply or CmdFAIL followed by a string */
typedef struct
{
  int sn;
  int version;
  AudioParameter para;
  int nameLength;
  /* char audioFile[] */
} INITaudioPara;

typedef struct
{
  int live;
  int format;

  AudioParameter para;
  int totalSamples;
} INITaudioReply;


/* CmdPLAY parameter */
typedef struct
{
  int sn;
  int nextSample;
#if 0
  int samplesPerSecond; /* <= shared->audioPara.samplesPerSecond   */
#endif
  int samplesPerSecond; /* audio playback speed */
  int samplesPerPacket; /* Number of samples in a packet */
  int ABsamples; /* size of client VB buffer in samples */
  int spslimit;  /* QoS parameter: sps supported by the audio channel */
} PLAYaudioPara;

/* STOP followed only by SN */

/* CmdSPEED parameter */
typedef struct
{
  int sn;
  int samplesPerSecond;
  int samplesPerPacket; /* Number of samples in a packet */
  int spslimit;
} SPEEDaudioPara;

/* audio packet structure */
typedef struct
{
  int cmdsn;
  int resend;
  int samplesPerSecond;
  int firstSample;
  int samples;
  int actualSamples;
  int dataBytes;
} AudioPacket;

typedef struct
{
  int firstSample;  /* Id of the first sample in this packet */
  int samples;   /* number of samples in current packet */
} APdescriptor; /* audio packet decriptor */

/* audio feedback packet */
typedef struct
{
  int cmdsn;
  int type;   /* 0 - feedback command; >=1 - Number of packets to be resent */
  union {
    struct {
      int addsps;
      int addSamples;
    } fb;
    APdescriptor ap;
  } data;
} AudioFeedBackPara;
/* One actual resent request may have multiple APdescriptors depending on
   the value in element type, all execpt the first one follows above structure*/

typedef struct {
  int sh, gop, frame, display, future, past;
  int refcount;                          /* reference count    */
  unsigned char * data;                  /* data buffer for image */
} FrameBlock;


#endif /* _MPEG_COMMON_H */