/*---------------------------------------------------------------------------*/
/* video_decoder.h                                                           */
/* copyright (c) innovaphone 2018                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class VideoDecoderH264 : public IMediaDecoder, public UMediaTranscoder
{
    class IIoMux * const iomux;
    class UMediaDecoder * const user;
    class IInstanceLog * const log;

    char * videoFrame;
    int frameLength;
    bool dropFrame;
    bool sequenceGap;
    bool rtpMarker;
    dword lTimestamp;
    int maxRtpVideoData;

    int frameLengthFua;
    int fragSb;
    dword fuaTimestamp;

    void TranscodeResult(class IMediaTranscoder * transcoder, const void * buf, int len, dword timestamp, dword duration, short sequenceDiff, int width, int height, int stride, dword flags);
    void MediaTranscoderCloseResult(class IMediaTranscoder * transcoder);
    IMediaTranscoder * transcoder;

    bool shutDown;
    int execCnt;

public:
    VideoDecoderH264(class IIoMux * const iomux, class UMediaDecoder * const user, class IInstanceLog * log);
    ~VideoDecoderH264();

    // IMediaDecoder
    void DecodeFrame(const void *buf, int len, dword timestamp) override;
    void DecodeStream(const void *stream, int len, dword timestamp, short sequenceNumberDiff, bool marker) override;
    void Close() override;
    enum VideoCoder GetVideoDecoder() override { return VideoCoder::H264; };
};

class VideoDecoderVPX : public IMediaDecoder, public UMediaTranscoder
{
    class IIoMux * const iomux;
    class UMediaDecoder * const user;
    class IInstanceLog * const log;

    bool vp9;

    void TranscodeResult(class IMediaTranscoder * transcoder, const void * buf, int len, dword timestamp, dword duration, short sequenceDiff, int width, int height, int stride, dword flags);
    void MediaTranscoderCloseResult(class IMediaTranscoder * transcoder);
    IMediaTranscoder * transcoder;
    bool shutDown;
    int execCnt;

    byte * videoFrame;
    int frameLength;
    bool dropFrame;
    bool sequenceGap;
    bool rtpMarker;
    dword lTimestamp;
    int fragSb;
    int vp8PicId;
    int rxVp8PicId;

    byte * image;
    int imageSize;

public:
    VideoDecoderVPX(class IIoMux * const iomux, class UMediaDecoder * const user, class IInstanceLog * log, bool vp9);
    ~VideoDecoderVPX();

    // IMediaDecoder
    void DecodeFrame(const void *buf, int len, dword timestamp) override;
    void DecodeStream(const void *stream, int len, dword timestamp, short sequenceNumberDiff, bool marker) override;
    void Close() override;
    enum VideoCoder GetVideoDecoder() override { return vp9 ? VideoCoder::VP9 : VideoCoder::VP8; };
};
