[vlc-commits] qtsound: fix crashes and some other issues

David Fuhrmann git at videolan.org
Sun Jun 15 14:17:30 CEST 2014


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Jun 15 14:11:43 2014 +0200| [070237de4a867f263b5aa4cab0503812ed5d5d67] | committer: David Fuhrmann

qtsound: fix crashes and some other issues

- do not misuse a block_t as a plain array
- use correct size of buffers
- do not overwrite buffer pointers of the second block_t, instead
copy the data

close #7886

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=070237de4a867f263b5aa4cab0503812ed5d5d67
---

 modules/access/qtsound.m |   44 ++++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/modules/access/qtsound.m b/modules/access/qtsound.m
index 3e366e4..776d601 100644
--- a/modules/access/qtsound.m
+++ b/modules/access/qtsound.m
@@ -131,7 +131,7 @@ vlc_module_end ()
             /*
              * Allocate storage for the interleaved audio data
              */
-            rawAudioData = block_Alloc(totalDataSize * sizeof(float));
+            rawAudioData = malloc(totalDataSize);
             if (NULL == rawAudioData) {
                 msg_Err(p_qtsound, "Raw audiodata could not be allocated");
                 return;
@@ -181,10 +181,7 @@ vlc_module_end ()
 
 - (void)freeAudioMem
 {
-    @synchronized (self) {
-        if (rawAudioData)
-            block_Release(rawAudioData);
-    }
+    FREENULL(rawAudioData);
 }
 
 - (mtime_t)getCurrentPts
@@ -499,41 +496,40 @@ static void Close(vlc_object_t *p_this)
 static int Demux(demux_t *p_demux)
 {
     demux_sys_t *p_sys = p_demux->p_sys;
-    block_t *p_blocka;
+    block_t *p_blocka = nil;
     NSAutoreleasePool *pool;
 
-    p_blocka = block_Alloc(p_sys->i_audio_max_buffer_size);
 
-    if(!p_blocka) {
-        msg_Err(p_demux, "cannot get audio block");
-        return 0;
-    }
 
     @synchronized (p_sys->audiooutput) {
         if ([p_sys->audiooutput checkCurrentAudioBuffer]) {
-            p_blocka->i_buffer = p_blocka->i_size = [p_sys->audiooutput getCurrentTotalDataSize];
-            p_blocka->p_buffer = p_blocka->p_start = [p_sys->audiooutput getCurrentAudioBufferData];
+            unsigned i_buffer_size = [p_sys->audiooutput getCurrentTotalDataSize];
+            p_blocka = block_Alloc(i_buffer_size);
+
+            if(!p_blocka) {
+                msg_Err(p_demux, "cannot get audio block");
+                return 0;
+            }
+
+            memcpy(p_blocka->p_buffer, [p_sys->audiooutput getCurrentAudioBufferData], i_buffer_size);
             p_blocka->i_nb_samples = [p_sys->audiooutput getNumberOfSamples];
             p_blocka->i_pts = [p_sys->audiooutput getCurrentPts];
+
+            [p_sys->audiooutput freeAudioMem];
         }
     }
 
-    if(!p_blocka->i_pts) {
-        // Nothing to transfer yet, just forget
-        block_Release(p_blocka);
-        msleep(10000);
-        return 1;
-    }
+    if (p_blocka) {
+        if (!p_blocka->i_pts) {
+            // Nothing to transfer yet, just forget
+            msleep(10000);
+            return 1;
+        }
 
-    if(p_blocka) {
         es_out_Control(p_demux->out, ES_OUT_SET_PCR, p_blocka->i_pts);
         es_out_Send(p_demux->out, p_sys->p_es_audio, p_blocka);
     }
 
-    @synchronized (p_sys->audiooutput) {
-        [p_sys->audiooutput freeAudioMem];
-    }
-
     return 1;
 }
 



More information about the vlc-commits mailing list