Skip to content
Snippets Groups Projects
Select Git revision
  • 4d689ef51a8af1d8d3a6662b41df344ca6d48a96
  • master default
  • build_error
  • copilot/fix-776
  • vcpkg_cache
  • cmake_fixes
  • pulls/1772757862/750
  • copilot/fix-770
  • windows_ci_static
  • c_link
  • cpack
  • windows_ci
  • cert_pk_id
  • proxy_push_result
  • cnode_put_id
  • update-windows-build
  • proxy
  • resubscribe_on_token_change
  • actions
  • client_mode
  • llhttp
  • v3.5.3rc1
  • v3.5.2
  • v3.5.1
  • v3.5.0
  • v3.5.0rc4
  • v3.5.0rc3
  • v3.5.0rc2
  • v3.5.0rc1
  • v3.4.0
  • v3.3.1
  • v3.3.1rc1
  • v3.3.1rc2
  • v3.3.0
  • v3.2.0
  • v3.1.11
  • v3.1.10
  • v3.1.9
  • v3.1.8.2
  • v3.1.8.1
  • v3.1.8
41 results

configure.ac

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    codeclist.c 4.45 KiB
    /*
     *  Copyright (C) 2007 Savoir-Faire Linux inc.
     *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.net>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
    
    #include <codeclist.h>
    
    #include <string.h>
    #include <stdlib.h>
    
    #include "dbus.h"
    
    GQueue * codecQueue = NULL;
    
    gint
    is_name_codecstruct (gconstpointer a, gconstpointer b)
    {
      codec_t * c = (codec_t *)a;
      if(strcmp(c->name, (const gchar *)b)==0)
        return 0;
      else
        return 1;
    }
    
    gint
    is_payload_codecstruct (gconstpointer a, gconstpointer b)
    {
      codec_t * c = (codec_t *)a;
      if(c->_payload == GPOINTER_TO_INT(b))
        return 0;
      else
        return 1;
    }
    
    void
    codec_list_init()
    {
      codecQueue = g_queue_new();
    }
    
    void
    codec_list_clear ()
    {
      g_queue_free (codecQueue);
      codecQueue = g_queue_new();
    }
    
    void
    codec_list_add(codec_t * c)
    {
      g_queue_push_tail (codecQueue, (gpointer *) c);
    }
    
    
    
    void 
    codec_set_active(codec_t * c)
    {
    	
    	if(c)
    	{
    		DEBUG("%s set active", c->name);
    		c->is_active = TRUE;
    	}
    }
    
    void
    codec_set_inactive(codec_t * c)
    {
      
      if(c)
        c->is_active = FALSE;
    }
    
    guint
    codec_list_get_size()
    {
      return g_queue_get_length(codecQueue);
    }
    
    codec_t*
    codec_list_get_by_name( const gchar* name)
    {
      GList * c = g_queue_find_custom(codecQueue, name, is_name_codecstruct);
      if(c)
        return (codec_t *)c->data;
      else
        return NULL;
    }
    
    codec_t*
    codec_list_get_by_payload(gconstpointer payload)
    {
      GList * c = g_queue_find_custom(codecQueue, payload, is_payload_codecstruct);
      if(c)
        return (codec_t *)c->data;
      else
        return NULL;
    }
    
    codec_t*
    codec_list_get_nth(guint index)
    {
      return g_queue_peek_nth(codecQueue, index);
    }
    
    void
    codec_set_prefered_order(guint index)
    {
      codec_t * prefered = codec_list_get_nth(index);
      g_queue_pop_nth(codecQueue, index);
      g_queue_push_head(codecQueue, prefered);
    }
    
    /**
     *
     */
    void
    codec_list_move_codec_up(guint index)
    {
            DEBUG("Codec list Size: %i \n",codec_list_get_size());
    	if(index != 0)
    	{
    		gpointer codec = g_queue_pop_nth(codecQueue, index);
    		g_queue_push_nth(codecQueue, codec, index-1);
    	}
    
    	// DEBUG
    	unsigned int i;
    	DEBUG("Codec list");
    	for(i=0; i < codecQueue->length; i++)
    		DEBUG("%s", codec_list_get_nth(i)->name);
    }
    
    /**
     *
     */
    void
    codec_list_move_codec_down(guint index)
    {
            DEBUG("Codec list Size: %i \n",codec_list_get_size());
    	if(index != codecQueue->length)
    	{
    		gpointer codec = g_queue_pop_nth(codecQueue, index);
    		g_queue_push_nth(codecQueue, codec, index+1);
    	}
    
    	// PRINT
    	unsigned int i;
    	DEBUG("Codec list");
    	for(i=0; i < codecQueue->length; i++)
    		DEBUG("%s", codec_list_get_nth(i)->name);
    }
    
    /**
     *
     */
    void
    codec_list_update_to_daemon()
    {
    	// String listing of all codecs payloads
    	const gchar** codecList;
    
    	// Length of the codec list
    	int length = codecQueue->length;
    
    	// Initiate double array char list for one string
    	codecList = (void*)malloc(sizeof(void*));
    
    	// Get all codecs in queue
    	int i, c = 0;
    	DEBUG("List of active codecs :");
    	for(i = 0; i < length; i++)
    	{
    		codec_t* currentCodec = codec_list_get_nth(i);
    		// Assert not null
    		if(currentCodec)
    		{
    			// Save only if active
    			if(currentCodec->is_active)
    			{
    				// Reallocate memory each time more than one active codec is found
    				if(c!=0)
    					codecList = (void*)realloc(codecList, (c+1)*sizeof(void*));
    				// Allocate memory for the payload
    				*(codecList+c) = (gchar*)malloc(sizeof(gchar*));
    				char payload[10];
    				// Put payload string in char array
    				sprintf(payload, "%d", currentCodec->_payload);
    				strcpy((char*)*(codecList+c), payload);
    				DEBUG(" %s", *(codecList+c));
    				c++;
    			}
    		}
    	}
    
    	// Allocate NULL array at the end for Dbus
    	codecList = (void*)realloc(codecList, (c+1)*sizeof(void*));
    	*(codecList+c) = NULL;
    
    	// call dbus function with array of strings
    	dbus_set_active_codec_list(codecList);
    
    	// Delete memory
    	for(i = 0; i < c; i++) {
    		free((gchar*)*(codecList+i));
    	}
    	free(codecList);
    }