73 |
|
|
74 |
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
75 |
|
|
76 |
if (dec->last_mbs) |
image_null(&dec->cur); |
77 |
|
image_null(&dec->refn[0]); |
78 |
|
image_null(&dec->refn[1]); |
79 |
|
image_null(&dec->tmp); |
80 |
|
image_null(&dec->qtmp); |
81 |
|
image_null(&dec->gmc); |
82 |
|
|
83 |
|
|
84 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
|
if (dec->mbs) |
|
85 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
|
if (dec->qscale) |
|
86 |
xvid_free(dec->qscale); |
xvid_free(dec->qscale); |
87 |
|
dec->last_mbs = NULL; |
88 |
|
dec->mbs = NULL; |
89 |
|
dec->qscale = NULL; |
90 |
|
|
91 |
/* realloc */ |
/* realloc */ |
92 |
dec->mb_width = (dec->width + 15) / 16; |
dec->mb_width = (dec->width + 15) / 16; |
95 |
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
96 |
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
97 |
|
|
98 |
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { |
if ( image_create(&dec->cur, dec->edged_width, dec->edged_height) |
99 |
xvid_free(dec); |
|| image_create(&dec->refn[0], dec->edged_width, dec->edged_height) |
100 |
return XVID_ERR_MEMORY; |
|| image_create(&dec->refn[1], dec->edged_width, dec->edged_height) /* Support B-frame to reference last 2 frame */ |
101 |
} |
|| image_create(&dec->tmp, dec->edged_width, dec->edged_height) |
102 |
|
|| image_create(&dec->qtmp, dec->edged_width, dec->edged_height) |
103 |
if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) { |
|| image_create(&dec->gmc, dec->edged_width, dec->edged_height) ) |
104 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
goto memory_error; |
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
|
/* Support B-frame to reference last 2 frame */ |
|
|
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
|
if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
|
if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
105 |
|
|
106 |
dec->mbs = |
dec->mbs = |
107 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
108 |
CACHE_LINE); |
CACHE_LINE); |
109 |
if (dec->mbs == NULL) { |
if (dec->mbs == NULL) |
110 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
goto memory_error; |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
111 |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
112 |
|
|
113 |
/* For skip MB flag */ |
/* For skip MB flag */ |
114 |
dec->last_mbs = |
dec->last_mbs = |
115 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
116 |
CACHE_LINE); |
CACHE_LINE); |
117 |
if (dec->last_mbs == NULL) { |
if (dec->last_mbs == NULL) |
118 |
xvid_free(dec->mbs); |
goto memory_error; |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
119 |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
120 |
|
|
121 |
/* nothing happens if that fails */ |
/* nothing happens if that fails */ |
126 |
memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height); |
memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height); |
127 |
|
|
128 |
return 0; |
return 0; |
129 |
|
|
130 |
|
memory_error: |
131 |
|
/* Most structures were deallocated / nullifieded, so it should be safe */ |
132 |
|
/* decoder_destroy(dec) minus the write_timer */ |
133 |
|
xvid_free(dec->mbs); |
134 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
135 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
136 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
137 |
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
138 |
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
139 |
|
|
140 |
|
xvid_free(dec); |
141 |
|
return XVID_ERR_MEMORY; |
142 |
} |
} |
143 |
|
|
144 |
|
|