Author: fejj
Date: 2008-01-23 15:27:18 -0500 (Wed, 23 Jan 2008)
New Revision: 93708

Modified:
   trunk/moon/src/asf/ChangeLog
   trunk/moon/src/asf/asf-ffmpeg.cpp
   trunk/moon/src/asf/asf-ffmpeg.h
   trunk/moon/src/asf/asf-generated.cpp
   trunk/moon/src/asf/asf-structures.cpp
   trunk/moon/src/asf/asf-structures.h
   trunk/moon/src/asf/asf.cpp
   trunk/moon/src/asf/asf.h
Log:
2008-01-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * asf-structures.cpp|h: Fixed lots of integer-type
        usage (e.g. don't use a size_t when it should be an int64_t, etc).

        * asf-ffmpeg.cpp|h: Same.

        * asf.cpp|h: Here too.



Modified: trunk/moon/src/asf/ChangeLog
===================================================================
--- trunk/moon/src/asf/ChangeLog        2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/ChangeLog        2008-01-23 20:27:18 UTC (rev 93708)
@@ -1,3 +1,12 @@
+2008-01-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
+       * asf-structures.cpp|h: Fixed lots of integer-type
+       usage (e.g. don't use a size_t when it should be an int64_t, etc).
+
+       * asf-ffmpeg.cpp|h: Same.
+
+       * asf.cpp|h: Here too.
+
 2008-01-14  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
 
        * asf.cpp, asf.h, asf-ffmpeg.h, asf-structures.cpp: Fix warnings.

Modified: trunk/moon/src/asf/asf-ffmpeg.cpp
===================================================================
--- trunk/moon/src/asf/asf-ffmpeg.cpp   2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/asf-ffmpeg.cpp   2008-01-23 20:27:18 UTC (rev 93708)
@@ -116,8 +116,8 @@
                av_set_pts_info(stream, 32, 1, 1000);
                stream->priv_data = parser;
                stream->codec->codec_type = codec_type;
-               stream->id = asp->get_stream_number ();
-               parser->AddStreamIndex (s->nb_streams - 1, 
asp->get_stream_number ());
+               stream->id = asp->get_stream_id ();
+               parser->AddStreamIndex (s->nb_streams - 1, asp->get_stream_id 
());
                stream->start_time = file_properties->preroll;
                
                if (!file_properties->is_broadcast ()) {
@@ -233,15 +233,15 @@
        do {    
                if (!reader->Advance ())
                        return -1;
-       } while (parser->ConvertStreamIndex (reader->StreamNumber ()) < 0);
+       } while (parser->ConvertStreamIndex (reader->StreamId ()) < 0);
        
        AVPacket* pkt = new AVPacket ();
        
        av_new_packet (pkt, reader->Size ());
-               
+       
        pkt->pts = reader->Pts ();
        pkt->dts = pkt->pts;
-       pkt->stream_index = parser->ConvertStreamIndex (reader->StreamNumber 
()); 
+       pkt->stream_index = parser->ConvertStreamIndex (reader->StreamId ()); 
        pkt->pos = parser->source->Position ();
        pkt->size = reader->Size ();
        reader->Write (pkt->data);

Modified: trunk/moon/src/asf/asf-ffmpeg.h
===================================================================
--- trunk/moon/src/asf/asf-ffmpeg.h     2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/asf-ffmpeg.h     2008-01-23 20:27:18 UTC (rev 93708)
@@ -133,27 +133,22 @@
                this->buffer = buffer;
        }
        
-       virtual ~FFMPEGSource ()
-       {
-               buffer = NULL;
-       }
+       virtual ~FFMPEGSource () { };
        
        ByteIOContext* GetBuffer ()
        {
                return buffer;
        }
        
-       virtual bool ReadInternal (void* destination, size_t bytes)
+       virtual bool ReadInternal (void* destination, uint32_t bytes)
        {
                int result;
                result = get_buffer (buffer, (unsigned char*) destination, 
(int) bytes);
                return result != 0; // Is this correct
        }
        
-       virtual bool SeekInternal (size_t offset, int mode)
+       virtual bool SeekInternal (int64_t offset, int mode)
        {
-               //printf ("FFMPEGSource::Seek (%i, %i).\n", offset, mode);
-               
                int64_t result = url_fseek (buffer, offset, mode);
                
                return result; // Is this correct?
@@ -162,7 +157,7 @@
        virtual bool Eof () { return url_feof (buffer); }
        virtual bool CanSeek () { return true; }
        
-       virtual guint64 Position () 
+       virtual int64_t Position () 
        {
                return buffer ? (buffer->pos - (buffer->buf_end - 
buffer->buf_ptr)) : 0;
        }

Modified: trunk/moon/src/asf/asf-generated.cpp
===================================================================
--- trunk/moon/src/asf/asf-generated.cpp        2008-01-23 20:18:02 UTC (rev 
93707)
+++ trunk/moon/src/asf/asf-generated.cpp        2008-01-23 20:27:18 UTC (rev 
93708)
@@ -123,7 +123,7 @@
        ASF_DUMP ("\tid = %s\n", asf_guid_tostring (&obj->id));
        ASF_DUMP ("\tsize = %llu\n", obj->size);
        ASF_DUMP ("\texclusion_type = %s\n", asf_guid_tostring 
(&obj->exclusion_type));
-       ASF_DUMP ("\tstream_number_count = %u\n", (asf_dword) 
obj->stream_number_count);
+       ASF_DUMP ("\tstream_count = %u\n", (asf_dword) obj->stream_count);
 }
 
 void asf_error_correction_dump (const asf_error_correction* obj)
@@ -188,7 +188,7 @@
        ASF_DUMP ("\talternate_initial_buffer_fullness = %u\n", (asf_dword) 
obj->alternate_initial_buffer_fullness);
        ASF_DUMP ("\tmaximum_object_size = %u\n", (asf_dword) 
obj->maximum_object_size);
        ASF_DUMP ("\tflags = %u\n", (asf_dword) obj->flags);
-       ASF_DUMP ("\tstream_number = %u\n", (asf_dword) obj->stream_number);
+       ASF_DUMP ("\tstream_id = %u\n", (asf_dword) obj->stream_id);
        ASF_DUMP ("\tstream_language_id_index = %u\n", (asf_dword) 
obj->stream_language_id_index);
        ASF_DUMP ("\taverage_time_per_frame = %llu\n", 
obj->average_time_per_frame);
        ASF_DUMP ("\tstream_name_count = %u\n", (asf_dword) 
obj->stream_name_count);

Modified: trunk/moon/src/asf/asf-structures.cpp
===================================================================
--- trunk/moon/src/asf/asf-structures.cpp       2008-01-23 20:18:02 UTC (rev 
93707)
+++ trunk/moon/src/asf/asf-structures.cpp       2008-01-23 20:27:18 UTC (rev 
93708)
@@ -352,14 +352,14 @@
 {      
        ASFSource* source = parser->source;
        
-       if (!source->Read (&stream_number, 1))
+       if (!source->Read (&stream_id, 1))
                return false;
        
-       is_key_frame = stream_number & 0x80;
-       stream_number = stream_number & 0x7F;
+       is_key_frame = stream_id & 0x80;
+       stream_id = stream_id & 0x7F;
        
-       if (!source->parser->IsValidStream (stream_number)) {
-               ASF_LOG ("asf_single_payload::FillInAll: Invalid stream number 
(%i).\n", (asf_dword) stream_number);
+       if (!source->parser->IsValidStream (stream_id)) {
+               ASF_LOG ("asf_single_payload::FillInAll: Invalid stream number 
(%d).\n", (int) stream_id);
                return false;
        }
        
@@ -536,7 +536,7 @@
 }
 
 bool
-asf_multiple_payloads::ReadCompressedPayload (ASFParser* parser, 
asf_single_payload* first, gint32 count, gint32 start_index)
+asf_multiple_payloads::ReadCompressedPayload (ASFParser* parser, 
asf_single_payload* first, int count, int start_index)
 {
        asf_byte* data = first->payload_data;
        asf_byte size = 0;
@@ -550,7 +550,7 @@
                payload = new asf_single_payload ();
                payloads [start_index + i] = payload;
                
-               payload->stream_number = first->stream_number;
+               payload->stream_id = first->stream_id;
                payload->is_key_frame = first->is_key_frame;
                payload->media_object_number = first->media_object_number + i;
                payload->offset_into_media_object = 0;

Modified: trunk/moon/src/asf/asf-structures.h
===================================================================
--- trunk/moon/src/asf/asf-structures.h 2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/asf-structures.h 2008-01-23 20:27:18 UTC (rev 93708)
@@ -191,7 +191,7 @@
 
 // struct with variable length fields (all but the first field)
 struct asf_single_payload {
-       asf_byte stream_number;
+       asf_byte stream_id;
        bool is_key_frame;
        asf_dword media_object_number;
        asf_dword offset_into_media_object;
@@ -223,7 +223,7 @@
        
        asf_single_payload () 
        {
-               stream_number = 0; media_object_number = 0; 
offset_into_media_object = 0;
+               stream_id = 0; media_object_number = 0; 
offset_into_media_object = 0;
                replicated_data_length = 0; replicated_data = 0; 
payload_data_length = 0;
                payload_data = 0; presentation_time = 0;
        }
@@ -236,26 +236,24 @@
        asf_byte payload_flags;
        
        asf_single_payload** payloads;
-       gint32 payloads_size;
+       int payloads_size;
        
        int get_number_of_payloads () { return payloads_size; }
        int get_payload_length_type () { return (payload_flags & 0xC0) >> 6; }
        
-       bool ResizeList (ASFParser* parser, gint32 requested_size);
+       bool ResizeList (ASFParser* parser, int requested_size);
        bool FillInAll (ASFParser* parser, asf_error_correction_data* ecd, 
asf_payload_parsing_information ppi);
-       bool ReadCompressedPayload (ASFParser* parser, asf_single_payload* 
first, gint32 count, gint32 start_index);
-       gint32 CountCompressedPayloads (ASFParser* parser, asf_single_payload* 
first); // Returns 0 on failure, values > 0 on success.
+       bool ReadCompressedPayload (ASFParser* parser, asf_single_payload* 
first, int count, int start_index);
+       int CountCompressedPayloads (ASFParser* parser, asf_single_payload* 
first); // Returns 0 on failure, values > 0 on success.
        
        asf_multiple_payloads () { payload_flags = 0; payloads = NULL; 
payloads_size = 0;}
        
        ~asf_multiple_payloads () 
        {
                if (payloads) {
-                       int i = -1;
-                       while (payloads [++i] != NULL)
-                               delete payloads [i];
+                       for (int i = 0; payloads[i]; i++)
+                               delete payloads[i];
                        g_free (payloads);
-                       payloads = NULL;
                }
        }
        
@@ -265,32 +263,32 @@
                        return 0;
                        
                asf_byte result = 0;
-               int index = 0;
-               while (index < get_number_of_payloads () && payloads [index] != 
NULL) {
-                       int current = payloads [index]->stream_number;
+               
+               for (int i = 0; i < get_number_of_payloads () && payloads[i]; 
i++) {
+                       asf_byte current = payloads[i]->stream_id;
                        result = current > result ? current : result;
-                       index++;
                }
+               
                return result;
        }
        
-       asf_dword get_stream_size (asf_byte stream_number)
+       asf_dword get_stream_size (asf_byte stream_id)
        {
                if (!payloads)
                        return 0;
-
+               
                asf_dword result = 0;
                int index = 0;
                while (index < get_number_of_payloads () && payloads [index] != 
NULL) {
-                       if (payloads [index]->stream_number == stream_number) {
+                       if (payloads [index]->stream_id == stream_id)
                                result += payloads [index]->payload_data_length;
-                       }
+                       
                        index++;
                }
                return result;
        }
        
-       bool write_payload_data (asf_byte stream_number, unsigned char* 
destination, size_t max_size)
+       bool write_payload_data (asf_byte stream_id, unsigned char 
*destination, size_t max_size)
        {
                if (!payloads)
                        return false;
@@ -300,7 +298,7 @@
                size_t size = 0;
                int index = 0;
                while (index < get_number_of_payloads () && payloads [index] != 
NULL) {
-                       if (payloads [index]->stream_number == stream_number) {
+                       if (payloads[index]->stream_id == stream_id) {
                                size = payloads [index]->payload_data_length;
                                g_assert ((size_t) (destination - 
initial_destination) + size  <= max_size);
                                memcpy (destination, payloads 
[index]->payload_data, size);
@@ -311,33 +309,35 @@
                return true;
        }
        
-       asf_dword get_presentation_time (asf_byte stream_number)
+       asf_dword get_presentation_time (asf_byte stream_id)
        {
                if (!payloads)
                        return 0;
-                       
+               
                int index = 0;
                while (index < get_number_of_payloads () && payloads [index] != 
NULL) {
-                       if (payloads [index]->stream_number == stream_number) {
+                       if (payloads[index]->stream_id == stream_id)
                                return payloads [index]->get_presentation_time 
();
-                       }
+                       
                        index++;
                }
                
                return 0;
        }
                
-       bool is_key_frame (asf_dword stream_index)
+       bool is_key_frame (asf_dword stream_id)
        {
                if (payloads == NULL)
                        return false;
-                       
+               
                int index = 0;
                while (payloads [index] != NULL) {
-                       if (payloads [index]->stream_number == stream_index)
+                       if (payloads[index]->stream_id == stream_id)
                                return payloads [index]->is_key_frame;
+                       
                        index++;
                }
+               
                return false;
        }
        
@@ -421,7 +421,7 @@
                return asf_guid_compare (&stream_type, 
&asf_guids_media_command);
        }
 
-       asf_dword get_stream_number () 
+       asf_dword get_stream_id () 
        {
                return flags & 0x7F;
        }
@@ -588,7 +588,7 @@
 
 struct asf_bitrate_mutual_exclusion : public asf_object {
        asf_guid exclusion_type;
-       asf_word stream_number_count;
+       asf_word stream_count;
        
        // data follows
 };
@@ -633,7 +633,7 @@
        asf_dword alternate_initial_buffer_fullness;
        asf_dword maximum_object_size;
        asf_dword flags;
-       asf_word stream_number;
+       asf_word stream_id;
        asf_word stream_language_id_index;
        asf_qword average_time_per_frame;
        asf_word stream_name_count;

Modified: trunk/moon/src/asf/asf.cpp
===================================================================
--- trunk/moon/src/asf/asf.cpp  2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/asf.cpp  2008-01-23 20:27:18 UTC (rev 93708)
@@ -16,24 +16,24 @@
  * ASFMediaSource
  */
 
-ASFMediaSource::ASFMediaSource (ASFParser* parser, IMediaSource* source) : 
ASFSource (parser)
+ASFMediaSource::ASFMediaSource (ASFParser *parser, IMediaSource *source) : 
ASFSource (parser)
 {
        this->source = source;
 }
 
 bool 
-ASFMediaSource::ReadInternal (void* destination, size_t bytes)
+ASFMediaSource::ReadInternal (void *buf, uint32_t n)
 {
-       return source->ReadAll (destination, bytes);
+       return source->ReadAll (buf, n);
 }
 
 bool 
-ASFMediaSource::SeekInternal (size_t offset, int mode)
+ASFMediaSource::SeekInternal (int64_t offset, int mode)
 {
        return source->Seek (offset, mode);
 }
 
-guint64 
+int64_t
 ASFMediaSource::Position ()
 {
        return source->GetPosition ();
@@ -50,26 +50,26 @@
 {
        return source->Eof ();
 }
-       
+
 /*
        ASFParser
 */
 
-ASFParser::ASFParser (const char* filename)
+ASFParser::ASFParser (const char *filename)
 {
        ASF_LOG ("ASFParser::ASFParser ('%s'), this: %p.\n", filename, this);
        source = new ASFFileSource (this, filename);
        Initialize ();
 }
 
-ASFParser::ASFParser (ASFSource* src)
+ASFParser::ASFParser (ASFSource *src)
 {
        ASF_LOG ("ASFParser::ASFParser ('%p'), this: %p.\n", src, this);
        source = src;
        Initialize ();
 }
 
-guint64
+uint64_t
 ASFParser::GetPacketCount ()
 {
        return file_properties->data_packet_count;
@@ -91,7 +91,7 @@
        errors = NULL;
        embedded_script_command = NULL;
        embedded_script_command_state = NULL;
-       memset (stream_properties, 0, sizeof (asf_stream_properties*) * 127);
+       memset (stream_properties, 0, sizeof (asf_stream_properties *) * 127);
 }
 
 ASFParser::~ASFParser ()
@@ -99,93 +99,86 @@
        ASF_LOG ("ASFParser::~ASFParser ().\n");
        
        delete source;
-       source = NULL;
                
        if (errors) {
-               error* current = errors;
-               error* next = NULL;
-               while (current != NULL) {
-                       next = current->next;
-                       g_free (current->msg);
-                       g_free (current);
-                       current = next;
+               error *next;
+               
+               while (errors != NULL) {
+                       next = errors->next;
+                       g_free (errors->msg);
+                       g_free (errors);
+                       errors = next;
                }
-               errors = NULL;
        }
        
        g_free (header);
-       header = NULL;
-       
        g_free (data);
-       data = NULL;
        
        if (header_objects) {
-               int i = -1;
-               while (header_objects [++i] != NULL)
-                       g_free (header_objects [i]);
-                       
+               for (int i = 0; header_objects[i]; i++)
+                       g_free (header_objects[i]);
+               
                g_free (header_objects);
-               header_objects = NULL;
        }
 }
 
 bool
-ASFParser::VerifyHeaderDataSize (guint64 size)
+ASFParser::VerifyHeaderDataSize (uint32_t size)
 {
        if (header == NULL)
                return false;
-               
+       
        return size >= 0 && size < header->size;
 }
 
-void* 
-ASFParser::Malloc (gint32 size)
+void *
+ASFParser::MallocVerified (uint32_t size)
 {
-       if (!VerifyHeaderDataSize (size))
-               return NULL;
-               
-       return MallocVerified (size);
-}
-
-void*
-ASFParser::MallocVerified (gint32 size)
-{
-       void* result = g_try_malloc0 (size);
+       void *result = g_try_malloc0 (size);
        
-       if (result == NULL) {
+       if (result == NULL)
                AddError ("Out of memory.");
-       }
        
        return result;
 }
 
-asf_object*
-ASFParser::ReadObject (asf_object* obj)
+void *
+ASFParser::Malloc (uint32_t size)
 {
-       ASF_LOG ("ASFParser::ReadObject ('%s', %llu)\n", asf_guid_tostring 
(&obj->id), obj->size);
+       if (!VerifyHeaderDataSize (size))
+               return NULL;
+       
+       return MallocVerified (size);
+}
 
-       asf_object* result = NULL;
+asf_object *
+ASFParser::ReadObject (asf_object *obj)
+{
        ASFTypes type = asf_get_guid_type (&obj->id);
+       asf_object *result = NULL;
+       char *guid;
        
+       ASF_LOG ("ASFParser::ReadObject ('%s', %llu)\n", asf_guid_tostring 
(&obj->id), obj->size);
+       
        if (type == ASF_NONE) {
-               char* g = asf_guid_tostring (&obj->id);
-               AddError (g_strdup_printf ("Unrecognized guid: %s.", g));
-               g_free (g);
+               guid = asf_guid_tostring (&obj->id);
+               AddError (g_strdup_printf ("Unrecognized guid: %s.", guid));
+               g_free (guid);
                return NULL;
        }
        
-       result = (asf_object*) Malloc (obj->size);
+       result = (asf_object *) Malloc (obj->size);
        if (result == NULL) {
-               char* g = asf_guid_tostring (&obj->id);
-               AddError (g_strdup_printf ("Header corrupted (id: %s)", g));
-               g_free (g);
+               guid = asf_guid_tostring (&obj->id);
+               AddError (g_strdup_printf ("Header corrupted (id: %s)", guid));
+               g_free (guid);
                return false;
        }
-
+       
        memcpy (result, obj, sizeof (asf_object));
-
+       
        if (obj->size > sizeof (asf_object)) {
-               if (!source->Read (((char*) result) + sizeof (asf_object), 
obj->size - sizeof (asf_object))) {
+               if (!source->Read (((char *) result) + sizeof (asf_object), 
obj->size - sizeof (asf_object))) {
                        g_free (result);
                        return NULL;
                }
@@ -195,18 +188,18 @@
                g_free (result);
                return NULL;
        }
-
+       
        return result;
 }
 
 bool
-ASFParser::ReadPacket (ASFPacket* packet, gint32 packet_index)
+ASFParser::ReadPacket (ASFPacket *packet, int packet_index)
 {
-       ASF_LOG ("ASFParser::ReadPacket (%p, %i).\n", packet, packet_index);
+       ASF_LOG ("ASFParser::ReadPacket (%p, %d).\n", packet, packet_index);
        
        if (packet_index >= 0) {
-               guint64 position = GetPacketOffset (packet_index);
-
+               int64_t position = GetPacketOffset (packet_index);
+               
                if (position == 0 || (source->Position () != position && 
!source->Seek (position, SEEK_SET)))
                        return false;
        }
@@ -215,13 +208,15 @@
 }
 
 bool
-ASFParser::ReadPacket (ASFPacket* packet)
+ASFParser::ReadPacket (ASFPacket *packet)
 {
-       ASF_LOG ("ASFParser::ReadPacket (%p): Reading packet at %lld (index: 
%i) of %lld packets.\n", packet, source->Position (), GetPacketIndex 
(source->Position ()), data->data_packet_count);
-       
-       asf_error_correction_data ecd;
        asf_payload_parsing_information ppi;
+       asf_error_correction_data ecd;
        
+       ASF_LOG ("ASFParser::ReadPacket (%p): Reading packet at %lld (index: 
%d) of %lld packets.\n",
+                packet, source->Position (), GetPacketIndex (source->Position 
()),
+                data->data_packet_count);
+       
        if (!ecd.FillInAll (this))
                return false;
        
@@ -232,7 +227,7 @@
        
        asf_payload_parsing_information_dump (&ppi);
        
-       asf_multiple_payloads* mp = new asf_multiple_payloads ();
+       asf_multiple_payloads *mp = new asf_multiple_payloads ();
        if (!mp->FillInAll (this, &ecd, ppi)) {
                delete mp;
                return false;
@@ -258,13 +253,13 @@
                return false;
        }
        
-       if (!source->Seek (header->size, SEEK_SET)) {
+       if (!source->Seek ((int64_t) header->size, SEEK_SET)) {
                return false;
        }
        
        ASF_LOG ("Current position: %llx (%lld)\n", source->Position (), 
source->Position ());
        
-       data = (asf_data*) Malloc (sizeof (asf_data));
+       data = (asf_data *) Malloc (sizeof (asf_data));
        if (data == NULL) {
                AddError ("Data corruption in data.");
                return false;
@@ -290,7 +285,7 @@
 {
        ASF_LOG ("ASFParser::ReadHeader ().\n");
        
-       header = (asf_header*) MallocVerified (sizeof (asf_header));
+       header = (asf_header *) MallocVerified (sizeof (asf_header));
        if (header == NULL) {
                ASF_LOG ("ASFParser::ReadHeader (): Malloc failed.\n");
                return false;
@@ -300,7 +295,7 @@
                ASF_LOG ("ASFParser::ReadHeader (): source->Read () failed.\n");
                return false;
        }
-               
+       
        asf_header_dump (header);
 
        if (!asf_header_validate (header, this)) {
@@ -308,7 +303,7 @@
                return false;
        }
        
-       header_objects = (asf_object**) Malloc ((header->object_count + 1) * 
sizeof (asf_object*));
+       header_objects = (asf_object **) Malloc ((header->object_count + 1) * 
sizeof (asf_object*));
        if (header_objects == NULL) {
                AddError ("Data corruption in header.");
                return false;
@@ -317,17 +312,18 @@
        ASF_LOG ("ASFParser::ReadHeader (): about to read streams...\n");
        
        bool any_streams = false;
-       for (guint32 i = 0; i < header->object_count; i++) {
+       for (uint32_t i = 0; i < header->object_count; i++) {
                asf_object tmp;
+               
                if (!source->Read (&tmp, sizeof (asf_object)))
                        return false;
                
                if (!(header_objects [i] = ReadObject (&tmp)))
                        return false;
                
-               if (asf_guid_compare (&asf_guids_stream_properties, 
&header_objects [i]->id)) {
-                       asf_stream_properties* stream = 
(asf_stream_properties*) header_objects [i];
-                       SetStream (stream->get_stream_number (), stream);
+               if (asf_guid_compare (&asf_guids_stream_properties, 
&header_objects[i]->id)) {
+                       asf_stream_properties *stream = (asf_stream_properties 
*) header_objects[i];
+                       SetStream (stream->get_stream_id (), stream);
                        any_streams = true;
                }
                
@@ -397,12 +393,14 @@
        return true;
 }
 
-const char*
+const char *
 ASFParser::GetLastError ()
 {
-       error* last = errors;
+       error *last = errors;
+       
        while (last != NULL && last->next != NULL)
                last = last->next;
+       
        if (last != NULL) {
                return last->msg;
        } else {
@@ -411,17 +409,23 @@
 }
 
 void
-ASFParser::AddError (const char* msg)
-{      
+ASFParser::AddError (const char *msg)
+{
+       AddError (g_strdup (msg));
+}
+
+void
+ASFParser::AddError (char *msg)
+{
        ASF_LOG ("ASFParser::AddError ('%s').\n", msg);
        
-       error* err = (error*) g_malloc0 (sizeof (error));
-       err->msg = g_strdup (msg);
-
-       error* last = errors;
+       error *err = (error *) g_malloc0 (sizeof (error));
+       err->msg = msg;
+       
+       error *last = errors;
        while (last != NULL && last->next != NULL)
                last = last->next;
-               
+       
        if (last == NULL) {
                errors = err;
        } else {
@@ -429,42 +433,36 @@
        }
 }
 
-void
-ASFParser::AddError (char* err)
-{
-       AddError ((const char*) err);
-       g_free (err);
-}
-
 asf_stream_properties* 
-ASFParser::GetStream (gint32 stream_index)
+ASFParser::GetStream (int stream_index)
 {
        if (stream_index < 1 || stream_index > 127)
                return NULL;
-               
+       
        return stream_properties [stream_index - 1];
 }
 
 void
-ASFParser::SetStream (gint32 stream_index, asf_stream_properties* stream)
+ASFParser::SetStream (int stream_index, asf_stream_properties *stream)
 {
        if (stream_index < 1 || stream_index > 127) {
                printf ("ASFParser::SetStream (%i, %p): Invalid stream 
index.\n", stream_index, stream);
                return;
        }
+       
        stream_properties [stream_index - 1] = stream;
 }
 
 bool
-ASFParser::IsValidStream (gint32 stream_index)
+ASFParser::IsValidStream (int stream_index)
 {
        return GetStream (stream_index) != NULL;
 }
 
-guint64
-ASFParser::GetPacketOffset (gint32 packet_index)
+int64_t
+ASFParser::GetPacketOffset (int packet_index)
 {
-       if (packet_index < 0 || (gint32) packet_index >= (gint32) 
file_properties->data_packet_count) {
+       if (packet_index < 0 || packet_index >= (int) 
file_properties->data_packet_count) {
 //             AddError (g_strdup_printf ("ASFParser::GetPacketOffset (%i): 
Invalid packet index (there are %llu packets).", packet_index, 
file_properties->data_packet_count)); 
                return 0;
        }
@@ -473,53 +471,59 @@
        return packet_offset + packet_index * file_properties->min_packet_size;
 }
 
-gint32
-ASFParser::GetPacketIndex (guint64 offset)
+int
+ASFParser::GetPacketIndex (int64_t offset)
 {
        if (offset < packet_offset)
                return -1;
-       if (offset > (guint64) packet_offset_end)
+       
+       if (offset > packet_offset_end)
                return file_properties->data_packet_count;
+       
        return (offset - packet_offset) / file_properties->min_packet_size;
 }
 
-gint32
-ASFParser::GetPacketIndexOfPts (gint32 stream_number, gint64 pts)
+int
+ASFParser::GetPacketIndexOfPts (int stream_id, int64_t pts)
 {
+       ASFPacket *packet = NULL;
        int result = 0;
-       ASFPacket* packet = NULL;
        
        // Read packets until we find the packet which has a pts
        // greater than the one we're looking for.
        
        while (ReadPacket (packet, result)) {
-               gint64 current_pts = packet->GetPts (stream_number);
+               int64_t current_pts = packet->GetPts (stream_id);
+               
                if (current_pts < 0) // 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
                        return result - 1; // return the previous one.
+               
                result++;
        }
        
        return -1;
 }
 
-asf_header* 
+asf_header *
 ASFParser::GetHeader ()
 {
        return header;
 }
 
-asf_file_properties* 
+asf_file_properties *
 ASFParser::GetFileProperties ()
 { 
        return file_properties;
 }
 
-asf_object* 
-ASFParser::GetHeaderObject (const asf_guid* guid)
+asf_object *
+ASFParser::GetHeaderObject (const asf_guid *guid)
 {
        int index = GetHeaderObjectIndex (guid);
+       
        if (index >= 0) {
                return header_objects [index];
        } else {
@@ -528,9 +532,10 @@
 }
 
 int 
-ASFParser::GetHeaderObjectIndex (const asf_guid* guid, int start)
+ASFParser::GetHeaderObjectIndex (const asf_guid *guid, int start)
 {
        int i = start;
+       
        if (i < 0)
                return -1;
                
@@ -544,11 +549,12 @@
        return -1;
 }
 
-asf_object* 
+asf_object *
 ASFParser::GetHeader (int index) 
 {
        if (index < 0)
                return NULL;
+       
        return header_objects [index];
 }
 
@@ -557,27 +563,25 @@
        ASFFileSource
 */
 
-ASFFileSource::ASFFileSource (ASFParser* parser, const char* fn) : ASFSource 
(parser)
+ASFFileSource::ASFFileSource (ASFParser *parser, const char *filename) : 
ASFSource (parser)
 {
-       filename = g_strdup (fn);
+       this->filename = g_strdup (filename);
        fd = NULL;
 }
 
 ASFFileSource::~ASFFileSource ()
 {
        g_free (filename);
-       filename = NULL;
-       if (fd) {
+       if (fd)
                fclose (fd);
-               fd = NULL;
-       }
 }
 
 bool
-ASFFileSource::SeekInternal (size_t offset, int mode)
+ASFFileSource::SeekInternal (int64_t offset, int mode)
 {
        if (fseek (fd, offset, mode) != 0) {
-               parser->AddError (g_strdup_printf ("Can't seek to offset %i 
with mode %i in '%s': %s.\n", offset, mode,  filename, strerror (errno)));
+               parser->AddError (g_strdup_printf ("Can't seek to offset %lld 
with mode %d in '%s': %s.\n",
+                                                  offset, mode, filename, 
strerror (errno)));
                return false;
        }
        
@@ -585,11 +589,11 @@
 }
 
 bool
-ASFFileSource::ReadInternal (void* destination, size_t bytes)
+ASFFileSource::ReadInternal (void *dest, uint32_t bytes)
 {
        size_t bytes_read;
        
-       if (destination == NULL) {
+       if (dest == NULL) {
                parser->AddError ("Out of memory.\n");
                return false;
        }
@@ -597,12 +601,13 @@
        if (!fd) {
                fd = fopen (filename, "rb");
                if (!fd) {
-                       parser->AddError (g_strdup_printf ("Could not open the 
file '%s': %s.\n", filename, strerror (errno)));
+                       parser->AddError (g_strdup_printf ("Could not open the 
file '%s': %s.\n",
+                                                          filename, strerror 
(errno)));
                        return false;
                }
        }
 
-       bytes_read = fread (destination, 1, bytes, fd);
+       bytes_read = fread (dest, 1, bytes, fd);
        
        if (bytes_read != bytes) {
                if (ferror (fd) != 0) {
@@ -622,7 +627,7 @@
        ASFSource
 */
 
-ASFSource::ASFSource (ASFParser* asf_parser)
+ASFSource::ASFSource (ASFParser *asf_parser)
 {
        parser = asf_parser;
 }
@@ -633,51 +638,45 @@
 }
 
 bool
-ASFSource::Seek (size_t offset)
+ASFSource::Seek (int64_t offset)
 {
        return SeekInternal (offset, SEEK_CUR);
 }
 
 bool
-ASFSource::Seek (size_t offset, int mode)
+ASFSource::Seek (int64_t offset, int mode)
 {
        return SeekInternal (offset, mode);
 }
 
 
 bool
-ASFSource::Read (void* destination, size_t bytes)
+ASFSource::Read (void *buf, uint32_t n)
 {
-       bool result;
-       
-       //printf ("ASFSource::Read (%.8p, %4i), pp: %lld, cp: %lld, result: 
%s", destination, bytes, position, Position (), result ? "true" : "false");
-               
-       result = ReadInternal (destination, bytes);
-       
-       
-       return result;
+       return ReadInternal (buf, n);
 }
 
 bool 
-ASFSource::ReadEncoded (gint32 length, guint32* destination)
+ASFSource::ReadEncoded (uint32_t length, uint32_t *dest)
 {
-       guint16 result2 = 0;
-       guint8 result1 = 0;
+       uint16_t result2 = 0;
+       uint8_t result1 = 0;
        
        switch (length) {
-       case 0x00: return true;
+       case 0x00:
+               return true;
        case 0x01: 
                if (!Read (&result1, 1))
                        return false;
-               *destination = result1;
+               *dest = result1;
                return true;
        case 0x02:
                if (!Read (&result2, 2))
                        return false;
-               *destination = result2;
+               *dest = result2;
                return true;
        case 0x03:
-               return Read (destination, 4);
+               return Read (dest, 4);
        default:
                parser->AddError (g_strdup_printf ("Invalid read length: %i.", 
length));
                return false;
@@ -691,58 +690,59 @@
 ASFPacket::ASFPacket ()
 {
        payloads = NULL;
-       index = -1;
        position = -1;
+       index = -1;
 }
 
 ASFPacket::~ASFPacket ()
 {
        delete payloads;
-       payloads = NULL;
 }
 
-gint32
+int
 ASFPacket::GetPayloadCount ()
 {
        if (!payloads)
                return 0;
+       
        return payloads->get_number_of_payloads ();
 }
 
-asf_single_payload* 
-ASFPacket::GetPayload (gint32 index /* 0 based */)
+asf_single_payload *
+ASFPacket::GetPayload (int index /* 0 based */)
 {
        if (index >= 0 && index < GetPayloadCount ())
                return payloads->payloads [index];
-               
+       
        return NULL;
 }
 
-gint64
-ASFPacket::GetPts (gint32 stream_number)
+int64_t
+ASFPacket::GetPts (int stream_id)
 {
        if (!payloads)
                return -1;
        
-       asf_single_payload* first = GetFirstPayload (stream_number);
+       asf_single_payload *first = GetFirstPayload (stream_id);
        if (!first)
                return -1;
-               
+       
        return first->get_presentation_time ();
 }
 
-asf_single_payload* 
-ASFPacket::GetFirstPayload (gint32 stream_number /* 1 - 127 */)
+asf_single_payload *
+ASFPacket::GetFirstPayload (int stream_id /* 1 - 127 */)
 {
        if (!payloads)
                return NULL;
-               
+       
        int index = 0;
        while (payloads->payloads [index] != NULL) {
-               if (payloads->payloads [index]->stream_number == stream_number)
+               if (payloads->payloads [index]->stream_id == stream_id)
                        return payloads->payloads [index];
                index++;
        }
+       
        return NULL;
 }
 
@@ -750,7 +750,7 @@
        ASFFrameReader
 */
 
-ASFFrameReader::ASFFrameReader (ASFParser* p)
+ASFFrameReader::ASFFrameReader (ASFParser *p)
 {
        parser = p;
        first = NULL;
@@ -767,17 +767,14 @@
        script_command_stream_index = 0;
        FindScriptCommandStream ();
 }
-       
+
 ASFFrameReader::~ASFFrameReader ()
 {
-       parser = NULL;
-       
        RemoveAll ();
        
-       gint32 i = -1;
-       while (payloads [++i] != NULL)
-               delete payloads [i];
-       g_free (payloads); payloads = NULL;
+       for (int i = 0; payloads[i]; i++)
+               delete payloads[i];
+       g_free (payloads);
 }
 
 void
@@ -785,7 +782,7 @@
 {
        if (script_command_stream_index > 0)
                return;
-               
+       
        for (int i = 1; i <= 127; i++) {
                asf_stream_properties* stream = parser->GetStream (i);
                //printf ("Checking guid of stream %i (%p): %s against %s\n", 
i, stream, stream == NULL ? "-" : asf_guid_tostring (&stream->stream_type), 
stream == NULL ? "-" : asf_guid_tostring (&asf_guids_media_command));
@@ -797,15 +794,15 @@
 }
 
 bool
-ASFFrameReader::ResizeList (gint32 size)
+ASFFrameReader::ResizeList (int size)
 {
-       asf_single_payload** new_list = NULL;
+       asf_single_payload **new_list = NULL;
        
        if (payloads_size >= size && size > 0)
                return true;
        
        // Allocate a new list
-       new_list = (asf_single_payload**) parser->Malloc (sizeof 
(asf_single_payload*) * (size + 1));
+       new_list = (asf_single_payload **) parser->Malloc (sizeof 
(asf_single_payload*) * (size + 1));
        
        if (new_list == NULL) {
                return false;
@@ -816,6 +813,7 @@
                memcpy (new_list, payloads, payloads_size * sizeof 
(asf_single_payload*));
                g_free (payloads);
        }
+       
        payloads = new_list;
        payloads_size = size;
        
@@ -823,18 +821,18 @@
 }
 
 bool
-ASFFrameReader::Seek (gint32 stream_number, gint64 pts)
+ASFFrameReader::Seek (int stream_id, int64_t pts)
 {
-       ASF_LOG ("ASFFrameReader::Seek (%i, %llu).\n", stream_number, pts);
+       ASF_LOG ("ASFFrameReader::Seek (%d, %lld).\n", stream_id, pts);
        
        if (!CanSeek ())
                return false;
-               
+       
        // Now this is an algorithm that might need some optimization.
        // We seek from the first frame to the key frame AFTER the one we want 
(counting the numbers of frames)
        // then we seek again from the first frame until the number of frames 
counted - 1.      
        
-       gint32 counter = 0;
+       int counter = 0;
        bool found = true;
        
        current_packet_index = 0;
@@ -859,7 +857,7 @@
                        return false;
                }
        }
-               
+       
        return true;
 }
 
@@ -870,7 +868,7 @@
 }
 
 bool
-ASFFrameReader::Advance (gint32 desired_stream_number)
+ASFFrameReader::Advance (int stream_id)
 {
 start:
        ASF_LOG ("ASFFrameReader::Advance ().\n");
@@ -885,13 +883,12 @@
                }
        } else {
                // Free all old payloads, they belong to the previous frame.
-               int i = -1;
-               while (payloads [++i] != NULL) {
-                       delete payloads [i];
-                       payloads [i] = NULL;
+               for (int i = 0; payloads[i]; i++) {
+                       delete payloads[i];
+                       payloads[i] = NULL;
                }
        }
-               
+       
        if (first == NULL) {
                if (!ReadMore ())
                        return false;
@@ -899,14 +896,14 @@
                        return false;
        }
        
-       gint32 payload_count = 0;
-       guint32 media_object_number = 0;
+       int payload_count = 0;
+       uint32_t media_object_number = 0;
        ASFFrameReaderData* current = NULL;
-
+       
        size = 0;
-
-       ASF_LOG ("ASFFrameReader::Advance (): frame data: size = %lld, key = 
%s, pts = %llu, stream# = %i, media_object_number = %u.\n", 
-               size, IsKeyFrame () ? "true" : "false", Pts (), StreamNumber 
(), media_object_number);
+       
+       ASF_LOG ("ASFFrameReader::Advance (): frame data: size = %lld, key = 
%s, pts = %lld, stream# = %d, media_object_number = %u.\n", 
+                size, IsKeyFrame () ? "true" : "false", Pts (), StreamId (), 
media_object_number);
        //asf_single_payload_dump (payloads [0]);
        current = first;
        
@@ -930,20 +927,19 @@
                        }
                }
                
-               ASF_LOG ("ASFFrameReader::Advance (): checking payload, stream: 
%i, media object number %i, size: %i\n", current->payload->stream_number, 
current->payload->media_object_number, current->payload->payload_data_length);
+               ASF_LOG ("ASFFrameReader::Advance (): checking payload, stream: 
%d, media object number %d, size: %d\n", current->payload->stream_id, 
current->payload->media_object_number, current->payload->payload_data_length);
                
                asf_single_payload* payload = current->payload;
                
-               if (desired_stream_number == 0 || payload->stream_number == 
desired_stream_number) {
+               if (stream_id == 0 || payload->stream_id == stream_id) {
                        if (payload_count > 0 && payload->media_object_number 
!= media_object_number) {
                                // We've found the end of the current frame's 
payloads
                                ASF_LOG ("ASFFrameReader::Advance (): reached 
media object number %i (while reading %i).\n", payload->media_object_number, 
media_object_number);
                                goto end_frame;
                        }
                        
-                       if (desired_stream_number == 0) {
-                               desired_stream_number = payload->stream_number;
-                       }
+                       if (stream_id == 0)
+                               stream_id = payload->stream_id;
                        
                        media_object_number = payload->media_object_number;
                        
@@ -983,7 +979,7 @@
 
        // Check if the current frame is a script command, in which case we 
must call the callback set in 
        // the parser (and read another frame).
-       if (StreamNumber () == script_command_stream_index && 
script_command_stream_index > 0) {
+       if (StreamId () == script_command_stream_index && 
script_command_stream_index > 0) {
                printf ("reading script command\n");
                ReadScriptCommand ();
                goto start;
@@ -995,12 +991,12 @@
 void
 ASFFrameReader::ReadScriptCommand ()
 {
-       guint64 pts;
-       char* text;
-       char* type;
-       gunichar2* data;
-       gunichar2* uni_type = NULL;
-       gunichar2* uni_text = NULL;
+       int64_t pts;
+       char *text;
+       char *type;
+       gunichar2 *data;
+       gunichar2 *uni_type = NULL;
+       gunichar2 *uni_text = NULL;
        int text_length = 0;
        int type_length = 0;
        ASF_LOG ("ASFFrameReader::ReadScriptCommand (), size = %llu.\n", size);
@@ -1010,7 +1006,7 @@
                return;
        }
 
-       data = (gunichar2*)g_malloc (Size ());
+       data = (gunichar2*) g_malloc (Size ());
        
        if (!Write (data)) {
                ASF_LOG ("ASFFrameReader::ReadScriptCommand (): couldn't read 
the data.\n");
@@ -1025,7 +1021,7 @@
        // there should be at least two null characters.
        int null_count = 0;
        
-       for (unsigned int i = 0; i < (size / sizeof (gunichar2)); i++) {
+       for (uint32_t i = 0; i < (size / sizeof (gunichar2)); i++) {
                if (uni_text == NULL) {
                        type_length++;
                } else {
@@ -1065,7 +1061,7 @@
        
        ASFPacket* packet = new ASFPacket ();
        
-       if ((guint32) current_packet_index >= parser->GetPacketCount ()) {
+       if ((uint32_t) current_packet_index >= parser->GetPacketCount ()) {
                eof = true;
                return false;
        }
@@ -1076,9 +1072,8 @@
                return false;
        }
        
-       if (CanSeek ()) {
+       if (CanSeek ())
                current_packet_index++;
-       }
        
        asf_single_payload** payloads = packet->payloads->steal_payloads ();
        int i = -1;
@@ -1097,22 +1092,21 @@
        }
        g_free (payloads);
        
-       ASF_LOG ("ASFFrameReader::ReadMore (): read %i payloads.\n", i);
-               
+       ASF_LOG ("ASFFrameReader::ReadMore (): read %d payloads.\n", i);
+       
        delete packet;
        return true;
 }
 
 bool
-ASFFrameReader::Write (void* destination)
+ASFFrameReader::Write (void *dest)
 {
        if (payloads == NULL)
                return false;
-
-       gint32 i = -1;
-       while (payloads [++i] != NULL) {
-               memcpy (destination, payloads [i]->payload_data, payloads 
[i]->payload_data_length);
-               destination = payloads [i]->payload_data_length + (char*) 
destination;
+       
+       for (int i = 0; payloads[i]; i++) {
+               memcpy (dest, payloads[i]->payload_data, 
payloads[i]->payload_data_length);
+               dest = ((char *) dest) + payloads[i]->payload_data_length;
        }
        
        return true;
@@ -1139,17 +1133,12 @@
        
        if (data->next != NULL)
                data->next->prev = data->prev;
-               
+       
        if (data == first)
                first = data->next;
-               
+       
        if (data == last)
                last = data->prev;
-
+       
        delete data;
 }
-
-       
-       
-       
-       

Modified: trunk/moon/src/asf/asf.h
===================================================================
--- trunk/moon/src/asf/asf.h    2008-01-23 20:18:02 UTC (rev 93707)
+++ trunk/moon/src/asf/asf.h    2008-01-23 20:27:18 UTC (rev 93708)
@@ -17,11 +17,11 @@
 #include <errno.h>
 #include <inttypes.h>
 
-typedef guint8 asf_byte;
-typedef guint16 asf_wchar; 
-typedef guint16 asf_word;
-typedef guint32 asf_dword;
-typedef guint64 asf_qword;
+typedef uint8_t asf_byte;
+typedef uint16_t asf_wchar; 
+typedef uint16_t asf_word;
+typedef uint32_t asf_dword;
+typedef uint64_t asf_qword;
 
 struct asf_guid;
 struct asf_object;
@@ -58,88 +58,86 @@
 
 class ASFSource {
 protected:
-       virtual bool ReadInternal (void* destination, size_t bytes) = 0;
-       virtual bool SeekInternal (size_t offset, int mode) = 0;
+       virtual bool ReadInternal (void *buf, uint32_t n) = 0;
+       virtual bool SeekInternal (int64_t offset, int mode) = 0;
        
 public: 
-       ASFSource (ASFParser* parser);
+       ASFSource (ASFParser *parser);
        virtual ~ASFSource ();
        
        // Reads the number of the specified encoded length (0-3)
        // encoded length 3 = read 4 bytes, rest equals encoded length and 
#bytes
        // into the destionation.
-       bool ReadEncoded (gint32 encoded_length, guint32* destionation);        
+       bool ReadEncoded (uint32_t encoded_length, uint32_t *dest);     
        
-       bool Read (void* destination, size_t bytes); // Reads the requested 
number of bytes into the destination
-
-       bool Seek (size_t offset); // Seeks to the offset from the current 
position
-       bool Seek (size_t offset, int mode); // Seeks to the offset, with the 
specified mode (SEEK_CUR, SEEK_END, SEEK_SET)
+       bool Read (void *buf, size_t n); // Reads the requested number of bytes 
into the destination
        
-       virtual guint64 Position () = 0; // Returns the position within the 
source (may not apply if the source is not seekable)
+       bool Seek (int64_t offset); // Seeks to the offset from the current 
position
+       bool Seek (int64_t offset, int mode); // Seeks to the offset, with the 
specified mode (SEEK_CUR, SEEK_END, SEEK_SET)
+       
+       virtual int64_t Position () = 0; // Returns the position within the 
source (may not apply if the source is not seekable)
        virtual bool CanSeek () = 0;
        virtual bool Eof () = 0;
        
-       ASFParser* parser;
+       ASFParser *parser;
 };
 
 class ASFMediaSource : public ASFSource {
-public:
-       ASFMediaSource (ASFParser* parser, IMediaSource* source);
-       
+       IMediaSource *source;
+
 protected:
-       virtual bool ReadInternal (void* destination, size_t bytes);
-       virtual bool SeekInternal (size_t offset, int mode);    
-       virtual guint64 Position ();
+       virtual bool ReadInternal (void *buf, uint32_t n);
+       virtual bool SeekInternal (int64_t offset, int mode);   
+       virtual int64_t Position ();
        virtual bool CanSeek ();
        virtual bool Eof ();
        
-private:
-       IMediaSource* source;
+public:
+       ASFMediaSource (ASFParser *parser, IMediaSource *source);
 };
 
 class ASFFileSource : public ASFSource {
+       char *filename;
+       FILE *fd;
+       
+protected:
+       virtual bool ReadInternal (void *buf, uint32_t n);
+       virtual bool SeekInternal (int64_t offset, int mode);
+       
 public:
-       ASFFileSource (ASFParser* parser, const char* filename);
+       ASFFileSource (ASFParser *parser, const char *filename);
        virtual ~ASFFileSource ();
        
-       virtual guint64 Position () { return fd == NULL ? 0 : ftell (fd); }
+       virtual int64_t Position () { return fd == NULL ? 0 : ftell (fd); }
        virtual bool CanSeek () { return true; }
        virtual bool Eof () { return fd == NULL ? false : feof (fd) != 0; }
        
-       const char* GetFileName () { return filename; }
-       
-protected:
-       virtual bool ReadInternal (void* destination, size_t bytes);
-       virtual bool SeekInternal (size_t offset, int mode);
-       
-private:
-       char* filename;
-       FILE* fd;
+       const char *GetFileName () { return filename; }
 };
 
 class ASFPacket {
+       int64_t position; // The position of this packet. -1 if not known.
+       int index; // The index of this packet. -1 if not known.
+       
 public:
        ASFPacket ();   
        virtual ~ASFPacket ();
        
-       gint32 GetPayloadCount (); // Returns the number of payloads in this 
packet.
-       asf_single_payload* GetPayload (gint32 index /* 0 based */);
-       gint64 GetPts (gint32 stream_number /* 1 - 127 */); // Gets the pts of 
the first payload.
-       asf_single_payload* GetFirstPayload (gint32 stream_number /* 1 - 127 
*/); // Gets the index first payload of the specified stream.
+       asf_multiple_payloads *payloads; // The payloads in this packet
        
-       asf_multiple_payloads* payloads; // The payloads in this packet
-
-private:
-       gint32 index; // The index of this packet. -1 if not known.
-       gint64 position; // The position of this packet. -1 if not known.       
        
+       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.
+       asf_single_payload *GetFirstPayload (int stream_id /* 1 - 127 */); // 
Gets the index first payload of the specified stream.
 };
 
 struct ASFFrameReaderData {
-       asf_single_payload* payload;
-       ASFFrameReaderData* prev;
-       ASFFrameReaderData* next;
+       asf_single_payload *payload;
+       ASFFrameReaderData *prev;
+       ASFFrameReaderData *next;
        
-       ASFFrameReaderData (asf_single_payload* load) 
+       ASFFrameReaderData (asf_single_payload *load) 
        {
                payload = load;
                prev = NULL;
@@ -179,149 +177,158 @@
 */
 
 class ASFFrameReader {
+       ASFParser *parser;
+       
+       int current_packet_index;
+       int script_command_stream_index;
+       
+       // The queue of payloads we've built.
+       ASFFrameReaderData *first;
+       ASFFrameReaderData *last;
+       
+       // A list of the payloads in the current frame
+       asf_single_payload **payloads;
+       int payloads_size;
+       
+       // Information about the current frame.
+       uint64_t size;
+       
+       bool eof;
+       
+       bool ResizeList (int size); // Resizes the list of payloads to the 
requested size. 
+       bool ReadMore (); // Reads another packet and stuffs the payloads into 
our queue 
+       void RemoveAll (); // Deletes the entire queue of payloads (and deletes 
every element)
+       void Remove (ASFFrameReaderData *data); // Unlinks the payload from the 
queue and deletes it.
+       
+       void ReadScriptCommand (); // If the current frame is a script command, 
decodes it and calls the callback set in the parser.
+       
 public:
-       ASFFrameReader (ASFParser* parser);
+       ASFFrameReader (ASFParser *parser);
        virtual ~ASFFrameReader ();
        
        // Can we seek?
        bool CanSeek () { return true; }
        
        // Seek to the frame with the provided pts 
-       bool Seek (gint32 stream_number, gint64 pts);
+       bool Seek (int stream_id, int64_t pts);
        
        // Advance to the next frame
        // Returns false if unsuccessful (if due to no more data, eof is set, 
otherwise some error occurred)
        bool Advance ();
        
        // Advance to the next frame of the specified stream number
-       // stream_number = 0 means any stream
-       bool Advance (gint32 stream_number);
+       // stream_id = 0 means any stream
+       bool Advance (int stream_id);
        
        // Write the frame's data to a the destination
-       bool Write (void* destination);
+       bool Write (void *dest);
        
        // Information about the current frame
-       guint64 Size () { return size; }
+       uint64_t Size () { return size; }
        bool IsKeyFrame () { return (payloads_size > 0 && payloads [0] != NULL) 
? payloads [0]->is_key_frame : false; }
-       gint64 Pts () { return (payloads_size > 0 && payloads [0] != NULL) ? 
payloads [0]->get_presentation_time () : 0; }
-       gint32 StreamNumber () { return (payloads_size > 0 && payloads [0] != 
NULL) ? payloads [0]->stream_number : 0; }
+       int64_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 ();
-       
-private:
-       ASFParser* parser;
-       
-       gint32 current_packet_index;
-       gint32 script_command_stream_index;
-       
-       // The queue of payloads we've built.
-       ASFFrameReaderData* first;
-       ASFFrameReaderData* last;
-       
-       // A list of the payloads in the current frame
-       asf_single_payload** payloads;
-       gint32 payloads_size;
-       
-       // Information about the current frame.
-       guint64 size;
-       
-       bool eof;
-       
-       bool ResizeList (gint32 size); // Resizes the list of payloads to the 
requested size. 
-       bool ReadMore (); // Reads another packet and stuffs the payloads into 
our queue 
-       void RemoveAll (); // Deletes the entire queue of payloads (and deletes 
every element)
-       void Remove (ASFFrameReaderData* data); // Unlinks the payload from the 
queue and deletes it.
-       
-       void ReadScriptCommand (); // If the current frame is a script command, 
decodes it and calls the callback set in the parser.
 };
 
 class ASFParser {
 private:
+       struct error {
+               error *next;
+               char *msg;
+       };
+       
+       error *errors;
+       
        void Initialize ();
        bool ReadData ();
-       asf_object* ReadObject (asf_object* guid);
-       void SetStream (gint32 stream_index, asf_stream_properties* stream);
-
+       asf_object *ReadObject (asf_object *guid);
+       void SetStream (int stream_id, asf_stream_properties *stream);
+       
 public:
-       ASFParser (const char* filename);
-       ASFParser (ASFSource* source); // The parser takes ownership of the 
source and will delete it when the parser is deleted.
+       ASFParser (const char *filename);
+       ASFParser (ASFSource *source); // The parser takes ownership of the 
source and will delete it when the parser is deleted.
        virtual ~ASFParser ();
        
-       bool ReadHeader (); // Reads the header of the asf file.
-       bool ReadPacket (ASFPacket* packet); // Reads the packet at the current 
position.
+       bool ReadHeader ();
+       bool ReadPacket (ASFPacket *packet);
+       
        // Seeks to the packet index (as long as the packet index >= 0), then 
reads it.
        // If the packet index is < 0, then just read at the current position
-       bool ReadPacket (ASFPacket* packet, gint32 packet_index); 
+       bool ReadPacket (ASFPacket *packet, int packet_index); 
        
-       bool VerifyHeaderDataSize (guint64 size); // Verifies that the 
requested size is a size that can be inside the header.
-       void* Malloc (gint32 size); // Allocates the requested memory and 
verifies that the size can actually be contained within the header. Reports an 
Out of Memory error if the memory can't be allocated, and returns NULL
-       void* MallocVerified (gint32 size); // Allocates the requested memory 
(no size checking), reports an Out of Memory error if the memory can't be 
allocated, and returns NULL
-
+       // Verifies that the requested size is a size that can be inside the 
header.
+       bool VerifyHeaderDataSize (uint32_t size);
+       
+       // Allocates the requested memory (no size checking), reports
+       // an Out of Memory error if the memory can't be allocated, and returns
+       // NULL
+       void *MallocVerified (uint32_t size);
+       
+       // Allocates the requested memory and verifies that the size
+       // can actually be contained within the header. Reports an Out of Memory
+       // error if the memory can't be allocated, and returns NULL
+       void *Malloc (uint32_t size);
+       
        // Error handling
-       const char* GetLastError (); // Returns the last error (NULL if no 
errors have been reported)
-       void AddError (const char* err); // Makes a copy of the provided error 
string.
-       void AddError (char* err); // Frees the provided error string (allows 
you to do things like: AddError (g_strdup_printf ("error #%i", 2)))
-
+       const char *GetLastError ();
+       void AddError (const char *err);
+       void AddError (char *err);
+       
        // Stream index: valid values range from 1 to 127
        // If the stream_index doesn't specify a valid stream (for whatever 
reason), NULL is returned.
-       asf_stream_properties* GetStream (gint32 stream_index);
+       asf_stream_properties *GetStream (int stream_index);
        
        // Checks if the stream_index (range 1 - 127) is a valid stream index 
in the asf file.
-       bool IsValidStream (gint32 stream_index);
+       bool IsValidStream (int stream_index);
        
        // Returns 0 on failure, otherwise the offset of the packet index.
-       guint64 GetPacketOffset (gint32 packet_index);
+       int64_t GetPacketOffset (int packet_index);
        
        // Returns the index of the packet at the specified offset (from the 
beginning of the file)
-       gint32 GetPacketIndex (guint64 offset);
+       int GetPacketIndex (int64_t offset);
        
        // Searches the header objects for the specified guid
        // returns -1 if nothing is found.
-       int GetHeaderObjectIndex (const asf_guid* guid, int start = 0);
+       int GetHeaderObjectIndex (const asf_guid *guid, int start = 0);
        
        // Returns the packet index where the desired pts is found.
        // Returns -1 on failure.
-       gint32 GetPacketIndexOfPts (gint32 stream_number, gint64 pts);
-
+       int GetPacketIndexOfPts (int stream_id, int64_t pts);
+       
        // The number of packets in the stream (0 if unknown).
-       guint64 GetPacketCount ();
-
+       uint64_t GetPacketCount ();
+       
        // Field accessors
        
-       asf_header* GetHeader ();
-       asf_object* GetHeader (int index);
-       asf_file_properties* GetFileProperties ();
-       asf_object* GetHeaderObject (const asf_guid* guid);
-
+       asf_header *GetHeader ();
+       asf_object *GetHeader (int index);
+       asf_file_properties *GetFileProperties ();
+       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, guint64 pts);
-       void* embedded_script_command_state;
-       embedded_script_command_callback* embedded_script_command;
+       typedef void embedded_script_command_callback (void *state, char *type, 
char *text, int64_t pts);
+       embedded_script_command_callback *embedded_script_command;
+       void *embedded_script_command_state;
        
        // The following fields are available only after ReadHeader is called.
        
-       asf_header* header;
-       asf_object** header_objects;
-       asf_file_properties* file_properties;
-       asf_header_extension* header_extension;
-       asf_stream_properties* stream_properties [127];
-       asf_marker* marker;
-       asf_script_command* script_command;
+       asf_header *header;
+       asf_object **header_objects;
+       asf_file_properties *file_properties;
+       asf_header_extension *header_extension;
+       asf_stream_properties *stream_properties[127];
+       asf_marker *marker;
+       asf_script_command *script_command;
        
-       asf_data* data;
-       guint64 data_offset; // location of data object
-       guint64 packet_offset; // location of the beginning of the first packet
-       guint64 packet_offset_end; // location of the end of the last packet
-
-       ASFSource* source; // The source used to read data.
+       asf_data *data;
+       int64_t data_offset; // location of data object
+       int64_t packet_offset; // location of the beginning of the first packet
+       int64_t packet_offset_end; // location of the end of the last packet
        
-private:
-       struct error {
-               char* msg;
-               error* next;
-       };
-       error* errors;
+       ASFSource *source; // The source used to read data.
 };
 
 
-#endif
+#endif /* _ASF_MOONLIGHT_H */

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

Reply via email to