Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64b11b0

Browse files
author
Arlin
committed
Add RawVideoData base v3.7.0 by mac
1 parent 72f74d9 commit 64b11b0

File tree

7 files changed

+442
-25
lines changed

7 files changed

+442
-25
lines changed

macOS/APIExample.xcodeproj/project.pbxproj

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
033A9FA0252EA86A00BC26E1 /* CustomAudioSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033A9F94252EA86A00BC26E1 /* CustomAudioSource.swift */; };
2626
033A9FA1252EA86A00BC26E1 /* CustomAudioRender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033A9F96252EA86A00BC26E1 /* CustomAudioRender.swift */; };
2727
033A9FA4252EA86A00BC26E1 /* RTMPStreaming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033A9F9B252EA86A00BC26E1 /* RTMPStreaming.swift */; };
28-
033A9FA5252EA86A00BC26E1 /* RawMediaData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033A9F9D252EA86A00BC26E1 /* RawMediaData.swift */; };
2928
033A9FB3252EAEB500BC26E1 /* JoinChannelVideo.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FB5252EAEB500BC26E1 /* JoinChannelVideo.storyboard */; };
3029
033A9FB8252EAEF700BC26E1 /* JoinChannelAudio.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FBA252EAEF700BC26E1 /* JoinChannelAudio.storyboard */; };
3130
033A9FBD252EB02600BC26E1 /* CustomAudioRender.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FBF252EB02600BC26E1 /* CustomAudioRender.storyboard */; };
3231
033A9FC2252EB02D00BC26E1 /* CustomAudioSource.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FC4252EB02D00BC26E1 /* CustomAudioSource.storyboard */; };
3332
033A9FC7252EB03700BC26E1 /* CustomVideoRender.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FC9252EB03700BC26E1 /* CustomVideoRender.storyboard */; };
3433
033A9FCC252EB03F00BC26E1 /* CustomVideoSourcePush.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FCE252EB03F00BC26E1 /* CustomVideoSourcePush.storyboard */; };
35-
033A9FD1252EB04700BC26E1 /* RawMediaData.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FD3252EB04700BC26E1 /* RawMediaData.storyboard */; };
3634
033A9FD6252EB05200BC26E1 /* RTMPStreaming.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FD8252EB05200BC26E1 /* RTMPStreaming.storyboard */; };
3735
033A9FDB252EB05A00BC26E1 /* PrecallTest.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FDD252EB05A00BC26E1 /* PrecallTest.storyboard */; };
3836
033A9FE0252EB58600BC26E1 /* CustomVideoSourceMediaIO.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 033A9FE2252EB58600BC26E1 /* CustomVideoSourceMediaIO.storyboard */; };
@@ -87,6 +85,9 @@
8785
57AF397B259B31AA00601E02 /* RawAudioData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57AF397A259B31AA00601E02 /* RawAudioData.swift */; };
8886
57AF3981259B329B00601E02 /* RawAudioData.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57AF3980259B329B00601E02 /* RawAudioData.storyboard */; };
8987
596A9F79AF0CD8DC1CA93253 /* Pods_APIExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F65EF2B97B89DE4581B426B /* Pods_APIExample.framework */; };
88+
6709B2322805CD58000BCC58 /* RawVideoData.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6709B2302805CD58000BCC58 /* RawVideoData.storyboard */; };
89+
6709B2332805CD58000BCC58 /* RawVideoData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6709B2312805CD58000BCC58 /* RawVideoData.swift */; };
90+
6709B2362805CD6C000BCC58 /* MediaUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 6709B2352805CD6C000BCC58 /* MediaUtils.m */; };
9091
67C3646427980E600080DB3A /* VideoProcess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67C3646327980E600080DB3A /* VideoProcess.swift */; };
9192
67C3646A27993A580080DB3A /* VideoProcess.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67C3646927993A580080DB3A /* VideoProcess.storyboard */; };
9293
67CB2ECA27EADD5000CB19D2 /* SpatialAudio.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67CB2EC927EADD5000CB19D2 /* SpatialAudio.storyboard */; };
@@ -152,15 +153,13 @@
152153
033A9F94252EA86A00BC26E1 /* CustomAudioSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAudioSource.swift; sourceTree = "<group>"; };
153154
033A9F96252EA86A00BC26E1 /* CustomAudioRender.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAudioRender.swift; sourceTree = "<group>"; };
154155
033A9F9B252EA86A00BC26E1 /* RTMPStreaming.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RTMPStreaming.swift; sourceTree = "<group>"; };
155-
033A9F9D252EA86A00BC26E1 /* RawMediaData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawMediaData.swift; sourceTree = "<group>"; };
156156
033A9FB2252EADF600BC26E1 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
157157
033A9FB4252EAEB500BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/JoinChannelVideo.storyboard; sourceTree = "<group>"; };
158158
033A9FB9252EAEF700BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/JoinChannelAudio.storyboard; sourceTree = "<group>"; };
159159
033A9FBE252EB02600BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/CustomAudioRender.storyboard; sourceTree = "<group>"; };
160160
033A9FC3252EB02D00BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/CustomAudioSource.storyboard; sourceTree = "<group>"; };
161161
033A9FC8252EB03700BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/CustomVideoRender.storyboard; sourceTree = "<group>"; };
162162
033A9FCD252EB03F00BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/CustomVideoSourcePush.storyboard; sourceTree = "<group>"; };
163-
033A9FD2252EB04700BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/RawMediaData.storyboard; sourceTree = "<group>"; };
164163
033A9FD7252EB05200BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/RTMPStreaming.storyboard; sourceTree = "<group>"; };
165164
033A9FDA252EB05500BC26E1 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/RTMPStreaming.strings"; sourceTree = "<group>"; };
166165
033A9FDC252EB05A00BC26E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/PrecallTest.storyboard; sourceTree = "<group>"; };
@@ -231,6 +230,10 @@
231230
57A635F32593544600EDC2F7 /* effectA.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = effectA.wav; sourceTree = "<group>"; };
232231
57AF397A259B31AA00601E02 /* RawAudioData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawAudioData.swift; sourceTree = "<group>"; };
233232
57AF3980259B329B00601E02 /* RawAudioData.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = RawAudioData.storyboard; sourceTree = "<group>"; };
233+
6709B2302805CD58000BCC58 /* RawVideoData.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RawVideoData.storyboard; sourceTree = "<group>"; };
234+
6709B2312805CD58000BCC58 /* RawVideoData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawVideoData.swift; sourceTree = "<group>"; };
235+
6709B2342805CD6C000BCC58 /* MediaUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaUtils.h; sourceTree = "<group>"; };
236+
6709B2352805CD6C000BCC58 /* MediaUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MediaUtils.m; sourceTree = "<group>"; };
234237
67C3646327980E600080DB3A /* VideoProcess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoProcess.swift; sourceTree = "<group>"; };
235238
67C3646927993A580080DB3A /* VideoProcess.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = VideoProcess.storyboard; sourceTree = "<group>"; };
236239
67CB2EC927EADD5000CB19D2 /* SpatialAudio.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SpatialAudio.storyboard; sourceTree = "<group>"; };
@@ -379,15 +382,6 @@
379382
path = RTMPStreaming;
380383
sourceTree = "<group>";
381384
};
382-
033A9F9C252EA86A00BC26E1 /* RawMediaData */ = {
383-
isa = PBXGroup;
384-
children = (
385-
033A9F9D252EA86A00BC26E1 /* RawMediaData.swift */,
386-
033A9FD3252EB04700BC26E1 /* RawMediaData.storyboard */,
387-
);
388-
path = RawMediaData;
389-
sourceTree = "<group>";
390-
};
391385
034C62652525857200296ECF /* JoinChannelAudio */ = {
392386
isa = PBXGroup;
393387
children = (
@@ -485,12 +479,12 @@
485479
children = (
486480
67C3646227980E1F0080DB3A /* VideoProcess */,
487481
57AF3979259B30BB00601E02 /* RawAudioData */,
482+
6709B22E2805CD05000BCC58 /* RawVideoData */,
488483
576459FD259B1C22007B1E30 /* CreateDataStream */,
489484
033A9F95252EA86A00BC26E1 /* CustomAudioRender */,
490485
033A9F93252EA86A00BC26E1 /* CustomAudioSource */,
491486
033A9F91252EA86A00BC26E1 /* CustomVideoRender */,
492487
033A9F8F252EA86A00BC26E1 /* CustomVideoSourcePush */,
493-
033A9F9C252EA86A00BC26E1 /* RawMediaData */,
494488
033A9F9A252EA86A00BC26E1 /* RTMPStreaming */,
495489
033A9EDE252C191000BC26E1 /* PrecallTest */,
496490
033A9ED9252C17F200BC26E1 /* CustomVideoSourceMediaIO */,
@@ -568,6 +562,7 @@
568562
03896D5B24F8D437008593CD /* Commons */ = {
569563
isa = PBXGroup;
570564
children = (
565+
6709B22F2805CD37000BCC58 /* Utils */,
571566
5770E2C0258C580E00812A80 /* Component */,
572567
57887A7F25885FC2006E962A /* Settings */,
573568
034C62922528474D00296ECF /* StatisticsInfo.swift */,
@@ -649,6 +644,24 @@
649644
path = RawAudioData;
650645
sourceTree = "<group>";
651646
};
647+
6709B22E2805CD05000BCC58 /* RawVideoData */ = {
648+
isa = PBXGroup;
649+
children = (
650+
6709B2302805CD58000BCC58 /* RawVideoData.storyboard */,
651+
6709B2312805CD58000BCC58 /* RawVideoData.swift */,
652+
);
653+
path = RawVideoData;
654+
sourceTree = "<group>";
655+
};
656+
6709B22F2805CD37000BCC58 /* Utils */ = {
657+
isa = PBXGroup;
658+
children = (
659+
6709B2342805CD6C000BCC58 /* MediaUtils.h */,
660+
6709B2352805CD6C000BCC58 /* MediaUtils.m */,
661+
);
662+
path = Utils;
663+
sourceTree = "<group>";
664+
};
652665
67C3646227980E1F0080DB3A /* VideoProcess */ = {
653666
isa = PBXGroup;
654667
children = (
@@ -818,6 +831,7 @@
818831
033A9FE5252EB59000BC26E1 /* VoiceChanger.storyboard in Resources */,
819832
033A9FBD252EB02600BC26E1 /* CustomAudioRender.storyboard in Resources */,
820833
034C62A025297ABB00296ECF /* audioeffect.mp3 in Resources */,
834+
6709B2322805CD58000BCC58 /* RawVideoData.storyboard in Resources */,
821835
03896D3424F8A011008593CD /* Assets.xcassets in Resources */,
822836
67C3646A27993A580080DB3A /* VideoProcess.storyboard in Resources */,
823837
03896D3724F8A011008593CD /* Main.storyboard in Resources */,
@@ -832,7 +846,6 @@
832846
033A9FF5252EB5F400BC26E1 /* JoinMultiChannel.storyboard in Resources */,
833847
033A9FD6252EB05200BC26E1 /* RTMPStreaming.storyboard in Resources */,
834848
033A9FF0252EB5EB00BC26E1 /* ChannelMediaRelay.storyboard in Resources */,
835-
033A9FD1252EB04700BC26E1 /* RawMediaData.storyboard in Resources */,
836849
034C62A125297ABB00296ECF /* audiomixing.mp3 in Resources */,
837850
);
838851
runOnlyForDeploymentPostprocessing = 0;
@@ -962,6 +975,7 @@
962975
isa = PBXSourcesBuildPhase;
963976
buildActionMask = 2147483647;
964977
files = (
978+
6709B2362805CD6C000BCC58 /* MediaUtils.m in Sources */,
965979
0301D3182507B4A800DF3BEA /* AgoraMetalShader.metal in Sources */,
966980
0333E63724FA32000063C5B0 /* VideoView.swift in Sources */,
967981
57887A83258886E1006E962A /* SettingCells.swift in Sources */,
@@ -978,11 +992,11 @@
978992
67CB2ECC27EADD6C00CB19D2 /* SpatialAudio.swift in Sources */,
979993
03267E1C24FF3AF4004A91A6 /* AgoraCameraSourcePush.swift in Sources */,
980994
034C626C25259FC200296ECF /* JoinChannelVideo.swift in Sources */,
981-
033A9FA5252EA86A00BC26E1 /* RawMediaData.swift in Sources */,
982995
034C62772525C68D00296ECF /* AgoraCustomEncryption.mm in Sources */,
983996
03896D3224F8A00F008593CD /* ViewController.swift in Sources */,
984997
03896D3024F8A00F008593CD /* AppDelegate.swift in Sources */,
985998
034C626425257EA600296ECF /* GlobalSettings.swift in Sources */,
999+
6709B2332805CD58000BCC58 /* RawVideoData.swift in Sources */,
9861000
0301D3192507B4A800DF3BEA /* AgoraMetalRender.swift in Sources */,
9871001
036D3A9A24FA395E00B1D8DC /* KeyCenter.swift in Sources */,
9881002
57AF397B259B31AA00601E02 /* RawAudioData.swift in Sources */,
@@ -1094,14 +1108,6 @@
10941108
name = CustomVideoSourcePush.storyboard;
10951109
sourceTree = "<group>";
10961110
};
1097-
033A9FD3252EB04700BC26E1 /* RawMediaData.storyboard */ = {
1098-
isa = PBXVariantGroup;
1099-
children = (
1100-
033A9FD2252EB04700BC26E1 /* Base */,
1101-
);
1102-
name = RawMediaData.storyboard;
1103-
sourceTree = "<group>";
1104-
};
11051111
033A9FD8252EB05200BC26E1 /* RTMPStreaming.storyboard */ = {
11061112
isa = PBXVariantGroup;
11071113
children = (

macOS/APIExample/APIExample-Bridging-Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
#import "AgoraMediaDataPlugin.h"
66
#import "ExternalAudio.h"
77
#import "AgoraCustomEncryption.h"
8+
#import "MediaUtils.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// MediaUtils.h
3+
// APIExample
4+
//
5+
// Created by Arlin on 2022/4/12.
6+
// Copyright © 2022 Agora Corp. All rights reserved.
7+
//
8+
9+
//#import <UIKit/UIKit.h>
10+
#import <Foundation/Foundation.h>
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface MediaUtils : NSObject
15+
16+
+ (nullable NSImage *)i420ToImage:(nullable void *)srcY srcU:(nullable void *)srcU srcV:(nullable void *)srcV width:(int)width height:(int)height;
17+
18+
@end
19+
20+
NS_ASSUME_NONNULL_END
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// MediaUtils.m
3+
// APIExample
4+
//
5+
// Created by Arlin on 2022/4/12.
6+
// Copyright © 2022 Agora Corp. All rights reserved.
7+
//
8+
9+
#import "MediaUtils.h"
10+
#import <CoreImage/CoreImage.h>
11+
#import <AppKit/AppKit.h>
12+
13+
@implementation MediaUtils
14+
15+
+ (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:(int)width height:(int)height {
16+
int size = width * height * 3 / 2;
17+
int yLength = width * height;
18+
int uLength = yLength / 4;
19+
20+
unsigned char *buf = (unsigned char *)malloc(size);
21+
memcpy(buf, srcY, yLength);
22+
memcpy(buf + yLength, srcU, uLength);
23+
memcpy(buf + yLength + uLength, srcV, uLength);
24+
25+
unsigned char * NV12buf = (unsigned char *)malloc(size);
26+
[self yuv420p_to_nv12:buf nv12:NV12buf width:width height:height];
27+
28+
int w = width;
29+
int h = height;
30+
NSDictionary *pixelAttributes = @{(NSString*)kCVPixelBufferIOSurfacePropertiesKey:@{}};
31+
CVPixelBufferRef pixelBuffer = NULL;
32+
CVReturn result = CVPixelBufferCreate(kCFAllocatorDefault,
33+
w,
34+
h,
35+
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
36+
(__bridge CFDictionaryRef)(pixelAttributes),
37+
&pixelBuffer);
38+
if (result != kCVReturnSuccess) {
39+
NSLog(@"Unable to create cvpixelbuffer %d", result);
40+
return nil;
41+
}
42+
43+
CVPixelBufferLockBaseAddress(pixelBuffer,0);
44+
void *yDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
45+
46+
// Here y_ch0 is Y-Plane of YUV(NV12) data.
47+
unsigned char *y_ch0 = NV12buf;
48+
unsigned char *y_ch1 = NV12buf + w * h;
49+
memcpy(yDestPlane, y_ch0, w * h);
50+
void *uvDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
51+
52+
// Here y_ch1 is UV-Plane of YUV(NV12) data.
53+
memcpy(uvDestPlane, y_ch1, w * h * 0.5);
54+
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
55+
56+
// CIImage Conversion
57+
CIImage *coreImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
58+
CIContext *temporaryContext = [CIContext contextWithOptions:nil];
59+
CGImageRef videoImage = [temporaryContext createCGImage:coreImage
60+
fromRect:CGRectMake(0, 0, w, h)];
61+
62+
NSImage *finalImage = [[NSImage alloc] initWithCGImage:videoImage size:NSMakeSize(width, height)];
63+
CVPixelBufferRelease(pixelBuffer);
64+
CGImageRelease(videoImage);
65+
return finalImage;
66+
}
67+
68+
69+
+ (void)yuv420p_to_nv12:(unsigned char*)yuv420p nv12:(unsigned char*)nv12 width:(int)width height:(int)height {
70+
int i, j;
71+
int y_size = width * height;
72+
73+
unsigned char* y = yuv420p;
74+
unsigned char* u = yuv420p + y_size;
75+
unsigned char* v = yuv420p + y_size * 5 / 4;
76+
77+
unsigned char* y_tmp = nv12;
78+
unsigned char* uv_tmp = nv12 + y_size;
79+
80+
memcpy(y_tmp, y, y_size);
81+
82+
for (j = 0, i = 0; j < y_size * 0.5; j += 2, i++) {
83+
uv_tmp[j] = u[i];
84+
uv_tmp[j+1] = v[i];
85+
}
86+
}
87+
88+
89+
@end

0 commit comments

Comments
 (0)