* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavutil/intmath.h"
#include "libavutil/log.h"
-#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "avcodec.h"
-#include "encode.h"
-#include "me_cmp.h"
#include "snow_dwt.h"
-#include "internal.h"
#include "snow.h"
#include "snowdata.h"
-#include "rangecoder.h"
-#include "mathops.h"
-
void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
}
}
-int ff_snow_get_buffer(SnowContext *s, AVFrame *frame)
-{
- int ret, i;
- int edges_needed = av_codec_is_encoder(s->avctx->codec);
-
- frame->width = s->avctx->width ;
- frame->height = s->avctx->height;
- if (edges_needed) {
- frame->width += 2 * EDGE_WIDTH;
- frame->height += 2 * EDGE_WIDTH;
-
- ret = ff_encode_alloc_frame(s->avctx, frame);
- } else
- ret = ff_get_buffer(s->avctx, frame, AV_GET_BUFFER_FLAG_REF);
- if (ret < 0)
- return ret;
- if (edges_needed) {
- for (i = 0; frame->data[i]; i++) {
- int offset = (EDGE_WIDTH >> (i ? s->chroma_v_shift : 0)) *
- frame->linesize[i] +
- (EDGE_WIDTH >> (i ? s->chroma_h_shift : 0));
- frame->data[i] += offset;
- }
- frame->width = s->avctx->width;
- frame->height = s->avctx->height;
- }
-
- return 0;
-}
-
void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts
int plane_index, level, orientation;
}
}
}else{
- uint8_t *src= s->last_picture[block->ref]->data[plane_index];
+ const uint8_t *src = s->last_picture[block->ref]->data[plane_index];
const int scale= plane_index ? (2*s->mv_scale)>>s->chroma_h_shift : 2*s->mv_scale;
int mx= block->mx*scale;
int my= block->my*scale;
s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
s->spatial_decomposition_count = 1;
- ff_me_cmp_init(&s->mecc, avctx);
- ff_hpeldsp_init(&s->hdsp, avctx->flags);
ff_videodsp_init(&s->vdsp, 8);
ff_dwt_init(&s->dwt);
ff_h264qpel_init(&s->h264qpel, 8);
-#define mcf(dx,dy)\
- s->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\
- s->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
- s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
- s->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\
- s->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
- s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
-
- mcf( 0, 0)
- mcf( 4, 0)
- mcf( 8, 0)
- mcf(12, 0)
- mcf( 0, 4)
- mcf( 4, 4)
- mcf( 8, 4)
- mcf(12, 4)
- mcf( 0, 8)
- mcf( 4, 8)
- mcf( 8, 8)
- mcf(12, 8)
- mcf( 0,12)
- mcf( 4,12)
- mcf( 8,12)
- mcf(12,12)
-
#define mcfh(dx,dy)\
s->hdsp.put_pixels_tab [0][dy/4+dx/8]=\
s->hdsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\
int ff_snow_common_init_after_header(AVCodecContext *avctx) {
SnowContext *s = avctx->priv_data;
int plane_index, level, orientation;
- int ret, emu_buf_size;
if(!s->scratchbuf) {
- if (av_codec_is_decoder(avctx->codec)) {
- if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
- AV_GET_BUFFER_FLAG_REF)) < 0)
- return ret;
- }
-
+ int emu_buf_size;
emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
!FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
return AVERROR(ENOMEM);
}
- if (av_codec_is_decoder(avctx->codec) &&
- s->mconly_picture->format != avctx->pix_fmt) {
- av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
- return AVERROR_INVALIDDATA;
- }
-
for(plane_index=0; plane_index < s->nb_planes; plane_index++){
int w= s->avctx->width;
int h= s->avctx->height;
return 0;
}
-#define USE_HALFPEL_PLANE 0
-
-static int halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){
- int p,x,y;
-
- for(p=0; p < s->nb_planes; p++){
- int is_chroma= !!p;
- int w= is_chroma ? AV_CEIL_RSHIFT(s->avctx->width, s->chroma_h_shift) : s->avctx->width;
- int h= is_chroma ? AV_CEIL_RSHIFT(s->avctx->height, s->chroma_v_shift) : s->avctx->height;
- int ls= frame->linesize[p];
- uint8_t *src= frame->data[p];
-
- halfpel[1][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
- halfpel[2][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
- halfpel[3][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
- if (!halfpel[1][p] || !halfpel[2][p] || !halfpel[3][p]) {
- av_freep(&halfpel[1][p]);
- av_freep(&halfpel[2][p]);
- av_freep(&halfpel[3][p]);
- return AVERROR(ENOMEM);
- }
- halfpel[1][p] += EDGE_WIDTH * (1 + ls);
- halfpel[2][p] += EDGE_WIDTH * (1 + ls);
- halfpel[3][p] += EDGE_WIDTH * (1 + ls);
-
- halfpel[0][p]= src;
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= y*ls + x;
-
- halfpel[1][p][i]= (20*(src[i] + src[i+1]) - 5*(src[i-1] + src[i+2]) + (src[i-2] + src[i+3]) + 16 )>>5;
- }
- }
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= y*ls + x;
-
- halfpel[2][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5;
- }
- }
- src= halfpel[1][p];
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= y*ls + x;
-
- halfpel[3][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5;
- }
- }
-
-//FIXME border!
- }
- return 0;
-}
-
void ff_snow_release_buffer(AVCodecContext *avctx)
{
SnowContext *s = avctx->priv_data;
- int i;
if(s->last_picture[s->max_ref_frames-1]->data[0]){
av_frame_unref(s->last_picture[s->max_ref_frames-1]);
- for(i=0; i<9; i++)
- if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) {
- av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture->linesize[i%3]));
- s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] = NULL;
- }
}
}
-int ff_snow_frame_start(SnowContext *s){
+int ff_snow_frames_prepare(SnowContext *s)
+{
AVFrame *tmp;
- int i, ret;
ff_snow_release_buffer(s->avctx);
tmp= s->last_picture[s->max_ref_frames-1];
- for(i=s->max_ref_frames-1; i>0; i--)
+ for (int i = s->max_ref_frames - 1; i > 0; i--)
s->last_picture[i] = s->last_picture[i-1];
- memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4);
- if(USE_HALFPEL_PLANE && s->current_picture->data[0]) {
- if((ret = halfpel_interpol(s, s->halfpel_plane[0], s->current_picture)) < 0)
- return ret;
- }
s->last_picture[0] = s->current_picture;
s->current_picture = tmp;
if(s->keyframe){
s->ref_frames= 0;
+ s->current_picture->flags |= AV_FRAME_FLAG_KEY;
}else{
int i;
for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++)
- if(i && s->last_picture[i-1]->key_frame)
+ if(i && (s->last_picture[i-1]->flags & AV_FRAME_FLAG_KEY))
break;
s->ref_frames= i;
if(s->ref_frames==0){
av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n");
return AVERROR_INVALIDDATA;
}
+ s->current_picture->flags &= ~AV_FRAME_FLAG_KEY;
}
- if ((ret = ff_snow_get_buffer(s, s->current_picture)) < 0)
- return ret;
-
- s->current_picture->key_frame= s->keyframe;
return 0;
}
av_freep(&s->temp_idwt_buffer);
av_freep(&s->run_buffer);
- s->m.me.temp= NULL;
- av_freep(&s->m.me.scratchpad);
- av_freep(&s->m.me.map);
- av_freep(&s->m.me.score_map);
- av_freep(&s->m.sc.obmc_scratchpad);
-
av_freep(&s->block);
av_freep(&s->scratchbuf);
av_freep(&s->emu_edge_buffer);
for(i=0; i<MAX_REF_FRAMES; i++){
- av_freep(&s->ref_mvs[i]);
- av_freep(&s->ref_scores[i]);
if(s->last_picture[i] && s->last_picture[i]->data[0]) {
av_assert0(s->last_picture[i]->data[0] != s->current_picture->data[0]);
}