X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=h264encode.cpp;h=54f72666df31930c727048e19e1d4171cc384487;hb=cc8c88d231b1cde40baac3c2a780b89c69b96175;hp=2569470ef006e70806d8c40c8ae7c52a03abfd73;hpb=a1f1d6374a7c519c7a8b412578c9b88d64edddd4;p=nageru diff --git a/h264encode.cpp b/h264encode.cpp index 2569470..54f7266 100644 --- a/h264encode.cpp +++ b/h264encode.cpp @@ -1206,12 +1206,12 @@ static void sort_two(VAPictureH264 ref[], int left, int right, unsigned int key, sort_one(ref, j+1, right, list1_ascending, frame_idx); } -static int update_ReferenceFrames(int frame_type) +static void update_ReferenceFrames(int frame_type) { int i; if (frame_type == FRAME_B) - return 0; + return; CurrentCurrPic.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; numShortTerm++; @@ -1224,8 +1224,6 @@ static int update_ReferenceFrames(int frame_type) current_frame_num++; if (current_frame_num > MaxFrameNum) current_frame_num = 0; - - return 0; } @@ -1612,8 +1610,8 @@ void H264Encoder::save_codeddata(storage_task task) vector audio; { unique_lock lock(frame_queue_mutex); - frame_queue_nonempty.wait(lock, [this]{ return copy_thread_should_quit || !pending_audio_frames.empty(); }); - if (copy_thread_should_quit) return; + frame_queue_nonempty.wait(lock, [this]{ return storage_thread_should_quit || !pending_audio_frames.empty(); }); + if (storage_thread_should_quit && pending_audio_frames.empty()) return; auto it = pending_audio_frames.begin(); if (it->first > task.pts) break; audio_pts = it->first; @@ -1697,7 +1695,7 @@ void H264Encoder::storage_task_thread() // wait until there's an encoded frame unique_lock lock(storage_task_queue_mutex); storage_task_queue_changed.wait(lock, [this]{ return storage_thread_should_quit || !storage_task_queue.empty(); }); - if (storage_thread_should_quit) return; + if (storage_thread_should_quit && storage_task_queue.empty()) return; current = move(storage_task_queue.front()); storage_task_queue.pop(); } @@ -1779,7 +1777,7 @@ H264Encoder::H264Encoder(QSurface *surface, int width, int height, HTTPD *httpd) storage_thread = thread(&H264Encoder::storage_task_thread, this); - copy_thread = thread([this]{ + encode_thread = thread([this]{ //SDL_GL_MakeCurrent(window, context); QOpenGLContext *context = create_context(this->surface); eglBindAPI(EGL_OPENGL_API); @@ -1788,24 +1786,25 @@ H264Encoder::H264Encoder(QSurface *surface, int width, int height, HTTPD *httpd) eglGetError()); exit(1); } - copy_thread_func(); + encode_thread_func(); }); } H264Encoder::~H264Encoder() { { - unique_lock lock(storage_task_queue_mutex); - storage_thread_should_quit = true; - storage_task_queue_changed.notify_all(); + unique_lock lock(frame_queue_mutex); + encode_thread_should_quit = true; + frame_queue_nonempty.notify_all(); } + encode_thread.join(); { - unique_lock lock(frame_queue_mutex); - copy_thread_should_quit = true; + unique_lock lock(storage_task_queue_mutex); + storage_thread_should_quit = true; frame_queue_nonempty.notify_all(); + storage_task_queue_changed.notify_all(); } storage_thread.join(); - copy_thread.join(); release_encode(); deinit_va(); @@ -1894,7 +1893,7 @@ void H264Encoder::end_frame(RefCountedGLsync fence, int64_t pts, const vector lock(frame_queue_mutex); frame_queue_nonempty.wait(lock, [this, display_frame_num]{ - return copy_thread_should_quit || pending_video_frames.count(display_frame_num) != 0; + return encode_thread_should_quit || pending_video_frames.count(display_frame_num) != 0; }); - if (copy_thread_should_quit) { + if (encode_thread_should_quit) { return; } else { frame = move(pending_video_frames[display_frame_num]);