Author: fejj
Date: 2007-06-12 18:50:58 -0400 (Tue, 12 Jun 2007)
New Revision: 79350
Added:
trunk/moon/src/media.h
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/ffvideo.cpp
Log:
2007-06-12 Jeffrey Stedfast <[EMAIL PROTECTED]>
* ffvideo.cpp: Instead of aborting when SDL_OpenAudio() fails,
simply disable audio for that video. Temporary hack.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-12 22:47:20 UTC (rev 79349)
+++ trunk/moon/src/ChangeLog 2007-06-12 22:50:58 UTC (rev 79350)
@@ -1,3 +1,8 @@
+2007-06-12 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * ffvideo.cpp: Instead of aborting when SDL_OpenAudio() fails,
+ simply disable audio for that video. Temporary hack.
+
2007-06-12 Sebastien Pouliot <[EMAIL PROTECTED]>
* transform.cpp: Fix SkewTransform with translations (Center[X|Y])
Modified: trunk/moon/src/ffvideo.cpp
===================================================================
--- trunk/moon/src/ffvideo.cpp 2007-06-12 22:47:20 UTC (rev 79349)
+++ trunk/moon/src/ffvideo.cpp 2007-06-12 22:50:58 UTC (rev 79350)
@@ -75,12 +75,19 @@
// Virtual method overrides
void getbounds ();
void render (Surface *s, int x, int y, int width, int height);
+ void pause (void);
+ void resume (void);
+ void stop (void);
+
virtual Point getxformorigin ();
GThread *decode_thread_id;
int pipes [2];
GIOChannel *pipe_channel;
+ GStaticMutex pause_mutex;
+ bool paused;
+
//
// AV Fields
//
@@ -90,14 +97,15 @@
AVCodec *video_codec;
AVStream *video_stream;
int video_stream_idx;
- GMutex *video_mutex;
+ GStaticMutex video_mutex;
// Audio
+ bool audio_enabled;
SDL_AudioSpec audio_spec;
AVCodec *audio_codec;
AVStream *audio_stream;
int audio_stream_idx;
- GMutex *audio_mutex;
+ GStaticMutex audio_mutex;
uint64_t target_pts;
@@ -235,13 +243,20 @@
QPacket *pkt;
int n;
+ /* try to aquire the pause mutex - if we can't, then we are paused -
output silence */
+ if (!g_static_mutex_trylock (&video->pause_mutex)) {
+ n = 0;
+
+ goto silence;
+ }
+
outlen = video->audio_outptr - video->audio_outbuf;
while (outlen < len) {
- g_mutex_lock (video->audio_mutex);
+ g_static_mutex_lock (&video->audio_mutex);
pkt = (QPacket *) g_async_queue_pop (video->audio_frames);
video->audio_frames_size -= pkt->size;
- g_mutex_unlock (video->audio_mutex);
+ g_static_mutex_unlock (&video->audio_mutex);
video->target_pts = pkt->pts;
@@ -276,6 +291,8 @@
outlen = video->audio_outptr - video->audio_outbuf;
}
+ g_static_mutex_unlock (&video->pause_mutex);
+
n = len < outlen ? len : outlen;
memcpy (stream, video->audio_outbuf, n);
if (n < outlen) {
@@ -285,6 +302,8 @@
video->audio_outptr = video->audio_outbuf;
}
+silence:
+
if (n < len)
memset (stream + n, 0, len - n);
}
@@ -346,7 +365,9 @@
spec.userdata = video;
if (SDL_OpenAudio (&spec, &video->audio_spec) < 0) {
printf ("SDL_OpenAudio: %s\n", SDL_GetError ());
- return -1;
+ video->audio_enabled = false;
+ } else {
+ video->audio_enabled = true;
}
//SDL_PauseAudio (0);
@@ -411,8 +432,11 @@
AVPacket pkt;
int ret;
+ g_static_mutex_lock (&video->pause_mutex);
+
if (av_read_frame (video->av_format_context, &pkt) < 0) {
// ffmpeg stream is complete (or error), either way -
nothing left to decode.
+ g_static_mutex_unlock (&video->pause_mutex);
break;
}
@@ -427,10 +451,10 @@
//printf ("queueing video packet\n");
- g_mutex_lock (video->video_mutex);
+ g_static_mutex_lock (&video->video_mutex);
g_async_queue_push (video->video_frames, pkt_new
(&pkt));
video->video_frames_size += pkt.size;
- g_mutex_unlock (video->video_mutex);
+ g_static_mutex_unlock (&video->video_mutex);
if (g_async_queue_length (video->video_frames) == 1)
notify_frame_ready (video);
@@ -438,16 +462,18 @@
} else if (pkt.stream_index == audio_stream_idx) {
//printf ("queueing audio packet\n");
- g_mutex_lock (video->audio_mutex);
+ g_static_mutex_lock (&video->audio_mutex);
g_async_queue_push (video->audio_frames, pkt_new
(&pkt));
video->audio_frames_size += pkt.size;
- g_mutex_unlock (video->audio_mutex);
+ g_static_mutex_unlock (&video->audio_mutex);
#endif /* ENABLE_AUDIO */
} else {
printf ("unknown packet\n");
}
av_free_packet (&pkt);
+
+ g_static_mutex_unlock (&video->pause_mutex);
}
while (g_async_queue_length (video->audio_frames) > 0)
@@ -484,22 +510,27 @@
gboolean cont = TRUE;
int redraw = 0;
-#ifndef ENABLE_AUDIO
- // no audio to sync to
- target_pts = (uint64_t) ((av_gettime () - video->play_start_time) *
video->micro_to_pts) + video->initial_pts;
-#else /* ENABLE_AUDIO */
- // sync w/ audio
- target_pts = video->target_pts;
-#endif
+ if (video->paused) {
+ video->timeout_handle = 0;
+ return FALSE;
+ }
+ if (!video->audio_enabled) {
+ // no audio to sync to
+ target_pts = (uint64_t) ((av_gettime () -
video->play_start_time) * video->micro_to_pts) + video->initial_pts;
+ } else {
+ // sync w/ audio
+ target_pts = video->target_pts;
+ }
+
while (g_async_queue_length (video->video_frames) > 0) {
QPacket *pkt;
long pkt_pts;
- g_mutex_lock (video->video_mutex);
+ g_static_mutex_lock (&video->video_mutex);
pkt = (QPacket *) g_async_queue_pop (video->video_frames);
video->video_frames_size -= pkt->size;
- g_mutex_unlock (video->video_mutex);
+ g_static_mutex_unlock (&video->video_mutex);
//
// Always decode the frame, or we get glitches in the screen if
we
@@ -608,9 +639,10 @@
// FIXME: Draw something, some black box or something
return;
}
+
cairo_save (s->cairo);
cairo_set_matrix (s->cairo, &absolute_xform);
-
+
cairo_set_source_surface (s->cairo, video_cairo_surface, 0, 0);
cairo_rectangle (s->cairo, 0, 0, this->w, this->h);
@@ -620,10 +652,37 @@
cairo_restore (s->cairo);
}
+void
+VideoFfmpeg::pause (void)
+{
+ if (!paused) {
+ g_static_mutex_lock (&pause_mutex);
+ SDL_PauseAudio (1);
+ paused = true;
+ }
+}
+
+void
+VideoFfmpeg::resume (void)
+{
+ if (paused) {
+ g_static_mutex_unlock (&pause_mutex);
+ restart_timer (this);
+ SDL_PauseAudio (0);
+ paused = false;
+ }
+}
+
+void
+VideoFfmpeg::stop (void)
+{
+
+}
+
static int ffmpeg_inited;
static void
-ffmpeg_init ()
+ffmpeg_init (void)
{
if (!ffmpeg_inited) {
avcodec_init ();
@@ -657,6 +716,8 @@
video_scale_context = NULL;
av_format_context = NULL;
+ audio_enabled = false;
+
audio_outbuf = ALIGN (audio_buffer, 2);
audio_outptr = audio_outbuf;
@@ -673,8 +734,9 @@
pipe (pipes);
fcntl (pipes [0], F_SETFL, O_NONBLOCK);
- audio_mutex = g_mutex_new ();
- video_mutex = g_mutex_new ();
+ g_static_mutex_init (&audio_mutex);
+ g_static_mutex_init (&video_mutex);
+
audio_frames = g_async_queue_new ();
video_frames = g_async_queue_new ();
pipe_channel = g_io_channel_unix_new (pipes [0]);
@@ -699,7 +761,7 @@
g_async_queue_unref (audio_frames);
g_async_queue_unref (video_frames);
- g_mutex_free (video_mutex);
+
close (pipes [0]);
close (pipes [1]);
g_io_channel_close (pipe_channel);
Added: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h 2007-06-12 22:47:20 UTC (rev 79349)
+++ trunk/moon/src/media.h 2007-06-12 22:50:58 UTC (rev 79350)
@@ -0,0 +1,93 @@
+#ifndef __MEDIA_H__
+#define __MEDIA_H__
+
+G_BEGIN_DECLS
+
+#include "runtime.h"
+#include "geometry.h"
+
+class MediaBase : public FrameworkElement {
+public:
+ static DependencyProperty *SourceProperty;
+ static DependencyProperty *StretchProperty;
+
+ MediaBase () { }
+ Value::Kind GetObjectType () { return Value::MEDIABASE; };
+};
+
+//Url *media_base_get_source (MediaBase *media_base);
+//void media_base_set_source (MediaBase *media_base, Url *source);
+
+Stretch media_base_get_stretch (MediaBase *media_base);
+void media_base_set_stretch (MediaBase *media_base, Stretch value);
+
+
+
+class MediaElement : public MediaBase {
+public:
+ static DependencyProperty *IsMutedProperty;
+ static DependencyProperty *AutoPlayProperty;
+ static DependencyProperty *VolumeProperty;
+ static DependencyProperty *BalanceProperty;
+ static DependencyProperty *NaturalVideoHeightProperty;
+ static DependencyProperty *NaturalVideoWidthProperty;
+ static DependencyProperty *NaturalDurationProperty;
+ static DependencyProperty *PositionProperty;
+ static DependencyProperty *DownloadProgressProperty;
+ static DependencyProperty *BufferingProgressProperty;
+ static DependencyProperty *CurrentStateProperty;
+ static DependencyProperty *BufferingTimeProperty;
+ static DependencyProperty *MarkersProperty;
+ static DependencyProperty *CanSeekProperty;
+ static DependencyProperty *AttributesProperty;
+
+ MediaElement ();
+ Value::Kind GetObjectType () { return Value::MEDIAELEMENT; };
+
+ void SetSource (DependencyObject *downloader, char *name);
+
+ void Pause ();
+ void Play ();
+ void Stop ();
+};
+
+
+bool media_element_get_auto_play (MediaElement *media);
+void media_element_set_auto_play (MediaElement *media, bool value);
+
+double media_element_get_balance (MediaElement *media);
+void media_element_set_balance (MediaElement *media, double value);
+
+double media_element_get_buffering_progress (MediaElement *media);
+void media_element_set_buffering_progress (MediaElement *media, double value);
+
+//TimeSpan media_element_get_buffering_time (MediaElement *media);
+//void media_element_set_buffering_time (MediaElement *media, TimeSpan value);
+
+bool media_element_get_can_seek (MediaElement *media);
+
+char *media_element_get_current_state (MediaElement *media);
+
+double media_element_get_download_progress (MediaElement *media);
+void media_element_set_download_progress (MediaElement *media, double value);
+
+bool media_element_get_is_muted (MediaElement *media);
+void media_element_set_is_muted (MediaElement *media, bool value);
+
+//TimelineMarkerCollection *media_element_get_markers (MediaElement *media);
+//void media_element_set_markers (MediaElement *media,
TimelineMarkerCollection *value);
+
+//Duration media_element_get_natural_duration (MediaElement *media);
+//void media_element_set_natural_duration (MediaElement *media, Duration
value);
+double media_element_get_natural_video_height (MediaElement *media);
+void media_element_set_natural_video_height (MediaElement *media, double
value);
+
+double media_element_get_natural_video_width (MediaElement *media);
+void media_element_set_natural_video_width (MediaElement *media, double value);
+
+//TimeSpan media_element_get_position (MediaElement *media);
+//void media_element_set_position (MediaElement *media, TimeSpan value);
+
+double media_element_get_volume (MediaElement *media);
+void media_element_set_volume (MediaElement *media, double value);
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches