Commit e19aca81 authored by Yann Diorcet's avatar Yann Diorcet

Merge branch 'master' of git.linphone.org:mediastreamer2

parents bed7a48f e25eb668
......@@ -36,6 +36,7 @@
GLuint defaultFrameBuffer, colorRenderBuffer;
struct opengles_display* helper;
BOOL glInitDone;
BOOL storageAllocationDone;
id displayLink;
......
......@@ -88,6 +88,7 @@
[EAGLContext setCurrentContext:nil];
glInitDone = FALSE;
storageAllocationDone = FALSE;
}
- (void) drawView:(id)sender
......@@ -101,7 +102,6 @@
ms_error("Failed to bind GL context");
return;
}
glBindFramebuffer(GL_FRAMEBUFFER, defaultFrameBuffer);
if (!glInitDone) {
......@@ -117,18 +117,25 @@
- (void) layoutSubviews
{
[EAGLContext setCurrentContext:context];
if (!storageAllocationDone) {
[EAGLContext setCurrentContext:context];
int width, height;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
CAEAGLLayer* layer = (CAEAGLLayer*)self.layer;
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
ogl_display_init(helper, width, height);
int width, height;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
CAEAGLLayer* layer = (CAEAGLLayer*)self.layer;
if (![context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]) {
NSLog(@"Error in renderbufferStorage");
}
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
storageAllocationDone = TRUE;
ogl_display_init(helper, self.superview.frame.size.width, self.superview.frame.size.height);
//ogl_display_init(helper, width, height);
} else {
ogl_display_init(helper, self.superview.frame.size.width, self.superview.frame.size.height);
}
glInitDone = TRUE;
}
......@@ -136,7 +143,17 @@
{
if (!animating)
{
[self.imageView addSubview:self];
if (self.superview != self.imageView) {
// remove from old parent
[self removeFromSuperview];
// add to new parent
[self.imageView addSubview:self];
}
// we use a square view, so we need to offset it
// the GL code draws in the bottom-left corner
[self setCenter: CGPointMake(
self.frame.size.width * 0.5,
self.frame.size.height * 0.5 - (self.frame.size.height - self.superview.frame.size.height))];
[self layoutSubviews];
displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(drawView:)];
......@@ -153,7 +170,7 @@
{
[displayLink release];
displayLink = nil;
animating = TRUE;
animating = FALSE;
[self removeFromSuperview];
}
......@@ -207,16 +224,26 @@ static void iosdisplay_unit(MSFilter *f){
}
/*filter specific method*/
/* This methods declare the PARENT window of the opengl view.
We'll create on gl view for once, and then simply change its parent.
This works only if parent size is the size in all possible orientation.
*/
static int iosdisplay_set_native_window(MSFilter *f, void *arg) {
UIView* parentView = *(UIView**)arg;
IOSDisplay* thiz;
if (f->data != nil) {
NSLog(@"%@", @"Multiple calls to iosdisplay_set_native_window\n");
NSLog(@"OpenGL view parent changed.");
thiz = f->data;
[thiz performSelectorOnMainThread:@selector(stopRendering:) withObject:nil waitUntilDone:NO];
} else if (parentView == nil) {
return 0;
} else {
// we need to allocate a square view as it'll be used in portrait/landscape mode
// (in landscape mode, height become width etc...)
int maxDim = MAX(parentView.frame.size.width, parentView.frame.size.height);
thiz = f->data = [[IOSDisplay alloc] initWithFrame:CGRectMake(0, 0, maxDim, maxDim)];
}
f->data = [[IOSDisplay alloc] initWithFrame:[parentView bounds]];
IOSDisplay* thiz = f->data;
thiz.imageView = parentView;
[thiz performSelectorOnMainThread:@selector(startRendering:) withObject:nil waitUntilDone:NO];
......
......@@ -664,8 +664,6 @@ void ms_init(){
}
#endif
ortp_srtp_init();
ms_message("ms_init() done");
}
......
......@@ -44,6 +44,7 @@ typedef struct AUData_t{
ms_mutex_t mutex;
queue_t rq;
MSBufferizer *bufferizer;
uint64_t last_failed_config_time;
bool_t started;
bool_t read_started;
bool_t write_started;
......@@ -88,6 +89,7 @@ static void au_init(MSSndCard *card){
d->started=FALSE;
d->io_unit_must_be_started=FALSE;
qinit(&d->rq);
d->last_failed_config_time = 0;
d->readTimeStamp.mSampleTime=-1;
ms_mutex_init(&d->mutex,NULL);
......@@ -137,6 +139,29 @@ static const char *FormatError(OSStatus error)
{
// not re-entrant but..
static char str[64];
switch (error) {
case kAudioSessionNotInitialized:
return "kAudioSessionNotInitialized";
case kAudioSessionAlreadyInitialized:
return "kAudioSessionAlreadyInitialized";
case kAudioSessionInitializationError:
return "kAudioSessionInitializationError";
case kAudioSessionUnsupportedPropertyError:
return "kAudioSessionUnsupportedPropertyError";
case kAudioSessionBadPropertySizeError:
return "kAudioSessionBadPropertySizeError";
case kAudioSessionNotActiveError:
return "kAudioSessionNotActiveError";
case kAudioServicesNoHardwareError:
return "kAudioServicesNoHardwareError";
case kAudioSessionNoCategorySet:
return "kAudioSessionNoCategorySet";
case kAudioSessionIncompatibleCategory:
return "kAudioSessionIncompatibleCategory";
case kAudioSessionUnspecifiedError:
return "kAudioSessionUnspecifiedError";
}
// see if it appears to be a 4-char-code
*(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
......@@ -197,7 +222,10 @@ static OSStatus au_read_cb (
putq(&d->rq,rm);
ms_mutex_unlock(&d->mutex);
d->readTimeStamp.mSampleTime+=ioData->mBuffers[0].mDataByteSize/(d->bits/2);
}else ms_warning("AudioUnitRender() failed: %s (%li)", FormatError(err), err);
} else {
ms_warning("AudioUnitRender() failed: %s (%li)", FormatError(err), err);
freeb(rm);
}
}
return err;
}
......@@ -254,18 +282,29 @@ static OSStatus au_render_cb (
/****************config**************/
static void au_configure(AUData *d) {
/* returns TRUE only if configuration is successful */
static bool_t au_configure(AUData *d, uint64_t time) {
AudioStreamBasicDescription audioFormat;
AudioComponentDescription au_description;
AudioComponent foundComponent;
OSStatus auresult;
UInt32 doSetProperty = 1;
UInt32 doNotSetProperty = 0;
auresult = AudioSessionSetActive(true);
check_auresult(auresult,"AudioSessionSetActive(true)");
UInt32 audioCategory;
if (d->last_failed_config_time && (time - d->last_failed_config_time) < 1000) {
/* only try to reconfigure every 1 sec */
return FALSE;
}
auresult = AudioSessionSetActive(true);
check_auresult(auresult,"AudioSessionSetActive(true)");
if (auresult != 0) {
ms_warning("AudioUnit configuration failed. Will retry in 1 s");
d->last_failed_config_time = time;
return FALSE;
}
if (d->is_ringer && kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber10_6 /*I.E is >=OS4*/) {
audioCategory= kAudioSessionCategory_AmbientSound;
......@@ -284,9 +323,10 @@ static void au_configure(AUData *d) {
ms_message("Configuring audio session default route to speaker");
}
if (d->started == TRUE) {
//nothing else to do
return;
return TRUE;
}
au_description.componentType = kAudioUnitType_Output;
......@@ -460,24 +500,21 @@ if (!d->is_ringer || kCFCoreFoundationVersionNumber <= kCFCoreFoundationVersionN
auresult=AudioOutputUnitStart(d->io_unit);
check_auresult(auresult,"AudioOutputUnitStart");
d->started=TRUE;
return;
return TRUE;
}
static void au_configure_read(AUData *d) {
d->read_started=TRUE;
au_configure(d);
ms_mutex_lock(&d->mutex);
flushq(&d->rq,0);
ms_mutex_unlock(&d->mutex);
static void au_configure_read(AUData *d, uint64_t t) {
d->read_started=au_configure(d, t);
ms_mutex_lock(&d->mutex);
flushq(&d->rq,0);
ms_mutex_unlock(&d->mutex);
}
static void au_configure_write(AUData *d) {
d->write_started=TRUE;
au_configure(d);
ms_mutex_lock(&d->mutex);
ms_bufferizer_flush(d->bufferizer);
ms_mutex_unlock(&d->mutex);
static void au_configure_write(AUData *d, uint64_t t) {
d->write_started=au_configure(d, t);
ms_mutex_lock(&d->mutex);
ms_bufferizer_flush(d->bufferizer);
ms_mutex_unlock(&d->mutex);
}
......@@ -502,6 +539,7 @@ static void au_unconfigure_read(AUData *d){
au_unconfigure(d);
ms_mutex_lock(&d->mutex);
flushq(&d->rq,0);
flushq(&d->rq,0);
ms_mutex_unlock(&d->mutex);
}
......@@ -527,9 +565,8 @@ static void au_unconfigure_write(AUData *d){
static void au_read_preprocess(MSFilter *f){
ms_debug("au_read_preprocess");
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
au_configure_read(d);
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
au_configure_read(d, f->ticker->time);
}
static void au_read_postprocess(MSFilter *f){
......@@ -540,6 +577,9 @@ static void au_read_postprocess(MSFilter *f){
static void au_read_process(MSFilter *f){
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
mblk_t *m;
if (!d->read_started)
au_configure_read(d, f->ticker->time);
if (d->io_unit_must_be_started) {
if (f->ticker->time % 100 == 0) { /*more or less every 100ms*/
......@@ -563,8 +603,8 @@ static void au_read_process(MSFilter *f){
static void au_write_preprocess(MSFilter *f){
ms_debug("au_write_preprocess");
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
au_configure_write(d);
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
au_configure_write(d, f->ticker->time);
}
static void au_write_postprocess(MSFilter *f){
......@@ -580,6 +620,9 @@ static void au_write_process(MSFilter *f){
mblk_t *m;
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
if (!d->write_started)
au_configure_write(d, f->ticker->time);
while((m=ms_queue_get(f->inputs[0]))!=NULL){
ms_mutex_lock(&d->mutex);
ms_bufferizer_put(d->bufferizer,m);
......
......@@ -30,8 +30,9 @@ extern void clear_mediastreams(MediastreamDatas* args);
-(void) run_mediastreamer_loop {
setup_media_streams(args);
run_non_interactive_loop(args);
clear_mediastreams(args);
exit(0);
}
-(void)applicationWillFinishLaunching: (NSNotification*) aNotification
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment