Skip to content

Commit

Permalink
vfxgraph-webcam: Compile fix when SSE is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel303 authored and Marcel Smit committed May 7, 2023
1 parent 1d6b8be commit 5b65e55
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion vfxGraph/vfxNodes/macWebcam.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
#import <AVFoundation/AVFoundation.h>
#include <SDL2/SDL.h>

#ifdef __SSE2__
#define USE_SSE 1
#else
#define USE_SSE 0
#endif

@interface MacWebcamImpl : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
@property (assign) AVCaptureSession * session;
@property (assign) AVCaptureDevice * device;
Expand Down Expand Up @@ -242,6 +248,8 @@ - (void)shutContext
}
}

#if USE_SSE == 1

static __m128i swizzle(const __m128i src)
{
__m128i srcL = _mm_unpacklo_epi8(src, _mm_setzero_si128());
Expand All @@ -256,6 +264,8 @@ static __m128i swizzle(const __m128i src)
return _mm_packus_epi16(srcL, srcH);
}

#endif

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
Expand Down Expand Up @@ -284,7 +294,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput

uint64_t t1 = g_TimerRT.TimeUS_get();

#if 1
#if USE_SSE == 1
for (int y = 0; y < sy; ++y)
{
const uint8_t * __restrict srcPtr = baseAddress + y * bytesPerRow;
Expand Down Expand Up @@ -383,12 +393,20 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput
, pitch(0)
, data(nullptr)
{
#if USE_SSE == 1
data = (uint8_t*)_mm_malloc(sx * sy * 4, 16);
#else
data = (uint8_t*)malloc(sx * sy * 4);
#endif
}

MacWebcamImage::~MacWebcamImage()
{
#if USE_SSE == 1
_mm_free(data);
#else
free(data);
#endif
data = nullptr;
}

Expand Down

0 comments on commit 5b65e55

Please sign in to comment.