fix(macos): fix broken streaming on MacOS (#2485)
This commit is contained in:
@@ -11,42 +11,56 @@
|
||||
|
||||
namespace platf {
|
||||
struct av_sample_buf_t {
|
||||
CMSampleBufferRef buf;
|
||||
|
||||
explicit av_sample_buf_t(CMSampleBufferRef buf):
|
||||
buf((CMSampleBufferRef) CFRetain(buf)) {}
|
||||
|
||||
~av_sample_buf_t() {
|
||||
CFRelease(buf);
|
||||
if (buf != nullptr) {
|
||||
CFRelease(buf);
|
||||
}
|
||||
}
|
||||
|
||||
CMSampleBufferRef buf;
|
||||
};
|
||||
|
||||
struct av_pixel_buf_t {
|
||||
explicit av_pixel_buf_t(CVPixelBufferRef buf):
|
||||
buf((CVPixelBufferRef) CFRetain(buf)),
|
||||
locked(false) {}
|
||||
CVPixelBufferRef buf;
|
||||
|
||||
// Constructor
|
||||
explicit av_pixel_buf_t(CMSampleBufferRef sb):
|
||||
buf(
|
||||
CMSampleBufferGetImageBuffer(sb)) {
|
||||
CVPixelBufferLockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t *
|
||||
lock() const {
|
||||
if (!locked) {
|
||||
CVPixelBufferLockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
|
||||
}
|
||||
return (uint8_t *) CVPixelBufferGetBaseAddress(buf);
|
||||
data() const {
|
||||
return static_cast<uint8_t *>(CVPixelBufferGetBaseAddress(buf));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
~av_pixel_buf_t() {
|
||||
if (locked) {
|
||||
if (buf != nullptr) {
|
||||
CVPixelBufferUnlockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
|
||||
}
|
||||
CFRelease(buf);
|
||||
}
|
||||
|
||||
CVPixelBufferRef buf;
|
||||
bool locked;
|
||||
};
|
||||
|
||||
struct av_img_t: public img_t {
|
||||
struct av_img_t: img_t {
|
||||
std::shared_ptr<av_sample_buf_t> sample_buffer;
|
||||
std::shared_ptr<av_pixel_buf_t> pixel_buffer;
|
||||
};
|
||||
|
||||
struct temp_retain_av_img_t {
|
||||
std::shared_ptr<av_sample_buf_t> sample_buffer;
|
||||
std::shared_ptr<av_pixel_buf_t> pixel_buffer;
|
||||
uint8_t *data;
|
||||
|
||||
temp_retain_av_img_t(
|
||||
std::shared_ptr<av_sample_buf_t> sb,
|
||||
std::shared_ptr<av_pixel_buf_t> pb,
|
||||
uint8_t *dt):
|
||||
sample_buffer(std::move(sb)),
|
||||
pixel_buffer(std::move(pb)), data(dt) {}
|
||||
};
|
||||
} // namespace platf
|
||||
|
||||
Reference in New Issue
Block a user