25#define HEADER(name) do { \
26 ff_cbs_trace_header(ctx, name); \
29#define CHECK(call) do { \
35#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
37#define u(width, name, range_min, range_max) \
38 xu(width, name, range_min, range_max, 0, )
39#define us(width, name, sub, range_min, range_max) \
40 xu(width, name, range_min, range_max, 1, sub)
45#define RWContext GetBitContext
46#define FUNC(name) cbs_jpeg_read_ ## name
48#define xu(width, name, range_min, range_max, subs, ...) do { \
50 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
51 SUBSCRIPTS(subs, __VA_ARGS__), \
52 &value, range_min, range_max)); \
53 current->name = value; \
65#define READWRITE write
66#define RWContext PutBitContext
67#define FUNC(name) cbs_jpeg_write_ ## name
69#define xu(width, name, range_min, range_max, subs, ...) do { \
70 uint32_t value = current->name; \
71 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
72 SUBSCRIPTS(subs, __VA_ARGS__), \
73 value, range_min, range_max)); \
93 int start, end, marker, next_start, next_marker;
94 int err,
i, j, length;
104 "beginning of image.\n",
i);
109 "no SOI marker found.\n");
112 marker = frag->
data[
i];
115 "marker is %02x, should be SOI.\n", marker);
121 "no image content found.\n");
124 marker = frag->
data[
i];
134 if (frag->
data[
i] != 0xff)
138 frag->
data[
i] == 0xff;
i++);
140 if (frag->
data[
i] == 0x00)
142 next_marker = frag->
data[
i];
151 "truncated at %02x marker.\n", marker);
157 "truncated at %02x marker segment.\n", marker);
160 end = start + length;
163 if (frag->
data[
i] != 0xff) {
167 frag->
data[
i] == 0xff;
i++);
171 next_marker = frag->
data[
i];
180 if (length > end - start)
189 memcpy(
data, frag->
data + start, length);
190 for (
i = start + length, j = length;
i < end;
i++, j++) {
191 if (frag->
data[
i] == 0xff) {
192 while (frag->
data[
i] == 0xff)
205 data_size = end - start;
209 err = ff_cbs_append_unit_data(frag, marker,
210 data, data_size, data_ref);
214 marker = next_marker;
216 }
while (next_marker != -1);
231 err = ff_cbs_alloc_unit_content(
ctx, unit);
237 err = cbs_jpeg_read_frame_header(
ctx, &gbc, unit->
content);
243 err = cbs_jpeg_read_application_data(
ctx, &gbc, unit->
content);
251 err = cbs_jpeg_read_scan_header(
ctx, &gbc, &scan->
header);
266 switch (unit->
type) {
267#define SEGMENT(marker, func) \
268 case JPEG_MARKER_ ## marker: \
270 err = cbs_jpeg_read_ ## func(ctx, &gbc, unit->content); \
294 err = cbs_jpeg_write_scan_header(
ctx, pbc, &scan->
header);
321 err = cbs_jpeg_write_frame_header(
ctx, pbc, unit->
content);
324 err = cbs_jpeg_write_application_data(
ctx, pbc, unit->
content);
326 switch (unit->
type) {
327#define SEGMENT(marker, func) \
328 case JPEG_MARKER_ ## marker: \
329 err = cbs_jpeg_write_ ## func(ctx, pbc, unit->content); \
365 for (sp = 0; sp < unit->
data_size; sp++) {
366 if (unit->
data[sp] == 0xff)
398 if (unit->
data[sp] == 0xff) {
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
#define CBS_UNIT_TYPE_POD(type_, structure)
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_RANGE_POD(range_start, range_end, structure)
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field)
const CodedBitstreamType ff_cbs_type_jpeg
static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static int cbs_jpeg_write_segment(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
#define SEGMENT(marker, func)
static int cbs_jpeg_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static CodedBitstreamUnitTypeDescriptor cbs_jpeg_unit_types[]
static int cbs_jpeg_write_scan(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int cbs_jpeg_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int FUNC comment(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawComment *current)
static int FUNC dht(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawHuffmanTableSpecification *current)
static int FUNC dqt(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawQuantisationTableSpecification *current)
static int get_bits_count(const GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Memory handling functions.
static int put_bits_count(PutBitContext *s)
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static const uint8_t header[24]
A reference to a data buffer.
uint8_t * data
The data buffer.
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
size_t data_size
The number of bytes in the bitstream.
uint8_t * data
Pointer to the bitstream form of this fragment.
AVBufferRef * data_ref
A reference to the buffer containing data.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
AVBufferRef * data_ref
A reference to the buffer containing data.
static AVFormatContext * ctx