summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/utils.c')
-rw-r--r--src/libffmpeg/libavcodec/utils.c180
1 files changed, 38 insertions, 142 deletions
diff --git a/src/libffmpeg/libavcodec/utils.c b/src/libffmpeg/libavcodec/utils.c
index af6ba986b..ca71807f7 100644
--- a/src/libffmpeg/libavcodec/utils.c
+++ b/src/libffmpeg/libavcodec/utils.c
@@ -24,8 +24,6 @@ void *av_mallocz(unsigned int size)
{
void *ptr;
- if(size == 0) fprintf(stderr, "Warning, allocating 0 bytes\n");
-
ptr = av_malloc(size);
if (!ptr)
return NULL;
@@ -33,6 +31,32 @@ void *av_mallocz(unsigned int size)
return ptr;
}
+char *av_strdup(const char *s)
+{
+ char *ptr;
+ int len;
+ len = strlen(s) + 1;
+ ptr = av_malloc(len);
+ if (!ptr)
+ return NULL;
+ memcpy(ptr, s, len);
+ return ptr;
+}
+
+/**
+ * realloc which does nothing if the block is large enough
+ */
+void *av_fast_realloc(void *ptr, int *size, int min_size)
+{
+ if(min_size < *size)
+ return ptr;
+
+ *size= min_size + 10*1024;
+
+ return av_realloc(ptr, *size);
+}
+
+
/* allocation of static arrays - do not use for normal allocation */
static unsigned int last_static = 0;
static char*** array_static = NULL;
@@ -47,7 +71,7 @@ void *__av_mallocz_static(void** location, unsigned int size)
if (location)
{
if (l > last_static)
- array_static = realloc(array_static, l);
+ array_static = av_realloc(array_static, l);
array_static[last_static++] = (char**) location;
*location = ptr;
}
@@ -61,10 +85,10 @@ void av_free_static()
unsigned i;
for (i = 0; i < last_static; i++)
{
- free(*array_static[i]);
+ av_free(*array_static[i]);
*array_static[i] = NULL;
}
- free(array_static);
+ av_free(array_static);
array_static = 0;
}
last_static = 0;
@@ -89,32 +113,6 @@ void register_avcodec(AVCodec *format)
format->next = NULL;
}
-void avcodec_get_chroma_sub_sample(int fmt, int *h_shift, int *v_shift){
- switch(fmt){
- case PIX_FMT_YUV410P:
- *h_shift=2;
- *v_shift=2;
- break;
- case PIX_FMT_YUV420P:
- *h_shift=1;
- *v_shift=1;
- break;
- case PIX_FMT_YUV411P:
- *h_shift=2;
- *v_shift=0;
- break;
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV422:
- *h_shift=1;
- *v_shift=0;
- break;
- default: //RGB/...
- *h_shift=0;
- *v_shift=0;
- break;
- }
-}
-
typedef struct DefaultPicOpaque{
int last_pic_num;
uint8_t *data[4];
@@ -125,10 +123,10 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
const int width = s->width;
const int height= s->height;
DefaultPicOpaque *opaque;
-
+/*
assert(pic->data[0]==NULL);
- /* assert(pic->type==0 || pic->type==FF_TYPE_INTERNAL); */
-
+ assert(pic->type==0 || pic->type==FF_TYPE_INTERNAL);
+*/
if(pic->opaque){
opaque= (DefaultPicOpaque *)pic->opaque;
for(i=0; i<3; i++)
@@ -152,7 +150,6 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
case PIX_FMT_BGR24:
pixel_size=3;
break;
- case PIX_FMT_BGRA32:
case PIX_FMT_RGBA32:
pixel_size=4;
break;
@@ -212,6 +209,10 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
//printf("R%X\n", pic->opaque);
}
+enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){
+ return fmt[0];
+}
+
void avcodec_get_context_defaults(AVCodecContext *s){
s->bit_rate= 800*1000;
s->bit_rate_tolerance= s->bit_rate*10;
@@ -234,6 +235,7 @@ void avcodec_get_context_defaults(AVCodecContext *s){
s->me_method= ME_EPZS;
s->get_buffer= avcodec_default_get_buffer;
s->release_buffer= avcodec_default_release_buffer;
+ s->get_format= avcodec_default_get_format;
s->me_subpel_quality=8;
}
@@ -410,19 +412,6 @@ AVCodec *avcodec_find(enum CodecID id)
return NULL;
}
-const char *pix_fmt_str[] = {
- "yuv420p",
- "yuv422",
- "rgb24",
- "bgr24",
- "yuv422p",
- "yuv444p",
- "rgba32",
- "bgra32",
- "yuv410p",
- "yuv411p",
-};
-
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
{
const char *codec_name;
@@ -462,7 +451,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
if (enc->codec_id == CODEC_ID_RAWVIDEO) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %s",
- pix_fmt_str[enc->pix_fmt]);
+ avcodec_get_pix_fmt_name(enc->pix_fmt));
}
if (enc->width) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
@@ -537,99 +526,6 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
}
}
-/* Picture field are filled with 'ptr' addresses */
-void avpicture_fill(AVPicture *picture, UINT8 *ptr,
- int pix_fmt, int width, int height)
-{
- int size;
-
- size = width * height;
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size / 4;
- picture->linesize[0] = width;
- picture->linesize[1] = width / 2;
- picture->linesize[2] = width / 2;
- break;
- case PIX_FMT_YUV422P:
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size / 2;
- picture->linesize[0] = width;
- picture->linesize[1] = width / 2;
- picture->linesize[2] = width / 2;
- break;
- case PIX_FMT_YUV444P:
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size;
- picture->linesize[0] = width;
- picture->linesize[1] = width;
- picture->linesize[2] = width;
- break;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 3;
- break;
- case PIX_FMT_RGBA32:
- case PIX_FMT_BGRA32:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 4;
- break;
- case PIX_FMT_YUV422:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 2;
- break;
- default:
- picture->data[0] = NULL;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- break;
- }
-}
-
-int avpicture_get_size(int pix_fmt, int width, int height)
-{
- int size;
-
- size = width * height;
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- size = (size * 3) / 2;
- break;
- case PIX_FMT_YUV422P:
- size = (size * 2);
- break;
- case PIX_FMT_YUV444P:
- size = (size * 3);
- break;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- size = (size * 3);
- break;
- case PIX_FMT_RGBA32:
- case PIX_FMT_BGRA32:
- size = (size * 4);
- break;
- case PIX_FMT_YUV422:
- size = (size * 2);
- break;
- default:
- size = -1;
- break;
- }
- return size;
-}
-
unsigned avcodec_version( void )
{
return LIBAVCODEC_VERSION_INT;