reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
MediaResourceCache.cxx
Go to the documentation of this file.
1#include "ReconSubsystem.hxx"
3
4#include <rutil/Log.hxx>
5#include <rutil/Logger.hxx>
7
8using namespace recon;
9using namespace resip;
10using namespace std;
11
12#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
13
17
19{
20 // Clear memory
21 CacheMap::iterator it;
22 for(it = mCacheMap.begin(); it != mCacheMap.end(); it++)
23 {
24 delete it->second;
25 }
26}
27
28void
29MediaResourceCache::addToCache(const resip::Data& name, const resip::Data& buffer, int type)
30{
31 Lock lock(mMutex);
32
33 CacheMap::iterator it = mCacheMap.find(name);
34 if(it != mCacheMap.end())
35 {
36 // Item already present update it
37 // SLG - WARNING - if this cached item is currently being played - there WILL be issues - need to fix this, if calling this at runtime is a requirement
38 it->second->mBuffer = buffer; // copies buffer locally, so that caller can free
39 it->second->mType = type;
40 }
41 else
42 {
43 // Add new item
44 mCacheMap[name] = new CacheItem(buffer, type);
45 }
46}
47
48bool
50{
51 Lock lock(mMutex);
52
53 CacheMap::iterator it = mCacheMap.find(name);
54 if(it != mCacheMap.end())
55 {
56 *buffer = &it->second->mBuffer;
57 *type = it->second->mType;
58 return true;
59 }
60 return false;
61}
62
63
64/* ====================================================================
65
66 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
67 Copyright (c) 2007-2008, Plantronics, Inc.
68 All rights reserved.
69
70 Redistribution and use in source and binary forms, with or without
71 modification, are permitted provided that the following conditions are
72 met:
73
74 1. Redistributions of source code must retain the above copyright
75 notice, this list of conditions and the following disclaimer.
76
77 2. Redistributions in binary form must reproduce the above copyright
78 notice, this list of conditions and the following disclaimer in the
79 documentation and/or other materials provided with the distribution.
80
81 3. Neither the name of Plantronics nor the names of its contributors
82 may be used to endorse or promote products derived from this
83 software without specific prior written permission.
84
85 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
86 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
87 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
88 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
89 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
90 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
91 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96
97 ==================================================================== */
bool getFromCache(const resip::Data &name, resip::Data **buffer, int *type)
void addToCache(const resip::Data &name, const resip::Data &buffer, int type)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
dcm! – add UnusedChecking(_enum) below;
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28