| 37 | } |
| 38 | |
| 39 | static int libwebp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 40 | const AVFrame *frame, int *got_packet) |
| 41 | { |
| 42 | LibWebPContext *s = avctx->priv_data; |
| 43 | WebPPicture *pic = NULL; |
| 44 | AVFrame *alt_frame = NULL; |
| 45 | WebPMemoryWriter mw = { 0 }; |
| 46 | |
| 47 | int ret = ff_libwebp_get_frame(avctx, s, frame, &alt_frame, &pic); |
| 48 | if (ret < 0) |
| 49 | goto end; |
| 50 | |
| 51 | WebPMemoryWriterInit(&mw); |
| 52 | pic->custom_ptr = &mw; |
| 53 | pic->writer = WebPMemoryWrite; |
| 54 | |
| 55 | ret = WebPEncode(&s->config, pic); |
| 56 | if (!ret) { |
| 57 | av_log(avctx, AV_LOG_ERROR, "WebPEncode() failed with error: %d\n", |
| 58 | pic->error_code); |
| 59 | ret = ff_libwebp_error_to_averror(pic->error_code); |
| 60 | goto end; |
| 61 | } |
| 62 | |
| 63 | ret = ff_get_encode_buffer(avctx, pkt, mw.size, 0); |
| 64 | if (ret < 0) |
| 65 | goto end; |
| 66 | memcpy(pkt->data, mw.mem, mw.size); |
| 67 | |
| 68 | *got_packet = 1; |
| 69 | |
| 70 | end: |
| 71 | #if (WEBP_ENCODER_ABI_VERSION > 0x0203) |
| 72 | WebPMemoryWriterClear(&mw); |
| 73 | #else |
| 74 | free(mw.mem); /* must use free() according to libwebp documentation */ |
| 75 | #endif |
| 76 | WebPPictureFree(pic); |
| 77 | av_freep(&pic); |
| 78 | av_frame_free(&alt_frame); |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | static int libwebp_encode_close(AVCodecContext *avctx) |
| 84 | { |
nothing calls this directly
no test coverage detected