diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-02-24 02:57:18 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-02-24 02:57:18 +0100 |
commit | e2cc39b6096ed4353293252e3955417b7766f161 (patch) | |
tree | 0bc4d98c120dedcffb9b6e50943b4fc9e3c2a877 /libavcodec/snowenc.c | |
parent | 32e74395a8e88dee1c149aeb36e7a21df431c181 (diff) | |
parent | 31632e73f47d25e2077fce729571259ee6354854 (diff) | |
download | ffmpeg-e2cc39b6096ed4353293252e3955417b7766f161.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (40 commits)
swf: check return values for av_get/new_packet().
wavpack: Don't shift minclip/maxclip
rtpenc: Expose the max packet size via an avoption
rtpenc: Move max_packet_size to a context variable
rtpenc: Add an option for not sending RTCP packets
lavc: drop encode() support for video.
snowenc: switch to encode2().
snowenc: don't abuse input picture for storing information.
a64multienc: switch to encode2().
a64multienc: don't write into output buffer when there's no output.
libxvid: switch to encode2().
tiffenc: switch to encode2().
tiffenc: properly forward error codes in encode_frame().
lavc: drop libdirac encoder.
gifenc: switch to encode2().
libvpxenc: switch to encode2().
flashsvenc: switch to encode2().
Remove libpostproc.
lcl: don't overwrite input memory.
swscale: take first/lastline over/underflows into account for MMX.
...
Conflicts:
.gitignore
Makefile
cmdutils.c
configure
doc/APIchanges
libavcodec/Makefile
libavcodec/allcodecs.c
libavcodec/libdiracenc.c
libavcodec/libxvidff.c
libavcodec/qtrleenc.c
libavcodec/tiffenc.c
libavcodec/utils.c
libavformat/mov.c
libavformat/movenc.c
libpostproc/Makefile
libpostproc/postprocess.c
libpostproc/postprocess.h
libpostproc/postprocess_altivec_template.c
libpostproc/postprocess_internal.h
libpostproc/postprocess_template.c
libswscale/swscale.c
libswscale/utils.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/snowenc.c')
-rw-r--r-- | libavcodec/snowenc.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 4c118fe986..2bcbd7e721 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -1600,17 +1600,25 @@ static void calculate_visual_weight(SnowContext *s, Plane *p){ } } -static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ +static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *pict, int *got_packet) +{ SnowContext *s = avctx->priv_data; RangeCoder * const c= &s->c; - AVFrame *pict = data; + AVFrame *pic = &s->new_picture; const int width= s->avctx->width; const int height= s->avctx->height; - int level, orientation, plane_index, i, y; + int level, orientation, plane_index, i, y, ret; uint8_t rc_header_bak[sizeof(s->header_state)]; uint8_t rc_block_bak[sizeof(s->block_state)]; - ff_init_range_encoder(c, buf, buf_size); + if (!pkt->data && + (ret = av_new_packet(pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_MIN_BUFFER_SIZE)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + return ret; + } + + ff_init_range_encoder(c, pkt->data, pkt->size); ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); for(i=0; i<3; i++){ @@ -1624,27 +1632,25 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, s->m.picture_number= avctx->frame_number; if(avctx->flags&CODEC_FLAG_PASS2){ - s->m.pict_type = - pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type; - s->keyframe= pict->pict_type==AV_PICTURE_TYPE_I; + s->m.pict_type = pic->pict_type = s->m.rc_context.entry[avctx->frame_number].new_pict_type; + s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I; if(!(avctx->flags&CODEC_FLAG_QSCALE)) { - pict->quality= ff_rate_estimate_qscale(&s->m, 0); - if (pict->quality < 0) + pic->quality = ff_rate_estimate_qscale(&s->m, 0); + if (pic->quality < 0) return -1; } }else{ s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; - s->m.pict_type= - pict->pict_type= s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + s->m.pict_type = pic->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; } if(s->pass1_rc && avctx->frame_number == 0) - pict->quality= 2*FF_QP2LAMBDA; - if(pict->quality){ - s->qlog= qscale2qlog(pict->quality); - s->lambda = pict->quality * 3/2; + pic->quality = 2*FF_QP2LAMBDA; + if (pic->quality) { + s->qlog = qscale2qlog(pic->quality); + s->lambda = pic->quality * 3/2; } - if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ + if (s->qlog < 0 || (!pic->quality && (avctx->flags & CODEC_FLAG_QSCALE))) { s->qlog= LOSSLESS_QLOG; s->lambda = 0; }//else keep previous frame's qlog until after motion estimation @@ -1654,7 +1660,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, s->m.current_picture_ptr= &s->m.current_picture; s->m.last_picture.f.pts = s->m.current_picture.f.pts; s->m.current_picture.f.pts = pict->pts; - if(pict->pict_type == AV_PICTURE_TYPE_P){ + if(pic->pict_type == AV_PICTURE_TYPE_P){ int block_width = (width +15)>>4; int block_height= (height+15)>>4; int stride= s->current_picture.linesize[0]; @@ -1679,7 +1685,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, s->m.mb_stride= s->m.mb_width+1; s->m.b8_stride= 2*s->m.mb_width+1; s->m.f_code=1; - s->m.pict_type= pict->pict_type; + s->m.pict_type = pic->pict_type; s->m.me_method= s->avctx->me_method; s->m.me.scene_change_score=0; s->m.flags= s->avctx->flags; @@ -1703,13 +1709,13 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, redo_frame: - if(pict->pict_type == AV_PICTURE_TYPE_I) + if (pic->pict_type == AV_PICTURE_TYPE_I) s->spatial_decomposition_count= 5; else s->spatial_decomposition_count= 5; - s->m.pict_type = pict->pict_type; - s->qbias= pict->pict_type == AV_PICTURE_TYPE_P ? 2 : 0; + s->m.pict_type = pic->pict_type; + s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0; ff_snow_common_init_after_header(avctx); @@ -1742,12 +1748,12 @@ redo_frame: predict_plane(s, s->spatial_idwt_buffer, plane_index, 0); if( plane_index==0 - && pict->pict_type == AV_PICTURE_TYPE_P + && pic->pict_type == AV_PICTURE_TYPE_P && !(avctx->flags&CODEC_FLAG_PASS2) && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ - ff_init_range_encoder(c, buf, buf_size); + ff_init_range_encoder(c, pkt->data, pkt->size); ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); - pict->pict_type= AV_PICTURE_TYPE_I; + pic->pict_type= AV_PICTURE_TYPE_I; s->keyframe=1; s->current_picture.key_frame=1; goto redo_frame; @@ -1773,12 +1779,12 @@ redo_frame: ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); if(s->pass1_rc && plane_index==0){ - int delta_qlog = ratecontrol_1pass(s, pict); + int delta_qlog = ratecontrol_1pass(s, pic); if (delta_qlog <= INT_MIN) return -1; if(delta_qlog){ //reordering qlog in the bitstream would eliminate this reset - ff_init_range_encoder(c, buf, buf_size); + ff_init_range_encoder(c, pkt->data, pkt->size); memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); encode_header(s); @@ -1793,7 +1799,7 @@ redo_frame: if(!QUANTIZE2) quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); if(orientation==0) - decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == AV_PICTURE_TYPE_P, 0); + decorrelate(s, b, b->ibuf, b->stride, pic->pict_type == AV_PICTURE_TYPE_P, 0); encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); assert(b->parent==NULL || b->parent->stride == b->stride*2); if(orientation==0) @@ -1820,7 +1826,7 @@ redo_frame: predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); }else{ //ME/MC only - if(pict->pict_type == AV_PICTURE_TYPE_I){ + if(pic->pict_type == AV_PICTURE_TYPE_I){ for(y=0; y<h; y++){ for(x=0; x<w; x++){ s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= @@ -1859,7 +1865,7 @@ redo_frame: s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; s->m.current_picture.f.display_picture_number = s->m.current_picture.f.coded_picture_number = avctx->frame_number; - s->m.current_picture.f.quality = pict->quality; + s->m.current_picture.f.quality = pic->quality; s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); if(s->pass1_rc) if (ff_rate_estimate_qscale(&s->m, 0) < 0) @@ -1874,7 +1880,12 @@ redo_frame: emms_c(); - return ff_rac_terminate(c); + pkt->size = ff_rac_terminate(c); + if (avctx->coded_frame->key_frame) + pkt->flags |= AV_PKT_FLAG_KEY; + *got_packet = 1; + + return 0; } static av_cold int encode_end(AVCodecContext *avctx) @@ -1909,7 +1920,7 @@ AVCodec ff_snow_encoder = { .id = CODEC_ID_SNOW, .priv_data_size = sizeof(SnowContext), .init = encode_init, - .encode = encode_frame, + .encode2 = encode_frame, .close = encode_end, .long_name = NULL_IF_CONFIG_SMALL("Snow"), .priv_class = &snowenc_class, |