The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.
SDL
Simple Directmedia Layer Forums
SDL Multithreading
madprogrammer24
Joined: 12 Jun 2015
Posts: 9
Location: South Dakota
Posted: Fri Jul 24, 2015 5:38 pm
Hello Everybody,
I am having issues with multithreading, currently I am trying to split up my decoding and networking into separate threads. I can get the networking thread to fill the buffer just fine, but the issue seems to crop up after the decode thread gets signaled. The fillBuffer() method just seems to hang, and I know it is because it is waiting on the condition signal. What I don't understand is that the queue_cond for which the fillBuffer() is waiting is signaled after the decode thread finishes, so it should fire just fine.
Should I make the fillBuffer() it's own thread?
Or should I move my condition check somewhere else?
// Frame has ended, now decode and display
if (ntohs(proto.frame_end) == 1)
{
std::cout << "we have a frame end" << std::endl;
uint8_t *frameData = buffer.data();
int dataSize = buffer.size();
uint8_t *outbuffer = NULL;
int outBufSize = 0;
//// Loop while given a valid size
//while (dataSize)
//{
// // parse the stream out
int rc = av_parser_parse2(parser, codecContext, &outbuffer, &outBufSize, frameData, dataSize, 0, 0, 0);
std::cout << "pulling data from buffer" << std::endl;
// just a test
while (count > 0)
{
std::cout << "decoding!" << std::endl;
count--;
}
/*uint8_t *frameData = buffer.data();
int dataSize = buffer.size();
uint8_t *outbuffer = NULL;
int outBufSize = 0;
buffer.empty();*/
// Loop while given a valid size
//while (dataSize)
//{
// // parse the stream out
// int rc = av_parser_parse2(parser, codecContext, &outbuffer, &outBufSize, frameData, dataSize, 0, 0, 0);
std::cout << "emptying buffer, queue_mutex has been locked" << std::endl;
buffer.empty();
SDL_UnlockMutex(queue_mutex);
return data;
}
// Get the horizontal and vertical screen sizes in pixel
void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}
int main()
{
SDL_Event event;
WORD wVersionRequested;
WSADATA wsaData;
int wsaerr;
if (SDL_Init(SDL_INIT_EVERYTHING)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
// Using MAKEWORD macro, Winsock version request 2.2
wVersionRequested = MAKEWORD(2, 2);
wsaerr = WSAStartup(wVersionRequested, &wsaData);
if (wsaerr != 0)
{
/* Tell the user that we could not find a usable */
/* WinSock DLL.*/
printf("The Winsock dll not found!\n");
return 0;
}
else
{
printf("The Winsock dll found!\n");
printf("The status: %s.\n", wsaData.szSystemStatus);
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{
/* Tell the user that we could not find a usable */
/* WinSock DLL.*/
printf("The dll do not support the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
WSACleanup();
return 0;
}
else
{
printf("The dll supports the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
printf("The highest version this dll can support: %u.%u\n", LOBYTE(wsaData.wHighVersion), HIBYTE(wsaData.wHighVersion));
}
CHECK_HR(spDecTransformUnk->QueryInterface(IID_PPV_ARGS(&pDecoderTransform)), "Failed to get IMFTransform interface from H264 MFT.\n");
MFCreateMediaType(&pDecInputMediaType);
pDecInputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pDecInputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
pDecInputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 240000);
CHECK_HR(MFSetAttributeSize(pDecInputMediaType, MF_MT_FRAME_SIZE, 1920, 1080), "Failed to set frame size on H264 MFT.\n");
CHECK_HR(MFSetAttributeRatio(pDecInputMediaType, MF_MT_FRAME_RATE, 30, 1), "Failed to set frame rate on H264 MFT.\n");
CHECK_HR(MFSetAttributeRatio(pDecInputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1), "Failed to set aspect ratio on H264 MFT.\n");
pDecInputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, 2);
pDecInputMediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
CHECK_HR(pDecoderTransform->SetInputType(0, pDecInputMediaType, 0), "Failed to set input medai type on H264 decoder MFT.\n");
MFCreateMediaType(&pDecOutputMediaType);
pDecOutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pDecOutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_IYUV);
CHECK_HR(MFSetAttributeSize(pDecOutputMediaType, MF_MT_FRAME_SIZE, 1920, 1080), "Failed to set frame size on decoder output MFT.\n");
CHECK_HR(MFSetAttributeRatio(pDecOutputMediaType, MF_MT_FRAME_RATE, 30, 1), "Failed to set frame rate on H264 MFT out type.\n");
CHECK_HR(MFSetAttributeRatio(pDecOutputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1), "Failed to set pixel aspect ratio on H264 out type.\n");
pDecOutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, 2);
CHECK_HR(pDecoderTransform->SetOutputType(0, pDecOutputMediaType, 0), "Failed to set output media type on H.264 decoder MFT.\n");
CHECK_HR(pDecoderTransform->GetInputStatus(0, &mftStatus), "Failed to get input status from H.264 decoder MFT.\n");
if (MFT_INPUT_STATUS_ACCEPT_DATA != mftStatus)
{
std::cout << "H.264 decoder MFT is not accepting data.\n";
std::cin.get();
}