[svn-commits] russell: branch russell/video_on_hold r141948 - /team/russell/video_on_hold/res/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Sep 8 20:18:57 CDT 2008
Author: russell
Date: Mon Sep 8 20:18:57 2008
New Revision: 141948
URL: http://svn.digium.com/view/asterisk?view=rev&rev=141948
Log:
Someone on asterisk-users asked about video on hold. I thought about it and it
didn't seem that hard so I figured I'd give it a try. Here is a rough first draft.
Maybe someone will have a video phone at Astricon in the code zone. If someone
brings one, we can get this working and merged. :)
Modified:
team/russell/video_on_hold/res/res_musiconhold.c
Modified: team/russell/video_on_hold/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/team/russell/video_on_hold/res/res_musiconhold.c?view=diff&rev=141948&r1=141947&r2=141948
==============================================================================
--- team/russell/video_on_hold/res/res_musiconhold.c (original)
+++ team/russell/video_on_hold/res/res_musiconhold.c Mon Sep 8 20:18:57 2008
@@ -211,6 +211,18 @@
*mohclass = NULL;
}
+static void close_streams(struct ast_channel *chan)
+{
+ if (chan->stream) {
+ ast_closestream(chan->stream);
+ chan->stream = NULL;
+ }
+
+ if (chan->vstream) {
+ ast_closestream(chan->vstream);
+ chan->vstream = NULL;
+ }
+}
static void moh_files_release(struct ast_channel *chan, void *data)
{
@@ -218,10 +230,8 @@
if (chan) {
if ((state = chan->music_state)) {
- if (chan->stream) {
- ast_closestream(chan->stream);
- chan->stream = NULL;
- }
+ close_streams(chan);
+
ast_verb(3, "Stopped music on hold on %s\n", chan->name);
if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) {
@@ -242,10 +252,7 @@
int tries;
/* Discontinue a stream if it is running already */
- if (chan->stream) {
- ast_closestream(chan->stream);
- chan->stream = NULL;
- }
+ close_streams(chan);
if (!state->class->total_files) {
ast_log(LOG_WARNING, "No files available for class '%s'\n", state->class->name);
@@ -280,44 +287,87 @@
return -1;
}
+ /* Check for a video stream, too */
+ ast_openvstream(chan, state->class->filearray[state->pos], chan->language);
+
/* Record the pointer to the filename for position resuming later */
state->save_pos_filename = state->class->filearray[state->pos];
ast_debug(1, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);
- if (state->samples)
- ast_seekstream(chan->stream, state->samples, SEEK_SET);
+ if (state->samples) {
+ if (chan->vstream) {
+ /* We can't seek a video stream, so we have to start at the beginning */
+ state->samples = 0;
+ } else {
+ ast_seekstream(chan->stream, state->samples, SEEK_SET);
+ }
+ }
return 0;
}
-
-static struct ast_frame *moh_files_readframe(struct ast_channel *chan)
-{
- struct ast_frame *f = NULL;
-
- if (!(chan->stream && (f = ast_readframe(chan->stream)))) {
- if (!ast_moh_files_next(chan))
- f = ast_readframe(chan->stream);
- }
-
- return f;
+struct moh_files_frames {
+ struct ast_frame *f;
+ struct ast_frame *vf;
+};
+
+static struct moh_files_frames moh_files_readframe(struct ast_channel *chan)
+{
+ struct moh_files_frames frs = {
+ .f = NULL,
+ };
+
+ /* wtf ... this code is ugly :( */
+
+ if (!(chan->stream && (frs.f = ast_readframe(chan->stream)))) {
+ goto moh_files_next;
+ }
+
+ if (chan->nativeformats & AST_FORMAT_VIDEO_MASK) {
+ if (chan->vstream) {
+ if (!(frs.vf = ast_readframe(chan->vstream))) {
+ ast_frfree(frs.f);
+ frs.f = NULL;
+ goto moh_files_next;
+ }
+ }
+ }
+
+ return frs;
+
+moh_files_next:
+ if (!ast_moh_files_next(chan)) {
+ frs.f = ast_readframe(chan->stream);
+ if (chan->vstream) {
+ frs.vf = ast_readframe(chan->vstream);
+ }
+ }
+
+ return frs;
}
static int moh_files_generator(struct ast_channel *chan, void *data, int len, int samples)
{
struct moh_files_state *state = chan->music_state;
- struct ast_frame *f = NULL;
+ struct moh_files_frames frs;
int res = 0;
state->sample_queue += samples;
while (state->sample_queue > 0) {
- if ((f = moh_files_readframe(chan))) {
- state->samples += f->samples;
- state->sample_queue -= f->samples;
- res = ast_write(chan, f);
- ast_frfree(f);
+ frs = moh_files_readframe(chan);
+ if (frs.f) {
+ state->samples += frs.f->samples;
+ state->sample_queue -= frs.f->samples;
+ res = ast_write(chan, frs.f);
+ ast_frfree(frs.f);
+ if (frs.vf) {
+ if (!res) {
+ res = ast_write_video(chan, frs.vf);
+ }
+ ast_frfree(frs.vf);
+ }
if (res < 0) {
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));
return -1;
@@ -1313,10 +1363,7 @@
ast_deactivate_generator(chan);
if (state) {
- if (chan->stream) {
- ast_closestream(chan->stream);
- chan->stream = NULL;
- }
+ close_streams(chan);
}
manager_event(EVENT_FLAG_CALL, "MusicOnHold",
More information about the svn-commits
mailing list