Lines Matching refs:ffmpeg_ctx
86 static void ffmpeg_close(struct ffmpeg_context_s * ffmpeg_ctx);
87 static void ffmpeg_close_src_ctx(struct ffmpeg_context_s * ffmpeg_ctx);
88 static void ffmpeg_close_dst_ctx(struct ffmpeg_context_s * ffmpeg_ctx);
89 static int ffmpeg_image_allocate(struct ffmpeg_context_s * ffmpeg_ctx);
91 static int ffmpeg_get_frame_refr_period(struct ffmpeg_context_s * ffmpeg_ctx);
92 static uint8_t * ffmpeg_get_image_data(struct ffmpeg_context_s * ffmpeg_ctx);
93 static int ffmpeg_update_next_frame(struct ffmpeg_context_s * ffmpeg_ctx);
94 static int ffmpeg_output_video_frame(struct ffmpeg_context_s * ffmpeg_ctx);
138 struct ffmpeg_context_s * ffmpeg_ctx = ffmpeg_open_file(path, LV_FFMPEG_PLAYER_USE_LV_FS); in lv_ffmpeg_get_frame_num() local
140 if(ffmpeg_ctx) { in lv_ffmpeg_get_frame_num()
141 ret = ffmpeg_ctx->video_stream->nb_frames; in lv_ffmpeg_get_frame_num()
142 ffmpeg_close(ffmpeg_ctx); in lv_ffmpeg_get_frame_num()
162 if(player->ffmpeg_ctx) { in lv_ffmpeg_player_set_src()
163 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
164 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_set_src()
169 player->ffmpeg_ctx = ffmpeg_open_file(path, LV_FFMPEG_PLAYER_USE_LV_FS); in lv_ffmpeg_player_set_src()
171 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_set_src()
176 if(ffmpeg_image_allocate(player->ffmpeg_ctx) < 0) { in lv_ffmpeg_player_set_src()
178 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
182 bool has_alpha = player->ffmpeg_ctx->has_alpha; in lv_ffmpeg_player_set_src()
183 int width = player->ffmpeg_ctx->video_dec_ctx->width; in lv_ffmpeg_player_set_src()
184 int height = player->ffmpeg_ctx->video_dec_ctx->height; in lv_ffmpeg_player_set_src()
194 player->imgdsc.data = ffmpeg_get_image_data(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
198 int period = ffmpeg_get_frame_refr_period(player->ffmpeg_ctx); in lv_ffmpeg_player_set_src()
220 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_set_cmd()
229 av_seek_frame(player->ffmpeg_ctx->fmt_ctx, in lv_ffmpeg_player_set_cmd()
235 av_seek_frame(player->ffmpeg_ctx->fmt_ctx, in lv_ffmpeg_player_set_cmd()
298 struct ffmpeg_context_s * ffmpeg_ctx = ffmpeg_open_file(path, true); in decoder_open() local
300 if(ffmpeg_ctx == NULL) { in decoder_open()
304 if(ffmpeg_image_allocate(ffmpeg_ctx) < 0) { in decoder_open()
306 ffmpeg_close(ffmpeg_ctx); in decoder_open()
310 if(ffmpeg_update_next_frame(ffmpeg_ctx) < 0) { in decoder_open()
311 ffmpeg_close(ffmpeg_ctx); in decoder_open()
316 ffmpeg_close_src_ctx(ffmpeg_ctx); in decoder_open()
317 uint8_t * img_data = ffmpeg_get_image_data(ffmpeg_ctx); in decoder_open()
319 dsc->user_data = ffmpeg_ctx; in decoder_open()
320 lv_draw_buf_t * decoded = &ffmpeg_ctx->draw_buf; in decoder_open()
339 struct ffmpeg_context_s * ffmpeg_ctx = dsc->user_data; in decoder_close() local
340 ffmpeg_close(ffmpeg_ctx); in decoder_close()
343 static uint8_t * ffmpeg_get_image_data(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_get_image_data() argument
345 uint8_t * img_data = ffmpeg_ctx->video_dst_data[0]; in ffmpeg_get_image_data()
380 static int ffmpeg_output_video_frame(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_output_video_frame() argument
384 int width = ffmpeg_ctx->video_dec_ctx->width; in ffmpeg_output_video_frame()
385 int height = ffmpeg_ctx->video_dec_ctx->height; in ffmpeg_output_video_frame()
386 AVFrame * frame = ffmpeg_ctx->frame; in ffmpeg_output_video_frame()
390 || frame->format != ffmpeg_ctx->video_dec_ctx->pix_fmt) { in ffmpeg_output_video_frame()
402 av_get_pix_fmt_name(ffmpeg_ctx->video_dec_ctx->pix_fmt), in ffmpeg_output_video_frame()
413 av_image_copy(ffmpeg_ctx->video_src_data, ffmpeg_ctx->video_src_linesize, in ffmpeg_output_video_frame()
415 ffmpeg_ctx->video_dec_ctx->pix_fmt, width, height); in ffmpeg_output_video_frame()
417 if(ffmpeg_ctx->sws_ctx == NULL) { in ffmpeg_output_video_frame()
420 if(ffmpeg_pix_fmt_is_yuv(ffmpeg_ctx->video_dec_ctx->pix_fmt)) { in ffmpeg_output_video_frame()
438 ffmpeg_ctx->sws_ctx = sws_getContext( in ffmpeg_output_video_frame()
439 width, height, ffmpeg_ctx->video_dec_ctx->pix_fmt, in ffmpeg_output_video_frame()
440 width, height, ffmpeg_ctx->video_dst_pix_fmt, in ffmpeg_output_video_frame()
445 if(!ffmpeg_ctx->has_alpha) { in ffmpeg_output_video_frame()
447 int dst_linesize = ffmpeg_ctx->video_dst_linesize[0]; in ffmpeg_output_video_frame()
452 ffmpeg_ctx->video_dst_linesize[0] = lv_linesize; in ffmpeg_output_video_frame()
457 ffmpeg_ctx->sws_ctx, in ffmpeg_output_video_frame()
458 (const uint8_t * const *)(ffmpeg_ctx->video_src_data), in ffmpeg_output_video_frame()
459 ffmpeg_ctx->video_src_linesize, in ffmpeg_output_video_frame()
462 ffmpeg_ctx->video_dst_data, in ffmpeg_output_video_frame()
463 ffmpeg_ctx->video_dst_linesize); in ffmpeg_output_video_frame()
470 struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_decode_packet() argument
484 ret = avcodec_receive_frame(dec, ffmpeg_ctx->frame); in ffmpeg_decode_packet()
501 ret = ffmpeg_output_video_frame(ffmpeg_ctx); in ffmpeg_decode_packet()
504 av_frame_unref(ffmpeg_ctx->frame); in ffmpeg_decode_packet()
631 static int ffmpeg_get_frame_refr_period(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_get_frame_refr_period() argument
633 int avg_frame_rate_num = ffmpeg_ctx->video_stream->avg_frame_rate.num; in ffmpeg_get_frame_refr_period()
635 int period = 1000 * (int64_t)ffmpeg_ctx->video_stream->avg_frame_rate.den in ffmpeg_get_frame_refr_period()
643 static int ffmpeg_update_next_frame(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_update_next_frame() argument
650 if(av_read_frame(ffmpeg_ctx->fmt_ctx, ffmpeg_ctx->pkt) >= 0) { in ffmpeg_update_next_frame()
656 if(ffmpeg_ctx->pkt->stream_index == ffmpeg_ctx->video_stream_idx) { in ffmpeg_update_next_frame()
657 ret = ffmpeg_decode_packet(ffmpeg_ctx->video_dec_ctx, in ffmpeg_update_next_frame()
658 ffmpeg_ctx->pkt, ffmpeg_ctx); in ffmpeg_update_next_frame()
662 av_packet_unref(ffmpeg_ctx->pkt); in ffmpeg_update_next_frame()
731 struct ffmpeg_context_s * ffmpeg_ctx = calloc(1, sizeof(struct ffmpeg_context_s)); in ffmpeg_open_file() local
733 if(ffmpeg_ctx == NULL) { in ffmpeg_open_file()
739 …lv_fs_open(&(ffmpeg_ctx->lv_file), path, LV_FS_MODE_RD); /* image_decoder_get_info says the fil… in ffmpeg_open_file()
741 …ffmpeg_ctx->io_ctx = ffmpeg_open_io_context(&(ffmpeg_ctx->lv_file)); /* Save the buffer pointe… in ffmpeg_open_file()
743 if(ffmpeg_ctx->io_ctx == NULL) { in ffmpeg_open_file()
748 ffmpeg_ctx->fmt_ctx = avformat_alloc_context(); in ffmpeg_open_file()
749 if(ffmpeg_ctx->fmt_ctx == NULL) { in ffmpeg_open_file()
753 ffmpeg_ctx->fmt_ctx->pb = ffmpeg_ctx->io_ctx; in ffmpeg_open_file()
754 ffmpeg_ctx->fmt_ctx->flags |= AVFMT_FLAG_CUSTOM_IO; in ffmpeg_open_file()
759 if(avformat_open_input(&(ffmpeg_ctx->fmt_ctx), path, NULL, NULL) < 0) { in ffmpeg_open_file()
766 if(avformat_find_stream_info(ffmpeg_ctx->fmt_ctx, NULL) < 0) { in ffmpeg_open_file()
772 &(ffmpeg_ctx->video_stream_idx), in ffmpeg_open_file()
773 &(ffmpeg_ctx->video_dec_ctx), in ffmpeg_open_file()
774 ffmpeg_ctx->fmt_ctx, AVMEDIA_TYPE_VIDEO) in ffmpeg_open_file()
776 ffmpeg_ctx->video_stream = ffmpeg_ctx->fmt_ctx->streams[ffmpeg_ctx->video_stream_idx]; in ffmpeg_open_file()
778 ffmpeg_ctx->has_alpha = ffmpeg_pix_fmt_has_alpha(ffmpeg_ctx->video_dec_ctx->pix_fmt); in ffmpeg_open_file()
780 … ffmpeg_ctx->video_dst_pix_fmt = (ffmpeg_ctx->has_alpha ? AV_PIX_FMT_BGRA : AV_PIX_FMT_TRUE_COLOR); in ffmpeg_open_file()
785 av_dump_format(ffmpeg_ctx->fmt_ctx, 0, path, 0); in ffmpeg_open_file()
788 if(ffmpeg_ctx->video_stream == NULL) { in ffmpeg_open_file()
793 return ffmpeg_ctx; in ffmpeg_open_file()
796 ffmpeg_close(ffmpeg_ctx); in ffmpeg_open_file()
800 static int ffmpeg_image_allocate(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_image_allocate() argument
806 ffmpeg_ctx->video_src_data, in ffmpeg_image_allocate()
807 ffmpeg_ctx->video_src_linesize, in ffmpeg_image_allocate()
808 ffmpeg_ctx->video_dec_ctx->width, in ffmpeg_image_allocate()
809 ffmpeg_ctx->video_dec_ctx->height, in ffmpeg_image_allocate()
810 ffmpeg_ctx->video_dec_ctx->pix_fmt, in ffmpeg_image_allocate()
821 ffmpeg_ctx->video_dst_data, in ffmpeg_image_allocate()
822 ffmpeg_ctx->video_dst_linesize, in ffmpeg_image_allocate()
823 ffmpeg_ctx->video_dec_ctx->width, in ffmpeg_image_allocate()
824 ffmpeg_ctx->video_dec_ctx->height, in ffmpeg_image_allocate()
825 ffmpeg_ctx->video_dst_pix_fmt, in ffmpeg_image_allocate()
835 ffmpeg_ctx->frame = av_frame_alloc(); in ffmpeg_image_allocate()
837 if(ffmpeg_ctx->frame == NULL) { in ffmpeg_image_allocate()
844 ffmpeg_ctx->pkt = av_packet_alloc(); in ffmpeg_image_allocate()
845 if(ffmpeg_ctx->pkt == NULL) { in ffmpeg_image_allocate()
849 ffmpeg_ctx->pkt->data = NULL; in ffmpeg_image_allocate()
850 ffmpeg_ctx->pkt->size = 0; in ffmpeg_image_allocate()
855 static void ffmpeg_close_src_ctx(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close_src_ctx() argument
857 avcodec_free_context(&(ffmpeg_ctx->video_dec_ctx)); in ffmpeg_close_src_ctx()
858 avformat_close_input(&(ffmpeg_ctx->fmt_ctx)); in ffmpeg_close_src_ctx()
859 av_frame_free(&(ffmpeg_ctx->frame)); in ffmpeg_close_src_ctx()
860 if(ffmpeg_ctx->video_src_data[0] != NULL) { in ffmpeg_close_src_ctx()
861 av_free(ffmpeg_ctx->video_src_data[0]); in ffmpeg_close_src_ctx()
862 ffmpeg_ctx->video_src_data[0] = NULL; in ffmpeg_close_src_ctx()
866 static void ffmpeg_close_dst_ctx(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close_dst_ctx() argument
868 if(ffmpeg_ctx->video_dst_data[0] != NULL) { in ffmpeg_close_dst_ctx()
869 av_free(ffmpeg_ctx->video_dst_data[0]); in ffmpeg_close_dst_ctx()
870 ffmpeg_ctx->video_dst_data[0] = NULL; in ffmpeg_close_dst_ctx()
874 static void ffmpeg_close(struct ffmpeg_context_s * ffmpeg_ctx) in ffmpeg_close() argument
876 if(ffmpeg_ctx == NULL) { in ffmpeg_close()
881 sws_freeContext(ffmpeg_ctx->sws_ctx); in ffmpeg_close()
882 ffmpeg_close_src_ctx(ffmpeg_ctx); in ffmpeg_close()
883 ffmpeg_close_dst_ctx(ffmpeg_ctx); in ffmpeg_close()
884 if(ffmpeg_ctx->io_ctx != NULL) { in ffmpeg_close()
885 av_free(ffmpeg_ctx->io_ctx->buffer); in ffmpeg_close()
886 av_free(ffmpeg_ctx->io_ctx); in ffmpeg_close()
887 lv_fs_close(&(ffmpeg_ctx->lv_file)); in ffmpeg_close()
889 free(ffmpeg_ctx); in ffmpeg_close()
899 if(!player->ffmpeg_ctx) { in lv_ffmpeg_player_frame_update_cb()
903 int has_next = ffmpeg_update_next_frame(player->ffmpeg_ctx); in lv_ffmpeg_player_frame_update_cb()
928 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_constructor()
952 ffmpeg_close(player->ffmpeg_ctx); in lv_ffmpeg_player_destructor()
953 player->ffmpeg_ctx = NULL; in lv_ffmpeg_player_destructor()