comparison bytestream.h @ 4488:601865b7fc26 libavcodec

simplify and remove useless index in AV_W*
author michael
date Tue, 06 Feb 2007 19:10:17 +0000
parents 05e932ddaaa9
children 76be6cfd7958
comparison
equal deleted inserted replaced
4487:0a0a9f0c9c2d 4488:601865b7fc26
20 */ 20 */
21 21
22 #ifndef FFMPEG_BYTESTREAM_H 22 #ifndef FFMPEG_BYTESTREAM_H
23 #define FFMPEG_BYTESTREAM_H 23 #define FFMPEG_BYTESTREAM_H
24 24
25 static av_always_inline unsigned int bytestream_get_le32(uint8_t **b) 25 #define DEF(name, bytes, read, write)\
26 { 26 static av_always_inline unsigned int bytestream_get_ ## name(uint8_t **b){\
27 (*b) += 4; 27 (*b) += bytes;\
28 return AV_RL32(*b - 4); 28 return read(*b - bytes);\
29 } 29 }\
30 static av_always_inline void bytestream_put_ ##name(uint8_t **b, const unsigned int value){\
31 write(*b, value);\
32 (*b) += bytes;\
33 };
30 34
31 static av_always_inline unsigned int bytestream_get_le16(uint8_t **b) 35 DEF(le32, 4, AV_RL32, AV_WL32)
32 { 36 DEF(le16, 2, AV_RL16, AV_WL16)
33 (*b) += 2; 37 DEF(be32, 4, AV_RB32, AV_WB32)
34 return AV_RL16(*b - 2); 38 DEF(be16, 2, AV_RB16, AV_WB16)
35 } 39 DEF(byte, 1, AV_RB8 , AV_WB8 )
36 40
37 static av_always_inline unsigned int bytestream_get_byte(uint8_t **b) 41 #undef DEF
38 {
39 (*b)++;
40 return (*b)[-1];
41 }
42 42
43 static av_always_inline unsigned int bytestream_get_buffer(uint8_t **b, uint8_t *dst, unsigned int size) 43 static av_always_inline unsigned int bytestream_get_buffer(uint8_t **b, uint8_t *dst, unsigned int size)
44 { 44 {
45 memcpy(dst, *b, size); 45 memcpy(dst, *b, size);
46 (*b) += size; 46 (*b) += size;
47 return size; 47 return size;
48 }
49
50 static av_always_inline void bytestream_put_be32(uint8_t **b, const unsigned int value)
51 {
52 *(*b)++ = value >> 24;
53 *(*b)++ = value >> 16;
54 *(*b)++ = value >> 8;
55 *(*b)++ = value;
56 };
57
58 static av_always_inline void bytestream_put_be16(uint8_t **b, const unsigned int value)
59 {
60 *(*b)++ = value >> 8;
61 *(*b)++ = value;
62 }
63
64 static av_always_inline void bytestream_put_le32(uint8_t **b, const unsigned int value)
65 {
66 *(*b)++ = value;
67 *(*b)++ = value >> 8;
68 *(*b)++ = value >> 16;
69 *(*b)++ = value >> 24;
70 }
71
72 static av_always_inline void bytestream_put_le16(uint8_t **b, const unsigned int value)
73 {
74 *(*b)++ = value;
75 *(*b)++ = value >> 8;
76 }
77
78 static av_always_inline void bytestream_put_byte(uint8_t **b, const unsigned int value)
79 {
80 *(*b)++ = value;
81 } 48 }
82 49
83 static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size) 50 static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
84 { 51 {
85 memcpy(*b, src, size); 52 memcpy(*b, src, size);