| 174 | } |
| 175 | |
| 176 | AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type) |
| 177 | { |
| 178 | FFHWDeviceContext *ctxi; |
| 179 | AVHWDeviceContext *ctx; |
| 180 | AVBufferRef *buf; |
| 181 | const HWContextType *hw_type = NULL; |
| 182 | int i; |
| 183 | |
| 184 | for (i = 0; hw_table[i]; i++) { |
| 185 | if (hw_table[i]->type == type) { |
| 186 | hw_type = hw_table[i]; |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | if (!hw_type) |
| 191 | return NULL; |
| 192 | |
| 193 | ctxi = av_mallocz(sizeof(*ctxi)); |
| 194 | if (!ctxi) |
| 195 | return NULL; |
| 196 | ctx = &ctxi->p; |
| 197 | |
| 198 | if (hw_type->device_hwctx_size) { |
| 199 | ctx->hwctx = av_mallocz(hw_type->device_hwctx_size); |
| 200 | if (!ctx->hwctx) |
| 201 | goto fail; |
| 202 | } |
| 203 | |
| 204 | buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx), |
| 205 | hwdevice_ctx_free, NULL, |
| 206 | AV_BUFFER_FLAG_READONLY); |
| 207 | if (!buf) |
| 208 | goto fail; |
| 209 | |
| 210 | ctx->type = type; |
| 211 | ctx->av_class = &hwdevice_ctx_class; |
| 212 | |
| 213 | ctxi->hw_type = hw_type; |
| 214 | |
| 215 | return buf; |
| 216 | |
| 217 | fail: |
| 218 | av_freep(&ctx->hwctx); |
| 219 | av_freep(&ctx); |
| 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | int av_hwdevice_ctx_init(AVBufferRef *ref) |
| 224 | { |
no test coverage detected