Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: media/capture/video/shared_memory_buffer_tracker.cc

Issue 2818513003: [Mojo Video Capture] Adapt video_capture service to refactored video capture stack (Closed)
Patch Set: Fix compile errors Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/shared_memory_buffer_tracker.h" 5 #include "media/capture/video/shared_memory_buffer_tracker.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "media/capture/video/shared_memory_buffer_handle.h"
8 #include "mojo/public/cpp/system/platform_handle.h" 9 #include "mojo/public/cpp/system/platform_handle.h"
9 10
10 namespace media { 11 namespace media {
11 12
12 SharedMemoryBufferTracker::SharedMemoryBufferTracker() 13 SharedMemoryBufferTracker::SharedMemoryBufferTracker()
13 : VideoCaptureBufferTracker() {} 14 : VideoCaptureBufferTracker() {}
14 15
15 bool SharedMemoryBufferTracker::Init(const gfx::Size& dimensions, 16 bool SharedMemoryBufferTracker::Init(const gfx::Size& dimensions,
16 VideoPixelFormat format, 17 VideoPixelFormat format,
17 VideoPixelStorage storage_type, 18 VideoPixelStorage storage_type,
18 base::Lock* lock) { 19 base::Lock* lock) {
19 DVLOG(2) << __func__ << "allocating ShMem of " << dimensions.ToString(); 20 DVLOG(2) << __func__ << "allocating ShMem of " << dimensions.ToString();
20 set_dimensions(dimensions); 21 set_dimensions(dimensions);
21 // |dimensions| can be 0x0 for trackers that do not require memory backing. 22 // |dimensions| can be 0x0 for trackers that do not require memory backing.
22 set_max_pixel_count(dimensions.GetArea()); 23 set_max_pixel_count(dimensions.GetArea());
23 set_pixel_format(format); 24 set_pixel_format(format);
24 set_storage_type(storage_type); 25 set_storage_type(storage_type);
25 mapped_size_ = VideoCaptureFormat(dimensions, 0.0f, format, storage_type) 26 mapped_size_ = VideoCaptureFormat(dimensions, 0.0f, format, storage_type)
26 .ImageAllocationSize(); 27 .ImageAllocationSize();
27 if (!mapped_size_) 28 if (!mapped_size_)
28 return true; 29 return true;
29 return shared_memory_.CreateAndMapAnonymous(mapped_size_); 30 return shared_memory_.CreateAndMapAnonymous(mapped_size_);
30 } 31 }
31 32
32 std::unique_ptr<VideoCaptureBufferHandle> 33 std::unique_ptr<VideoCaptureBufferHandle>
33 SharedMemoryBufferTracker::GetMemoryMappedAccess() { 34 SharedMemoryBufferTracker::GetMemoryMappedAccess() {
34 return base::MakeUnique<SharedMemoryBufferHandle>(this); 35 return base::MakeUnique<SharedMemoryBufferHandle>(&shared_memory_,
36 mapped_size_);
35 } 37 }
36 38
37 mojo::ScopedSharedBufferHandle 39 mojo::ScopedSharedBufferHandle
38 SharedMemoryBufferTracker::GetHandleForTransit() { 40 SharedMemoryBufferTracker::GetHandleForTransit() {
39 return mojo::WrapSharedMemoryHandle( 41 return mojo::WrapSharedMemoryHandle(
40 base::SharedMemory::DuplicateHandle(shared_memory_.handle()), 42 base::SharedMemory::DuplicateHandle(shared_memory_.handle()),
41 mapped_size_, false /* read_only */); 43 mapped_size_, false /* read_only */);
42 } 44 }
43 45
44 base::SharedMemoryHandle 46 base::SharedMemoryHandle
45 SharedMemoryBufferTracker::GetNonOwnedSharedMemoryHandleForLegacyIPC() { 47 SharedMemoryBufferTracker::GetNonOwnedSharedMemoryHandleForLegacyIPC() {
46 return shared_memory_.handle(); 48 return shared_memory_.handle();
47 } 49 }
48 50
49 SharedMemoryBufferHandle::SharedMemoryBufferHandle(
50 SharedMemoryBufferTracker* tracker)
51 : tracker_(tracker) {}
52
53 SharedMemoryBufferHandle::~SharedMemoryBufferHandle() = default;
54
55 size_t SharedMemoryBufferHandle::mapped_size() const {
56 return tracker_->mapped_size_;
57 }
58
59 uint8_t* SharedMemoryBufferHandle::data() {
60 return static_cast<uint8_t*>(tracker_->shared_memory_.memory());
61 }
62
63 const uint8_t* SharedMemoryBufferHandle::data() const {
64 return static_cast<const uint8_t*>(tracker_->shared_memory_.memory());
65 }
66
67 } // namespace media 51 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/shared_memory_buffer_tracker.h ('k') | media/capture/video/video_capture_buffer_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698