You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2KB

  1. /*
  2. * AVFrame wrapper
  3. * Copyright (c) 2015 Luca Barbato
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Simple wrapper to store an AVFrame and forward it as AVPacket.
  24. */
  25. #include "avcodec.h"
  26. #include "internal.h"
  27. #include "libavutil/internal.h"
  28. #include "libavutil/frame.h"
  29. #include "libavutil/buffer.h"
  30. #include "libavutil/pixdesc.h"
  31. static void wrapped_avframe_release_buffer(void *unused, uint8_t *data)
  32. {
  33. AVFrame *frame = (AVFrame *)data;
  34. av_frame_free(&frame);
  35. }
  36. static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
  37. const AVFrame *frame, int *got_packet)
  38. {
  39. AVFrame *wrapped = av_frame_clone(frame);
  40. if (!wrapped)
  41. return AVERROR(ENOMEM);
  42. pkt->buf = av_buffer_create((uint8_t *)wrapped, sizeof(*wrapped),
  43. wrapped_avframe_release_buffer, NULL,
  44. AV_BUFFER_FLAG_READONLY);
  45. if (!pkt->buf) {
  46. av_frame_free(&wrapped);
  47. return AVERROR(ENOMEM);
  48. }
  49. pkt->data = (uint8_t *)wrapped;
  50. pkt->size = sizeof(*wrapped);
  51. pkt->flags |= AV_PKT_FLAG_KEY;
  52. *got_packet = 1;
  53. return 0;
  54. }
  55. AVCodec ff_wrapped_avframe_encoder = {
  56. .name = "wrapped_avframe",
  57. .long_name = NULL_IF_CONFIG_SMALL("AVFrame to AVPacket passthrough"),
  58. .type = AVMEDIA_TYPE_VIDEO,
  59. .id = AV_CODEC_ID_WRAPPED_AVFRAME,
  60. .encode2 = wrapped_avframe_encode,
  61. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  62. };