comparison flashsvenc.c @ 4992:52d8e61c0280 libavcodec

Added support for instances where linesize[0] is negative. Based on patch by Jason Askew, jason dot askew at gmail dot com.
author banan
date Sat, 12 May 2007 19:37:26 +0000
parents f99e40a7155b
children c9b17d87df0a
comparison
equal deleted inserted replaced
4991:b77f43ff3991 4992:52d8e61c0280
232 static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) 232 static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
233 { 233 {
234 FlashSVContext * const s = avctx->priv_data; 234 FlashSVContext * const s = avctx->priv_data;
235 AVFrame *pict = data; 235 AVFrame *pict = data;
236 AVFrame * const p = &s->frame; 236 AVFrame * const p = &s->frame;
237 uint8_t *pfptr;
237 int res; 238 int res;
238 int I_frame = 0; 239 int I_frame = 0;
239 int opt_w, opt_h; 240 int opt_w, opt_h;
240 241
241 *p = *pict; 242 *p = *pict;
242 243
243 /* First frame needs to be a keyframe */ 244 /* First frame needs to be a keyframe */
244 if (avctx->frame_number == 0) { 245 if (avctx->frame_number == 0) {
245 s->previous_frame = av_mallocz(p->linesize[0]*s->image_height); 246 s->previous_frame = av_mallocz(abs(p->linesize[0])*s->image_height);
246 if (!s->previous_frame) { 247 if (!s->previous_frame) {
247 av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); 248 av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
248 return -1; 249 return -1;
249 } 250 }
250 I_frame = 1; 251 I_frame = 1;
251 } 252 }
253
254 if (p->linesize[0] < 0)
255 pfptr = s->previous_frame - ((s->image_height-1) * p->linesize[0]);
256 else
257 pfptr = s->previous_frame;
252 258
253 /* Check the placement of keyframes */ 259 /* Check the placement of keyframes */
254 if (avctx->gop_size > 0) { 260 if (avctx->gop_size > 0) {
255 if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) { 261 if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
256 I_frame = 1; 262 I_frame = 1;
296 //Conservative upper bound check for compressed data 302 //Conservative upper bound check for compressed data
297 av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->image_width*s->image_height*3); 303 av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->image_width*s->image_height*3);
298 return -1; 304 return -1;
299 } 305 }
300 306
301 res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, s->previous_frame, &I_frame); 307 res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, pfptr, &I_frame);
302 #endif 308 #endif
303 //save the current frame 309 //save the current frame
304 memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]); 310 if(p->linesize[0] > 0)
311 memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]);
312 else
313 memcpy(s->previous_frame, p->data[0] + p->linesize[0] * (s->image_height-1), s->image_height*abs(p->linesize[0]));
305 314
306 //mark the frame type so the muxer can mux it correctly 315 //mark the frame type so the muxer can mux it correctly
307 if (I_frame) { 316 if (I_frame) {
308 p->pict_type = FF_I_TYPE; 317 p->pict_type = FF_I_TYPE;
309 p->key_frame = 1; 318 p->key_frame = 1;