git migration: Refactor the ASTERISK_FILE_VERSION macro
[asterisk/asterisk.git] / main / file.c
index fa4c63b..acd2cc6 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+ASTERISK_REGISTER_FILE()
 
 #include <dirent.h>
 #include <sys/stat.h>
@@ -97,6 +97,10 @@ static int publish_format_update(const struct ast_format_def *f, struct stasis_m
        RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup);
        RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 
+       if (!type) {
+               return -1;
+       }
+
        json_object = ast_json_pack("{s: s, s: o}",
                "format", f->name,
                "extensions", json_array_from_list(f->exts, "|"));
@@ -408,17 +412,12 @@ static void filestream_destructor(void *arg)
                }
        }
 
-       if (f->filename)
-               free(f->filename);
-       if (f->realfilename)
-               free(f->realfilename);
+       ast_free(f->filename);
+       ast_free(f->realfilename);
        if (f->vfs)
                ast_closestream(f->vfs);
-       if (f->write_buffer) {
-               ast_free(f->write_buffer);
-       }
-       if (f->orig_chan_name)
-               free((void *) f->orig_chan_name);
+       ast_free(f->write_buffer);
+       ast_free((void *)f->orig_chan_name);
        ao2_cleanup(f->lastwriteformat);
        ao2_cleanup(f->fr.subclass.format);
        ast_module_unref(f->fmt->module);
@@ -431,6 +430,7 @@ static struct ast_filestream *get_filestream(struct ast_format_def *fmt, FILE *b
        int l = sizeof(*s) + fmt->buf_size + fmt->desc_size;    /* total allocation size */
        if ( (s = ao2_alloc(l, filestream_destructor)) == NULL)
                return NULL;
+       ast_module_ref(fmt->module);
        s->fmt = fmt;
        s->f = bfile;
 
@@ -468,8 +468,7 @@ static int fn_wrapper(struct ast_filestream *s, const char *comment, enum wrap_f
        else if (mode == WRAP_REWRITE && f->rewrite && f->rewrite(s, comment))
                ast_log(LOG_WARNING, "Unable to rewrite format %s\n", f->name);
        else {
-               /* preliminary checks succeed. update usecount */
-               ast_module_ref(f->module);
+               /* preliminary checks succeed. */
                ret = 0;
        }
        return ret;
@@ -773,9 +772,11 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
        }
 
        /* Set the channel to a format we can work with and save off the previous format. */
+       ast_channel_lock(chan);
        ast_channel_set_oldwriteformat(chan, ast_channel_writeformat(chan));
        /* Set the channel to the best format that exists for the file. */
        res = ast_set_write_format_from_cap(chan, file_fmt_cap);
+       ast_channel_unlock(chan);
        /* don't need this anymore now that the channel's write format is set. */
        ao2_ref(file_fmt_cap, -1);
 
@@ -1020,6 +1021,11 @@ off_t ast_tellstream(struct ast_filestream *fs)
        return fs->fmt->tell(fs);
 }
 
+int ast_ratestream(struct ast_filestream *fs)
+{
+       return ast_format_get_sample_rate(fs->fmt->format);
+}
+
 int ast_stream_fastforward(struct ast_filestream *fs, off_t ms)
 {
        return ast_seekstream(fs, ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
@@ -1118,6 +1124,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
                return -1;
        if (vfs && ast_applystream(chan, vfs))
                return -1;
+       ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", filename, ast_channel_name(chan));
        res = ast_playstream(fs);
        if (!res && vfs)
                res = ast_playstream(vfs);
@@ -1624,7 +1631,6 @@ int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *
 {
        int res = 0;
        if (!ast_strlen_zero(file)) {
-               ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", file, ast_channel_name(chan));
                res = ast_streamfile(chan, file, ast_channel_language(chan));
                if (!res) {
                        res = ast_waitstream(chan, digits);
@@ -1774,6 +1780,6 @@ int ast_file_init(void)
        STASIS_MESSAGE_TYPE_INIT(ast_format_register_type);
        STASIS_MESSAGE_TYPE_INIT(ast_format_unregister_type);
        ast_cli_register_multiple(cli_file, ARRAY_LEN(cli_file));
-       ast_register_atexit(file_shutdown);
+       ast_register_cleanup(file_shutdown);
        return 0;
 }