Skip to content

Commit

Permalink
Merge pull request #90 from hakobera/fix/macos
Browse files Browse the repository at this point in the history
macOS 版がビルドは成功するが動作させようとするとセグメンテーションフォルトする問題の修正
  • Loading branch information
voluntas authored Aug 8, 2019
2 parents 481010c + df5887f commit 31bf2d6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ $(foreach package_name, $(PACKAGE_NAMES), $(eval $(call generateDockerRules,$(pa

.PHONY: macos
macos: macos.prepare
make -C .. MOMO_CFLAGS="-O2" PACKAGE_NAME=macos MOMO_VERSION=${MOMO_VERSION} momo
make -C .. MOMO_CFLAGS="-O2 -fobjc-arc" PACKAGE_NAME=macos MOMO_VERSION=${MOMO_VERSION} momo

.PHONY: macos.package
macos.package: macos.prepare
# momo を package モードでビルドし直す
rm -f ../_build/macos/momo && make -C .. MOMO_CFLAGS="-O2" PACKAGE_NAME=macos BUILD_MODE=package momo
rm -f ../_build/macos/momo && make -C .. MOMO_CFLAGS="-O2 -fobjc-arc" PACKAGE_NAME=macos BUILD_MODE=package momo

# パッケージのバイナリを作る
rm -rf package/momo-$(MOMO_VERSION)_macos
Expand Down
8 changes: 6 additions & 2 deletions src/mac_helper/mac_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

#include "api/media_stream_interface.h"
#include "api/scoped_refptr.h"
#include "base/RTCMacros.h"
#include "modules/video_capture/video_capture.h"
#include "rtc_base/thread.h"

#include "rtc/scalable_track_source.h"

RTC_FWD_DECL_OBJC_CLASS(RTCCameraVideoCapturer);
RTC_FWD_DECL_OBJC_CLASS(RTCVideoSourceAdapter);

class MacCapturer : public ScalableVideoTrackSource,
public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
Expand All @@ -38,8 +42,8 @@ class MacCapturer : public ScalableVideoTrackSource,
private:
void Destroy();

void* capturer_;
void* adapter_;
RTCCameraVideoCapturer* capturer_;
RTCVideoSourceAdapter* adapter_;
};

#endif // TEST_MAC_CAPTURER_H_
17 changes: 5 additions & 12 deletions src/mac_helper/mac_capturer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFram
size_t height,
size_t target_fps,
size_t capture_device_index) {
RTCVideoSourceAdapter *adapter = [[RTCVideoSourceAdapter alloc] init];
adapter_ = (__bridge_retained void *)adapter;
adapter.capturer = this;
adapter_ = [[RTCVideoSourceAdapter alloc] init];
adapter_.capturer = this;

RTCCameraVideoCapturer *capturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:adapter];
capturer_ = (__bridge_retained void *)capturer;
capturer_ = [[RTCCameraVideoCapturer alloc] initWithDelegate:adapter_];

AVCaptureDevice *device =
[[RTCCameraVideoCapturer captureDevices] objectAtIndex:capture_device_index];
AVCaptureDeviceFormat *format = SelectClosestFormat(device, width, height);
[capturer startCaptureWithDevice:device format:format fps:target_fps];
[capturer_ startCaptureWithDevice:device format:format fps:target_fps];
}

rtc::scoped_refptr<MacCapturer> MacCapturer::Create(size_t width,
Expand All @@ -81,12 +79,7 @@ - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFram
}

void MacCapturer::Destroy() {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
RTCVideoSourceAdapter *adapter = (__bridge_transfer RTCVideoSourceAdapter *)adapter_;
RTCCameraVideoCapturer *capturer = (__bridge_transfer RTCCameraVideoCapturer *)capturer_;
[capturer stopCapture];
#pragma clang diagnostic pop
[capturer_ stopCapture];
}

MacCapturer::~MacCapturer() {
Expand Down
2 changes: 1 addition & 1 deletion src/rtc/scalable_track_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ScalableVideoTrackSource::OnCapturedFrame(const webrtc::VideoFrame& frame)
return;
}

if (frame.video_frame_buffer()->type() == webrtc::VideoFrameBuffer::Type::kNative)
if (useNativeBuffer() && frame.video_frame_buffer()->type() == webrtc::VideoFrameBuffer::Type::kNative)
{
NativeBuffer* frame_buffer = dynamic_cast<NativeBuffer*>(frame.video_frame_buffer().get());
frame_buffer->SetScaledSize(adapted_width, adapted_height);
Expand Down
1 change: 1 addition & 0 deletions src/rtc/scalable_track_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ScalableVideoTrackSource : public rtc::AdaptedVideoTrackSource {
webrtc::MediaSourceInterface::SourceState state() const override;
bool remote() const override;
void OnCapturedFrame(const webrtc::VideoFrame& frame);
bool useNativeBuffer() { return false; }

private:
rtc::TimestampAligner timestamp_aligner_;
Expand Down
10 changes: 7 additions & 3 deletions src/v4l2_video_capturer/v4l2_video_capturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ int32_t V4L2VideoCapture::StopCapture() {
return 0;
}

bool V4L2VideoCapture::useNativeBuffer() {
return _useNative &&
(_captureVideoType == webrtc::VideoType::kMJPEG ||
_captureVideoType == webrtc::VideoType::kI420);
}

// critical section protected by the caller

bool V4L2VideoCapture::AllocateVideoBuffers() {
Expand Down Expand Up @@ -439,9 +445,7 @@ bool V4L2VideoCapture::CaptureProcess() {
}

rtc::scoped_refptr<webrtc::VideoFrameBuffer> dst_buffer = nullptr;
if (_useNative &&
(_captureVideoType == webrtc::VideoType::kMJPEG ||
_captureVideoType == webrtc::VideoType::kI420))
if (useNativeBuffer())
{
rtc::scoped_refptr<NativeBuffer> native_buffer(
NativeBuffer::Create(
Expand Down
2 changes: 2 additions & 0 deletions src/v4l2_video_capturer/v4l2_video_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class V4L2VideoCapture : public ScalableVideoTrackSource {
int32_t Init(const char* deviceUniqueId);
int32_t StartCapture(ConnectionSettings cs);

bool useNativeBuffer() override;

private:
enum { kNoOfV4L2Bufffers = 4 };

Expand Down

0 comments on commit 31bf2d6

Please sign in to comment.