// Copyright 2014-2025 Jesper Larsson
//
// This file is part of Klipspringer, <https://klipspringer.avadeaux.net/>
//
// Klipspringer is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Klipspringer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Klipspringer. If
// not, see <https://www.gnu.org/licenses/>.

package net.avadeaux.klipspringer.codec;

import java.io.IOException;

/** FLAC file decoder that interfaces to FLAC library. In order to receive pictures from FLAC
  * metadata, use a subclass of this class that implements {@link PictureTarget}.
  */
public class FlacDecoder extends ExternalDecoder {
    void checkSupported() {
        if (!Library.flacSupported()) {
            throw new UnsupportedOperationException("Klipspringer library lacks FLAC support");
        }
    }

    /** Initiates decoder, including opening the file. */
    public FlacDecoder(String fileName, Target target) throws IOException {
        super(fileName, target);
    }

    // invoked by superclass
    long create(String fnam, byte[] bfnam) throws IOException {
        return create(bfnam, fnam.endsWith(".oga"));
    }

    // Native methods.
    private native long create(byte[] fnam, boolean ogg) throws IOException;
    native void rewind(long handle) throws IOException;
    native void free(long handle);
    native void nativeSeek(long handle, long samplePos) throws IOException;
    native void nativeDecodeMetadata(long handle) throws IOException;
    native boolean nativeDecodeAll(long handle) throws IOException;
}
