// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CGGeometry.h>
#include <stddef.h>
#include <stdint.h>

extern "C" {

//
// Declare CoreMedia types.
//

typedef signed long CMItemCount;
typedef uint32_t CMBlockBufferFlags;
typedef struct OpaqueCMBlockBuffer *CMBlockBufferRef;
typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
typedef CMFormatDescriptionRef CMVideoFormatDescriptionRef;
typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;

typedef int64_t CMTimeValue;
typedef int32_t CMTimeScale;
typedef int64_t CMTimeEpoch;
typedef uint32_t CMTimeFlags;

typedef struct {
  CMTimeValue value;
  CMTimeScale timescale;
  CMTimeFlags flags;
  CMTimeEpoch epoch;
} CMTime;

typedef struct {
  CMTime duration;
  CMTime presentationTimeStamp;
  CMTime decodeTimeStamp;
} CMSampleTimingInfo;

typedef struct {
  int32_t width;
  int32_t height;
} CMVideoDimensions;

typedef struct {
  uint32_t version;
  void *(*AllocateBlock)(void *refCon, size_t sizeInBytes);
  void (*FreeBlock)(void *refCon, void *doomedMemoryBlock, size_t sizeInBytes);
  void *refCon;
} CMBlockBufferCustomBlockSource;

typedef OSStatus (*CMSampleBufferMakeDataReadyCallback)(
    CMSampleBufferRef sbuf,
    void *makeDataReadyRefcon);

//
// Declare VideoToolbox types.
//

typedef struct __CVBuffer *CVBufferRef;
typedef CVBufferRef CVImageBufferRef;
typedef uint32_t VTDecodeFrameFlags;
enum {
  kVTDecodeFrame_EnableAsynchronousDecompression = 1 << 0,
  kVTDecodeFrame_DoNotOutputFrame = 1 << 1,
  kVTDecodeFrame_1xRealTimePlayback = 1 << 2,
  kVTDecodeFrame_EnableTemporalProcessing = 1 << 3,
};
typedef UInt32 VTDecodeInfoFlags;
typedef struct OpaqueVTDecompressionSession* VTDecompressionSessionRef;
typedef CFTypeRef VTSessionRef;

typedef void (*VTDecompressionOutputCallback)(
    void *decompressionOutputRefCon,
    void *sourceFrameRefCon,
    OSStatus status,
    VTDecodeInfoFlags infoFlags,
    CVImageBufferRef imageBuffer,
    CMTime presentationTimeStamp,
    CMTime presentationDuration);

typedef struct {
  VTDecompressionOutputCallback decompressionOutputCallback;
  void *decompressionOutputRefCon;
} VTDecompressionOutputCallbackRecord;

}  // extern "C"
