Make --with-pjproject-bundled the default for Asterisk 15
[asterisk/asterisk.git] / channels / chan_oss.c
index 3a52ac9..ec112de 100644 (file)
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include <ctype.h>             /* isalnum() used here */
 #include <math.h>
 #include <sys/ioctl.h>         
 
 #ifdef __linux
 #include <linux/soundcard.h>
-#elif defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__GLIBC__)
+#elif defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__GLIBC__) || defined(__sun)
 #include <sys/soundcard.h>
 #else
 #include <soundcard.h>
@@ -69,6 +67,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/musiconhold.h"
 #include "asterisk/app.h"
 #include "asterisk/bridge.h"
+#include "asterisk/format_cache.h"
 
 #include "console_video.h"
 
@@ -334,7 +333,7 @@ static struct chan_oss_pvt oss_default = {
 
 static int setformat(struct chan_oss_pvt *o, int mode);
 
-static struct ast_channel *oss_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor,
+static struct ast_channel *oss_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor,
                                                                           const char *data, int *cause);
 static int oss_digit_begin(struct ast_channel *c, char digit);
 static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration);
@@ -726,7 +725,7 @@ static struct ast_frame *oss_read(struct ast_channel *c)
                return f;
        /* ok we can build and deliver the frame to the caller */
        f->frametype = AST_FRAME_VOICE;
-       ast_format_set(&f->subclass.format, AST_FORMAT_SLINEAR, 0);
+       f->subclass.format = ast_format_slin;
        f->samples = FRAME_SIZE;
        f->datalen = FRAME_SIZE * 2;
        f->data.ptr = o->oss_read_buf + AST_FRIENDLY_OFFSET;
@@ -792,11 +791,11 @@ static int oss_indicate(struct ast_channel *c, int cond, const void *data, size_
 /*!
  * \brief allocate a new channel.
  */
-static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state, const char *linkedid)
+static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
 {
        struct ast_channel *c;
 
-       c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, linkedid, 0, "Console/%s", o->device + 5);
+       c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, assignedids, requestor, 0, "Console/%s", o->device + 5);
        if (c == NULL)
                return NULL;
        ast_channel_tech_set(c, &oss_tech);
@@ -804,9 +803,9 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx,
                setformat(o, O_RDWR);
        ast_channel_set_fd(c, 0, o->sounddev); /* -1 if device closed, override later */
 
-       ast_format_set(ast_channel_readformat(c), AST_FORMAT_SLINEAR, 0);
-       ast_format_set(ast_channel_writeformat(c), AST_FORMAT_SLINEAR, 0);
-       ast_format_cap_add(ast_channel_nativeformats(c), ast_channel_readformat(c));
+       ast_channel_set_readformat(c, ast_format_slin);
+       ast_channel_set_writeformat(c, ast_format_slin);
+       ast_channel_nativeformats_set(c, oss_tech.capabilities);
 
        /* if the console makes the call, add video to the offer */
        /* if (state == AST_STATE_RINGING) TODO XXX CONSOLE VIDEO IS DISABLED UNTIL IT GETS A MAINTAINER
@@ -842,7 +841,7 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx,
        return c;
 }
 
-static struct ast_channel *oss_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause)
+static struct ast_channel *oss_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
 {
        struct ast_channel *c;
        struct chan_oss_pvt *o;
@@ -851,8 +850,6 @@ static struct ast_channel *oss_request(const char *type, struct ast_format_cap *
                AST_APP_ARG(flags);
        );
        char *parse = ast_strdupa(data);
-       char buf[256];
-       struct ast_format tmpfmt;
 
        AST_NONSTANDARD_APP_ARGS(args, parse, '/');
        o = find_desc(args.name);
@@ -863,8 +860,9 @@ static struct ast_channel *oss_request(const char *type, struct ast_format_cap *
                /* XXX we could default to 'dsp' perhaps ? */
                return NULL;
        }
-       if (!(ast_format_cap_iscompatible(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0)))) {
-               ast_log(LOG_NOTICE, "Format %s unsupported\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
+       if (ast_format_cap_iscompatible_format(cap, ast_format_slin) == AST_FORMAT_CMP_NOT_EQUAL) {
+               struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
+               ast_log(LOG_NOTICE, "Format %s unsupported\n", ast_format_cap_get_names(cap, &codec_buf));
                return NULL;
        }
        if (o->owner) {
@@ -872,7 +870,7 @@ static struct ast_channel *oss_request(const char *type, struct ast_format_cap *
                *cause = AST_CAUSE_BUSY;
                return NULL;
        }
-       c = oss_new(o, NULL, NULL, AST_STATE_DOWN, requestor ? ast_channel_linkedid(requestor) : NULL);
+       c = oss_new(o, NULL, NULL, AST_STATE_DOWN, assignedids, requestor);
        if (c == NULL) {
                ast_log(LOG_WARNING, "Unable to create new OSS channel\n");
                return NULL;
@@ -1131,7 +1129,7 @@ static char *console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args
                myc = o->ctx;
        if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
                o->hookstate = 1;
-               oss_new(o, mye, myc, AST_STATE_RINGING, NULL);
+               oss_new(o, mye, myc, AST_STATE_RINGING, NULL, NULL);
        } else
                ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
        if (s)
@@ -1175,7 +1173,6 @@ static char *console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args
 static char *console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
        struct chan_oss_pvt *o = find_desc(oss_active);
-       RAII_VAR(struct ast_channel *, b, NULL, ast_channel_cleanup);
        char *tmp, *ext, *ctx;
 
        switch (cmd) {
@@ -1438,6 +1435,31 @@ error:
 #endif
 }
 
+static int unload_module(void)
+{
+       struct chan_oss_pvt *o, *next;
+
+       ast_channel_unregister(&oss_tech);
+       ast_cli_unregister_multiple(cli_oss, ARRAY_LEN(cli_oss));
+
+       o = oss_default.next;
+       while (o) {
+               close(o->sounddev);
+               if (o->owner)
+                       ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
+               if (o->owner)
+                       return -1;
+               next = o->next;
+               ast_free(o->name);
+               ast_free(o);
+               o = next;
+       }
+       ao2_cleanup(oss_tech.capabilities);
+       oss_tech.capabilities = NULL;
+
+       return 0;
+}
+
 /*!
  * \brief Load the module
  *
@@ -1453,7 +1475,6 @@ static int load_module(void)
        struct ast_config *cfg = NULL;
        char *ctg = NULL;
        struct ast_flags config_flags = { 0 };
-       struct ast_format tmpfmt;
 
        /* Copy the default jb config over global_jbconf */
        memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
@@ -1476,14 +1497,14 @@ static int load_module(void)
        if (find_desc(oss_active) == NULL) {
                ast_log(LOG_NOTICE, "Device %s not found\n", oss_active);
                /* XXX we could default to 'dsp' perhaps ? */
-               /* XXX should cleanup allocated memory etc. */
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(oss_tech.capabilities = ast_format_cap_alloc(0))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
-       ast_format_cap_add(oss_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+       ast_format_cap_append(oss_tech.capabilities, ast_format_slin, 0);
 
        /* TODO XXX CONSOLE VIDEO IS DISABLE UNTIL IT HAS A MAINTAINER
         * add console_video_formats to oss_tech.capabilities once this occurs. */
@@ -1498,28 +1519,5 @@ static int load_module(void)
        return AST_MODULE_LOAD_SUCCESS;
 }
 
+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "OSS Console Channel Driver");
 
-static int unload_module(void)
-{
-       struct chan_oss_pvt *o, *next;
-
-       ast_channel_unregister(&oss_tech);
-       ast_cli_unregister_multiple(cli_oss, ARRAY_LEN(cli_oss));
-
-       o = oss_default.next;
-       while (o) {
-               close(o->sounddev);
-               if (o->owner)
-                       ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
-               if (o->owner)
-                       return -1;
-               next = o->next;
-               ast_free(o->name);
-               ast_free(o);
-               o = next;
-       }
-       oss_tech.capabilities = ast_format_cap_destroy(oss_tech.capabilities);
-       return 0;
-}
-
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "OSS Console Channel Driver");