Skip to content

Commit e0e1569

Browse files
author
xianing
committed
fix 37200 issues
1 parent 2b4a7f0 commit e0e1569

15 files changed

Lines changed: 59 additions & 87 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ProcessAudioRawData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ public boolean onRecordAudioFrame(int audioFrameType, int samples, int bytesPerS
322322
byteBuffer.get(origin);
323323
byteBuffer.flip();
324324
byteBuffer.put(audioAggregate(origin, buffer), 0, byteBuffer.remaining());
325+
byteBuffer.flip();
325326
}
326327
return true;
327328
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/CustomAudioSource.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ public class CustomAudioSource extends BaseFragment implements View.OnClickListe
5454
private Switch mic, pcm;
5555
private ChannelMediaOptions option = new ChannelMediaOptions();
5656
private static final String AUDIO_FILE = "output.raw";
57-
private static final Integer SAMPLE_RATE = 44100;
57+
private static final Integer SAMPLE_RATE = 16000;
5858
private static final Integer SAMPLE_NUM_OF_CHANNEL = 1;
5959
private static final Integer SAMPLES = 1024;
6060
private static final Integer BUFFER_SIZE = SAMPLES * SAMPLE_NUM_OF_CHANNEL * 2;
6161

6262
private InputStream inputStream;
63+
private Thread pushingTask = new Thread(new PushingTask());
6364

6465
@Override
6566
public void onCreate(@Nullable Bundle savedInstanceState)
@@ -72,8 +73,10 @@ public void onCreate(@Nullable Bundle savedInstanceState)
7273
private void initMediaOption() {
7374
option.autoSubscribeAudio = true;
7475
option.autoSubscribeVideo = true;
75-
option.publishAudioTrack = false;
76+
option.publishAudioTrack = true;
7677
option.publishCustomAudioTrack = false;
78+
option.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
79+
option.enableAudioRecordingOrPlayout = true;
7780
}
7881

7982
private void openAudioFile(){
@@ -176,6 +179,7 @@ public void onDestroy()
176179
{
177180
super.onDestroy();
178181
/**leaveChannel and Destroy the RtcEngine instance*/
182+
pushingTask.interrupt();
179183
if(engine != null)
180184
{
181185
engine.leaveChannel();
@@ -285,7 +289,7 @@ private void joinChannel(String channelId)
285289
* 0: Success.
286290
* < 0: Failure.
287291
* PS: Ensure that you call this method before the joinChannel method.*/
288-
engine.setExternalAudioSource(true, SAMPLE_RATE, SAMPLE_NUM_OF_CHANNEL, 2, true, true);
292+
engine.setExternalAudioSource(true, SAMPLE_RATE, SAMPLE_NUM_OF_CHANNEL);
289293
/**Please configure accessToken in the string_config file.
290294
* A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
291295
* https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
@@ -356,7 +360,7 @@ public void run()
356360
pcm.setEnabled(true);
357361
join.setEnabled(true);
358362
join.setText(getString(R.string.leave));
359-
new Thread(new PushingTask()).start();
363+
pushingTask.start();
360364
}
361365
});
362366
}
@@ -368,7 +372,7 @@ class PushingTask implements Runnable {
368372
@Override
369373
public void run() {
370374
while (true){
371-
engine.pushExternalAudioFrame(readBuffer(), BUFFER_SIZE);
375+
engine.pushExternalAudioFrame(readBuffer(), System.currentTimeMillis());
372376
}
373377
}
374378
}

Android/APIExample/app/src/main/res/layout/fragment_custom_audiorecord.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
android:text="@string/microphone"
1515
android:layout_alignParentEnd="true"
1616
android:layout_alignParentBottom="true"
17+
android:checked="true"
1718
android:layout_marginEnd="16dp"
1819
android:layout_marginBottom="64dp"/>
1920

iOS/APIExample/Common/ExternalAudio/AgoraPcmSourcePush.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class AgoraPcmSourcePush: NSObject {
5757
input.open()
5858

5959
let bufferSize = self.samples * self.bitPerSample / 8 * self.channelsPerFrame
60-
let sleepTime = TimeInterval(self.samples) / TimeInterval(self.sampleRate)
60+
// let sleepTime = TimeInterval(self.samples) / TimeInterval(self.sampleRate)
6161
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
6262
while input.hasBytesAvailable && self.state == .Play {
6363
input.read(buffer, maxLength: bufferSize)
6464
self.delegate?.onAudioFrame(data: Data(bytes: buffer, count: bufferSize))
65-
Thread.sleep(forTimeInterval: sleepTime)
65+
// Thread.sleep(forTimeInterval: sleepTime)
6666
}
6767
buffer.deallocate()
6868
input.close()

iOS/APIExample/Common/Settings/SettingsCells.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class SettingsSelectCell : SettingsBaseCell
113113
}
114114

115115
@IBAction func onSelect(_ sender:UIButton) {
116-
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
116+
let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? UIAlertController.Style.alert : UIAlertController.Style.actionSheet)
117117
guard let param = configs as? SettingsSelectParam else {return}
118118
for option in param.settingItem.options {
119119
alert.addAction(getSelectAction(option))

iOS/APIExample/Examples/Advanced/AudioMixing/AudioMixing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AudioMixingEntry : UIViewController
5757
}
5858

5959
@IBAction func setAudioProfile(){
60-
let alert = UIAlertController(title: "Set Audio Profile".localized, message: nil, preferredStyle: .actionSheet)
60+
let alert = UIAlertController(title: "Set Audio Profile".localized, message: nil, preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? UIAlertController.Style.alert : UIAlertController.Style.actionSheet)
6161
for profile in AgoraAudioProfile.allValues(){
6262
alert.addAction(getAudioProfileAction(profile))
6363
}
@@ -66,7 +66,7 @@ class AudioMixingEntry : UIViewController
6666
}
6767

6868
@IBAction func setAudioScenario(){
69-
let alert = UIAlertController(title: "Set Audio Scenario".localized, message: nil, preferredStyle: .actionSheet)
69+
let alert = UIAlertController(title: "Set Audio Scenario".localized, message: nil, preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? UIAlertController.Style.alert : UIAlertController.Style.actionSheet)
7070
for scenario in AgoraAudioScenario.allValues(){
7171
alert.addAction(getAudioScenarioAction(scenario))
7272
}

iOS/APIExample/Examples/Advanced/CustomPcmAudioSource/Base.lproj/CustomPcmAudioSource.storyboard

Lines changed: 5 additions & 38 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="18122" 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="19162" 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="18093"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
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"/>
@@ -69,31 +69,6 @@
6969
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
7070
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
7171
<subviews>
72-
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jwi-Fx-i0J" userLabel="play">
73-
<rect key="frame" x="0.0" y="584" width="414" height="48"/>
74-
<subviews>
75-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Play Audio" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mZd-9B-Gf5">
76-
<rect key="frame" x="20" y="16" width="64" height="16"/>
77-
<fontDescription key="fontDescription" type="system" pointSize="13"/>
78-
<nil key="textColor"/>
79-
<nil key="highlightedColor"/>
80-
</label>
81-
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="ZH1-8h-XIF">
82-
<rect key="frame" x="345" y="8.5" width="51" height="31"/>
83-
<connections>
84-
<action selector="playAudio:" destination="wEj-TK-x0n" eventType="valueChanged" id="pRl-hv-Is8"/>
85-
</connections>
86-
</switch>
87-
</subviews>
88-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
89-
<constraints>
90-
<constraint firstItem="mZd-9B-Gf5" firstAttribute="leading" secondItem="jwi-Fx-i0J" secondAttribute="leading" constant="20" id="0i5-yk-35U"/>
91-
<constraint firstAttribute="height" constant="48" id="JL2-23-KuM"/>
92-
<constraint firstItem="ZH1-8h-XIF" firstAttribute="centerY" secondItem="mZd-9B-Gf5" secondAttribute="centerY" id="Uea-tK-o0P"/>
93-
<constraint firstItem="ZH1-8h-XIF" firstAttribute="centerY" secondItem="jwi-Fx-i0J" secondAttribute="centerY" id="Z6y-st-z3j"/>
94-
<constraint firstAttribute="trailing" secondItem="ZH1-8h-XIF" secondAttribute="trailing" constant="20" id="l0W-20-keL"/>
95-
</constraints>
96-
</view>
9772
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="a0t-ZI-lHz" userLabel="pcm">
9873
<rect key="frame" x="0.0" y="632" width="414" height="48"/>
9974
<subviews>
@@ -153,29 +128,21 @@
153128
<viewLayoutGuide key="safeArea" id="G80-iS-Qjj"/>
154129
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
155130
<constraints>
156-
<constraint firstItem="a0t-ZI-lHz" firstAttribute="leading" secondItem="jwi-Fx-i0J" secondAttribute="leading" id="3eq-Cf-XPg"/>
157131
<constraint firstItem="a0t-ZI-lHz" firstAttribute="trailing" secondItem="6aN-r3-OBp" secondAttribute="trailing" id="60X-EQ-nK0"/>
158-
<constraint firstItem="jwi-Fx-i0J" firstAttribute="leading" secondItem="a0t-ZI-lHz" secondAttribute="leading" id="JYm-p1-snD"/>
132+
<constraint firstItem="a0t-ZI-lHz" firstAttribute="trailing" secondItem="Dyj-wd-Iae" secondAttribute="trailing" id="F4s-qq-AzG"/>
159133
<constraint firstItem="a0t-ZI-lHz" firstAttribute="leading" secondItem="6aN-r3-OBp" secondAttribute="leading" id="Joq-Xa-6lq"/>
160-
<constraint firstItem="a0t-ZI-lHz" firstAttribute="top" secondItem="jwi-Fx-i0J" secondAttribute="bottom" id="LAi-c6-nFB"/>
161-
<constraint firstItem="a0t-ZI-lHz" firstAttribute="trailing" secondItem="jwi-Fx-i0J" secondAttribute="trailing" id="PMH-u8-Sd0"/>
134+
<constraint firstItem="a0t-ZI-lHz" firstAttribute="leading" secondItem="Dyj-wd-Iae" secondAttribute="leading" id="LO1-aq-Snk"/>
162135
<constraint firstItem="Dyj-wd-Iae" firstAttribute="top" secondItem="G80-iS-Qjj" secondAttribute="top" id="Q4y-3r-C8F"/>
163136
<constraint firstItem="Dyj-wd-Iae" firstAttribute="height" secondItem="G80-iS-Qjj" secondAttribute="height" multiplier="0.66" id="UZX-WO-lGB"/>
164-
<constraint firstItem="jwi-Fx-i0J" firstAttribute="top" secondItem="Dyj-wd-Iae" secondAttribute="bottom" id="W7l-e3-H2T"/>
165-
<constraint firstItem="a0t-ZI-lHz" firstAttribute="trailing" secondItem="jwi-Fx-i0J" secondAttribute="trailing" id="aGI-Oe-5yF"/>
166-
<constraint firstItem="jwi-Fx-i0J" firstAttribute="trailing" secondItem="Dyj-wd-Iae" secondAttribute="trailing" id="c4k-8Q-qeB"/>
167-
<constraint firstItem="Dyj-wd-Iae" firstAttribute="trailing" secondItem="jwi-Fx-i0J" secondAttribute="trailing" id="ik9-cJ-lFw"/>
137+
<constraint firstItem="a0t-ZI-lHz" firstAttribute="top" secondItem="Dyj-wd-Iae" secondAttribute="bottom" constant="48" id="YbB-pC-ig4"/>
168138
<constraint firstItem="Dyj-wd-Iae" firstAttribute="leading" secondItem="G80-iS-Qjj" secondAttribute="leading" id="j0D-mQ-kSD"/>
169139
<constraint firstItem="6aN-r3-OBp" firstAttribute="top" secondItem="a0t-ZI-lHz" secondAttribute="bottom" id="quk-DL-urB"/>
170140
<constraint firstItem="Dyj-wd-Iae" firstAttribute="trailing" secondItem="G80-iS-Qjj" secondAttribute="trailing" id="wVa-Un-LvW"/>
171-
<constraint firstItem="Dyj-wd-Iae" firstAttribute="leading" secondItem="jwi-Fx-i0J" secondAttribute="leading" id="zIi-JC-O2L"/>
172141
</constraints>
173142
</view>
174143
<connections>
175144
<outlet property="container" destination="Dyj-wd-Iae" id="YY7-wi-33p"/>
176145
<outlet property="micSwitch" destination="Jll-ir-flF" id="JgX-Ka-uye"/>
177-
<outlet property="playAudioSwitch" destination="ZH1-8h-XIF" id="vBP-hJ-Qiy"/>
178-
<outlet property="playAudioView" destination="jwi-Fx-i0J" id="Ta2-ae-ctn"/>
179146
<outlet property="pushPcmSwitch" destination="dV6-q6-Gqm" id="9b8-1h-vN4"/>
180147
</connections>
181148
</viewController>

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,21 @@ class CustomPcmAudioSourceMain: BaseViewController {
4040
var pcmSourcePush: AgoraPcmSourcePush?
4141
@IBOutlet weak var container: AGEVideoContainer!
4242
var audioViews: [UInt:VideoView] = [:]
43-
@IBOutlet weak var playAudioSwitch: UISwitch!
4443
@IBOutlet weak var playAudioView: UIView!
4544
@IBOutlet weak var pushPcmSwitch: UISwitch!
4645
@IBOutlet weak var micSwitch: UISwitch!
4746

4847
// indicate if current instance has joined channel
4948
var isJoined: Bool = false {
5049
didSet {
51-
playAudioSwitch.isEnabled = isJoined
5250
pushPcmSwitch.isEnabled = isJoined
5351
micSwitch.isEnabled = isJoined
5452
}
5553
}
5654

5755
override func viewDidLoad(){
5856
super.viewDidLoad()
59-
let sampleRate:UInt = 44100, channel:UInt = 2, bitPerSample = 16, samples = 441 * 10
57+
let sampleRate:UInt = 44100, channel:UInt = 1, bitPerSample = 16, samples = 441 * 10
6058

6159
// set up agora instance when view loaded
6260
let config = AgoraRtcEngineConfig()
@@ -85,7 +83,6 @@ class CustomPcmAudioSourceMain: BaseViewController {
8583
pcmSourcePush = AgoraPcmSourcePush(delegate: self, filePath: filepath, sampleRate: Int(sampleRate),
8684
channelsPerFrame: Int(channel), bitPerSample: bitPerSample, samples: samples)
8785
agoraKit.setExternalAudioSource(true, sampleRate: Int(sampleRate), channels: Int(channel), sourceNumber: 2, localPlayback: true, publish: true)
88-
agoraKit.adjustPlaybackSignalVolume(0)
8986
// start joining channel
9087
// 1. Users can only see each other after they join the
9188
// same channel successfully using the same app id.
@@ -119,17 +116,12 @@ class CustomPcmAudioSourceMain: BaseViewController {
119116
}
120117
}
121118
}
122-
123-
@IBAction func playAudio(_ sender: UISwitch) {
124-
agoraKit.adjustPlaybackSignalVolume(sender.isOn ? 50 : 0)
125-
}
126119

127120
@IBAction func openOrCloseMic(_ sender: UISwitch) {
128121
// if isOn, update config to publish mic audio
129122
let option = AgoraRtcChannelMediaOptions()
130123
option.publishCameraTrack = .of(false)
131124
option.publishAudioTrack = .of(sender.isOn)
132-
option.publishCustomAudioTrack = .of(true)
133125
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
134126
agoraKit.updateChannel(with: option)
135127
}
@@ -141,13 +133,14 @@ class CustomPcmAudioSourceMain: BaseViewController {
141133
} else {
142134
pcmSourcePush?.stop()
143135
}
144-
playAudioView.isHidden = !sender.isOn
145136
}
146137
}
147138

148139
extension CustomPcmAudioSourceMain: AgoraPcmSourcePushDelegate {
149140
func onAudioFrame(data: Data) {
150-
agoraKit.pushExternalAudioFrameNSData(data, sourceId: 1, timestamp: 0)
141+
let time = Date().timeIntervalSince1970 * 1000 * 1000
142+
let ret = agoraKit.pushExternalAudioFrameNSData(data, sourceId: 1, timestamp: time)
143+
LogUtils.log(message: "onAudioFrame, result: \(ret)", level: .info)
151144
}
152145
}
153146

0 commit comments

Comments
 (0)