From: Jaroslav Kysela Date: Tue, 28 Nov 2017 16:53:16 +0000 (+0100) Subject: move sbuf definitions to sbuf.h X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9891cf7e6449d445cbaedd816e7576919e5a1a1;p=thirdparty%2Ftvheadend.git move sbuf definitions to sbuf.h --- diff --git a/src/download.h b/src/download.h index 8c791174a..9f1f1dd9c 100644 --- a/src/download.h +++ b/src/download.h @@ -21,6 +21,7 @@ #define __DOWNLOAD__ #include "http.h" +#include "sbuf.h" typedef struct download { int subsys; diff --git a/src/epgdb.c b/src/epgdb.c index 8457394c8..1acb961ea 100644 --- a/src/epgdb.c +++ b/src/epgdb.c @@ -26,7 +26,7 @@ #include #include "tvheadend.h" -#include "queue.h" +#include "sbuf.h" #include "htsmsg_binary.h" #include "settings.h" #include "channels.h" diff --git a/src/imagecache.c b/src/imagecache.c index fe8a8b2ad..b01d0ae1e 100644 --- a/src/imagecache.c +++ b/src/imagecache.c @@ -32,7 +32,7 @@ #include "tvheadend.h" #include "filebundle.h" #include "imagecache.h" -#include "queue.h" +#include "sbuf.h" #include "redblack.h" #include "notify.h" #include "prop.h" diff --git a/src/parsers/parser_avc.h b/src/parsers/parser_avc.h index 96758ed9c..4ff0effa6 100644 --- a/src/parsers/parser_avc.h +++ b/src/parsers/parser_avc.h @@ -24,6 +24,7 @@ #include "tvheadend.h" #include "packet.h" +#include "sbuf.h" const uint8_t * avc_find_startcode(const uint8_t *p, const uint8_t *end); diff --git a/src/parsers/parser_hevc.c b/src/parsers/parser_hevc.c index 5fa1b86b5..4354149a6 100644 --- a/src/parsers/parser_hevc.c +++ b/src/parsers/parser_hevc.c @@ -37,6 +37,7 @@ */ #include "tvheadend.h" +#include "sbuf.h" #include "parsers.h" #include "parser_hevc.h" #include "parser_avc.h" diff --git a/src/sbuf.h b/src/sbuf.h new file mode 100644 index 000000000..b59c1948d --- /dev/null +++ b/src/sbuf.h @@ -0,0 +1,95 @@ +/* + * Tvheadend - sbuf routines + * Copyright (C) 2007 Andreas Öman + * Copyright (C) 2014-2017 Jaroslav Kysela + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TVH_SBUF_H +#define __TVH_SBUF_H + +#include +#include +#include + +/** + * Simple dynamically growing buffer + */ +typedef struct sbuf { + uint8_t *sb_data; + int sb_ptr; + int sb_size; + uint16_t sb_err; + uint8_t sb_bswap; +} sbuf_t; + + +void sbuf_init(sbuf_t *sb); +void sbuf_init_fixed(sbuf_t *sb, int len); + +void sbuf_free(sbuf_t *sb); + +void sbuf_reset(sbuf_t *sb, int max_len); +void sbuf_reset_and_alloc(sbuf_t *sb, int len); + +static inline void sbuf_steal_data(sbuf_t *sb) +{ + sb->sb_data = NULL; + sb->sb_ptr = sb->sb_size = sb->sb_err = 0; +} + +static inline void sbuf_err(sbuf_t *sb, int errors) +{ + sb->sb_err += errors; +} + +void sbuf_alloc_(sbuf_t *sb, int len); + +static inline void sbuf_alloc(sbuf_t *sb, int len) +{ + if (sb->sb_ptr + len >= sb->sb_size) + sbuf_alloc_(sb, len); +} + +void sbuf_realloc(sbuf_t *sb, int len); + +void sbuf_append(sbuf_t *sb, const void *data, int len); +void sbuf_append_from_sbuf(sbuf_t *sb, sbuf_t *src); + +void sbuf_cut(sbuf_t *sb, int off); + +void sbuf_put_be32(sbuf_t *sb, uint32_t u32); +void sbuf_put_be16(sbuf_t *sb, uint16_t u16); +void sbuf_put_byte(sbuf_t *sb, uint8_t u8); + +ssize_t sbuf_read(sbuf_t *sb, int fd); + +static inline uint8_t sbuf_peek_u8(sbuf_t *sb, int off) { return sb->sb_data[off]; } +static inline int8_t sbuf_peek_s8(sbuf_t *sb, int off) { return sb->sb_data[off]; } +uint16_t sbuf_peek_u16(sbuf_t *sb, int off); +static inline int16_t sbuf_peek_s16(sbuf_t *sb, int off) { return sbuf_peek_u16(sb, off); } +uint16_t sbuf_peek_u16le(sbuf_t *sb, int off); +static inline int16_t sbuf_peek_s16le(sbuf_t *sb, int off) { return sbuf_peek_u16le(sb, off); } +uint16_t sbuf_peek_u16be(sbuf_t *sb, int off); +static inline int16_t sbuf_peek_s16be(sbuf_t *sb, int off) { return sbuf_peek_u16be(sb, off); } +uint32_t sbuf_peek_u32(sbuf_t *sb, int off); +static inline int32_t sbuf_peek_s32(sbuf_t *sb, int off) { return sbuf_peek_u32(sb, off); } +uint32_t sbuf_peek_u32le(sbuf_t *sb, int off); +static inline int32_t sbuf_peek_s32le(sbuf_t *sb, int off) { return sbuf_peek_u32le(sb, off); } +uint32_t sbuf_peek_u32be(sbuf_t *sb, int off); +static inline int32_t sbuf_peek_s32be(sbuf_t *sb, int off) { return sbuf_peek_u32be(sb, off); } +static inline uint8_t *sbuf_peek(sbuf_t *sb, int off) { return sb->sb_data + off; } + +#endif /* __TVH_SBUF_H */ diff --git a/src/service.h b/src/service.h index b80b4716a..ed31eb16e 100644 --- a/src/service.h +++ b/src/service.h @@ -19,6 +19,7 @@ #ifndef SERVICE_H__ #define SERVICE_H__ +#include "sbuf.h" #include "htsmsg.h" #include "idnode.h" #include "profile.h" diff --git a/src/tvheadend.h b/src/tvheadend.h index ece6ee433..8f6dc19c9 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -637,18 +637,6 @@ typedef struct streaming_queue { } streaming_queue_t; -/** - * Simple dynamically growing buffer - */ -typedef struct sbuf { - uint8_t *sb_data; - int sb_ptr; - int sb_size; - uint16_t sb_err; - uint8_t sb_bswap; -} sbuf_t; - - streaming_component_type_t streaming_component_txt2type(const char *str); const char *streaming_component_type2txt(streaming_component_type_t s); streaming_component_type_t streaming_component_txt2type(const char *s); @@ -778,67 +766,6 @@ static inline int64_t ts_rescale_inv(int64_t ts, int tb) return (ts * 90000LL) / tb; } -void sbuf_init(sbuf_t *sb); - -void sbuf_init_fixed(sbuf_t *sb, int len); - -void sbuf_free(sbuf_t *sb); - -void sbuf_reset(sbuf_t *sb, int max_len); - -void sbuf_reset_and_alloc(sbuf_t *sb, int len); - -static inline void sbuf_steal_data(sbuf_t *sb) -{ - sb->sb_data = NULL; - sb->sb_ptr = sb->sb_size = sb->sb_err = 0; -} - -static inline void sbuf_err(sbuf_t *sb, int errors) -{ - sb->sb_err += errors; -} - -void sbuf_alloc_(sbuf_t *sb, int len); - -static inline void sbuf_alloc(sbuf_t *sb, int len) -{ - if (sb->sb_ptr + len >= sb->sb_size) - sbuf_alloc_(sb, len); -} - -void sbuf_realloc(sbuf_t *sb, int len); - -void sbuf_append(sbuf_t *sb, const void *data, int len); - -void sbuf_append_from_sbuf(sbuf_t *sb, sbuf_t *src); - -void sbuf_cut(sbuf_t *sb, int off); - -void sbuf_put_be32(sbuf_t *sb, uint32_t u32); - -void sbuf_put_be16(sbuf_t *sb, uint16_t u16); - -void sbuf_put_byte(sbuf_t *sb, uint8_t u8); - -ssize_t sbuf_read(sbuf_t *sb, int fd); - -static inline uint8_t sbuf_peek_u8(sbuf_t *sb, int off) { return sb->sb_data[off]; } -static inline int8_t sbuf_peek_s8(sbuf_t *sb, int off) { return sb->sb_data[off]; } -uint16_t sbuf_peek_u16(sbuf_t *sb, int off); -static inline int16_t sbuf_peek_s16(sbuf_t *sb, int off) { return sbuf_peek_u16(sb, off); } -uint16_t sbuf_peek_u16le(sbuf_t *sb, int off); -static inline int16_t sbuf_peek_s16le(sbuf_t *sb, int off) { return sbuf_peek_u16le(sb, off); } -uint16_t sbuf_peek_u16be(sbuf_t *sb, int off); -static inline int16_t sbuf_peek_s16be(sbuf_t *sb, int off) { return sbuf_peek_u16be(sb, off); } -uint32_t sbuf_peek_u32(sbuf_t *sb, int off); -static inline int32_t sbuf_peek_s32(sbuf_t *sb, int off) { return sbuf_peek_u32(sb, off); } -uint32_t sbuf_peek_u32le(sbuf_t *sb, int off); -static inline int32_t sbuf_peek_s32le(sbuf_t *sb, int off) { return sbuf_peek_u32le(sb, off); } -uint32_t sbuf_peek_u32be(sbuf_t *sb, int off); -static inline int32_t sbuf_peek_s32be(sbuf_t *sb, int off) { return sbuf_peek_u32be(sb, off); } -static inline uint8_t *sbuf_peek(sbuf_t *sb, int off) { return sb->sb_data + off; } - char *md5sum ( const char *str, int lowercase ); int makedirs ( int subsys, const char *path, int mode, int mstrict, gid_t gid, uid_t uid ); diff --git a/src/utils.c b/src/utils.c index 2fd26761b..53cf95bc2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -33,6 +33,7 @@ #include "tvheadend.h" #include "tvh_endian.h" +#include "sbuf.h" /** * CRC32