[asterisk-commits] dlee: branch dlee/record r389589 - in /team/dlee/record: include/asterisk/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 23 15:13:33 CDT 2013
Author: dlee
Date: Thu May 23 15:13:29 2013
New Revision: 389589
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389589
Log:
More recording stuffz
Modified:
team/dlee/record/include/asterisk/channel.h
team/dlee/record/include/asterisk/file.h
team/dlee/record/res/res_stasis_recording.c
Modified: team/dlee/record/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/channel.h?view=diff&rev=389589&r1=389588&r2=389589
==============================================================================
--- team/dlee/record/include/asterisk/channel.h (original)
+++ team/dlee/record/include/asterisk/channel.h Thu May 23 15:13:29 2013
@@ -1560,6 +1560,24 @@
* \retval non-zero on failure
*/
int ast_answer(struct ast_channel *chan);
+
+/*!
+ * \brief Answer a channel, if it's not already answered.
+ *
+ * \param chan channel to answer
+ *
+ * \details See ast_answer()
+ *
+ * \retval 0 on success
+ * \retval non-zero on failure
+ */
+static inline int ast_auto_answer(struct ast_channel *chan)
+{
+ if (ast_channel_state(chan) == AST_STATE_UP) {
+ /* Already answered */
+ return 0;
+ }
+ return ast_answer(chan);}
/*!
* \brief Answer a channel
Modified: team/dlee/record/include/asterisk/file.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/file.h?view=diff&rev=389589&r1=389588&r2=389589
==============================================================================
--- team/dlee/record/include/asterisk/file.h (original)
+++ team/dlee/record/include/asterisk/file.h Thu May 23 15:13:29 2013
@@ -64,8 +64,8 @@
*/
typedef void (ast_waitstream_fr_cb)(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val);
-/*!
- * \brief Streams a file
+/*!
+ * \brief Streams a file
* \param c channel to stream the file to
* \param filename the name of the file you wish to stream, minus the extension
* \param preflang the preferred language you wish to have the file streamed to you in
@@ -75,6 +75,27 @@
* \retval -1 on failure.
*/
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang);
+
+/*!
+ * \brief Plays a sound to the channel, in the channel's default language.
+ *
+ * This will stop any existing streams on the channel.
+
+ * \param c channel to stream the file to
+ * \param filename the name of the file you wish to stream, minus the extension
+ * \retval 0 on success.
+ * \retval -1 on failure.
+ */
+static int ast_play_sound(struct ast_channel *c, const char *filename)
+{
+ int res;
+ res = ast_streamfile(chan, "beep", ast_channel_language(chan));
+ if (res == 0) {
+ res = ast_waitstream(chan, "");
+ }
+ ast_stopstream(chan);
+ return res;
+}
/*!
* \brief stream file until digit
@@ -86,12 +107,12 @@
*/
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits);
-/*!
- * \brief Stops a stream
+/*!
+ * \brief Stops a stream
*
* \param c The channel you wish to stop playback on
*
- * Stop playback of a stream
+ * Stop playback of a stream
*
* \retval 0 always
*
Modified: team/dlee/record/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_recording.c?view=diff&rev=389589&r1=389588&r2=389589
==============================================================================
--- team/dlee/record/res/res_stasis_recording.c (original)
+++ team/dlee/record/res/res_stasis_recording.c Thu May 23 15:13:29 2013
@@ -145,39 +145,62 @@
}
static void *record_file(struct stasis_app_control *control,
- struct ast_channel *chan, void *data)
+ struct ast_channel *chan, void *data)
{
struct stasis_app_recording *recording = data;
- int res = 0;
+ int res;
+ long maxms;
ao2_lock(recording);
recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
recording_publish(recording);
ao2_unlock(recording);
- if (ast_channel_state(chan) != AST_STATE_UP) {
- res = ast_answer(chan);
- }
-
+ res = ast_auto_answer(chan);
if (res != 0) {
recording_fail(recording);
return NULL;
}
if (!recording->no_beep) {
- res = ast_streamfile(chan, "beep", ast_channel_language(chan));
- if (res == 0) {
- res = ast_waitstream(chan, "");
- }
- ast_stopstream(chan);
- }
-
+ res = ast_play_sound(chan, "beep");
+ }
if (res != 0) {
recording_fail(recording);
return NULL;
}
- ast_assert(0); // TODO
+ maxms = control->max_duration_seconds * 1000;
+ start = ast_tvnow();
+ while ((ms = ast_remaining_ms(start, maxms))) {
+ RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
+
+ res = ast_waitfor(chan, ms);
+ if (res < 0) {
+ break;
+ }
+
+ if (maxduration > 0 && res == 0) {
+ break;
+ }
+
+ f = ast_read(chan);
+ if (!f) {
+ break;
+ }
+
+ switch (f->frametype) {
+ case AST_FRAME_VOICE:
+ res = ast_writestream(s, f);
+ break;
+ case AST_FRAME_VIDEO:
+ res = ast_writestream(s, f);
+ break;
+ case AST_FRAME_DTMF:
+
+ break;
+ }
+ }
ao2_lock(recording);
recording->state = STASIS_APP_RECORDING_STATE_COMPLETE;
More information about the asterisk-commits
mailing list