aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Encoder/enc_fhgaac/mp4FastAAClib.h
blob: e73506699a4ed45234ffd856bae6ae493fe62534 (plain) (blame)
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
/*************************  Fast MPEG AAC Audio Encoder  **********************

                     (C) Copyright Fraunhofer IIS (2004-2010)
                                All Rights Reserved

   $Id: mp4FastAAClib.h,v 1.8 2013/10/29 00:56:15 dromagod Exp $
   Initial author:       M. Schug / A. Groeschel
   contents/description: Fast MPEG AAC Encoder Interface Library Functions

   This software and/or program is protected by copyright law and international 
   treaties. Any reproduction or distribution of this software and/or program, 
   or any portion of it, may result in severe civil and criminal penalties, and 
   will be prosecuted to the maximum extent possible under law.

******************************************************************************/

#ifndef _mp4FastAAClib_h_
#define _mp4FastAAClib_h_

#ifdef __cplusplus
extern "C"
{
#endif

/* ------------------------ structure alignment ---------------------------*/

#if defined(WIN32) || defined(WIN64)
#pragma pack(push, 1)
#endif

/*-------------------------- defines --------------------------------------*/

/*
 * calling convention
 */

#ifndef MPEG4ENCAPI
#if defined(WIN32) || defined(WIN64)
#define MPEG4ENCAPI __stdcall
#else
#define MPEG4ENCAPI
#endif
#endif

/*-------------------- enum definitions -----------------------------------*/

typedef enum 
{
  AUD_OBJ_TYP_LC              = 2,   /* AAC LC                                          */
  AUD_OBJ_TYP_LTP             = 4,   /* AAC LTP                                         */
  AUD_OBJ_TYP_HEAAC           = 5,   /* AAC LC + SBR                                    */
  AUD_OBJ_TYP_ER_LC           = 17,  /* ER AAC LC                                       */
  AUD_OBJ_TYP_ER_LTP          = 19,  /* ER AAC LTP                                      */
  AUD_OBJ_TYP_ER_SCAL         = 20,  /* ER AAC LC scalable                              */
  AUD_OBJ_TYP_PS              = 29,  /* AAC LC + SBR + PS                               */
  AUD_OBJ_TYP_MP2_LC          = 129, /* virtual AOT MP2 Low Complexity Profile          */
  AUD_OBJ_TYP_MP2_SBR         = 132, /* virtual AOT MP2 Low Complexity Profile with SBR */
  AUD_OBJ_TYP_SBR_DS          = 133, /* virtual AOT for downsampled SBR                 */
  AUD_OBJ_TYP_ER_SCAL_SBR     = 148, /* ER AAC LC scalable + SBR                        */
  AUD_OBJ_TYP_ER_SCAL_SBR_PS  = 157,  /* ER AAC LC scalable + SBR + PS                  */
  AUD_OBJ_TYP_MPS             =  30
} AUD_OBJ_TYP;

typedef enum {
  MP4_QUAL_FAST=0,
  MP4_QUAL_MEDIUM,
  MP4_QUAL_HIGH,
  MP4_QUAL_HIGHEST      /* Always resample to preferred sample rate */
} MPEG4ENC_QUALITY;

typedef enum {
  MP4_TT_RAW        = 0,
  MP4_TT_ADIF       = 1,
  MP4_TT_ADTS       = 2,
  MP4_TT_ADTSCRC    = 3,
  MP4_TT_LOAS       = 4,
  MP4_TT_LOAS_NOSMC = 5,
  MP4_TT_LATM       = 6,
  MP4_TT_LATM_NOSMC = 7,
  /* MP4_TT_LOAS_CRC = 8, */
  /* MP4_TT_LATM_CRC = 9, */
  ___mp4_tt_dummy
} MPEG4ENC_TRANSPORT_TYPE;

typedef enum {
  /*  These are the standard MPEG Channel mappings */
  MP4_CH_MODE_INVALID = 0,
  MP4_CH_MODE_MONO,         /* 1   channel mono   */
  MP4_CH_MODE_STEREO,       /* 2   channel stereo */
  MP4_CH_MODE_3,            /* 3   channel audio ( center + left/right front                       speaker       ) */
  MP4_CH_MODE_4,            /* 4   channel audio ( center + left/right front +     rear   surround speaker       ) */
  MP4_CH_MODE_5,            /* 5   channel audio ( center + left/right front + left/right surround speaker       ) */
  MP4_CH_MODE_5_1,          /* 5.1 channel audio ( center + left/right front + left/right surround speaker + LFE ) */
  MP4_CH_MODE_7_1,          /* 7.1 channel audio ( center + left/right front 
                                                      +  left/right outside front + left/right surround speaker + LFE ) */
  /* Channel mappings 8 to 15 are reserved */
  MP4_CH_MODE_6_1               = 11, /* 6.1 channel audio ( center + front left/right + surround left/right + rear surround center     + LFE ) */
  MP4_CH_MODE_7_1_REAR_SURROUND = 12, /* 7.1 channel audio ( center + front left/right + surround left/right + rear surround left/right + LFE ) */
  MP4_CH_MODE_7_1_TOP_FRONT     = 14, /* 7.1 channel audio ( center + front left/right + surround left/right + LFE  + + TOP front left/right  ) */

  /* Some non standard channel mappings */
  MP4_CH_MODE_DUAL_MONO = 16, /*  2 independent channels */
  MP4_CH_MODE_4TIMES1,        /*  4 independent channels */
  MP4_CH_MODE_6TIMES1,        /*  6 independent channels */
  MP4_CH_MODE_8TIMES1,        /*  8 independent channels */
  MP4_CH_MODE_12TIMES1,       /* 12 independent channels */
  MP4_CH_MODE_16TIMES1,
  MP4_CH_MODE_2TIMES2,        /*  2 stereo channel pairs */
  MP4_CH_MODE_3TIMES2,        /*  3 stereo channel pairs */
  MP4_CH_MODE_4TIMES2,        /*  4 stereo channel pairs */
  MP4_CH_MODE_6TIMES2,        /*  6 stereo channel pairs */

  MP4_CH_MODE_7_1_SIDE_CHANNEL = 32, /* 7.1 channel audio ( center + left/right front
                                                            + left/right side channels + left/right surround speakers + LFE ) */
  MP4_CH_MODE_7_1_FRONT_CENTER,      /* 7.1 channel audio ( center + left/right front
                                                            + left/right frontal center speakers + left/right surround speakers + LFE ) */

  /* Channel mapping for parametric stereo 
     (only works with AUD_OBJ_TYP_HEAAC, AUD_OBJ_TYP_PS)   */
  MP4_CH_MODE_PARAMETRIC_STEREO = 64,  /* 2 channel stereo input, transmit 1 channel mono + SBR + PS */
  MP4_CH_MODE_MPEGS_5x5         = 128, /* 6 channel input, transmit 1/2 channel(s) (+ SBR) + MPEGS Payload */
#ifdef SUPPORT_UPMIX
  MP4_CH_MODE_MPEGS_SXPRO_UPMIX,       /* 2 channel input, sxPro Upmix,  transmit 2 channel(s) (+ SBR) + MPEGS Payload */
#endif
#ifdef SUPPORT_MPS_7_X_7
  MP4_CH_MODE_MPEGS_7x7_REAR_SURROUND, /* 8 channel input (5.1 + left/right side speakers), transmit 2 channel(s) (+ SBR) + MPEGS Payload */ 
  /* 7.1 front center channel mapping is not yet supported! */
  MP4_CH_MODE_MPEGS_7x7_FRONT_CENTER,  /* 8 channel input (5.1 + left/right frontal center speakers), transmit 2 channel(s) (+ SBR) + MPEGS Payload */
#ifdef SUPPORT_MPS_7_5_7
  MP4_CH_MODE_MPEGS_757_FRONT_CENTER,  /* 8 channel input (5.1 + left/right frontal center speakers), transmit 5 channel(s) (+ SBR) + MPEGS Payload */
  MP4_CH_MODE_MPEGS_757_REAR_SURROUND, /* 8 channel input (5.1 + left/right side speakers), transmit 5 channel(s) (+ SBR) + MPEGS Payload */
#endif /* SUPPORT_MPS_7_5_7 */
#endif /* SUPPORT_MPS_7_X_7 */

  /* The following channel mappings are not yet supported! */
  MP4_CH_MODE_MPEGS_5x5_BLIND,
  MP4_CH_MODE_MPEGS_ARBITRARY_DOWNMIX_MONO,  /* 7 channel input, transmit 1 channel (+ SBR) + MPEGS Payload */
  MP4_CH_MODE_MPEGS_ARBITRARY_DOWNMIX_STEREO /* 8 channel input, transmit 2 channel(s) (+ SBR) + MPEGS Payload */

} MPEG4ENC_CH_MODE;

typedef enum {

  MP4_MPEGS_DOWNMIX_DEFAULT = 0, 
  /* The following config (FORCE_STEREO) is not yet supported! */
  MP4_MPEGS_DOWNMIX_FORCE_STEREO,
  MP4_MPEGS_DOWNMIX_MATRIX_COMPAT,
  /* The following configs are not yet supported! */
  MP4_MPEGS_DOWNMIX_ARBITRARY_MONO,
  MP4_MPEGS_DOWNMIX_ARBITRARY_STEREO
#ifdef SUPPORT_MPS_7_5_7
  , MP4_MPEGS_DOWNMIX_51
#endif /* SUPPORT_MPS_7_5_7 */

} MPEG4ENC_MPEGS_DOWNMIX_CONFIG;


typedef enum {
  MPEG4ENC_NO_ERROR = 0,
  MPEG4ENC_UNKNOWN_ERROR, 
  MPEG4ENC_PARAM_ERROR,
  MPEG4ENC_NOTIMPLEMENTED_ERROR,
  MPEG4ENC_MEMORY_ERROR,
  MPEG4ENC_INIT_ERROR,
  MPEG4ENC_FATAL_ERROR,
  MPEG4ENC_STACK_ALIGNMENT_ERROR,
  MPEG4ENC_METADATA_ERROR,
  MPEG4ENC_AOT_NOT_SUPPORTED = 64,
  MPEG4ENC_CHMODE_NOT_SUPPORTED,
  MPEG4ENC_BRMODE_NOT_SUPPORTED,
  MPEG4ENC_WARNING_MIN = 128,
  MPEG4ENC_WARNING_STACK_ALIGNMENT = MPEG4ENC_WARNING_MIN,
  MPEG4ENC_WARNING_METADATA,
  MPEG4ENC_WARNING_NOSYNC_TRIGGERED
} MPEG4ENC_ERROR;

typedef enum {
  MP4_SBRSIG_IMPLICIT  = 0, /* implicit signaling  (signaling 1) */
  MP4_SBRSIG_EXPL_BC   = 1, /* explicit backward compatible signaling (signaling 2.B.) */
  MP4_SBRSIG_EXPL_HIER = 2  /* explicit hierarchical signaling (signaling 2.A.) */
} MPEG4ENC_SIGNALING_MODE;

typedef enum {
  MP4_MPEGS_PAYLOAD_EMBED        = 0,   /* in case of MPEG-4 transportation, embed payload into AAC payload */
  MP4_MPEGS_NO_PAYLOAD_EMBED     = 1,   /* in case of MPEG-4 transportation, do *not* embed payload into AAC payload, but transport payload in extra stream */
  MP4_MPEGS_PAYLOAD_EMBED_ASCEXT = 2    /* M16117 */
} MPEG4ENC_MPEGS_PAYLOAD_MODE;

typedef enum {
  MP4_BR_MODE_CBR = 0, 
  MP4_BR_MODE_VBR_1   = 1,
  MP4_BR_MODE_VBR_2   = 2,
  MP4_BR_MODE_VBR_3   = 3,
  MP4_BR_MODE_VBR_4   = 4,
  MP4_BR_MODE_VBR_5   = 5,
  MP4_BR_MODE_VBR_6   = 6,
  MP4_BR_MODE_SFR     = 7, /* Superframing */
  MP4_BR_MODE_DABPLUS = 8, /* Superframing + DAB+ constraints */
  MP4_BR_MODE_DRMPLUS = 9, /* Superframing + DRM+ constraints */
  MP4_BR_MODE_DMB     = 10
} MPEG4ENC_BITRATE_MODE; 

typedef enum{
  MP4_GRANULE_960 = 960,
  MP4_GRANULE_1024 = 1024
} MPEG4ENC_GRANULE_LEN;

typedef enum {
  MP4_METADATA_NONE         = 0, /* do not embed any metadata */
  MP4_METADATA_MPEG,             /* embed MPEG defined metadata only */
  MP4_METADATA_MPEG_ETSI         /* embed all metadata */
} MPEG4ENC_METADATA_MODE;

typedef enum {
  MP4_METADATA_DRC_NONE          = 0,
  MP4_METADATA_DRC_FILMSTANDARD,
  MP4_METADATA_DRC_FILMLIGHT,
  MP4_METADATA_DRC_MUSICSTANDARD,
  MP4_METADATA_DRC_MUSICLIGHT,
  MP4_METADATA_DRC_SPEECH,
#ifdef SUPPORT_METADATA_DRC_MOBILE
  MP4_METADATA_DRC_MOBILE,
#endif
  MP4_METADATA_DRC_EMBED_EXTERN = -1,
  MP4_METADATA_DRC_NOT_PRESENT = -2
} MPEG4ENC_METADATA_DRC_PROFILE;

typedef enum {
  MPEG4ENC_METADATA_DMX_GAIN_0_dB    = 0,
  MPEG4ENC_METADATA_DMX_GAIN_1_5_dB  = 1,
  MPEG4ENC_METADATA_DMX_GAIN_3_dB    = 2,
  MPEG4ENC_METADATA_DMX_GAIN_4_5_dB  = 3,
  MPEG4ENC_METADATA_DMX_GAIN_6_dB    = 4,
  MPEG4ENC_METADATA_DMX_GAIN_7_5_dB  = 5,
  MPEG4ENC_METADATA_DMX_GAIN_9_dB    = 6,
  MPEG4ENC_METADATA_DMX_GAIN_INF     = 7,
} MPEG4ENC_METADATA_DMX_GAIN;

typedef enum {
  MP4_METADATA_DSUR_NOT_INDICATED  = 0, /* Dolby Surround mode not indicated */
  MP4_METADATA_DSUR_NOT_USED       = 1, /* 2-ch audio part is not Dolby surround encoded */
  MP4_METADATA_DSUR_IS_USED        = 2  /* 2-ch audio part is Dolby surround encoded */
} MPEG4ENC_METADATA_DSUR_IND;

typedef enum {                          /* see ETSI TS 101 154 V1.11.1, section C.5.2.2.3 and C.5.3 */
  MP4_METADATA_DRCPRESENTATION_NOT_INDICATED = 0,
  MP4_METADATA_DRCPRESENTATION_MODE_1 = 1,
  MP4_METADATA_DRCPRESENTATION_MODE_2 = 2
} MPEG4ENC_METADATA_DRCPRESENTATION;

typedef enum {
  MP4_MAX_ASC_SIZE = 64,
  MP4_MAX_SMC_SIZE = 256,
  MAX_DRC_BANDS = (1<<4),
  MP4_MAX_NUM_STREAMS =  2
} MPEG4ENC_DEFINES;   


typedef enum {
  MPEG4ENC_SYNCFRAME_STARTUP = 0,
  MPEG4ENC_SYNCFRAME_SWITCH,
  MPEG4ENC_SYNCFRAME_DASH
} MPEG4ENC_SYNCFRAME_TYPES;   

typedef enum {
  MP4_MPSDMXGAIN_INVALID =  -1,
  MP4_MPSDMXGAIN_0_dB    =   0,
  MP4_MPSDMXGAIN_1_5_dB  =   1,
  MP4_MPSDMXGAIN_3_dB    =   2,
  MP4_MPSDMXGAIN_4_5_dB  =   3,
  MP4_MPSDMXGAIN_6_dB    =   4,
  MP4_MPSDMXGAIN_7_5_dB  =   5,
  MP4_MPSDMXGAIN_9_dB    =   6,
  MP4_MPSDMXGAIN_12_dB   =   7
} MPEG4ENC_MPS_DMX_GAIN;

#ifdef SUPPORT_UPMIX
typedef enum {
  MP4_SXPRO_DEFAULT = 0,
  MP4_SXPRO_DRY,
  MP4_SXPRO_VIBRANT
} MP4_SXPRO_UPMIX_WORKMODE;

typedef enum {
  MP4_SXPRO_LFE_OFF = 0,
  MP4_SXPRO_LFE_ON
} MP4_SXPRO_UPMIX_LFE;
#endif

/*-------------------- structure definitions ------------------------------*/

typedef struct {
  AUD_OBJ_TYP               aot;
  int                       nBitRate;
  MPEG4ENC_BITRATE_MODE     bitrateMode;
  MPEG4ENC_QUALITY          quality;
  MPEG4ENC_CH_MODE          chMode;
  int                       nSampleRateIn;
  MPEG4ENC_TRANSPORT_TYPE   transportFormat;
  MPEG4ENC_SIGNALING_MODE   sbrSignaling;
  MPEG4ENC_GRANULE_LEN      nGranuleLength;
  MPEG4ENC_METADATA_MODE    metadataMode;
} MPEG4ENC_SETUP;

typedef enum{
  MP4_THREADING_MODE_SINGLE = 1,
  MP4_THREADING_MODE_MULTIPLE_BLOCKING,
  MP4_THREADING_MODE_MULTIPLE_NOBLOCKING
} MPEG4ENC_THREADING_MODE;


typedef MPEG4ENC_SETUP *HANDLE_MPEG4ENC_SETUP;

struct MPEG4ENC_ENCODER;
typedef struct MPEG4ENC_ENCODER * HANDLE_MPEG4ENC_ENCODER;

typedef struct
{
  int  nOutputStreams;                              /* number of output streams */
  int  nAccessUnitsPerStream[MP4_MAX_NUM_STREAMS];  /* number of AUs in bitstream buffer */
  int *pnAccessUnitOffset[MP4_MAX_NUM_STREAMS];     /* offset of AUs per stream, i.e. pnAccessUnitOffset[stream][numberAuPerStream] */
  int *pByteCnt[MP4_MAX_NUM_STREAMS];               /* lenght of each single AU in bitstream buffer */
  int *pIsSync[MP4_MAX_NUM_STREAMS];            /* flag, signaling if AU is self contained i.e. does not contain backward dependencies */
} MPEG4ENC_AUINFO;

typedef struct {
  int            nAscSizeBits;
  unsigned char  ascBuffer[MP4_MAX_ASC_SIZE];
} MPEG4ENC_ASCBUF;

typedef struct {
  int            nSmcSizeBits;
  unsigned char  smcBuffer[MP4_MAX_ASC_SIZE];
} MPEG4ENC_SMCBUF;

typedef struct 
{
  float fBandWidth;       /* audio bandwidth in Hz */
  int   nDelay;           /* encoder delay in units of sample frames */
  int   nDelayCore;       /* encoder delay in units of sample frames */
  int   nCbBufSizeMin;    /* minimum size of output buffer (bytes) */
  int   nSyncFrameDelay;

  int   nBitRate[MP4_MAX_NUM_STREAMS];
  int   nMaxBitRate[MP4_MAX_NUM_STREAMS];
  int   nBitResMax[MP4_MAX_NUM_STREAMS];
  int   nSamplingRate[MP4_MAX_NUM_STREAMS];
  int   nSamplesFrame[MP4_MAX_NUM_STREAMS];

  unsigned int   nAncBytesPerFrame;
  int   aot;
  int   nValidAsc;
  MPEG4ENC_ASCBUF ascBuf[MP4_MAX_NUM_STREAMS];
  MPEG4ENC_SMCBUF smcBuf;
  int   nProfLev;

  char  pVersion[50];
  char  pBuildDate[50];

} MPEG4ENC_INFO;

typedef struct MPEG4ENC_METADATA
{
  MPEG4ENC_METADATA_DRC_PROFILE drc_profile;  /* MPEG DRC compression profile */
  MPEG4ENC_METADATA_DRC_PROFILE comp_profile; /* ETSI heavy compression profile */

  float drc_TargetRefLevel;   /* used to define expected level to */
  float comp_TargetRefLevel;  /* adjust limiter to avoid overload */

  float drc_ext;  /* external feed DRC compression value */
  float comp_ext; /* external feed heavy compression value */

  int prog_ref_level_present;   /* flag, if prog_ref_level is present */
  float prog_ref_level;         /* Programme Reference Level = Dialogue Level: */
                                /*    -31.75dB .. 0 dB ; stepsize: 0.25dB      */

  int  PCE_mixdown_idx_present; /* flag, if dmx-idx should be written in programme config element */
  int  ETSI_DmxLvl_present;     /* flag, if dmx-lvl should be written in ETSI-ancData */
  MPEG4ENC_METADATA_DMX_GAIN  centerMixLevel;          /* center downmix level */
  MPEG4ENC_METADATA_DMX_GAIN  surroundMixLevel;        /* surround downmix level */

  MPEG4ENC_METADATA_DSUR_IND dolbySurroundMode;   /* Indication for Dolby Surround Encoding Mode */

  MPEG4ENC_METADATA_DRCPRESENTATION drcPresentationMode; /* DRC presentation mode (ETSI) */

  /* preprocessing */
  int dcFilter;             /* flag specifying if DC filtering is applied to input */
  int lfeLowpassFilter;     /* flag specifying if 120 Hz low-pass filter is applied to LFE channel */
  int surPhase90;           /* flag specifying if 90 degree phase shift is applied to surround channels */
  int surAtt3dB;            /* flag specifying if 3 dB attenuation is applied to surround channels */

} MPEG4ENC_METADATA;

typedef struct MPEG4ENC_EXTMETADATA
{
#if 1 /* ENABLE_ISO14496_3_2009_AMD4 */
  /* not fully supported yet */
  /* extended ancillary data */
  int pseudoSurroundEnable;     /* flag */
  int extAncDataEnable;         /* flag */
  int extDownmixLevelEnable;    /* flag */
  int extDownmixLevel_A;        /* downmix level index A (0...7, according to table) */
  int extDownmixLevel_B;        /* downmix level index B (0...7, according to table) */
  int dmxGainEnable;            /* flag */
  float dmxGain5;               /* gain factor for downmix to 5 channels */
  float dmxGain2;               /* gain factor for downmix to 2 channels */
  int lfeDmxEnable;             /* flag */
  int lfeDmxLevel;              /* downmix level index for LFE (0..15, according to table) */
#endif
} MPEG4ENC_EXTMETADATA;

typedef struct MPEG4ENC_METADATA *HANDLE_MPEG4ENC_METADATA;
typedef struct MPEG4ENC_EXTMETADATA *HANDLE_MPEG4ENC_EXTMETADATA;


/*-------------------- function prototypes --------------------------------*/


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

    functionname: MPEG4ENC_Configure
    description : fills encoder handle structure with default values
                  to be called before MPEG4ENC_Open                  
    returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_Configure (
                    HANDLE_MPEG4ENC_ENCODER     *phMp4Enc,  /* adress of encoder handle */
                    const HANDLE_MPEG4ENC_SETUP  hSetup     /* handle to filled setup stucture  */
                    );

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

    functionname:MPEG4ENC_GetVersionInfo
    description: get Version Number information about the encoding process 
    returns:     MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI
MPEG4ENC_GetVersionInfo(char *const pVersionInfo,
                        const int bufSize);

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

    functionname: MPEG4ENC_Open
    description:  allocate and initialize a new encoder instance
                  samplesFirst holds the desired number of input
                  samples (of all channels) for the first frame
    returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

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

MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_Open(
              HANDLE_MPEG4ENC_ENCODER *phMp4Enc,     /* pointer to encoder handle, initialized on return */
              unsigned int* const      pSamplesFirst /* number of samples needed to encode the first frame */
              );

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

    functionname: MPEG4ENC_Close
    description:  deallocate an encoder instance
    returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

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

MPEG4ENC_ERROR MPEG4ENCAPI
MPEG4ENC_Close (
                HANDLE_MPEG4ENC_ENCODER* phMp4Enc  /* pointer to an encoder handle */
                );

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

    functionname: MPEG4ENC_Encode
    description:  encode the passed samples
    modifies:     pSamplesConsumed: number of used samples
                  pSamplesNext: number of samples needed to encode
                  the next frame
                  pOutputBytes: number of valid bytes in pOutput
    returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

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

MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_Encode(
                HANDLE_MPEG4ENC_ENCODER const hMp4Enc,          /* an encoder handle */
                const float* const            pSamples,         /* pointer to audio samples, interleaved*/
                const int                     nSamples,         /* number of samples
                                                                   must be a multiple of number of input channels */
                int*                          pSamplesConsumed, /* number of used input samples,
                                                                   will be a multiple of number of input channels */
                unsigned int* const           pSamplesNext,     /* number of desired samples for a complete frame */
                unsigned char* const          pOutput,          /* pointer to bitstream buffer */
                const int                     nOutputBufSize,   /* the size of the output buffer; 
                                                                   must be large enough to receive all data */
                int* const                    pOutputBytes,     /* number of bytes in bitstream buffer */
                MPEG4ENC_AUINFO             **ppAuInfo          /* */  
                );

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

    functionname: MPEG4ENC_SRInfo
    description : returns the sample rate range and 
                  to be called before MPEG4ENC_Open                  
    returns:      MPEG4ENC_NO_ERROR on success,
                  MPEG4ENC_INIT_ERROR if the bitrate, channel, aot configuration 
                  is not supported

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SRInfo (

                 const int       bitRate,        /* the targeted bit rate            */
                 const MPEG4ENC_BITRATE_MODE  bitrateMode,    /* the bitrateMode */
                 const MPEG4ENC_CH_MODE       chMode,         /* the number of channels to encode */
                 const AUD_OBJ_TYP            aot,            /* the audio object type */
                 const MPEG4ENC_QUALITY       quality,        /* encoder quality       */
                       int *const             sampleRateMin,  /* lowest supported      */
                       int *const             sampleRateMax,  /* highest supported     */
                       int *const             sampleRatePref  /* preferred
                                                                 sampling frequency for the given 
                                                                 bitrate, channel, aot configuration */
                 );

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

    functionname: MPEG4ENC_GetInfo
    description:  get information about the encoding process
    returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI
MPEG4ENC_GetInfo(const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                       MPEG4ENC_INFO * const   pInfo);

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

  functionname: MPEG4ENC_SetAncDataRate
  description:  Sets bitrate for ancillary data
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetAncDataRate(
                     HANDLE_MPEG4ENC_ENCODER hMp4Enc,                     
                     int                     nAncDataRate 
                     );

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

  functionname: MPEG4ENC_SetAncData
  description:  Passes ancillary data to encoder
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetAncData(
                    HANDLE_MPEG4ENC_ENCODER    const hMp4Enc,    /* an encoder handle */
                    unsigned char*             pAncBytes,        /* ancillary data buffer */
                    unsigned int*              pNumAncBytes      /* ancillary data bytes left */
                    );

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

  functionname: MPEG4ENC_SetOffsets
  description:  changes mapping of input audio channels to AAC channels
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetOffsets(
                     const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                     const unsigned int            nChannels,
                     const unsigned int *const     channelOffset
                     );

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

  functionname: MPEG4ENC_SetSbrTransmissionConfig
  description:  changes signaling interval of SBR header, additional CRC bits 
                for SBR data
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetSbrTransmissionConfig(
                                  const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                                  const int                     bUseCRC,
                                  const float                   sendHeaderTimeInterval
                                  );


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

  functionname: MPEG4ENC_SetInbandPceTimeInterval 
  description:  set update interval for explicit in band  PCE transmission 
                sendPceTimeInterval  > 0 -> regular time interval in seconds
                sendPceTimeInterval == 0 -> send no PCE (MPEG-2 only)
                sendPceTimeInterval  < 0 -> send PCE only the 1st frame
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetInbandPceTimeInterval(const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                                  const float                   sendPceTimeInterval);

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

  functionname: MPEG4ENC_SetAdtsPceTimeInterval 
  description:  set update interval for explicit channel signaling via PCE in
                case of ADTS transport stream, MPEG-2/4 AAC and 
                channel_configuration == 0
                sendPceTimeInterval  > 0 -> regular time interval in seconds
                sendPceTimeInterval == 0 -> send no PCE (MPEG-2 only)
                sendPceTimeInterval  < 0 -> send PCE only the 1st frame
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetAdtsPceTimeInterval(
				const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
				const float                   sendPceTimeInterval
				);

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

  functionname: MPEG4ENC_MpsSetSscTimeInterval 
  description:  set update interval for transmission of SpatialSpecificConfig
                (SSC) in case of encoding using MPEG Surround 
                sendSscTimeInterval  > 0 -> regular time interval in seconds
                sendSscTimeInterval == 0 -> send SSC every (MPEGS) frame
                sendSscTimeInterval  < 0 -> send SSC only the 1st frame
                - in combination with MPEGS only
                - MPEGS payload mode has to be MP4_MPEGS_PAYLOAD_EMBED, because 
                  otherwise the SSC is transmitted in a seperate ESD, which has 
                  to be handled by the user
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_MpsSetSscTimeInterval(
                               const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                               const float                   sendSscTimeInterval
                               );

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

  functionname: MPEG4ENC_MpsSetDownmixConfig
  description:  set MPEG Surround Downmix Configuration
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_MpsSetDownmixConfig(
                             const HANDLE_MPEG4ENC_ENCODER       hMp4Enc,
                             const MPEG4ENC_MPEGS_DOWNMIX_CONFIG mpegsDownmixCfg
                             );

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

  functionname: MPEG4ENC_MpsSetPayloadMode
  description:  set MPEG Surround Payload Transmission Mode 
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_MpsSetPayloadMode(
                           const HANDLE_MPEG4ENC_ENCODER       hMp4Enc,
                           const MPEG4ENC_MPEGS_PAYLOAD_MODE   mpegsPayloadMode
                           );

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

  functionname: MPEG4ENC_SetThreadingMode (deprecated)
  description:  sets threading mode to single threaded, multiple threaded
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

  Please note that this function is deprecated and should not be used any more.

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetThreadingMode(const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                          const MPEG4ENC_THREADING_MODE threadingMode);


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

  functionname: MPEG4ENC_GetError
  description:  get error text
  returns:      pointer to an error text

 ------------------------------------------------------------------------------*/
char*  MPEG4ENCAPI 
MPEG4ENC_GetError(MPEG4ENC_ERROR error);

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

  functionname: MPEG4ENC_SetBandwidth
  description:  set bandwidth by user, returns with actual used bandwidth
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetBandwidth(const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                      const float proposedBandwidth,
                      float* usedBandwidth);

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

  functionname: MPEG4ENC_SetStereoPrePro
  description:  set bandwidth by user, returns with actual used bandwidth
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetStereoPrePro(const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                         const int enableStereoPrePro);


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

  functionname: MPEG4ENC_SetLatmSmcTimeInterval 
  description:  set update interval for appearance of stream mux config in
                case of LOAS/LATM transport stream
                sendSmcTimeInterval  > 0 -> regular time interval (every n-th frame, default: 8)
                sendSmcTimeInterval == 0 -> send no inband StreamMuxConfig
                sendSmcTimeInterval  < 0 -> send StreamMuxConfig only the 1st frame
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetLatmSmcTimeInterval(
				const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
				const int                     sendSmcTimeInterval
				);

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

  functionname: MPEG4ENC_SetLatmNrOfSubframes
  description:  set the nr of subframes per latm frame in
                case of LOAS/LATM transport stream
                nrOfSubframes < 1  -> reserved
                nrOfSubframes >= 1 -> use 'nrOfSubframes'

                optional, default is 1

  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetLatmNrOfSubframes(
                              const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                              const int                     nrOfSubframes
                              );


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

  functionname: MPEG4ENC_GetLatmSmc
  description:  returns pointer to and size of LATM stream mux config

  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_GetLatmSmc(
                    const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                    unsigned char**               buffer,
                    int*                          nBits
                    );


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

    functionname: MPEG4ENC_Submit_Metadata
    description:  submit metadata
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_Submit_Metadata(
                         const HANDLE_MPEG4ENC_ENCODER  hMpeg4Enc,        /* an encoder handle */
                         const HANDLE_MPEG4ENC_METADATA pMetadata         /* pointer to metadata */
                        );
                        
                        
/*---------------------------------------------------------------------------

    functionname: MPEG4ENC_Submit_ExtMetadata
    description:  submit metadata
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_Submit_ExtMetadata(
                         const HANDLE_MPEG4ENC_ENCODER  hMpeg4Enc,        /* an encoder handle */
                         const HANDLE_MPEG4ENC_EXTMETADATA pExtMetadata   /* pointer to extended metadata */
                        );



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

    functionname: MPEG4ENC_BRInfo
    description : Provides the compatible bitrate range
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_BRInfo (
                 const AUD_OBJ_TYP        aot,
                 const MPEG4ENC_CH_MODE   chMode,
                 const int                samplingRate,
                 int*                     brMin,
                 int*                     brMax);


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

    functionname: MPEG4ENC_SetSbrSpeechConfig
    description : Sets SBR Speech config flag
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetSbrSpeechConfig(
                            const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                            unsigned int                  flag
                           );


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

    functionname: MPEG4ENC_SetSbrTimeDiffCoding
    description : Sets SBR time differential coding (TDC); 
                    flag==0: Do not use TDC
                    flag==1: Use TDC
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetSbrTimeDiffCoding(
                              const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                              unsigned int                  flag
                             );


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

    functionname: MPEG4ENC_SetUseIntensityStereo
    description : Sets intensity stereo coding (IS); 
                    flag==1: Use IS (default)
                    flag==0: Do not use IS
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetUseIntensityStereo(
                               const HANDLE_MPEG4ENC_ENCODER hMp4Enc,
                               unsigned int                  flag
                              );


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

  functionname: MPEG4ENC_SendChCfgZero
  description:  will always use channel config zero + pce although a standard 
                channel config could be signalled
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SendChCfgZero(
                       const HANDLE_MPEG4ENC_ENCODER hMp4Enc
                       );



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

  functionname: MPEG4ENC_SetSyncFrame
  description:  will generate a synchaable frame
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetSyncFrame(
                      const HANDLE_MPEG4ENC_ENCODER hMp4Enc
                      );


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

  functionname: MPEG4ENC_SetSyncFrameWithType
  description:  will generate a synchaable frame
  returns:      MPEG4ENC_NO_ERROR on success, an appropriate error code else

 ------------------------------------------------------------------------------*/
MPEG4ENC_ERROR  MPEG4ENCAPI
MPEG4ENC_SetSyncFrameWithType(
                              const HANDLE_MPEG4ENC_ENCODER  hMp4Enc,
                              const MPEG4ENC_SYNCFRAME_TYPES syncType
                              );


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

    functionname: MPEG4ENC_InitDASH
    description : Configure encoder for DASH mode
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_InitDASH(
                  const HANDLE_MPEG4ENC_ENCODER   hMp4Enc
                  );


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

    functionname: MPEG4ENC_SetTransportType
    description : Reconfigure Transport Format
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetTransportType(
                          const HANDLE_MPEG4ENC_ENCODER   hMp4Enc,
                          const MPEG4ENC_TRANSPORT_TYPE   transportType
                          );


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

    functionname: MPEG4ENC_SetMPEG4Flag
    description : Reconfigure MPEG-2/4 compliance
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetMPEG4Flag(
                      const HANDLE_MPEG4ENC_ENCODER   hMp4Enc,
                      const int                       mpeg4Flag
                      );


#ifdef SUPPORT_UPMIX
/*---------------------------------------------------------------------------

    functionname: MPEG4ENC_SetSXProUpmixParameter
    description : Sets SXPro parameters; 
                    umxMode: Upmix workmode
                    umxLFE:  Upmix LFE on/off
    returns:      MPEG4ENC_ERROR (error code)

  ---------------------------------------------------------------------------*/
MPEG4ENC_ERROR MPEG4ENCAPI 
MPEG4ENC_SetSXProUpmixParameter(
                                const HANDLE_MPEG4ENC_ENCODER   hMp4Enc,
                                const MP4_SXPRO_UPMIX_WORKMODE  umxMode,
                                const MP4_SXPRO_UPMIX_LFE       umxLFE
                               );
#endif


/*---------------------------------------------------------------------------*/
#if defined(WIN32) || defined(WIN64)
#pragma pack(pop)
#endif

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

#ifdef __cplusplus
}
#endif

#endif /* _mp4FastAAClib_h_  */