Author: fejj
Date: 2007-08-21 16:40:27 -0400 (Tue, 21 Aug 2007)
New Revision: 84586
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/mplayer.cpp
trunk/moon/src/mplayer.h
Log:
2007-08-21 Jeffrey Stedfast <[EMAIL PROTECTED]>
* mplayer.cpp (Open): Merged both Open() implementations into a
single one. We no longer use Open() without passing a uri (since
Stop() has been implemented in a better way).
(AdvanceFrame): Keep track of our current pts so that we won't get
ahead of the audio if called too often.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-21 20:38:53 UTC (rev 84585)
+++ trunk/moon/src/ChangeLog 2007-08-21 20:40:27 UTC (rev 84586)
@@ -1,3 +1,11 @@
+2007-08-21 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * mplayer.cpp (Open): Merged both Open() implementations into a
+ single one. We no longer use Open() without passing a uri (since
+ Stop() has been implemented in a better way).
+ (AdvanceFrame): Keep track of our current pts so that we won't get
+ ahead of the audio if called too often.
+
2007-08-20 Chris Toshok <[EMAIL PROTECTED]>
* rect.cpp (bounding_rect_for_transformed_rect): oops, got
Modified: trunk/moon/src/mplayer.cpp
===================================================================
--- trunk/moon/src/mplayer.cpp 2007-08-21 20:38:53 UTC (rev 84585)
+++ trunk/moon/src/mplayer.cpp 2007-08-21 20:40:27 UTC (rev 84586)
@@ -32,6 +32,7 @@
G_END_DECLS
#include "mplayer.h"
+//#include "stream.h"
#if GLIB_SIZEOF_VOID_P == 8
#define ALIGN(addr,size) (uint8_t *) (((uint64_t) (((uint8_t *) (addr)) +
(size) - 1)) & ~((size) - 1))
@@ -99,7 +100,7 @@
// sync
uint64_t initial_pts;
- int usec_per_frame;
+ int msec_per_frame;
double usec_to_pts;
};
@@ -167,11 +168,13 @@
video->surface = NULL;
video->rgb_buffer = NULL;
video->initial_pts = 0;
- video->usec_per_frame = 0;
+ video->msec_per_frame = 0;
video->usec_to_pts = 0;
pause_time = 0;
start_time = 0;
+
+ current_pts = 0;
target_pts = 0;
seek_pts = 0;
@@ -203,11 +206,16 @@
}
bool
-MediaPlayer::Open ()
+MediaPlayer::Open (const char *uri)
{
AVCodecContext *encoding;
AVStream *stream;
+ Close ();
+
+ g_free (this->uri);
+ this->uri = NULL;
+
if (uri == NULL || *uri == '\0')
return false;
@@ -224,6 +232,7 @@
return false;
}
+ this->uri = g_strdup (uri);
opened = true;
av_read_play (av_ctx);
@@ -278,8 +287,8 @@
// starting time
video->initial_pts = stream->start_time;
- // usec per frame
- video->usec_per_frame = (int) (1000 / av_q2d
(stream->r_frame_rate));
+ // msec per frame
+ video->msec_per_frame = (int) (1000 / av_q2d
(stream->r_frame_rate));
// usec -> pts conversion
video->usec_to_pts = (double) encoding->time_base.num /
(double) encoding->time_base.den;
@@ -319,17 +328,6 @@
return true;
}
-bool
-MediaPlayer::Open (const char *uri)
-{
- Close ();
-
- g_free (this->uri);
- this->uri = g_strdup (uri);
-
- return Open ();
-}
-
void
MediaPlayer::Close ()
{
@@ -367,11 +365,13 @@
video->stream = NULL;
video->codec = NULL;
video->initial_pts = 0;
- video->usec_per_frame = 0;
+ video->msec_per_frame = 0;
video->usec_to_pts = 0;
pause_time = 0;
start_time = 0;
+
+ current_pts = 0;
target_pts = 0;
seek_pts = 0;
}
@@ -399,9 +399,9 @@
AVFrame *frame = NULL;
bool advanced = false;
uint64_t target_pts;
+ int skipped = 0;
int redraw = 0;
Packet *pkt;
- uint64_t pts;
if (paused) {
// shouldn't happen, but just in case
@@ -427,25 +427,32 @@
target_pts = this->target_pts;
}
+ if (current_pts >= target_pts)
+ return false;
+
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 ();
avcodec_decode_video (video->stream->codec, frame,
&redraw, pkt->data, pkt->size);
- pts = pkt->pts;
+ current_pts = pkt->pts;
pkt_free (pkt);
- if (pts + video->usec_per_frame >= target_pts) {
+ if (current_pts >= target_pts) {
// we are in sync (or ahead) of audio playback
break;
}
+ skipped++;
+
// we are lagging behind, drop this frame
av_free (frame);
frame = NULL;
}
+ printf ("skipped %d frames\n", skipped);
+
if (redraw) {
convert_to_rgb (video, frame);
advanced = true;
@@ -511,7 +518,7 @@
start_time += (av_gettime () - pause_time);
if (video->stream_id != -1)
- return g_timeout_add (video->usec_per_frame, callback,
user_data);
+ return g_timeout_add (video->msec_per_frame, callback,
user_data);
return 0;
}
@@ -767,6 +774,7 @@
avcodec_init ();
av_register_all ();
avcodec_register_all ();
+ //register_protocol (&stream_protocol);
ffmpeg_initialized = true;
}
@@ -1058,5 +1066,7 @@
av_free_packet (&pkt);
}
+ printf ("mplayer io_loop exiting\n");
+
return NULL;
}
Modified: trunk/moon/src/mplayer.h
===================================================================
--- trunk/moon/src/mplayer.h 2007-08-21 20:38:53 UTC (rev 84585)
+++ trunk/moon/src/mplayer.h 2007-08-21 20:40:27 UTC (rev 84586)
@@ -43,6 +43,7 @@
uint64_t pause_time;
uint64_t start_time;
+ uint64_t current_pts;
uint64_t target_pts;
uint64_t seek_pts;
@@ -59,7 +60,6 @@
void Render (cairo_t *cr);
cairo_surface_t *GetSurface ();
- bool Open ();
bool Open (const char *uri);
void Close ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches