gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash backend/sound_handler_gst.cpp server/soun...


From: Tomas Groth
Subject: [Gnash-commit] gnash backend/sound_handler_gst.cpp server/soun...
Date: Mon, 24 Jul 2006 15:53:35 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       06/07/24 15:53:35

Modified files:
        backend        : sound_handler_gst.cpp 
        server         : sound.cpp 

Log message:
        Cleaned up the gstreamer code a bit.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sound.cpp?cvsroot=gnash&r1=1.10&r2=1.11

Patches:
Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- backend/sound_handler_gst.cpp       24 Jul 2006 13:30:50 -0000      1.1
+++ backend/sound_handler_gst.cpp       24 Jul 2006 15:53:35 -0000      1.2
@@ -123,6 +123,8 @@
        int currentStream;
        
        GST_sound_handler()
+               : soundsPlaying(0),
+                 looping(false)
        {
                // init gstreamer
                gst_init(NULL, NULL);
@@ -151,10 +153,6 @@
                // link adder and audiosink
                gst_element_link (adder, audiosink);
 
-               soundsPlaying = 0;
-               
-               looping = false;
-               
        }
 
        ~GST_sound_handler()
@@ -164,7 +162,6 @@
                        stop_sound(i);
                        delete_sound(i);
                }
-               m_sound_data.clear();
 
                gst_object_unref (GST_OBJECT (pipeline));
 
@@ -192,7 +189,7 @@
                int     adjusted_size = 0;
 
                sound_data *sounddata = new sound_data;
-               if (sounddata == NULL) {
+               if (!sounddata) {
                        gnash::log_error("could not allocate memory for 
sounddata !\n");
                        return -1;
                }
@@ -216,11 +213,11 @@
                   width: 8
                   depth: [ 1, 8 ]
                  signed: { true, false }*/
-                       /*convert_raw_data(&adjusted_data, &adjusted_size, 
data, sample_count, 1, sample_rate, stereo);
-                       sounddata->data = (guint8*) malloc(adjusted_size);
-                       memcpy(sounddata->data, adjusted_data, adjusted_size);*/
-
-                       sounddata->data = (guint8*) malloc(data_bytes);
+                       sounddata->data = static_cast<guint8*>(new 
guint8[data_bytes]);
+                       if (!sounddata->data) { 
+                               gnash::log_error("could not allocate space for 
data in soundhandler\n");
+                               return -1;
+                       }
                        memcpy(sounddata->data, data, data_bytes);
                        break;
 
@@ -233,17 +230,21 @@
                   width: 16
                   depth: [ 1, 16 ]
                  signed: { true, false }*/
-                       /*convert_raw_data(&adjusted_data, &adjusted_size, 
data, sample_count, 2, sample_rate, stereo);
-                       sounddata->data = (guint8*) malloc(adjusted_size);
-                       memcpy(sounddata->data, adjusted_data, adjusted_size);*/
-                       
-                       sounddata->data = (guint8*) malloc(data_bytes);
+                       sounddata->data = static_cast<guint8*>(new 
guint8[data_bytes]);
+                       if (!sounddata->data) { 
+                               gnash::log_error("could not allocate space for 
data in soundhandler\n");
+                               return -1;
+                       }
                        memcpy(sounddata->data, data, data_bytes);
                        break;
 
                case FORMAT_MP3:
                //case FORMAT_VORBIS:
-                       sounddata->data = (guint8*) malloc(data_bytes);
+                       sounddata->data = static_cast<guint8*>(new 
guint8[data_bytes]);
+                       if (!sounddata->data) { 
+                               gnash::log_error("could not allocate space for 
data in soundhandler\n");
+                               return -1;
+                       }
                        memcpy(sounddata->data, data, data_bytes);
 
                        break;
@@ -268,7 +269,7 @@
                
                if (currentStream >= 0 && currentStream < m_sound_data.size())
                {
-                       m_sound_data[currentStream]->data = (guint8*) 
realloc(m_sound_data[currentStream]->data, data_bytes + 
m_sound_data[currentStream]->data_size);
+                       m_sound_data[currentStream]->data = 
static_cast<guint8*>(realloc(m_sound_data[currentStream]->data, data_bytes + 
m_sound_data[currentStream]->data_size));
                        memcpy(m_sound_data[currentStream]->data + 
m_sound_data[currentStream]->data_size, data, data_bytes);
                        m_sound_data[currentStream]->data_size += data_bytes;
                }
@@ -282,7 +283,7 @@
        // The callback function which refills the buffer with data
        static void callback_handoff (GstElement *c, GstBuffer *buffer, GstPad  
*pad, gpointer user_data)
        {
-               gst_elements *gstelements = (gst_elements*) user_data;
+               gst_elements *gstelements = 
static_cast<gst_elements*>(user_data);
 
                // First callback
                if (GST_BUFFER_SIZE(buffer) == 0) {
@@ -291,7 +292,7 @@
                        } else {
                                GST_BUFFER_SIZE(buffer) = 
gstelements->data_size;
                        }
-                       GST_BUFFER_DATA(buffer) = (guint8*) 
realloc(GST_BUFFER_DATA(buffer),GST_BUFFER_SIZE(buffer));
+                       GST_BUFFER_DATA(buffer) = 
static_cast<guint8*>(realloc(GST_BUFFER_DATA(buffer),GST_BUFFER_SIZE(buffer)));
                }
 
                // This shouldn't happen
@@ -306,7 +307,7 @@
                        // If loop_count is anything else we continue to loop.
                        if (gstelements->loop_count == 0) {
                                GST_BUFFER_SIZE(buffer) = 
gstelements->data_size-gstelements->position;
-                               memcpy(GST_BUFFER_DATA(buffer), (guint8*) 
gstelements->data+gstelements->position, 
gstelements->data_size-gstelements->position);
+                               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position), 
gstelements->data_size-gstelements->position);
                                gstelements->position += BUFFER_SIZE;
 
                                gst_element_set_state (GST_ELEMENT 
(gstelements->input), GST_STATE_PAUSED);
@@ -314,8 +315,8 @@
                        } else {
                                // Copy what's left of the data, and then fill 
the rest with "new" data.
                                //int chunck_size = 
(gstelements->data_size-gstelements->position);
-                               memcpy(GST_BUFFER_DATA(buffer), (guint8*) 
gstelements->data+gstelements->position,  
(gstelements->data_size-gstelements->position));
-                               memcpy(GST_BUFFER_DATA(buffer)+ 
(gstelements->data_size-gstelements->position), (guint8*) gstelements->data, 
GST_BUFFER_SIZE(buffer)- (gstelements->data_size-gstelements->position));
+                               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position),  
(gstelements->data_size-gstelements->position));
+                               memcpy(GST_BUFFER_DATA(buffer) + 
(gstelements->data_size-gstelements->position), 
static_cast<guint8*>(gstelements->data), GST_BUFFER_SIZE(buffer)- 
(gstelements->data_size-gstelements->position));
                                gstelements->position = 
GST_BUFFER_SIZE(buffer)- (gstelements->data_size-gstelements->position);
                                gstelements->loop_count--;
 
@@ -326,7 +327,7 @@
                }
 
                // Standard re-fill
-               memcpy(GST_BUFFER_DATA(buffer), 
(guint8*)gstelements->data+gstelements->position, BUFFER_SIZE);
+               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position), BUFFER_SIZE);
                gstelements->position += BUFFER_SIZE;
 
        }
@@ -423,7 +424,7 @@
                        gst_caps_unref (caps);
 
                        // number of buffers to send
-                       int numBuf = 
(int)ceil((float)m_sound_data[sound_handle]->data_size / (float)BUFFER_SIZE);
+                       int numBuf = 
static_cast<int>(ceil(static_cast<float>(m_sound_data[sound_handle]->data_size) 
/ static_cast<float>(BUFFER_SIZE)));
                        if (loop_count == -1) {
                                numBuf = -1;
                        } else if (loop_count > 0) {
@@ -458,7 +459,7 @@
                        gst_caps_unref (caps);
 
                        // number of buffers to send
-                       int numBuf = 
(int)ceil((float)m_sound_data[sound_handle]->data_size / (float)BUFFER_SIZE);
+                       int numBuf = 
static_cast<int>(ceil(static_cast<float>(m_sound_data[sound_handle]->data_size) 
/ static_cast<float>(BUFFER_SIZE)));
                        if (loop_count == -1) {
                                numBuf = -1;
                        } else if (loop_count > 0) {
@@ -496,7 +497,7 @@
                gst_element_link(gst_element->bin,adder);
                
                // Set the volume
-               g_object_set (G_OBJECT (gst_element->volume), "volume", 
(double)m_sound_data[sound_handle]->volume / 100.0, NULL);
+               g_object_set (G_OBJECT (gst_element->volume), "volume", 
static_cast<double>(m_sound_data[sound_handle]->volume) / 100.0, NULL);
 
                //gst_pad_add_event_probe(pad, G_CALLBACK(event_callback), 
m_sound_data[sound_handle]);
 
@@ -610,7 +611,7 @@
                
                for (int i = 0; i < 
m_sound_data[sound_handle]->m_gst_elements.size(); i++) {
                        g_object_set (G_OBJECT 
(m_sound_data[sound_handle]->m_gst_elements[i]->volume),
-                                               "volume", volume/100, NULL);
+                                               "volume", 
static_cast<double>(volume/100.0), NULL);
                }
 
        }

Index: server/sound.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sound.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- server/sound.cpp    24 Jul 2006 13:30:51 -0000      1.10
+++ server/sound.cpp    24 Jul 2006 15:53:35 -0000      1.11
@@ -500,13 +500,13 @@
        // extract garbage data
        int     garbage = in->read_uint(8);
 
-       sound_handler::format_type      format = (sound_handler::format_type) 
in->read_uint(4);
+       sound_handler::format_type      format = 
static_cast<sound_handler::format_type>(in->read_uint(4));
        int     sample_rate = in->read_uint(2); // multiples of 5512.5
        bool    sample_16bit = in->read_uint(1) ? true : false;
        bool    stereo = in->read_uint(1) ? true : false;
        
        // checks if this is a new streams header or just one in the row
-       if (format == 0 && sample_rate == 0 && sample_16bit == 0 && stereo == 
0) return;
+       if (format == 0 && sample_rate == 0 && !sample_16bit && !stereo) return;
        
        int     sample_count = in->read_u32();
        if (format == 2) garbage = in->read_uint(16);
@@ -520,10 +520,9 @@
        if (s_sound_handler)
        {
                int     data_bytes = 0;
-               unsigned char*  data = NULL;
 
                int     handler_id = s_sound_handler->create_sound(
-                       data,
+                       NULL,
                        data_bytes,
                        sample_count,
                        format,
@@ -537,7 +536,6 @@
                start_stream_sound_tag* ssst = new start_stream_sound_tag();
                ssst->read(m, sam_impl);
 
-               delete [] data;
        }
 #endif
 }
@@ -561,6 +559,9 @@
 
                // @@ This is pretty awful -- lots of copying, slow reading.
                data_bytes = in->get_tag_end_position() - in->get_position();
+
+               if (data_bytes <= 0) return;
+               
                data = new unsigned char[data_bytes];
                for (int i = 0; i < data_bytes; i++)
                {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]