~ubuntu-branches/ubuntu/karmic/asterisk/karmic-proposed

« back to all changes in this revision

Viewing changes to main/frame.c

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Michel Dault, Faidon Liambotis, Tzafrir Cohen
  • Date: 2009-08-20 03:40:08 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090820034008-rg2s51o9ruqvmwml
Tags: 1:1.6.2.0~dfsg~beta4-0ubuntu1
* Merge from Debian.
  - Lsb patches dropped: fixed upstream
  - Patch for LP #350732 dropped: fixed upstream
* Added:
  - Add support for web interface
  - Don't enable voicetronix cards by default
  - Chown /dev/dahdi in init script
  - Add files for potential backports
  - Change maintainer
  - Standards version 3.8.3

* Debian changes

 [ Faidon Liambotis ]
 * Fix FTBFS on armel. (Closes: #532971)

 [ Tzafrir Cohen ]
 * New upstream beta.
 * Patch hardware_dtmf_mute_fix removed: Applied upstream.
 * No need for a separate app_directory_odbc (will use app_voicemail_odbc).
 * Fix name of voicemail 'openssl' dep. (Thomas Renard) (Closes: #539150)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "asterisk.h"
27
27
 
28
 
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 195212 $")
 
28
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 208501 $")
29
29
 
30
30
#include "asterisk/_private.h"
31
31
#include "asterisk/lock.h"
40
40
#include "asterisk/dsp.h"
41
41
#include "asterisk/file.h"
42
42
 
43
 
#ifdef TRACE_FRAMES
44
 
static int headers;
45
 
static AST_LIST_HEAD_STATIC(headerlist, ast_frame);
46
 
#endif
47
 
 
48
43
#if !defined(LOW_MEMORY)
49
44
static void frame_cache_cleanup(void *data);
50
45
 
318
313
#endif
319
314
 
320
315
        f->mallocd_hdr_len = sizeof(*f);
321
 
#ifdef TRACE_FRAMES
322
 
        AST_LIST_LOCK(&headerlist);
323
 
        headers++;
324
 
        AST_LIST_INSERT_HEAD(&headerlist, f, frame_list);
325
 
        AST_LIST_UNLOCK(&headerlist);
326
 
#endif  
327
316
        
328
317
        return f;
329
318
}
341
330
}
342
331
#endif
343
332
 
344
 
void ast_frame_free(struct ast_frame *fr, int cache)
 
333
static void __frame_free(struct ast_frame *fr, int cache)
345
334
{
346
335
        if (ast_test_flag(fr, AST_FRFLAG_FROM_TRANSLATOR)) {
347
336
                ast_translate_frame_freed(fr);
360
349
                 * to keep things simple... */
361
350
                struct ast_frame_cache *frames;
362
351
 
363
 
                if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) 
364
 
                    && frames->size < FRAME_CACHE_MAX_SIZE) {
 
352
                if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) &&
 
353
                    (frames->size < FRAME_CACHE_MAX_SIZE)) {
365
354
                        AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list);
366
355
                        frames->size++;
367
356
                        return;
375
364
        }
376
365
        if (fr->mallocd & AST_MALLOCD_SRC) {
377
366
                if (fr->src)
378
 
                        ast_free((char *)fr->src);
 
367
                        ast_free((void *) fr->src);
379
368
        }
380
369
        if (fr->mallocd & AST_MALLOCD_HDR) {
381
 
#ifdef TRACE_FRAMES
382
 
                AST_LIST_LOCK(&headerlist);
383
 
                headers--;
384
 
                AST_LIST_REMOVE(&headerlist, fr, frame_list);
385
 
                AST_LIST_UNLOCK(&headerlist);
386
 
#endif                  
387
370
                ast_free(fr);
388
371
        }
389
372
}
390
373
 
 
374
 
 
375
void ast_frame_free(struct ast_frame *frame, int cache)
 
376
{
 
377
        struct ast_frame *next;
 
378
 
 
379
        for (next = AST_LIST_NEXT(frame, frame_list);
 
380
             frame;
 
381
             frame = next, next = frame ? AST_LIST_NEXT(frame, frame_list) : NULL) {
 
382
                __frame_free(frame, cache);
 
383
        }
 
384
}
 
385
 
391
386
/*!
392
387
 * \brief 'isolates' a frame by duplicating non-malloc'ed components
393
388
 * (header, src, data).
398
393
        struct ast_frame *out;
399
394
        void *newdata;
400
395
 
401
 
        ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
402
 
        ast_clear_flag(fr, AST_FRFLAG_FROM_DSP);
 
396
        /* if none of the existing frame is malloc'd, let ast_frdup() do it
 
397
           since it is more efficient
 
398
        */
 
399
        if (fr->mallocd == 0) {
 
400
                return ast_frdup(fr);
 
401
        }
 
402
 
 
403
        /* if everything is already malloc'd, we are done */
 
404
        if ((fr->mallocd & (AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) ==
 
405
            (AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) {
 
406
                return fr;
 
407
        }
403
408
 
404
409
        if (!(fr->mallocd & AST_MALLOCD_HDR)) {
405
410
                /* Allocate a new header if needed */
406
 
                if (!(out = ast_frame_header_new()))
 
411
                if (!(out = ast_frame_header_new())) {
407
412
                        return NULL;
 
413
                }
408
414
                out->frametype = fr->frametype;
409
415
                out->subclass = fr->subclass;
410
416
                out->datalen = fr->datalen;
411
417
                out->samples = fr->samples;
412
418
                out->offset = fr->offset;
413
 
                out->data = fr->data;
414
419
                /* Copy the timing data */
415
420
                ast_copy_flags(out, fr, AST_FRFLAG_HAS_TIMING_INFO);
416
421
                if (ast_test_flag(fr, AST_FRFLAG_HAS_TIMING_INFO)) {
418
423
                        out->len = fr->len;
419
424
                        out->seqno = fr->seqno;
420
425
                }
421
 
        } else
 
426
        } else {
 
427
                ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
 
428
                ast_clear_flag(fr, AST_FRFLAG_FROM_DSP);
 
429
                ast_clear_flag(fr, AST_FRFLAG_FROM_FILESTREAM);
422
430
                out = fr;
 
431
        }
423
432
        
424
 
        if (!(fr->mallocd & AST_MALLOCD_SRC)) {
425
 
                if (fr->src) {
426
 
                        if (!(out->src = ast_strdup(fr->src))) {
427
 
                                if (out != fr)
428
 
                                        ast_free(out);
429
 
                                return NULL;
 
433
        if (!(fr->mallocd & AST_MALLOCD_SRC) && fr->src) {
 
434
                if (!(out->src = ast_strdup(fr->src))) {
 
435
                        if (out != fr) {
 
436
                                ast_free(out);
430
437
                        }
 
438
                        return NULL;
431
439
                }
432
 
        } else
 
440
        } else {
433
441
                out->src = fr->src;
 
442
                fr->src = NULL;
 
443
                fr->mallocd &= ~AST_MALLOCD_SRC;
 
444
        }
434
445
        
435
446
        if (!(fr->mallocd & AST_MALLOCD_DATA))  {
436
447
                if (!(newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET))) {
437
 
                        if (out->src != fr->src)
 
448
                        if (out->src != fr->src) {
438
449
                                ast_free((void *) out->src);
439
 
                        if (out != fr)
 
450
                        }
 
451
                        if (out != fr) {
440
452
                                ast_free(out);
 
453
                        }
441
454
                        return NULL;
442
455
                }
443
456
                newdata += AST_FRIENDLY_OFFSET;
445
458
                out->datalen = fr->datalen;
446
459
                memcpy(newdata, fr->data.ptr, fr->datalen);
447
460
                out->data.ptr = newdata;
 
461
        } else {
 
462
                out->data = fr->data;
 
463
                memset(&fr->data, 0, sizeof(fr->data));
 
464
                fr->mallocd &= ~AST_MALLOCD_DATA;
448
465
        }
449
466
 
450
467
        out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
822
839
                case AST_CONTROL_UNHOLD:
823
840
                        strcpy(subclass, "Unhold");
824
841
                        break;
825
 
                case AST_CONTROL_T38:
826
 
                        if (f->datalen != sizeof(enum ast_control_t38)) {
 
842
                case AST_CONTROL_T38_PARAMETERS:
 
843
                        if (f->datalen != sizeof(struct ast_control_t38_parameters *)) {
827
844
                                message = "Invalid";
828
845
                        } else {
829
 
                                enum ast_control_t38 state = *((enum ast_control_t38 *) f->data.ptr);
 
846
                                struct ast_control_t38_parameters *parameters = f->data.ptr;
 
847
                                enum ast_control_t38 state = parameters->request_response;
830
848
                                if (state == AST_T38_REQUEST_NEGOTIATE)
831
849
                                        message = "Negotiation Requested";
832
850
                                else if (state == AST_T38_REQUEST_TERMINATE)
838
856
                                else if (state == AST_T38_REFUSED)
839
857
                                        message = "Refused";
840
858
                        }
841
 
                        snprintf(subclass, sizeof(subclass), "T38/%s", message);
 
859
                        snprintf(subclass, sizeof(subclass), "T38_Parameters/%s", message);
842
860
                        break;
843
861
                case -1:
844
862
                        strcpy(subclass, "Stop generators");
939
957
}
940
958
 
941
959
 
942
 
#ifdef TRACE_FRAMES
943
 
static char *show_frame_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
944
 
{
945
 
        struct ast_frame *f;
946
 
        int x=1;
947
 
 
948
 
        switch (cmd) {
949
 
        case CLI_INIT:
950
 
                e->command = "core show frame stats";
951
 
                e->usage = 
952
 
                        "Usage: core show frame stats\n"
953
 
                        "       Displays debugging statistics from framer\n";
954
 
                return NULL;
955
 
        case CLI_GENERATE:
956
 
                return NULL;    
957
 
        }
958
 
 
959
 
        if (a->argc != 4)
960
 
                return CLI_SHOWUSAGE;
961
 
        AST_LIST_LOCK(&headerlist);
962
 
        ast_cli(a->fd, "     Framer Statistics     \n");
963
 
        ast_cli(a->fd, "---------------------------\n");
964
 
        ast_cli(a->fd, "Total allocated headers: %d\n", headers);
965
 
        ast_cli(a->fd, "Queue Dump:\n");
966
 
        AST_LIST_TRAVERSE(&headerlist, f, frame_list)
967
 
                ast_cli(a->fd, "%d.  Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
968
 
        AST_LIST_UNLOCK(&headerlist);
969
 
        return CLI_SUCCESS;
970
 
}
971
 
#endif
972
 
 
973
960
/* Builtin Asterisk CLI-commands for debugging */
974
961
static struct ast_cli_entry my_clis[] = {
975
962
        AST_CLI_DEFINE(show_codecs, "Displays a list of codecs"),
976
963
        AST_CLI_DEFINE(show_codec_n, "Shows a specific codec"),
977
 
#ifdef TRACE_FRAMES
978
 
        AST_CLI_DEFINE(show_frame_stats, "Shows frame statistics"),
979
 
#endif
980
964
};
981
965
 
982
966
int init_framer(void)