1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

store packet GetBitContext in the decoder context

Originally committed as revision 19762 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Sascha Sommer 2009-09-05 09:56:06 +00:00
parent d2a47a578e
commit 2016932472

View File

@ -188,6 +188,7 @@ typedef struct WMAProDecodeCtx {
int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]; ///< subwoofer cutoff values int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]; ///< subwoofer cutoff values
/* packet decode state */ /* packet decode state */
GetBitContext pgb; ///< bitstream reader context for the packet
uint8_t packet_sequence_number; ///< current packet number uint8_t packet_sequence_number; ///< current packet number
int num_saved_bits; ///< saved number of bits int num_saved_bits; ///< saved number of bits
int frame_offset; ///< frame offset in the bit reservoir int frame_offset; ///< frame offset in the bit reservoir
@ -1441,8 +1442,8 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
static int decode_packet(AVCodecContext *avctx, static int decode_packet(AVCodecContext *avctx,
void *data, int *data_size, AVPacket* avpkt) void *data, int *data_size, AVPacket* avpkt)
{ {
GetBitContext gb;
WMAProDecodeCtx *s = avctx->priv_data; WMAProDecodeCtx *s = avctx->priv_data;
GetBitContext* gb = &s->pgb;
const uint8_t* buf = avpkt->data; const uint8_t* buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
int more_frames = 1; int more_frames = 1;
@ -1463,12 +1464,12 @@ static int decode_packet(AVCodecContext *avctx,
buf_size = avctx->block_align; buf_size = avctx->block_align;
/** parse packet header */ /** parse packet header */
init_get_bits(&gb, buf, s->buf_bit_size); init_get_bits(gb, buf, s->buf_bit_size);
packet_sequence_number = get_bits(&gb, 4); packet_sequence_number = get_bits(gb, 4);
skip_bits(&gb, 2); skip_bits(gb, 2);
/** get number of bits that need to be added to the previous frame */ /** get number of bits that need to be added to the previous frame */
num_bits_prev_frame = get_bits(&gb, s->log2_frame_size); num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
dprintf(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number, dprintf(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number,
num_bits_prev_frame); num_bits_prev_frame);
@ -1484,7 +1485,7 @@ static int decode_packet(AVCodecContext *avctx,
if (num_bits_prev_frame > 0) { if (num_bits_prev_frame > 0) {
/** append the previous frame data to the remaining data from the /** append the previous frame data to the remaining data from the
previous packet to create a full frame */ previous packet to create a full frame */
save_bits(s, &gb, num_bits_prev_frame, 1); save_bits(s, gb, num_bits_prev_frame, 1);
dprintf(avctx, "accumulated %x bits of frame data\n", dprintf(avctx, "accumulated %x bits of frame data\n",
s->num_saved_bits - s->frame_offset); s->num_saved_bits - s->frame_offset);
@ -1499,12 +1500,12 @@ static int decode_packet(AVCodecContext *avctx,
s->packet_loss = 0; s->packet_loss = 0;
/** decode the rest of the packet */ /** decode the rest of the packet */
while (!s->packet_loss && more_frames && while (!s->packet_loss && more_frames &&
remaining_bits(s, &gb) > s->log2_frame_size) { remaining_bits(s, gb) > s->log2_frame_size) {
int frame_size = show_bits(&gb, s->log2_frame_size); int frame_size = show_bits(gb, s->log2_frame_size);
/** there is enough data for a full frame */ /** there is enough data for a full frame */
if (remaining_bits(s, &gb) >= frame_size && frame_size > 0) { if (remaining_bits(s, gb) >= frame_size && frame_size > 0) {
save_bits(s, &gb, frame_size, 0); save_bits(s, gb, frame_size, 0);
/** decode the frame */ /** decode the frame */
more_frames = decode_frame(s); more_frames = decode_frame(s);
@ -1516,10 +1517,10 @@ static int decode_packet(AVCodecContext *avctx,
more_frames = 0; more_frames = 0;
} }
if (!s->packet_loss && remaining_bits(s, &gb) > 0) { if (!s->packet_loss && remaining_bits(s, gb) > 0) {
/** save the rest of the data so that it can be decoded /** save the rest of the data so that it can be decoded
with the next packet */ with the next packet */
save_bits(s, &gb, remaining_bits(s, &gb), 0); save_bits(s, gb, remaining_bits(s, gb), 0);
} }
*data_size = (int8_t *)s->samples - (int8_t *)data; *data_size = (int8_t *)s->samples - (int8_t *)data;