Skip to content

Commit e17b4f6

Browse files
authored
fix: copy CVPixelBuffer for macOS (#2298)
1 parent 92c4dbd commit e17b4f6

File tree

5 files changed

+415
-1
lines changed

5 files changed

+415
-1
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../shared/darwin/AgoraCVPixelBufferUtils.h
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../shared/darwin/AgoraCVPixelBufferUtils.mm
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#import <AVFoundation/AVFoundation.h>
2+
3+
@interface AgoraCVPixelBufferUtils : NSObject
4+
5+
/**
6+
* Frees all CVPixelBuffer pools.
7+
*
8+
* We use a pool of CVPixelBuffers to avoid allocating and freeing them
9+
* frequently. This method allows us to free all the CVPixelBuffers in the
10+
* pool when needed.
11+
*/
12+
+ (void)freeAllCVPixelBufferPools;
13+
14+
/**
15+
* Creates a copy of a CVPixelBuffer.
16+
*
17+
* Always returns a new CVPixelBuffer with the same properties as the source
18+
* CVPixelBuffer.
19+
*
20+
* @param sourcePixelBuffer The source CVPixelBuffer to copy from
21+
* @return A new CVPixelBuffer containing a copy of the source data
22+
*/
23+
+ (CVPixelBufferRef _Nullable)copyCVPixelBuffer:
24+
(CVPixelBufferRef _Nonnull)sourcePixelBuffer;
25+
26+
27+
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
28+
/**
29+
* Saves a CVPixelBuffer to a PNG file in the documents directory.
30+
*
31+
* @param pixelBuffer The CVPixelBuffer to save
32+
* @param name The filename to save as
33+
* @return YES if successful, NO otherwise
34+
*/
35+
+ (BOOL)saveCVPixelBufferToFile:(CVPixelBufferRef _Nonnull)pixelBuffer
36+
name:(NSString *_Nonnull)name;
37+
#endif
38+
39+
@end

0 commit comments

Comments
 (0)