Skip to content

Commit

Permalink
Define and use alignment macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
foo86 committed Apr 15, 2015
1 parent 5c5205d commit 77ee882
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libdcadec/bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ int bits_seek(struct bitstream *bits, size_t n)

size_t bits_align1(struct bitstream *bits)
{
bits->index = (bits->index + 7) & ~7;
bits->index = DCA_ALIGN(bits->index, 8);
return bits->index;
}

size_t bits_align4(struct bitstream *bits)
{
bits->index = (bits->index + 31) & ~31;
bits->index = DCA_ALIGN(bits->index, 32);
return bits->index;
}

Expand Down
3 changes: 3 additions & 0 deletions libdcadec/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
typeof(b) _b = (b); \
_a < _b ? _a : _b; })

#define DCA_ALIGN(value, align) \
(((value) + (align) - 1) & ~((align) - 1))

#define DCA_MEM16BE(data) \
(((uint32_t)(data)[0] << 8) | (data)[1])

Expand Down
2 changes: 1 addition & 1 deletion libdcadec/dca_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ DCADEC_API int dcadec_context_parse(struct dcadec_context *dca, uint8_t *data, s
dca->packet |= DCADEC_PACKET_CORE;

// EXXS data must be aligned on 4-byte boundary by the caller
size_t frame_size = (dca->core->frame_size + 3) & ~3;
size_t frame_size = DCA_ALIGN(dca->core->frame_size, 4);
if (size - 4 > frame_size) {
data += frame_size;
size -= frame_size;
Expand Down
4 changes: 2 additions & 2 deletions libdcadec/dca_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ DCADEC_API void dcadec_stream_close(struct dcadec_stream *stream)
static uint8_t *prepare_packet_buffer(struct dcadec_stream *stream, size_t size)
{
size += stream->packet_size + DCADEC_BUFFER_PADDING;
size = (size + BUFFER_ALIGN - 1) & ~(BUFFER_ALIGN - 1);
size = DCA_ALIGN(size, BUFFER_ALIGN);

uint8_t *buf = ta_realloc_size(stream, stream->buffer, size);
if (buf) {
Expand Down Expand Up @@ -304,7 +304,7 @@ static int read_frame(struct dcadec_stream *stream, uint32_t *sync_p)
}

// Align frame size to 4-byte boundary
size_t aligned_size = (frame_size + 3) & ~3;
size_t aligned_size = DCA_ALIGN(frame_size, 4);

// Reallocate packet buffer
if (!(buf = prepare_packet_buffer(stream, aligned_size)))
Expand Down

0 comments on commit 77ee882

Please sign in to comment.