简体   繁体   中英

Macros in C++ / FFMPEG

I'm new to C++ and I'm trying to build a custom codec for FFMPEG. I'm trying to base it off of PCM but with only one type. I've run into a macro and I have no idea what the macro turns into after it compiles. The macro looks like this:

#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)          \
n /= avctx->channels;                                               \
for (c = 0; c < avctx->channels; c++) {                             \
    int i;                                                          \
    samples_ ## type = (const type *) frame->extended_data[c];      \
    for (i = n; i > 0; i--) {                                       \
        register type v = (*samples_ ## type++ >> shift) + offset;  \
        bytestream_put_ ## endian(&dst, v);                         \
    }                                                               \
}

Would the samples_ declaration line and bytestream_put line be equal to what I put below if endian = byte and type = uint8_t?

uint8_t samples_ = (const uint8_t *) frame->extended_data[c];
bytestream_put_byte(&dst, v);

I find it very confusing and I am unsure if this is correct.

This C macro (not C++) used in FFmpeg's pcm.c file, pcm_encode_frame function. PCM audio frames (either 8, 16, 24 or 32 bit) at various channel configuration and endianness either stored in packed (interleaved) or planar format. This macro (as clearly seen in the file) used to fill buffers as planar format.

Example expansion will be like this (for AV_CODEC_ID_PCM_S16LE_PLANAR):

n /= avctx->channels;
for (c = 0; c < avctx->channels; c++) {
    int i;
    samples_int16_t = (const int16_t *) frame->extended_data[c];
    for (i = n; i > 0; i--) {
        register int16_t v = (*samples_int16_t++ >> 0) + 0;
        bytestream_put_le16(&dst, v);
    }
}

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM