sdl
sdl 是一个集成了opengl, d3d, 声音等功能得lib,同时封装了线程和互斥等待等方法,在制作播放器得过程中,可以使用sdl 封装得方法来达到自己想要得过程,又有时间,定时器,图形,这些封装可以使用,所以播放器最好直接使用sdl很多封装好得功能,其好处在于: 1 支持c和c++ 2 方法简单 3 良好配合ffmpeg 4 将opengl和d3d等细节过滤,不用过多涉及
互斥sample
#include
#include
#include
SDL_bool condition = SDL_FALSE;
SDL_mutex *lock;
SDL_cond *cond;
#ifdef WIN32
#pragma comment(lib,"../lib/sdl2.lib")
#pragma comment(lib,"../lib/sdl2main.lib")
#endif
int test = 10;
int threadA(void *arg) {
SDL_LockMutex(lock);
printf("in thread A\n");
test = 12;
printf("test is %d\n",test);
SDL_UnlockMutex(lock);
return 0;
}
int threadB(void *arg) {
SDL_LockMutex(lock);
printf("in thread B\n");
test = 13;
printf("test is %d\n", test);
SDL_CondWait(cond, lock);
test = 14;
printf("test is %d\n", test);
SDL_UnlockMutex(lock);
return 0;
}
int main(int argv, char* argc[])
{
lock = SDL_CreateMutex();
cond = SDL_CreateCond();
SDL_Thread * t1 = SDL_CreateThread(threadA, "threada", NULL);
SDL_Thread * t2 = SDL_CreateThread(threadB, "threadb", NULL);
SDL_LockMutex(lock);
printf("send signal====================>\n");
SDL_CondSignal(cond);
SDL_UnlockMutex(lock);
SDL_DestroyCond(cond);
SDL_DestroyMutex(lock);
SDL_Quit();
getchar();
return 0;
}
结果如图