Mercurial > libavcodec.hg
comparison utils.c @ 1214:327c5a36dfe7 libavcodec
fixing mixed dr1 + internal buffers
author | michaelni |
---|---|
date | Fri, 25 Apr 2003 00:29:48 +0000 |
parents | e0fc95a6eb4e |
children | eb2affe57a2a |
comparison
equal
deleted
inserted
replaced
1213:a71fe70b428b | 1214:327c5a36dfe7 |
---|---|
117 while (*p != NULL) p = &(*p)->next; | 117 while (*p != NULL) p = &(*p)->next; |
118 *p = format; | 118 *p = format; |
119 format->next = NULL; | 119 format->next = NULL; |
120 } | 120 } |
121 | 121 |
122 typedef struct DefaultPicOpaque{ | 122 typedef struct InternalBuffer{ |
123 int last_pic_num; | 123 int last_pic_num; |
124 uint8_t *base[4]; | |
124 uint8_t *data[4]; | 125 uint8_t *data[4]; |
125 }DefaultPicOpaque; | 126 }InternalBuffer; |
127 | |
128 #define INTERNAL_BUFFER_SIZE 32 | |
126 | 129 |
127 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ | 130 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
128 int i; | 131 int i; |
129 const int width = s->width; | 132 const int width = s->width; |
130 const int height= s->height; | 133 const int height= s->height; |
131 DefaultPicOpaque *opaque; | 134 InternalBuffer *buf; |
132 | 135 |
133 assert(pic->data[0]==NULL); | 136 assert(pic->data[0]==NULL); |
134 assert(pic->type==0 || pic->type==FF_BUFFER_TYPE_INTERNAL); | 137 assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); |
135 | 138 |
136 if(pic->opaque){ | 139 if(s->internal_buffer==NULL){ |
137 opaque= (DefaultPicOpaque *)pic->opaque; | 140 s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer)); |
138 for(i=0; i<3; i++) | 141 } |
139 pic->data[i]= opaque->data[i]; | 142 #if 0 |
140 | 143 s->internal_buffer= av_fast_realloc( |
141 // printf("get_buffer %X coded_pic_num:%d last:%d\n", pic->opaque, pic->coded_picture_number, opaque->last_pic_num); | 144 s->internal_buffer, |
142 pic->age= pic->coded_picture_number - opaque->last_pic_num; | 145 &s->internal_buffer_size, |
143 opaque->last_pic_num= pic->coded_picture_number; | 146 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ |
144 //printf("age: %d %d %d\n", pic->age, c->picture_number, pic->coded_picture_number); | 147 ); |
148 #endif | |
149 | |
150 buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; | |
151 | |
152 if(buf->base[0]){ | |
153 pic->age= pic->coded_picture_number - buf->last_pic_num; | |
154 buf->last_pic_num= pic->coded_picture_number; | |
145 }else{ | 155 }else{ |
146 int align, h_chroma_shift, v_chroma_shift; | 156 int align, h_chroma_shift, v_chroma_shift; |
147 int w, h, pixel_size; | 157 int w, h, pixel_size; |
148 | 158 |
149 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | 159 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
172 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | 182 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
173 w+= EDGE_WIDTH*2; | 183 w+= EDGE_WIDTH*2; |
174 h+= EDGE_WIDTH*2; | 184 h+= EDGE_WIDTH*2; |
175 } | 185 } |
176 | 186 |
177 opaque= av_mallocz(sizeof(DefaultPicOpaque)); | 187 buf->last_pic_num= -256*256*256*64; |
178 if(opaque==NULL) return -1; | |
179 | |
180 pic->opaque= opaque; | |
181 opaque->last_pic_num= -256*256*256*64; | |
182 | 188 |
183 for(i=0; i<3; i++){ | 189 for(i=0; i<3; i++){ |
184 const int h_shift= i==0 ? 0 : h_chroma_shift; | 190 const int h_shift= i==0 ? 0 : h_chroma_shift; |
185 const int v_shift= i==0 ? 0 : v_chroma_shift; | 191 const int v_shift= i==0 ? 0 : v_chroma_shift; |
186 | 192 |
187 pic->linesize[i]= pixel_size*w>>h_shift; | 193 pic->linesize[i]= pixel_size*w>>h_shift; |
188 | 194 |
189 pic->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 | 195 buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 |
190 if(pic->base[i]==NULL) return -1; | 196 if(buf->base[i]==NULL) return -1; |
191 | 197 memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift); |
192 memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift); | |
193 | 198 |
194 if(s->flags&CODEC_FLAG_EMU_EDGE) | 199 if(s->flags&CODEC_FLAG_EMU_EDGE) |
195 pic->data[i] = pic->base[i]; | 200 buf->data[i] = buf->base[i]; |
196 else | 201 else |
197 pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift); | 202 buf->data[i] = buf->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift); |
198 | |
199 opaque->data[i]= pic->data[i]; | |
200 } | 203 } |
201 pic->age= 256*256*256*64; | 204 pic->age= 256*256*256*64; |
202 pic->type= FF_BUFFER_TYPE_INTERNAL; | 205 pic->type= FF_BUFFER_TYPE_INTERNAL; |
203 } | 206 } |
204 | 207 |
208 for(i=0; i<4; i++){ | |
209 pic->base[i]= buf->base[i]; | |
210 pic->data[i]= buf->data[i]; | |
211 } | |
212 s->internal_buffer_count++; | |
213 | |
205 return 0; | 214 return 0; |
206 } | 215 } |
207 | 216 |
208 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ | 217 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ |
209 int i; | 218 int i; |
210 | 219 InternalBuffer *buf, *last, temp; |
220 | |
211 assert(pic->type==FF_BUFFER_TYPE_INTERNAL); | 221 assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |
212 | 222 |
213 for(i=0; i<3; i++) | 223 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize |
224 buf= &((InternalBuffer*)s->internal_buffer)[i]; | |
225 if(buf->data[0] == pic->data[0]) | |
226 break; | |
227 } | |
228 assert(i < s->internal_buffer_count); | |
229 s->internal_buffer_count--; | |
230 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; | |
231 | |
232 temp= *buf; | |
233 *buf= *last; | |
234 *last= temp; | |
235 | |
236 for(i=0; i<3; i++){ | |
214 pic->data[i]=NULL; | 237 pic->data[i]=NULL; |
238 // pic->base[i]=NULL; | |
239 } | |
215 //printf("R%X\n", pic->opaque); | 240 //printf("R%X\n", pic->opaque); |
216 } | 241 } |
217 | 242 |
218 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){ | 243 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){ |
219 return fmt[0]; | 244 return fmt[0]; |
590 //FIXME | 615 //FIXME |
591 break; | 616 break; |
592 } | 617 } |
593 } | 618 } |
594 | 619 |
620 void avcodec_default_free_buffers(AVCodecContext *s){ | |
621 int i, j; | |
622 | |
623 if(s->internal_buffer==NULL) return; | |
624 | |
625 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ | |
626 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; | |
627 for(j=0; j<4; j++){ | |
628 av_freep(&buf->base[j]); | |
629 buf->data[j]= NULL; | |
630 } | |
631 } | |
632 av_freep(&s->internal_buffer); | |
633 | |
634 s->internal_buffer_count=0; | |
635 } | |
636 | |
595 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ | 637 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ |
596 int exact=1, sign=0; | 638 int exact=1, sign=0; |
597 int64_t gcd, larger; | 639 int64_t gcd, larger; |
598 | 640 |
599 assert(den != 0); | 641 assert(den != 0); |