-
Notifications
You must be signed in to change notification settings - Fork 12
Chuongv/audio tests and demo #52
Changes from 11 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 |
---|---|---|
|
@@ -52,6 +52,8 @@ - (instancetype)initWithDatabasePath:(NSString *)path | |
_realm = [RLMRealm realmWithPath:path]; | ||
}); | ||
|
||
[self removeAllCalls]; | ||
|
||
return self; | ||
} | ||
|
||
|
@@ -258,6 +260,25 @@ - (void)removeChatWithAllMessages:(OCTChat *)chat | |
}); | ||
} | ||
|
||
- (void)removeAllCalls | ||
{ | ||
RLMResults *calls = [OCTCall objectsInRealm:self.realm where:nil]; | ||
|
||
DDLogInfo(@"OCTRealmManager: removing %lu calls", calls.count); | ||
|
||
RBQRealmChangeLogger *logger = [self logger]; | ||
|
||
for (OCTCall *call in calls) { | ||
OCTMessageCallEvent event = (call.status != OCTCallStatusActive) ? OCTMessageCallEventUnanswered : OCTMessageCallEventAnswered; | ||
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. It would look nicer if it would be positive statement
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. Even better it would be to use switch here. This way in case if new value will be added to enum compiler will give you an error.
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. Also as
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 this cleans up the code quite a bit. I like 👍 Thanks |
||
[self addMessageCallEvent:event call:call callDuration:call.callDuration]; | ||
} | ||
|
||
[self.realm beginWriteTransaction]; | ||
[logger willDeleteObjects:calls]; | ||
[self.realm deleteObjects:calls]; | ||
[self.realm commitWriteTransaction]; | ||
} | ||
|
||
- (OCTMessageAbstract *)addMessageWithText:(NSString *)text | ||
type:(OCTToxMessageType)type | ||
chat:(OCTChat *)chat | ||
|
@@ -290,9 +311,9 @@ - (OCTMessageAbstract *)addMessageWithText:(NSString *)text | |
return messageAbstract; | ||
} | ||
|
||
- (void)addMessageCall:(OCTMessageCallEvent)event | ||
call:(OCTCall *)call | ||
callDuration:(NSTimeInterval)duration | ||
- (void)addMessageCallEvent:(OCTMessageCallEvent)event | ||
call:(OCTCall *)call | ||
callDuration:(NSTimeInterval)duration | ||
{ | ||
NSParameterAssert(call); | ||
DDLogInfo(@"OCTRealmManager: adding messageCall to call %@", call); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
|
@@ -224,7 +220,7 @@ - (void)updateCall:(OCTCall *)call withStatus:(OCTCallStatus)status | |
- (void)addMessageCall:(OCTMessageCallEvent)event forCall:(OCTCall *)call withDuration:(NSTimeInterval)duration | ||
{ | ||
OCTRealmManager *realmManager = [self.dataSource managerGetRealmManager]; | ||
[realmManager addMessageCall:event call:call callDuration:duration]; | ||
[realmManager addMessageCallEvent:event call:call callDuration:duration]; | ||
|
||
[self.timer stopTimer]; | ||
[realmManager deleteObject:call]; | ||
|
@@ -234,28 +230,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; | ||
}]; | ||
} | ||
|
||
|
@@ -277,9 +273,9 @@ - (void)toxAV:(OCTToxAV *)toxAV callStateChanged:(OCTToxAVCallState)state friend | |
|
||
OCTCallStatus status = call.status; | ||
|
||
if ((state & OCTToxAVCallStateFinished) || (state & OCTToxAVCallStateError)) { | ||
if ((state & OCTToxAVFriendCallStateFinished) || (state & OCTToxAVFriendCallStateError)) { | ||
|
||
OCTMessageCallEvent event = (status = OCTCallStatusRinging) ? OCTMessageCallEventUnanswered : OCTMessageCallEventAnswered; | ||
OCTMessageCallEvent event = (status != OCTCallStatusActive) ? OCTMessageCallEventUnanswered : OCTMessageCallEventAnswered; | ||
|
||
[self addMessageCall:event forCall:call withDuration:call.callDuration]; | ||
|
||
|
@@ -290,6 +286,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,12 +296,24 @@ - (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? | ||
NSArray *validBitrates = @[@8, @16, @24, @32, @48]; | ||
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. Why are you sure that these are valid bitrates and that toxav will return them? 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. They were working when I was testing them, well at least for 24/32/48. I never got down lower than 24. These are just numbers that mannol suggested me to try. 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. Hm, can you maybe make them constants? Enum with these values will be fine. |
||
|
||
if (! stable) { | ||
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. Early return would look nicer (at the start of method, before validBitrates array)
|
||
NSUInteger currentIndexBitRate = [validBitrates indexOfObject:[NSNumber numberWithInt:bitrate]]; | ||
|
||
if (currentIndexBitRate == NSNotFound) { | ||
return; | ||
} | ||
|
||
NSNumber *newBitrate = [validBitrates objectAtIndex:currentIndexBitRate - 1]; | ||
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. Crash on |
||
|
||
[self.toxAV setAudioBitRate:newBitrate.intValue force:NO forFriend:friendNumber error:nil]; | ||
} | ||
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 |
||
} | ||
|
||
- (void)toxAV:(OCTToxAV *)toxAV videoBitRateChanged:(OCTToxAVVideoBitRate)bitrate friendNumber:(OCTToxFriendNumber)friendNumber stable:(BOOL)stable | ||
{ | ||
// Lower bitrate if unstable? | ||
if (! stable) {} | ||
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. Early return. Or remove this at all until video implementation. |
||
} | ||
|
||
- (void) toxAV:(OCTToxAV *)toxAV | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -494,6 +494,9 @@ - (void)fillError:(NSError **)error withCErrorSendFrame:(TOXAV_ERR_SEND_FRAME)cE | |
code = OCTToxAVErrorSendFrameInvalid; | ||
failureReason = @"One of the frame parameters was invalid. E.g. the resolution may be too small or too large, or the audio sampling rate may be unsupported"; | ||
break; | ||
case TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED: | ||
code = OCTToxAVErrorSendFramePayloadTypeDisabled; | ||
failureReason = @"Either friend turned off audio or video receiving or we turned off sending for the said payload."; | ||
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.
|
||
case TOXAV_ERR_SEND_FRAME_RTP_FAILED: | ||
code = OCTToxAVErrorSendFrameRTPFailed; | ||
failureReason = @"Failed to push frame through rtp interface"; | ||
|
@@ -542,7 +545,7 @@ void callIncomingCallback(ToxAV *cToxAV, | |
|
||
void callStateCallback(ToxAV *cToxAV, | ||
uint32_t friendNumber, | ||
enum TOXAV_CALL_STATE cState, | ||
enum TOXAV_FRIEND_CALL_STATE cState, | ||
void *userData) | ||
{ | ||
OCTToxAV *toxAV = (__bridge OCTToxAV *)userData; | ||
|
@@ -553,23 +556,23 @@ void callStateCallback(ToxAV *cToxAV, | |
|
||
OCTToxAVCallState state = 0; | ||
|
||
if (cState & TOXAV_CALL_STATE_ERROR) { | ||
state |= OCTToxAVCallStateError; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_ERROR) { | ||
state |= OCTToxAVFriendCallStateError; | ||
} | ||
if (cState & TOXAV_CALL_STATE_FINISHED) { | ||
state |= OCTToxAVCallStateFinished; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_FINISHED) { | ||
state |= OCTToxAVFriendCallStateFinished; | ||
} | ||
if (cState & TOXAV_CALL_STATE_SENDING_A) { | ||
state |= OCTToxAVCallStateSendingAudio; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_SENDING_A) { | ||
state |= OCTToxAVFriendCallStateSendingAudio; | ||
} | ||
if (cState & TOXAV_CALL_STATE_SENDING_V) { | ||
state |= OCTToxAVCallStateSendingVideo; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_SENDING_V) { | ||
state |= OCTToxAVFriendCallStateSendingVideo; | ||
} | ||
if (cState & TOXAV_CALL_STATE_RECEIVING_A) { | ||
state |= OCTToxAVCallStateReceivingAudio; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_RECEIVING_A) { | ||
state |= OCTToxAVFriendCallStateReceivingAudio; | ||
} | ||
if (cState & TOXAV_CALL_STATE_RECEIVING_V) { | ||
state |= OCTToxAVCallStateReceivingVideo; | ||
if (cState & TOXAV_FRIEND_CALL_STATE_RECEIVING_V) { | ||
state |= OCTToxAVFriendCallStateReceivingVideo; | ||
} | ||
|
||
if ([toxAV.delegate respondsToSelector:@selector(toxAV:callStateChanged:friendNumber:)]) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// OCTCallsViewController.h | ||
// objcTox | ||
// | ||
// Created by Chuong Vu on 6/26/15. | ||
// Copyright (c) 2015 dvor. All rights reserved. | ||
// | ||
|
||
#import "OCTTableViewController.h" | ||
|
||
@interface OCTCallsViewController : OCTTableViewController | ||
|
||
@end |
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.
It would be better to rename method to something more explicit like
convertAllCallsToMessages