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.

118 lines
4.1KB

  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 "config.h"
  28. #include "avcodec.h"
  29. /**
  30. * Waits for decoding threads to finish and resets internal
  31. * state. Called by avcodec_flush_buffers().
  32. *
  33. * @param avctx The context.
  34. */
  35. void ff_thread_flush(AVCodecContext *avctx);
  36. /**
  37. * Submits a new frame to a decoding thread.
  38. * Returns the next available frame in picture. *got_picture_ptr
  39. * will be 0 if none is available.
  40. * The return value on success is the size of the consumed packet for
  41. * compatiblity with avcodec_decode_video2(). This means the decoder
  42. * has to consume the full packet.
  43. *
  44. * Parameters are the same as avcodec_decode_video2().
  45. */
  46. int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
  47. int *got_picture_ptr, AVPacket *avpkt);
  48. /**
  49. * If the codec defines update_thread_context(), call this
  50. * when they are ready for the next thread to start decoding
  51. * the next frame. After calling it, do not change any variables
  52. * read by the update_thread_context() method, or call ff_thread_get_buffer().
  53. *
  54. * @param avctx The context.
  55. */
  56. void ff_thread_finish_setup(AVCodecContext *avctx);
  57. /**
  58. * Notifies later decoding threads when part of their reference picture
  59. * is ready.
  60. * Call this when some part of the picture is finished decoding.
  61. * Later calls with lower values of progress have no effect.
  62. *
  63. * @param f The picture being decoded.
  64. * @param progress Value, in arbitrary units, of how much of the picture has decoded.
  65. * @param field The field being decoded, for field-picture codecs.
  66. * 0 for top field or frame pictures, 1 for bottom field.
  67. */
  68. void ff_thread_report_progress(AVFrame *f, int progress, int field);
  69. /**
  70. * Waits for earlier decoding threads to finish reference pictures
  71. * Call this before accessing some part of a picture, with a given
  72. * value for progress, and it will return after the responsible decoding
  73. * thread calls ff_thread_report_progress() with the same or
  74. * higher value for progress.
  75. *
  76. * @param f The picture being referenced.
  77. * @param progress Value, in arbitrary units, to wait for.
  78. * @param field The field being referenced, for field-picture codecs.
  79. * 0 for top field or frame pictures, 1 for bottom field.
  80. */
  81. void ff_thread_await_progress(AVFrame *f, int progress, int field);
  82. /**
  83. * Wrapper around get_buffer() for frame-multithreaded codecs.
  84. * Call this function instead of avctx->get_buffer(f).
  85. * Cannot be called after the codec has called ff_thread_finish_setup().
  86. *
  87. * @param avctx The current context.
  88. * @param f The frame to write into.
  89. */
  90. int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f);
  91. /**
  92. * Wrapper around release_buffer() frame-for multithreaded codecs.
  93. * Call this function instead of avctx->release_buffer(f).
  94. * The AVFrame will be copied and the actual release_buffer() call
  95. * will be performed later. The contents of data pointed to by the
  96. * AVFrame should not be changed until ff_thread_get_buffer() is called
  97. * on it.
  98. *
  99. * @param avctx The current context.
  100. * @param f The picture being released.
  101. */
  102. void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f);
  103. int ff_thread_init(AVCodecContext *s);
  104. void ff_thread_free(AVCodecContext *s);
  105. #endif /* AVCODEC_THREAD_H */