1 /* Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
20 #include "gstsparrow.h"
29 load_images(GstSparrow
*sparrow
){
30 int fd
= open(sparrow
->jpeg_blob
, O_RDONLY
);
31 off_t length
= lseek(fd
, 0, SEEK_END
);
32 off_t start
= lseek(fd
, 0, SEEK_SET
);
34 void *mem
= mmap(NULL
, length
, PROT_READ
, MAP_PRIVATE
| MAP_POPULATE
, fd
, 0);
35 madvise(mem
, length
, POSIX_MADV_WILLNEED
);
37 sparrow
->shared
->jpeg_blob
= mem
;
38 sparrow
->shared
->blob_size
= length
;
42 unload_images(GstSparrow
*sparrow
){
43 int munmap(sparrow
->shared
->jpeg_blob
, sparrow
->shared
->blob_size
);
46 GStaticRWLock blob_lock
= G_STATIC_RW_LOCK_INIT
;
47 GStaticRWLock index_lock
= G_STATIC_RW_LOCK_INIT
;
49 /* not using the reader locks (?)
50 g_static_rw_lock_reader_lock ();
51 g_static_rw_lock_reader_unlock ();
55 maybe_load_images(GstSparrow
*sparrow
)
57 if (g_static_rw_lock_writer_trylock(&blob_lock
)){
58 if (sparrow
->shared
->jpeg_blob
== NULL
){
62 GST_WARNING("trying to load images that are already loaded !!\n");
64 g_static_rw_lock_writer_unlock(&blob_lock
);
69 maybe_unload_images(GstSparrow
*sparrow
){
70 if (g_static_rw_lock_writer_trylock(&blob_lock
)){
71 if (sparrow
->shared
->jpeg_blob
){
72 unload_images(sparrow
);
73 sparrow
->shared
->jpeg_blob
= NULL
;
75 g_static_rw_lock_writer_unlock(&blob_lock
);