fix(macos): fix broken streaming on MacOS (#2485)
This commit is contained in:
@@ -31,6 +31,9 @@ namespace platf {
|
||||
capture_e
|
||||
capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override {
|
||||
auto signal = [av_capture capture:^(CMSampleBufferRef sampleBuffer) {
|
||||
auto new_sample_buffer = std::make_shared<av_sample_buf_t>(sampleBuffer);
|
||||
auto new_pixel_buffer = std::make_shared<av_pixel_buf_t>(new_sample_buffer->buf);
|
||||
|
||||
std::shared_ptr<img_t> img_out;
|
||||
if (!pull_free_image_cb(img_out)) {
|
||||
// got interrupt signal
|
||||
@@ -39,17 +42,22 @@ namespace platf {
|
||||
}
|
||||
auto av_img = std::static_pointer_cast<av_img_t>(img_out);
|
||||
|
||||
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
||||
auto old_data_retainer = std::make_shared<temp_retain_av_img_t>(
|
||||
av_img->sample_buffer,
|
||||
av_img->pixel_buffer,
|
||||
img_out->data);
|
||||
|
||||
av_img->sample_buffer = std::make_shared<av_sample_buf_t>(sampleBuffer);
|
||||
av_img->pixel_buffer = std::make_shared<av_pixel_buf_t>(pixelBuffer);
|
||||
img_out->data = av_img->pixel_buffer->lock();
|
||||
av_img->sample_buffer = new_sample_buffer;
|
||||
av_img->pixel_buffer = new_pixel_buffer;
|
||||
img_out->data = new_pixel_buffer->data();
|
||||
|
||||
img_out->width = (int) CVPixelBufferGetWidth(pixelBuffer);
|
||||
img_out->height = (int) CVPixelBufferGetHeight(pixelBuffer);
|
||||
img_out->row_pitch = (int) CVPixelBufferGetBytesPerRow(pixelBuffer);
|
||||
img_out->width = (int) CVPixelBufferGetWidth(new_pixel_buffer->buf);
|
||||
img_out->height = (int) CVPixelBufferGetHeight(new_pixel_buffer->buf);
|
||||
img_out->row_pitch = (int) CVPixelBufferGetBytesPerRow(new_pixel_buffer->buf);
|
||||
img_out->pixel_pitch = img_out->row_pitch / img_out->width;
|
||||
|
||||
old_data_retainer = nullptr;
|
||||
|
||||
if (!push_captured_image_cb(std::move(img_out), true)) {
|
||||
// got interrupt signal
|
||||
// returning false here stops capture backend
|
||||
@@ -93,19 +101,27 @@ namespace platf {
|
||||
int
|
||||
dummy_img(img_t *img) override {
|
||||
auto signal = [av_capture capture:^(CMSampleBufferRef sampleBuffer) {
|
||||
auto new_sample_buffer = std::make_shared<av_sample_buf_t>(sampleBuffer);
|
||||
auto new_pixel_buffer = std::make_shared<av_pixel_buf_t>(new_sample_buffer->buf);
|
||||
|
||||
auto av_img = (av_img_t *) img;
|
||||
|
||||
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
||||
auto old_data_retainer = std::make_shared<temp_retain_av_img_t>(
|
||||
av_img->sample_buffer,
|
||||
av_img->pixel_buffer,
|
||||
img->data);
|
||||
|
||||
av_img->sample_buffer = std::make_shared<av_sample_buf_t>(sampleBuffer);
|
||||
av_img->pixel_buffer = std::make_shared<av_pixel_buf_t>(pixelBuffer);
|
||||
img->data = av_img->pixel_buffer->lock();
|
||||
av_img->sample_buffer = new_sample_buffer;
|
||||
av_img->pixel_buffer = new_pixel_buffer;
|
||||
img->data = new_pixel_buffer->data();
|
||||
|
||||
img->width = (int) CVPixelBufferGetWidth(pixelBuffer);
|
||||
img->height = (int) CVPixelBufferGetHeight(pixelBuffer);
|
||||
img->row_pitch = (int) CVPixelBufferGetBytesPerRow(pixelBuffer);
|
||||
img->width = (int) CVPixelBufferGetWidth(new_pixel_buffer->buf);
|
||||
img->height = (int) CVPixelBufferGetHeight(new_pixel_buffer->buf);
|
||||
img->row_pitch = (int) CVPixelBufferGetBytesPerRow(new_pixel_buffer->buf);
|
||||
img->pixel_pitch = img->row_pitch / img->width;
|
||||
|
||||
old_data_retainer = nullptr;
|
||||
|
||||
// returning false here stops capture backend
|
||||
return false;
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user