|
@@ -41,7 +41,7 @@ static int video_decode_frame(AVCodecContext *p_codec_ctx, packet_queue_t *p_pkt
|
|
|
|
|
|
while (0 == p_pkt_queue->abort_flag)
|
|
|
{
|
|
|
- AVPacket pkt;
|
|
|
+ AVPacket pkt = {0};
|
|
|
av_init_packet(&pkt);
|
|
|
while (0 == p_pkt_queue->abort_flag)
|
|
|
{
|
|
@@ -63,7 +63,6 @@ static int video_decode_frame(AVCodecContext *p_codec_ctx, packet_queue_t *p_pkt
|
|
|
else if (ret == AVERROR(EAGAIN))
|
|
|
{
|
|
|
//hostapi->Debug(MEDIA_LOG_DEBUG,"video avcodec_receive_frame(): output is not available in this state - " "user must try to send new input");
|
|
|
- av_usleep(2);
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
@@ -95,8 +94,7 @@ static int video_decode_frame(AVCodecContext *p_codec_ctx, packet_queue_t *p_pkt
|
|
|
// pkt.pos变量可以标识当前packet在视频文件中的地址偏移
|
|
|
int isend_ret = -1;
|
|
|
isend_ret = avcodec_send_packet(p_codec_ctx, &pkt);
|
|
|
- av_usleep(2);
|
|
|
- //hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d after avcodec_send_packet.", __FUNCTION__, __LINE__);
|
|
|
+
|
|
|
if (0 != isend_ret){
|
|
|
if (AVERROR(EAGAIN) == isend_ret) {
|
|
|
hostapi->Debug(MEDIA_LOG_DEBUG, "receive_frame and send_packet both returned EAGAIN, which is an API violation.");
|
|
@@ -383,7 +381,7 @@ static int open_video_playing(void* arg)
|
|
|
for (size_t index = 0; index < is->uFilesCount; index++) {
|
|
|
is->p_frm_yuv[index] = av_frame_alloc();
|
|
|
if (is->p_frm_yuv[index] == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_frame_alloc() for p_frm_raw failed");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "av_frame_alloc() for p_frm_raw failed");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -403,7 +401,7 @@ static int open_video_playing(void* arg)
|
|
|
// buffer将作为p_frm_yuv的视频数据缓冲区
|
|
|
buffer = (uint8_t*)av_malloc(buf_size);
|
|
|
if (buffer == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_malloc() for buffer failed!");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "av_malloc() for buffer failed!");
|
|
|
return -1;
|
|
|
}
|
|
|
is->p_video_buffer[index] = buffer;
|
|
@@ -418,7 +416,7 @@ static int open_video_playing(void* arg)
|
|
|
);
|
|
|
|
|
|
if (ret < 0) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_image_fill_arrays() failed %d", ret);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "av_image_fill_arrays() failed %d", ret);
|
|
|
return -1;;
|
|
|
}
|
|
|
|
|
@@ -441,11 +439,11 @@ static int open_video_playing(void* arg)
|
|
|
);
|
|
|
|
|
|
if (is->img_convert_ctx[index] == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "sws_getContext() failed");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "sws_getContext() failed");
|
|
|
return -1;
|
|
|
}
|
|
|
else {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d is->img_convert_ctx[%d] = 0x%0x", __FUNCTION__, __LINE__, index, is->img_convert_ctx[index]);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d is->img_convert_ctx[%d] = 0x%08x", __FUNCTION__, __LINE__, index, is->img_convert_ctx[index]);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -473,7 +471,7 @@ static int open_video_playing(void* arg)
|
|
|
);
|
|
|
|
|
|
if (is->sdl_video.window == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateWindow() failed: %s.", SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_CreateWindow() failed: %s.", SDL_GetError());
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -488,7 +486,7 @@ static int open_video_playing(void* arg)
|
|
|
if (NULL != is->piconpath) {
|
|
|
IconSurface = SDL_LoadBMP(is->piconpath);
|
|
|
if (NULL == IconSurface) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_LoadBMP(%s) failed: %s", is->piconpath, SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_LoadBMP(%s) failed: %s", is->piconpath, SDL_GetError());
|
|
|
}
|
|
|
else {
|
|
|
SDL_SetWindowIcon(is->sdl_video.window, IconSurface);
|
|
@@ -501,7 +499,7 @@ static int open_video_playing(void* arg)
|
|
|
is->sdl_video.renderer = SDL_CreateRenderer(is->sdl_video.window, -1, 0);
|
|
|
if (is->sdl_video.renderer == NULL)
|
|
|
{
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateRenderer() failed: %s", SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_CreateRenderer() failed: %s", SDL_GetError());
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -516,13 +514,13 @@ static int open_video_playing(void* arg)
|
|
|
|
|
|
if (is->sdl_video.texture == NULL)
|
|
|
{
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateTexture() failed: %s", SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_CreateTexture() failed: %s", SDL_GetError());
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
is->video_playing_tid = SDL_CreateThread(video_playing_thread, "video playing thread", is);
|
|
|
if (NULL == is->video_playing_tid) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_Create video playing thread failed: %s.", SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_Create video playing thread failed: %s.", SDL_GetError());
|
|
|
return -1;
|
|
|
}
|
|
|
else {
|
|
@@ -550,7 +548,7 @@ static int open_video_stream(player_stat_t *is)
|
|
|
// 1.2 获取解码器
|
|
|
p_codec = avcodec_find_decoder(p_codec_par->codec_id);
|
|
|
if (p_codec == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "Cann't find codec!");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "Cann't find codec!");
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -558,29 +556,28 @@ static int open_video_stream(player_stat_t *is)
|
|
|
// 1.3.1 p_codec_ctx初始化:分配结构体,使用p_codec初始化相应成员为默认值
|
|
|
p_codec_ctx = avcodec_alloc_context3(p_codec);
|
|
|
if (p_codec_ctx == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_alloc_context3() failed");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_alloc_context3() failed");
|
|
|
return ret;
|
|
|
}
|
|
|
// 1.3.2 p_codec_ctx初始化:p_codec_par ==> p_codec_ctx,初始化相应成员
|
|
|
ret = avcodec_parameters_to_context(p_codec_ctx, p_codec_par);
|
|
|
if (ret < 0) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_parameters_to_context() failed");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_parameters_to_context() failed");
|
|
|
return ret;
|
|
|
}
|
|
|
// 1.3.3 p_codec_ctx初始化:使用p_codec初始化p_codec_ctx,初始化完成
|
|
|
ret = avcodec_open2(p_codec_ctx, p_codec, NULL);
|
|
|
if (ret < 0) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_open2() failed %d", ret);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_open2() failed %d", ret);
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
is->p_vcodec_ctx[index] = p_codec_ctx;
|
|
|
}
|
|
|
|
|
|
// 2. 创建视频解码线程
|
|
|
is->video_decode_tid = SDL_CreateThread(video_decode_thread, "video decode thread", is);
|
|
|
if (NULL == is->video_decode_tid) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_Create video decode thread failed: %s.", SDL_GetError());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_Create video decode thread failed: %s.", SDL_GetError());
|
|
|
return -1;
|
|
|
}
|
|
|
else {
|