Mercurial > libavcodec.hg
comparison utils.c @ 1538:2312ceb69d17 libavcodec
default_get_buffer() fixes
author | michael |
---|---|
date | Wed, 15 Oct 2003 21:59:08 +0000 |
parents | 010f76d07a27 |
children | 9c4921a51392 |
comparison
equal
deleted
inserted
replaced
1537:6df940415116 | 1538:2312ceb69d17 |
---|---|
125 uint8_t *data[4]; | 125 uint8_t *data[4]; |
126 }InternalBuffer; | 126 }InternalBuffer; |
127 | 127 |
128 #define INTERNAL_BUFFER_SIZE 32 | 128 #define INTERNAL_BUFFER_SIZE 32 |
129 | 129 |
130 #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1)) | |
131 | |
132 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ | |
133 int w_align= 1; | |
134 int h_align= 1; | |
135 | |
136 switch(s->pix_fmt){ | |
137 case PIX_FMT_YUV420P: | |
138 case PIX_FMT_YUV422: | |
139 case PIX_FMT_YUV422P: | |
140 case PIX_FMT_YUV444P: | |
141 case PIX_FMT_GRAY8: | |
142 case PIX_FMT_YUVJ420P: | |
143 case PIX_FMT_YUVJ422P: | |
144 case PIX_FMT_YUVJ444P: | |
145 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment | |
146 h_align= 16; | |
147 break; | |
148 case PIX_FMT_YUV411P: | |
149 w_align=32; | |
150 h_align=8; | |
151 break; | |
152 case PIX_FMT_YUV410P: | |
153 if(s->codec_id == CODEC_ID_SVQ1){ | |
154 w_align=64; | |
155 h_align=64; | |
156 } | |
157 break; | |
158 default: | |
159 w_align= 1; | |
160 h_align= 1; | |
161 break; | |
162 } | |
163 | |
164 *width = ALIGN(*width , w_align); | |
165 *height= ALIGN(*height, h_align); | |
166 } | |
167 | |
130 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ | 168 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
131 int i; | 169 int i; |
132 const int width = s->width; | 170 int w= s->width; |
133 const int height= s->height; | 171 int h= s->height; |
134 InternalBuffer *buf; | 172 InternalBuffer *buf; |
135 | 173 |
136 assert(pic->data[0]==NULL); | 174 assert(pic->data[0]==NULL); |
137 assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); | 175 assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); |
138 | 176 |
151 | 189 |
152 if(buf->base[0]){ | 190 if(buf->base[0]){ |
153 pic->age= pic->coded_picture_number - buf->last_pic_num; | 191 pic->age= pic->coded_picture_number - buf->last_pic_num; |
154 buf->last_pic_num= pic->coded_picture_number; | 192 buf->last_pic_num= pic->coded_picture_number; |
155 }else{ | 193 }else{ |
156 int align, h_chroma_shift, v_chroma_shift; | 194 int h_chroma_shift, v_chroma_shift; |
157 int w, h, pixel_size; | 195 int s_align, pixel_size; |
158 | 196 |
159 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | 197 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
198 | |
160 switch(s->pix_fmt){ | 199 switch(s->pix_fmt){ |
161 case PIX_FMT_RGB555: | 200 case PIX_FMT_RGB555: |
162 case PIX_FMT_RGB565: | 201 case PIX_FMT_RGB565: |
163 case PIX_FMT_YUV422: | 202 case PIX_FMT_YUV422: |
164 pixel_size=2; | 203 pixel_size=2; |
171 pixel_size=4; | 210 pixel_size=4; |
172 break; | 211 break; |
173 default: | 212 default: |
174 pixel_size=1; | 213 pixel_size=1; |
175 } | 214 } |
176 | 215 |
177 if(s->codec_id==CODEC_ID_SVQ1) align=63; | 216 avcodec_align_dimensions(s, &w, &h); |
178 else align=15; | 217 #if defined(ARCH_POWERPC) || defined(HAVE_MMI) //FIXME some cleaner check |
179 | 218 s_align= 16; |
180 w= (width +align)&~align; | 219 #else |
181 h= (height+align)&~align; | 220 s_align= 8; |
182 | 221 #endif |
222 | |
183 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | 223 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
184 w+= EDGE_WIDTH*2; | 224 w+= EDGE_WIDTH*2; |
185 h+= EDGE_WIDTH*2; | 225 h+= EDGE_WIDTH*2; |
186 } | 226 } |
187 | 227 |
189 | 229 |
190 for(i=0; i<3; i++){ | 230 for(i=0; i<3; i++){ |
191 const int h_shift= i==0 ? 0 : h_chroma_shift; | 231 const int h_shift= i==0 ? 0 : h_chroma_shift; |
192 const int v_shift= i==0 ? 0 : v_chroma_shift; | 232 const int v_shift= i==0 ? 0 : v_chroma_shift; |
193 | 233 |
194 pic->linesize[i]= pixel_size*w>>h_shift; | 234 pic->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align); |
195 | 235 |
196 buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 | 236 buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 |
197 if(buf->base[i]==NULL) return -1; | 237 if(buf->base[i]==NULL) return -1; |
198 memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift); | 238 memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift); |
199 | 239 |