浏览代码

patches: 2 more

Felix Paul Kühne 12 年之前
父节点
当前提交
eaf7f66123

+ 100 - 0
patches/0014-ios_vout2-fix-crash-when-trying-to-draw-OpenGL-chang.patch

@@ -0,0 +1,100 @@
+From 5480de322f8f0c78c8a9da060c94a652e1d445a6 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
+Date: Thu, 28 Mar 2013 12:34:46 +0100
+Subject: [PATCH 1/2] ios_vout2: fix crash when trying to draw OpenGL changes
+ while the app is in the background
+
+---
+ modules/video_output/ios2.m | 25 +++++++++++++++++++++----
+ 1 file changed, 21 insertions(+), 4 deletions(-)
+
+diff --git a/modules/video_output/ios2.m b/modules/video_output/ios2.m
+index a18f8f2..0774550 100644
+--- a/modules/video_output/ios2.m
++++ b/modules/video_output/ios2.m
+@@ -89,9 +89,11 @@ vlc_module_end ()
+     GLuint _frameBuffer;
+ 
+     BOOL _bufferNeedReset;
++    BOOL _appActive;
+ }
+ @property (readwrite) vout_display_t* voutDisplay;
+ @property (readonly) EAGLContext* eaglContext;
++@property (readonly) BOOL isAppActive;
+ 
+ - (void)createBuffers;
+ - (void)destroyBuffers;
+@@ -189,6 +191,8 @@ static int Open(vlc_object_t *this)
+     vd->control = Control;
+ 
+     /* */
++    [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationWillResignActiveNotification object:nil];
++    [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationDidBecomeActiveNotification object:nil];
+     [sys->glESView performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:YES];
+ 
+     [autoreleasePool release];
+@@ -311,7 +315,8 @@ static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *sub
+ {
+     vout_display_sys_t *sys = vd->sys;
+     sys->has_first_frame = true;
+-    vout_display_opengl_Display(sys->vgl, &vd->source);
++    if ([sys->glESView isAppActive])
++        vout_display_opengl_Display(sys->vgl, &vd->source);
+ 
+     picture_Release(pic);
+ 
+@@ -324,7 +329,8 @@ static void PictureRender(vout_display_t *vd, picture_t *pic, subpicture_t *subp
+ 
+     vout_display_sys_t *sys = vd->sys;
+ 
+-    vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
++    if ([sys->glESView isAppActive])
++        vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
+ }
+ 
+ static picture_pool_t *PicturePool(vout_display_t *vd, unsigned requested_count)
+@@ -350,14 +356,15 @@ static int OpenglESClean(vlc_gl_t *gl)
+ static void OpenglESSwap(vlc_gl_t *gl)
+ {
+     vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
+-    [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
++    if ([sys->glESView isAppActive])
++        [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
+ }
+ 
+ /*****************************************************************************
+  * Our UIView object
+  *****************************************************************************/
+ @implementation VLCOpenGLES2VideoView
+-@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext;
++@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext, isAppActive = _appActive;
+ 
+ + (Class)layerClass
+ {
+@@ -384,6 +391,8 @@ static void OpenglESSwap(vlc_gl_t *gl)
+     [self performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:NO];
+     [self setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
+ 
++    _appActive = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive);
++
+     return self;
+ }
+ 
+@@ -484,6 +493,14 @@ static void OpenglESSwap(vlc_gl_t *gl)
+     glViewport(place.x, place.y, place.width, place.height);
+ }
+ 
++- (void)applicationStateChanged:(NSNotification *)notification
++{
++    if ([[notification name] isEqualToString: UIApplicationWillResignActiveNotification])
++        _appActive = NO;
++    else
++        _appActive = YES;
++}
++
+ - (void)updateConstraints
+ {
+     [self reshape];
+-- 
+1.7.12.4 (Apple Git-37)
+

+ 134 - 0
patches/0015-AudioUnit-adapt-7fec79d9.patch

@@ -0,0 +1,134 @@
+From db184a04f5130d6d6fbd8ad801c72b0a9eb39318 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
+Date: Thu, 28 Mar 2013 12:43:29 +0100
+Subject: [PATCH 2/2] AudioUnit: adapt 7fec79d9
+
+---
+ modules/audio_output/audiounit_ios.c | 52 +++++++++++++-----------------------
+ 1 file changed, 18 insertions(+), 34 deletions(-)
+
+diff --git a/modules/audio_output/audiounit_ios.c b/modules/audio_output/audiounit_ios.c
+index 4763cb7..6574ea9 100644
+--- a/modules/audio_output/audiounit_ios.c
++++ b/modules/audio_output/audiounit_ios.c
+@@ -48,7 +48,7 @@
+     (unsigned int)sfm.mFramesPerPacket, (unsigned int)sfm.mBytesPerFrame, \
+     (unsigned int)sfm.mChannelsPerFrame, (unsigned int)sfm.mBitsPerChannel
+ 
+-#define kBufferLength 2048 * 8 * 8 * 4
++#define AUDIO_BUFFER_SIZE_IN_SECONDS (AOUT_MAX_ADVANCE_TIME / CLOCK_FREQ)
+ 
+ /*****************************************************************************
+  * aout_sys_t: private audio output method descriptor
+@@ -69,9 +69,7 @@ struct aout_sys_t
+     AudioUnit                   au_unit;            /* The AudioUnit we use */
+ 
+     int                         i_rate;             /* media sample rate */
+-    mtime_t                     i_played_length;    /* how much did we play already */
+-    mtime_t                     i_last_sample_time; /* last sample time played by the AudioUnit */
+-    mtime_t                     i_first_time_stamp;
++    int                         i_bytes_per_sample;
+     bool                        b_got_first_sample;
+ 
+     vlc_mutex_t                 lock;
+@@ -138,6 +136,7 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
+     p_sys = p_aout->sys;
+     p_sys->au_component = NULL;
+     p_sys->au_unit = NULL;
++    p_sys->i_bytes_per_sample = 0;
+ 
+     aout_FormatPrint(p_aout, "VLC is looking for:", fmt);
+ 
+@@ -270,12 +269,9 @@ static int StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
+ 	AudioSessionSetActive(true);
+ 
+     /* setup circular buffer */
+-    TPCircularBufferInit(&p_sys->circular_buffer, kBufferLength);
++    TPCircularBufferInit(&p_sys->circular_buffer, AUDIO_BUFFER_SIZE_IN_SECONDS * fmt->i_rate * fmt->i_bytes_per_frame);
+ 
+     p_sys->b_got_first_sample = false;
+-    p_sys->i_played_length = 0;
+-    p_sys->i_last_sample_time = 0;
+-    p_sys->i_first_time_stamp = 0;
+ 
+     return true;
+ }
+@@ -296,10 +292,7 @@ static void Stop(audio_output_t *p_aout)
+         if (status != noErr)
+             msg_Warn(p_aout, "failed to dispose Audio Component instance (%li)", status);
+     }
+-
+-    p_sys->i_played_length = 0;
+-    p_sys->i_last_sample_time = 0;
+-    p_sys->i_first_time_stamp = 0;
++    p_sys->i_bytes_per_sample = 0;
+ 
+     /* clean-up circular buffer */
+     TPCircularBufferCleanup(&p_sys->circular_buffer);
+@@ -329,11 +322,12 @@ static void Play (audio_output_t * p_aout, block_t * p_block)
+                                VLC_CODEC_FL32);
+         }
+ 
+-        /* keep track of the played data */
+-        p_aout->sys->i_played_length += p_block->i_length;
+-
+         /* move data to buffer */
+-        TPCircularBufferProduceBytes(&p_sys->circular_buffer, p_block->p_buffer, p_block->i_buffer);
++        if (unlikely(TPCircularBufferProduceBytes(&p_sys->circular_buffer, p_block->p_buffer, p_block->i_buffer)))
++            msg_Warn(p_aout, "Audio buffer was dropped");
++
++        if (!p_sys->i_bytes_per_sample)
++            p_sys->i_bytes_per_sample = p_block->i_buffer / p_block->i_nb_samples;
+     }
+ 
+     block_Release(p_block);
+@@ -363,26 +357,21 @@ static void Flush(audio_output_t *p_aout, bool wait)
+     /* flush circular buffer */
+     AudioOutputUnitStop(p_aout->sys->au_unit);
+     TPCircularBufferClear(&p_aout->sys->circular_buffer);
+-
+-    p_sys->i_played_length = 0;
+-    p_sys->i_last_sample_time = 0;
+-    p_sys->i_first_time_stamp = 0;
+ }
+ 
+ static int TimeGet(audio_output_t *p_aout, mtime_t *delay)
+ {
+     struct aout_sys_t * p_sys = p_aout->sys;
+ 
+-    vlc_mutex_lock(&p_sys->lock);
+-    mtime_t i_pos = (p_sys->i_last_sample_time - p_sys->i_first_time_stamp) * CLOCK_FREQ / p_sys->i_rate;
+-    vlc_mutex_unlock(&p_sys->lock);
+-
+-    if (i_pos > 0) {
+-        *delay = p_aout->sys->i_played_length - i_pos;
+-        return 0;
+-    }
+-    else
++    if (!p_sys->i_bytes_per_sample)
+         return -1;
++
++    int32_t availableBytes;
++    TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
++
++    *delay = (availableBytes / p_sys->i_bytes_per_sample) * CLOCK_FREQ / p_sys->i_rate;
++
++    return 0;
+ }
+ 
+ /*****************************************************************************
+@@ -420,11 +409,6 @@ static OSStatus RenderCallback(vlc_object_t *p_obj,
+         memcpy(targetBuffer, buffer, __MIN(bytesToCopy, availableBytes));
+         TPCircularBufferConsume(&p_sys->circular_buffer, __MIN(bytesToCopy, availableBytes));
+         VLC_UNUSED(inNumberFrames);
+-        vlc_mutex_lock(&p_sys->lock);
+-        p_sys->i_last_sample_time = inTimeStamp->mSampleTime;
+-        vlc_mutex_unlock(&p_sys->lock);
+-        if (p_sys->i_first_time_stamp == 0)
+-            p_sys->i_first_time_stamp = inTimeStamp->mSampleTime;
+     }
+ 
+     return noErr;
+-- 
+1.7.12.4 (Apple Git-37)
+