Author: fejj
Date: 2008-01-17 16:59:15 -0500 (Thu, 17 Jan 2008)
New Revision: 93208
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/list.cpp
trunk/moon/src/mplayer2.cpp
trunk/moon/src/pipeline.cpp
trunk/moon/src/pipeline.h
Log:
2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
* pipeline.cpp (Mp3FrameReader::ReadFrame): If we fail to read an
MPEG header, set MediaFrame->event to EOF. Same if we can't read
the frame data.
(Media::GetNextFrame): Don't try to decode the frame if it is an
event.
(ASFDemuxer::ReadFrame): If we reach EOF, set MediaFrame->event to
EOF.
* mplayer2.cpp (media_player_callback): pts is allowed to be 0.
(AdvanceFrame): Handle EOF frame events.
(audio_loop): Handle EOF frame events.
* list.cpp (Wait): Added.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2008-01-17 21:33:45 UTC (rev 93207)
+++ trunk/moon/src/ChangeLog 2008-01-17 21:59:15 UTC (rev 93208)
@@ -1,3 +1,19 @@
+2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * pipeline.cpp (Mp3FrameReader::ReadFrame): If we fail to read an
+ MPEG header, set MediaFrame->event to EOF. Same if we can't read
+ the frame data.
+ (Media::GetNextFrame): Don't try to decode the frame if it is an
+ event.
+ (ASFDemuxer::ReadFrame): If we reach EOF, set MediaFrame->event to
+ EOF.
+
+ * mplayer2.cpp (media_player_callback): pts is allowed to be 0.
+ (AdvanceFrame): Handle EOF frame events.
+ (audio_loop): Handle EOF frame events.
+
+ * list.cpp (Wait): Added.
+
2008-01-17 Chris Toshok <[EMAIL PROTECTED]>
* stylus.cpp (InkPresenter::OnCollectionChanged): we need to
@@ -22,10 +38,6 @@
2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
- * list.cpp (Wait): Added.
-
-2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
-
* mplayer2.cpp: Updated for MediaFrame changes.
* pipeline-ffmpeg.cc: Updated for MediaFrame changes.
Modified: trunk/moon/src/list.cpp
===================================================================
--- trunk/moon/src/list.cpp 2008-01-17 21:33:45 UTC (rev 93207)
+++ trunk/moon/src/list.cpp 2008-01-17 21:59:15 UTC (rev 93208)
@@ -339,14 +339,14 @@
Queue::Queue ()
{
pthread_mutex_init (&lock, NULL);
- pthread_cond_init (&cond, NULL);
+ //pthread_cond_init (&cond, NULL);
list = new List ();
}
Queue::~Queue ()
{
pthread_mutex_destroy (&lock);
- pthread_cond_destroy (&cond);
+ //pthread_cond_destroy (&cond);
delete list;
}
@@ -387,7 +387,7 @@
{
Lock ();
list->Append (node);
- pthread_cond_signal (&cond);
+ //pthread_cond_signal (&cond);
Unlock ();
}
Modified: trunk/moon/src/mplayer2.cpp
===================================================================
--- trunk/moon/src/mplayer2.cpp 2008-01-17 21:33:45 UTC (rev 93207)
+++ trunk/moon/src/mplayer2.cpp 2008-01-17 21:59:15 UTC (rev 93208)
@@ -234,7 +234,7 @@
MediaFrame *frame = closure->frame;
IMediaStream *stream = frame->stream;
- if (closure->frame == NULL || closure->frame->pts == 0)
+ if (closure->frame == NULL)
return MEDIA_SUCCESS;
closure->frame = NULL;
@@ -509,18 +509,26 @@
}
if (current_pts >= target_pts) {
- //printf ("MediaPlayer::AdvanceFrame () we're ahead of playback
(current_pts = %lld, seek_pts = xxx, target_pts = %lld).\n", current_pts,
target_pts);
+ // we are ahead of playback
return !eof;
- }
+ } else if (eof)
+ return false;
video->queue->Lock ();
list = video->queue->LinkedList ();
- int count = list->Length ();
- int dropped = 0;
-
if ((pkt = (Packet *) list->First ())) {
+ if (pkt->frame->event == FrameEventEOF) {
+ list->Unlink (pkt);
+ delete pkt;
+ eof = true;
+
+ video->queue->Unlock ();
+
+ return false;
+ }
+
do {
// always decode the frame or we get glitches in the
screen
frame = pkt->frame;
@@ -530,57 +538,58 @@
npkt = (Packet *) pkt->next;
current_pts = frame->pts;
- //printf ("MediaPlayer::AdvanceFrame (): got video
frame with pts %lld, frame->pts = %lld, queue length: %i\n", pkt->pts,
pkt->frame->pts, list->Length ());
list->Unlink (pkt);
media_player_enqueue_frames (this, 0, 1);
- //printf ("MediaPlayer::AdvanceFrame (): got video
frame with pts %lld, frame->pts = %lld, queue length: %i\n", pkt->pts,
pkt->frame->pts, list->Length ());
-
if (!frame->IsDecoded ()) {
//printf ("MediaPlayer::AdvanceFrame ():
decoding on main thread.\n");
MediaResult result =
stream->decoder->DecodeFrame (frame);
if (!MEDIA_SUCCEEDED (result)) {
+ printf ("MediaPlayer::AdvanceFrame ():
Couldn't decode frame.\n");
update = false;
- printf ("MediaPlayer::AdvanceFrame ():
Couldn't decode frame.\n");
}
}
if (update && current_pts >= target_pts) {
// we are in sync (or ahead) of audio playback
- //printf ("MediaPlayer::AdvanceFrame () we are
in sync (or ahead) of audio playback (current_pts = %lld, seek_pts = %lld,
target_pts = %lld).\n", current_pts, seek_pts, target_pts);
break;
}
if (!npkt) {
// no more packets in queue, this frame is the
most recent we have available
- //printf ("MediaPlayer::AdvanceFrame () no more
packets in queue (current_pts = %lld, seek_pts = %lld, target_pts = %lld).\n",
current_pts, seek_pts, target_pts);
break;
}
- delete pkt;
- dropped++;
+ if (npkt->frame->event == FrameEventEOF) {
+ // We've reached the EOF, current frame is the
most recent we can render
+ list->Unlink (npkt);
+ delete npkt;
+ eof = true;
+ break;
+ }
// we are lagging behind, drop this frame
- //printf ("MediaPlayer::AdvanceFrame () we are lagging
behind, drop this frame (current_pts = %lld, seek_pts = %lld, target_pts =
%lld).\n", current_pts, seek_pts, target_pts);
frame = NULL;
+ delete pkt;
pkt = npkt;
} while (pkt);
}
+ int nframes_left = list->Length ();
+
video->queue->Unlock ();
if (update && frame) {
- //printf ("MediaPlayer::AdvanceFrame () (%.2i items in list,
%.2i dropped) copying ? bytes to rgb buffer for current_pts = %lld (target_pts
= %lld, pkt->frame->pts = %lld), diff = %lld.\n", count, dropped, current_pts,
target_pts, pkt-frame->>pts, target_pts - pkt->frame->pts);
render_frame (this, frame);
//memcpy (video->rgb_buffer, pkt->data, pkt->size);
- if (count < 10) {
- media_player_enqueue_frames (this, 0, 1);
- printf ("Requested an extra frame.\n");
- }
+ if (nframes_left < 10)
+ media_player_enqueue_frames (this, 0, 10 -
nframes_left);
+
delete pkt;
+
return true;
}
@@ -1105,7 +1114,6 @@
uint32_t inleft;
uint8_t *inptr;
uint32_t n;
- bool play;
int ndfs;
outend = audio->outbuf + AUDIO_BUFLEN;
@@ -1142,9 +1150,8 @@
continue;
}
- play = true;
-
- if ((frame_pts = audio_play (audio, play, ufds, ndfs)) > 0) {
+ if ((frame_pts = audio_play (audio, true, ufds, ndfs)) > 0) {
+ printf ("played an audio frame\n");
// calculated pts
//printf ("frame_pts = %llu\n", frame_pts);
pthread_mutex_lock (&mplayer->target_pts_lock);
@@ -1157,6 +1164,9 @@
stream = pkt->frame->stream;
frame = pkt->frame;
+ if (frame->event == FrameEventEOF)
+ break;
+
if (!frame->IsDecoded ())
stream->decoder->DecodeFrame (frame);
@@ -1170,9 +1180,10 @@
media_player_enqueue_frames (mplayer, 1, 0);
} else if (!pkt) {
- // need to either wait for a packet to
- // be queued or break if the audio
- // stream is complete...
+ // need to either wait for another
+ // audio packet to be queued
+ //audio->queue->Wait ();
+ printf ("waiting for audio packet\n");
}
if (pkt != NULL) {
@@ -1199,7 +1210,7 @@
}
}
- //printf ("audio_loop (): exited.\n");
+ printf ("audio_loop (): exited.\n");
if (pkt != NULL)
delete pkt;
Modified: trunk/moon/src/pipeline.cpp
===================================================================
--- trunk/moon/src/pipeline.cpp 2008-01-17 21:33:45 UTC (rev 93207)
+++ trunk/moon/src/pipeline.cpp 2008-01-17 21:59:15 UTC (rev 93208)
@@ -353,7 +353,7 @@
}
MediaResult
-Media::GetNextFrame (MediaFrame *frame, uint8_t states)
+Media::GetNextFrame (MediaFrame *frame, uint16_t states)
{
//printf ("Media::GetNextFrame (%p).\n", stream);
@@ -374,9 +374,13 @@
if ((states & FRAME_DECODED) != FRAME_DECODED)
return result;
- result = frame->stream->decoder->DecodeFrame (frame);
- if (!MEDIA_SUCCEEDED (result))
- return result;
+ if (frame->event == 0) {
+ result = frame->stream->decoder->DecodeFrame (frame);
+ if (!MEDIA_SUCCEEDED (result))
+ return result;
+ } else {
+ frame->AddState (FRAME_DECODED);
+ }
//printf ("Media::GetNextFrame (%p) finished, size: %i.\n", stream,
frame->buflen);
@@ -413,21 +417,28 @@
pthread_mutex_lock (&queue_mutex);
while (queued_requests != NULL && queued_requests->IsEmpty ())
pthread_cond_wait (&queue_condition, &queue_mutex);
+
LOG_FRAMEREADERLOOP ("Media::FrameReaderLoop (): got
something.\n");
+
if (queued_requests != NULL) {
// Find the first audio node
- current = (Media::Node*) queued_requests->First ();
+ current = (Media::Node *) queued_requests->First ();
while (current != NULL &&
current->frame->stream->GetType () != MediaTypeAudio) {
- current = (Media::Node*) current->next;
+ current = (Media::Node *) current->next;
}
+
if (current != NULL && current->frame->stream->GetType
() == MediaTypeAudio) {
node = current;
} else {
// No audio node, just get the first node
node = (Media::Node*) queued_requests->First ();
}
+
queued_requests->Unlink (node);
- LOG_FRAMEREADERLOOP ("Media::FrameReaderLoop (): got a
%s node, there are %i nodes left.\n", node->stream->GetType () ==
MediaTypeAudio ? "audio" : (node->stream->GetType () == MediaTypeVideo ?
"video" : "unknown") , queued_requests->Length ());
+ LOG_FRAMEREADERLOOP ("Media::FrameReaderLoop (): got a
%s node, there are %i nodes left.\n",
+ node->stream->GetType () ==
MediaTypeAudio ? "audio" :
+ (node->stream->GetType () ==
MediaTypeVideo ? "video" : "unknown"),
+ queued_requests->Length ());
}
pthread_mutex_unlock (&queue_mutex);
@@ -449,6 +460,7 @@
}
LOG_FRAMEREADERLOOP ("Media::FrameReaderLoop (): exiting.\n");
}
+
#include <sched.h>
void
@@ -458,7 +470,7 @@
}
void
-Media::GetNextFrameAsync (MediaFrame *frame, uint8_t states)
+Media::GetNextFrameAsync (MediaFrame *frame, uint16_t states)
{
//printf ("Media::GetNextFrameAsync (%p).\n", stream);
if (queued_requests == NULL) {
@@ -477,7 +489,7 @@
pthread_mutex_lock (&queue_mutex);
// Add another node to our queue.
- Media::Node* node = new Media::Node ();
+ Media::Node *node = new Media::Node ();
node->frame = frame;
node->states = states;
queued_requests->Append (node);
@@ -812,7 +824,7 @@
}
MediaResult
-ASFDemuxer::ReadFrame (MediaFrame* frame)
+ASFDemuxer::ReadFrame (MediaFrame *frame)
{
//printf ("ASFDemuxer::ReadFrame (%p).\n", frame);
@@ -829,6 +841,7 @@
return MEDIA_DEMUXER_ERROR;
} else {
media->AddMessage (MEDIA_NO_MORE_DATA, "Reached end of
data.");
+ frame->event = FrameEventEOF;
return MEDIA_NO_MORE_DATA;
}
}
@@ -882,7 +895,7 @@
}
IMediaDemuxer *
-ASFDemuxerInfo::Create (Media* media)
+ASFDemuxerInfo::Create (Media *media)
{
return new ASFDemuxer (media);
}
@@ -1302,8 +1315,11 @@
offset = stream->GetPosition ();
- if (!stream->Read (buffer, 4))
+ if (!stream->Read (buffer, 4)) {
+ frame->AddState (FRAME_DEMUXED);
+ frame->event = FrameEventEOF;
return MEDIA_NO_MORE_DATA;
+ }
memset ((void *) &mpeg, 0, sizeof (mpeg));
if (mpeg_parse_header (&mpeg, buffer) == -1)
@@ -1329,20 +1345,16 @@
else
frame->buffer = (uint8_t *) g_try_malloc (frame->buflen);
- if (frame->buffer == NULL) {
- //media->AddMessage (MEDIA_OUT_OF_MEMORY, "Could not allocate
memory for next frame.");
+ if (frame->buffer == NULL)
return MEDIA_OUT_OF_MEMORY;
- }
if (mpeg.layer != 1 && !mpeg.padded)
frame->buffer[frame->buflen - 1] = 0;
memcpy (frame->buffer, buffer, 4);
- if (!stream->Read (frame->buffer + 4, len - 4)) {
- //media->AddMessage (MEDIA_DEMUXER_ERROR, "Error while copying
the next frame.");
- return MEDIA_DEMUXER_ERROR;
- }
+ if (!stream->Read (frame->buffer + 4, len - 4))
+ frame->event = FrameEventEOF;
frame->pts = cur_pts;
frame->duration = duration;
@@ -1351,6 +1363,9 @@
cur_pts += duration;
+ if (frame->event == FrameEventEOF)
+ return MEDIA_NO_MORE_DATA;
+
return MEDIA_SUCCESS;
}
@@ -1556,45 +1571,47 @@
bool
FileSource::Eof ()
{
- printf ("FileSource::Eof ().\n");
- printf ("FileSource::Eof (): Not implemented.\n");
- return false;
+ if (fd)
+ return feof (fd) != 0;
+
+ return true;
}
bool
-FileSource::Read (void* buffer, guint32 size)
+FileSource::Read (void *buffer, uint32_t n)
{
+ size_t nread;
+
//printf ("FileSource::Read (%p, %u).\n", buffer, size);
- size_t bytes_read;
-
if (buffer == NULL) {
- media->AddMessage (MEDIA_INVALID_ARGUMENT, g_strdup_printf
("FileSource::Read (%p, %u): buffer\n", buffer, size));
+ fprintf (stderr, "FileSource::Read (%p, %u): buffer\n", buffer,
n);
return false;
}
-
+
// Open the file if it hasn't been opened.
if (!fd && !(fd = fopen (filename, "rb"))) {
- media->AddMessage (MEDIA_FILE_ERROR, g_strdup_printf ("Could
not open the file '%s': %s.\n", filename, strerror (errno)));
+ fprintf (stderr, "FileSource::Read (%p, %u): could not open
`%s': %s.\n",
+ buffer, n, filename, strerror (errno));
return false;
}
-
- // Read
- bytes_read = fread (buffer, 1, size, fd);
- // Report any errors
- if (bytes_read != size) {
- if (ferror (fd) != 0) {
- media->AddMessage (MEDIA_FILE_ERROR, g_strdup_printf
("Could not read from the file '%s': %s.\n", filename, strerror (errno)));
- } else if (feof (fd) != 0) {
- media->AddMessage (MEDIA_FILE_ERROR, g_strdup_printf
("Reached end of file prematurely of the file '%s'.\n", filename));
- } else {
- media->AddMessage (MEDIA_FILE_ERROR, g_strdup_printf
("Unspecified error while reading the file '%s'.\n", filename));
- }
- return false;
+ // Read
+ if ((nread = fread (buffer, 1, n, fd)) == n)
+ return true;
+
+ if (ferror (fd) != 0) {
+ fprintf (stderr, "FileSource::Read (%p, %u): only managed to
read %u bytes from `%s': %s.\n",
+ buffer, n, nread, filename, strerror (errno));
+ } else if (feof (fd) != 0) {
+ fprintf (stderr, "FileSource::Read (%p, %u): only managed to
read %u bytes from `%s': end of file reached.\n",
+ buffer, n, nread, filename);
+ } else {
+ fprintf (stderr, "FileSource::Read (%p, %u): only managed to
read %u bytes from `%s': unknown error.\n",
+ buffer, n, nread, filename);
}
-
- return true;
+
+ return false;
}
bool
@@ -1619,29 +1636,24 @@
bool
FileSource::IsSeekable ()
{
- printf ("FileSource::IsSeekable ().\n");
-
return true;
}
bool
FileSource::Seek (int64_t offset)
{
- //printf ("FileSource::Seek (%llu).\n", position);
-
return Seek (offset, SEEK_CUR);
}
bool
FileSource::Seek (int64_t offset, int mode)
{
- //printf ("FileSource::Seek (%llu, %i).\n", offset, mode);
-
if (fseek (fd, offset, mode) == 0)
return true;
- media->AddMessage (MEDIA_SEEK_ERROR, g_strdup_printf ("Can't seek to
offset %llu with mode %i in '%s': %s.\n",
- offset, mode,
filename, strerror (errno)));
+ fprintf (stderr, "FileSource::Seek (%lld, %d) on `%s' failed: %s.\n",
+ offset, mode, filename, strerror (errno));
+
return false;
}
@@ -1726,6 +1738,7 @@
buffer = NULL;
buflen = 0;
state = 0;
+ event = 0;
for (int i = 0; i < 4; i++) {
data_stride[i] = 0;
Modified: trunk/moon/src/pipeline.h
===================================================================
--- trunk/moon/src/pipeline.h 2008-01-17 21:33:45 UTC (rev 93207)
+++ trunk/moon/src/pipeline.h 2008-01-17 21:59:15 UTC (rev 93208)
@@ -129,6 +129,11 @@
// is the frame you want to show).
#define FRAME_COPY_DECODED_DATA (1 << 7)
+enum FrameEvent {
+ FrameEventNone,
+ FrameEventEOF
+};
+
enum MoonPixelFormat {
MoonPixelFormatNone = 0,
MoonPixelFormatRGB32,
@@ -226,11 +231,11 @@
// Requests the decoder to decode the frame
// Returns the decoded frame
MediaResult GetNextFrame (MediaFrame *frame);
- MediaResult GetNextFrame (MediaFrame *frame, uint8_t states);
+ MediaResult GetNextFrame (MediaFrame *frame, uint16_t states);
// Requests reading of the next frame
void GetNextFrameAsync (MediaFrame *frame);
- void GetNextFrameAsync (MediaFrame *frame, uint8_t states);
+ void GetNextFrameAsync (MediaFrame *frame, uint16_t states);
void ClearQueue (); // Clears the queue and make sure the thread has
finished processing what it's doing
void DeleteQueue (); // Deletes the queue and finishes the thread
that's processing the queue.
void SetQueueCallback (MediaClosure *closure) { queue_closure =
closure; }
@@ -289,7 +294,7 @@
class Node : public List::Node {
public:
MediaFrame *frame;
- uint8_t states;
+ uint16_t states;
};
};
@@ -298,7 +303,7 @@
~MediaFrame ();
MediaFrame (IMediaStream *stream);
- void AddState (uint8_t state) { this->state |= state; } // There's no
way of "going back" to an earlier state
+ void AddState (uint16_t state) { this->state |= state; } // There's no
way of "going back" to an earlier state
bool IsDecoded () { return (state & FRAME_DECODED) == FRAME_DECODED; }
bool IsDemuxed () { return (state & FRAME_DEMUXED) == FRAME_DEMUXED; }
bool IsConverted () { return (state & FRAME_CONVERTED) ==
FRAME_CONVERTED; }
@@ -310,7 +315,8 @@
uint64_t pts; // Set by the demuxer
uint64_t duration; // Set by the demuxer
- uint8_t state; // Current state of the frame
+ uint16_t state; // Current state of the frame
+ uint16_t event; // special frame event if non-0
// The demuxer sets these to the encoded data which the
// decoder then uses and replaces with the decoded data.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches