1 /* 2 * Copyright 2002, Marcus Overhagen. All rights reserved. 3 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <set> 9 10 #include <Locker.h> 11 #include <MediaDefs.h> 12 13 #include <HashMap.h> 14 15 16 struct _shared_buffer_list; 17 18 19 class BufferManager { 20 public: 21 BufferManager(); 22 ~BufferManager(); 23 24 area_id SharedBufferListID(); 25 26 status_t RegisterBuffer(team_id team, 27 media_buffer_id bufferID, size_t* _size, 28 int32* _flags, size_t* _offset, area_id* _area); 29 30 status_t RegisterBuffer(team_id team, size_t size, 31 int32 flags, size_t offset, area_id area, 32 media_buffer_id* _bufferID); 33 34 status_t UnregisterBuffer(team_id team, 35 media_buffer_id bufferID); 36 37 void CleanupTeam(team_id team); 38 39 void Dump(); 40 41 private: 42 area_id _CloneArea(area_id area); 43 void _ReleaseClonedArea(area_id clone); 44 45 private: 46 struct clone_info { 47 area_id clone; 48 vint32 ref_count; 49 }; 50 51 struct buffer_info { 52 media_buffer_id id; 53 area_id area; 54 size_t offset; 55 size_t size; 56 int32 flags; 57 std::set<team_id> teams; 58 }; 59 60 template<typename Type> struct id_hash { 61 id_hash() 62 : 63 fID(0) 64 { 65 } 66 67 id_hash(Type id) 68 : 69 fID(id) 70 { 71 } 72 73 id_hash(const id_hash& other) 74 { 75 fID = other.fID; 76 } 77 78 uint32 GetHashCode() const 79 { 80 return fID; 81 } 82 83 operator Type() const 84 { 85 return fID; 86 } 87 88 id_hash& operator=(const id_hash& other) 89 { 90 fID = other.fID; 91 return *this; 92 } 93 94 private: 95 Type fID; 96 }; 97 98 typedef HashMap<id_hash<media_buffer_id>, buffer_info> BufferInfoMap; 99 typedef HashMap<id_hash<area_id>, clone_info> CloneInfoMap; 100 typedef HashMap<id_hash<area_id>, area_id> SourceInfoMap; 101 102 _shared_buffer_list* fSharedBufferList; 103 area_id fSharedBufferListID; 104 media_buffer_id fNextBufferID; 105 BLocker fLocker; 106 BufferInfoMap fBufferInfoMap; 107 CloneInfoMap fCloneInfoMap; 108 SourceInfoMap fSourceInfoMap; 109 }; 110 111