1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2026-04-24 04:44:54 +02:00
Files
FFmpeg/libavcodec/bitstream.c
T

73 lines
2.1 KiB
C
Raw Normal View History

2001-07-22 14:18:56 +00:00
/*
* Common bit i/o utils
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
2010-03-29 02:50:23 +00:00
* Copyright (c) 2010 Loren Merritt
2001-07-22 14:18:56 +00:00
*
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
2002-05-25 22:45:33 +00:00
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
2001-07-22 14:18:56 +00:00
*
* FFmpeg is distributed in the hope that it will be useful,
2001-07-22 14:18:56 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2002-05-25 22:45:33 +00:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2001-07-22 14:18:56 +00:00
*
2002-05-25 22:45:33 +00:00
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2001-07-22 14:18:56 +00:00
*/
2003-03-06 11:32:04 +00:00
/**
* @file
* bitstream api.
2003-03-06 11:32:04 +00:00
*/
2005-12-17 18:14:38 +00:00
#include <stdint.h>
#include <string.h>
#include "config.h"
2012-07-23 22:17:52 +02:00
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "put_bits.h"
2003-01-27 20:39:29 +00:00
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
2002-05-03 23:13:24 +00:00
{
2013-06-15 10:19:51 +02:00
while (*string) {
put_bits(pb, 8, *string);
string++;
2002-05-03 23:13:24 +00:00
}
2013-06-15 10:19:51 +02:00
if (terminate_string)
put_bits(pb, 8, 0);
2002-05-03 23:13:24 +00:00
}
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
2007-07-06 14:13:25 +00:00
{
2013-06-15 10:19:51 +02:00
int words = length >> 4;
int bits = length & 15;
2007-07-06 14:13:25 +00:00
int i;
2013-06-15 10:19:51 +02:00
if (length == 0)
return;
2007-07-06 14:13:25 +00:00
av_assert0(length <= put_bits_left(pb));
2013-06-15 10:19:51 +02:00
if (CONFIG_SMALL || words < 16 || put_bits_count(pb) & 7) {
for (i = 0; i < words; i++)
put_bits(pb, 16, AV_RB16(src + 2 * i));
} else {
for (i = 0; put_bits_count(pb) & 31; i++)
2007-07-06 14:13:25 +00:00
put_bits(pb, 8, src[i]);
flush_put_bits(pb);
2013-06-15 10:19:51 +02:00
memcpy(put_bits_ptr(pb), src + i, 2 * words - i);
skip_put_bytes(pb, 2 * words - i);
2007-07-06 14:13:25 +00:00
}
2013-06-15 10:19:51 +02:00
put_bits(pb, bits, AV_RB16(src + 2 * words) >> (16 - bits));
2007-07-06 14:13:25 +00:00
}