Skip to content

Commit

Permalink
add mac os's version
Browse files Browse the repository at this point in the history
  • Loading branch information
zxc524580210 committed Sep 3, 2019
1 parent 71d432b commit 83b09e9
Show file tree
Hide file tree
Showing 256 changed files with 23,342 additions and 3,924 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ AgoraRtcEngineKit.framework
xcuserdata
node_modules
.DS_Store
sdk.log
sdk_1.log
9 changes: 9 additions & 0 deletions MediaPlayer/Mediaplayer-Mac/MediaPlayerKitQuickstart/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) 2017 Agora Lab, Inc (http://www.agora.io/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "071CE22C1D79362D00B82401"
BuildableName = "MediaPlayerKitQuickstart.app"
BlueprintName = "MediaPlayerKitQuickstart"
ReferencedContainer = "container:MediaPlayerKitQuickstart.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "071CE22C1D79362D00B82401"
BuildableName = "MediaPlayerKitQuickstart.app"
BlueprintName = "MediaPlayerKitQuickstart"
ReferencedContainer = "container:MediaPlayerKitQuickstart.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "071CE22C1D79362D00B82401"
BuildableName = "MediaPlayerKitQuickstart.app"
BlueprintName = "MediaPlayerKitQuickstart"
ReferencedContainer = "container:MediaPlayerKitQuickstart.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "071CE22C1D79362D00B82401"
BuildableName = "MediaPlayerKitQuickstart.app"
BlueprintName = "MediaPlayerKitQuickstart"
ReferencedContainer = "container:MediaPlayerKitQuickstart.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// AgoraAudioFrame.hpp
// MediaPlayerKitQuickstart
//
// Created by zhanxiaochao on 2018/3/9.
// Copyright © 2018 agora. All rights reserved.
//
#import <AgoraRtcEngineKit/AgoraRtcEngineKit.h>

@interface AgoraAudioFrame:NSObject
typedef struct AVideoFrame {

uint8_t *data[8]; ///< pointers to the image data planes
int linesize[8]; ///< number of bytes per line
} AVideoFrame;

@property (nonatomic, assign) NSInteger eqBindValue1;
@property (nonatomic, assign) NSInteger eqBindValue2;
@property (nonatomic, assign) NSInteger eqBindValue3;
@property (nonatomic, assign) BOOL isAudience;
@property (nonatomic, assign) NSInteger sampleRate;

@property (nonatomic, assign) NSInteger re_sampleRate;
@property (nonatomic, assign) NSInteger re_channels;

//调节伴奏音量大小 值的范围0 ~ 1
@property (nonatomic, assign) float songNum;
//调节人声大小
@property (nonatomic, assign) float voiceNum;

+(instancetype)shareInstance;
-(void)registerEngineKit:(AgoraRtcEngineKit *)rtcEngine;
-(void)pushAudioSource:(void *)data byteLength:(long)bytesLength;
-(void)pushVideoSource:(void *)yuv width:(int)width height:(int)height;
-(void)destroyAudioBuf;
-(void)isOpenAudioEffect;
-(void)destroy;
@end

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
//
// AgoraAudioFrame.cpp
// MediaPlayerKitQuickstart
//
// Created by zhanxiaochao on 2018/3/9.
// Copyright © 2018 agora. All rights reserved.
//

#import "AgoraAudioFrame.h"
#include <stdio.h>
#include <iostream>
#include <queue>
#include <AgoraRtcEngineKit/IAgoraRtcEngine.h>
#include <AgoraRtcEngineKit/IAgoraMediaEngine.h>

#import <mach/mach_time.h>
#import "AudioCircularBuffer.h"
#import <MediaPlayerKit/external_resampler.h>
using namespace AgoraRTC;
static scoped_ptr<AudioCircularBuffer<char>> agoraAudioBuf(new AudioCircularBuffer<char>(2048,true));

//static scoped_ptr<AudioCircularBuffer<char>> earBackBuf(new AudioCircularBuffer<char>(2048,true));
static external_resampler *resample = new external_resampler();
static external_resampler *capture_resample = new external_resampler();
static NSObject *lock = [[NSObject alloc] init];
static NSObject *threadLockCapture = [[NSObject alloc] init];
using namespace std;

static float *stereoBuffer;
//static float *effectBuffer;

static float audio_sonSum = 1;
static float audio_voiceSum = 0;

class AudioFrameObserver:public agora::media::IAudioFrameObserver
{

public:

int sampleRate = 0;
int sampleRate_play = 0;
int isOpenAudioEffect;
float voiceSum;
float songSum;
std::mutex mtx;
public:
#pragma mark- <C++ Capture>
// push audio data to special buffer(Array byteBuffer)
// bytesLength = date length
void pushExternalData(void* data, long bytesLength)
{
@synchronized(threadLockCapture) {
mtx.lock();
char *buf = (char *)data;
agoraAudioBuf->Push(buf, (int)bytesLength);
mtx.unlock();
}


}
virtual bool onRecordAudioFrame(AudioFrame& audioFrame) override
{
@synchronized(threadLockCapture) {

int bytes = audioFrame.samples * audioFrame.channels * audioFrame.bytesPerSample;
int16_t *tmpBuf = (int16_t *)malloc(sizeof(int16_t)*bytes);
memcpy(tmpBuf, audioFrame.buffer, bytes);

if (agoraAudioBuf->mAvailSamples < bytes) {
memcpy(audioFrame.buffer, tmpBuf, sizeof(int16_t)*bytes);
free(tmpBuf);
return true;
}

mtx.lock();

int mv_samplerate = (int)[AgoraAudioFrame shareInstance].re_sampleRate;
int mv_channels = (int)[AgoraAudioFrame shareInstance].re_channels;

int mv_size = mv_samplerate * 0.01 * 2 * mv_channels;
int ret = agoraAudioBuf->mAvailSamples - mv_size;
if(ret < 0){
mtx.unlock();
return true;
}
char *data = (char *)malloc(sizeof(char)*mv_size);
agoraAudioBuf->Pop(data, mv_size);
int16_t *buf = (int16_t *)malloc(bytes);
resample->do_resample((int16_t *)data, mv_samplerate * 0.01 , mv_channels,mv_samplerate, buf, audioFrame.samples, audioFrame.channels, (int)[AgoraAudioFrame shareInstance].sampleRate);
int16_t* p16 = (int16_t*) buf;
int16_t *audioBuf = (int16_t *)malloc(sizeof(int16_t)*bytes);
memcpy(audioBuf, tmpBuf, bytes);
for (int i = 0; i < bytes / 2; ++i) {
int tmp = p16[i] * audio_sonSum;
audioBuf[i] = audioBuf[i] * audio_voiceSum;
tmp += audioBuf[i];

if (tmp > 32767) {
audioBuf[i] = 32767;
}
else if (tmp < -32768) {
audioBuf[i] = -32768;
}
else {
audioBuf[i] = tmp;
}
}
memcpy(audioFrame.buffer, audioBuf,sizeof(int16_t) * bytes);
free(audioBuf);
free(tmpBuf);
free(data);
free(p16);
mtx.unlock();

}
return true;

}
virtual bool onPlaybackAudioFrame(AudioFrame& audioFrame) override{

return true;
}
virtual bool onPlaybackAudioFrameBeforeMixing(unsigned int uid, AudioFrame& audioFrame) override {

return true;
}
virtual bool onMixedAudioFrame(AudioFrame& audioFrame) override {


return true; }

};
@interface AgoraAudioFrame()
{
AgoraRtcEngineKit *_rtcEngine;
}
@end
static AudioFrameObserver* s_audioFrameObserver;

@implementation AgoraAudioFrame

+ (instancetype)shareInstance{

static dispatch_once_t once;
static AgoraAudioFrame *sharedInstance;
dispatch_once(&once, ^{
if (sharedInstance == NULL) {

sharedInstance = [[self alloc] init];
}
});
return sharedInstance;

}

-(void)registerEngineKit:(AgoraRtcEngineKit *)rtcEngine
{
_rtcEngine = rtcEngine;
agora::rtc::IRtcEngine* rtc_engine = (agora::rtc::IRtcEngine*)rtcEngine.getNativeHandle;
agora::util::AutoPtr<agora::media::IMediaEngine> mediaEngine;
mediaEngine.queryInterface(rtc_engine, agora::AGORA_IID_MEDIA_ENGINE);
if (mediaEngine) {
s_audioFrameObserver = new AudioFrameObserver();
s_audioFrameObserver->sampleRate = (int)self.sampleRate;
s_audioFrameObserver->sampleRate_play = (int)self.sampleRate;
mediaEngine->registerAudioFrameObserver(s_audioFrameObserver);

}

}
-(void)pushAudioSource:(void *)data byteLength:(long)bytesLength{
s_audioFrameObserver->pushExternalData(data, bytesLength);
}

-(void)setIsAudience:(BOOL)isAudience
{
_isAudience = isAudience;


}
-(void)destroyAudioBuf{

agoraAudioBuf.reset(new AudioCircularBuffer<char>(2048,true));
}
-(void)setSongNum:(float)songNum
{
_songNum = songNum;
audio_sonSum = songNum;
}
-(void)setVoiceNum:(float)voiceNum
{
_voiceNum = voiceNum;
audio_voiceSum = voiceNum;
}
-(void)destroy{
agora::rtc::IRtcEngine* rtc_engine = (agora::rtc::IRtcEngine*)_rtcEngine.getNativeHandle;
agora::util::AutoPtr<agora::media::IMediaEngine> mediaEngine;
mediaEngine.queryInterface(rtc_engine, agora::AGORA_IID_MEDIA_ENGINE);
if (mediaEngine) {
mediaEngine->registerAudioFrameObserver(NULL);
}
agoraAudioBuf.release();
}

- (void)dealloc
{
delete resample;
delete capture_resample;
}
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2016 The Agora project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#include "AudioCircularBuffer.h"
#include <string.h>




Loading

0 comments on commit 83b09e9

Please sign in to comment.