[FFmpeg-cvslog] shorten: Convert to the new bitstream reader
Alexandra Hájková
git at videolan.org
Tue Sep 26 21:08:29 EEST 2017
ffmpeg | branch: master | Alexandra Hájková <alexandra at khirnov.net> | Tue Mar 22 16:09:39 2016 +0100| [2b94ed12de7b6b7f444ed67e1a7068141af3d4ff] | committer: Diego Biurrun
shorten: Convert to the new bitstream reader
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2b94ed12de7b6b7f444ed67e1a7068141af3d4ff
---
libavcodec/shorten.c | 49 +++++++++++++++++++++++++------------------------
1 file changed, 25 insertions(+), 24 deletions(-)
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 82fa2ab943..e040b9cfed 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -26,10 +26,11 @@
*/
#include <limits.h>
+
#include "avcodec.h"
+#include "bitstream.h"
#include "bytestream.h"
-#include "get_bits.h"
-#include "golomb_legacy.h"
+#include "golomb.h"
#include "internal.h"
#define MAX_CHANNELS 8
@@ -79,7 +80,7 @@ static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
typedef struct ShortenContext {
AVCodecContext *avctx;
- GetBitContext gb;
+ BitstreamContext bc;
int min_framesize, max_framesize;
unsigned channels;
@@ -154,8 +155,8 @@ static int allocate_buffers(ShortenContext *s)
static inline unsigned int get_uint(ShortenContext *s, int k)
{
if (s->version != 0)
- k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
- return get_ur_golomb_shorten(&s->gb, k);
+ k = get_ur_golomb_shorten(&s->bc, ULONGSIZE);
+ return get_ur_golomb_shorten(&s->bc, k);
}
static void fix_bitshift(ShortenContext *s, int32_t *buffer)
@@ -280,7 +281,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
if (command == FN_QLPC) {
/* read/validate prediction order */
- pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
+ pred_order = get_ur_golomb_shorten(&s->bc, LPCQSIZE);
if (pred_order > s->nwrap) {
av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
pred_order);
@@ -288,7 +289,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
}
/* read LPC coefficients */
for (i = 0; i < pred_order; i++)
- s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
+ s->coeffs[i] = get_sr_golomb_shorten(&s->bc, LPCQUANT);
coeffs = s->coeffs;
qshift = LPCQUANT;
@@ -315,7 +316,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
sum = init_sum;
for (j = 0; j < pred_order; j++)
sum += coeffs[j] * s->decoded[channel][i - j - 1];
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->bc, residual_size) +
(sum >> qshift);
}
@@ -332,7 +333,7 @@ static int read_header(ShortenContext *s)
int i, ret;
int maxnlpc = 0;
/* shorten signature */
- if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
+ if (bitstream_read(&s->bc, 32) != AV_RB32("ajkg")) {
av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
return AVERROR_INVALIDDATA;
}
@@ -340,7 +341,7 @@ static int read_header(ShortenContext *s)
s->lpcqoffset = 0;
s->blocksize = DEFAULT_BLOCK_SIZE;
s->nmean = -1;
- s->version = get_bits(&s->gb, 8);
+ s->version = bitstream_read(&s->bc, 8);
s->internal_ftype = get_uint(s, TYPESIZE);
s->channels = get_uint(s, CHANSIZE);
@@ -374,7 +375,7 @@ static int read_header(ShortenContext *s)
skip_bytes = get_uint(s, NSKIPSIZE);
for (i = 0; i < skip_bytes; i++)
- skip_bits(&s->gb, 8);
+ bitstream_skip(&s->bc, 8);
}
s->nwrap = FFMAX(NWRAP, maxnlpc);
@@ -387,13 +388,13 @@ static int read_header(ShortenContext *s)
if (s->version > 1)
s->lpcqoffset = V2LPCQOFFSET;
- if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
+ if (get_ur_golomb_shorten(&s->bc, FNSIZE) != FN_VERBATIM) {
av_log(s->avctx, AV_LOG_ERROR,
"missing verbatim section at beginning of stream\n");
return AVERROR_INVALIDDATA;
}
- s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ s->header_size = get_ur_golomb_shorten(&s->bc, VERBATIM_CKSIZE_SIZE);
if (s->header_size >= OUT_BUFFER_SIZE ||
s->header_size < CANONICAL_HEADER_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
@@ -402,7 +403,7 @@ static int read_header(ShortenContext *s)
}
for (i = 0; i < s->header_size; i++)
- s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ s->header[i] = (char)get_ur_golomb_shorten(&s->bc, VERBATIM_BYTE_SIZE);
if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
return ret;
@@ -464,8 +465,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
}
}
/* init and position bitstream reader */
- init_get_bits(&s->gb, buf, buf_size * 8);
- skip_bits(&s->gb, s->bitindex);
+ bitstream_init8(&s->bc, buf, buf_size);
+ bitstream_skip(&s->bc, s->bitindex);
/* process header or next subblock */
if (!s->got_header) {
@@ -486,12 +487,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
unsigned cmd;
int len;
- if (get_bits_left(&s->gb) < 3 + FNSIZE) {
+ if (bitstream_bits_left(&s->bc) < 3 + FNSIZE) {
*got_frame_ptr = 0;
break;
}
- cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
+ cmd = get_ur_golomb_shorten(&s->bc, FNSIZE);
if (cmd > FN_VERBATIM) {
av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
@@ -503,12 +504,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
/* process non-audio command */
switch (cmd) {
case FN_VERBATIM:
- len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ len = get_ur_golomb_shorten(&s->bc, VERBATIM_CKSIZE_SIZE);
while (len--)
- get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ get_ur_golomb_shorten(&s->bc, VERBATIM_BYTE_SIZE);
break;
case FN_BITSHIFT:
- s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
+ s->bitshift = get_ur_golomb_shorten(&s->bc, BITSHIFTSIZE);
if (s->bitshift < 0)
return AVERROR_INVALIDDATA;
break;
@@ -543,7 +544,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
/* get Rice code for residual decoding */
if (cmd != FN_ZERO) {
- residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
+ residual_size = get_ur_golomb_shorten(&s->bc, ENERGYSIZE);
/* This is a hack as version 0 differed in the definition
* of get_sr_golomb_shorten(). */
if (s->version == 0)
@@ -616,8 +617,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
*got_frame_ptr = 0;
finish_frame:
- s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
- i = get_bits_count(&s->gb) / 8;
+ s->bitindex = bitstream_tell(&s->bc) - 8 * (bitstream_tell(&s->bc) / 8);
+ i = bitstream_tell(&s->bc) / 8;
if (i > buf_size) {
av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
s->bitstream_size = 0;
More information about the ffmpeg-cvslog
mailing list