MythTV master
bytereader.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Unlicense
2// Created by Scott Theisen, 2022-2025
3/* The Unlicense
4This is free and unencumbered software released into the public domain.
5
6Anyone is free to copy, modify, publish, use, compile, sell, or
7distribute this software, either in source code form or as a compiled
8binary, for any purpose, commercial or non-commercial, and by any
9means.
10
11In jurisdictions that recognize copyright laws, the author or authors
12of this software dedicate any and all copyright interest in the
13software to the public domain. We make this dedication for the benefit
14of the public at large and to the detriment of our heirs and
15successors. We intend this dedication to be an overt act of
16relinquishment in perpetuity of all present and future rights to this
17software under copyright law.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25OTHER DEALINGS IN THE SOFTWARE.
26
27For more information, please refer to <https://unlicense.org>
28*/
29
30#ifndef BYTEREADER_H
31#define BYTEREADER_H
32
33#include <cstdint>
34
35#include "mythtvexp.h"
36
49namespace ByteReader
50{
62inline bool start_code_is_valid(uint32_t start_code)
63{
64 return (start_code & 0xFFFFFF00) == 0x100;
65}
66
86const uint8_t* find_start_code(const uint8_t *p,
87 const uint8_t *end,
88 uint32_t *start_code);
89
105const uint8_t *find_start_code_truncated(const uint8_t * p,
106 const uint8_t * end,
107 uint32_t * start_code);
108
109inline uint32_t readBigEndianU32(const uint8_t* x)
110{
111 return uint32_t{x[0]} << 24 |
112 uint32_t{x[1]} << 16 |
113 uint32_t{x[2]} << 8 |
114 uint32_t{x[3]};
115}
116
117inline uint32_t readBigEndianU24(const uint8_t* x)
118{
119 return uint32_t{x[0]} << 16 |
120 uint32_t{x[1]} << 8 |
121 uint32_t{x[2]};
122}
123} // namespace ByteReader
124
125#endif // BYTEREADER_H
#define MTV_PUBLIC
Definition: mythtvexp.h:11
These functions are rewritten copies from FFmpeg's libavcodec, where find_start_code() is prefixed wi...
Definition: bytereader.h:50
bool start_code_is_valid(uint32_t start_code)
Test whether a start code found by find_start_code() is valid.
Definition: bytereader.h:62
MTV_PUBLIC const uint8_t * find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *start_code)
Find the first start code in the buffer p.
Definition: bytereader.cpp:34
uint32_t readBigEndianU32(const uint8_t *x)
Definition: bytereader.h:109
uint32_t readBigEndianU24(const uint8_t *x)
Definition: bytereader.h:117
MTV_PUBLIC const uint8_t * find_start_code_truncated(const uint8_t *p, const uint8_t *end, uint32_t *start_code)
By preserving the start_code value between subsequent calls, the caller can detect start codes across...
Definition: bytereader.cpp:79