Author: fejj
Date: 2008-01-24 15:33:40 -0500 (Thu, 24 Jan 2008)
New Revision: 93835

Modified:
   trunk/moon/src/asf/asf.cpp
   trunk/moon/src/asf/asf.h
   trunk/moon/src/media.cpp
   trunk/moon/src/media.h
   trunk/moon/src/mplayer.cpp
   trunk/moon/src/mplayer.h
   trunk/moon/src/pipeline.cpp
   trunk/moon/src/pipeline.h
Log:
go back to using uint64_t for pts values

Modified: trunk/moon/src/asf/asf.cpp
===================================================================
--- trunk/moon/src/asf/asf.cpp  2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/asf/asf.cpp  2008-01-24 20:33:40 UTC (rev 93835)
@@ -477,7 +477,7 @@
 }
 
 int
-ASFParser::GetPacketIndexOfPts (int stream_id, int64_t pts)
+ASFParser::GetPacketIndexOfPts (int stream_id, uint64_t pts)
 {
        ASFPacket *packet = NULL;
        int result = 0;
@@ -486,9 +486,9 @@
        // greater than the one we're looking for.
        
        while (ReadPacket (packet, result)) {
-               int64_t current_pts = packet->GetPts (stream_id);
+               uint64_t current_pts = packet->GetPts (stream_id);
                
-               if (current_pts < 0) // Can't read pts for some reason.
+               if (current_pts == ULLONG_MAX) // Can't read pts for some 
reason.
                        return -1;
                
                if (current_pts > pts) // We've found the packet after the one 
we're looking for
@@ -646,15 +646,15 @@
        return NULL;
 }
 
-int64_t
+uint64_t
 ASFPacket::GetPts (int stream_id)
 {
        if (!payloads)
-               return -1;
+               return ULLONG_MAX;
        
        asf_single_payload *first = GetFirstPayload (stream_id);
        if (!first)
-               return -1;
+               return ULLONG_MAX;
        
        return first->get_presentation_time ();
 }
@@ -704,6 +704,7 @@
        
        for (int i = 0; payloads[i]; i++)
                delete payloads[i];
+       
        g_free (payloads);
 }
 
@@ -751,9 +752,9 @@
 }
 
 bool
-ASFFrameReader::Seek (int stream_id, int64_t pts)
+ASFFrameReader::Seek (int stream_id, uint64_t pts)
 {
-       //printf ("ASFFrameReader::Seek (%d, %lld).\n", stream_id, pts);
+       //printf ("ASFFrameReader::Seek (%d, %llu).\n", stream_id, pts);
        
        if (!CanSeek ())
                return false;
@@ -769,17 +770,17 @@
        RemoveAll ();
        
        while (Advance (stream_id)) {
-               //printf ("ASFFrameReader::Seek (%d, %lld): Checking pts: 
%lld\n", stream_id, pts, Pts ());
+               //printf ("ASFFrameReader::Seek (%d, %llu): Checking pts: 
%llu\n", stream_id, pts, Pts ());
                if (Pts () > pts) {
-                       //printf ("ASFFrameReader::Seek (%d, %lld): Found pts: 
%lld\n", stream_id, pts, Pts ());
+                       //printf ("ASFFrameReader::Seek (%d, %llu): Found pts: 
%llu\n", stream_id, pts, Pts ());
                        if (IsKeyFrame ()) {
-                               //printf ("ASFFrameReader::Seek (%d, %lld): 
Found a key frame\n", stream_id, pts);
+                               //printf ("ASFFrameReader::Seek (%d, %llu): 
Found a key frame\n", stream_id, pts);
                                found = true;
                        } else if (false) {
-                               //printf ("ASFFrameReader::Seek (%d, %lld): 
Checking for audio frame..\n", stream_id, pts);
+                               //printf ("ASFFrameReader::Seek (%d, %llu): 
Checking for audio frame..\n", stream_id, pts);
                                asf_stream_properties* asp = parser->GetStream 
(StreamId ());
                                found = asp->is_audio ();
-                               //printf ("ASFFrameReader::Seek (%d, %lld): 
Checking for audio frame: %s\n", stream_id, pts, found ? "true" : "false");
+                               //printf ("ASFFrameReader::Seek (%d, %llu): 
Checking for audio frame: %s\n", stream_id, pts, found ? "true" : "false");
                        }
                        if (found)
                                break;
@@ -792,7 +793,7 @@
                return false;
        }
        
-       //printf ("ASFFrameReader::Seek (%d, %lld): Counted to %i.\n", 
stream_id, pts, counter);
+       //printf ("ASFFrameReader::Seek (%d, %llu): Counted to %d.\n", 
stream_id, pts, counter);
                
        current_packet_index = 0;
        RemoveAll ();
@@ -801,7 +802,7 @@
                if (!Advance (stream_id)) {
                        return false;
                }
-               //printf ("ASFFrameReader::Seek (%d, %lld): Counting: %i, pts: 
%lld, size: %i.\n", stream_id, pts, counter, Pts (), Size ());
+               //printf ("ASFFrameReader::Seek (%d, %lld): Counting: %i, pts: 
%llu, size: %i.\n", stream_id, pts, counter, Pts (), Size ());
        }
        
        // Don't return any frames before the pts we seeked to.
@@ -809,7 +810,7 @@
        // has frames with pts below this one.
        first_pts = pts; 
        
-       //printf ("ASFFrameReader::Seek (%d, %lld): Found the requested pts, 
we're now at: %lld.\n", stream_id, pts, Pts ());
+       //printf ("ASFFrameReader::Seek (%d, %llu): Found the requested pts, 
we're now at: %llu.\n", stream_id, pts, Pts ());
        
        return true;
 }
@@ -855,7 +856,7 @@
        
        size = 0;
        
-       ASF_LOG ("ASFFrameReader::Advance (): frame data: size = %lld, key = 
%s, pts = %lld, stream# = %d, media_object_number = %u.\n", 
+       ASF_LOG ("ASFFrameReader::Advance (): frame data: size = %lld, key = 
%s, pts = %llu, stream# = %d, media_object_number = %u.\n", 
                 size, IsKeyFrame () ? "true" : "false", Pts (), StreamId (), 
media_object_number);
        //asf_single_payload_dump (payloads [0]);
        current = first;
@@ -948,7 +949,7 @@
 void
 ASFFrameReader::ReadScriptCommand ()
 {
-       int64_t pts;
+       uint64_t pts;
        char *text;
        char *type;
        gunichar2 *data;

Modified: trunk/moon/src/asf/asf.h
===================================================================
--- trunk/moon/src/asf/asf.h    2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/asf/asf.h    2008-01-24 20:33:40 UTC (rev 93835)
@@ -108,7 +108,7 @@
        int GetPayloadCount (); // Returns the number of payloads in this 
packet.
        asf_single_payload *GetPayload (int index /* 0 based */);
        
-       int64_t GetPts (int stream_id /* 1 - 127 */); // Gets the pts of the 
first payload.
+       uint64_t GetPts (int stream_id /* 1 - 127 */); // Gets the pts of the 
first payload.
        asf_single_payload *GetFirstPayload (int stream_id /* 1 - 127 */); // 
Gets the index first payload of the specified stream.
 };
 
@@ -160,7 +160,7 @@
        ASFParser *parser;
        
        // The first pts that should be returned, any frames with pts below 
this one will be dropped.
-       int64_t first_pts;
+       uint64_t first_pts;
        
        int current_packet_index;
        int script_command_stream_index;
@@ -193,7 +193,7 @@
        bool CanSeek () { return true; }
        
        // Seek to the frame with the provided pts 
-       bool Seek (int stream_id, int64_t pts);
+       bool Seek (int stream_id, uint64_t pts);
        
        // Advance to the next frame
        // Returns false if unsuccessful (if due to no more data, eof is set, 
otherwise some error occurred)
@@ -209,13 +209,13 @@
        // Information about the current frame
        uint64_t Size () { return size; }
        bool IsKeyFrame () { return (payloads_size > 0 && payloads [0] != NULL) 
? payloads [0]->is_key_frame : false; }
-       int64_t Pts () { return (payloads_size > 0 && payloads [0] != NULL) ? 
payloads [0]->get_presentation_time () : 0; }
+       uint64_t Pts () { return (payloads_size > 0 && payloads [0] != NULL) ? 
payloads [0]->get_presentation_time () : 0; }
        int StreamId () { return (payloads_size > 0 && payloads [0] != NULL) ? 
payloads [0]->stream_id : 0; }
        bool Eof () { return eof; } // EOF might be true even if there are more 
packets in the reader (if Advance () fails, and Eof () = true, then advance 
failed because of eof).
        void FindScriptCommandStream ();
        
        // Index 
-       uint32_t FrameSearch (int64_t pts);
+       uint32_t FrameSearch (uint64_t pts);
        // Adds the current frame to the index.
        void AddFrameIndex ();
 };
@@ -283,7 +283,7 @@
        
        // Returns the packet index where the desired pts is found.
        // Returns -1 on failure.
-       int GetPacketIndexOfPts (int stream_id, int64_t pts);
+       int GetPacketIndexOfPts (int stream_id, uint64_t pts);
        
        // The number of packets in the stream (0 if unknown).
        uint64_t GetPacketCount ();
@@ -296,7 +296,7 @@
        asf_object *GetHeaderObject (const asf_guid *guid);
        
        // This callback is called whenever a script command payload is 
encountered while decoding.
-       typedef void embedded_script_command_callback (void *state, char *type, 
char *text, int64_t pts);
+       typedef void embedded_script_command_callback (void *state, char *type, 
char *text, uint64_t pts);
        embedded_script_command_callback *embedded_script_command;
        void *embedded_script_command_state;
        

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/media.cpp    2008-01-24 20:33:40 UTC (rev 93835)
@@ -341,7 +341,7 @@
        }
        
        // Docs says we overwrite whatever's been loaded already.
-       //printf ("MediaElement::ReadMarkers (): setting %i markers.\n", 
collection_count (col));
+       //printf ("MediaElement::ReadMarkers (): setting %d markers.\n", 
collection_count (col));
        SetValue (MarkersProperty, col);
        col->unref ();
 }
@@ -366,7 +366,7 @@
 void
 MediaElement::CheckMarkers (int64_t from, int64_t to, 
TimelineMarkerCollection* col, bool remove)
 {
-       Value* val = NULL;
+       Value *val = NULL;
 
        if (col == NULL)
                return;
@@ -409,30 +409,32 @@
 bool
 MediaElement::AdvanceFrame ()
 {
-       int64_t position;
+       uint64_t position;
        bool advanced;
        
        if (!IsPlaying ())
                return false;
        
        advanced = mplayer->AdvanceFrame ();
-
-       if ((position = mplayer->Position ()) < 0)
-               position = 0;
+       
+       position = mplayer->Position ();
        position *= TIMESPANTICKS_IN_SECOND / 1000;
-
+       
        if (advanced) {
                updating = true;
                //printf ("MediaElement::AdvanceFrame (): advanced, setting 
position to: %lld\n", position);
                media_element_set_position (this, position);
                updating = false;
        }
-
+       
        CheckMarkers (previous_position, position);
-       previous_position = position + 1; // Add 1 to avoid the same position 
to be able to be both beginning and end of a range (otherwise the same marker 
might raise two events).
-
+       
+       // Add 1 to avoid the same position to be able to be both
+       // beginning and end of a range (otherwise the same marker
+       // might raise two events).
+       previous_position = position + 1;
+       
        if (!advanced) {
-               //if (source)
                mplayer->Stop ();
                SetState (Stopped);
                Emit (MediaEndedEvent);
@@ -492,10 +494,10 @@
        if (downloader)
                DownloaderAbort ();
        downloader = NULL;
-
+       
        delete downloaded_file;
        downloaded_file = NULL;
-
+       
        g_free (part_name);
        part_name = NULL;
 /*     
@@ -707,7 +709,7 @@
                // The code assumes that if Buffering then downloaded_file 
isn't NULL
                // (crashes might occur if this took place)
                // So don't allow it to happen.
-               fprintf (stderr, "MediaElement::SetState (%i): Trying to change 
to 'Buffering' but there's no file to save buffered data to.\n", new_state);
+               fprintf (stderr, "MediaElement::SetState (%d): Trying to change 
to 'Buffering' but there's no file to save buffered data to.\n", new_state);
                return;
        }
 
@@ -715,10 +717,10 @@
                previous_state = state;
                const char* state_name = GetStateName (new_state);
                if (state_name == NULL) {
-                       printf ("MediaElement::SetState (%i) state is not 
valid.\n", new_state);
+                       printf ("MediaElement::SetState (%d) state is not 
valid.\n", new_state);
                        return;
                }
-               //printf ("MediaElement::SetState (%i): New state: %s\n", 
new_state, state_name);
+               //printf ("MediaElement::SetState (%d): New state: %s\n", 
new_state, state_name);
                state = new_state;
                media_element_set_current_state (this, state_name);             
        }
@@ -727,7 +729,7 @@
 void 
 MediaElement::DataWrite (void *buf, int32_t offset, int32_t n)
 {
-       //printf ("MediaElement::DataWrite (%p, %i, %i)\n", buf, offset, n);
+       //printf ("MediaElement::DataWrite (%p, %d, %d)\n", buf, offset, n);
 
        if (downloaded_file != NULL) {
                downloaded_file->Write (buf, offset, n);
@@ -755,13 +757,9 @@
 void
 MediaElement::size_notify (int64_t size, gpointer data)
 {
-       // Do something with it?
-       // if size == -1, we do not know the size of the file, can happen
-       // if the server does not return a Content-Length header
-       //printf ("The video size is %lld\n", size);
+       MediaElement *element = (MediaElement *) data;
        
-       MediaElement* element = (MediaElement*) data;
-       if (element != NULL && element->downloaded_file != NULL)
+       if (element->downloaded_file != NULL)
                element->downloaded_file->NotifySize (size);
 }
 
@@ -774,10 +772,9 @@
 void
 MediaElement::BufferingComplete ()
 {
-       //printf ("MediaElement::BufferingComplete (). Current state: %s, 
previous state: %s\n", GetStateName (state), GetStateName (previous_state));
-       
        if (state != Buffering) {
-               printf ("MediaElement::BufferingComplete (): current state is 
invalid ('%s'), should only be 'Buffering'\n", GetStateName (state));
+               printf ("MediaElement::BufferingComplete (): current state is 
invalid ('%s'), should only be 'Buffering'\n",
+                       GetStateName (state));
                return;
        }
        
@@ -801,8 +798,6 @@
 void
 MediaElement::TryOpen ()
 {
-       //printf ("MediaElement::TryOpen (). Current state %s, previous state: 
%s.\n", GetStateName (state), GetStateName (previous_state));
-       
        switch (state) {
        case Closed:
        case Error:
@@ -822,7 +817,7 @@
                // Try to open it now
                break;
        default:
-               printf ("MediaElement::TryOpen (): Unknown state: %i\n", state);
+               printf ("MediaElement::TryOpen (): Unknown state: %d\n", state);
                return;
        }
        
@@ -875,11 +870,13 @@
                Media *media = new Media ();
                
                if (MEDIA_SUCCEEDED (media->Open (downloaded_file))) {
-                       printf ("MediaElement::TryOpen (): download is not 
complete, but media was opened successfully and we'll now start buffering.\n");
+                       printf ("MediaElement::TryOpen (): download is not 
complete, but media was "
+                               "opened successfully and we'll now start 
buffering.\n");
                        MediaOpened (media);
                        SetState (Buffering);
                } else {
-                       downloaded_file->Seek (0, SEEK_SET); // Seek back to 
the beginning of the file
+                       // Seek back to the beginning of the file
+                       downloaded_file->Seek (0, SEEK_SET);
                        delete media;
                }
        }
@@ -890,8 +887,6 @@
 void
 MediaElement::DownloaderComplete ()
 {
-       //printf ("MediaElement::DownloadedComplete (). Current state: %s\n", 
GetStateName (state));
-       
        download_complete = true;
        
        UpdateProgress ();
@@ -899,7 +894,7 @@
        switch (state) {
        case Closed:
        case Error:
-               printf ("MediaElement::DownloaderComplete (): Current state 
(%i) is invalid.\n", state);
+               printf ("MediaElement::DownloaderComplete (): Current state 
(%d) is invalid.\n", state);
                // Should not happen
                return;
        case Playing:
@@ -919,7 +914,7 @@
                TryOpen ();
                break;
        default:
-               printf ("MediaElement::DownloaderComplete (): Unknown state: 
%i\n", state);
+               printf ("MediaElement::DownloaderComplete (): Unknown state: 
%d\n", state);
                return;
        }
        
@@ -928,8 +923,6 @@
 void
 MediaElement::SetSource (DependencyObject *dl, const char *PartName)
 {
-       //printf ("MediaElement<%i>::SetSource (%p, '%s'). Current state: %s, 
URI: %s\n", id, dl, PartName, GetStateName (state), dl->GetValue 
(Downloader::UriProperty)->AsString ());
-       
        g_return_if_fail (dl->GetObjectType () == Type::DOWNLOADER);
                
        Cleanup (true);
@@ -966,8 +959,6 @@
 void
 MediaElement::Pause ()
 {
-       //printf ("MediaElement::Pause (). Current state: %s\n", GetStateName 
(state));
-       
        switch (state) {
        case Opening:// docs: No specified behaviour
                play_pending = false; // This seems to be the actual behaviour
@@ -991,8 +982,6 @@
 void
 MediaElement::Play ()
 {
-       //printf ("MediaElement::Play (). Current state: %s\n", GetStateName 
(state));
-       
        switch (state) {
        case Closed: // docs: No specified behaviour
        case Opening:// docs: No specified behaviour
@@ -1014,8 +1003,6 @@
 void
 MediaElement::Stop ()
 {
-       //printf ("MediaElement::Stop (). Current state: %s\n", GetStateName 
(state));
-       
        switch (state) {
        case Opening:// docs: No specified behaviour
                play_pending = false; // This seems to be the actual behaviour
@@ -1038,7 +1025,7 @@
 MediaElement::GetValue (DependencyProperty *prop)
 {
        if (prop == MediaElement::PositionProperty) {
-               int64_t position = mplayer->Position ();
+               uint64_t position = mplayer->Position ();
                Value v = Value (position * TIMESPANTICKS_IN_SECOND / 1000, 
Type::TIMESPAN);
                
                updating = true;
@@ -1075,7 +1062,7 @@
                }
                // Buffering, Playing: playing
                // Paused, Stopped: paused
-       
+               
                Duration *duration = media_element_get_natural_duration (this);
                TimeSpan position = value->AsTimeSpan ();
                
@@ -1094,9 +1081,8 @@
                        return;
                }
                
-               if (IsStopped ()) {
+               if (IsStopped ())
                        SetState (Paused);
-               }
        }
        
        MediaBase::SetValue (prop, value);
@@ -1171,9 +1157,8 @@
                // read-only property
                recalculate_matrix = true;
        } else if (prop == MediaElement::PositionProperty) {
-               if (IsPlaying() && mplayer->HasVideo ()) {
+               if (IsPlaying() && mplayer->HasVideo ())
                        Invalidate ();
-               }
        } else if (prop == MediaElement::VolumeProperty) {
                mplayer->SetVolume (media_element_get_volume (this));
        }

Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h      2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/media.h      2008-01-24 20:33:40 UTC (rev 93835)
@@ -202,14 +202,26 @@
                Stopped,
                Error
        };
+       
 private:
        State state;
-       State previous_state; // this is used to know what to do after a 
Buffering state finishes
+       
+       // this is used to know what to do after a Buffering state finishes
+       State previous_state;
+       
        bool waiting_for_loaded;
-       bool tried_buffering; // When enough of a file has been downloaded to 
try to open and buffer it, and the open fails, don't try again.
+       
+       // When enough of a file has been downloaded to try to open
+       // and buffer it, and the open fails, don't try again.
+       bool tried_buffering;
+       
        bool download_complete;
-       bool disable_buffering; // If SetSource is called with a Downloader 
that has started, disable buffering (since can't get the start of the file).
-       ProgressiveSource *downloaded_file; // This contains the downloaded 
data.
+       
+       // If SetSource is called with a Downloader that has started,
+       // disable buffering (since can't get the start of the file).
+       bool disable_buffering;
+       
+       ProgressiveSource *downloaded_file;
        Media *media;
 
        bool recalculate_matrix;
@@ -217,9 +229,9 @@
        bool updating;
        bool loaded;
        bool play_pending;
-       int64_t previous_position;
+       uint64_t previous_position;
        
-       TimelineMarkerCollection* streamed_markers;
+       TimelineMarkerCollection *streamed_markers;
        
        virtual void OnLoaded ();
        
@@ -235,6 +247,7 @@
        void DownloaderAbort ();
        void DownloaderComplete ();
        void BufferingComplete ();
+       
        // Try to open the media (i.e. read the headers).
        void TryOpen ();
        // Fill in all information from the opened media and raise 
MediaOpenedEvent. Does not change any state.
@@ -248,9 +261,10 @@
        
        void ReadMarkers ();
        void CheckMarkers (int64_t from, int64_t to);
-       void CheckMarkers (int64_t from, int64_t to, TimelineMarkerCollection* 
col, bool remove);
+       void CheckMarkers (int64_t from, int64_t to, TimelineMarkerCollection 
*col, bool remove);
        
 public:
+       // properties
        static DependencyProperty *AttributesProperty;
        static DependencyProperty *AudioStreamCountProperty;
        static DependencyProperty *AudioStreamIndexProperty;
@@ -269,13 +283,21 @@
        static DependencyProperty *PositionProperty;
        static DependencyProperty *VolumeProperty;
        
-       bool AdvanceFrame ();
-       MediaPlayer *mplayer;
+       // events
+       static int BufferingProgressChangedEvent;
+       static int CurrentStateChangedEvent;
+       static int MarkerReachedEvent;
+       static int MediaEndedEvent;
+       static int MediaFailedEvent;
+       static int MediaOpenedEvent;
        
        MediaElement ();
        virtual ~MediaElement ();
        virtual Type::Kind GetObjectType () { return Type::MEDIAELEMENT; };
        
+       bool AdvanceFrame ();
+       MediaPlayer *mplayer;
+       
        // overrides
        virtual void Render (cairo_t *cr, Region *region);
        virtual void ComputeBounds ();
@@ -299,24 +321,19 @@
        bool IsPlaying () { return state == Playing; }
        bool IsPaused () { return state == Paused; }
        bool IsStopped () { return state == Stopped; }
+       
        void SetState (State new_state);
        State GetState () { return state; }
-       static const char* GetStateName (State state);
        
+       static const char *GetStateName (State state);
+       
        virtual bool EnableAntiAlias ()
        {
                return !(absolute_xform.xx == absolute_xform.yy /* no rotation 
*/
                         && (absolute_xform.yx == 0 && absolute_xform.xy == 0) 
/* no skew */);
        }
        
-       void AddStreamedMarker (TimelineMarker* marker);
-       
-       static int BufferingProgressChangedEvent;
-       static int CurrentStateChangedEvent;
-       static int MarkerReachedEvent;
-       static int MediaEndedEvent;
-       static int MediaFailedEvent;
-       static int MediaOpenedEvent;
+       void AddStreamedMarker (TimelineMarker *marker);
 };
 
 MediaElement *media_element_new (void);

Modified: trunk/moon/src/mplayer.cpp
===================================================================
--- trunk/moon/src/mplayer.cpp  2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/mplayer.cpp  2008-01-24 20:33:40 UTC (rev 93835)
@@ -457,7 +457,7 @@
        MediaFrame *frame = NULL;
        IMediaStream *stream;
        bool update = false;
-       int64_t target_pts;
+       uint64_t target_pts;
        List *list;
        
        if (paused) {
@@ -713,7 +713,7 @@
 void
 MediaPlayer::StopThreads ()
 {
-       int64_t initial_pts = 0;
+       uint64_t initial_pts;
        
        stop = true;
        
@@ -737,8 +737,12 @@
        
        audio->outptr = audio->outbuf;
        
-       if (HasVideo ())
+       if (audio->pcm != NULL && HasAudio ())
+               initial_pts = audio->stream->start_time;
+       else if (HasVideo ())
                initial_pts = video->stream->start_time;
+       else
+               initial_pts = 0;
        
        current_pts = initial_pts;
        target_pts = initial_pts;
@@ -750,7 +754,6 @@
 void
 MediaPlayer::Stop ()
 {
-       //printf ("MediaPlayer::Stop (), paused = %s, opened = %s, playing = 
%s\n", paused ? "true" : "false", opened ? "true" : "false", playing ? "true" : 
"false");
        StopThreads ();
        
        playing = false;
@@ -769,21 +772,14 @@
 }
 
 void
-MediaPlayer::Seek (int64_t position)
+MediaPlayer::Seek (uint64_t position)
 {
-       //printf ("MediaPlayer::Seek (%lld), paused = %s, opened = %s, playing 
= %s\n", position, paused ? "true" : "false", opened ? "true" : "false", 
playing ? "true" : "false");
-       int64_t initial_pts, duration;
+       uint64_t initial_pts, duration;
        bool resume = !paused;
        
        if (!CanSeek ())
                return;
        
-       /*printf ("MediaPlayer::Seek (), audio-duration: %lld, 
audio-initialpts: %lld, video-duration: %lld, video-initial-pts: %lld\n",
-               HasAudio () ? audio->stream->duration : 0,
-               HasAudio () ? audio->initial_pts : 0,
-               HasVideo () ? video->stream->duration : 0,
-               HasVideo () ? video->initial_pts : 0);
-               */
        if (audio->pcm != NULL && HasAudio ()) {
                duration = audio->stream->duration;
                initial_pts = audio->stream->start_time;
@@ -817,7 +813,7 @@
                //TODO: LoadVideoFrame ();
        }
        
-       //printf ("MediaPlayer::Seek (%lld) (playing: %s)\n", position, playing 
? "true" : "false");
+       //printf ("MediaPlayer::Seek (%llu) (playing: %s)\n", position, playing 
? "true" : "false");
        
        if (playing) {
                media_player_enqueue_frames (this, 1, 1);
@@ -842,14 +838,11 @@
        }
 }
 
-int64_t
+uint64_t
 MediaPlayer::Position ()
 {
-       int64_t position = target_pts;
-/*
-       printf ("MediaPlayer::Position (), position: %lld, audio->initialpts: 
%lld, video->initialpts = %lld, seek_pts = %lld, target_pts = %lld, paused = 
%s, opened = %s, playing = %s\n", position,
-               audio->initial_pts, video->initial_pts, seek_pts, target_pts, 
paused ? "true" : "false", opened ? "true" : "false", playing ? "true" : 
"false");
-       */      
+       uint64_t position = target_pts;
+       
        if (audio->pcm != NULL && HasAudio ())
                return position - audio->stream->start_time;
        
@@ -859,12 +852,9 @@
        return position;
 }
 
-int64_t
+uint64_t
 MediaPlayer::Duration ()
 {
-       //printf ("MediaPlayer::Duration (), audio->stream->duration: %lld, 
video->stream->duration: %lld\n", HasAudio () ? audio->stream->duration : -1,
-       //              HasVideo () ? video->stream->duration : -1);
-       
        if (audio->pcm != NULL && HasAudio ())
                return audio->stream->duration;
        

Modified: trunk/moon/src/mplayer.h
===================================================================
--- trunk/moon/src/mplayer.h    2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/mplayer.h    2008-01-24 20:33:40 UTC (rev 93835)
@@ -27,9 +27,10 @@
        Media *media;
        // The pts when we start playing (set when resuming playback to current 
pts, when starting to play to initial pts, and when seeking to the seeked pts)
        // While playing it can be used to calculate the current pts (knowing 
the time)
-       guint64 start_pts;
-       guint64 initial_pts;
-       gint64 duration;
+       uint64_t start_pts;
+       uint64_t initial_pts;
+       uint64_t duration;
+       
        pthread_mutex_t pause_mutex;
        pthread_cond_t pause_cond;
        bool paused;
@@ -37,6 +38,7 @@
        bool playing;
        bool stop;
        bool eof;
+       
        GThread *audio_thread;
        Audio *audio;
        Video *video;
@@ -46,8 +48,9 @@
        uint64_t start_time;  
        
        pthread_mutex_t target_pts_lock;
-       int64_t current_pts;
-       int64_t target_pts;
+       uint64_t current_pts;
+       uint64_t target_pts;
+       
        /* Public API */
        
        // read-only
@@ -74,9 +77,9 @@
        void Stop ();
        
        bool CanSeek ();
-       void Seek (int64_t position);
-       int64_t Position ();
-       int64_t Duration ();
+       void Seek (uint64_t position);
+       uint64_t Position ();
+       uint64_t Duration ();
        
        void Mute ();
        void UnMute ();

Modified: trunk/moon/src/pipeline.cpp
===================================================================
--- trunk/moon/src/pipeline.cpp 2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/pipeline.cpp 2008-01-24 20:33:40 UTC (rev 93835)
@@ -194,7 +194,7 @@
 }
 
 MediaResult
-Media::Seek (int64_t pts)
+Media::Seek (uint64_t pts)
 {
        if (demuxer)
                return demuxer->Seek (pts);
@@ -203,7 +203,7 @@
 }
 
 MediaResult
-Media::SeekAsync (int64_t pts)
+Media::SeekAsync (uint64_t pts)
 {
        if (demuxer == NULL)
                return MEDIA_FAIL;
@@ -537,6 +537,8 @@
 void
 Media::GetNextFrameAsync (MediaFrame *frame, uint16_t states)
 {
+       MoonWorkType type;
+       
        if (frame == NULL) {
                AddMessage (MEDIA_INVALID_ARGUMENT, "frame is NULL.");
                return;
@@ -547,12 +549,18 @@
                return;
        }
        
-       MoonWorkType type;
        switch (frame->stream->GetType ()) {
-       case MediaTypeAudio: type = WorkTypeAudio; break;
-       case MediaTypeVideo: type = WorkTypeVideo; break;
-       case MediaTypeMarker: type = WorkTypeMarker; break;
+       case MediaTypeAudio:
+               type = WorkTypeAudio;
+               break;
+       case MediaTypeVideo:
+               type = WorkTypeVideo;
+               break;
+       case MediaTypeMarker:
+               type = WorkTypeMarker;
+               break;
        case MediaTypeNone:
+       default:
                AddMessage (MEDIA_INVALID_ARGUMENT, "The frame's stream is of 
an unknown type.");
                return;
        }
@@ -689,7 +697,7 @@
 }
 
 MediaResult
-ASFDemuxer::Seek (int64_t pts)
+ASFDemuxer::Seek (uint64_t pts)
 {
        if (reader == NULL)
                reader = new ASFFrameReader (parser);
@@ -705,6 +713,7 @@
                        break;
                }
        }
+       
        if (reader->Seek (stream_id, pts))
                return MEDIA_SUCCESS;
        
@@ -730,7 +739,7 @@
        List *markers = media->GetMarkers ();
        //guint64 preroll = parser->file_properties->preroll;
        const char *type;
-       int64_t pts;
+       uint64_t pts;
        char *text;
        int i = -1;
        
@@ -1298,7 +1307,7 @@
 }
 
 void
-Mp3FrameReader::AddFrameIndex (int64_t offset, int64_t pts, uint32_t dur, 
int32_t bit_rate)
+Mp3FrameReader::AddFrameIndex (int64_t offset, uint64_t pts, uint32_t dur, 
int32_t bit_rate)
 {
        if (used == avail) {
                avail += MPEG_JUMP_TABLE_GROW_SIZE;
@@ -1331,9 +1340,9 @@
 #define MID(lo, hi) (lo + ((hi - lo) >> 1))
 
 uint32_t
-Mp3FrameReader::MpegFrameSearch (int64_t pts)
+Mp3FrameReader::MpegFrameSearch (uint64_t pts)
 {
-       int64_t start, end;
+       uint64_t start, end;
        uint32_t hi = used - 1;
        uint32_t m = hi >> 1;
        uint32_t lo = 0;
@@ -1362,11 +1371,11 @@
 }
 
 bool
-Mp3FrameReader::Seek (int64_t pts)
+Mp3FrameReader::Seek (uint64_t pts)
 {
        int64_t offset = stream->GetPosition ();
        int32_t bit_rate = this->bit_rate;
-       int64_t cur_pts = this->cur_pts;
+       uint64_t cur_pts = this->cur_pts;
        uint32_t frame;
        
        if (pts == cur_pts)
@@ -1562,7 +1571,7 @@
 }
 
 MediaResult
-Mp3Demuxer::Seek (int64_t pts)
+Mp3Demuxer::Seek (uint64_t pts)
 {
        if (reader && reader->Seek (pts))
                return MEDIA_SUCCESS;
@@ -2490,7 +2499,7 @@
  * MediaMarker
  */ 
 
-MediaMarker::MediaMarker (const char *type, const char *text, int64_t pts)
+MediaMarker::MediaMarker (const char *type, const char *text, uint64_t pts)
 {
        this->type = g_strdup (type);
        this->text = g_strdup (text);

Modified: trunk/moon/src/pipeline.h
===================================================================
--- trunk/moon/src/pipeline.h   2008-01-24 20:12:46 UTC (rev 93834)
+++ trunk/moon/src/pipeline.h   2008-01-24 20:33:40 UTC (rev 93835)
@@ -221,7 +221,7 @@
 public:
        MoonWorkType type;
        union {
-               int64_t seek_pts;
+               uint64_t seek_pts;
                struct {
                        MediaFrame *frame;
                        uint16_t states;
@@ -289,8 +289,8 @@
        MediaResult Open (IMediaSource *source); // Called if you have your own 
source
        
        // Seeks to the specified pts (if seekable).
-       MediaResult Seek (int64_t pts);
-       MediaResult SeekAsync (int64_t pts);
+       MediaResult Seek (uint64_t pts);
+       MediaResult SeekAsync (uint64_t pts);
        
        //      Reads the next frame from the demuxer
        //      Requests the decoder to decode the frame
@@ -350,7 +350,7 @@
        
        IMediaStream *stream;
        void *decoder_specific_data; // data specific to the decoder
-       int64_t pts; // Set by the demuxer
+       uint64_t pts; // Set by the demuxer
        uint64_t duration; // Set by the demuxer
        
        uint16_t state; // Current state of the frame
@@ -369,7 +369,7 @@
 };
 
 class MediaMarker {
-       int64_t pts;
+       uint64_t pts;
        char *type;
        char *text;
        
@@ -381,12 +381,12 @@
                MediaMarker *marker;
        };
        
-       MediaMarker (const char *type, const char *text, int64_t pts);
+       MediaMarker (const char *type, const char *text, uint64_t pts);
        ~MediaMarker ();
        
        const char *Type () { return type; }
        const char *Text () { return text; }
-       int64_t Pts () { return pts; }
+       uint64_t Pts () { return pts; }
 };
 
 // Interfaces
@@ -462,7 +462,7 @@
        virtual MediaResult ReadHeader () = 0;
        // Fills the uncompressed_data field in the frame with data.
        virtual MediaResult ReadFrame (MediaFrame *frame) = 0;
-       virtual MediaResult Seek (int64_t pts) = 0;
+       virtual MediaResult Seek (uint64_t pts) = 0;
        int GetStreamCount () { return stream_count; }
        IMediaStream *GetStream (int index)
        {
@@ -635,7 +635,7 @@
        IImageConverter *converter; // This stream has the ownership of the 
converter, it will be deleted upon destruction.
        uint32_t bits_per_sample;
        uint32_t msec_per_frame;
-       int64_t initial_pts;
+       uint64_t initial_pts;
        uint32_t height;
        uint32_t width;
        
@@ -674,7 +674,7 @@
        
        virtual MediaResult ReadHeader ();
        virtual MediaResult ReadFrame (MediaFrame *frame);
-       virtual MediaResult Seek (int64_t pts);
+       virtual MediaResult Seek (uint64_t pts);
        
        ASFParser *GetParser () { return parser; }
 };
@@ -712,8 +712,8 @@
 
 struct MpegFrame {
        int64_t offset;
+       uint64_t pts;
        uint32_t dur;
-       int64_t pts;
        
        // this is needed in case this frame did not specify it's own
        // bit rate which is possible for MPEG-1 Layer 3 audio.
@@ -723,15 +723,15 @@
 class Mp3FrameReader {
        IMediaSource *stream;
        int64_t stream_start;
+       uint64_t cur_pts;
        int32_t bit_rate;
-       int64_t cur_pts;
        
        MpegFrame *jmptab;
        uint32_t avail;
        uint32_t used;
        
-       uint32_t MpegFrameSearch (int64_t pts);
-       void AddFrameIndex (int64_t offset, int64_t pts, uint32_t dur, int32_t 
bit_rate);
+       uint32_t MpegFrameSearch (uint64_t pts);
+       void AddFrameIndex (int64_t offset, uint64_t pts, uint32_t dur, int32_t 
bit_rate);
        
        bool SkipFrame ();
        
@@ -739,7 +739,7 @@
        Mp3FrameReader (IMediaSource *source, int64_t start);
        ~Mp3FrameReader ();
        
-       bool Seek (int64_t pts);
+       bool Seek (uint64_t pts);
        
        MediaResult ReadFrame (MediaFrame *frame);
 };
@@ -753,7 +753,7 @@
        
        virtual MediaResult ReadHeader ();
        virtual MediaResult ReadFrame (MediaFrame *frame);
-       virtual MediaResult Seek (int64_t pts);
+       virtual MediaResult Seek (uint64_t pts);
 };
 
 class Mp3DemuxerInfo : public DemuxerInfo {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to