Mercurial > libavcodec.hg
comparison indeo3.c @ 7950:9d2399045441 libavcodec
Check allocations on init.
author | benoit |
---|---|
date | Tue, 30 Sep 2008 09:54:13 +0000 |
parents | 0835de0148f8 |
children | f6c77b264d9b |
comparison
equal
deleted
inserted
replaced
7949:0835de0148f8 | 7950:9d2399045441 |
---|---|
60 128, 79, 79, 79, 79, 79, 79, 79 | 60 128, 79, 79, 79, 79, 79, 79, 79 |
61 }; | 61 }; |
62 | 62 |
63 static const uint8_t corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; | 63 static const uint8_t corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; |
64 | 64 |
65 static av_cold void build_modpred(Indeo3DecodeContext *s) | 65 static av_cold int build_modpred(Indeo3DecodeContext *s) |
66 { | 66 { |
67 int i, j; | 67 int i, j; |
68 | 68 |
69 s->ModPred = av_malloc(8 * 128); | 69 if (!(s->ModPred = av_malloc(8 * 128))) |
70 return AVERROR(ENOMEM); | |
70 | 71 |
71 for (i=0; i < 128; ++i) { | 72 for (i=0; i < 128; ++i) { |
72 s->ModPred[i+0*128] = i > 126 ? 254 : 2*(i + 1 - ((i + 1) % 2)); | 73 s->ModPred[i+0*128] = i > 126 ? 254 : 2*(i + 1 - ((i + 1) % 2)); |
73 s->ModPred[i+1*128] = i == 7 ? 20 : | 74 s->ModPred[i+1*128] = i == 7 ? 20 : |
74 i == 119 || | 75 i == 119 || |
79 s->ModPred[i+5*128] = 2*(i + 4 - ((i + 3) % 7)); | 80 s->ModPred[i+5*128] = 2*(i + 4 - ((i + 3) % 7)); |
80 s->ModPred[i+6*128] = i > 123 ? 240 : 2*(i + 4 - ((i + 4) % 8)); | 81 s->ModPred[i+6*128] = i > 123 ? 240 : 2*(i + 4 - ((i + 4) % 8)); |
81 s->ModPred[i+7*128] = 2*(i + 5 - ((i + 4) % 9)); | 82 s->ModPred[i+7*128] = 2*(i + 5 - ((i + 4) % 9)); |
82 } | 83 } |
83 | 84 |
84 s->corrector_type = av_malloc(24 * 256); | 85 if (!(s->corrector_type = av_malloc(24 * 256))) |
86 return AVERROR(ENOMEM); | |
85 | 87 |
86 for (i=0; i < 24; ++i) { | 88 for (i=0; i < 24; ++i) { |
87 for (j=0; j < 256; ++j) { | 89 for (j=0; j < 256; ++j) { |
88 s->corrector_type[i*256+j] = j < corrector_type_0[i] ? 1 : | 90 s->corrector_type[i*256+j] = j < corrector_type_0[i] ? 1 : |
89 j < 248 || (i == 16 && j == 248) ? 0 : | 91 j < 248 || (i == 16 && j == 248) ? 0 : |
90 corrector_type_2[j - 248]; | 92 corrector_type_2[j - 248]; |
91 } | 93 } |
92 } | 94 } |
95 | |
96 return 0; | |
93 } | 97 } |
94 | 98 |
95 static void iv_Decode_Chunk(Indeo3DecodeContext *s, uint8_t *cur, | 99 static void iv_Decode_Chunk(Indeo3DecodeContext *s, uint8_t *cur, |
96 uint8_t *ref, int width, int height, const uint8_t *buf1, | 100 uint8_t *ref, int width, int height, const uint8_t *buf1, |
97 long fflags2, const uint8_t *hdr, | 101 long fflags2, const uint8_t *hdr, |
98 const uint8_t *buf2, int min_width_160); | 102 const uint8_t *buf2, int min_width_160); |
99 | 103 |
100 /* ---------------------------------------------------------------------- */ | 104 /* ---------------------------------------------------------------------- */ |
101 static av_cold void iv_alloc_frames(Indeo3DecodeContext *s) | 105 static av_cold int iv_alloc_frames(Indeo3DecodeContext *s) |
102 { | 106 { |
103 int luma_width, luma_height, luma_pixels, chroma_width, chroma_height, | 107 int luma_width, luma_height, luma_pixels, chroma_width, chroma_height, |
104 chroma_pixels, i; | 108 chroma_pixels, i; |
105 unsigned int bufsize; | 109 unsigned int bufsize; |
106 | 110 |
120 | 124 |
121 bufsize = luma_pixels * 2 + luma_width * 3 + | 125 bufsize = luma_pixels * 2 + luma_width * 3 + |
122 (chroma_pixels + chroma_width) * 4; | 126 (chroma_pixels + chroma_width) * 4; |
123 | 127 |
124 if(!(s->iv_frame[0].the_buf = av_malloc(bufsize))) | 128 if(!(s->iv_frame[0].the_buf = av_malloc(bufsize))) |
125 return; | 129 return AVERROR(ENOMEM); |
126 s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width; | 130 s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width; |
127 s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height; | 131 s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height; |
128 s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width; | 132 s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width; |
129 s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height; | 133 s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height; |
130 s->iv_frame[0].the_buf_size = bufsize; | 134 s->iv_frame[0].the_buf_size = bufsize; |
149 s->iv_frame[1].Ubuf[-i] = 0x80; | 153 s->iv_frame[1].Ubuf[-i] = 0x80; |
150 s->iv_frame[0].Vbuf[-i] = 0x80; | 154 s->iv_frame[0].Vbuf[-i] = 0x80; |
151 s->iv_frame[1].Vbuf[-i] = 0x80; | 155 s->iv_frame[1].Vbuf[-i] = 0x80; |
152 s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80; | 156 s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80; |
153 } | 157 } |
158 | |
159 return 0; | |
154 } | 160 } |
155 | 161 |
156 /* ---------------------------------------------------------------------- */ | 162 /* ---------------------------------------------------------------------- */ |
157 static av_cold void iv_free_func(Indeo3DecodeContext *s) | 163 static av_cold void iv_free_func(Indeo3DecodeContext *s) |
158 { | 164 { |
1048 } | 1054 } |
1049 | 1055 |
1050 static av_cold int indeo3_decode_init(AVCodecContext *avctx) | 1056 static av_cold int indeo3_decode_init(AVCodecContext *avctx) |
1051 { | 1057 { |
1052 Indeo3DecodeContext *s = avctx->priv_data; | 1058 Indeo3DecodeContext *s = avctx->priv_data; |
1059 int ret = 0; | |
1053 | 1060 |
1054 s->avctx = avctx; | 1061 s->avctx = avctx; |
1055 s->width = avctx->width; | 1062 s->width = avctx->width; |
1056 s->height = avctx->height; | 1063 s->height = avctx->height; |
1057 avctx->pix_fmt = PIX_FMT_YUV410P; | 1064 avctx->pix_fmt = PIX_FMT_YUV410P; |
1058 | 1065 |
1059 build_modpred(s); | 1066 if (!(ret = build_modpred(s))) |
1060 iv_alloc_frames(s); | 1067 ret = iv_alloc_frames(s); |
1061 | 1068 if (ret) |
1062 return 0; | 1069 iv_free_func(s); |
1070 | |
1071 return ret; | |
1063 } | 1072 } |
1064 | 1073 |
1065 static int indeo3_decode_frame(AVCodecContext *avctx, | 1074 static int indeo3_decode_frame(AVCodecContext *avctx, |
1066 void *data, int *data_size, | 1075 void *data, int *data_size, |
1067 const uint8_t *buf, int buf_size) | 1076 const uint8_t *buf, int buf_size) |