從佇列中的AVPacket解碼出AVFrame的相關函式:
步驟一:AVPacket *avPacket = av_packet_alloc();
queue->getAvpacket(avPacket);
avcodec_send_packet(avCodecContext, avPacket);
步驟二:AVFrame *avFrame = av_frame_alloc();
avcodec_receive_frame(avCodecContext, avFrame);
在 video.cpp 檔案中的 void * playVideo(void *data) 方法中 while(video->playstatus != NULL && !video->playstatus->exit) 下撰寫
if (video->playstatus->seek) {
av_usleep(1000 * 100);
}
if (video->queue->getQueueSize() == 0) {
if (video->playstatus->load) {
video->playstatus->load = true;
video->wlCallJava->onCallLoad(CHILD_THREAD, true);
}
av_usleep(1000 * 100);
continue;
} else {
if (video->playstatus->load) {
video->playstatus->load = false;
video->wlCallJava->onCallLoad(CHILD_THREAD, false);
}
}
//宣告avPacket的記憶體空間
AVPacket *avPacket = av_packet_alloc();
if (video->queue->getAvpacket(avPacket) != 0) {
av_packet_free(&avPacket);
av_free(avPacket);
continue;
}
if (avcodec_send_packet(video->avCodecContext, avPacket) != 0) {
av_packet_free(&avPacket);
av_free(avPacket);
continue;
}
AVFrame *avFrame = av_frame_alloc();
if (avcodec_receive_frame(video->avCodecContext, avFrame) != 0) {
av_frame_free(&avFrame);
av_free(avFrame);
av_packet_free(&avPacket);
av_free(avPacket);
continue;
}
LOGE("子執行緒解碼一個avFrame成功");
av_frame_free(&avFrame);
av_free(avFrame);
av_packet_free(&avPacket);
av_free(avPacket);
*使用 av_usleep() 需要在 video.h 匯入頭檔案
extern "C"
{
/*...*/
#include <libavutil/time.h>
};
在 video.h 檔案中宣告 void release(); 方法用來釋放video的相關資源
主要釋放的資源有:
釋放佇列
delete(queue);
釋放解碼器背景關系
avcodec_close(avCodecContext);
avcodec_free_context(&avCodecContext);
在 video.cpp 檔案中實作該方法
void WlVideo::release() {
if (queue != NULL) {
delete (queue);
queue = NULL;
}
if (avCodecContext != NULL) {
avcodec_close(avCodecContext);
avcodec_free_context(&avCodecContext);
avCodecContext = NULL;
}
if (playstatus != NULL) {
playstatus = NULL;
}
if (wlCallJava != NULL) {
wlCallJava = NULL;
}
}
在 FFmpeg.cpp 檔案的 void WlFFmpeg::release() 方法下 呼叫釋放video資源的release方法
if(video != NULL)
{
video->release();
delete(video);
video = NULL;
}
*在使用 delete 關鍵字的時候需要注意被釋放的實體的類中需要存在解構式并且實作該解構式
在 video.h 下宣告解構式并實作
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/208921.html
標籤:其他
上一篇:Pr:音頻過渡效果
