1 /* 2 * Copyright (c) 2024, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 3-Clause Clear License 5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear 6 * License was not distributed with this source code in the LICENSE file, you 7 * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the 8 * Alliance for Open Media Patent License 1.0 was not distributed with this 9 * source code in the PATENTS file, you can obtain it at 10 * www.aomedia.org/license/patent. 11 */ 12 13 #ifndef CLI_CODEC_FLAC_DECODER_STREAM_CALLBACKS_H_ 14 #define CLI_CODEC_FLAC_DECODER_STREAM_CALLBACKS_H_ 15 16 #include <cstddef> 17 18 #include "include/FLAC/format.h" 19 #include "include/FLAC/ordinals.h" 20 #include "include/FLAC/stream_decoder.h" 21 22 namespace iamf_tools { 23 /*!\brief Reads an encoded flac frame into the libflac decoder 24 * 25 * This callback function is used whenever the decoder needs more input data. 26 * 27 * \param decoder libflac stream decoder 28 * This parameter is not used in this implementation, but is included to 29 * override the libflac signature. 30 * \param buffer Output buffer for the encoded frame. 31 * \param bytes Maximum size of the buffer; in the case of a successful read, 32 * this will be set to the actual number of bytes read. 33 * \param client_data universal pointer, which in this case should point to 34 * FlacDecoder. 35 * 36 * \return A libflac read status indicating whether the read was successful. 37 */ 38 FLAC__StreamDecoderReadStatus LibFlacReadCallback( 39 const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, 40 void* client_data); 41 42 /*!\brief Writes a decoded flac frame to an instance of FlacDecoder. 43 * 44 * This callback function is used to write out a decoded frame from the libflac 45 * decoder. 46 * 47 * \param decoder Unused libflac stream decoder. This parameter is not used in 48 * this implementation, but is included to override the libflac 49 * signature. 50 * \param frame libflac encoded frame metadata. 51 * \param buffer Array of pointers to decoded channels of data. Each pointer 52 * will point to an array of signed samples of length 53 * `frame->header.blocksize`. Channels will be ordered according to the 54 * FLAC specification. 55 * \param client_data Universal pointer, which in this case should point to 56 * FlacDecoder. 57 * 58 * \return A libflac write status indicating whether the write was successful. 59 */ 60 FLAC__StreamDecoderWriteStatus LibFlacWriteCallback( 61 const FLAC__StreamDecoder* /*decoder*/, const FLAC__Frame* frame, 62 const FLAC__int32* const buffer[], void* client_data); 63 64 /*!\brief Logs an error from the libflac decoder. 65 * 66 * This function will be called whenever an error occurs during libflac 67 * decoding. 68 * 69 * \param decoder libflac stream decoder 70 * This parameter is not used in this implementation, but is included to 71 * override the libflac signature. 72 * \param status The error encountered by the decoder. 73 * \param client_data Universal pointer, which in this case should point to 74 * FlacDecoder. Unused in this implementation. 75 */ 76 void LibFlacErrorCallback(const FLAC__StreamDecoder* /*decoder*/, 77 FLAC__StreamDecoderErrorStatus status, 78 void* /*client_data*/); 79 80 } // namespace iamf_tools 81 82 #endif // CLI_CODEC_FLAC_DECODER_STREAM_CALLBACKS_H_ 83