]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res/res_stasis_snoop: generate silence when audiohook returns null
authorTorrey Searle <torrey@voxbone.com>
Tue, 11 Jul 2017 14:55:36 +0000 (16:55 +0200)
committerTorrey Searle <tsearle@gmail.com>
Thu, 13 Jul 2017 14:46:53 +0000 (09:46 -0500)
Currently when rtp is paused, no packets are written to the
recorded audio file, causing the silence to be skipped and recording
not properly time aligned.  The read handler as been adapted to
return a silence frame of the correct size.

ASTERISK-27128 #close

Change-Id: I2d7f60650457860b9c70907b14426756b058a844

res/res_stasis_snoop.c

index cd51638ea918519d6ca8a32ef00207cb9929a163..f797a9b942758b633002f2826469f87567293d86 100644 (file)
@@ -72,6 +72,8 @@ struct stasis_app_snoop {
        unsigned int whisper_active:1;
        /*! \brief Uniqueid of the channel this snoop is snooping on */
        char uniqueid[AST_MAX_UNIQUEID];
+       /*! \brief A frame of silence to use when the audiohook returns null */
+       struct ast_frame silence;
 };
 
 /*! \brief Destructor for snoop structure */
@@ -91,6 +93,11 @@ static void snoop_destroy(void *obj)
                ast_audiohook_destroy(&snoop->whisper);
        }
 
+       if (snoop->silence.data.ptr) {
+               ast_free(snoop->silence.data.ptr);
+               snoop->silence.data.ptr = NULL;
+       }
+
        ast_free(snoop->app);
 
        ast_channel_cleanup(snoop->chan);
@@ -197,7 +204,7 @@ static struct ast_frame *snoop_read(struct ast_channel *chan)
        frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, snoop->spy_format);
        ast_audiohook_unlock(&snoop->spy);
 
-       return frame ? frame : &ast_null_frame;
+       return frame ? frame : &snoop->silence;
 }
 
 /*! \brief Callback function for hanging up a Snoop channel */
@@ -383,6 +390,19 @@ struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan,
 
                snoop->spy_samples = ast_format_get_sample_rate(snoop->spy_format) / (1000 / SNOOP_INTERVAL);
                snoop->spy_active = 1;
+
+               snoop->silence.frametype = AST_FRAME_VOICE,
+               snoop->silence.datalen = snoop->spy_samples * sizeof(uint16_t),
+               snoop->silence.samples = snoop->spy_samples,
+               snoop->silence.mallocd = 0,
+               snoop->silence.offset = 0,
+               snoop->silence.src = __PRETTY_FUNCTION__,
+               snoop->silence.subclass.format = snoop->spy_format,
+               snoop->silence.data.ptr = ast_calloc(snoop->spy_samples, sizeof(uint16_t));
+               if (!snoop->silence.data.ptr) {
+                       ast_hangup(snoop->chan);
+                       return NULL;
+               }
        }
 
        /* If whispering is enabled set up the audiohook */