• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/sys_info.h"
6 #include "shared_memory_region.h"
7 
8 namespace media {
9 
SharedMemoryRegion(const base::SharedMemoryHandle & handle,off_t offset,size_t size,bool read_only)10 SharedMemoryRegion::SharedMemoryRegion(const base::SharedMemoryHandle& handle,
11                                        off_t offset,
12                                        size_t size,
13                                        bool read_only)
14     : shm_(handle, read_only),
15       offset_(offset),
16       size_(size),
17       alignment_size_(offset % base::SysInfo::VMAllocationGranularity()) {
18   DCHECK_GE(offset_, 0) << "Invalid offset: " << offset_;
19 }
20 
SharedMemoryRegion(const BitstreamBuffer & bitstream_buffer,bool read_only)21 SharedMemoryRegion::SharedMemoryRegion(const BitstreamBuffer& bitstream_buffer,
22                                        bool read_only)
23     : SharedMemoryRegion(bitstream_buffer.handle(),
24                          bitstream_buffer.offset(),
25                          bitstream_buffer.size(),
26                          read_only) {}
27 
Map()28 bool SharedMemoryRegion::Map() {
29   if (offset_ < 0) {
30     DVLOG(1) << "Invalid offset: " << offset_;
31     return false;
32   }
33   return shm_.MapAt(offset_ - alignment_size_, size_ + alignment_size_);
34 }
35 
memory()36 void* SharedMemoryRegion::memory() {
37   int8_t* addr = reinterpret_cast<int8_t*>(shm_.memory());
38   return addr ? addr + alignment_size_ : nullptr;
39 }
40 
41 }  // namespace media
42