MCPcopy Create free account
hub / github.com/aethersdr/AetherSDR / openShmSegment

Function openShmSegment

src/core/VirtualAudioBridge.cpp:49–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49static bool openShmSegment(const char* name, int& fd, DaxShmBlock*& block)
50{
51 // Try to open existing segment first (HAL plugin may already have it mapped).
52 fd = shm_open(name, O_RDWR, 0666);
53 if (fd < 0) {
54 // Does not exist yet — create it.
55 fd = shm_open(name, O_CREAT | O_RDWR, 0666);
56 if (fd < 0) {
57 qCWarning(lcDax) << "VirtualAudioBridge: shm_open failed for" << name;
58 return false;
59 }
60 if (ftruncate(fd, sizeof(DaxShmBlock)) != 0) {
61 qCWarning(lcDax) << "VirtualAudioBridge: ftruncate failed for" << name;
62 ::close(fd);
63 fd = -1;
64 return false;
65 }
66 }
67 // else: segment already exists at the right size — reuse it so the
68 // HAL plugin's existing mmap stays valid.
69
70 void* ptr = mmap(nullptr, sizeof(DaxShmBlock), PROT_READ | PROT_WRITE,
71 MAP_SHARED, fd, 0);
72 if (ptr == MAP_FAILED) {
73 qCWarning(lcDax) << "VirtualAudioBridge: mmap failed for" << name;
74 ::close(fd);
75 fd = -1;
76 return false;
77 }
78
79 // Re-initialize the header fields (resets write/read positions).
80 auto* b = static_cast<DaxShmBlock*>(ptr);
81 b->writePos.store(0, std::memory_order_relaxed);
82 b->readPos.store(0, std::memory_order_relaxed);
83 b->sampleRate = 24000;
84 b->channels = 2;
85 block = b;
86 return true;
87}
88
89bool VirtualAudioBridge::open()
90{

Callers 1

openMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected