[FFmpeg-cvslog] ffplay: use lock manager callback to make libavcodec thread-safe
Marton Balint
git at videolan.org
Thu Aug 25 06:57:02 CEST 2011
ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Mon Aug 22 22:26:53 2011 +0200| [ee0ff051f2e0dcc3279a586c97ec756ba102813a] | committer: Michael Niedermayer
ffplay: use lock manager callback to make libavcodec thread-safe
Altough ffplay is working pretty well without using a lock manager, it is still
a multithreaded application calling libavcodec functions from multiple threads,
so using a lock manager is probably a good idea.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ee0ff051f2e0dcc3279a586c97ec756ba102813a
---
ffplay.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/ffplay.c b/ffplay.c
index 80611e8..8d22b48 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -891,6 +891,7 @@ static void do_exit(VideoState *is)
if (is) {
stream_close(is);
}
+ av_lockmgr_register(NULL);
uninit_opts();
#if CONFIG_AVFILTER
avfilter_uninit();
@@ -2988,6 +2989,25 @@ static int opt_help(const char *opt, const char *arg)
return 0;
}
+static int lockmgr(void **mtx, enum AVLockOp op)
+{
+ switch(op) {
+ case AV_LOCK_CREATE:
+ *mtx = SDL_CreateMutex();
+ if(!*mtx)
+ return 1;
+ return 0;
+ case AV_LOCK_OBTAIN:
+ return !!SDL_LockMutex(*mtx);
+ case AV_LOCK_RELEASE:
+ return !!SDL_UnlockMutex(*mtx);
+ case AV_LOCK_DESTROY:
+ SDL_DestroyMutex(*mtx);
+ return 0;
+ }
+ return 1;
+}
+
/* Called from the main */
int main(int argc, char **argv)
{
@@ -3046,6 +3066,11 @@ int main(int argc, char **argv)
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+ if (av_lockmgr_register(lockmgr)) {
+ fprintf(stderr, "Could not initialize lock manager!\n");
+ do_exit(NULL);
+ }
+
av_init_packet(&flush_pkt);
flush_pkt.data= "FLUSH";
More information about the ffmpeg-cvslog
mailing list