/work/obj-fuzz/dist/include/AllocationHandle.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef AllocationHandle_h |
8 | | #define AllocationHandle_h |
9 | | |
10 | | #include <cstdint> |
11 | | #include <limits> |
12 | | |
13 | | #include "MediaEnginePrefs.h" |
14 | | #include "MediaManager.h" |
15 | | #include "MediaTrackConstraints.h" |
16 | | #include "mozilla/Assertions.h" |
17 | | #include "mozilla/ipc/PBackgroundSharedTypes.h" |
18 | | #include "nsString.h" |
19 | | |
20 | | namespace mozilla { |
21 | | |
22 | | /** |
23 | | * AllocationHandle helps keep track of metadata for allocations of shared |
24 | | * MediaEngineSources. That is, for MediaEngineSources that support more than |
25 | | * one concurrent allocation. |
26 | | */ |
27 | | class AllocationHandle |
28 | | { |
29 | 0 | ~AllocationHandle() = default; |
30 | | |
31 | | public: |
32 | | static uint64_t GetUniqueId() |
33 | | { |
34 | | static uint64_t sId = 0; |
35 | | |
36 | | MOZ_ASSERT(MediaManager::GetIfExists()); |
37 | | MOZ_ASSERT(MediaManager::GetIfExists()->IsInMediaThread()); |
38 | | MOZ_RELEASE_ASSERT(sId < std::numeric_limits<decltype(sId)>::max()); |
39 | | return sId++; |
40 | | } |
41 | | |
42 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AllocationHandle); |
43 | | |
44 | | AllocationHandle() = delete; |
45 | | AllocationHandle(const dom::MediaTrackConstraints& aConstraints, |
46 | | const ipc::PrincipalInfo& aPrincipalInfo, |
47 | | const nsString& aDeviceId) |
48 | | : mId(GetUniqueId()) |
49 | | , mDeviceId(aDeviceId) |
50 | | , mPrincipalInfo(aPrincipalInfo) |
51 | | , mConstraints(aConstraints) |
52 | | {} |
53 | | |
54 | | const uint64_t mId; |
55 | | const nsString mDeviceId; |
56 | | const ipc::PrincipalInfo mPrincipalInfo; |
57 | | NormalizedConstraints mConstraints; |
58 | | }; |
59 | | |
60 | | } // namespace mozilla |
61 | | |
62 | | #endif // AllocationHandle_h |