Path: blob/master/dep/ffmpeg/include/libavutil/bswap.h
4216 views
/*1* copyright (c) 2006 Michael Niedermayer <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920/**21* @file22* byte swapping routines23*/2425#ifndef AVUTIL_BSWAP_H26#define AVUTIL_BSWAP_H2728#include <stdint.h>29#include "libavutil/avconfig.h"30#include "attributes.h"3132#ifdef HAVE_AV_CONFIG_H3334#include "config.h"3536#if ARCH_ARM37# include "arm/bswap.h"38#elif ARCH_RISCV39# include "riscv/bswap.h"40#elif ARCH_X8641# include "x86/bswap.h"42#endif4344#endif /* HAVE_AV_CONFIG_H */4546#define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff))47#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))48#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))4950#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)5152#ifndef av_bswap1653static av_always_inline av_const uint16_t av_bswap16(uint16_t x)54{55x= (x>>8) | (x<<8);56return x;57}58#endif5960#ifndef av_bswap3261static av_always_inline av_const uint32_t av_bswap32(uint32_t x)62{63return AV_BSWAP32C(x);64}65#endif6667#ifndef av_bswap6468static inline uint64_t av_const av_bswap64(uint64_t x)69{70return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);71}72#endif7374// be2ne ... big-endian to native-endian75// le2ne ... little-endian to native-endian7677#if AV_HAVE_BIGENDIAN78#define av_be2ne16(x) (x)79#define av_be2ne32(x) (x)80#define av_be2ne64(x) (x)81#define av_le2ne16(x) av_bswap16(x)82#define av_le2ne32(x) av_bswap32(x)83#define av_le2ne64(x) av_bswap64(x)84#define AV_BE2NEC(s, x) (x)85#define AV_LE2NEC(s, x) AV_BSWAPC(s, x)86#else87#define av_be2ne16(x) av_bswap16(x)88#define av_be2ne32(x) av_bswap32(x)89#define av_be2ne64(x) av_bswap64(x)90#define av_le2ne16(x) (x)91#define av_le2ne32(x) (x)92#define av_le2ne64(x) (x)93#define AV_BE2NEC(s, x) AV_BSWAPC(s, x)94#define AV_LE2NEC(s, x) (x)95#endif9697#define AV_BE2NE16C(x) AV_BE2NEC(16, x)98#define AV_BE2NE32C(x) AV_BE2NEC(32, x)99#define AV_BE2NE64C(x) AV_BE2NEC(64, x)100#define AV_LE2NE16C(x) AV_LE2NEC(16, x)101#define AV_LE2NE32C(x) AV_LE2NEC(32, x)102#define AV_LE2NE64C(x) AV_LE2NEC(64, x)103104#endif /* AVUTIL_BSWAP_H */105106107