From a895292f2734b4aacd2f2c2db6c07ff5a6d535c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 16 Apr 2016 12:17:24 +0200 Subject: [PATCH 1/3] mov: Convert to the new bitstream reader --- libavformat/mov.c | 10 ++++++---- libavformat/movenc.c | 41 +++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 8b38fa43b8..37afe79df0 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -39,13 +39,15 @@ #include "libavutil/pixdesc.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" + #include "libavcodec/ac3tab.h" +#include "libavcodec/bitstream.h" + #include "avformat.h" #include "internal.h" #include "avio_internal.h" #include "riff.h" #include "isom.h" -#include "libavcodec/get_bits.h" #include "id3v1.h" #include "mov_chan.h" #include "replaygain.h" @@ -2078,7 +2080,7 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; MOVStreamContext *sc; unsigned int i, entries, sample_size, field_size, num_bytes; - GetBitContext gb; + BitstreamContext bc; unsigned char* buf; int ret; @@ -2136,10 +2138,10 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) return ret; } - init_get_bits(&gb, buf, 8*num_bytes); + bitstream_init(&bc, buf, 8 * num_bytes); for (i = 0; i < entries && !pb->eof_reached; i++) { - sc->sample_sizes[i] = get_bits_long(&gb, field_size); + sc->sample_sizes[i] = bitstream_read(&bc, field_size); sc->data_size += sc->sample_sizes[i]; } diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 3dd882c263..ac76dedca4 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -31,7 +31,8 @@ #include "avio.h" #include "isom.h" #include "avc.h" -#include "libavcodec/get_bits.h" + +#include "libavcodec/bitstream.h" #include "libavcodec/put_bits.h" #include "libavcodec/vc1_common.h" #include "internal.h" @@ -240,7 +241,7 @@ static int mov_write_amr_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track) { - GetBitContext gbc; + BitstreamContext bc; PutBitContext pbc; uint8_t buf[3]; int fscod, bsid, bsmod, acmod, lfeon, frmsizecod; @@ -251,21 +252,21 @@ static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, 11); ffio_wfourcc(pb, "dac3"); - init_get_bits(&gbc, track->vos_data + 4, (track->vos_len - 4) * 8); - fscod = get_bits(&gbc, 2); - frmsizecod = get_bits(&gbc, 6); - bsid = get_bits(&gbc, 5); - bsmod = get_bits(&gbc, 3); - acmod = get_bits(&gbc, 3); + bitstream_init(&bc, track->vos_data + 4, (track->vos_len - 4) * 8); + fscod = bitstream_read(&bc, 2); + frmsizecod = bitstream_read(&bc, 6); + bsid = bitstream_read(&bc, 5); + bsmod = bitstream_read(&bc, 3); + acmod = bitstream_read(&bc, 3); if (acmod == 2) { - skip_bits(&gbc, 2); // dsurmod + bitstream_skip(&bc, 2); // dsurmod } else { if ((acmod & 1) && acmod != 1) - skip_bits(&gbc, 2); // cmixlev + bitstream_skip(&bc, 2); // cmixlev if (acmod & 4) - skip_bits(&gbc, 2); // surmixlev + bitstream_skip(&bc, 2); // surmixlev } - lfeon = get_bits1(&gbc); + lfeon = bitstream_read_bit(&bc); init_put_bits(&pbc, buf, sizeof(buf)); put_bits(&pbc, 2, fscod); @@ -462,28 +463,28 @@ static int mov_write_dvc1_structs(MOVTrack *track, uint8_t *buf) return AVERROR(ENOMEM); start = find_next_marker(track->vos_data, end); for (next = start; next < end; start = next) { - GetBitContext gb; + BitstreamContext bc; int size; next = find_next_marker(start + 4, end); size = next - start - 4; if (size <= 0) continue; unescaped_size = vc1_unescape_buffer(start + 4, size, unescaped); - init_get_bits(&gb, unescaped, 8 * unescaped_size); + bitstream_init(&bc, unescaped, 8 * unescaped_size); if (AV_RB32(start) == VC1_CODE_SEQHDR) { - int profile = get_bits(&gb, 2); + int profile = bitstream_read(&bc, 2); if (profile != PROFILE_ADVANCED) { av_free(unescaped); return AVERROR(ENOSYS); } seq_found = 1; - level = get_bits(&gb, 3); + level = bitstream_read(&bc, 3); /* chromaformat, frmrtq_postproc, bitrtq_postproc, postprocflag, * width, height */ - skip_bits_long(&gb, 2 + 3 + 5 + 1 + 2*12); - skip_bits(&gb, 1); /* broadcast */ - interlace = get_bits1(&gb); - skip_bits(&gb, 4); /* tfcntrflag, finterpflag, reserved, psf */ + bitstream_skip(&bc, 2 + 3 + 5 + 1 + 2 * 12); + bitstream_skip(&bc, 1); /* broadcast */ + interlace = bitstream_read_bit(&bc); + bitstream_skip(&bc, 4); /* tfcntrflag, finterpflag, reserved, psf */ } } if (!seq_found) { From b1e7394ea0428318c0407a6c030577196fe834a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sun, 17 Apr 2016 16:59:24 +0200 Subject: [PATCH 2/3] rtp: Convert to the new bitstream reader --- libavformat/rtpdec_h261.c | 19 ++++++++++--------- libavformat/rtpdec_h263_rfc2190.c | 19 ++++++++++--------- libavformat/rtpdec_latm.c | 24 +++++++++++++----------- libavformat/rtpdec_mpeg4.c | 16 +++++++++------- libavformat/rtpdec_qt.c | 31 ++++++++++++++++--------------- libavformat/rtpenc_h263_rfc2190.c | 29 +++++++++++++++-------------- 6 files changed, 73 insertions(+), 65 deletions(-) diff --git a/libavformat/rtpdec_h261.c b/libavformat/rtpdec_h261.c index 00086c21c5..b1bd1e0475 100644 --- a/libavformat/rtpdec_h261.c +++ b/libavformat/rtpdec_h261.c @@ -19,7 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/get_bits.h" +#include "libavcodec/bitstream.h" + #include "avformat.h" #include "avio_internal.h" #include "rtpdec_formats.h" @@ -118,18 +119,18 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte); } else { /* ebit/sbit values inconsistent, assuming packet loss */ - GetBitContext gb; - init_get_bits(&gb, buf, len*8 - ebit); - skip_bits(&gb, sbit); + BitstreamContext bc; + bitstream_init(&bc, buf, len * 8 - ebit); + bitstream_skip(&bc, sbit); if (rtp_h261_ctx->endbyte_bits) { - rtp_h261_ctx->endbyte |= get_bits(&gb, 8 - rtp_h261_ctx->endbyte_bits); + rtp_h261_ctx->endbyte |= bitstream_read(&bc, 8 - rtp_h261_ctx->endbyte_bits); avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte); } - while (get_bits_left(&gb) >= 8) - avio_w8(rtp_h261_ctx->buf, get_bits(&gb, 8)); - rtp_h261_ctx->endbyte_bits = get_bits_left(&gb); + while (bitstream_bits_left(&bc) >= 8) + avio_w8(rtp_h261_ctx->buf, bitstream_read(&bc, 8)); + rtp_h261_ctx->endbyte_bits = bitstream_bits_left(&bc); if (rtp_h261_ctx->endbyte_bits) - rtp_h261_ctx->endbyte = get_bits(&gb, rtp_h261_ctx->endbyte_bits) << + rtp_h261_ctx->endbyte = bitstream_read(&bc, rtp_h261_ctx->endbyte_bits) << (8 - rtp_h261_ctx->endbyte_bits); ebit = 0; len = 0; diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c index 019eea779b..5744d71da0 100644 --- a/libavformat/rtpdec_h263_rfc2190.c +++ b/libavformat/rtpdec_h263_rfc2190.c @@ -30,7 +30,8 @@ #include "rtpdec_formats.h" #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" -#include "libavcodec/get_bits.h" + +#include "libavcodec/bitstream.h" struct PayloadContext { AVIOContext *buf; @@ -141,18 +142,18 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, avio_w8(data->buf, data->endbyte); } else { /* Start/end skip bits not matching - missed packets? */ - GetBitContext gb; - init_get_bits(&gb, buf, len*8 - ebit); - skip_bits(&gb, sbit); + BitstreamContext bc; + bitstream_init(&bc, buf, len * 8 - ebit); + bitstream_skip(&bc, sbit); if (data->endbyte_bits) { - data->endbyte |= get_bits(&gb, 8 - data->endbyte_bits); + data->endbyte |= bitstream_read(&bc, 8 - data->endbyte_bits); avio_w8(data->buf, data->endbyte); } - while (get_bits_left(&gb) >= 8) - avio_w8(data->buf, get_bits(&gb, 8)); - data->endbyte_bits = get_bits_left(&gb); + while (bitstream_bits_left(&bc) >= 8) + avio_w8(data->buf, bitstream_read(&bc, 8)); + data->endbyte_bits = bitstream_bits_left(&bc); if (data->endbyte_bits) - data->endbyte = get_bits(&gb, data->endbyte_bits) << + data->endbyte = bitstream_read(&bc, data->endbyte_bits) << (8 - data->endbyte_bits); ebit = 0; len = 0; diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index df85ed3615..bb826269b0 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -19,11 +19,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avstring.h" + +#include "libavcodec/bitstream.h" + #include "avio_internal.h" #include "rtpdec_formats.h" #include "internal.h" -#include "libavutil/avstring.h" -#include "libavcodec/get_bits.h" struct PayloadContext { AVIOContext *dyn_buf; @@ -92,7 +94,7 @@ static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data, static int parse_fmtp_config(AVStream *st, const char *value) { int len = ff_hex_to_data(NULL, value), i, ret = 0; - GetBitContext gb; + BitstreamContext bc; uint8_t *config; int audio_mux_version, same_time_framing, num_programs, num_layers; @@ -101,12 +103,12 @@ static int parse_fmtp_config(AVStream *st, const char *value) if (!config) return AVERROR(ENOMEM); ff_hex_to_data(config, value); - init_get_bits(&gb, config, len*8); - audio_mux_version = get_bits(&gb, 1); - same_time_framing = get_bits(&gb, 1); - skip_bits(&gb, 6); /* num_sub_frames */ - num_programs = get_bits(&gb, 4); - num_layers = get_bits(&gb, 3); + bitstream_init(&bc, config, len * 8); + audio_mux_version = bitstream_read(&bc, 1); + same_time_framing = bitstream_read(&bc, 1); + bitstream_skip(&bc, 6); /* num_sub_frames */ + num_programs = bitstream_read(&bc, 4); + num_layers = bitstream_read(&bc, 3); if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 || num_layers != 0) { avpriv_report_missing_feature(NULL, "LATM config (%d,%d,%d,%d)", @@ -116,7 +118,7 @@ static int parse_fmtp_config(AVStream *st, const char *value) goto end; } av_freep(&st->codecpar->extradata); - st->codecpar->extradata_size = (get_bits_left(&gb) + 7)/8; + st->codecpar->extradata_size = (bitstream_bits_left(&bc) + 7) / 8; st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!st->codecpar->extradata) { @@ -124,7 +126,7 @@ static int parse_fmtp_config(AVStream *st, const char *value) goto end; } for (i = 0; i < st->codecpar->extradata_size; i++) - st->codecpar->extradata[i] = get_bits(&gb, 8); + st->codecpar->extradata[i] = bitstream_read(&bc, 8); end: av_free(config); diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 00a732b1cc..b3cd6c9404 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -27,11 +27,13 @@ * @author Romain Degez */ -#include "rtpdec_formats.h" -#include "internal.h" #include "libavutil/attributes.h" #include "libavutil/avstring.h" -#include "libavcodec/get_bits.h" + +#include "libavcodec/bitstream.h" + +#include "rtpdec_formats.h" +#include "internal.h" #define MAX_AAC_HBR_FRAME_SIZE 8191 @@ -113,7 +115,7 @@ static int parse_fmtp_config(AVCodecParameters *par, const char *value) static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) { int au_headers_length, au_header_size, i; - GetBitContext getbitcontext; + BitstreamContext bctx; if (len < 2) return AVERROR_INVALIDDATA; @@ -134,7 +136,7 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) if (len < data->au_headers_length_bytes) return AVERROR_INVALIDDATA; - init_get_bits(&getbitcontext, buf, data->au_headers_length_bytes * 8); + bitstream_init(&bctx, buf, data->au_headers_length_bytes * 8); /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */ au_header_size = data->sizelength + data->indexlength; @@ -151,8 +153,8 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) } for (i = 0; i < data->nb_au_headers; ++i) { - data->au_headers[i].size = get_bits_long(&getbitcontext, data->sizelength); - data->au_headers[i].index = get_bits_long(&getbitcontext, data->indexlength); + data->au_headers[i].size = bitstream_read(&bctx, data->sizelength); + data->au_headers[i].index = bitstream_read(&bctx, data->indexlength); } return 0; diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c index 97df210916..2c0f8188b6 100644 --- a/libavformat/rtpdec_qt.c +++ b/libavformat/rtpdec_qt.c @@ -25,13 +25,14 @@ * @author Ronald S. Bultje */ +#include "libavcodec/bitstream.h" + #include "avformat.h" #include "internal.h" #include "avio_internal.h" #include "rtp.h" #include "rtpdec.h" #include "isom.h" -#include "libavcodec/get_bits.h" struct PayloadContext { AVPacket pkt; @@ -45,7 +46,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, int len, uint16_t seq, int flags) { AVIOContext pb; - GetBitContext gb; + BitstreamContext bc; int packing_scheme, has_payload_desc, has_packet_info, alen, has_marker_bit = flags & RTP_FLAG_MARKER, keyframe; @@ -71,38 +72,38 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, * The RTP payload is described in: * http://developer.apple.com/quicktime/icefloe/dispatch026.html */ - init_get_bits(&gb, buf, len << 3); + bitstream_init(&bc, buf, len << 3); ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL); if (len < 4) return AVERROR_INVALIDDATA; - skip_bits(&gb, 4); // version - if ((packing_scheme = get_bits(&gb, 2)) == 0) + bitstream_skip(&bc, 4); // version + if ((packing_scheme = bitstream_read(&bc, 2)) == 0) return AVERROR_INVALIDDATA; - keyframe = get_bits1(&gb); - has_payload_desc = get_bits1(&gb); - has_packet_info = get_bits1(&gb); - skip_bits(&gb, 23); // reserved:7, cache payload info:1, payload ID:15 + keyframe = bitstream_read_bit(&bc); + has_payload_desc = bitstream_read_bit(&bc); + has_packet_info = bitstream_read_bit(&bc); + bitstream_skip(&bc, 23); // reserved:7, cache payload info:1, payload ID:15 if (has_payload_desc) { int data_len, pos, is_start, is_finish; uint32_t tag; - pos = get_bits_count(&gb) >> 3; + pos = bitstream_tell(&bc) >> 3; if (pos + 12 > len) return AVERROR_INVALIDDATA; - skip_bits(&gb, 2); // has non-I-frames:1, is sparse:1 - is_start = get_bits1(&gb); - is_finish = get_bits1(&gb); + bitstream_skip(&bc, 2); // has non-I-frames:1, is sparse:1 + is_start = bitstream_read_bit(&bc); + is_finish = bitstream_read_bit(&bc); if (!is_start || !is_finish) { avpriv_request_sample(s, "RTP-X-QT with payload description " "split over several packets"); return AVERROR_PATCHWELCOME; } - skip_bits(&gb, 12); // reserved - data_len = get_bits(&gb, 16); + bitstream_skip(&bc, 12); // reserved + data_len = bitstream_read(&bc, 16); avio_seek(&pb, pos + 4, SEEK_SET); tag = avio_rl32(&pb); diff --git a/libavformat/rtpenc_h263_rfc2190.c b/libavformat/rtpenc_h263_rfc2190.c index b8d7a0ab1c..750a52bcd8 100644 --- a/libavformat/rtpenc_h263_rfc2190.c +++ b/libavformat/rtpenc_h263_rfc2190.c @@ -19,10 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavcodec/bitstream.h" +#include "libavcodec/put_bits.h" + #include "avformat.h" #include "rtpenc.h" -#include "libavcodec/put_bits.h" -#include "libavcodec/get_bits.h" struct H263Info { int src; @@ -103,7 +104,7 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size, { RTPMuxContext *s = s1->priv_data; int len, sbits = 0, ebits = 0; - GetBitContext gb; + BitstreamContext bc; struct H263Info info = { 0 }; struct H263State state = { 0 }; int mb_info_pos = 0, mb_info_count = mb_info_size / 12; @@ -111,17 +112,17 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size, s->timestamp = s->cur_timestamp; - init_get_bits(&gb, buf, size*8); - if (get_bits(&gb, 22) == 0x20) { /* Picture Start Code */ - info.tr = get_bits(&gb, 8); - skip_bits(&gb, 2); /* PTYPE start, H.261 disambiguation */ - skip_bits(&gb, 3); /* Split screen, document camera, freeze picture release */ - info.src = get_bits(&gb, 3); - info.i = get_bits(&gb, 1); - info.u = get_bits(&gb, 1); - info.s = get_bits(&gb, 1); - info.a = get_bits(&gb, 1); - info.pb = get_bits(&gb, 1); + bitstream_init(&bc, buf, size * 8); + if (bitstream_read(&bc, 22) == 0x20) { /* Picture Start Code */ + info.tr = bitstream_read(&bc, 8); + bitstream_skip(&bc, 2); /* PTYPE start, H.261 disambiguation */ + bitstream_skip(&bc, 3); /* Split screen, document camera, freeze picture release */ + info.src = bitstream_read(&bc, 3); + info.i = bitstream_read(&bc, 1); + info.u = bitstream_read(&bc, 1); + info.s = bitstream_read(&bc, 1); + info.a = bitstream_read(&bc, 1); + info.pb = bitstream_read(&bc, 1); } while (size > 0) { From 4795e4f61f993940c5384044caff56cc15078698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 7 Apr 2016 22:04:58 +0200 Subject: [PATCH 3/3] alac: Convert to the new bitstream reader --- libavcodec/alac.c | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/libavcodec/alac.c b/libavcodec/alac.c index aef68e76a3..0f1c59e486 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -48,19 +48,20 @@ #include #include "libavutil/channel_layout.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "bytestream.h" #include "internal.h" #include "mathops.h" -#include "unary_legacy.h" +#include "unary.h" #include "alac_data.h" #define ALAC_EXTRADATA_SIZE 36 typedef struct ALACContext { AVCodecContext *avctx; - GetBitContext gb; + BitstreamContext bc; int channels; int32_t *predict_error_buffer[2]; @@ -77,24 +78,24 @@ typedef struct ALACContext { int nb_samples; /**< number of samples in the current frame */ } ALACContext; -static inline unsigned int decode_scalar(GetBitContext *gb, int k, int bps) +static inline unsigned int decode_scalar(BitstreamContext *bc, int k, int bps) { - unsigned int x = get_unary_0_9(gb); + unsigned int x = get_unary_0_9(bc); if (x > 8) { /* RICE THRESHOLD */ /* use alternative encoding */ - x = get_bits_long(gb, bps); + x = bitstream_read(bc, bps); } else if (k != 1) { - int extrabits = show_bits(gb, k); + int extrabits = bitstream_peek(bc, k); /* multiply x by 2^k - 1, as part of their strange algorithm */ x = (x << k) - x; if (extrabits > 1) { x += extrabits - 1; - skip_bits(gb, k); + bitstream_skip(bc, k); } else - skip_bits(gb, k - 1); + bitstream_skip(bc, k - 1); } return x; } @@ -113,7 +114,7 @@ static void rice_decompress(ALACContext *alac, int32_t *output_buffer, /* calculate rice param and decode next value */ k = av_log2((history >> 9) + 3); k = FFMIN(k, alac->rice_limit); - x = decode_scalar(&alac->gb, k, bps); + x = decode_scalar(&alac->bc, k, bps); x += sign_modifier; sign_modifier = 0; output_buffer[i] = (x >> 1) ^ -(x & 1); @@ -132,7 +133,7 @@ static void rice_decompress(ALACContext *alac, int32_t *output_buffer, /* calculate rice param and decode block size */ k = 7 - av_log2(history) + ((history + 16) >> 6); k = FFMIN(k, alac->rice_limit); - block_size = decode_scalar(&alac->gb, k, 16); + block_size = decode_scalar(&alac->bc, k, 16); if (block_size > 0) { if (block_size >= nb_samples - i) { @@ -257,13 +258,13 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, uint32_t output_samples; int i, ch; - skip_bits(&alac->gb, 4); /* element instance tag */ - skip_bits(&alac->gb, 12); /* unused header bits */ + bitstream_skip(&alac->bc, 4); /* element instance tag */ + bitstream_skip(&alac->bc, 12); /* unused header bits */ /* the number of output samples is stored in the frame */ - has_size = get_bits1(&alac->gb); + has_size = bitstream_read_bit(&alac->bc); - alac->extra_bits = get_bits(&alac->gb, 2) << 3; + alac->extra_bits = bitstream_read(&alac->bc, 2) << 3; bps = alac->sample_size - alac->extra_bits + channels - 1; if (bps > 32) { avpriv_report_missing_feature(avctx, "bps %d", bps); @@ -271,10 +272,10 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, } /* whether the frame is compressed */ - is_compressed = !get_bits1(&alac->gb); + is_compressed = !bitstream_read_bit(&alac->bc); if (has_size) - output_samples = get_bits_long(&alac->gb, 32); + output_samples = bitstream_read(&alac->bc, 32); else output_samples = alac->max_samples_per_frame; if (!output_samples || output_samples > alac->max_samples_per_frame) { @@ -313,27 +314,27 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, return AVERROR(ENOSYS); } - decorr_shift = get_bits(&alac->gb, 8); - decorr_left_weight = get_bits(&alac->gb, 8); + decorr_shift = bitstream_read(&alac->bc, 8); + decorr_left_weight = bitstream_read(&alac->bc, 8); for (ch = 0; ch < channels; ch++) { - prediction_type[ch] = get_bits(&alac->gb, 4); - lpc_quant[ch] = get_bits(&alac->gb, 4); - rice_history_mult[ch] = get_bits(&alac->gb, 3); - lpc_order[ch] = get_bits(&alac->gb, 5); + prediction_type[ch] = bitstream_read(&alac->bc, 4); + lpc_quant[ch] = bitstream_read(&alac->bc, 4); + rice_history_mult[ch] = bitstream_read(&alac->bc, 3); + lpc_order[ch] = bitstream_read(&alac->bc, 5); if (lpc_order[ch] >= alac->max_samples_per_frame) return AVERROR_INVALIDDATA; /* read the predictor table */ for (i = lpc_order[ch] - 1; i >= 0; i--) - lpc_coefs[ch][i] = get_sbits(&alac->gb, 16); + lpc_coefs[ch][i] = bitstream_read_signed(&alac->bc, 16); } if (alac->extra_bits) { for (i = 0; i < alac->nb_samples; i++) { for (ch = 0; ch < channels; ch++) - alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits); + alac->extra_bits_buffer[ch][i] = bitstream_read(&alac->bc, alac->extra_bits); } } for (ch = 0; ch < channels; ch++) { @@ -366,7 +367,7 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, for (i = 0; i < alac->nb_samples; i++) { for (ch = 0; ch < channels; ch++) { alac->output_samples_buffer[ch][i] = - get_sbits_long(&alac->gb, alac->sample_size); + bitstream_read_signed(&alac->bc, alac->sample_size); } } alac->extra_bits = 0; @@ -412,13 +413,13 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, int channels; int ch, ret, got_end; - init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8); + bitstream_init8(&alac->bc, avpkt->data, avpkt->size); got_end = 0; alac->nb_samples = 0; ch = 0; - while (get_bits_left(&alac->gb) >= 3) { - element = get_bits(&alac->gb, 3); + while (bitstream_bits_left(&alac->bc) >= 3) { + element = bitstream_read(&alac->bc, 3); if (element == TYPE_END) { got_end = 1; break; @@ -438,7 +439,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, ret = decode_element(avctx, frame, ff_alac_channel_layout_offsets[alac->channels - 1][ch], channels); - if (ret < 0 && get_bits_left(&alac->gb)) + if (ret < 0 && bitstream_bits_left(&alac->bc)) return ret; ch += channels; @@ -452,9 +453,9 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) { + if (avpkt->size * 8 - bitstream_tell(&alac->bc) > 8) { av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", - avpkt->size * 8 - get_bits_count(&alac->gb)); + avpkt->size * 8 - bitstream_tell(&alac->bc)); } *got_frame_ptr = 1;