UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
binka_ue_file_header.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4#include <stdint.h>
5
8typedef uint8_t uint8;
9
11{
12 uint32 tag; // UEBA
15 uint16 PADDING; // unused atm.
18
19 // the max for a bink audio block - includes all streams, but does _not_ include
20 // the block header info.
22
23 // unused in UE (holds whether it's BA2 or not, which is always true for UE)
25
26 // bytes for the whole file
28
29 // number of encoded seek table entries stored directly after the file header.
30 // each one is 16 bits, and is the delta from the last entry.
32
33 // number of bink audio blocks for a single entry in the seek table. Encoding
34 // keeps seek tables under 4k, so larger files will correspondingly have more
35 // distance between seek table lookup points. Note that while you could consider
36 // each bink audio stream decode a single block, this is referring to the set
37 // of low level bink audio blocks for a given timepoint (so for 6 channels, you
38 // have 3 low level bink streams, but the set of those 3 is referred to as one
39 // block for the purposes of this.)
41};
42
43#define BLOCK_HEADER_MAGIC 0x9999
44
46{
47 //
48 // Returns true if the current input buffer can be decoded
49 //
50 if (input_reservoir_len < 4)
51 {
52 // need an unknown amount of data - fill the reservoir
53 return false;
54 }
55
56 // Check for the frame header.
59
60 if ((FrameCheck & 0xffff) != BLOCK_HEADER_MAGIC)
61 {
62 return false;
63 }
64
65 uint32 FrameSize = FrameCheck >> 16;
66 if (FrameSize == 0xffff)
67 {
68 // Trimmed frame - size & sample next.
69 if (input_reservoir_len < 8)
70 {
71 return false;
72 }
73
75 FrameSize = TrimmedFrameHeader & 0xffff;
77 }
78
79 if (FrameSize > header_max_comp_space_needed)
80 {
81 // Invalid frame.
82 return false;
83 }
84
85 *out_block_size = FrameSize + FrameHeaderSize;
86 return true;
87}
88
89#define BINK_AUDIO_BLOCK_VALID 0 // The buffer can be passed to Bink.
90#define BINK_AUDIO_BLOCK_INCOMPLETE 1 // The buffer looks good but needs more data
91#define BINK_AUDIO_BLOCK_INVALID 2 // Buffer consistency checks failed.
93{
94 //
95 // Returns true if the current input buffer can be decoded,
96 // doesn't affect BcfStr at all.
97 //
100
101 if (input_reservoir_len < 4)
102 return BINK_AUDIO_BLOCK_INCOMPLETE; // no space for header.
103
104 // Check for the frame header.
106 input_buffer += 4;
107 if ((FrameCheck & 0xffff) != BLOCK_HEADER_MAGIC)
108 {
110 }
111
112 uint32 FrameSize = FrameCheck >> 16;
113 if (FrameSize == 0xffff)
114 {
115 // Trimmed frame - size & sample next.
116 if (input_reservoir_len < 8)
117 return BINK_AUDIO_BLOCK_INCOMPLETE; // no space for header
118
120 input_buffer += 4;
121 FrameSize = TrimmedFrameHeader & 0xffff;
122 }
123
124 if (FrameSize > header_max_comp_space_needed)
125 {
126 // Invalid frame.
128 }
129
130 uint8 const* frame_end = input_buffer + FrameSize;
131 if (frame_end > input_end)
132 return BINK_AUDIO_BLOCK_INCOMPLETE; // frame isn't resident
133
134 if (frame_end == input_end)
135 return BINK_AUDIO_BLOCK_VALID; // we assume it's valid, even though it's possible that it's a fake.
136
137 if (frame_end + 4 <= input_end)
138 {
139 // we have enough to double check.
140 if ((*(uint32 const*)(frame_end) & 0xffff) != BLOCK_HEADER_MAGIC)
141 {
142 // This was a fake!
144 }
145 }
146
148}
149
150// input_reservoir MUST have passed BinkAudioValidateBlock
151static void BinkAudioCrackBlock(uint8 const* input_reservoir, uint8 const** out_block_start, uint8 const** out_block_end, uint32* out_trim_to_sample_count)
152{
153 uint8 const* input_buffer = (uint8 const*)input_reservoir;
155 input_buffer += 4;
156
158 uint32 FrameBytes = FrameCheck >> 16;
159 if (FrameBytes == 0xffff)
160 {
161 // Trimmed frame - # of output samples after.
163 input_buffer += 4;
164
165 FrameBytes = TrimmedFrameHeader & 0xffff;
167 }
168
170 *out_block_end = input_buffer + FrameBytes;
172}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define BINK_AUDIO_BLOCK_VALID
Definition binka_ue_file_header.h:89
uint8_t uint8
Definition binka_ue_file_header.h:8
#define BINK_AUDIO_BLOCK_INVALID
Definition binka_ue_file_header.h:91
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
#define BINK_AUDIO_BLOCK_INCOMPLETE
Definition binka_ue_file_header.h:90
#define BLOCK_HEADER_MAGIC
Definition binka_ue_file_header.h:43
Definition binka_ue_file_header.h:11
uint16 seek_table_entry_count
Definition binka_ue_file_header.h:31
uint8 channels
Definition binka_ue_file_header.h:14
uint16 blocks_per_seek_table_entry
Definition binka_ue_file_header.h:40
uint32 tag
Definition binka_ue_file_header.h:12
uint32 sample_count
Definition binka_ue_file_header.h:17
uint16 PADDING
Definition binka_ue_file_header.h:15
uint32 rate
Definition binka_ue_file_header.h:16
uint8 version
Definition binka_ue_file_header.h:13
uint16 flags
Definition binka_ue_file_header.h:24
uint32 output_file_size
Definition binka_ue_file_header.h:27
uint16 max_comp_space_needed
Definition binka_ue_file_header.h:21