Sunshine master
Self-hosted game stream host for Moonlight.
av_img_t.h
Go to the documentation of this file.
1
5#pragma once
6
7// platform includes
8#include <CoreMedia/CoreMedia.h>
9#include <CoreVideo/CoreVideo.h>
10
11// local includes
12#include "src/platform/common.h"
13
14namespace platf {
19 CMSampleBufferRef buf;
20
26 explicit av_sample_buf_t(CMSampleBufferRef buf):
27 buf((CMSampleBufferRef) CFRetain(buf)) {
28 }
29
31 if (buf != nullptr) {
32 CFRelease(buf);
33 }
34 }
35 };
36
41 CVPixelBufferRef buf;
42
43 // Constructor
49 explicit av_pixel_buf_t(CMSampleBufferRef sb):
50 buf(
51 CMSampleBufferGetImageBuffer(sb)
52 ) {
53 CVPixelBufferLockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
54 }
55
61 [[nodiscard]] uint8_t *data() const {
62 return static_cast<uint8_t *>(CVPixelBufferGetBaseAddress(buf));
63 }
64
65 // Destructor
67 if (buf != nullptr) {
68 CVPixelBufferUnlockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
69 }
70 }
71 };
72
76 struct av_img_t: img_t {
77 std::shared_ptr<av_sample_buf_t> sample_buffer;
78 std::shared_ptr<av_pixel_buf_t> pixel_buffer;
79 };
80
85 std::shared_ptr<av_sample_buf_t> sample_buffer;
86 std::shared_ptr<av_pixel_buf_t> pixel_buffer;
87 uint8_t *data;
88
97 std::shared_ptr<av_sample_buf_t> sb,
98 std::shared_ptr<av_pixel_buf_t> pb,
99 uint8_t *dt
100 ):
101 sample_buffer(std::move(sb)),
102 pixel_buffer(std::move(pb)),
103 data(dt) {
104 }
105 };
106} // namespace platf
Declarations for common platform specific utilities.
Captured macOS image backed by an AV sample buffer.
Definition av_img_t.h:76
std::shared_ptr< av_sample_buf_t > sample_buffer
Retained AVFoundation sample buffer for the captured frame.
Definition av_img_t.h:77
std::shared_ptr< av_pixel_buf_t > pixel_buffer
Retained CoreVideo pixel buffer extracted from the sample.
Definition av_img_t.h:78
CoreVideo pixel buffer retained by an AV image wrapper.
Definition av_img_t.h:40
av_pixel_buf_t(CMSampleBufferRef sb)
Lock the sample buffer's pixel buffer for read-only access.
Definition av_img_t.h:49
uint8_t * data() const
Return the base address of the locked Core Video pixel buffer.
Definition av_img_t.h:61
CVPixelBufferRef buf
Pixel buffer extracted from the sample buffer.
Definition av_img_t.h:41
CoreMedia sample buffer retained by an AV image wrapper.
Definition av_img_t.h:18
av_sample_buf_t(CMSampleBufferRef buf)
Retain a CoreMedia sample buffer for captured-image lifetime.
Definition av_img_t.h:26
CMSampleBufferRef buf
Retained CoreMedia sample buffer.
Definition av_img_t.h:19
Captured frame buffer shared between capture and encode stages.
Definition common.h:502
Temporary retain wrapper used while AV image data is borrowed.
Definition av_img_t.h:84
temp_retain_av_img_t(std::shared_ptr< av_sample_buf_t > sb, std::shared_ptr< av_pixel_buf_t > pb, uint8_t *dt)
Construct a temporary AV image retain wrapper.
Definition av_img_t.h:96
std::shared_ptr< av_pixel_buf_t > pixel_buffer
Pixel buffer kept locked while data is borrowed.
Definition av_img_t.h:86
std::shared_ptr< av_sample_buf_t > sample_buffer
Sample buffer kept alive while data is borrowed.
Definition av_img_t.h:85
uint8_t * data
Pointer to the locked pixel buffer bytes.
Definition av_img_t.h:87