Boost threads and FFmpeg: Such simple code gives me error C2064. What I do wrong way?
I have some class file.h where public: bool frameSendingFinished;
is defined.
So in class logic i create and encode video frame, now I want to send it to some server using ffmpeg. I want to send in separate thread so in one of my classes function (in file.cpp) I do:
if (frameSendingFinished)
{
boost::thread UrlWriteFrame(url_context, (unsigned char *)pb_buffer, len);
}
....// some other functions code etc.
void VideoEncoder::UrlWriteFrame( URLContext *h, const unsigned char *buf, int size )
{
frameSendingFinished =false;
url_write (h, (unsigned char *)buf, size);
frameSendingFinished =true;
}
it works with out creation of new thread. Commenting thread line makes it compile...
so error is error c2064 term does not evaluate to a function taking 2 arguments
So - what shall I do 开发者_开发问答with my code to make boost work with in my class?
When you write:
boost::thread UrlWriteFrame(url_context, (unsigned char *)pb_buffer, len);
you create a boost::thread object named UrlWriteFrame, and pass url_context
, pb_buffer
and len
the the boost::thread constructor. One of boost::thread's ctors expects something callable (function pointer, function object) as the 1st argument, and forwards the other arguments to that function. In your example, it ends up trying something like:
url_context(pb_buffer, len);
which is probably what triggers the "does not evaluate to a function taking 2 arguments" error.
IIUC, you would like to call the UrlWriteFrame
function in a new thread. The proper way to do that with boost::thread would be something like:
boost::thread (&VideoEncoder::UrlWriteFrame, this, url_context, (unsigned char *)pb_buffer, len);
(Assuming that this is called from one of VideoEncoder's methods)
精彩评论