OSDN Git Service

[MOVIE_SAVER] Use SIMD to transfer a picture OSD(VM)->MOVIE_SAVER .
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 24 Aug 2016 06:52:39 +0000 (15:52 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 24 Aug 2016 06:52:39 +0000 (15:52 +0900)
source/src/qt/avio/movie_saver.cpp
source/src/qt/avio/movie_saver.h
source/src/qt/avio/movie_saver_video.cpp
source/src/qt/osd_screen.cpp

index 19bc1bc..4693f4d 100644 (file)
@@ -41,6 +41,8 @@ MOVIE_SAVER::MOVIE_SAVER(int width, int height, int fps, OSD *osd, config_t *cfg
        video_data_queue.clear();
        
        do_reset_encoder_options();
+
+       //video_queue_mutex = new QMutex(QMutex::Recursive);
        totalSrcFrame = 0;
        totalDstFrame = 0;
        totalAudioFrame = 0;
@@ -54,11 +56,14 @@ MOVIE_SAVER::MOVIE_SAVER(int width, int height, int fps, OSD *osd, config_t *cfg
        req_close = false;
        req_stop = false;
        bRunThread = false;
+       
 }
 
 MOVIE_SAVER::~MOVIE_SAVER()
 {
        if(recording) do_close_main();
+       //if(video_queue_mutex) delete video_queue_mutex;
+
 }
 
 QString MOVIE_SAVER::ts2str(int64_t ts)
@@ -123,8 +128,10 @@ void MOVIE_SAVER::enqueue_video(int frames, int width, int height, QImage *p)
        if(req_stop) return;
        uint32_t *pq;
        VIDEO_DATA *px = new VIDEO_DATA(frames, width, height, p);
-       //AGAR_DebugLog(AGAR_LOG_DEBUG, "Movie: Enqueue video data %dx%d %d bytes %dx%d", width, height, p->byteCount(), p->width(), p->height());
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "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();
        video_data_queue.enqueue(px);
+       //video_queue_mutex->unlock();
 #endif   
 }
 
index 483fcd4..88d47e1 100644 (file)
@@ -73,7 +73,7 @@ typedef struct OutputStream {
 } OutputStream;
 
 class OSD;
-
+class QMutex;
 QT_BEGIN_NAMESPACE
 class VIDEO_DATA {
 
@@ -97,7 +97,7 @@ class MOVIE_SAVER: public QThread
 private:
        int n_encode_audio;
        int n_encode_video;
-//     int64_t audio_enqueue_count;
+       //QMutex *video_queue_mutex;
 protected:
        OSD *p_osd;
        config_t *p_config;
index ae4c90b..e2d2eeb 100644 (file)
@@ -268,6 +268,7 @@ void *MOVIE_SAVER::get_video_frame(void)
                uint32_t *p;
                AVFrame *qq = ost->tmp_frame;
                uint32_t *q;
+               uint32_t cacheline[8];
                int i;
                int ret;
                if(ost->tmp_frame != NULL) {
@@ -276,12 +277,35 @@ void *MOVIE_SAVER::get_video_frame(void)
                        //exit(1);
                        for(y = 0; y < h; y++) {
                                yy[0] = y * qq->linesize[0];
-                               //yy[0] = y * in_linesize[0];
                                p = (uint32_t *)(&(video_frame_buf[y * w]));
                                q = (uint32_t *)(&(qq->data[0][yy[0]]));
-                               for(x = 0; x < w; x++) {
-                                       *q++ = *p++;
-                               }                       
+                               for(x = 0; x < (w / 8); x++) {
+                                       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];
+
+                                       q += 8;
+                                       p += 8;
+                               }
+                               if((w & 7) != 0) {
+                                       for(x = 0; x < (w & 7); x++) {
+                                               q[x] = p[x];
+                                       }
+                               }
                        }
                }
                sws_scale(ost->sws_ctx,
index 1b601ee..be6ac42 100644 (file)
@@ -298,7 +298,18 @@ int OSD_BASE::add_video_frames()
        double vm_fps = vm_frame_rate();
        int delta_ns = (int)(1.0e9 / vm_fps);
        //if(rec_video_fps_nsec >= delta_ns) {
-       { // Will branch whether rec_video_fps_nsec >= delta_ns ?
+       if(delta_ns == rec_video_fps_nsec) {
+               rec_video_nsec += delta_ns;
+               if(rec_video_nsec > (rec_video_fps_nsec * 2)) {
+                       rec_video_nsec -= rec_video_fps_nsec;
+               } else if(rec_video_nsec < (rec_video_fps_nsec * -2)) {
+                       rec_video_nsec += rec_video_fps_nsec;
+               }
+               while(rec_video_nsec > rec_video_fps_nsec) {
+                       rec_video_nsec -= rec_video_fps_nsec;
+                       counter++;
+               }
+       } else { // Will branch whether rec_video_fps_nsec >= delta_ns ?
                rec_video_nsec += delta_ns;
                if(rec_video_nsec > (rec_video_fps_nsec * 2)) {
                        rec_video_nsec -= rec_video_fps_nsec;
@@ -343,8 +354,8 @@ int OSD_BASE::add_video_frames()
        } else {
                int size = vm_screen_buffer.pImage.byteCount();
                int i = counter;
-               // Rescaling
                QImage video_result = QImage(vm_screen_buffer.pImage);
+               // Rescaling
                if(i > 0) {
                        // Enqueue to frame.
                        emit sig_enqueue_video(i, vm_screen_width, vm_screen_height, &video_result);