Mercurial > libavcodec.hg
comparison utils.c @ 903:22ee74da2cd3 libavcodec
cleanup
adding AVVideoFrame
moving quality, pict_type, key_frame, qscale_table, ... to AVVideoFrame
removing obsolete variables in AVCodecContext
skiping of MBs in b frames
correctly initalizing AVCodecContext
picture buffer cleanup
author | michaelni |
---|---|
date | Wed, 04 Dec 2002 10:04:03 +0000 |
parents | 6acc8394960d |
children | 2ac4caad5ca6 |
comparison
equal
deleted
inserted
replaced
902:6acc8394960d | 903:22ee74da2cd3 |
---|---|
84 while (*p != NULL) p = &(*p)->next; | 84 while (*p != NULL) p = &(*p)->next; |
85 *p = format; | 85 *p = format; |
86 format->next = NULL; | 86 format->next = NULL; |
87 } | 87 } |
88 | 88 |
89 void avcodec_get_chroma_sub_sample(int fmt, int *h_shift, int *v_shift){ | |
90 switch(fmt){ | |
91 case PIX_FMT_YUV410P: | |
92 *h_shift=2; | |
93 *v_shift=2; | |
94 break; | |
95 case PIX_FMT_YUV420P: | |
96 *h_shift=1; | |
97 *v_shift=1; | |
98 break; | |
99 case PIX_FMT_YUV411P: | |
100 *h_shift=2; | |
101 *v_shift=0; | |
102 break; | |
103 case PIX_FMT_YUV422P: | |
104 case PIX_FMT_YUV422: | |
105 *h_shift=1; | |
106 *v_shift=0; | |
107 break; | |
108 default: //RGB/... | |
109 *h_shift=0; | |
110 *v_shift=0; | |
111 break; | |
112 } | |
113 } | |
114 | |
115 typedef struct DefaultPicOpaque{ | |
116 int last_pic_num; | |
117 uint8_t *data[4]; | |
118 }DefaultPicOpaque; | |
119 | |
120 int avcodec_default_get_buffer(AVCodecContext *s, AVVideoFrame *pic){ | |
121 int i; | |
122 const int width = s->width; | |
123 const int height= s->height; | |
124 DefaultPicOpaque *opaque; | |
125 | |
126 if(pic->opaque){ | |
127 opaque= (DefaultPicOpaque *)pic->opaque; | |
128 for(i=0; i<3; i++) | |
129 pic->data[i]= opaque->data[i]; | |
130 | |
131 // printf("get_buffer %X coded_pic_num:%d last:%d\n", pic->opaque, pic->coded_picture_number, opaque->last_pic_num); | |
132 pic->age= pic->coded_picture_number - opaque->last_pic_num; | |
133 opaque->last_pic_num= pic->coded_picture_number; | |
134 //printf("age: %d %d %d\n", pic->age, c->picture_number, pic->coded_picture_number); | |
135 }else{ | |
136 int align, h_chroma_shift, v_chroma_shift; | |
137 int w, h, pixel_size; | |
138 | |
139 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
140 | |
141 switch(s->pix_fmt){ | |
142 case PIX_FMT_YUV422: | |
143 pixel_size=2; | |
144 break; | |
145 case PIX_FMT_RGB24: | |
146 case PIX_FMT_BGR24: | |
147 pixel_size=3; | |
148 break; | |
149 case PIX_FMT_BGRA32: | |
150 case PIX_FMT_RGBA32: | |
151 pixel_size=4; | |
152 break; | |
153 default: | |
154 pixel_size=1; | |
155 } | |
156 | |
157 if(s->codec_id==CODEC_ID_SVQ1) align=63; | |
158 else align=15; | |
159 | |
160 w= (width +align)&~align; | |
161 h= (height+align)&~align; | |
162 | |
163 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | |
164 w+= EDGE_WIDTH*2; | |
165 h+= EDGE_WIDTH*2; | |
166 } | |
167 | |
168 opaque= av_mallocz(sizeof(DefaultPicOpaque)); | |
169 if(opaque==NULL) return -1; | |
170 | |
171 pic->opaque= opaque; | |
172 opaque->last_pic_num= -256*256*256*64; | |
173 | |
174 for(i=0; i<3; i++){ | |
175 int h_shift= i==0 ? 0 : h_chroma_shift; | |
176 int v_shift= i==0 ? 0 : v_chroma_shift; | |
177 | |
178 pic->linesize[i]= pixel_size*w>>h_shift; | |
179 | |
180 pic->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 | |
181 if(pic->base[i]==NULL) return -1; | |
182 | |
183 memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift); | |
184 | |
185 if(s->flags&CODEC_FLAG_EMU_EDGE) | |
186 pic->data[i] = pic->base[i]; | |
187 else | |
188 pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift); | |
189 | |
190 opaque->data[i]= pic->data[i]; | |
191 } | |
192 pic->age= 256*256*256*64; | |
193 } | |
194 | |
195 return 0; | |
196 } | |
197 | |
198 void avcodec_default_release_buffer(AVCodecContext *s, AVVideoFrame *pic){ | |
199 int i; | |
200 | |
201 for(i=0; i<3; i++) | |
202 pic->data[i]=NULL; | |
203 //printf("R%X\n", pic->opaque); | |
204 } | |
205 | |
89 void avcodec_get_context_defaults(AVCodecContext *s){ | 206 void avcodec_get_context_defaults(AVCodecContext *s){ |
90 s->bit_rate= 800*1000; | 207 s->bit_rate= 800*1000; |
91 s->bit_rate_tolerance= s->bit_rate*10; | 208 s->bit_rate_tolerance= s->bit_rate*10; |
92 s->qmin= 2; | 209 s->qmin= 2; |
93 s->qmax= 31; | 210 s->qmax= 31; |
102 s->error_resilience= 1; | 219 s->error_resilience= 1; |
103 s->workaround_bugs= FF_BUG_AUTODETECT; | 220 s->workaround_bugs= FF_BUG_AUTODETECT; |
104 s->frame_rate = 25 * FRAME_RATE_BASE; | 221 s->frame_rate = 25 * FRAME_RATE_BASE; |
105 s->gop_size= 50; | 222 s->gop_size= 50; |
106 s->me_method= ME_EPZS; | 223 s->me_method= ME_EPZS; |
224 s->get_buffer= avcodec_default_get_buffer; | |
225 s->release_buffer= avcodec_default_release_buffer; | |
107 } | 226 } |
108 | 227 |
109 /** | 228 /** |
110 * allocates a AVCodecContext and set it to defaults. | 229 * allocates a AVCodecContext and set it to defaults. |
111 * this can be deallocated by simply calling free() | 230 * this can be deallocated by simply calling free() |
116 if(avctx==NULL) return NULL; | 235 if(avctx==NULL) return NULL; |
117 | 236 |
118 avcodec_get_context_defaults(avctx); | 237 avcodec_get_context_defaults(avctx); |
119 | 238 |
120 return avctx; | 239 return avctx; |
240 } | |
241 | |
242 /** | |
243 * allocates a AVPicture and set it to defaults. | |
244 * this can be deallocated by simply calling free() | |
245 */ | |
246 AVVideoFrame *avcodec_alloc_picture(void){ | |
247 AVVideoFrame *pic= av_mallocz(sizeof(AVVideoFrame)); | |
248 | |
249 return pic; | |
121 } | 250 } |
122 | 251 |
123 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) | 252 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
124 { | 253 { |
125 int ret; | 254 int ret; |
150 avctx->frame_number++; | 279 avctx->frame_number++; |
151 return ret; | 280 return ret; |
152 } | 281 } |
153 | 282 |
154 int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size, | 283 int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size, |
155 const AVPicture *pict) | 284 const AVVideoFrame *pict) |
156 { | 285 { |
157 int ret; | 286 int ret; |
158 | 287 |
159 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); | 288 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); |
160 | 289 |
165 } | 294 } |
166 | 295 |
167 /* decode a frame. return -1 if error, otherwise return the number of | 296 /* decode a frame. return -1 if error, otherwise return the number of |
168 bytes used. If no frame could be decompressed, *got_picture_ptr is | 297 bytes used. If no frame could be decompressed, *got_picture_ptr is |
169 zero. Otherwise, it is non zero */ | 298 zero. Otherwise, it is non zero */ |
170 int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture, | 299 int avcodec_decode_video(AVCodecContext *avctx, AVVideoFrame *picture, |
171 int *got_picture_ptr, | 300 int *got_picture_ptr, |
172 UINT8 *buf, int buf_size) | 301 UINT8 *buf, int buf_size) |
173 { | 302 { |
174 int ret; | 303 int ret; |
175 | 304 |
176 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | 305 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
177 buf, buf_size); | 306 buf, buf_size); |
178 | 307 |
179 emms_c(); //needed to avoid a emms_c() call before every return; | 308 emms_c(); //needed to avoid a emms_c() call before every return; |
180 | 309 |
181 if (*got_picture_ptr) | 310 if (*got_picture_ptr) |
182 avctx->frame_number++; | 311 avctx->frame_number++; |
183 return ret; | 312 return ret; |
184 } | 313 } |
185 | 314 |