Revision eb285cfe

View differences:

libavcodec/avcodec.h
1367 1367
    /**
1368 1368
     * Called at the beginning of each frame to get a buffer for it.
1369 1369
     * If pic.reference is set then the frame will be read later by libavcodec.
1370
     * avcodec_align_dimensions() should be used to find the required width and
1370
     * avcodec_align_dimensions2() should be used to find the required width and
1371 1371
     * height, as they normally need to be rounded up to the next multiple of 16.
1372 1372
     * if CODEC_CAP_DR1 is not set then get_buffer() must call
1373 1373
     * avcodec_default_get_buffer() instead of providing buffers allocated by
......
3226 3226
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
3227 3227
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
3228 3228
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
3229
/**
3230
 * Modifies width and height values so that they will result in a memory
3231
 * buffer that is acceptable for the codec if you do not use any horizontal
3232
 * padding.
3233
 */
3229 3234
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
3235
/**
3236
 * Modifies width and height values so that they will result in a memory
3237
 * buffer that is acceptable for the codec if you also ensure that all
3238
 * line sizes are a multiple of the respective linesize_align[i].
3239
 */
3240
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
3241
                               int linesize_align[4]);
3230 3242

  
3231 3243
/**
3232 3244
 * Checks if the given dimension of a picture is valid, meaning that all
libavcodec/utils.c
31 31
#include "libavutil/avstring.h"
32 32
#include "libavutil/integer.h"
33 33
#include "libavutil/crc.h"
34
#include "libavutil/pixdesc.h"
34 35
#include "avcodec.h"
35 36
#include "dsputil.h"
36 37
#include "opt.h"
......
117 118

  
118 119
#define INTERNAL_BUFFER_SIZE 32
119 120

  
120
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
121
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
121 122
    int w_align= 1;
122 123
    int h_align= 1;
123 124

  
......
180 181
    *height= FFALIGN(*height, h_align);
181 182
    if(s->codec_id == CODEC_ID_H264)
182 183
        *height+=2; // some of the optimized chroma MC reads one line too much
184

  
185
    linesize_align[0] =
186
    linesize_align[1] =
187
    linesize_align[2] =
188
    linesize_align[3] = STRIDE_ALIGN;
189
//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
190
//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
191
//picture size unneccessarily in some cases. The solution here is not
192
//pretty and better ideas are welcome!
193
#if HAVE_MMX
194
    if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
195
       s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
196
       s->codec_id == CODEC_ID_VP6A) {
197
        linesize_align[0] =
198
        linesize_align[1] =
199
        linesize_align[2] = 16;
200
    }
201
#endif
202
}
203

  
204
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
205
    int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
206
    int linesize_align[4];
207
    int align;
208
    avcodec_align_dimensions2(s, width, height, linesize_align);
209
    align = FFMAX(linesize_align[0], linesize_align[3]);
210
    linesize_align[1] <<= chroma_shift;
211
    linesize_align[2] <<= chroma_shift;
212
    align = FFMAX3(align, linesize_align[1], linesize_align[2]);
213
    *width=FFALIGN(*width, align);
183 214
}
184 215

  
185 216
int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
......
244 275

  
245 276
        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
246 277

  
247
        avcodec_align_dimensions(s, &w, &h);
278
        avcodec_align_dimensions2(s, &w, &h, stride_align);
248 279

  
249 280
        if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
250 281
            w+= EDGE_WIDTH*2;
......
260 291

  
261 292
            unaligned = 0;
262 293
            for (i=0; i<4; i++){
263
//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
264
//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
265
//picture size unneccessarily in some cases. The solution here is not
266
//pretty and better ideas are welcome!
267
#if HAVE_MMX
268
                if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
269
                   s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
270
                   s->codec_id == CODEC_ID_VP6A)
271
                    stride_align[i]= 16;
272
                else
273
#endif
274
                stride_align[i] = STRIDE_ALIGN;
275 294
                unaligned |= picture.linesize[i] % stride_align[i];
276 295
            }
277 296
        } while (unaligned);

Also available in: Unified diff