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