Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
amf-vce: Fix compiler errors if THREADED is not set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Fabian Dirks committed Aug 8, 2016
1 parent e6eb565 commit f90df7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion win-amf/Include/amf-vce.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ namespace AMFEncoder {
/// Frame Size & Rate
std::pair<uint32_t, uint32_t> m_frameSize;
std::pair<uint32_t, uint32_t> m_frameRate;
double_t m_frameRateDiv;

// Dynamic Properties
/// Rate Control Method
Expand Down Expand Up @@ -334,7 +335,7 @@ namespace AMFEncoder {
std::vector<uint8_t> m_PacketDataBuffer;
std::vector<uint8_t> m_ExtraDataBuffer;

// Threading: Input & Output
#ifdef THREADED // Threading: Input & Output
ThreadDataInput m_InputThreadData;
ThreadDataOutput m_OutputThreadData;

Expand All @@ -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
Expand Down
32 changes: 23 additions & 9 deletions win-amf/Source/amf-vce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -520,6 +521,7 @@ void AMFEncoder::VCE::SetFrameRate(std::pair<uint32_t, uint32_t>& 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("<AMFEncoder::VCE::SetFrameRate> Set to %d/%d.", m_frameRate.first, m_frameRate.second);
} else { // Not OK? Then throw an error instead.
std::vector<char> sizebuf(96);
Expand Down Expand Up @@ -1320,15 +1322,14 @@ void AMFEncoder::VCE::Start() {
throwAMFError("<AMFEncoder::VCE::Start> 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
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::mutex> lock(data->m_mutex);
do {
Expand Down Expand Up @@ -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<char> msgBuf(1024);
Expand Down

0 comments on commit f90df7f

Please sign in to comment.