/**
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sac_bitdec.h"
#include "sac_dec_conceal.h"
#include <iostream>

#define MAX_PARAMETER_SETS (9)
#define MAX_NUM_OTT (5)
#define ARR_SIZE (16)

typedef signed char SCHAR;

int main() {
  spatialDec decoder;
  memset(&decoder, 0x0, sizeof(spatialDec));

  decoder.numOttBoxes = MAX_NUM_OTT;

  SPATIAL_SPECIFIC_CONFIG pConfigCurrent;
  memset(&pConfigCurrent, 0x0, sizeof(SPATIAL_SPECIFIC_CONFIG));
  decoder.pConfigCurrent = &pConfigCurrent;

  SCHAR ottCLDidxPrev[ARR_SIZE] = {};
  decoder.ottCLDidxPrev = (SCHAR **)&ottCLDidxPrev;

  int smgTime = 1;
  decoder.smgTime = &smgTime;

  UCHAR smgData[ARR_SIZE] = {};
  decoder.smgData = (UCHAR **)&smgData;

  SMOOTHING_STATE smoothState;
  memset(&smoothState, 0x0, sizeof(SMOOTHING_STATE));
  decoder.smoothState = &smoothState;

  decoder.arbitraryDownmix = 0;
  (decoder.concealInfo).concealState = SpatialDecConcealState_Ok;

  const size_t allocSize = MAX_NUM_OTT * MAX_NUM_PARAMETERS;

  SPATIAL_BS_FRAME frame;
  memset(&frame, 0x0, sizeof(SPATIAL_BS_FRAME));

  frame.numParameterSets = MAX_PARAMETER_SETS;

  LOSSLESSDATA CLDLosslessData[allocSize] = {};
  frame.CLDLosslessData = CLDLosslessData;

  LOSSLESSDATA ICCLosslessData[allocSize] = {};
  frame.ICCLosslessData = ICCLosslessData;

  LOSSLESSDATA IPDLosslessData[allocSize] = {};
  frame.IPDLosslessData = IPDLosslessData;

  for (int i = 0; i < MAX_NUM_OTT; ++i) {
    for (int j = 0; j < MAX_PARAMETER_SETS; ++j) {
      (frame.CLDLosslessData[i]).bsXXXDataMode[j] = 2;
    }
    LOSSLESSSTATE lossLessState;
    (frame.CLDLosslessData[i]).state = &lossLessState;
  }

  SpatialDecDecodeFrame(&decoder, &frame);
  return EXIT_SUCCESS;
}
