本文整理汇总了C++中put_bits_count函数的典型用法代码示例。如果您正苦于以下问题:C++ put_bits_count函数的具体用法?C++ put_bits_count怎么用?C++ put_bits_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put_bits_count函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode_superframe
static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
WMACodecContext *s = avctx->priv_data;
int i, total_gain, ret, error;
s->block_len_bits = s->frame_len_bits; // required by non variable block len
s->block_len = 1 << s->block_len_bits;
ret = apply_window_and_mdct(avctx, frame);
if (ret < 0)
return ret;
if (s->ms_stereo) {
float a, b;
int i;
for (i = 0; i < s->block_len; i++) {
a = s->coefs[0][i] * 0.5;
b = s->coefs[1][i] * 0.5;
s->coefs[0][i] = a + b;
s->coefs[1][i] = a - b;
}
}
if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE, 0)) < 0)
return ret;
total_gain = 128;
for (i = 64; i; i >>= 1) {
error = encode_frame(s, s->coefs, avpkt->data, avpkt->size,
total_gain - i);
if (error <= 0)
total_gain -= i;
}
while(total_gain <= 128 && error > 0)
error = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain++);
if (error > 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid input data or requested bitrate too low, cannot encode\n");
avpkt->size = 0;
return AVERROR(EINVAL);
}
av_assert0((put_bits_count(&s->pb) & 7) == 0);
i= avctx->block_align - (put_bits_count(&s->pb)+7)/8;
av_assert0(i>=0);
while(i--)
put_bits(&s->pb, 8, 'N');
flush_put_bits(&s->pb);
av_assert0(put_bits_ptr(&s->pb) - s->pb.buf == avctx->block_align);
if (frame->pts != AV_NOPTS_VALUE)
avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
avpkt->size = avctx->block_align;
*got_packet_ptr = 1;
return 0;
}
示例2: ff_copy_pce_data
int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
{
int five_bit_ch, four_bit_ch, comment_size, bits;
int offset = put_bits_count(pb);
copy_bits(pb, gb, 10); //Tag, Object Type, Frequency
five_bit_ch = copy_bits(pb, gb, 4); //Front
five_bit_ch += copy_bits(pb, gb, 4); //Side
five_bit_ch += copy_bits(pb, gb, 4); //Back
four_bit_ch = copy_bits(pb, gb, 2); //LFE
four_bit_ch += copy_bits(pb, gb, 3); //Data
five_bit_ch += copy_bits(pb, gb, 4); //Coupling
if (copy_bits(pb, gb, 1)) //Mono Mixdown
copy_bits(pb, gb, 4);
if (copy_bits(pb, gb, 1)) //Stereo Mixdown
copy_bits(pb, gb, 4);
if (copy_bits(pb, gb, 1)) //Matrix Mixdown
copy_bits(pb, gb, 3);
for (bits = five_bit_ch*5+four_bit_ch*4; bits > 16; bits -= 16)
copy_bits(pb, gb, 16);
if (bits)
copy_bits(pb, gb, bits);
align_put_bits(pb);
align_get_bits(gb);
comment_size = copy_bits(pb, gb, 8);
for (; comment_size > 0; comment_size--)
copy_bits(pb, gb, 8);
return put_bits_count(pb) - offset;
}
示例3: encode_superframe
static int encode_superframe(AVCodecContext *avctx,
unsigned char *buf, int buf_size, void *data){
WMACodecContext *s = avctx->priv_data;
short *samples = data;
int i, total_gain;
s->block_len_bits= s->frame_len_bits; //required by non variable block len
s->block_len = 1 << s->block_len_bits;
apply_window_and_mdct(avctx, samples, avctx->frame_size);
if (s->ms_stereo) {
float a, b;
int i;
for(i = 0; i < s->block_len; i++) {
a = s->coefs[0][i]*0.5;
b = s->coefs[1][i]*0.5;
s->coefs[0][i] = a + b;
s->coefs[1][i] = a - b;
}
}
#if 1
total_gain= 128;
for(i=64; i; i>>=1){
int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);
if(error<0)
total_gain-= i;
}
#else
total_gain= 90;
best= encode_frame(s, s->coefs, buf, buf_size, total_gain);
for(i=32; i; i>>=1){
int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);
int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i);
av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain);
if(scoreL < FFMIN(best, scoreR)){
best = scoreL;
total_gain -= i;
}else if(scoreR < best){
best = scoreR;
total_gain += i;
}
}
#endif
encode_frame(s, s->coefs, buf, buf_size, total_gain);
assert((put_bits_count(&s->pb) & 7) == 0);
i= s->block_align - (put_bits_count(&s->pb)+7)/8;
assert(i>=0);
while(i--)
put_bits(&s->pb, 8, 'N');
flush_put_bits(&s->pb);
return put_bits_ptr(&s->pb) - s->pb.buf;
}
示例4: cbs_jpeg_write_unit
static int cbs_jpeg_write_unit(CodedBitstreamContext *ctx,
CodedBitstreamUnit *unit)
{
CodedBitstreamJPEGContext *priv = ctx->priv_data;
PutBitContext pbc;
int err;
if (!priv->write_buffer) {
// Initial write buffer size is 1MB.
priv->write_buffer_size = 1024 * 1024;
reallocate_and_try_again:
err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
if (err < 0) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
"sufficiently large write buffer (last attempt "
"%"SIZE_SPECIFIER" bytes).\n", priv->write_buffer_size);
return err;
}
}
init_put_bits(&pbc, priv->write_buffer, priv->write_buffer_size);
if (unit->type == JPEG_MARKER_SOS)
err = cbs_jpeg_write_scan(ctx, unit, &pbc);
else
err = cbs_jpeg_write_segment(ctx, unit, &pbc);
if (err == AVERROR(ENOSPC)) {
// Overflow.
priv->write_buffer_size *= 2;
goto reallocate_and_try_again;
}
if (err < 0) {
// Write failed for some other reason.
return err;
}
if (put_bits_count(&pbc) % 8)
unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
else
unit->data_bit_padding = 0;
unit->data_size = (put_bits_count(&pbc) + 7) / 8;
flush_put_bits(&pbc);
err = ff_cbs_alloc_unit_data(ctx, unit, unit->data_size);
if (err < 0)
return err;
memcpy(unit->data, priv->write_buffer, unit->data_size);
return 0;
}
示例5: vaapi_encode_h264_write_sei
static void vaapi_encode_h264_write_sei(PutBitContext *pbc,
VAAPIEncodeContext *ctx,
VAAPIEncodePicture *pic)
{
VAAPIEncodeH264Context *priv = ctx->priv_data;
PutBitContext payload_bits;
char payload[256];
int payload_type, payload_size, i;
void (*write_payload)(PutBitContext *pbc,
VAAPIEncodeContext *ctx,
VAAPIEncodePicture *pic) = NULL;
vaapi_encode_h264_write_nal_header(pbc, NAL_SEI, 0);
for (payload_type = 0; payload_type < 64; payload_type++) {
switch (payload_type) {
case SEI_TYPE_BUFFERING_PERIOD:
if (!priv->send_timing_sei ||
pic->type != PICTURE_TYPE_IDR)
continue;
write_payload = &vaapi_encode_h264_write_buffering_period;
break;
case SEI_TYPE_PIC_TIMING:
if (!priv->send_timing_sei)
continue;
write_payload = &vaapi_encode_h264_write_pic_timing;
break;
case SEI_TYPE_USER_DATA_UNREGISTERED:
if (pic->encode_order != 0)
continue;
write_payload = &vaapi_encode_h264_write_identifier;
break;
default:
continue;
}
init_put_bits(&payload_bits, payload, sizeof(payload));
write_payload(&payload_bits, ctx, pic);
if (put_bits_count(&payload_bits) & 7) {
write_u(&payload_bits, 1, 1, bit_equal_to_one);
while (put_bits_count(&payload_bits) & 7)
write_u(&payload_bits, 1, 0, bit_equal_to_zero);
}
payload_size = put_bits_count(&payload_bits) / 8;
flush_put_bits(&payload_bits);
u(8, payload_type, last_payload_type_byte);
u(8, payload_size, last_payload_size_byte);
for (i = 0; i < payload_size; i++)
u(8, payload[i] & 0xff, sei_payload);
}
vaapi_encode_h264_write_trailing_rbsp(pbc);
}
示例6: encode_frame
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
ASV1Context * const a = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p= (AVFrame*)&a->picture;
int size;
int mb_x, mb_y;
init_put_bits(&a->pb, buf, buf_size);
*p = *pict;
p->pict_type= I_TYPE;
p->key_frame= 1;
for(mb_y=0; mb_y<a->mb_height2; mb_y++){
for(mb_x=0; mb_x<a->mb_width2; mb_x++){
dct_get(a, mb_x, mb_y);
encode_mb(a, a->block);
}
}
if(a->mb_width2 != a->mb_width){
mb_x= a->mb_width2;
for(mb_y=0; mb_y<a->mb_height2; mb_y++){
dct_get(a, mb_x, mb_y);
encode_mb(a, a->block);
}
}
if(a->mb_height2 != a->mb_height){
mb_y= a->mb_height2;
for(mb_x=0; mb_x<a->mb_width; mb_x++){
dct_get(a, mb_x, mb_y);
encode_mb(a, a->block);
}
}
emms_c();
align_put_bits(&a->pb);
while(put_bits_count(&a->pb)&31)
put_bits(&a->pb, 8, 0);
size= put_bits_count(&a->pb)/32;
if(avctx->codec_id == CODEC_ID_ASV1)
a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
else{
int i;
for(i=0; i<4*size; i++)
buf[i]= reverse[ buf[i] ];
}
return size*4;
}
示例7: append_picture_header
static int append_picture_header(const MPEG4PictureInfo *pic_info)
{
MPEG4SliceInfo slice_info;
uint8_t buf[32], buf_size;
const uint8_t *slice_data;
unsigned int slice_data_size;
PutBitContext pb;
int r;
if (mpeg4_get_slice_info(0, &slice_info) < 0)
return -1;
int time_incr = 1 + ilog2(pic_info->vop_time_increment_resolution - 1);
if (time_incr < 1)
time_incr = 1;
/* Reconstruct the VOP header */
init_put_bits(&pb, buf, sizeof(buf));
put_bits(&pb, 16, 0); /* vop header */
put_bits(&pb, 16, VOP_STARTCODE); /* vop header */
put_bits(&pb, 2, pic_info->vop_fields.bits.vop_coding_type);
put_bits(&pb, 1, 0);
put_bits(&pb, 1, 1); /* marker */
put_bits(&pb, time_incr, 0); /* time increment */
put_bits(&pb, 1, 1); /* marker */
put_bits(&pb, 1, 1); /* vop coded */
if (pic_info->vop_fields.bits.vop_coding_type == VOP_P_TYPE)
put_bits(&pb, 1, pic_info->vop_fields.bits.vop_rounding_type);
put_bits(&pb, 3, pic_info->vop_fields.bits.intra_dc_vlc_thr);
if (pic_info->vol_fields.bits.interlaced) {
put_bits(&pb, 1, pic_info->vop_fields.bits.top_field_first);
put_bits(&pb, 1, pic_info->vop_fields.bits.alternate_vertical_scan_flag);
}
put_bits(&pb, pic_info->quant_precision, slice_info.quant_scale);
if (pic_info->vop_fields.bits.vop_coding_type != VOP_I_TYPE)
put_bits(&pb, 3, pic_info->vop_fcode_forward);
if (pic_info->vop_fields.bits.vop_coding_type == VOP_B_TYPE)
put_bits(&pb, 3, pic_info->vop_fcode_backward);
/* Merge in bits from the first byte of the slice */
if ((put_bits_count(&pb) % 8) != slice_info.macroblock_offset)
return -1;
if (mpeg4_get_slice_data(0, &slice_data, &slice_data_size) < 0)
return -1;
r = 8 - (put_bits_count(&pb) % 8);
put_bits(&pb, r, slice_data[0] & ((1U << r) - 1));
flush_put_bits(&pb);
buf_size = put_bits_count(&pb) / 8;
return vdpau_append_slice_data(buf, buf_size);
}
示例8: avpriv_dca_convert_bitstream
int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
int max_size)
{
uint32_t mrk;
int i, tmp;
PutBitContext pb;
if ((unsigned) src_size > (unsigned) max_size)
src_size = max_size;
mrk = AV_RB32(src);
switch (mrk) {
case DCA_SYNCWORD_CORE_BE:
memcpy(dst, src, src_size);
return src_size;
case DCA_SYNCWORD_CORE_LE:
for (i = 0; i < (src_size + 1) >> 1; i++) {
AV_WB16(dst, AV_RL16(src));
src += 2;
dst += 2;
}
return src_size;
case DCA_SYNCWORD_CORE_14B_BE:
case DCA_SYNCWORD_CORE_14B_LE:
init_put_bits(&pb, dst, max_size);
for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
tmp = ((mrk == DCA_SYNCWORD_CORE_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
put_bits(&pb, 14, tmp);
}
flush_put_bits(&pb);
return (put_bits_count(&pb) + 7) >> 3;
default:
return AVERROR_INVALIDDATA;
}
}
示例9: xau_pcm8m_encode
size_t xau_pcm8m_encode( const sint8* pcm, size_t samples, void* buf, size_t bufsize )
{
// check preconditions
xau_codec_t codec;
init_put_bits( &codec.pb, (uint8*)buf, bufsize );
rice_init( codec.rice, PCM8M_K1, PCM8M_K2 );
ppfilter_init( &codec.flt, PCM8M_SH );
const sint8* p = pcm;
for( size_t n = 0; n != samples; ++n ) {
// a) skip sample diffing part as it seems hurting performance a lot on 8bit mode
// *p -= prev / 2
// b) apply polyphase filter
sint32 tmp = ppfilter_encode( &codec.flt, *p++ );
// c) skip median predictor part - also hurts performance on 8bps
// *p -= PREDICTOR1( last, 4 );
// d) encode the 'unsignificated' code
rice_enc( &codec.pb, codec.rice, xbs_sign_pack( tmp ) );
}
align_put_bits( &codec.pb );
uint32 written = put_bits_count( &codec.pb ) / 8;
// check for overruns
return written;
}
示例10: vaapi_encode_h264_write_extra_header
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
int index, int *type,
char *data, size_t *data_len)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
PutBitContext pbc;
char tmp[256];
size_t header_len;
if (index == 0 && ctx->va_rc_mode == VA_RC_CBR) {
*type = VAEncPackedHeaderH264_SEI;
init_put_bits(&pbc, tmp, sizeof(tmp));
vaapi_encode_h264_write_sei(&pbc, ctx, pic);
header_len = put_bits_count(&pbc);
flush_put_bits(&pbc);
return ff_vaapi_encode_h26x_nal_unit_to_byte_stream(data, data_len,
tmp, header_len);
} else {
return AVERROR_EOF;
}
}
示例11: encode_frame
static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
int buf_size, void *data)
{
PutBitContext pb;
AVFrame *p = data;
int x, y;
p->pict_type = AV_PICTURE_TYPE_I;
p->key_frame = 1;
init_put_bits(&pb, buf, buf_size / 8);
for (y = 0; y < avctx->height; y++) {
uint8_t *luma = &p->data[0][y * p->linesize[0]];
uint8_t *cb = &p->data[1][y * p->linesize[1]];
uint8_t *cr = &p->data[2][y * p->linesize[2]];
for (x = 0; x < avctx->width; x += 4) {
put_bits(&pb, 5, luma[3] >> 3);
put_bits(&pb, 5, luma[2] >> 3);
put_bits(&pb, 5, luma[1] >> 3);
put_bits(&pb, 5, luma[0] >> 3);
luma += 4;
put_bits(&pb, 6, *(cb++) >> 2);
put_bits(&pb, 6, *(cr++) >> 2);
}
}
flush_put_bits(&pb);
return put_bits_count(&pb) / 8;
}
示例12: ff_dca_convert_bitstream
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
int max_size)
{
uint32_t mrk;
int i, tmp;
const uint16_t *ssrc = (const uint16_t *) src;
uint16_t *sdst = (uint16_t *) dst;
PutBitContext pb;
if ((unsigned) src_size > (unsigned) max_size)
src_size = max_size;
mrk = AV_RB32(src);
switch (mrk) {
case DCA_MARKER_RAW_BE:
memcpy(dst, src, src_size);
return src_size;
case DCA_MARKER_RAW_LE:
for (i = 0; i < (src_size + 1) >> 1; i++)
*sdst++ = av_bswap16(*ssrc++);
return src_size;
case DCA_MARKER_14B_BE:
case DCA_MARKER_14B_LE:
init_put_bits(&pb, dst, max_size);
for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
put_bits(&pb, 14, tmp);
}
flush_put_bits(&pb);
return (put_bits_count(&pb) + 7) >> 3;
default:
return AVERROR_INVALIDDATA;
}
}
示例13: latm_read_audio_specific_config
static int latm_read_audio_specific_config(GetBitContext *gb,
PutBitContext *pb)
{
int num_bits=0;
int audio_object_type;
MPEG4AudioConfig b, *c;
c = &b;
c->sbr = -1;
audio_object_type = copy_bits(pb, gb, 5);
if (audio_object_type == AOT_ESCAPE) {
audio_object_type = AOT_ESCAPE + copy_bits(pb, gb, 6) + 1;
}
c->object_type = audio_object_type;
c->sampling_index = copy_bits(pb, gb, 4);
c->sample_rate = ff_mpeg4audio_sample_rates[c->sampling_index];
if (c->sampling_index == 0x0f) {
c->sample_rate = copy_bits(pb, gb, 24);
}
c->chan_config = copy_bits(pb, gb, 4);
if (c->chan_config < FF_ARRAY_ELEMS(ff_mpeg4audio_channels))
c->channels = ff_mpeg4audio_channels[c->chan_config];
if (audio_object_type == AOT_AAC_MAIN ||
audio_object_type == AOT_AAC_LC ||
audio_object_type == AOT_AAC_SSR ||
audio_object_type == AOT_AAC_LTP ||
audio_object_type == AOT_AAC_SCALABLE ||
audio_object_type == AOT_TWINVQ) {
latm_read_ga_specific_config(audio_object_type, c, gb, pb);
} else if (audio_object_type == AOT_SBR) {
c->sbr = 1;
c->ext_sampling_index = copy_bits(pb, gb, 4);
c->ext_sample_rate = ff_mpeg4audio_sample_rates[c->ext_sampling_index];
if (c->ext_sampling_index == 0x0f) {
c->ext_sample_rate = copy_bits(pb, gb, 24);
}
c->object_type = copy_bits(pb, gb, 5);
} else if (audio_object_type >= AOT_ER_AAC_LC) {
latm_read_ga_specific_config(audio_object_type, c, gb, pb);
copy_bits(pb, gb, 2); // epConfig
}
if (c->sbr == -1 && c->sample_rate <= 24000)
c->sample_rate *= 2;
// count the extradata
num_bits = put_bits_count(pb);
flush_put_bits(pb);
return num_bits;
}
示例14: ff_copy_bits
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
{
int words= length>>4;
int bits= length&15;
int i;
if(length==0) return;
if(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++)
put_bits(pb, 8, src[i]);
flush_put_bits(pb);
memcpy(put_bits_ptr(pb), src+i, 2*words-i);
skip_put_bytes(pb, 2*words-i);
}
put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
}
示例15: vaapi_encode_h264_write_sequence_header
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
char *data, size_t *data_len)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
PutBitContext pbc;
char tmp[256];
int err;
size_t nal_len, bit_len, bit_pos, next_len;
bit_len = *data_len;
bit_pos = 0;
init_put_bits(&pbc, tmp, sizeof(tmp));
vaapi_encode_h264_write_sps(&pbc, ctx);
nal_len = put_bits_count(&pbc);
flush_put_bits(&pbc);
next_len = bit_len - bit_pos;
err = ff_vaapi_encode_h26x_nal_unit_to_byte_stream(data + bit_pos / 8,
&next_len,
tmp, nal_len);
if (err < 0)
return err;
bit_pos += next_len;
init_put_bits(&pbc, tmp, sizeof(tmp));
vaapi_encode_h264_write_pps(&pbc, ctx);
nal_len = put_bits_count(&pbc);
flush_put_bits(&pbc);
next_len = bit_len - bit_pos;
err = ff_vaapi_encode_h26x_nal_unit_to_byte_stream(data + bit_pos / 8,
&next_len,
tmp, nal_len);
if (err < 0)
return err;
bit_pos += next_len;
*data_len = bit_pos;
return 0;
}