forked from mirrors/linphone-iphone
More work on MS2 example
This commit is contained in:
parent
9caecd7727
commit
14a04940f2
3 changed files with 49 additions and 46 deletions
|
|
@ -45,7 +45,7 @@
|
|||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Dof-dF-W5E">
|
||||
<rect key="frame" x="16" y="230" width="568" height="360"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Infos" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ahO-FT-Buh" userLabel="LabelLocal IP">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Infos" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ahO-FT-Buh" userLabel="InfoLabel">
|
||||
<rect key="frame" x="10" y="58" width="548" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
|
|
@ -76,17 +76,27 @@
|
|||
<action selector="changeCamUp:" destination="BYZ-38-t0r" eventType="touchUpInside" id="i7t-HS-skE"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Bandwidth" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qRc-kS-kqP" userLabel="BWLabel">
|
||||
<rect key="frame" x="12" y="87" width="548" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="ahO-FT-Buh" secondAttribute="trailing" constant="10" id="IMo-n1-N9M"/>
|
||||
<constraint firstItem="hJG-dO-y2z" firstAttribute="top" secondItem="Dof-dF-W5E" secondAttribute="top" constant="8" id="Koi-ap-9Ac"/>
|
||||
<constraint firstItem="ahO-FT-Buh" firstAttribute="leading" secondItem="Dof-dF-W5E" secondAttribute="leading" constant="10" id="NeM-ch-QXt"/>
|
||||
<constraint firstItem="ahO-FT-Buh" firstAttribute="height" secondItem="qRc-kS-kqP" secondAttribute="height" id="TFn-Oz-nA8"/>
|
||||
<constraint firstItem="ahO-FT-Buh" firstAttribute="leading" secondItem="qRc-kS-kqP" secondAttribute="leading" constant="-2" id="TSw-Fw-4gv"/>
|
||||
<constraint firstItem="ahO-FT-Buh" firstAttribute="top" secondItem="dpE-4Z-Bca" secondAttribute="bottom" constant="20" id="bHD-BD-qfs"/>
|
||||
<constraint firstItem="qRc-kS-kqP" firstAttribute="top" secondItem="ahO-FT-Buh" secondAttribute="bottom" constant="8" id="bQ1-79-qUP"/>
|
||||
<constraint firstItem="dpE-4Z-Bca" firstAttribute="top" secondItem="Dof-dF-W5E" secondAttribute="top" constant="8" id="bff-S2-ssI"/>
|
||||
<constraint firstItem="hJG-dO-y2z" firstAttribute="centerY" secondItem="dpE-4Z-Bca" secondAttribute="centerY" id="cpB-ox-u06"/>
|
||||
<constraint firstItem="dpE-4Z-Bca" firstAttribute="leading" secondItem="Dof-dF-W5E" secondAttribute="leading" constant="10" id="lGn-tx-JZk"/>
|
||||
<constraint firstAttribute="centerX" secondItem="ahO-FT-Buh" secondAttribute="centerX" id="qGi-4Q-dov"/>
|
||||
<constraint firstItem="ahO-FT-Buh" firstAttribute="width" secondItem="qRc-kS-kqP" secondAttribute="width" id="s5k-sE-Di2"/>
|
||||
<constraint firstAttribute="trailing" secondItem="hJG-dO-y2z" secondAttribute="trailing" constant="10" id="yuZ-Up-tVt"/>
|
||||
</constraints>
|
||||
</view>
|
||||
|
|
@ -103,9 +113,11 @@
|
|||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="bandwidthLabel" destination="qRc-kS-kqP" id="6Y0-4e-J9B"/>
|
||||
<outlet property="infoLabel" destination="ahO-FT-Buh" id="EZr-MB-hUS"/>
|
||||
<outlet property="localView" destination="VjN-5I-lOb" id="Hee-ge-Sjd"/>
|
||||
<outlet property="remoteView" destination="CBm-CY-BBe" id="avg-4V-Kse"/>
|
||||
<outlet property="startStreamLabel" destination="dpE-4Z-Bca" id="NzX-dg-Wok"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
@property (weak, nonatomic) IBOutlet UIView *remoteView;
|
||||
@property (weak, nonatomic) IBOutlet UIView *localView;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *startStreamLabel;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *bandwidthLabel;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#import "mediastreamer2/mediastream.h"
|
||||
#import "oRTP/rtpsession.h"
|
||||
#import "UITextField+DoneButton.h"
|
||||
extern void libmsopenh264_init();
|
||||
|
||||
|
|
@ -21,15 +22,15 @@ extern void libmsopenh264_init();
|
|||
MSFilter* noWebCamFilter;
|
||||
MSFilter* videoCamFilter;
|
||||
|
||||
RtpProfile* profile;
|
||||
RtpProfile* profile;
|
||||
VideoStream* currentStream;
|
||||
IceSession* iceSession;
|
||||
IceSession* iceSession;
|
||||
PayloadType* vp8_pt;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
#define CAM_NAME "AV Capture: com.apple.avfoundation.avcapturedevice.built-in_video:0" /*"AV Capture: Back Camera"*/
|
||||
#define CAM_NAME "AV Capture: com.apple.avfoundation.avcapturedevice.built-in_video:1"
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
|
@ -50,8 +51,6 @@ extern void libmsopenh264_init();
|
|||
videoCam = ms_web_cam_manager_get_cam(ms_web_cam_manager_get(), CAM_NAME);
|
||||
|
||||
noWebCamFilter = ms_web_cam_create_reader(noCam);
|
||||
|
||||
// open the cam immediately
|
||||
videoCamFilter = ms_web_cam_create_reader(videoCam);
|
||||
|
||||
currentStream = NULL;
|
||||
|
|
@ -70,6 +69,7 @@ extern void libmsopenh264_init();
|
|||
vp8_pt->normal_bitrate = 500000;
|
||||
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timer:) userInfo:nil repeats:TRUE];
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(infoTimer:) userInfo:nil repeats:TRUE];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
|
|
@ -77,59 +77,47 @@ extern void libmsopenh264_init();
|
|||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
- (void)timer:(NSTimer*)timer {
|
||||
if( currentStream) media_stream_iterate((MediaStream*)currentStream);
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)getIPAddress {
|
||||
|
||||
NSString *address = @"error";
|
||||
struct ifaddrs *interfaces = NULL;
|
||||
struct ifaddrs *temp_addr = NULL;
|
||||
int success = 0;
|
||||
// retrieve the current interfaces - returns 0 on success
|
||||
success = getifaddrs(&interfaces);
|
||||
if (success == 0) {
|
||||
// Loop through linked list of interfaces
|
||||
temp_addr = interfaces;
|
||||
while(temp_addr != NULL) {
|
||||
if(temp_addr->ifa_addr->sa_family == AF_INET) {
|
||||
// Check if interface is en0 which is the wifi connection on the iPhone
|
||||
NSString* ifa = [NSString stringWithUTF8String:temp_addr->ifa_name];
|
||||
if([ifa isEqualToString:@"en0"] || [ifa isEqualToString:@"en1"]) {
|
||||
// Get NSString from C String
|
||||
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
temp_addr = temp_addr->ifa_next;
|
||||
}
|
||||
}
|
||||
// Free memory
|
||||
freeifaddrs(interfaces);
|
||||
return address;
|
||||
|
||||
}
|
||||
|
||||
- (void)updateInfo {
|
||||
if( currentStream == NULL )return;
|
||||
if( currentStream == NULL ){
|
||||
self.infoLabel.text = @"No stream";
|
||||
self.bandwidthLabel.text = @"";
|
||||
return;
|
||||
|
||||
}
|
||||
const MSWebCam* currentCam = video_stream_get_camera(currentStream);
|
||||
if( currentCam )
|
||||
self.infoLabel.text = [NSString stringWithFormat:@"Stream running, current cam: %s", currentCam->name];
|
||||
else
|
||||
self.infoLabel.text = @"No Webcam ?!";
|
||||
|
||||
MediaStream* ms = (MediaStream*)currentStream;
|
||||
float upload = rtp_session_get_rtp_send_bandwidth(ms->sessions.rtp_session);
|
||||
float download = rtp_session_get_rtp_recv_bandwidth(ms->sessions.rtp_session);
|
||||
|
||||
self.bandwidthLabel.text = [NSString stringWithFormat:@"Upload: %f kbit/s, Download: %f kbit/s", upload/1000.0, download/1000.0];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - Timer callbacks
|
||||
- (void)timer:(NSTimer*)timer {
|
||||
if( currentStream) {
|
||||
media_stream_iterate((MediaStream*)currentStream);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)infoTimer:(NSTimer*)timer {
|
||||
[self updateInfo];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (IBAction)onStartStreamsClick:(id)sender {
|
||||
if( currentStream ){
|
||||
VideoStream* stream = currentStream;
|
||||
currentStream = NULL;
|
||||
video_stream_stop(stream);
|
||||
video_stream_stop_keep_source(stream);
|
||||
[self.startStreamLabel setTitle:@"Start streams" forState:UIControlStateNormal];
|
||||
|
||||
} else {
|
||||
VideoStream * stream = video_stream_new(3456, 3457, FALSE);
|
||||
|
|
@ -137,6 +125,7 @@ extern void libmsopenh264_init();
|
|||
video_stream_set_native_preview_window_id(stream, (unsigned long)self.localView);
|
||||
video_stream_start_with_source(stream, profile, "127.0.0.1", 3456, "127.0.0.1", 3457, 103, 30, noCam, noWebCamFilter);
|
||||
currentStream = stream;
|
||||
[self.startStreamLabel setTitle:@"Stop streams" forState:UIControlStateNormal];
|
||||
[self updateInfo];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue