yading@10: /* yading@10: * Copyright (c) 2008 Alexander Strange yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * Multithreading support functions yading@10: * @author Alexander Strange yading@10: */ yading@10: yading@10: #ifndef AVCODEC_THREAD_H yading@10: #define AVCODEC_THREAD_H yading@10: yading@10: #include "libavutil/buffer.h" yading@10: yading@10: #include "config.h" yading@10: #include "avcodec.h" yading@10: yading@10: typedef struct ThreadFrame { yading@10: AVFrame *f; yading@10: AVCodecContext *owner; yading@10: // progress->data is an array of 2 ints holding progress for top/bottom yading@10: // fields yading@10: AVBufferRef *progress; yading@10: } ThreadFrame; yading@10: yading@10: /** yading@10: * Wait for decoding threads to finish and reset internal state. yading@10: * Called by avcodec_flush_buffers(). yading@10: * yading@10: * @param avctx The context. yading@10: */ yading@10: void ff_thread_flush(AVCodecContext *avctx); yading@10: yading@10: /** yading@10: * Submit a new frame to a decoding thread. yading@10: * Returns the next available frame in picture. *got_picture_ptr yading@10: * will be 0 if none is available. yading@10: * The return value on success is the size of the consumed packet for yading@10: * compatibility with avcodec_decode_video2(). This means the decoder yading@10: * has to consume the full packet. yading@10: * yading@10: * Parameters are the same as avcodec_decode_video2(). yading@10: */ yading@10: int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, yading@10: int *got_picture_ptr, AVPacket *avpkt); yading@10: yading@10: /** yading@10: * If the codec defines update_thread_context(), call this yading@10: * when they are ready for the next thread to start decoding yading@10: * the next frame. After calling it, do not change any variables yading@10: * read by the update_thread_context() method, or call ff_thread_get_buffer(). yading@10: * yading@10: * @param avctx The context. yading@10: */ yading@10: void ff_thread_finish_setup(AVCodecContext *avctx); yading@10: yading@10: /** yading@10: * Notify later decoding threads when part of their reference picture is ready. yading@10: * Call this when some part of the picture is finished decoding. yading@10: * Later calls with lower values of progress have no effect. yading@10: * yading@10: * @param f The picture being decoded. yading@10: * @param progress Value, in arbitrary units, of how much of the picture has decoded. yading@10: * @param field The field being decoded, for field-picture codecs. yading@10: * 0 for top field or frame pictures, 1 for bottom field. yading@10: */ yading@10: void ff_thread_report_progress(ThreadFrame *f, int progress, int field); yading@10: yading@10: /** yading@10: * Wait for earlier decoding threads to finish reference pictures. yading@10: * Call this before accessing some part of a picture, with a given yading@10: * value for progress, and it will return after the responsible decoding yading@10: * thread calls ff_thread_report_progress() with the same or yading@10: * higher value for progress. yading@10: * yading@10: * @param f The picture being referenced. yading@10: * @param progress Value, in arbitrary units, to wait for. yading@10: * @param field The field being referenced, for field-picture codecs. yading@10: * 0 for top field or frame pictures, 1 for bottom field. yading@10: */ yading@10: void ff_thread_await_progress(ThreadFrame *f, int progress, int field); yading@10: yading@10: /** yading@10: * Wrapper around get_format() for frame-multithreaded codecs. yading@10: * Call this function instead of avctx->get_format(). yading@10: * Cannot be called after the codec has called ff_thread_finish_setup(). yading@10: * yading@10: * @param avctx The current context. yading@10: * @param fmt The list of available formats. yading@10: */ yading@10: enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt); yading@10: yading@10: /** yading@10: * Wrapper around get_buffer() for frame-multithreaded codecs. yading@10: * Call this function instead of ff_get_buffer(f). yading@10: * Cannot be called after the codec has called ff_thread_finish_setup(). yading@10: * yading@10: * @param avctx The current context. yading@10: * @param f The frame to write into. yading@10: */ yading@10: int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags); yading@10: yading@10: /** yading@10: * Wrapper around release_buffer() frame-for multithreaded codecs. yading@10: * Call this function instead of avctx->release_buffer(f). yading@10: * The AVFrame will be copied and the actual release_buffer() call yading@10: * will be performed later. The contents of data pointed to by the yading@10: * AVFrame should not be changed until ff_thread_get_buffer() is called yading@10: * on it. yading@10: * yading@10: * @param avctx The current context. yading@10: * @param f The picture being released. yading@10: */ yading@10: void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f); yading@10: yading@10: int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src); yading@10: yading@10: int ff_thread_init(AVCodecContext *s); yading@10: void ff_thread_free(AVCodecContext *s); yading@10: yading@10: #endif /* AVCODEC_THREAD_H */