00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #ifndef AVCODEC_BYTESTREAM_H
00023 #define AVCODEC_BYTESTREAM_H
00024 
00025 #include <string.h>
00026 #include "libavutil/common.h"
00027 #include "libavutil/intreadwrite.h"
00028 
00029 #define DEF_T(type, name, bytes, read, write)                             \
00030 static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\
00031     (*b) += bytes;\
00032     return read(*b - bytes);\
00033 }\
00034 static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\
00035     write(*b, value);\
00036     (*b) += bytes;\
00037 }
00038 
00039 #define DEF(name, bytes, read, write) \
00040     DEF_T(unsigned int, name, bytes, read, write)
00041 #define DEF64(name, bytes, read, write) \
00042     DEF_T(uint64_t, name, bytes, read, write)
00043 
00044 DEF64(le64, 8, AV_RL64, AV_WL64)
00045 DEF  (le32, 4, AV_RL32, AV_WL32)
00046 DEF  (le24, 3, AV_RL24, AV_WL24)
00047 DEF  (le16, 2, AV_RL16, AV_WL16)
00048 DEF64(be64, 8, AV_RB64, AV_WB64)
00049 DEF  (be32, 4, AV_RB32, AV_WB32)
00050 DEF  (be24, 3, AV_RB24, AV_WB24)
00051 DEF  (be16, 2, AV_RB16, AV_WB16)
00052 DEF  (byte, 1, AV_RB8 , AV_WB8 )
00053 
00054 #undef DEF
00055 #undef DEF64
00056 #undef DEF_T
00057 
00058 static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
00059 {
00060     memcpy(dst, *b, size);
00061     (*b) += size;
00062     return size;
00063 }
00064 
00065 static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
00066 {
00067     memcpy(*b, src, size);
00068     (*b) += size;
00069 }
00070 
00071 #endif