//帧级解码函数,在avcodec_open2的时候,就会判断片还是帧解码,分析见下一篇
int ff_thread_decode_frame(AVCodecContext *avctx,
AVFrame *picture, int *got_picture_ptr, * Submit a packet to the next decoding thread.
*提交数据包发送到下一个解码线程
* If we're still receiving the initial packets, don't return a frame.
*如果我们仍然接收的初步数据包,不返回帧
*/
注释:
1.
/**
* thread opaque
* Can be used by execute() to store some per AVCodecContext stuff.
//能够使用execute()函数来存储每个AVCodecContext数据
* - encoding: set by execute()
* - decoding: set by execute()
*/
void *thread_opaque;
2.
/**
* Context used by codec threads and stored in their AVCodecContext thread_opaque.
*上下文所使用的编解码器线程和存储在他们的AVCodecContext thread_opaque
*/
typedef struct PerThreadContext {
struct FrameThreadContext *parent;
pthread_t thread;
int thread_init;
pthread_cond_t input_cond; ///< Used to wait for a new packet from the main thread.从主线程等待一个新的数据包。
pthread_cond_t progress_cond; ///< Used by child threads to wait for progress to change.
pthread_cond_t output_cond; ///< Used by the main thread to wait for frames to finish.用于由主线程等待帧来完成
pthread_mutex_t mutex; ///< Mutex used to protect the contents of the PerThreadContext.
pthread_mutex_t progress_mutex; ///< Mutex used to protect frame progress values and progress_cond.
AVCodecContext *avctx; ///< Context used to decode packets passed to this thread.
AVPacket avpkt; ///< Input packet (for decoding) or output (for encoding).
uint8_t *buf; ///< backup storage for packet data when the input packet is not refcounted
int allocated_buf_size; ///< Size allocated for buf
AVFrame frame; ///< Output frame (for decoding) or input (for encoding).
int got_frame; ///< The output of got_picture_ptr from the last avcodec_decode_video() call.
int result; ///< The result of the last codec decode/encode() call.
enum { //这个可以看之前文章中提到的帧级解码状态图
STATE_INPUT_READY, ///< Set when the thread is awaiting a packet.
STATE_SETTING_UP, ///< Set before the codec has called ff_thread_finish_setup().
STATE_GET_BUFFER, /**<
* Set when the codec calls get_buffer().
* State is returned to STATE_SETTING_UP afterwards.
*/
STATE_SETUP_FINISHED ///< Set after the codec has called ff_thread_finish_setup().
} state;
/**
* Array of frames passed to ff_thread_release_buffer().
* Frames are released after all threads referencing them are finished.
*/
AVFrame *released_buffers;
int num_released_buffers;
int released_buffers_allocated;
AVFrame *requested_frame; ///< AVFrame the codec passed to get_buffer()
int requested_flags; ///< flags passed to get_buffer() for requested_frame
} PerThreadContext;