• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/bytestream.h

Go to the documentation of this file.
00001 /*
00002  * Bytestream functions
00003  * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 typedef struct {
00030     const uint8_t *buffer, *buffer_end;
00031 } GetByteContext;
00032 
00033 #define DEF_T(type, name, bytes, read, write)                             \
00034 static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\
00035     (*b) += bytes;\
00036     return read(*b - bytes);\
00037 }\
00038 static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\
00039     write(*b, value);\
00040     (*b) += bytes;\
00041 }\
00042 static av_always_inline type bytestream2_get_ ## name(GetByteContext *g)\
00043 {\
00044     if (g->buffer_end - g->buffer < bytes)\
00045         return 0;\
00046     return bytestream_get_ ## name(&g->buffer);\
00047 }\
00048 static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)\
00049 {\
00050     if (g->buffer_end - g->buffer < bytes)\
00051         return 0;\
00052     return read(g->buffer);\
00053 }
00054 
00055 #define DEF(name, bytes, read, write) \
00056     DEF_T(unsigned int, name, bytes, read, write)
00057 #define DEF64(name, bytes, read, write) \
00058     DEF_T(uint64_t, name, bytes, read, write)
00059 
00060 DEF64(le64, 8, AV_RL64, AV_WL64)
00061 DEF  (le32, 4, AV_RL32, AV_WL32)
00062 DEF  (le24, 3, AV_RL24, AV_WL24)
00063 DEF  (le16, 2, AV_RL16, AV_WL16)
00064 DEF64(be64, 8, AV_RB64, AV_WB64)
00065 DEF  (be32, 4, AV_RB32, AV_WB32)
00066 DEF  (be24, 3, AV_RB24, AV_WB24)
00067 DEF  (be16, 2, AV_RB16, AV_WB16)
00068 DEF  (byte, 1, AV_RB8 , AV_WB8 )
00069 
00070 #undef DEF
00071 #undef DEF64
00072 #undef DEF_T
00073 
00074 static av_always_inline void bytestream2_init(GetByteContext *g,
00075                                               const uint8_t *buf, int buf_size)
00076 {
00077     g->buffer =  buf;
00078     g->buffer_end = buf + buf_size;
00079 }
00080 
00081 static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
00082 {
00083     return g->buffer_end - g->buffer;
00084 }
00085 
00086 static av_always_inline void bytestream2_skip(GetByteContext *g,
00087                                               unsigned int size)
00088 {
00089     g->buffer += FFMIN(g->buffer_end - g->buffer, size);
00090 }
00091 
00092 static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g,
00093                                                             uint8_t *dst,
00094                                                             unsigned int size)
00095 {
00096     int size2 = FFMIN(g->buffer_end - g->buffer, size);
00097     memcpy(dst, g->buffer, size2);
00098     g->buffer += size2;
00099     return size2;
00100 }
00101 
00102 static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
00103 {
00104     memcpy(dst, *b, size);
00105     (*b) += size;
00106     return size;
00107 }
00108 
00109 static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
00110 {
00111     memcpy(*b, src, size);
00112     (*b) += size;
00113 }
00114 
00115 #endif /* AVCODEC_BYTESTREAM_H */

Generated on Fri Feb 22 2013 07:24:25 for FFmpeg by  doxygen 1.7.1