Skip to content

Commit

Permalink
Merge pull request #8 from EricssonResearch/settings
Browse files Browse the repository at this point in the history
Added settings for media properties
  • Loading branch information
stefanalund committed Mar 24, 2015
2 parents 04fe1cd + 7ab4b32 commit 4c3b3cb
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 8 deletions.
1 change: 1 addition & 0 deletions SDK/OpenWebRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#import <OpenWebRTC-SDK/OpenWebRTCVideoView.h>
#import <OpenWebRTC-SDK/OpenWebRTCUtils.h>
#import <OpenWebRTC-SDK/OpenWebRTCSettings.h>
#import <OpenWebRTC-SDK/OpenWebRTCNativeHandler.h>

#import "owr.h"
Expand Down
2 changes: 2 additions & 0 deletions SDK/OpenWebRTCNativeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#import <Foundation/Foundation.h>
#import "OpenWebRTCVideoView.h"
#import "OpenWebRTCSettings.h"

@protocol OpenWebRTCNativeHandlerDelegate <NSObject>

Expand All @@ -43,6 +44,7 @@
@interface OpenWebRTCNativeHandler : NSObject

@property (nonatomic, weak) id <OpenWebRTCNativeHandlerDelegate> delegate;
@property (nonatomic, strong) OpenWebRTCSettings *settings;

- (instancetype)initWithDelegate:(id <OpenWebRTCNativeHandlerDelegate>)delegate;

Expand Down
28 changes: 20 additions & 8 deletions SDK/OpenWebRTCNativeHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ - (instancetype)initWithDelegate:(id <OpenWebRTCNativeHandlerDelegate>)delegate
{
if (self = [super init]) {
staticSelf = self;
self.delegate = delegate;
_delegate = delegate;
_settings = [[OpenWebRTCSettings alloc] initWithDefaults];
}
return self;
}
Expand Down Expand Up @@ -185,6 +186,9 @@ - (void)handleOfferReceived:(NSString *)offer

NSArray *payloads = mediaDescription[@"payloads"];
codec_type = OWR_CODEC_TYPE_NONE;

OpenWebRTCSettings *settings = staticSelf.settings;

for (int j = 0; j < [payloads count] && codec_type == OWR_CODEC_TYPE_NONE; j++) {
NSDictionary *payload = payloads[j];

Expand All @@ -206,8 +210,10 @@ - (void)handleOfferReceived:(NSString *)offer

channels = [payload[@"channels"] intValue];

send_payload = owr_audio_payload_new(codec_type, payload_type, clock_rate,
channels);
//send_payload = owr_audio_payload_new(codec_type, payload_type, clock_rate, channels);
send_payload = owr_audio_payload_new(codec_type, payload_type, clock_rate, settings.audioChannels);
g_object_set(send_payload, "bitrate", settings.audioBitrate, NULL);

receive_payload = owr_audio_payload_new(codec_type, payload_type, clock_rate,
channels);
} else if (!g_strcmp0(mtype, "video")) {
Expand All @@ -222,10 +228,15 @@ - (void)handleOfferReceived:(NSString *)offer
ccm_fir = [payload[@"ccmfir"] boolValue];
nack_pli = [payload[@"nackpli"] boolValue];

send_payload = owr_video_payload_new(codec_type, payload_type, clock_rate,
ccm_fir, nack_pli);
receive_payload = owr_video_payload_new(codec_type, payload_type, clock_rate,
ccm_fir, nack_pli);
send_payload = owr_video_payload_new(codec_type, payload_type, clock_rate, ccm_fir, nack_pli);

// Update based on specified settings.
g_object_set(send_payload, "bitrate", settings.videoBitrate, NULL);
g_object_set(send_payload, "width", settings.videoWidth, NULL);
g_object_set(send_payload, "height", settings.videoHeight, NULL);
g_object_set(send_payload, "framerate", settings.videoFramerate, NULL);

receive_payload = owr_video_payload_new(codec_type, payload_type, clock_rate, ccm_fir, nack_pli);
} else
g_warn_if_reached();

Expand Down Expand Up @@ -838,7 +849,8 @@ static void got_local_sources(GList *sources)
renderer = owr_video_renderer_new(SELF_VIEW_TAG);
g_assert(renderer);

g_object_set(renderer, "width", 640, "height", 480, "max-framerate", 25.0, NULL);
OpenWebRTCSettings *settings = staticSelf.settings;
g_object_set(renderer, "width", settings.videoWidth, "height", settings.videoHeight, "max-framerate", settings.videoFramerate, NULL);

owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
have_video = TRUE;
Expand Down
49 changes: 49 additions & 0 deletions SDK/OpenWebRTCSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// OpenWebRTCSettings.h
//
// Copyright (c) 2015, Ericsson AB.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
// OF SUCH DAMAGE.
//

#define kOpenWebRTCSettingsDefaultVideoWidth 640
#define kOpenWebRTCSettingsDefaultVideoHeight 480
#define kOpenWebRTCSettingsDefaultVideoFramerate 25.0
#define kOpenWebRTCSettingsDefaultVideoBitrate 768000

#define kOpenWebRTCSettingsDefaultAudioBitrate 64000
#define kOpenWebRTCSettingsDefaultAudioChannels 1

@interface OpenWebRTCSettings : NSObject

@property (nonatomic, assign) int videoBitrate;
@property (nonatomic, assign) int videoWidth;
@property (nonatomic, assign) int videoHeight;
@property (nonatomic, assign) double videoFramerate;

@property (nonatomic, assign) int audioBitrate;
@property (nonatomic, assign) int audioChannels;

- (instancetype)initWithDefaults;

@end
51 changes: 51 additions & 0 deletions SDK/OpenWebRTCSettings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// OpenWebRTCSettings.m
//
// Copyright (c) 2015, Ericsson AB.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
// OF SUCH DAMAGE.
//

#import "OpenWebRTCSettings.h"

@implementation OpenWebRTCSettings

- (instancetype)init
{
return [self initWithDefaults];
}

- (instancetype)initWithDefaults
{
if (self = [super init]) {
_videoWidth = kOpenWebRTCSettingsDefaultVideoWidth;
_videoHeight = kOpenWebRTCSettingsDefaultVideoHeight;
_videoFramerate = kOpenWebRTCSettingsDefaultVideoFramerate;
_videoBitrate = kOpenWebRTCSettingsDefaultVideoBitrate;
_audioBitrate = kOpenWebRTCSettingsDefaultAudioBitrate;
_audioChannels = kOpenWebRTCSettingsDefaultAudioChannels;
}
return self;
}

@end

0 comments on commit 4c3b3cb

Please sign in to comment.