From f90df7f7dd323b6c7d39ce10bf4f4ceae94a645c Mon Sep 17 00:00:00 2001 From: Michael Fabian Dirks Date: Mon, 8 Aug 2016 21:15:14 +0200 Subject: [PATCH] amf-vce: Fix compiler errors if THREADED is not set. --- win-amf/Include/amf-vce.h | 4 +++- win-amf/Source/amf-vce.cpp | 32 +++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/win-amf/Include/amf-vce.h b/win-amf/Include/amf-vce.h index 08999c9e..c4b29f9a 100644 --- a/win-amf/Include/amf-vce.h +++ b/win-amf/Include/amf-vce.h @@ -290,6 +290,7 @@ namespace AMFEncoder { /// Frame Size & Rate std::pair m_frameSize; std::pair m_frameRate; + double_t m_frameRateDiv; // Dynamic Properties /// Rate Control Method @@ -334,7 +335,7 @@ namespace AMFEncoder { std::vector m_PacketDataBuffer; std::vector m_ExtraDataBuffer; - // Threading: Input & Output + #ifdef THREADED // Threading: Input & Output ThreadDataInput m_InputThreadData; ThreadDataOutput m_OutputThreadData; @@ -346,6 +347,7 @@ namespace AMFEncoder { bool m_InputShouldEnd, m_OutputShouldEnd; static void InputThreadMain(ThreadDataInput* data); static void OutputThreadMain(ThreadDataOutput* data); + #endif ////////////////////////////////////////////////////////////////////////// // Logging & Exception Helpers diff --git a/win-amf/Source/amf-vce.cpp b/win-amf/Source/amf-vce.cpp index 7a95575e..1fe48b5a 100644 --- a/win-amf/Source/amf-vce.cpp +++ b/win-amf/Source/amf-vce.cpp @@ -100,9 +100,10 @@ AMFEncoder::VCE::VCE(VCE_Encoder_Type type) { /// Binding: AMF m_AMFContext = nullptr; m_AMFEncoder = nullptr; - /// Threading: Input & Output + #ifdef THREADED /// Threading: Input & Output m_InputThreadData.m_encoder = m_AMFEncoder; m_OutputThreadData.m_encoder = m_AMFEncoder; + #endif // Attempt to create an AMF Context res = AMFCreateContext(&m_AMFContext); @@ -520,6 +521,7 @@ void AMFEncoder::VCE::SetFrameRate(std::pair& value) { if (res == AMF_OK) { m_frameRate.first = value.first; m_frameRate.second = value.second; + m_frameRateDiv = (double_t)m_frameRate.first / (double_t)m_frameRate.second; //avoid re-calc AMF_LOG_INFO(" Set to %d/%d.", m_frameRate.first, m_frameRate.second); } else { // Not OK? Then throw an error instead. std::vector sizebuf(96); @@ -1320,15 +1322,14 @@ void AMFEncoder::VCE::Start() { throwAMFError(" Unable to start, error %s (code %d).", res); } else { m_isStarted = true; - - // Threading Stuff + #ifdef THREADED // Threading m_InputThreadData.m_encoder = m_AMFEncoder; m_InputThreadData.m_shouldEnd = false; + m_InputThread = std::thread(&InputThreadMain, &m_InputThreadData); m_OutputThreadData.m_encoder = m_AMFEncoder; m_OutputThreadData.m_shouldEnd = false; - - m_InputThread = std::thread(&InputThreadMain, &m_InputThreadData); m_OutputThread = std::thread(&OutputThreadMain, &m_OutputThreadData); + #endif } } @@ -1342,6 +1343,15 @@ void AMFEncoder::VCE::Stop() { throw std::exception(error); } + #ifdef THREADED // Threading + m_InputThreadData.m_shouldEnd = true; + m_InputThreadData.m_condVar.notify_all(); + m_InputThread.join(); + m_OutputThreadData.m_shouldEnd = true; + m_OutputThreadData.m_condVar.notify_all(); + m_OutputThread.join(); + #endif + //ToDo: Support for ReInit at different FrameSize? How does that even work? res = m_AMFEncoder->Terminate(); if (res != AMF_OK) { @@ -1423,8 +1433,10 @@ void AMFEncoder::VCE::GetOutput(struct encoder_packet*& packet, bool*& received_ packet->type = OBS_ENCODER_VIDEO; packet->size = bufferSize; packet->data = m_PacketDataBuffer.data(); - pData->GetProperty(AMFVCE_PROPERTY_FRAME, &packet->pts); + packet->pts = int64_t(pData->GetPts() * m_frameRateDiv / 1e7); packet->dts = packet->pts; + //pData->GetProperty(AMFVCE_PROPERTY_FRAME, &packet->pts); + //packet->dts = pData->GetPts() / 10; { amf::AMFVariant variant; res = pData->GetProperty(AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE, &variant); @@ -1457,9 +1469,9 @@ void AMFEncoder::VCE::GetOutput(struct encoder_packet*& packet, bool*& received_ AMF_LOG_INFO(" Priority: %d", packet->priority); AMF_LOG_INFO(" Drop Priority: %d", packet->drop_priority); AMF_LOG_INFO(" Size: %d", packet->size); - AMF_LOG_INFO(" PTS: %d", packet->pts); - AMF_LOG_INFO(" PTS (from Data): %d", pData->GetPts()); - AMF_LOG_INFO(" PTS (from Buffer): %d", pBuffer->GetPts()); + AMF_LOG_INFO(" PTS in Frames: %f", (double_t)pData->GetPts() * m_frameRateDiv / (double_t)1e7); + AMF_LOG_INFO(" PTS in Frames: %d", int64_t(pData->GetPts() * m_frameRateDiv / 1e7)); + AMF_LOG_INFO(" PTS (Property): %d", packet->pts); #endif *received_packet = true; @@ -1605,6 +1617,7 @@ amf::AMFSurfacePtr inline AMFEncoder::VCE::CreateSurfaceFromFrame(struct encoder return pSurface; } +#ifdef THREADED // Threading void AMFEncoder::VCE::InputThreadMain(ThreadDataInput* data) { std::unique_lock lock(data->m_mutex); do { @@ -1642,6 +1655,7 @@ void AMFEncoder::VCE::OutputThreadMain(ThreadDataOutput* data) { } } while (!data->m_shouldEnd); } +#endif void AMFEncoder::VCE::throwAMFError(const char* errorMsg, AMF_RESULT res) { std::vector msgBuf(1024);