return ptr;
}
/* free all static arrays and reset pointers to 0 */
-void av_free_static()
+void av_free_static(void)
{
if (array_static)
{
format->next = NULL;
}
-typedef struct DefaultPicOpaque{
+typedef struct InternalBuffer{
int last_pic_num;
+ uint8_t *base[4];
uint8_t *data[4];
-}DefaultPicOpaque;
+}InternalBuffer;
+
+#define INTERNAL_BUFFER_SIZE 32
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
int i;
const int width = s->width;
const int height= s->height;
- DefaultPicOpaque *opaque;
+ InternalBuffer *buf;
assert(pic->data[0]==NULL);
- assert(pic->type==0 || pic->type==FF_BUFFER_TYPE_INTERNAL);
-
- if(pic->opaque){
- opaque= (DefaultPicOpaque *)pic->opaque;
- for(i=0; i<3; i++)
- pic->data[i]= opaque->data[i];
+ assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
-// printf("get_buffer %X coded_pic_num:%d last:%d\n", pic->opaque, pic->coded_picture_number, opaque->last_pic_num);
- pic->age= pic->coded_picture_number - opaque->last_pic_num;
- opaque->last_pic_num= pic->coded_picture_number;
-//printf("age: %d %d %d\n", pic->age, c->picture_number, pic->coded_picture_number);
+ if(s->internal_buffer==NULL){
+ s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
+ }
+#if 0
+ s->internal_buffer= av_fast_realloc(
+ s->internal_buffer,
+ &s->internal_buffer_size,
+ sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
+ );
+#endif
+
+ buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
+
+ if(buf->base[0]){
+ pic->age= pic->coded_picture_number - buf->last_pic_num;
+ buf->last_pic_num= pic->coded_picture_number;
}else{
int align, h_chroma_shift, v_chroma_shift;
int w, h, pixel_size;
avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
-
switch(s->pix_fmt){
+ case PIX_FMT_RGB555:
+ case PIX_FMT_RGB565:
case PIX_FMT_YUV422:
pixel_size=2;
break;
h+= EDGE_WIDTH*2;
}
- opaque= av_mallocz(sizeof(DefaultPicOpaque));
- if(opaque==NULL) return -1;
-
- pic->opaque= opaque;
- opaque->last_pic_num= -256*256*256*64;
+ buf->last_pic_num= -256*256*256*64;
for(i=0; i<3; i++){
const int h_shift= i==0 ? 0 : h_chroma_shift;
pic->linesize[i]= pixel_size*w>>h_shift;
- pic->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16
- if(pic->base[i]==NULL) return -1;
-
- memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift);
+ buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16
+ if(buf->base[i]==NULL) return -1;
+ memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift);
if(s->flags&CODEC_FLAG_EMU_EDGE)
- pic->data[i] = pic->base[i];
+ buf->data[i] = buf->base[i];
else
- pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift);
-
- opaque->data[i]= pic->data[i];
+ buf->data[i] = buf->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift);
}
pic->age= 256*256*256*64;
pic->type= FF_BUFFER_TYPE_INTERNAL;
}
+ for(i=0; i<4; i++){
+ pic->base[i]= buf->base[i];
+ pic->data[i]= buf->data[i];
+ }
+ s->internal_buffer_count++;
+
return 0;
}
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
int i;
-
+ InternalBuffer *buf, *last, temp;
+
assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
-
- for(i=0; i<3; i++)
+
+ for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
+ buf= &((InternalBuffer*)s->internal_buffer)[i];
+ if(buf->data[0] == pic->data[0])
+ break;
+ }
+ assert(i < s->internal_buffer_count);
+ s->internal_buffer_count--;
+ last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
+
+ temp= *buf;
+ *buf= *last;
+ *last= temp;
+
+ for(i=0; i<3; i++){
pic->data[i]=NULL;
+// pic->base[i]=NULL;
+ }
//printf("R%X\n", pic->opaque);
}
return ret;
}
-/* decode a frame. return -1 if error, otherwise return the number of
- bytes used. If no frame could be decompressed, *got_picture_ptr is
- zero. Otherwise, it is non zero */
+/**
+ * decode a frame.
+ * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
+ * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
+ * @param buf_size the size of the buffer in bytes
+ * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
+ * @return -1 if error, otherwise return the number of
+ * bytes used.
+ */
int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
int *got_picture_ptr,
uint8_t *buf, int buf_size)
return;
inited = 1;
- //dsputil_init();
+ dsputil_static_init();
}
/* this can be called after seeking and before trying to decode the next keyframe */
case CODEC_ID_MPEG1VIDEO:
case CODEC_ID_H263:
case CODEC_ID_RV10:
- case CODEC_ID_MJPEG:
- case CODEC_ID_MJPEGB:
+// case CODEC_ID_MJPEG:
+// case CODEC_ID_MJPEGB:
case CODEC_ID_MPEG4:
case CODEC_ID_MSMPEG4V1:
case CODEC_ID_MSMPEG4V2:
}
}
+void avcodec_default_free_buffers(AVCodecContext *s){
+ int i, j;
+
+ if(s->internal_buffer==NULL) return;
+
+ for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
+ InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
+ for(j=0; j<4; j++){
+ av_freep(&buf->base[j]);
+ buf->data[j]= NULL;
+ }
+ }
+ av_freep(&s->internal_buffer);
+
+ s->internal_buffer_count=0;
+}
+
+char av_get_pict_type_char(int pict_type){
+ switch(pict_type){
+ case I_TYPE: return 'I';
+ case P_TYPE: return 'P';
+ case B_TYPE: return 'B';
+ case S_TYPE: return 'S';
+ case SI_TYPE:return 'i';
+ case SP_TYPE:return 'p';
+ default: return '?';
+ }
+}
+
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
int exact=1, sign=0;
int64_t gcd, larger;