1 module ffmpeg.libavresample.audio_data; 2 import std.stdint; 3 import ffmpeg.libavutil.avutil; 4 import ffmpeg.libavutil.samplefmt; 5 6 import ffmpeg.libavresample.avresample; 7 8 @nogc nothrow extern(C): 9 10 int ff_sample_fmt_is_planar(AVSampleFormat sample_fmt, int channels); 11 12 /** 13 * Audio buffer used for intermediate storage between conversion phases. 14 */ 15 struct AudioData { 16 const AVClass *_class; /**< AVClass for logging */ 17 uint8_t[AVRESAMPLE_MAX_CHANNELS] *data; /**< data plane pointers */ 18 uint8_t *buffer; /**< data buffer */ 19 uint buffer_size; /**< allocated buffer size */ 20 int allocated_samples; /**< number of samples the buffer can hold */ 21 int nb_samples; /**< current number of samples */ 22 AVSampleFormat sample_fmt; /**< sample format */ 23 int channels; /**< channel count */ 24 int allocated_channels; /**< allocated channel count */ 25 int is_planar; /**< sample format is planar */ 26 int planes; /**< number of data planes */ 27 int sample_size; /**< bytes per sample */ 28 int stride; /**< sample byte offset within a plane */ 29 int read_only; /**< data is read-only */ 30 int allow_realloc; /**< realloc is allowed */ 31 int ptr_align; /**< minimum data pointer alignment */ 32 int samples_align; /**< allocated samples alignment */ 33 const char *name; /**< name for debug logging */ 34 } 35 36 int ff_audio_data_set_channels(AudioData *a, int channels); 37 38 /** 39 * Initialize AudioData using a given source. 40 * 41 * This does not allocate an internal buffer. It only sets the data pointers 42 * and audio parameters. 43 * 44 * @param a AudioData struct 45 * @param src source data pointers 46 * @param plane_size plane size, in bytes. 47 * This can be 0 if unknown, but that will lead to 48 * optimized functions not being used in many cases, 49 * which could slow down some conversions. 50 * @param channels channel count 51 * @param nb_samples number of samples in the source data 52 * @param sample_fmt sample format 53 * @param read_only indicates if buffer is read only or read/write 54 * @param name name for debug logging (can be NULL) 55 * @return 0 on success, negative AVERROR value on error 56 */ 57 int ff_audio_data_init(AudioData *a, uint8_t * *src, int plane_size, 58 int channels, int nb_samples, 59 AVSampleFormat sample_fmt, int read_only, 60 const char *name); 61 62 /** 63 * Allocate AudioData. 64 * 65 * This allocates an internal buffer and sets audio parameters. 66 * 67 * @param channels channel count 68 * @param nb_samples number of samples to allocate space for 69 * @param sample_fmt sample format 70 * @param name name for debug logging (can be NULL) 71 * @return newly allocated AudioData struct, or NULL on error 72 */ 73 AudioData *ff_audio_data_alloc(int channels, int nb_samples, 74 AVSampleFormat sample_fmt, 75 const char *name); 76 77 /** 78 * Reallocate AudioData. 79 * 80 * The AudioData must have been previously allocated with ff_audio_data_alloc(). 81 * 82 * @param a AudioData struct 83 * @param nb_samples number of samples to allocate space for 84 * @return 0 on success, negative AVERROR value on error 85 */ 86 int ff_audio_data_realloc(AudioData *a, int nb_samples); 87 88 /** 89 * Free AudioData. 90 * 91 * The AudioData must have been previously allocated with ff_audio_data_alloc(). 92 * 93 * @param a AudioData struct 94 */ 95 void ff_audio_data_free(AudioData **a); 96 97 /** 98 * Copy data from one AudioData to another. 99 * 100 * @param out output AudioData 101 * @param in input AudioData 102 * @param map channel map, NULL if not remapping 103 * @return 0 on success, negative AVERROR value on error 104 */ 105 //int ff_audio_data_copy(AudioData *out_ad, AudioData *in_ad, ChannelMapInfo *map); 106 107 /** 108 * Append data from one AudioData to the end of another. 109 * 110 * @param dst destination AudioData 111 * @param dst_offset offset, in samples, to start writing, relative to the 112 * start of dst 113 * @param src source AudioData 114 * @param src_offset offset, in samples, to start copying, relative to the 115 * start of the src 116 * @param nb_samples number of samples to copy 117 * @return 0 on success, negative AVERROR value on error 118 */ 119 int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src, 120 int src_offset, int nb_samples); 121 122 /** 123 * Drain samples from the start of the AudioData. 124 * 125 * Remaining samples are shifted to the start of the AudioData. 126 * 127 * @param a AudioData struct 128 * @param nb_samples number of samples to drain 129 */ 130 void ff_audio_data_drain(AudioData *a, int nb_samples); 131 132 /** 133 * Add samples in AudioData to an AVAudioFifo. 134 * 135 * @param af Audio FIFO Buffer 136 * @param a AudioData struct 137 * @param offset number of samples to skip from the start of the data 138 * @param nb_samples number of samples to add to the FIFO 139 * @return number of samples actually added to the FIFO, or 140 * negative AVERROR code on error 141 */ 142 //int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, 143 // int nb_samples); 144 145 /** 146 * Read samples from an AVAudioFifo to AudioData. 147 * 148 * @param af Audio FIFO Buffer 149 * @param a AudioData struct 150 * @param nb_samples number of samples to read from the FIFO 151 * @return number of samples actually read from the FIFO, or 152 * negative AVERROR code on error 153 */ 154 //int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples);