Skip to content

Commit a9d9fe6

Browse files
author
xianing
committed
adapt latest sdk changes
1 parent f26525a commit a9d9fe6

2 files changed

Lines changed: 62 additions & 133 deletions

File tree

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

Lines changed: 58 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
import io.agora.api.example.common.BaseFragment;
2727
import io.agora.api.example.examples.advanced.customaudio.AudioPlayer;
2828
import io.agora.api.example.utils.CommonUtil;
29+
import io.agora.rtc.AudioFrame;
2930
import io.agora.rtc.Constants;
3031
import io.agora.rtc.IAudioFrameObserver;
3132
import io.agora.rtc.IRtcEngineEventHandler;
3233
import io.agora.rtc.RtcEngine;
34+
import io.agora.rtc.audio.AudioParams;
3335
import io.agora.rtc.models.ChannelMediaOptions;
3436

3537
import static io.agora.api.example.common.model.Examples.ADVANCED;
36-
import static io.agora.api.example.common.model.Examples.BASIC;
38+
import static io.agora.rtc.IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER;
3739

3840
/**
3941
* This demo demonstrates how to make a one-to-one voice call
@@ -112,133 +114,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
112114
* - 0: Success.
113115
* - < 0: Failure.
114116
*/
115-
engine.registerAudioFrameObserver(new IAudioFrameObserver() {
116-
/** Occurs when the recorded audio frame is received.
117-
*
118-
* @param samples Sample data of the frame.
119-
* @param numOfSamples Number of samples.
120-
* @param bytesPerSample Number of bytes per audio sample. For example, each PCM audio sample usually takes up 16 bits (2 bytes).
121-
* @param channels Number of audio channels. If the channel uses stereo, the data is interleaved.
122-
* <ul>
123-
* <li>1: Mono.
124-
* <li>2: Stereo.
125-
* </ul>
126-
* @param samplesPerSec The number of samples per channel per second in the audio frame.
127-
* @return
128-
* <ul>
129-
* <li>true: The recorded audio frame is valid and is encoded and sent.</li>
130-
* <li>false: The recorded audio frame is invalid and is not encoded or sent.</li>
131-
* </ul>
132-
*/
133-
@Override
134-
public boolean onRecordFrame(byte[] samples, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec) {
135-
if(isEnableLoopBack){
136-
mAudioPlayer.play(samples, 0, numOfSamples * bytesPerSample);
137-
}
138-
return false;
139-
}
140-
/** Occurs when the playback audio frame is received.
141-
*
142-
* @param samples Sample data of the frame.
143-
* @param numOfSamples Number of samples.
144-
* @param bytesPerSample Number of bytes per audio sample. For example, each PCM audio sample usually takes up 16 bits (2 bytes).
145-
* @param channels Number of audio channels. If the channel uses stereo, the data is interleaved.
146-
* <ul>
147-
* <li>1: Mono.
148-
* <li>2: Stereo.
149-
* </ul>
150-
* @param samplesPerSec The number of samples per channel per second in the audio frame.
151-
* @return
152-
* <ul>
153-
* <li>true: The playback audio frame is valid and is encoded and sent.</li>
154-
* <li>false: The playback audio frame is invalid and is not encoded or sent.</li>
155-
* </ul>
156-
*/
157-
@Override
158-
public boolean onPlaybackFrame(byte[] samples, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec) {
159-
return false;
160-
}
161-
162-
/** Occurs when the audio frame of a specified user before mixing.
163-
*
164-
* @note This callback only returns the single-channel data.
165-
*
166-
* @param samples Sample data of the frame.
167-
* @param numOfSamples Number of samples.
168-
* @param bytesPerSample Number of bytes per audio sample. For example, each PCM audio sample usually takes up 16 bits (2 bytes).
169-
* @param channels Number of audio channels. If the channel uses stereo, the data is interleaved.
170-
* <ul>
171-
* <li>1: Mono.
172-
* <li>2: Stereo.
173-
* </ul>
174-
* @param samplesPerSec The number of samples per channel per second in the audio frame.
175-
* @param uid The User ID.
176-
* @return
177-
* <ul>
178-
* <li>true: The playback audio frame is valid and the mixed recorded and playback audio frame is encoded and sent.</li>
179-
* <li>false: The playback audio frame is invalid and the mixed recorded and playback audio frame is not encoded or sent.</li>
180-
* </ul>
181-
*/
182-
@Override
183-
public boolean onPlaybackFrameBeforeMixing(byte[] samples, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec, int uid) {
184-
return false;
185-
}
186-
187-
/** Occurs when the mixed recorded and playback audio frame.
188-
*
189-
* @param samples Sample data of the frame.
190-
* @param numOfSamples Number of samples.
191-
* @param bytesPerSample Number of bytes per audio sample. For example, each PCM audio sample usually takes up 16 bits (2 bytes).
192-
* @param channels Number of audio channels. If the channel uses stereo, the data is interleaved.
193-
* <ul>
194-
* <li>1: Mono.
195-
* <li>2: Stereo.
196-
* </ul>
197-
* @param samplesPerSec The number of samples per channel per second in the audio frame.
198-
* @return
199-
* <ul>
200-
* <li>true: The playback audio frame is valid and the mixed recorded and playback audio frame is encoded and sent.</li>
201-
* <li>false: The playback audio frame is invalid and the mixed recorded and playback audio frame is not encoded or sent.</li>
202-
* </ul>
203-
*/
204-
@Override
205-
public boolean onMixedFrame(byte[] samples, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec) {
206-
return false;
207-
}
208-
209-
/**
210-
*
211-
* @return
212-
* <ul>
213-
* <li>true: The playback audio frame is valid and the mixed recorded and playback audio frame is encoded and sent.</li>
214-
* <li>false: The playback audio frame is invalid and the mixed recorded and playback audio frame is not encoded or sent.</li>
215-
* </ul>
216-
*/
217-
@Override
218-
public boolean isMultipleChannelFrameWanted() {
219-
return false;
220-
}
221-
222-
/**
223-
* Occurs when the playback audio frame is received.
224-
* @param samples Sample data of the frame.
225-
* @param numOfSamples Number of samples.
226-
* @param bytesPerSample Number of bytes per audio sample. For example, each PCM audio sample usually takes up 16 bits (2 bytes).
227-
* @param channels Number of audio channels. If the channel uses stereo, the data is interleaved.
228-
* @param samplesPerSec The number of samples per channel per second in the audio frame.
229-
* @param uid The User ID.
230-
* @param channelId The Channel ID.
231-
* @return
232-
* <ul>
233-
* <li>true: The playback audio frame is valid and the mixed recorded and playback audio frame is encoded and sent.</li>
234-
* <li>false: The playback audio frame is invalid and the mixed recorded and playback audio frame is not encoded or sent.</li>
235-
* </ul>
236-
*/
237-
@Override
238-
public boolean onPlaybackFrameBeforeMixingEx(byte[] samples, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec, int uid, String channelId) {
239-
return false;
240-
}
241-
});
117+
engine.registerAudioFrameObserver(audioFrameObserver);
242118
engine.setRecordingAudioFrameParameters(SAMPLE_RATE, SAMPLE_NUM_OF_CHANNEL, Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY, SAMPLES_PER_CALL);
243119
engine.setMixedAudioFrameParameters(SAMPLE_RATE, SAMPLES_PER_CALL);
244120
engine.setPlaybackAudioFrameParameters(SAMPLE_RATE, SAMPLE_NUM_OF_CHANNEL, Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY, SAMPLES_PER_CALL);
@@ -335,7 +211,7 @@ private void joinChannel(String channelId) {
335211
an audience can only receive streams.*/
336212
engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
337213
/**In the demo, the default is to enter as the anchor.*/
338-
engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
214+
engine.setClientRole(CLIENT_ROLE_BROADCASTER);
339215
/**Please configure accessToken in the string_config file.
340216
* A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
341217
* https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
@@ -373,6 +249,7 @@ private void joinChannel(String channelId) {
373249
* The SDK uses this class to report to the app on SDK runtime events.
374250
*/
375251
private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
252+
376253
/**Reports a warning during SDK runtime.
377254
* Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
378255
@Override
@@ -495,6 +372,58 @@ public void onActiveSpeaker(int uid) {
495372
}
496373
};
497374

375+
private final IAudioFrameObserver audioFrameObserver = new IAudioFrameObserver() {
376+
@Override
377+
public boolean onRecordFrame(AudioFrame audioFrame) {
378+
return false;
379+
}
380+
381+
@Override
382+
public boolean onPlaybackFrame(AudioFrame audioFrame) {
383+
return false;
384+
}
385+
386+
@Override
387+
public boolean onPlaybackFrameBeforeMixing(AudioFrame audioFrame, int uid) {
388+
return false;
389+
}
390+
391+
@Override
392+
public boolean onMixedFrame(AudioFrame audioFrame) {
393+
return false;
394+
}
395+
396+
@Override
397+
public boolean isMultipleChannelFrameWanted() {
398+
return false;
399+
}
400+
401+
@Override
402+
public boolean onPlaybackFrameBeforeMixingEx(AudioFrame audioFrame, int uid, String channelId) {
403+
return false;
404+
}
405+
406+
@Override
407+
public int getObservedFramePosition() {
408+
return 0;
409+
}
410+
411+
@Override
412+
public AudioParams getRecordAudioParams() {
413+
return null;
414+
}
415+
416+
@Override
417+
public AudioParams getPlaybackAudioParams() {
418+
return null;
419+
}
420+
421+
@Override
422+
public AudioParams getMixedAudioParams() {
423+
return null;
424+
}
425+
};
426+
498427
@Override
499428
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
500429
isEnableLoopBack = b;

windows/APIExample/APIExample/Basic/LiveBroadcasting/CLiveBroadcastingDlg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,9 @@ void CLiveBroadcastingDlg::OnBnClickedButtonImage()
757757

758758
void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
759759
{
760-
agora::rtc::VideoBackgroundSource source;
760+
agora::rtc::VirtualBackgroundSource source;
761761
if (m_chkEnableBackground.GetCheck()) {
762-
source.background_source_type = (agora::rtc::VideoBackgroundSource::BACKGROUND_SOURCE_TYPE)m_cmbBackground.GetCurSel();
762+
source.background_source_type = (agora::rtc::VirtualBackgroundSource::BACKGROUND_SOURCE_TYPE)m_cmbBackground.GetCurSel();
763763

764764
if (m_cmbBackground.GetCurSel() == 0) {
765765
m_staBackColor.ShowWindow(SW_HIDE);
@@ -801,7 +801,7 @@ void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
801801
m_cmbBackground.ShowWindow(SW_SHOW);
802802
m_btnImagePath.ShowWindow(SW_SHOW);
803803

804-
m_rtcEngine->enableVideoBackgroundSubstitution(true, source);
804+
m_rtcEngine->enableVirtualBackground(true, source);
805805
}
806806
else {
807807
m_staBackColor.ShowWindow(SW_HIDE);
@@ -810,7 +810,7 @@ void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
810810
m_cmbColor.ShowWindow(SW_HIDE);
811811
m_btnImagePath.ShowWindow(SW_HIDE);
812812

813-
m_rtcEngine->enableVideoBackgroundSubstitution(false, source);
813+
m_rtcEngine->enableVirtualBackground(false, source);
814814
}
815815
}
816816

0 commit comments

Comments
 (0)