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.

129 lines
4.4KB

  1. /*
  2. * Copyright (c) 2008 Alexander Strange <astrange@ithinksw.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * Multithreading support functions
  23. * @author Alexander Strange <astrange@ithinksw.com>
  24. */
  25. #ifndef AVCODEC_THREAD_H
  26. #define AVCODEC_THREAD_H
  27. #include "libavutil/buffer.h"
  28. #include "config.h"
  29. #include "avcodec.h"
  30. typedef struct ThreadFrame {
  31. AVFrame *f;
  32. AVCodecContext *owner;
  33. // progress->data is an array of 2 ints holding progress for top/bottom
  34. // fields
  35. AVBufferRef *progress;
  36. } ThreadFrame;
  37. /**
  38. * Wait for decoding threads to finish and reset internal state.
  39. * Called by avcodec_flush_buffers().
  40. *
  41. * @param avctx The context.
  42. */
  43. void ff_thread_flush(AVCodecContext *avctx);
  44. /**
  45. * Submit a new frame to a decoding thread.
  46. * Returns the next available frame in picture. *got_picture_ptr
  47. * will be 0 if none is available.
  48. * The return value on success is the size of the consumed packet for
  49. * compatibility with avcodec_decode_video2(). This means the decoder
  50. * has to consume the full packet.
  51. *
  52. * Parameters are the same as avcodec_decode_video2().
  53. */
  54. int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
  55. int *got_picture_ptr, AVPacket *avpkt);
  56. /**
  57. * If the codec defines update_thread_context(), call this
  58. * when they are ready for the next thread to start decoding
  59. * the next frame. After calling it, do not change any variables
  60. * read by the update_thread_context() method, or call ff_thread_get_buffer().
  61. *
  62. * @param avctx The context.
  63. */
  64. void ff_thread_finish_setup(AVCodecContext *avctx);
  65. /**
  66. * Notify later decoding threads when part of their reference picture is ready.
  67. * Call this when some part of the picture is finished decoding.
  68. * Later calls with lower values of progress have no effect.
  69. *
  70. * @param f The picture being decoded.
  71. * @param progress Value, in arbitrary units, of how much of the picture has decoded.
  72. * @param field The field being decoded, for field-picture codecs.
  73. * 0 for top field or frame pictures, 1 for bottom field.
  74. */
  75. void ff_thread_report_progress(ThreadFrame *f, int progress, int field);
  76. /**
  77. * Wait for earlier decoding threads to finish reference pictures.
  78. * Call this before accessing some part of a picture, with a given
  79. * value for progress, and it will return after the responsible decoding
  80. * thread calls ff_thread_report_progress() with the same or
  81. * higher value for progress.
  82. *
  83. * @param f The picture being referenced.
  84. * @param progress Value, in arbitrary units, to wait for.
  85. * @param field The field being referenced, for field-picture codecs.
  86. * 0 for top field or frame pictures, 1 for bottom field.
  87. */
  88. void ff_thread_await_progress(ThreadFrame *f, int progress, int field);
  89. /**
  90. * Wrapper around get_buffer() for frame-multithreaded codecs.
  91. * Call this function instead of ff_get_buffer(f).
  92. * Cannot be called after the codec has called ff_thread_finish_setup().
  93. *
  94. * @param avctx The current context.
  95. * @param f The frame to write into.
  96. */
  97. int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags);
  98. /**
  99. * Wrapper around release_buffer() frame-for multithreaded codecs.
  100. * Call this function instead of avctx->release_buffer(f).
  101. * The AVFrame will be copied and the actual release_buffer() call
  102. * will be performed later. The contents of data pointed to by the
  103. * AVFrame should not be changed until ff_thread_get_buffer() is called
  104. * on it.
  105. *
  106. * @param avctx The current context.
  107. * @param f The picture being released.
  108. */
  109. void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f);
  110. int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src);
  111. int ff_thread_init(AVCodecContext *s);
  112. void ff_thread_free(AVCodecContext *s);
  113. #endif /* AVCODEC_THREAD_H */