-
Notifications
You must be signed in to change notification settings - Fork 12
Chuongv/audio tests and demo #52
Changes from 13 commits
850afc3
602c8b6
0692479
31cf146
ec1fb5b
1d9cf0d
f89220b
15836f8
6c895c6
c1003f4
656e02f
cab93d8
211e9fd
9fc04f3
43fac74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
#import "OCTSubmanagerCalls+Private.h" | ||
|
||
const OCTToxAVAudioBitRate kDefaultAudioBitRate = 48; | ||
const OCTToxAVAudioBitRate kDefaultAudioBitRate = OCTToxAVAudioBitRate48; | ||
const OCTToxAVAudioBitRate kDefaultVideoBitRate = 400; | ||
|
||
@interface OCTSubmanagerCalls () <OCTToxAVDelegate> | ||
|
@@ -36,10 +36,6 @@ - (instancetype)initWithTox:(OCTTox *)tox | |
_toxAV.delegate = self; | ||
[_toxAV start]; | ||
|
||
_audioEngine = [OCTAudioEngine new]; | ||
_audioEngine.toxav = self.toxAV; | ||
[_audioEngine setupWithError:nil]; | ||
|
||
return self; | ||
} | ||
|
||
|
@@ -61,7 +57,7 @@ - (BOOL)setupWithError:(NSError **)error | |
|
||
- (OCTCall *)callToChat:(OCTChat *)chat enableAudio:(BOOL)enableAudio enableVideo:(BOOL)enableVideo error:(NSError **)error | ||
{ | ||
OCTToxAVAudioBitRate audioBitRate = (enableAudio) ? kDefaultAudioBitRate : kOCTToxAVAudioBitRateDisable; | ||
OCTToxAVAudioBitRate audioBitRate = (enableAudio) ? kDefaultAudioBitRate : OCTToxAVAudioBitRateDisabled; | ||
OCTToxAVVideoBitRate videoBitRate = (enableVideo) ? kDefaultVideoBitRate : kOCTToxAVVideoBitRateDisable; | ||
|
||
if (chat.friends.count == 1) { | ||
|
@@ -89,7 +85,7 @@ - (OCTCall *)callToChat:(OCTChat *)chat enableAudio:(BOOL)enableAudio enableVide | |
|
||
- (BOOL)answerCall:(OCTCall *)call enableAudio:(BOOL)enableAudio enableVideo:(BOOL)enableVideo error:(NSError **)error | ||
{ | ||
OCTToxAVAudioBitRate audioBitRate = (enableAudio) ? kDefaultAudioBitRate : kOCTToxAVAudioBitRateDisable; | ||
OCTToxAVAudioBitRate audioBitRate = (enableAudio) ? kDefaultAudioBitRate : OCTToxAVAudioBitRateDisabled; | ||
OCTToxAVVideoBitRate videoBitRate = (enableVideo) ? kDefaultVideoBitRate : kOCTToxAVVideoBitRateDisable; | ||
|
||
if (call.chat.friends.count == 1) { | ||
|
@@ -141,15 +137,13 @@ - (BOOL)sendCallControl:(OCTToxAVCallControl)control toCall:(OCTCall *)call erro | |
return NO; | ||
} | ||
|
||
OCTMessageCallEvent event = (call.status == OCTCallStatusActive) ? OCTMessageCallEventAnswered : OCTMessageCallEventUnanswered; | ||
|
||
switch (control) { | ||
case OCTToxAVCallControlResume: | ||
[self updateCall:call withStatus:OCTCallStatusActive]; | ||
break; | ||
case OCTToxAVCallControlCancel: | ||
[self.timer stopTimer]; | ||
[self addMessageCall:event forCall:call withDuration:call.callDuration]; | ||
[self addMessageCall:call]; | ||
return [self.audioEngine stopAudioFlow:error]; | ||
case OCTToxAVCallControlPause: | ||
break; | ||
|
@@ -221,10 +215,10 @@ - (void)updateCall:(OCTCall *)call withStatus:(OCTCallStatus)status | |
}]; | ||
} | ||
|
||
- (void)addMessageCall:(OCTMessageCallEvent)event forCall:(OCTCall *)call withDuration:(NSTimeInterval)duration | ||
- (void)addMessageCall:(OCTCall *)call | ||
{ | ||
OCTRealmManager *realmManager = [self.dataSource managerGetRealmManager]; | ||
[realmManager addMessageCall:event call:call callDuration:duration]; | ||
[realmManager addMessageCall:call]; | ||
|
||
[self.timer stopTimer]; | ||
[realmManager deleteObject:call]; | ||
|
@@ -234,28 +228,28 @@ - (void)updateCall:(OCTCall *)call withState:(OCTToxAVCallState)state | |
{ | ||
BOOL sendingAudio, sendingVideo, receivingAudio, receivingVideo; | ||
|
||
if (state & OCTToxAVCallStateReceivingAudio) { | ||
if (state & OCTToxAVFriendCallStateReceivingAudio) { | ||
receivingAudio = YES; | ||
} | ||
|
||
if (state & OCTToxAVCallStateReceivingVideo) { | ||
if (state & OCTToxAVFriendCallStateReceivingVideo) { | ||
receivingVideo = YES; | ||
} | ||
|
||
if (state & OCTToxAVCallStateSendingAudio) { | ||
if (state & OCTToxAVFriendCallStateSendingAudio) { | ||
sendingAudio = YES; | ||
} | ||
|
||
if (state & OCTToxAVCallStateSendingVideo) { | ||
if (state & OCTToxAVFriendCallStateSendingVideo) { | ||
sendingVideo = YES; | ||
} | ||
|
||
OCTRealmManager *realmManager = [self.dataSource managerGetRealmManager]; | ||
[realmManager updateObject:call withBlock:^(OCTCall *callToUpdate) { | ||
call.receivingAudio = receivingAudio; | ||
call.receivingVideo = receivingVideo; | ||
call.sendingAudio = sendingAudio; | ||
call.sendingVideo = sendingVideo; | ||
callToUpdate.receivingAudio = receivingAudio; | ||
callToUpdate.receivingVideo = receivingVideo; | ||
callToUpdate.sendingAudio = sendingAudio; | ||
callToUpdate.sendingVideo = sendingVideo; | ||
}]; | ||
} | ||
|
||
|
@@ -275,13 +269,9 @@ - (void)toxAV:(OCTToxAV *)toxAV callStateChanged:(OCTToxAVCallState)state friend | |
{ | ||
OCTCall *call = [self getOrCreateCallWithFriendNumber:friendNumber]; | ||
|
||
OCTCallStatus status = call.status; | ||
|
||
if ((state & OCTToxAVCallStateFinished) || (state & OCTToxAVCallStateError)) { | ||
if ((state & OCTToxAVFriendCallStateFinished) || (state & OCTToxAVFriendCallStateError)) { | ||
|
||
OCTMessageCallEvent event = (status = OCTCallStatusRinging) ? OCTMessageCallEventUnanswered : OCTMessageCallEventAnswered; | ||
|
||
[self addMessageCall:event forCall:call withDuration:call.callDuration]; | ||
[self addMessageCall:call]; | ||
|
||
[self.audioEngine stopAudioFlow:nil]; | ||
|
||
|
@@ -290,6 +280,8 @@ - (void)toxAV:(OCTToxAV *)toxAV callStateChanged:(OCTToxAVCallState)state friend | |
|
||
if (call.status == OCTCallStatusDialing) { | ||
[self updateCall:call withStatus:OCTCallStatusActive]; | ||
self.audioEngine.friendNumber = friendNumber; | ||
[self.audioEngine startAudioFlow:nil]; | ||
[self.timer startTimerForCall:call]; | ||
} | ||
|
||
|
@@ -298,13 +290,37 @@ - (void)toxAV:(OCTToxAV *)toxAV callStateChanged:(OCTToxAVCallState)state friend | |
|
||
- (void)toxAV:(OCTToxAV *)toxAV audioBitRateChanged:(OCTToxAVAudioBitRate)bitrate stable:(BOOL)stable friendNumber:(OCTToxFriendNumber)friendNumber | ||
{ | ||
// Lower bitrate if unstable? | ||
if (stable) { | ||
return; | ||
} | ||
|
||
OCTToxAVAudioBitRate newBitrate; | ||
|
||
switch (bitrate) { | ||
case OCTToxAVAudioBitRateDisabled: | ||
NSAssert(NO, @"We shouldn't be here!"); | ||
break; | ||
case OCTToxAVAudioBitRate8: | ||
return; | ||
case OCTToxAVAudioBitRate48: | ||
newBitrate = OCTToxAVAudioBitRate32; | ||
break; | ||
case OCTToxAVAudioBitRate32: | ||
newBitrate = OCTToxAVAudioBitRate24; | ||
break; | ||
case OCTToxAVAudioBitRate24: | ||
newBitrate = OCTToxAVAudioBitRate16; | ||
break; | ||
case OCTToxAVAudioBitRate16: | ||
newBitrate = OCTToxAVAudioBitRate8; | ||
break; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if bitrate is unstable we will lower it. Any ideas of possibilities of increasing bitrate, e.g. if network quality increased? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I'm not sure what the best way to do that is? We can submit a new non-forceful bitrate change request every few minutes in the call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can leave it for now. Currently it is more important just to make things work. I've created an issue so we won't forget about that #53 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks okay, you can just change the ordering to be more consistent. From lowest to highest. |
||
|
||
[self.toxAV setAudioBitRate:newBitrate force:NO forFriend:friendNumber error:nil]; | ||
} | ||
|
||
- (void)toxAV:(OCTToxAV *)toxAV videoBitRateChanged:(OCTToxAVVideoBitRate)bitrate friendNumber:(OCTToxFriendNumber)friendNumber stable:(BOOL)stable | ||
{ | ||
// Lower bitrate if unstable? | ||
} | ||
{} | ||
|
||
- (void) toxAV:(OCTToxAV *)toxAV | ||
receiveAudio:(OCTToxAVPCMData *)pcm | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
break;
here. This may save us from error in future.