Skip to content

Commit 0501dbd

Browse files
committed
fix: pcm audio publish fixed
1 parent 8a25ac8 commit 0501dbd

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

iOS/APIExample-OC/APIExample-OC/Examples/Advanced/CustomPcmAudioSource/CustomPcmAudioSource.m

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ - (IBAction)onClickJoinButton:(id)sender {
3838
@interface CustomPcmAudioSource ()<AgoraRtcEngineDelegate, AgoraPcmSourceDelegate>
3939
@property (weak, nonatomic) IBOutlet UIView *containerView;
4040
@property (weak, nonatomic) IBOutlet UISwitch *pushPcmSwitch;
41+
@property (weak, nonatomic) IBOutlet UISwitch *pushMicrophoneSwitch;
4142
@property (nonatomic, strong)VideoView *localView;
4243
@property (nonatomic, strong)VideoView *remoteView;
4344
@property (nonatomic, strong)AgoraRtcEngineKit *agoraKit;
@@ -72,7 +73,7 @@ - (void)viewDidLoad {
7273
[self.containerView layoutStream:@[self.localView, self.remoteView]];
7374

7475
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"output.raw" ofType:nil];
75-
self.pcmSourcePush = [[AgoraPCMSourcePush alloc] initWithDelegate:self filePath:filePath sampleRate:44100 channelsPerFrame:1 bitPerSamples:16 samples:441 * 10];
76+
self.pcmSourcePush = [[AgoraPCMSourcePush alloc] initWithDelegate:self filePath:filePath sampleRate:44100 channelsPerFrame:2 bitPerSamples:16 samples:441 * 10];
7677

7778
// set up agora instance when view loaded
7879
AgoraRtcEngineConfig *config = [[AgoraRtcEngineConfig alloc] init];
@@ -82,18 +83,9 @@ - (void)viewDidLoad {
8283
self.agoraKit = [AgoraRtcEngineKit sharedEngineWithConfig:config delegate:self];
8384

8485
NSString *channelName = [self.configs objectForKey:@"channelName"];
85-
// make myself a broadcaster
86-
[self.agoraKit setClientRole:(AgoraClientRoleBroadcaster)];
8786
// enable video module and set up video encoding configs
8887
[self.agoraKit enableAudio];
8988

90-
AgoraVideoEncoderConfiguration *encoderConfig = [[AgoraVideoEncoderConfiguration alloc] initWithSize:CGSizeMake(960, 540)
91-
frameRate:(AgoraVideoFrameRateFps15)
92-
bitrate:15
93-
orientationMode:(AgoraVideoOutputOrientationModeFixedPortrait)
94-
mirrorMode:(AgoraVideoMirrorModeAuto)];
95-
[self.agoraKit setVideoEncoderConfiguration:encoderConfig];
96-
9789
AgoraAudioTrackConfig *trackConfig = [[AgoraAudioTrackConfig alloc] init];
9890
trackConfig.enableLocalPlayback = YES;
9991
self.trackId = [self.agoraKit createCustomAudioTrack:(AgoraAudioTrackTypeMixable) config:trackConfig];
@@ -117,12 +109,9 @@ - (void)viewDidLoad {
117109
// when joining channel. The channel name and uid used to calculate
118110
// the token has to match the ones used for channel join
119111
AgoraRtcChannelMediaOptions *options = [[AgoraRtcChannelMediaOptions alloc] init];
120-
options.autoSubscribeAudio = YES;
121112
options.autoSubscribeVideo = NO;
122-
options.publishMicrophoneTrack = YES;
113+
options.publishMicrophoneTrack = NO;
123114
options.publishCameraTrack = NO;
124-
options.publishCustomAudioTrack = YES;
125-
options.publishCustomAudioTrackId = self.trackId;
126115
options.clientRoleType = AgoraClientRoleBroadcaster;
127116

128117
[[NetworkManager shared] generateTokenWithChannelName:channelName uid:0 success:^(NSString * _Nullable token) {
@@ -144,6 +133,13 @@ - (IBAction)pushPCM:(UISwitch *)sender {
144133
}
145134
AgoraRtcChannelMediaOptions *mediaOption = [[AgoraRtcChannelMediaOptions alloc] init];
146135
mediaOption.publishCustomAudioTrack = sender.isOn;
136+
mediaOption.publishCustomAudioTrackId = self.trackId;
137+
[self.agoraKit updateChannelWithMediaOptions:mediaOption];
138+
}
139+
140+
- (IBAction)pushMicrophone:(UISwitch*)sender {
141+
AgoraRtcChannelMediaOptions *mediaOption = [[AgoraRtcChannelMediaOptions alloc] init];
142+
mediaOption.publishMicrophoneTrack = sender.isOn;
147143
[self.agoraKit updateChannelWithMediaOptions:mediaOption];
148144
}
149145

@@ -159,9 +155,9 @@ - (void)viewDidDisappear:(BOOL)animated {
159155
// AgoraPcmSourcePushDelegate
160156
- (void)onAudioFrame:(void *)data {
161157
[self.agoraKit pushExternalAudioFrameRawData:data
162-
samples:441 * 10
158+
samples:441 * 10 * 2
163159
sampleRate:44100
164-
channels:1
160+
channels:2
165161
trackId:self.trackId
166162
timestamp:0];
167163
}

iOS/APIExample-OC/APIExample-OC/Examples/Advanced/CustomPcmAudioSource/CustomPcmAudioSource.storyboard

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -76,32 +76,59 @@
7676
</constraints>
7777
</view>
7878
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Push PCM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z7W-4N-9Hc">
79-
<rect key="frame" x="20" y="689" width="79" height="21"/>
79+
<rect key="frame" x="20" y="689" width="313" height="21"/>
80+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
81+
<nil key="textColor"/>
82+
<nil key="highlightedColor"/>
83+
</label>
84+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Push MicroPhone" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gYD-wZ-bgV">
85+
<rect key="frame" x="20" y="745" width="313" height="21"/>
8086
<fontDescription key="fontDescription" type="system" pointSize="17"/>
8187
<nil key="textColor"/>
8288
<nil key="highlightedColor"/>
8389
</label>
8490
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="6zD-2m-sj0">
8591
<rect key="frame" x="343" y="684" width="51" height="31"/>
92+
<constraints>
93+
<constraint firstAttribute="width" constant="49" id="09s-Xb-SsZ"/>
94+
</constraints>
8695
<connections>
8796
<action selector="pushPCM:" destination="p70-sh-D1h" eventType="valueChanged" id="M9I-qX-4le"/>
8897
</connections>
8998
</switch>
99+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DC4-cQ-aEa" userLabel="Push Microphone Switch">
100+
<rect key="frame" x="343" y="740" width="51" height="31"/>
101+
<constraints>
102+
<constraint firstAttribute="width" constant="49" id="HBu-0v-eJu"/>
103+
</constraints>
104+
<connections>
105+
<action selector="pushMicrophone:" destination="p70-sh-D1h" eventType="valueChanged" id="Xkl-P9-jbx"/>
106+
</connections>
107+
</switch>
90108
</subviews>
91109
<viewLayoutGuide key="safeArea" id="f4j-hu-9mE"/>
92110
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
93111
<constraints>
112+
<constraint firstItem="DC4-cQ-aEa" firstAttribute="leading" secondItem="gYD-wZ-bgV" secondAttribute="trailing" constant="10" id="0OA-Vr-mOn"/>
94113
<constraint firstItem="f4j-hu-9mE" firstAttribute="trailing" secondItem="6zD-2m-sj0" secondAttribute="trailing" constant="22" id="10L-T1-qci"/>
95114
<constraint firstItem="f4j-hu-9mE" firstAttribute="bottom" secondItem="6zD-2m-sj0" secondAttribute="bottom" constant="147" id="35B-kw-EC9"/>
96115
<constraint firstItem="f4j-hu-9mE" firstAttribute="bottom" secondItem="z7W-4N-9Hc" secondAttribute="bottom" constant="152" id="4ME-kX-uN6"/>
97116
<constraint firstItem="z7W-4N-9Hc" firstAttribute="leading" secondItem="f4j-hu-9mE" secondAttribute="leading" constant="20" id="906-Ar-HWu"/>
98117
<constraint firstItem="f4j-hu-9mE" firstAttribute="trailing" secondItem="bLu-sF-1q0" secondAttribute="trailing" id="FL8-6w-T28"/>
118+
<constraint firstItem="f4j-hu-9mE" firstAttribute="bottom" secondItem="DC4-cQ-aEa" secondAttribute="bottom" constant="91" id="RLE-Jv-f4s"/>
119+
<constraint firstItem="f4j-hu-9mE" firstAttribute="trailing" secondItem="DC4-cQ-aEa" secondAttribute="trailing" constant="22" id="SQl-1k-qb5"/>
120+
<constraint firstItem="gYD-wZ-bgV" firstAttribute="firstBaseline" secondItem="z7W-4N-9Hc" secondAttribute="baseline" constant="55.5" id="VlZ-2k-zgf"/>
121+
<constraint firstItem="DC4-cQ-aEa" firstAttribute="firstBaseline" secondItem="6zD-2m-sj0" secondAttribute="baseline" constant="25" id="YsM-QH-vVI"/>
122+
<constraint firstItem="gYD-wZ-bgV" firstAttribute="leading" secondItem="f4j-hu-9mE" secondAttribute="leading" constant="20" id="hiR-pD-kGK"/>
123+
<constraint firstItem="6zD-2m-sj0" firstAttribute="leading" secondItem="z7W-4N-9Hc" secondAttribute="trailing" constant="10" id="i8B-0H-Msl"/>
124+
<constraint firstItem="f4j-hu-9mE" firstAttribute="bottom" secondItem="gYD-wZ-bgV" secondAttribute="bottom" constant="96" id="m5g-KF-dLP"/>
99125
<constraint firstItem="bLu-sF-1q0" firstAttribute="top" secondItem="f4j-hu-9mE" secondAttribute="top" id="qnE-dw-lXn"/>
100126
<constraint firstItem="bLu-sF-1q0" firstAttribute="leading" secondItem="f4j-hu-9mE" secondAttribute="leading" id="wEO-sQ-bsY"/>
101127
</constraints>
102128
</view>
103129
<connections>
104130
<outlet property="containerView" destination="bLu-sF-1q0" id="c0q-w6-tfF"/>
131+
<outlet property="pushMicrophoneSwitch" destination="DC4-cQ-aEa" id="fRG-RN-G2o"/>
105132
<outlet property="pushPcmSwitch" destination="6zD-2m-sj0" id="Kps-03-qsf"/>
106133
</connections>
107134
</viewController>

iOS/APIExample/APIExample/Examples/Advanced/CustomPcmAudioSource/CustomPcmAudioSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CustomPcmAudioSourceMain: BaseViewController {
9696
// when joining channel. The channel name and uid used to calculate
9797
// the token has to match the ones used for channel join
9898
let option = AgoraRtcChannelMediaOptions()
99+
option.autoSubscribeVideo = false
99100
option.publishCameraTrack = false
100101
option.publishMicrophoneTrack = false
101102
NetworkManager.shared.generateToken(channelName: channelName, success: { token in

0 commit comments

Comments
 (0)