~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/src/audio/codecs/g729.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *  Author:  Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
28
28
 *  as that of the covered work.
29
29
 */
30
30
#include "g729.h"
 
31
#include "sfl_types.h"
31
32
#include <iostream>
32
33
#include <dlfcn.h>
33
34
#include <stdexcept>
34
35
 
35
 
#define G729_TYPE_ENCODER        (void (*)(bcg729EncoderChannelContextStruct*, int16_t[], uint8_t[]))
36
 
#define G729_TYPE_DECODER        (void (*)(bcg729DecoderChannelContextStruct*, uint8_t[], uint8_t, int16_t[]))
 
36
#define G729_TYPE_ENCODER        (void (*)(bcg729EncoderChannelContextStruct*, SFLAudioSample[], uint8_t[]))
 
37
#define G729_TYPE_DECODER        (void (*)(bcg729DecoderChannelContextStruct*, uint8_t[], uint8_t, SFLAudioSample[]))
37
38
 
38
39
#define G729_TYPE_DECODER_INIT   (bcg729DecoderChannelContextStruct*(*)())
39
40
#define G729_TYPE_ENCODER_INIT   (bcg729EncoderChannelContextStruct*(*)())
47
48
    encoder_(0),
48
49
    decoder_(0)
49
50
{
50
 
   handler_ = dlopen("libbcg729.so.0", RTLD_NOW);
51
 
   if (!handler_)
52
 
       throw std::runtime_error("g729: did not open shared lib");
53
 
 
54
 
   encoder_ = G729_TYPE_ENCODER dlsym(handler_, "bcg729Encoder");
55
 
   loadError(dlerror());
56
 
   decoder_ = G729_TYPE_DECODER dlsym(handler_, "bcg729Decoder");
57
 
   loadError(dlerror());
58
 
 
59
 
   bcg729DecoderChannelContextStruct*(*decInit)() = G729_TYPE_DECODER_INIT dlsym(handler_, "initBcg729DecoderChannel");
60
 
   loadError(dlerror());
61
 
   bcg729EncoderChannelContextStruct*(*encInit)() = G729_TYPE_ENCODER_INIT dlsym(handler_, "initBcg729EncoderChannel");
62
 
   loadError(dlerror());
63
 
 
64
 
   decoderContext_ = (*decInit)();
65
 
   encoderContext_ = (*encInit)();
 
51
    handler_ = dlopen("libbcg729.so.0", RTLD_NOW);
 
52
 
 
53
    if (!handler_)
 
54
        throw std::runtime_error("g729: did not open shared lib");
 
55
 
 
56
    encoder_ = G729_TYPE_ENCODER dlsym(handler_, "bcg729Encoder");
 
57
    loadError(dlerror());
 
58
    decoder_ = G729_TYPE_DECODER dlsym(handler_, "bcg729Decoder");
 
59
    loadError(dlerror());
 
60
 
 
61
    bcg729DecoderChannelContextStruct*(*decInit)() = G729_TYPE_DECODER_INIT dlsym(handler_, "initBcg729DecoderChannel");
 
62
    loadError(dlerror());
 
63
    bcg729EncoderChannelContextStruct*(*encInit)() = G729_TYPE_ENCODER_INIT dlsym(handler_, "initBcg729EncoderChannel");
 
64
    loadError(dlerror());
 
65
 
 
66
    decoderContext_ = (*decInit)();
 
67
    encoderContext_ = (*encInit)();
66
68
}
67
69
 
68
70
G729::~G729()
71
73
        dlclose(handler_);
72
74
}
73
75
 
74
 
int G729::decode(short *dst, unsigned char *buf, size_t buffer_size)
75
 
{
76
 
   decoder_(decoderContext_, buf, false, dst);
77
 
   decoder_(decoderContext_, buf + (buffer_size / 2), false, dst + 80);
78
 
   return 160;
79
 
}
80
 
 
81
 
int G729::encode(unsigned char *dst, short *src, size_t buffer_size)
82
 
{
83
 
   encoder_(encoderContext_, src, dst);
84
 
   encoder_(encoderContext_, src + (buffer_size / 2), dst + 10);
85
 
   return 20;
 
76
sfl::AudioCodec *
 
77
G729::clone()
 
78
{
 
79
    return new G729;
 
80
}
 
81
 
 
82
int G729::decode(SFLAudioSample *dst, unsigned char *buf, size_t buffer_size)
 
83
{
 
84
    decoder_(decoderContext_, buf, false, dst);
 
85
    decoder_(decoderContext_, buf + (buffer_size / 2), false, dst + 80);
 
86
    return 160;
 
87
}
 
88
 
 
89
int G729::encode(unsigned char *dst, SFLAudioSample *src, size_t buffer_size)
 
90
{
 
91
    encoder_(encoderContext_, src, dst);
 
92
    encoder_(encoderContext_, src + (buffer_size / 2), dst + 10);
 
93
    return 20;
86
94
}
87
95
 
88
96
void G729::loadError(const char *error)
89
97
{
90
 
   if (error != NULL)
91
 
      throw std::runtime_error("G729 failed to load");
 
98
    if (error != NULL)
 
99
        throw std::runtime_error("G729 failed to load");
92
100
}
93
101
 
94
102
// cppcheck-suppress unusedFunction