Changeset 229 for trunk

Show
Ignore:
Timestamp:
02/15/08 00:52:50 (4 years ago)
Author:
ath
Message:

Fix some old-standing memory-handling bugs in FmOutputAlsa and FmInputTest?.

Location:
trunk/fm_server/src
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/fm_server/src/fm_buffer.c

    r190 r229  
    4141 
    4242        size_bytes = samples_to_bytes(n_samples, n_channels); 
    43         g_print ("Allocated a new buffer of %d bytes\n", size_bytes); 
     43        g_print ("Allocated a new buffer of %d samples, %d bytes\n", n_samples, size_bytes); 
    4444 
    4545         
  • trunk/fm_server/src/fm_element.c

    r195 r229  
    207207        g_return_if_fail (FM_IS_ELEMENT (element)); 
    208208        g_return_if_fail (name); 
    209          
     209 
    210210        element->name = g_strdup (name); 
    211211} 
     
    217217        g_return_val_if_fail (FM_IS_ELEMENT (element), NULL); 
    218218         
    219         return (element->name); 
     219        return (gchar *) g_object_get_data (G_OBJECT (element), "name"); 
     220        //return (element->name); 
    220221} 
    221222 
     
    282283        FmElementClass *klass = FM_ELEMENT_GET_CLASS (element); 
    283284 
    284 //      g_print("fm_element_activate, %p\n", element); 
    285  
    286         g_return_val_if_fail (!element->active, FALSE); 
     285        g_print("fm_element_activate, %p - %s\n", element, fm_element_get_name (element)); 
     286 
     287        if (element->active) { 
     288                g_warning ("Element \"%s\" was active!", fm_element_get_name (element)); 
     289                return FALSE; 
     290        } 
    287291 
    288292        if (!element->pipeline) { 
     
    312316        g_return_val_if_fail (FM_IS_ELEMENT (element), FALSE); 
    313317        FmElementClass *class = FM_ELEMENT_GET_CLASS (element); 
    314          
    315         g_return_val_if_fail (element->active, FALSE); 
     318 
     319        g_print("fm_element_deactivate, %p - %s\n", element, fm_element_get_name (element)); 
     320         
     321        if (!element->active) { 
     322                g_warning ("Element \"%s\" was not active!", fm_element_get_name (element)); 
     323                return FALSE; 
     324        } 
    316325         
    317326        gboolean ret;    
     
    390399 
    391400 
     401gboolean 
     402fm_element_deactivate_connected         (FmElement      *element) 
     403{ 
     404        g_return_val_if_fail (element->sink_ports, FALSE); 
     405 
     406//      g_print("fm_element_activate_connected, %p\n", element); 
     407 
     408        GList *tmp = element->sink_ports; 
     409        while (tmp) { 
     410                FmElementSinkPort *our_port = (FmElementSinkPort *) tmp->data; 
     411                FmElementSrcPort *peer_port = our_port->peer; 
     412 
     413                if (peer_port == NULL) 
     414                        return TRUE; 
     415 
     416                if (!fm_element_deactivate (FM_ELEMENT (peer_port->owner))) 
     417                        return FALSE; 
     418                tmp = tmp->next; 
     419        } 
     420 
     421        return TRUE; 
     422} 
     423 
     424 
    392425void 
    393426fm_element_get_buffer_from_src          (FmElement      *element, 
  • trunk/fm_server/src/fm_element.h

    r195 r229  
    167167fm_element_activate_connected           (FmElement      *element); 
    168168 
     169gboolean 
     170fm_element_deactivate_connected         (FmElement      *element); 
     171 
    169172void 
    170173fm_element_get_buffer_from_src          (FmElement      *element, 
  • trunk/fm_server/src/fm_input.c

    r58 r229  
    9595fm_input_class_init                     (FmInputClass   *class) 
    9696{ 
    97         GObjectClass *gobject_class = G_OBJECT_CLASS (class); 
     97        //GObjectClass *gobject_class = G_OBJECT_CLASS (class); 
    9898        //FmElementClass *element_class = FM_ELEMENT_CLASS (class); 
    9999        FmInputClass *input_class = FM_INPUT_CLASS (class); 
     
    106106        input_class->set_position = NULL; 
    107107         
    108         g_object_class_install_property (gobject_class, 
     108/*        g_object_class_install_property (gobject_class, 
    109109                                         PROP_STATE, 
    110110                                         g_param_spec_int ("state", 
     
    112112                                         "Input state", 
    113113                                         FM_INPUT_STOP, FM_INPUT_PLAY, FM_INPUT_PLAY, 
    114                                          G_PARAM_READWRITE)); 
     114                                         G_PARAM_READWRITE));*/ 
    115115} 
    116116 
  • trunk/fm_server/src/fm_input_test.c

    r192 r229  
    207207        FmInputTest *input_test = FM_INPUT_TEST (object); 
    208208        g_return_if_fail (FM_IS_INPUT_TEST (input_test)); 
    209         /* Nothing to do here */ 
     209         
     210        G_OBJECT_CLASS (parent_class)->dispose (object); 
    210211} 
    211212 
     
    216217        FmInputTest *input_test = FM_INPUT_TEST (object); 
    217218        g_return_if_fail (FM_IS_INPUT_TEST (input_test)); 
    218         g_free (input_test); 
    219          
    220         g_print ("aaaaaaaaalllllllllrrrrrrriiiiggggghhhhhhhhtttttttt!!!!!!!\n"); 
     219         
     220        G_OBJECT_CLASS (parent_class)->finalize (object); 
    221221} 
    222222 
  • trunk/fm_server/src/fm_output.c

    r58 r229  
    105105 
    106106 
    107 /*guint 
    108 fm_output_get_max_buffer_size           (FmOutput       *output) 
    109 { 
    110         return 0; 
    111 }*/ 
    112  
    113  
    114107gboolean 
    115108fm_output_start                         (FmOutput       *output) 
     
    125118        } 
    126119} 
     120 
    127121 
    128122gboolean 
  • trunk/fm_server/src/fm_output.h

    r123 r229  
    5353        FmElementClass parent; 
    5454 
    55         /*guint (*get_max_buffer_size)  (FmOutput       *output);*/ 
     55        /* Let the output element start and allow it to call get_buffer() on its connected elements. 
     56           It will be called after activate() */ 
    5657        gboolean (*start)               (FmOutput       *output); 
     58 
     59        /* Signal the output element to stop (it isn't allowed to call get_buffer() again. */ 
    5760        gboolean (*stop)                (FmOutput       *output); 
    5861}; 
  • trunk/fm_server/src/fm_output_alsa.c

    r191 r229  
    7575static gboolean fm_output_alsa_activate (FmElement      *element); 
    7676static gboolean fm_output_alsa_deactivate (FmElement    *element); 
     77static void fm_output_alsa_dispose      (GObject        *object); 
    7778static void fm_output_alsa_finalize     (GObject        *object); 
    7879static gint xrun_recovery               (snd_pcm_t      *handle, 
     
    8081static gpointer fm_output_alsa_play     (gpointer       data); 
    8182static gboolean fm_output_alsa_start    (FmOutput       *output); 
     83static gboolean fm_output_alsa_stop     (FmOutput       *output); 
    8284                                  
    8385 
     
    129131        gobject_class->set_property = fm_output_alsa_set_property; 
    130132        gobject_class->get_property = fm_output_alsa_get_property; 
    131          
     133 
     134        gobject_class->dispose = fm_output_alsa_dispose;         
    132135        gobject_class->finalize = fm_output_alsa_finalize; 
    133136         
     
    136139         
    137140        output_class->start = fm_output_alsa_start; 
    138          
     141        output_class->stop = fm_output_alsa_stop; 
    139142         
    140143        g_object_class_install_property (gobject_class, 
     
    248251        gint err; 
    249252         
    250         g_print ("Activating FmOutputAlsa\n"); 
     253//      g_print ("Activating FmOutputAlsa\n"); 
    251254                 
    252255        // Open the device 
     
    304307        } 
    305308         
    306         g_print ("ALSA sample rate: %d\n", output->sample_rate); 
     309//      g_print ("ALSA sample rate: %d\n", output->sample_rate); 
    307310 
    308311        guint n_channels = FM_CHANNELS_STEREO; 
     
    334337        } 
    335338         
    336         g_print ("ALSA: buffer size is %lu\n", output_alsa->buffer_size); 
    337          
    338339        err = snd_pcm_hw_params_set_period_time_near (output_alsa->sound_handle, 
    339340                                                      output_alsa->hwparams, 
     
    360361                return FALSE; 
    361362        } 
     363 
     364/*      g_print ("ALSA: buffer size is %lu frames\n", output_alsa->buffer_size); 
     365        g_print ("ALSA: period size is %lu frames\n", output_alsa->period_size);*/ 
    362366 
    363367        output_alsa->buffer_size_samples = output_alsa->period_size; 
     
    378382fm_output_alsa_deactivate               (FmElement      *element) 
    379383{ 
    380         /*FmOutputAlsa *output_alsa = FM_OUTPUT_ALSA (element); 
     384//      g_print ("ALSA: deactivate\n"); 
     385        FmOutputAlsa *output_alsa = FM_OUTPUT_ALSA (element); 
    381386        gint err; 
    382387         
    383388        g_free (output_alsa->device_name); 
    384389         
     390        snd_pcm_hw_free (output_alsa->sound_handle); 
    385391        err = snd_pcm_close (output_alsa->sound_handle); 
    386392        if (err < 0) { 
     
    397403        output_alsa->buffer_size = 0; 
    398404        output_alsa->period_size = 0; 
    399         output_alsa->engine_buffer = NULL;*/ 
     405        output_alsa->thread = NULL; 
     406        output_alsa->stop_processing = FALSE; 
     407 
     408        g_free (output_alsa->buffer_int); 
     409        fm_buffer_destroy (output_alsa->main_buffer); 
     410 
     411        if (!fm_element_deactivate_connected (element)) 
     412                return FALSE; 
    400413         
    401414        return TRUE; 
     415} 
     416 
     417 
     418static void 
     419fm_output_alsa_dispose                  (GObject        *object) 
     420{ 
     421        FmOutputAlsa *output_alsa = FM_OUTPUT_ALSA (object); 
     422        g_assert (!output_alsa->sound_handle); 
     423         
     424        G_OBJECT_CLASS (parent_class)->dispose (object); 
    402425} 
    403426 
     
    410433         
    411434        g_free (output_alsa->device_name); 
    412         g_free (output_alsa); 
     435 
     436        G_OBJECT_CLASS (parent_class)->finalize (object); 
    413437} 
    414438 
     
    421445                 
    422446        output_alsa->thread = g_thread_create (fm_output_alsa_play, output_alsa, 
    423                                                FALSE, &error); 
     447                                               TRUE, &error); 
    424448        if (output_alsa->thread) { 
    425                 g_print("ALSA output started!\n"); 
     449//              g_print("ALSA output started!\n"); 
    426450                return TRUE; 
    427451        } else { 
     
    432456 
    433457 
     458static gboolean 
     459fm_output_alsa_stop                     (FmOutput       *output) 
     460{ 
     461        FmOutputAlsa *output_alsa = FM_OUTPUT_ALSA(output); 
     462 
     463        output_alsa->stop_processing = TRUE; 
     464 
     465//      g_print ("joining\n"); 
     466        g_thread_join (output_alsa->thread); 
     467 
     468        return TRUE; 
     469} 
     470 
     471 
    434472#define FLOAT_TO_INT(x) ((gint16) ((x) * 32768.0)) 
    435473 
     
    452490                                                 output_alsa->main_buffer->channel_data[1], 
    453491                                                 output_alsa->buffer_int, output_alsa->buffer_size_samples); 
    454  
    455492                gint err = 0; 
    456493                 
     
    458495                                      output_alsa->buffer_int,  
    459496                                      output_alsa->buffer_size_samples); 
     497 
     498//              g_print ("ALSA: written %u frames\n", output_alsa->buffer_size_samples); 
    460499                                       
    461500                if (err < 0) { 
     
    478517        } 
    479518         
    480         g_print ("output_alsa->stop_processing == TRUE!\n"); 
     519//      g_print ("output_alsa->stop_processing == TRUE!\n"); 
    481520         
    482521        return NULL; 
  • trunk/fm_server/src/fm_pipeline.c

    r195 r229  
    108108                             0); 
    109109 
     110        rgc_method_register ("deactivate", 
     111                             FM_TYPE_PIPELINE, 
     112                             G_CALLBACK (fm_pipeline_deactivate), 
     113                             rgc_marshal_VOID__VOID, 
     114                             0); 
     115 
    110116        rgc_method_register ("run", 
    111117                             FM_TYPE_PIPELINE, 
     
    155161fm_pipeline_activate                    (FmPipeline     *pipeline) 
    156162{ 
     163        FmElement *element = FM_ELEMENT (pipeline); 
    157164        g_assert (FM_IS_PIPELINE (pipeline)); 
    158165        g_return_if_fail (FM_IS_ELEMENT (pipeline->sink)); 
     166        g_return_if_fail (!element->active); 
    159167                 
    160168        g_print ("Activating pipeline...\n"); 
     
    162170        pipeline->sample_rate = fm_output_get_sample_rate(pipeline->sink); 
    163171        fm_element_activate(FM_ELEMENT(pipeline->sink)); 
     172} 
     173 
     174 
     175void 
     176fm_pipeline_deactivate                  (FmPipeline     *pipeline) 
     177{ 
     178        g_assert (FM_IS_PIPELINE (pipeline)); 
     179        g_return_if_fail (FM_IS_ELEMENT (pipeline->sink)); 
     180                 
     181        g_print ("Deactivating pipeline...\n"); 
     182         
     183        fm_element_deactivate(FM_ELEMENT(pipeline->sink)); 
    164184} 
    165185 
     
    225245        g_return_if_fail (FM_IS_PIPELINE (pipeline)); 
    226246        g_return_if_fail (FM_IS_OUTPUT(pipeline->sink)); 
    227          
     247 
    228248        g_debug("Stopping pipeline..."); 
    229249        fm_output_stop(pipeline->sink); 
  • trunk/fm_server/src/fm_pipeline.h

    r195 r229  
    6969 
    7070void 
     71fm_pipeline_deactivate                  (FmPipeline     *pipeline); 
     72 
     73void 
    7174fm_pipeline_set_sink                    (FmPipeline     *pipeline, 
    7275                                         FmElement      *sink);