| 284 | } |
| 285 | |
| 286 | void CVideo::Stop() |
| 287 | { |
| 288 | dbg_assert(!m_Stopped, "Already stopped"); |
| 289 | m_Stopped = true; |
| 290 | |
| 291 | m_pGraphics->WaitForIdle(); |
| 292 | |
| 293 | for(auto &pVideoThread : m_vpVideoThreads) |
| 294 | { |
| 295 | { |
| 296 | std::unique_lock<std::mutex> Lock(pVideoThread->m_Mutex); |
| 297 | pVideoThread->m_Finished = true; |
| 298 | pVideoThread->m_Cond.notify_all(); |
| 299 | } |
| 300 | |
| 301 | pVideoThread->m_Thread.join(); |
| 302 | } |
| 303 | m_vpVideoThreads.clear(); |
| 304 | |
| 305 | for(auto &pAudioThread : m_vpAudioThreads) |
| 306 | { |
| 307 | { |
| 308 | std::unique_lock<std::mutex> Lock(pAudioThread->m_Mutex); |
| 309 | pAudioThread->m_Finished = true; |
| 310 | pAudioThread->m_Cond.notify_all(); |
| 311 | } |
| 312 | |
| 313 | pAudioThread->m_Thread.join(); |
| 314 | } |
| 315 | m_vpAudioThreads.clear(); |
| 316 | |
| 317 | while(m_ProcessingVideoFrame > 0 || m_ProcessingAudioFrame > 0) |
| 318 | std::this_thread::sleep_for(10us); |
| 319 | |
| 320 | m_Recording = false; |
| 321 | |
| 322 | FinishFrames(&m_VideoStream); |
| 323 | |
| 324 | if(m_HasAudio) |
| 325 | FinishFrames(&m_AudioStream); |
| 326 | |
| 327 | if(m_pFormatContext && m_Started) |
| 328 | av_write_trailer(m_pFormatContext); |
| 329 | |
| 330 | CloseStream(&m_VideoStream); |
| 331 | |
| 332 | if(m_HasAudio) |
| 333 | CloseStream(&m_AudioStream); |
| 334 | |
| 335 | if(m_pFormatContext) |
| 336 | { |
| 337 | if(!(m_pFormat->flags & AVFMT_NOFILE)) |
| 338 | avio_closep(&m_pFormatContext->pb); |
| 339 | |
| 340 | avformat_free_context(m_pFormatContext); |
| 341 | } |
| 342 | |
| 343 | ISound *volatile pSound = m_pSound; |
no test coverage detected