Author: fejj
Date: 2007-10-05 10:42:33 -0400 (Fri, 05 Oct 2007)
New Revision: 86986
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/media.cpp
trunk/moon/src/mplayer.cpp
trunk/moon/src/mplayer.h
Log:
2007-10-05 Jeffrey Stedfast <[EMAIL PROTECTED]>
* media.cpp (DownloaderComplete): Call mplayer->DisplayFrame() in
the paused case.
(Stop): Here too.
(SetValue): And here too after a Seek() (altho it won't work if
the media is paused).
* mplayer.cpp (AdvanceFrame): Introduced a new bool variable,
update, which is true if any avcodec_decode_video() sets redraw to
true.
(DisplayFrame): New method largely based on JB's work to load the
current video frame into the mplayer surface.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-10-05 14:32:07 UTC (rev 86985)
+++ trunk/moon/src/ChangeLog 2007-10-05 14:42:33 UTC (rev 86986)
@@ -1,3 +1,17 @@
+2007-10-05 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * media.cpp (DownloaderComplete): Call mplayer->DisplayFrame() in
+ the paused case.
+ (Stop): Here too.
+ (SetValue): And here too after a Seek() (altho it won't work if
+ the media is paused).
+
+ * mplayer.cpp (AdvanceFrame): Introduced a new bool variable,
+ update, which is true if any avcodec_decode_video() sets redraw to
+ true.
+ (DisplayFrame): New method largely based on JB's work to load the
+ current video frame into the mplayer surface.
+
2007-10-05 Jb Evain <[EMAIL PROTECTED]>
* media.cpp|h, playlist.cpp|h: Don't open the first entry
Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp 2007-10-05 14:32:07 UTC (rev 86985)
+++ trunk/moon/src/media.cpp 2007-10-05 14:42:33 UTC (rev 86986)
@@ -472,10 +472,13 @@
//printf ("DownloaderComplete: autoplay = %s\n", autoplay ? "true" :
"false");
- if (autoplay || play_pending)
+ if (autoplay || play_pending) {
Play ();
- else
+ } else {
Pause ();
+ mplayer->DisplayFrame ();
+ Invalidate ();
+ }
}
void
@@ -559,8 +562,11 @@
if (!source)
return;
-
+
source->Stop (false);
+
+ mplayer->DisplayFrame ();
+ Invalidate ();
}
Value *
@@ -600,6 +606,8 @@
// position is in ticks, while mplayer expects time in
milliseconds.
mplayer->Seek (position * 1000 / TIMESPANTICKS_IN_SECOND);
+ mplayer->DisplayFrame ();
+ Invalidate ();
if (position != value->AsTimeSpan ()) {
v = Value (position, Type::TIMESPAN);
Modified: trunk/moon/src/mplayer.cpp
===================================================================
--- trunk/moon/src/mplayer.cpp 2007-10-05 14:32:07 UTC (rev 86985)
+++ trunk/moon/src/mplayer.cpp 2007-10-05 14:42:33 UTC (rev 86986)
@@ -416,9 +416,10 @@
MediaPlayer::AdvanceFrame ()
{
AVFrame *frame = NULL;
+ bool update = false;
int64_t target_pts;
- int redraw = 0;
Packet *pkt;
+ int redraw;
if (paused) {
// shouldn't happen, but just in case
@@ -459,9 +460,13 @@
while ((pkt = (Packet *) g_async_queue_try_pop (video->queue))) {
// always decode the frame or we get glitches in the screen
frame = avcodec_alloc_frame ();
+
+ redraw = 0;
avcodec_decode_video (video->stream->codec, frame,
&redraw, pkt->data, pkt->size);
+ update = update || redraw;
+
current_pts = pkt->pts;
pkt_free (pkt);
@@ -475,7 +480,7 @@
frame = NULL;
}
- if (redraw)
+ if (update)
convert_to_rgb (video, frame);
if (frame != NULL) {
@@ -487,6 +492,50 @@
}
void
+MediaPlayer::DisplayFrame ()
+{
+ AVFrame *frame;
+ AVPacket pkt;
+ int redraw;
+ int rv;
+
+ if (playing || video->stream_id == -1)
+ return;
+
+ if (audio->pcm != NULL && audio->stream_id != -1)
+ av_seek_frame (av_ctx, audio->stream_id, seek_pts,
AVSEEK_FLAG_BACKWARD);
+ else
+ av_seek_frame (av_ctx, video->stream_id, seek_pts,
AVSEEK_FLAG_BACKWARD);
+
+ while (av_read_frame (av_ctx, &pkt) >= 0) {
+ if (pkt.stream_index != video->stream_id) {
+ av_free_packet (&pkt);
+ continue;
+ }
+
+ redraw = 0;
+ frame = avcodec_alloc_frame ();
+
+ rv = avcodec_decode_video (video->stream->codec, frame,
&redraw, pkt.data, pkt.size);
+
+ if (rv > 0 && redraw) {
+ convert_to_rgb (video, frame);
+ av_free_packet (&pkt);
+ av_free (frame);
+ break;
+ }
+
+ av_free_packet (&pkt);
+ av_free (frame);
+ }
+
+ if (audio->pcm != NULL && audio->stream_id != -1)
+ av_seek_frame (av_ctx, audio->stream_id, seek_pts,
AVSEEK_FLAG_BACKWARD);
+ else
+ av_seek_frame (av_ctx, video->stream_id, seek_pts,
AVSEEK_FLAG_BACKWARD);
+}
+
+void
MediaPlayer::Render (cairo_t *cr)
{
if (video->stream_id == -1) {
@@ -659,9 +708,10 @@
playing = false;
if (av_ctx != NULL) {
- int stream_id = audio->stream_id != -1 ? audio->stream_id :
video->stream_id;
-
- av_seek_frame (av_ctx, stream_id, 0, AVSEEK_FLAG_BACKWARD);
+ if (audio->pcm != NULL && audio->stream_id != -1)
+ av_seek_frame (av_ctx, audio->stream_id, 0,
AVSEEK_FLAG_BACKWARD);
+ else
+ av_seek_frame (av_ctx, video->stream_id, 0,
AVSEEK_FLAG_BACKWARD);
}
}
Modified: trunk/moon/src/mplayer.h
===================================================================
--- trunk/moon/src/mplayer.h 2007-10-05 14:32:07 UTC (rev 86985)
+++ trunk/moon/src/mplayer.h 2007-10-05 14:42:33 UTC (rev 86986)
@@ -59,6 +59,7 @@
~MediaPlayer ();
bool AdvanceFrame ();
+ void DisplayFrame ();
void Render (cairo_t *cr);
cairo_surface_t *GetSurface ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches