fix sw fallback for hw probe fail, fix timebar dblclk deadlock, ffmpeg format menu...
authorGood Guy <[email protected]>
Wed, 4 Mar 2020 03:52:12 +0000 (20:52 -0700)
committerGood Guy <[email protected]>
Wed, 4 Mar 2020 03:52:12 +0000 (20:52 -0700)
cinelerra-5.1/cinelerra/ffmpeg.C
cinelerra-5.1/cinelerra/ffmpeg.h
cinelerra-5.1/cinelerra/fileffmpeg.C
cinelerra-5.1/cinelerra/timebar.C

index 857b7de740197ac8a749e4e18a5f55889d763d67..485385b4138bffd4cd822551766a8506521c9b96 100644 (file)
@@ -275,6 +275,7 @@ FFStream::FFStream(FFMPEG *ffmpeg, AVStream *st, int fidx)
        flushed = 0;
        need_packet = 1;
        frame = fframe = 0;
+       probe_frame = 0;
        bsfc = 0;
        stats_fp = 0;
        stats_filename = 0;
@@ -293,6 +294,7 @@ FFStream::~FFStream()
        if( filter_graph ) avfilter_graph_free(&filter_graph);
        if( frame ) av_frame_free(&frame);
        if( fframe ) av_frame_free(&fframe);
+       if( probe_frame ) av_frame_free(&probe_frame);
        delete frm_lock;
        if( stats_fp ) fclose(stats_fp);
        if( stats_in ) av_freep(&stats_in);
@@ -428,30 +430,31 @@ int FFStream::decode_activate()
                                ret = avcodec_open2(avctx, decoder, &copts);
                        }
                        if( ret >= 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) {
-                               if( need_packet ) {
-                                       need_packet = 0;
-                                       ret = read_packet();
+                               AVFrame *frame = av_frame_alloc();
+                               if( !frame ) {
+                                       fprintf(stderr, "FFStream::decode_activate: av_frame_alloc failed\n");
+                                       ret = AVERROR(ENOMEM);
                                }
-                               if( ret >= 0 ) {
-                                       AVPacket *pkt = (AVPacket*)ipkt;
-                                       ret = avcodec_send_packet(avctx, pkt);
-                                       if( ret < 0 || hw_pix_fmt == AV_PIX_FMT_NONE ) {
-                                               ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n",
-                                                       ffmpeg->fmt_ctx->url);
-                                               avcodec_close(avctx);
-                                               avcodec_free_context(&avctx);
-                                               av_buffer_unref(&hw_device_ctx);
-                                               hw_device_ctx = 0;
-                                               hw_type = AV_HWDEVICE_TYPE_NONE;
-                                               int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY;
-                                               int idx = st->index;
-                                               av_seek_frame(fmt_ctx, idx, INT64_MIN, flags);
-                                               need_packet = 1;  flushed = 0;
-                                               seeked = 1;  st_eof(0);
-                                               ret = 0;
-                                               continue;
-                                       }
+                               if( ret >= 0 )
+                                       ret = decode(frame);
+                               if( ret < 0 || hw_pix_fmt == AV_PIX_FMT_NONE ) {
+                                       ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n",
+                                               ffmpeg->fmt_ctx->url);
+                                       avcodec_close(avctx);
+                                       avcodec_free_context(&avctx);
+                                       av_buffer_unref(&hw_device_ctx);
+                                       hw_device_ctx = 0;
+                                       av_frame_free(&frame);
+                                       hw_type = AV_HWDEVICE_TYPE_NONE;
+                                       int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY;
+                                       int idx = st->index;
+                                       av_seek_frame(fmt_ctx, idx, INT64_MIN, flags);
+                                       need_packet = 1;  flushed = 0;
+                                       seeked = 1;  st_eof(0);
+                                       ret = 0;
+                                       continue;
                                }
+                               probe_frame = frame;
                        }
                        if( ret >= 0 ) {
                                reading = 1;
@@ -483,6 +486,11 @@ int FFStream::read_packet()
 
 int FFStream::decode(AVFrame *frame)
 {
+       if( probe_frame ) { // hw probe reads first frame
+               av_frame_ref(frame, probe_frame);
+               av_frame_free(&probe_frame);
+               return 1;
+       }
        int ret = 0;
        int retries = MAX_RETRY;
 
@@ -720,7 +728,7 @@ int FFStream::seek(int64_t no, double rate)
        tstmp = av_rescale_q(tstmp, time_base, AV_TIME_BASE_Q);
        idx = -1;
 #endif
-
+       av_frame_free(&probe_frame);
        avcodec_flush_buffers(avctx);
        avformat_flush(fmt_ctx);
 #if 0
index 100d80f556e48856f9c25d8ffa2f4632514ad517..56ce4e5b22d512a09d2f97863e5d321987f24b63 100644 (file)
@@ -119,6 +119,7 @@ public:
        AVFilterContext *buffersrc_ctx;
        AVFilterGraph *filter_graph;
        AVFrame *frame, *fframe;
+       AVFrame *probe_frame;
        AVBSFContext *bsfc;
 
        FFPacket ipkt;
index 21e3067e2f4bbbd4203962979ceac13b442f40bc..ff206b1011dea4569c2d09c1467fe157d0ccd86c 100644 (file)
@@ -864,10 +864,10 @@ void FFMPEGConfigFormat::save_options()
 }
 void FFMPEGConfigFormat::save_changes()
 {
+       read_options();
        char *options = asset->ff_format_options;
        int options_len = sizeof(asset->ff_format_options)-1;
        ff_options_dialog->store_options(options, options_len);
-       format_options->update(options);
 }
 
 void FFMPEGConfigFormat::load_options()
@@ -1974,11 +1974,8 @@ BC_Window *FFOptionsFormatViewDialog::new_gui()
 
 void FFOptionsFormatViewDialog::handle_done_event(int result)
 {
-       if( !result ) {
-               cfg_window->lock_window("FFOptionsFormatViewDialog::handle_done_event");
+       if( !result )
                cfg_window->save_changes();
-               cfg_window->unlock_window();
-       }
        cfg_window = 0;
 }
 
index 7dfc7c01e62242886496d644e66b8e17261681ec..222c6effdee124318938f5fe8a4a678a4d82c5a0 100644 (file)
@@ -918,9 +918,8 @@ int TimeBar::select_region(double position)
        }
 
 // Que the CWindow
-       mwindow->cwindow->gui->lock_window("TimeBar::select_region");
+       unlock_window();
        mwindow->cwindow->update(1, 0, 0);
-       mwindow->cwindow->gui->unlock_window();
        mwindow->gui->lock_window("TimeBar::select_region");
        mwindow->gui->hide_cursor(0);
        mwindow->gui->draw_cursor(1);
@@ -928,6 +927,7 @@ int TimeBar::select_region(double position)
        mwindow->gui->activate_timeline();
        mwindow->gui->zoombar->update();
        mwindow->gui->unlock_window();
+       lock_window("TimeBar::select_region");
        update_highlights();
        return 0;
 }