CI: Fix missing script block in jenkinsfiles
[asterisk/asterisk.git] / formats / format_ogg_vorbis.c
index 9eb3900..ba86842 100644 (file)
@@ -33,8 +33,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
+#include <ogg/ogg.h>
 #include <vorbis/codec.h>
 #include <vorbis/vorbisenc.h>
 #include <vorbis/vorbisfile.h>
@@ -45,6 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/mod_format.h"
 #include "asterisk/module.h"
+#include "asterisk/format_cache.h"
 
 /*
  * this is the number of samples we deal with. Samples are converted
@@ -63,13 +63,13 @@ struct ogg_vorbis_desc {    /* format specific parameters */
        ogg_stream_state os;
        ogg_page og;
        ogg_packet op;
-       
+
        /* structures for handling Vorbis audio data */
        vorbis_info vi;
        vorbis_comment vc;
        vorbis_dsp_state vd;
        vorbis_block vb;
-       
+
        /*! \brief Indicates whether this filestream is set up for reading or writing. */
        int writing;
 
@@ -159,6 +159,7 @@ static int ogg_vorbis_rewrite(struct ast_filestream *s,
 
        if (vorbis_encode_init_vbr(&tmp->vi, 1, DEFAULT_SAMPLE_RATE, 0.4)) {
                ast_log(LOG_ERROR, "Unable to initialize Vorbis encoder!\n");
+               vorbis_info_clear(&tmp->vi);
                return -1;
        }
 
@@ -181,10 +182,10 @@ static int ogg_vorbis_rewrite(struct ast_filestream *s,
        while (!tmp->eos) {
                if (ogg_stream_flush(&tmp->os, &tmp->og) == 0)
                        break;
-               if (!fwrite(tmp->og.header, 1, tmp->og.header_len, s->f)) {
+               if (fwrite(tmp->og.header, 1, tmp->og.header_len, s->f) != tmp->og.header_len) {
                        ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
                }
-               if (!fwrite(tmp->og.body, 1, tmp->og.body_len, s->f)) {
+               if (fwrite(tmp->og.body, 1, tmp->og.body_len, s->f) != tmp->og.body_len) {
                        ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
                }
                if (ogg_page_eos(&tmp->og))
@@ -211,10 +212,10 @@ static void write_stream(struct ogg_vorbis_desc *s, FILE *f)
                                if (ogg_stream_pageout(&s->os, &s->og) == 0) {
                                        break;
                                }
-                               if (!fwrite(s->og.header, 1, s->og.header_len, f)) {
-                               ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
+                               if (fwrite(s->og.header, 1, s->og.header_len, f) != s->og.header_len) {
+                                       ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
                                }
-                               if (!fwrite(s->og.body, 1, s->og.body_len, f)) {
+                               if (fwrite(s->og.body, 1, s->og.body_len, f) != s->og.body_len) {
                                        ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
                                }
                                if (ogg_page_eos(&s->og)) {
@@ -242,16 +243,6 @@ static int ogg_vorbis_write(struct ast_filestream *fs, struct ast_frame *f)
                ast_log(LOG_ERROR, "This stream is not set up for writing!\n");
                return -1;
        }
-
-       if (f->frametype != AST_FRAME_VOICE) {
-               ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
-               return -1;
-       }
-       if (f->subclass.format.id != AST_FORMAT_SLINEAR) {
-               ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%s)!\n",
-                       ast_getformatname(&f->subclass.format));
-               return -1;
-       }
        if (!f->datalen)
                return -1;
 
@@ -284,6 +275,13 @@ static void ogg_vorbis_close(struct ast_filestream *fs)
                 * and write out the rest of the data */
                vorbis_analysis_wrote(&s->vd, 0);
                write_stream(s, fs->f);
+
+               /* Cleanup */
+               ogg_stream_clear(&s->os);
+               vorbis_block_clear(&s->vb);
+               vorbis_dsp_clear(&s->vd);
+               vorbis_comment_clear(&s->vc);
+               vorbis_info_clear(&s->vi);
        } else {
                /* clear OggVorbis_File handle */
                ov_clear(&s->ov_f);
@@ -310,9 +308,6 @@ static struct ast_frame *ogg_vorbis_read(struct ast_filestream *fs,
        }
 
        /* initialize frame */
-       fs->fr.frametype = AST_FRAME_VOICE;
-       ast_format_set(&fs->fr.subclass.format, AST_FORMAT_SLINEAR, 0);
-       fs->fr.mallocd = 0;
        AST_FRAME_SET_BUFFER(&fs->fr, fs->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        out_buf = (char *) (fs->fr.data.ptr);   /* SLIN data buffer */
 
@@ -376,7 +371,7 @@ static off_t ogg_vorbis_tell(struct ast_filestream *fs)
  * \brief Seek to a specific position in an OGG/Vorbis filestream.
  * \param fs The filestream to take action on.
  * \param sample_offset New position for the filestream, measured in 8KHz samples.
- * \param whence Location to measure 
+ * \param whence Location to measure
  * \return 0 on success, -1 on failure.
  */
 static int ogg_vorbis_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
@@ -435,9 +430,9 @@ static struct ast_format_def vorbis_f = {
 
 static int load_module(void)
 {
-       ast_format_set(&vorbis_f.format, AST_FORMAT_SLINEAR, 0);
+       vorbis_f.format = ast_format_slin;
        if (ast_format_def_register(&vorbis_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -447,6 +442,7 @@ static int unload_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "OGG/Vorbis audio",
+       .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
        .unload = unload_module,
        .load_pri = AST_MODPRI_APP_DEPEND