OSDN Git Service

[MOVIE_LOADER] Fix scaling factor.Displaying video as correct width and height.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 25 Mar 2018 16:21:43 +0000 (01:21 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 25 Mar 2018 16:21:43 +0000 (01:21 +0900)
[MOVIE_LOADER] Fix hang up at end of video.
[MOVIE_SAVER][WIP] Fixing crash when saving movie and playing video.(still not fix).

source/src/qt/CMakeLists.txt
source/src/qt/avio/CMakeLists.txt
source/src/qt/avio/movie_loader.cpp
source/src/qt/avio/movie_loader.h
source/src/qt/avio/movie_saver.cpp
source/src/qt/osd_screen.cpp
source/src/qt/osd_wrapper.cpp

index a39186a..e91376b 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 2.10.3
+SET(THIS_LIB_VERSION 2.10.4
 
 set(s_qt_osd_headers
        osd_base.h
index 6590fa4..0cd5b4c 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/avio")
 
-SET(THIS_LIB_VERSION 2.7.2)
+SET(THIS_LIB_VERSION 2.7.3)
 set(s_qt_avio_headers
          movie_saver.h
          movie_loader.h
index 9d943e8..50830f0 100644 (file)
@@ -142,6 +142,8 @@ int MOVIE_LOADER::decode_packet(int *got_frame, int cached)
                                                                                         dst_width, dst_height,
                                                                                         AV_PIX_FMT_BGRA,
                                                                                         SCALE_FLAGS, NULL, NULL, NULL);
+                               //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_LOADER, "Src frame=%dx%d Allocate frame: %dx%d", frame->width, frame->height, dst_width, dst_height);
+
                                if (sws_context == NULL) {
                                        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_MOVIE_LOADER,
                                                                  "MOVIE_LOADER: Could not initialize the conversion context\n");
@@ -152,7 +154,7 @@ int MOVIE_LOADER::decode_packet(int *got_frame, int cached)
                        video_mutex->lock();
                        sws_scale(sws_context,
                                          frame->data, frame->linesize,
-                                         0, dst_height, video_dst_data, video_dst_linesize);
+                                         0, frame->height, video_dst_data, video_dst_linesize);
                        req_transfer = true;
                        video_mutex->unlock();
                }
@@ -504,6 +506,7 @@ void MOVIE_LOADER::do_decode_frames(int frames, int width, int height)
        bool end_of_frame = false;
        int real_frames = 0;
        double d_frames = (double)frames * (frame_rate / p_osd->vm_frame_rate());
+       if(now_pausing) return;
        if(now_playing) duration_us = duration_us + (int64_t)((1.0e6 * (double)frames) / p_osd->vm_frame_rate());
 
        mod_frames = mod_frames + d_frames;
@@ -552,7 +555,10 @@ void MOVIE_LOADER::do_decode_frames(int frames, int width, int height)
                a_f = (av_rescale_rnd(audio_total_samples, 1000000, audio_stream->codec->sample_rate, AV_ROUND_UP) < duration_us);
                //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_LOADER, "%lld usec. V=%lld A=%lld, %d - %d\n", duration_us, video_frame_count, audio_total_samples, v_f, a_f);
                if(!a_f && !v_f) break; 
-               av_read_frame(fmt_ctx, &pkt);
+               if(av_read_frame(fmt_ctx, &pkt) < 0) {
+                       this->close();
+                       return;
+               }
                decode_packet(&got_frame, 0);
                if(got_frame == 0) {
                        end_of_frame = true;
@@ -578,7 +584,9 @@ void MOVIE_LOADER::get_video_frame()
 
        QMutexLocker Locker_S(p_osd->screen_mutex);
        QMutexLocker Locker_V(video_mutex);
+
        if(req_transfer) {
+               //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_LOADER, "Transfer frame: %dx%d", dst_width, dst_height);
                req_transfer = false;
                for(int yy = 0; yy < dst_height; yy++) {
                        q = (uint32_t *)(p_osd->get_vm_screen_buffer(yy));
@@ -586,24 +594,11 @@ void MOVIE_LOADER::get_video_frame()
                        p = (uint32_t *)(&(video_dst_data[0][yy * video_dst_linesize[0]]));
                        if((p == NULL) || (q == NULL)) break;
                        for(xx = dst_width; xx > 7;) {
-                               cacheline[0] = p[0];
-                               cacheline[1] = p[1];
-                               cacheline[2] = p[2];
-                               cacheline[3] = p[3];
-                               cacheline[4] = p[4];
-                               cacheline[5] = p[5];
-                               cacheline[6] = p[6];
-                               cacheline[7] = p[7];
-                               
-                               q[0] = cacheline[0];
-                               q[1] = cacheline[1];
-                               q[2] = cacheline[2];
-                               q[3] = cacheline[3];
-                               q[4] = cacheline[4];
-                               q[5] = cacheline[5];
-                               q[6] = cacheline[6];
-                               q[7] = cacheline[7];
-                               
+__DECL_VECTORIZED_LOOP
+                               for(int i = 0; i < 8; i++) {
+                                       cacheline[i] = p[i];
+                                       q[i] = cacheline[i];
+                               }
                                p += 8;
                                q += 8;
                                xx -= 8;
@@ -617,23 +612,17 @@ void MOVIE_LOADER::get_video_frame()
                        uint32_t col = 0xffffffff;
                        if(q == NULL) break;
                        for(xx = dst_width; xx > 7;) {
-                               
-                               q[0] = col;
-                               q[1] = col;
-                               q[2] = col;
-                               q[3] = col;
-                               q[4] = col;
-                               q[5] = col;
-                               q[6] = col;
-                               q[7] = col;
-                               
+__DECL_VECTORIZED_LOOP
+                               for(int i = 0; i < 8; i++) {
+                                       q[i] = col;
+                               }
                                p += 8;
                                q += 8;
                                xx -= 8;
                                if(xx < 8) break;
                        }
                        for(; xx > 0; xx--) {
-                               *q++ = *p++;
+                               *q++ = col;
                        }
 #endif            
                }
index f4e2fe3..81202a3 100644 (file)
@@ -25,8 +25,9 @@ extern "C" {
 // Copy from FFMPEG-3.0.2; doc/example/muxing.c .
 #define STREAM_PIX_FMT AV_PIX_FMT_RGBA /* default pix_fmt */
 
-#define SCALE_FLAGS SWS_BICUBLIN
+//#define SCALE_FLAGS SWS_BICUBLIN
 //#define SCALE_FLAGS SWS_POINT
+#define SCALE_FLAGS SWS_FAST_BILINEAR
 
 #include <QObject>
 #include <QReadWriteLock>
index 720c66d..ce85d61 100644 (file)
@@ -61,9 +61,8 @@ MOVIE_SAVER::MOVIE_SAVER(int width, int height, int fps, OSD *osd, config_t *cfg
 
 MOVIE_SAVER::~MOVIE_SAVER()
 {
+       req_close = true;
        if(recording) do_close_main();
-       //if(video_queue_mutex) delete video_queue_mutex;
-
 }
 
 QString MOVIE_SAVER::ts2str(int64_t ts)
@@ -126,6 +125,8 @@ void MOVIE_SAVER::enqueue_video(int frames, int width, int height, QImage *p)
        if(!recording) return;
        if(p == NULL) return;
        if(req_stop) return;
+       if((width  <= 0) || (height <= 0) || (frames <= 0)) return;
+       if((p->width() <= 0) || (p->height() <= 0)) return;
        VIDEO_DATA *px = new VIDEO_DATA(frames, width, height, p);
        //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_SAVER, "Movie: Enqueue video data %dx%d %d bytes %dx%d %d frames", width, height, p->byteCount(), p->width(), p->height(), frames);
        //video_queue_mutex->lock();
@@ -155,7 +156,7 @@ bool MOVIE_SAVER::dequeue_video(uint32_t *p)
                        my_memcpy(&(p[_width * y]), pq, (((uint)_width * sizeof(uint32_t)) > pp_i->bytesPerLine()) ? pp_i->bytesPerLine() : _width * sizeof(uint32_t));
                }
                video_size = _width * y;
-               //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_SAVER, "Movie: Dequeue video data %d bytes", pp->byteCount());
+               //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_MOVIE_SAVER, "Movie: Dequeue video data %d bytes", video_size);
        }
 #else
        video_size = 0;
index c151b40..938f8f5 100644 (file)
@@ -131,7 +131,9 @@ int OSD_BASE::no_draw_screen()
 void OSD_BASE::do_draw(bool flag)
 {
        int frames;
+#if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
        do_decode_movie(1);
+#endif
        if(flag) {
                frames = draw_screen();
        } else {
@@ -157,7 +159,7 @@ void OSD_BASE::initialize_screen_buffer(bitmap_t *buffer, int width, int height,
                buffer->pImage = QImage(width, height, QImage::Format_ARGB32);
                buffer->pImage.fill(col);
        }
-       //printf("%dx%d NULL=%d\n", buffer->pImage.width(), buffer->pImage.height(), buffer->pImage.isNull() ? 1 : 0);
+       printf("%dx%d NULL=%d\n", buffer->pImage.width(), buffer->pImage.height(), buffer->pImage.isNull() ? 1 : 0);
        QColor fillcolor;
        fillcolor.setRgb(0, 0, 0, 255);
        buffer->pImage.fill(fillcolor);
index ae6c7d9..fdf04c2 100644 (file)
@@ -497,7 +497,8 @@ void OSD::do_run_movie_audio_callback(uint8_t *data, long len)
 void OSD::do_decode_movie(int frames)
 {
 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
-       movie_loader->do_decode_frames(frames, this->get_vm_window_width(), this->get_vm_window_height());
+       //movie_loader->do_decode_frames(frames, SCREEN_WIDTH, SCREEN_HEIGHT);
+       movie_loader->do_decode_frames(frames, vm_window_width_aspect, vm_window_height_aspect);
 #endif 
 }