1 /*
2 * GPAC - Multimedia Framework C SDK
3 *
4 * Authors: Arash Shafiei
5 * Copyright (c) Telecom ParisTech 2000-2013
6 * All rights reserved
7 *
8 * This file is part of GPAC / dashcast
9 *
10 * GPAC is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * GPAC is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26 #include "register.h"
27
28
29 static GF_List *av_mutex = NULL;
30
lock_call_back(void ** mutex,enum AVLockOp op)31 int lock_call_back(void ** mutex, enum AVLockOp op)
32 {
33 switch (op) {
34 case AV_LOCK_CREATE:
35 {
36 static int i = 0;
37 char mxName[64];
38 snprintf(mxName, 64, "AVLIB callback mutex %d", i++);
39 *mutex = gf_mx_new(mxName);
40 gf_list_add(av_mutex, *mutex);
41 break;
42 }
43 case AV_LOCK_OBTAIN:
44 gf_mx_p(*mutex);
45 break;
46 case AV_LOCK_RELEASE:
47 gf_mx_v(*mutex);
48 break;
49 case AV_LOCK_DESTROY:
50 gf_list_del_item(av_mutex, *mutex);
51 gf_mx_del(*mutex);
52 *mutex = NULL;
53 break;
54 }
55
56 return 0;
57 }
58
dc_register_libav()59 void dc_register_libav()
60 {
61 av_mutex = gf_list_new();
62
63 av_register_all();
64 avcodec_register_all();
65 avdevice_register_all();
66 avformat_network_init();
67
68 av_lockmgr_register(&lock_call_back);
69 }
70
dc_unregister_libav()71 void dc_unregister_libav()
72 {
73 av_lockmgr_register(NULL);
74
75 if (av_mutex) {
76 while (gf_list_count(av_mutex)) {
77 GF_Mutex *mx = (GF_Mutex*)gf_list_last(av_mutex);
78 gf_list_rem_last(av_mutex);
79 gf_mx_del(mx);
80 }
81 gf_list_del(av_mutex);
82 av_mutex = NULL;
83 }
84 }
85
86