Lines Matching refs:ffmpeg_ctx

77 static void ffmpeg_close(struct ffmpeg_context_s * ffmpeg_ctx);
78 static void ffmpeg_close_src_ctx(struct ffmpeg_context_s * ffmpeg_ctx);
79 static void ffmpeg_close_dst_ctx(struct ffmpeg_context_s * ffmpeg_ctx);
80 static int ffmpeg_image_allocate(struct ffmpeg_context_s * ffmpeg_ctx);
82 static int ffmpeg_get_frame_refr_period(struct ffmpeg_context_s * ffmpeg_ctx);
83 static uint8_t * ffmpeg_get_img_data(struct ffmpeg_context_s * ffmpeg_ctx);
84 static int ffmpeg_update_next_frame(struct ffmpeg_context_s * ffmpeg_ctx);
85 static int ffmpeg_output_video_frame(struct ffmpeg_context_s * ffmpeg_ctx);
129 struct ffmpeg_context_s * ffmpeg_ctx = ffmpeg_open_file(path); in lv_ffmpeg_get_frame_num() local
131 if(ffmpeg_ctx) { in lv_ffmpeg_get_frame_num()
132 ret = ffmpeg_ctx->video_stream->nb_frames; in lv_ffmpeg_get_frame_num()
133 ffmpeg_close(ffmpeg_ctx); in lv_ffmpeg_get_frame_num()
153 if(player->ffmpeg_ctx) { in lv_ffmpeg_player_set_src()
154 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
155 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_set_src()
160 player->ffmpeg_ctx = ffmpeg_open_file(path); in lv_ffmpeg_player_set_src()
162 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_set_src()
167 if(ffmpeg_image_allocate(player->ffmpeg_ctx) < 0) { in lv_ffmpeg_player_set_src()
169 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
173 bool has_alpha = player->ffmpeg_ctx->has_alpha; in lv_ffmpeg_player_set_src()
174 int width = player->ffmpeg_ctx->video_dec_ctx->width; in lv_ffmpeg_player_set_src()
175 int height = player->ffmpeg_ctx->video_dec_ctx->height; in lv_ffmpeg_player_set_src()
190 player->imgdsc.data = ffmpeg_get_img_data(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
194 int period = ffmpeg_get_frame_refr_period(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
216 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_set_cmd()
225 av_seek_frame(player->ffmpeg_ctx->fmt_ctx, in lv_ffmpeg_player_set_cmd()
231 av_seek_frame(player->ffmpeg_ctx->fmt_ctx, in lv_ffmpeg_player_set_cmd()
286 struct ffmpeg_context_s * ffmpeg_ctx = ffmpeg_open_file(path); in decoder_open() local
288 if(ffmpeg_ctx == NULL) { in decoder_open()
292 if(ffmpeg_image_allocate(ffmpeg_ctx) < 0) { in decoder_open()
294 ffmpeg_close(ffmpeg_ctx); in decoder_open()
298 if(ffmpeg_update_next_frame(ffmpeg_ctx) < 0) { in decoder_open()
299 ffmpeg_close(ffmpeg_ctx); in decoder_open()
304 ffmpeg_close_src_ctx(ffmpeg_ctx); in decoder_open()
305 uint8_t * img_data = ffmpeg_get_img_data(ffmpeg_ctx); in decoder_open()
308 if(ffmpeg_ctx->has_alpha) { in decoder_open()
313 dsc->user_data = ffmpeg_ctx; in decoder_open()
326 struct ffmpeg_context_s * ffmpeg_ctx = dsc->user_data; in decoder_close() local
327 ffmpeg_close(ffmpeg_ctx); in decoder_close()
349 static uint8_t * ffmpeg_get_img_data(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_get_img_data() argument
351 uint8_t * img_data = ffmpeg_ctx->video_dst_data[0]; in ffmpeg_get_img_data()
386 static int ffmpeg_output_video_frame(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_output_video_frame() argument
390 int width = ffmpeg_ctx->video_dec_ctx->width; in ffmpeg_output_video_frame()
391 int height = ffmpeg_ctx->video_dec_ctx->height; in ffmpeg_output_video_frame()
392 AVFrame * frame = ffmpeg_ctx->frame; in ffmpeg_output_video_frame()
396 || frame->format != ffmpeg_ctx->video_dec_ctx->pix_fmt) { in ffmpeg_output_video_frame()
408 av_get_pix_fmt_name(ffmpeg_ctx->video_dec_ctx->pix_fmt), in ffmpeg_output_video_frame()
419 av_image_copy(ffmpeg_ctx->video_src_data, ffmpeg_ctx->video_src_linesize, in ffmpeg_output_video_frame()
421 ffmpeg_ctx->video_dec_ctx->pix_fmt, width, height); in ffmpeg_output_video_frame()
423 if(ffmpeg_ctx->sws_ctx == NULL) { in ffmpeg_output_video_frame()
426 if(ffmpeg_pix_fmt_is_yuv(ffmpeg_ctx->video_dec_ctx->pix_fmt)) { in ffmpeg_output_video_frame()
444 ffmpeg_ctx->sws_ctx = sws_getContext( in ffmpeg_output_video_frame()
445 width, height, ffmpeg_ctx->video_dec_ctx->pix_fmt, in ffmpeg_output_video_frame()
446 width, height, ffmpeg_ctx->video_dst_pix_fmt, in ffmpeg_output_video_frame()
451 if(!ffmpeg_ctx->has_alpha) { in ffmpeg_output_video_frame()
453 int dst_linesize = ffmpeg_ctx->video_dst_linesize[0]; in ffmpeg_output_video_frame()
458 ffmpeg_ctx->video_dst_linesize[0] = lv_linesize; in ffmpeg_output_video_frame()
463 ffmpeg_ctx->sws_ctx, in ffmpeg_output_video_frame()
464 (const uint8_t * const *)(ffmpeg_ctx->video_src_data), in ffmpeg_output_video_frame()
465 ffmpeg_ctx->video_src_linesize, in ffmpeg_output_video_frame()
468 ffmpeg_ctx->video_dst_data, in ffmpeg_output_video_frame()
469 ffmpeg_ctx->video_dst_linesize); in ffmpeg_output_video_frame()
476 struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_decode_packet() argument
490 ret = avcodec_receive_frame(dec, ffmpeg_ctx->frame); in ffmpeg_decode_packet()
507 ret = ffmpeg_output_video_frame(ffmpeg_ctx); in ffmpeg_decode_packet()
510 av_frame_unref(ffmpeg_ctx->frame); in ffmpeg_decode_packet()
619 static int ffmpeg_get_frame_refr_period(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_get_frame_refr_period() argument
621 int avg_frame_rate_num = ffmpeg_ctx->video_stream->avg_frame_rate.num; in ffmpeg_get_frame_refr_period()
623 int period = 1000 * (int64_t)ffmpeg_ctx->video_stream->avg_frame_rate.den in ffmpeg_get_frame_refr_period()
631 static int ffmpeg_update_next_frame(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_update_next_frame() argument
638 if(av_read_frame(ffmpeg_ctx->fmt_ctx, &(ffmpeg_ctx->pkt)) >= 0) { in ffmpeg_update_next_frame()
644 if(ffmpeg_ctx->pkt.stream_index == ffmpeg_ctx->video_stream_idx) { in ffmpeg_update_next_frame()
645 ret = ffmpeg_decode_packet(ffmpeg_ctx->video_dec_ctx, in ffmpeg_update_next_frame()
646 &(ffmpeg_ctx->pkt), ffmpeg_ctx); in ffmpeg_update_next_frame()
650 av_packet_unref(&(ffmpeg_ctx->pkt)); in ffmpeg_update_next_frame()
678 struct ffmpeg_context_s * ffmpeg_ctx = calloc(1, sizeof(struct ffmpeg_context_s)); in ffmpeg_open_file() local
680 if(ffmpeg_ctx == NULL) { in ffmpeg_open_file()
687 if(avformat_open_input(&(ffmpeg_ctx->fmt_ctx), path, NULL, NULL) < 0) { in ffmpeg_open_file()
694 if(avformat_find_stream_info(ffmpeg_ctx->fmt_ctx, NULL) < 0) { in ffmpeg_open_file()
700 &(ffmpeg_ctx->video_stream_idx), in ffmpeg_open_file()
701 &(ffmpeg_ctx->video_dec_ctx), in ffmpeg_open_file()
702 ffmpeg_ctx->fmt_ctx, AVMEDIA_TYPE_VIDEO) in ffmpeg_open_file()
704 ffmpeg_ctx->video_stream = ffmpeg_ctx->fmt_ctx->streams[ffmpeg_ctx->video_stream_idx]; in ffmpeg_open_file()
706 ffmpeg_ctx->has_alpha = ffmpeg_pix_fmt_has_alpha(ffmpeg_ctx->video_dec_ctx->pix_fmt); in ffmpeg_open_file()
708ffmpeg_ctx->video_dst_pix_fmt = (ffmpeg_ctx->has_alpha ? AV_PIX_FMT_BGRA : AV_PIX_FMT_TRUE_COLOR); in ffmpeg_open_file()
713 av_dump_format(ffmpeg_ctx->fmt_ctx, 0, path, 0); in ffmpeg_open_file()
716 if(ffmpeg_ctx->video_stream == NULL) { in ffmpeg_open_file()
721 return ffmpeg_ctx; in ffmpeg_open_file()
724 ffmpeg_close(ffmpeg_ctx); in ffmpeg_open_file()
728 static int ffmpeg_image_allocate(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_image_allocate() argument
734 ffmpeg_ctx->video_src_data, in ffmpeg_image_allocate()
735 ffmpeg_ctx->video_src_linesize, in ffmpeg_image_allocate()
736 ffmpeg_ctx->video_dec_ctx->width, in ffmpeg_image_allocate()
737 ffmpeg_ctx->video_dec_ctx->height, in ffmpeg_image_allocate()
738 ffmpeg_ctx->video_dec_ctx->pix_fmt, in ffmpeg_image_allocate()
749 ffmpeg_ctx->video_dst_data, in ffmpeg_image_allocate()
750 ffmpeg_ctx->video_dst_linesize, in ffmpeg_image_allocate()
751 ffmpeg_ctx->video_dec_ctx->width, in ffmpeg_image_allocate()
752 ffmpeg_ctx->video_dec_ctx->height, in ffmpeg_image_allocate()
753 ffmpeg_ctx->video_dst_pix_fmt, in ffmpeg_image_allocate()
763 ffmpeg_ctx->frame = av_frame_alloc(); in ffmpeg_image_allocate()
765 if(ffmpeg_ctx->frame == NULL) { in ffmpeg_image_allocate()
771 av_init_packet(&ffmpeg_ctx->pkt); in ffmpeg_image_allocate()
772 ffmpeg_ctx->pkt.data = NULL; in ffmpeg_image_allocate()
773 ffmpeg_ctx->pkt.size = 0; in ffmpeg_image_allocate()
778 static void ffmpeg_close_src_ctx(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close_src_ctx() argument
780 avcodec_free_context(&(ffmpeg_ctx->video_dec_ctx)); in ffmpeg_close_src_ctx()
781 avformat_close_input(&(ffmpeg_ctx->fmt_ctx)); in ffmpeg_close_src_ctx()
782 av_frame_free(&(ffmpeg_ctx->frame)); in ffmpeg_close_src_ctx()
783 if(ffmpeg_ctx->video_src_data[0] != NULL) { in ffmpeg_close_src_ctx()
784 av_free(ffmpeg_ctx->video_src_data[0]); in ffmpeg_close_src_ctx()
785 ffmpeg_ctx->video_src_data[0] = NULL; in ffmpeg_close_src_ctx()
789 static void ffmpeg_close_dst_ctx(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close_dst_ctx() argument
791 if(ffmpeg_ctx->video_dst_data[0] != NULL) { in ffmpeg_close_dst_ctx()
792 av_free(ffmpeg_ctx->video_dst_data[0]); in ffmpeg_close_dst_ctx()
793 ffmpeg_ctx->video_dst_data[0] = NULL; in ffmpeg_close_dst_ctx()
797 static void ffmpeg_close(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close() argument
799 if(ffmpeg_ctx == NULL) { in ffmpeg_close()
804 sws_freeContext(ffmpeg_ctx->sws_ctx); in ffmpeg_close()
805 ffmpeg_close_src_ctx(ffmpeg_ctx); in ffmpeg_close()
806 ffmpeg_close_dst_ctx(ffmpeg_ctx); in ffmpeg_close()
807 free(ffmpeg_ctx); in ffmpeg_close()
817 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_frame_update_cb()
821 int has_next = ffmpeg_update_next_frame(player->ffmpeg_ctx); in lv_ffmpeg_player_frame_update_cb()
829 if(player->ffmpeg_ctx->has_alpha) { in lv_ffmpeg_player_frame_update_cb()
847 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_constructor()
869 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_destructor()
870 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_destructor()