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 #ifndef _BUFFER_MANAGER_H 7 #define _BUFFER_MANAGER_H 8 9 #include <set> 10 11 #include <Locker.h> 12 #include <MediaDefs.h> 13 14 #include <HashMap.h> 15 16 17 namespace BPrivate { 18 class SharedBufferList; 19 } 20 21 22 class BufferManager { 23 public: 24 BufferManager(); 25 ~BufferManager(); 26 27 area_id SharedBufferListArea(); 28 29 status_t RegisterBuffer(team_id team, 30 media_buffer_id bufferID, size_t* _size, 31 int32* _flags, size_t* _offset, area_id* _area); 32 33 status_t RegisterBuffer(team_id team, size_t size, 34 int32 flags, size_t offset, area_id area, 35 media_buffer_id* _bufferID); 36 37 status_t UnregisterBuffer(team_id team, 38 media_buffer_id bufferID); 39 40 void CleanupTeam(team_id team); 41 42 void Dump(); 43 44 private: 45 area_id _CloneArea(area_id area); 46 void _ReleaseClonedArea(area_id clone); 47 48 private: 49 struct clone_info { 50 area_id clone; 51 vint32 ref_count; 52 }; 53 54 struct buffer_info { 55 media_buffer_id id; 56 area_id area; 57 size_t offset; 58 size_t size; 59 int32 flags; 60 std::set<team_id> teams; 61 }; 62 63 typedef HashMap<HashKey32<media_buffer_id>, buffer_info> BufferInfoMap; 64 typedef HashMap<HashKey32<area_id>, clone_info> CloneInfoMap; 65 typedef HashMap<HashKey32<area_id>, area_id> SourceInfoMap; 66 67 BPrivate::SharedBufferList* fSharedBufferList; 68 area_id fSharedBufferListArea; 69 media_buffer_id fNextBufferID; 70 BLocker fLocker; 71 BufferInfoMap fBufferInfoMap; 72 CloneInfoMap fCloneInfoMap; 73 SourceInfoMap fSourceInfoMap; 74 }; 75 76 #endif // _BUFFER_MANAGER_H 77