Author: dlmcpaul Date: 2010-07-03 08:12:56 +0200 (Sat, 03 Jul 2010) New Revision: 37363 Changeset: http://dev.haiku-os.org/changeset/37363/haiku Added: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/compat.h Removed: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/fileio.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/fileio.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/utf.c Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/ASFFileReader.cpp haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/Jamfile haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asfint.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/debug.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/guid.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/guid.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/header.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/header.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/parse.c haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/parse.h haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/utf.h Log: Update to latest libasf (r107) Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/ASFFileReader.cpp =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/ASFFileReader.cpp 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/ASFFileReader.cpp 2010-07-03 06:12:56 UTC (rev 37363) @@ -184,9 +184,9 @@ format->extraData = videoHeader->data; if (stream->flags & ASF_STREAM_FLAG_EXTENDED) { - format->FrameScale = stream->extended->avg_time_per_frame; + format->FrameScale = stream->extended_properties->avg_time_per_frame; format->FrameRate = 10000000L; - printf("num avg time per frame for video %Ld\n",stream->extended->avg_time_per_frame); + printf("num avg time per frame for video %Ld\n",stream->extended_properties->avg_time_per_frame); } return true; @@ -210,9 +210,9 @@ if (stream) { if (stream->flags & ASF_STREAM_FLAG_EXTENDED) { - printf("STREAM %ld end time %Ld, start time %Ld\n",streamIndex, stream->extended->end_time, stream->extended->start_time); - if (stream->extended->end_time - stream->extended->start_time > 0) { - return stream->extended->end_time - stream->extended->start_time; + printf("STREAM %ld end time %Ld, start time %Ld\n",streamIndex, stream->extended_properties->end_time, stream->extended_properties->start_time); + if (stream->extended_properties->end_time - stream->extended_properties->start_time > 0) { + return stream->extended_properties->end_time - stream->extended_properties->start_time; } } } Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/Jamfile =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/Jamfile 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/Jamfile 2010-07-03 06:12:56 UTC (rev 37363) @@ -6,9 +6,7 @@ asf.c byteio.c data.c - fileio.c guid.c header.c parse.c - utf.c ; Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.c 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.c 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,13 +21,31 @@ #include "asf.h" #include "asfint.h" -#include "fileio.h" #include "byteio.h" #include "header.h" #include "parse.h" #include "data.h" #include "debug.h" + +static int +asf_fileio_read_cb(void *stream, void *buffer, int size) +{ + int ret; + + ret = fread(buffer, 1, size, stream); + if (!ret && !feof(stream)) + return -1; + + return ret; +} + +static int64_t +asf_fileio_seek_cb(void *stream, int64_t offset) +{ + return fseek(stream, offset, SEEK_SET); +} + asf_file_t * asf_open_file(const char *filename) { @@ -35,12 +53,12 @@ asf_iostream_t stream; FILE *fstream; - fstream = fopen(filename, "r"); + fstream = fopen(filename, "rb"); if (!fstream) return NULL; stream.read = asf_fileio_read_cb; - stream.write = asf_fileio_write_cb; + stream.write = NULL; stream.seek = asf_fileio_seek_cb; stream.opaque = fstream; @@ -80,7 +98,7 @@ file->streams[i].type = ASF_STREAM_TYPE_NONE; file->streams[i].flags = ASF_STREAM_FLAG_NONE; file->streams[i].properties = NULL; - file->streams[i].extended = NULL; + file->streams[i].extended_properties = NULL; } return file; @@ -96,7 +114,7 @@ tmp = asf_parse_header(file); if (tmp < 0) { - printf("error parsing header: %d\n", tmp); + debug_printf("error parsing header: %d", tmp); return tmp; } file->position += tmp; @@ -104,7 +122,7 @@ tmp = asf_parse_data(file); if (tmp < 0) { - printf("error parsing data object: %d\n", tmp); + debug_printf("error parsing data object: %d", tmp); return tmp; } file->position += tmp; @@ -124,7 +142,7 @@ file->index_position < file->file_size && !file->index) { tmp = asf_parse_index(file); if (tmp < 0) { - printf("Error finding index object! %d\n", tmp); + debug_printf("Error finding index object! %d", tmp); break; } @@ -152,7 +170,7 @@ for (tmp = 0; tmp < ASF_MAX_STREAMS; tmp++) { if (file->streams[tmp].type != ASF_STREAM_TYPE_NONE) { - debug_printf("stream %d of type %s found!", tmp, file->streams[tmp].type == 1 ? "Audio" : file->streams[tmp].type == 2 ? "Video" : "Unknown"); + debug_printf("stream %d of type %d found!", tmp, file->streams[tmp].type); } } @@ -176,7 +194,7 @@ for (i=0; i < ASF_MAX_STREAMS; i++) { free(file->streams[i].properties); - free(file->streams[i].extended); + free(file->streams[i].extended_properties); } free(file); Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.h 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asf.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,9 +19,8 @@ #ifndef ASF_H #define ASF_H - /* used int types for different platforms */ -#if !defined(__MINGW_H) && defined(_WIN32) +#if defined(WIN32) && !defined(__MINGW_H) typedef char int8_t; typedef unsigned char uint8_t; typedef short int16_t; @@ -35,14 +34,84 @@ #include <stdint.h> #endif -struct asf_guid_s { - uint32_t v1; - uint32_t v2; - uint16_t v3; - uint8_t v4[8]; +#if defined(WIN32) && defined(DLL_EXPORT) +# define LIBASF_API __declspec(dllexport) +#else +# define LIBASF_API +#endif + + + + +typedef enum { + /* fatal errors related to library function */ + ASF_ERROR_INTERNAL = -100, /* incorrect input to API calls */ + ASF_ERROR_OUTOFMEM = -101, /* some malloc inside program failed */ + + /* errors related to reading data from stream */ + ASF_ERROR_NEEDS_BYTES = -200, /* not enough data from read */ + ASF_ERROR_EOF = -201, /* end of file reached */ + ASF_ERROR_IO = -202, /* error reading or writing to file */ + + /* errors related to file being corrupted */ + ASF_ERROR_INVALID_LENGTH = -300, /* length value conflict in input data */ + ASF_ERROR_INVALID_VALUE = -301, /* other value conflict in input data */ + ASF_ERROR_INVALID_OBJECT = -302, /* ASF object missing or in wrong place */ + ASF_ERROR_INVALID_OBJECT_SIZE = -303, /* invalid ASF object size (too small) */ + + /* errors related to seeking, usually non-fatal */ + ASF_ERROR_SEEKABLE = -400, /* file not seekable */ + ASF_ERROR_SEEK = -401 /* file is seekable but seeking failed */ +} asf_error_t; + +typedef enum { + ASF_STREAM_TYPE_NONE = 0x00, + ASF_STREAM_TYPE_AUDIO = 0x01, + ASF_STREAM_TYPE_VIDEO = 0x02, + ASF_STREAM_TYPE_COMMAND = 0x03, + ASF_STREAM_TYPE_UNKNOWN = 0xff +} asf_stream_type_t; + +#define ASF_STREAM_FLAG_NONE 0x0000 +#define ASF_STREAM_FLAG_AVAILABLE 0x0001 +#define ASF_STREAM_FLAG_HIDDEN 0x0002 +#define ASF_STREAM_FLAG_EXTENDED 0x0004 + + +/* waveformatex fields specified in Microsoft documentation: + http://msdn2.microsoft.com/en-us/library/ms713497.aspx */ +struct asf_waveformatex_s { + uint16_t wFormatTag; + uint16_t nChannels; + uint32_t nSamplesPerSec; + uint32_t nAvgBytesPerSec; + uint16_t nBlockAlign; + uint16_t wBitsPerSample; + uint16_t cbSize; + uint8_t *data; }; -typedef struct asf_guid_s asf_guid_t; +typedef struct asf_waveformatex_s asf_waveformatex_t; +#define ASF_BITMAPINFOHEADER_SIZE 40 +/* bitmapinfoheader fields specified in Microsoft documentation: + http://msdn2.microsoft.com/en-us/library/ms532290.aspx */ +struct asf_bitmapinfoheader_s { + uint32_t biSize; + uint32_t biWidth; + uint32_t biHeight; + uint16_t biPlanes; + uint16_t biBitCount; + uint32_t biCompression; + uint32_t biSizeImage; + uint32_t biXPelsPerMeter; + uint32_t biYPelsPerMeter; + uint32_t biClrUsed; + uint32_t biClrImportant; + uint8_t *data; +}; +typedef struct asf_bitmapinfoheader_s asf_bitmapinfoheader_t; + + struct asf_iostream_s { /* read function, returns -1 on error, 0 on EOF and read bytes * otherwise */ @@ -102,6 +171,7 @@ uint8_t *ec_data; /* error correction data array */ uint32_t length; /* length of this packet, usually constant per stream */ + uint32_t sequence; /* sequence value reserved for future use, should be ignored */ uint32_t padding_length; /* length of the padding after the data in this packet */ uint32_t send_time; /* send time of this packet in milliseconds */ uint16_t duration; /* duration of this packet in milliseconds */ @@ -118,55 +188,7 @@ }; typedef struct asf_packet_s asf_packet_t; -/* waveformatex fields specified in Microsoft documentation: - http://msdn2.microsoft.com/en-us/library/ms713497.aspx */ -struct asf_waveformatex_s { - uint16_t wFormatTag; - uint16_t nChannels; - uint32_t nSamplesPerSec; - uint32_t nAvgBytesPerSec; - uint16_t nBlockAlign; - uint16_t wBitsPerSample; - uint16_t cbSize; - uint8_t *data; -}; -typedef struct asf_waveformatex_s asf_waveformatex_t; - -#define ASF_BITMAPINFOHEADER_SIZE 40 - -/* bitmapinfoheader fields specified in Microsoft documentation: - http://msdn2.microsoft.com/en-us/library/ms532290.aspx */ -struct asf_bitmapinfoheader_s { - uint32_t biSize; - uint32_t biWidth; - uint32_t biHeight; - uint16_t biPlanes; - uint16_t biBitCount; - uint32_t biCompression; - uint32_t biSizeImage; - uint32_t biXPelsPerMeter; - uint32_t biYPelsPerMeter; - uint32_t biClrUsed; - uint32_t biClrImportant; - uint8_t *data; -}; -typedef struct asf_bitmapinfoheader_s asf_bitmapinfoheader_t; - -enum asf_stream_type_e { - ASF_STREAM_TYPE_NONE = 0x00, - ASF_STREAM_TYPE_AUDIO = 0x01, - ASF_STREAM_TYPE_VIDEO = 0x02, - ASF_STREAM_TYPE_COMMAND = 0x03, - ASF_STREAM_TYPE_UNKNOWN = 0xff -}; -typedef enum asf_stream_type_e asf_stream_type_t; - -#define ASF_STREAM_FLAG_NONE 0x0000 -#define ASF_STREAM_FLAG_AVAILABLE 0x0001 -#define ASF_STREAM_FLAG_HIDDEN 0x0002 -#define ASF_STREAM_FLAG_EXTENDED 0x0004 - -struct asf_stream_extended_s { +struct asf_stream_extended_properties_s { uint64_t start_time; uint64_t end_time; uint32_t data_bitrate; @@ -183,7 +205,7 @@ uint16_t stream_name_count; uint16_t num_payload_ext; }; -typedef struct asf_stream_extended_s asf_stream_extended_t; +typedef struct asf_stream_extended_properties_s asf_stream_extended_properties_t; struct asf_stream_s { asf_stream_type_t type; /* type of this current stream */ @@ -195,101 +217,82 @@ /* pointer to extended properties of the stream if they specified * only available if ASF_STREAM_FLAG_EXTENDED flag is set, otherwise NULL */ - asf_stream_extended_t *extended; + asf_stream_extended_properties_t *extended_properties; }; typedef struct asf_stream_s asf_stream_t; typedef struct asf_file_s asf_file_t; -enum asf_error_e { - ASF_ERROR_INTERNAL = -1, /* incorrect input to API calls */ - ASF_ERROR_OUTOFMEM = -2, /* some malloc inside program failed */ - ASF_ERROR_EOF = -3, /* unexpected end of file */ - ASF_ERROR_IO = -4, /* error reading or writing to file */ - ASF_ERROR_INVALID_LENGTH = -5, /* length value conflict in input data */ - ASF_ERROR_INVALID_VALUE = -6, /* other value conflict in input data */ - ASF_ERROR_INVALID_OBJECT = -7, /* ASF object missing or in wrong place */ - ASF_ERROR_OBJECT_SIZE = -8, /* invalid ASF object size (too small) */ - ASF_ERROR_SEEKABLE = -9, /* file not seekable */ - ASF_ERROR_SEEK = -10 /* file is seekable but seeking failed */ -}; -struct asf_object_s { - asf_guid_t guid; - uint64_t size; - uint8_t *data; -}; -typedef struct asf_object_s asf_object_t; - /* initialize the library using file on a local filesystem */ -asf_file_t *asf_open_file(const char *filename); +LIBASF_API asf_file_t *asf_open_file(const char *filename); /* initialize the library using callbacks defined on a stream structure, the stream structure can be freed after calling this function */ -asf_file_t *asf_open_cb(asf_iostream_t *iostream); +LIBASF_API asf_file_t *asf_open_cb(asf_iostream_t *iostream); /* close the library handle and free all allocated memory */ -void asf_close(asf_file_t *file); +LIBASF_API void asf_close(asf_file_t *file); /* initialize the library and read all header information of the ASF file */ -int asf_init(asf_file_t *file); +LIBASF_API int asf_init(asf_file_t *file); /* create a packet structure for reading data packets */ -asf_packet_t *asf_packet_create(); +LIBASF_API asf_packet_t *asf_packet_create(); /* free the packet structure allocated earlier, need to be called only once */ -void asf_packet_destroy(asf_packet_t *packet); +LIBASF_API void asf_packet_destroy(asf_packet_t *packet); /* get next packet from the stream to the specified packet structure */ -int asf_get_packet(asf_file_t *file, asf_packet_t *packet); +LIBASF_API int asf_get_packet(asf_file_t *file, asf_packet_t *packet); /* seek to the closest (key frame) packet specified by milliseconds position */ -int64_t asf_seek_to_msec(asf_file_t *file, int64_t msec); +LIBASF_API int64_t asf_seek_to_msec(asf_file_t *file, int64_t msec); /* get metadata information of the ASF file handle */ -asf_metadata_t *asf_header_get_metadata(asf_file_t *file); +LIBASF_API asf_metadata_t *asf_header_get_metadata(asf_file_t *file); /* free metadata structure received from the library */ -void asf_metadata_destroy(asf_metadata_t *metadata); +LIBASF_API void asf_metadata_destroy(asf_metadata_t *metadata); /* free all header information from the ASF file structure * WARNING: after calling this function all asf_header_* * functions will return NULL or failure!!! */ -void asf_header_destroy(asf_file_t *file); +LIBASF_API void asf_header_destroy(asf_file_t *file); /* calculate how many streams are available in current ASF file */ -uint8_t asf_get_stream_count(asf_file_t *file); +LIBASF_API uint8_t asf_get_stream_count(asf_file_t *file); /* get info of a stream, the resulting pointer and its contents should NOT be freed */ -asf_stream_t *asf_get_stream(asf_file_t *file, uint8_t track); +LIBASF_API asf_stream_t *asf_get_stream(asf_file_t *file, uint8_t track); /* return non-zero if the file is broadcasted, 0 otherwise */ -int asf_is_broadcast(asf_file_t *file); +LIBASF_API int asf_is_broadcast(asf_file_t *file); /* return non-zero if the file is seekable, 0 otherwise */ -int asf_is_seekable(asf_file_t *file); +LIBASF_API int asf_is_seekable(asf_file_t *file); /* get size of the ASF file in bytes */ -uint64_t asf_get_file_size(asf_file_t *file); +LIBASF_API uint64_t asf_get_file_size(asf_file_t *file); /* get creation date in 100-nanosecond units since Jan 1, 1601 GMT this value should be ignored for broadcasts */ -uint64_t asf_get_creation_date(asf_file_t *file); +LIBASF_API uint64_t asf_get_creation_date(asf_file_t *file); /* get number of data packets available in this file this value should be ignored for broadcasts */ -uint64_t asf_get_data_packets(asf_file_t *file); +LIBASF_API uint64_t asf_get_data_packets(asf_file_t *file); /* get play duration of the file in 100-nanosecond units, this value should be ignored for broadcasts */ -uint64_t asf_get_duration(asf_file_t *file); +LIBASF_API uint64_t asf_get_duration(asf_file_t *file); /* maximum bitrate as bits per second in the entire file */ -uint32_t asf_get_max_bitrate(asf_file_t *file); +LIBASF_API uint32_t asf_get_max_bitrate(asf_file_t *file); #endif Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asfint.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asfint.h 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/asfint.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,9 +19,29 @@ #ifndef ASFINT_H #define ASFINT_H +#include <string.h> + #include "asf.h" #include "guid.h" +#include "compat.h" +static INLINE void +GetGUID(const void *pointer, asf_guid_t *guid) +{ + const uint8_t *data = pointer; + guid->v1 = GetDWLE(data); + guid->v2 = GetWLE(data + 4); + guid->v3 = GetWLE(data + 6); + memcpy(guid->v4, data + 8, 8); +} + +#define GETLEN2b(bits) (((bits) == 0x03) ? 4 : bits) +#define GETVALUE2b(bits, data) \ + (((bits) != 0x03) ? ((bits) != 0x02) ? ((bits) != 0x01) ? \ + 0 : *((uint8_t *)data) : GetWLE(data) : GetDWLE(data)) + + + /* DO NOT MODIFY THE FIRST 3 VARIABLES, BECAUSE THEY ARE * ALSO DEFINED IN asf.h HEADER AND WILL BREAK THINGS */ #define ASF_OBJECT_COMMON \ Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.c 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.c 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,71 +17,12 @@ */ #include <string.h> + +#include "asfint.h" #include "byteio.h" -uint16_t -asf_byteio_getWLE(uint8_t *data) -{ - uint16_t ret; - int i; - - for (i=1, ret=0; i>=0; i--) { - ret <<= 8; - ret |= data[i]; - } - - return ret; -} - -uint32_t -asf_byteio_getDWLE(uint8_t *data) -{ - uint32_t ret; - int i; - - for (i=3, ret=0; i>=0; i--) { - ret <<= 8; - ret |= data[i]; - } - - return ret; -} - -uint64_t -asf_byteio_getQWLE(uint8_t *data) -{ - uint64_t ret; - int i; - - for (i=7, ret=0; i>=0; i--) { - ret <<= 8; - ret |= data[i]; - } - - return ret; -} - -void -asf_byteio_getGUID(asf_guid_t *guid, uint8_t *data) -{ - guid->v1 = asf_byteio_getDWLE(data); - guid->v2 = asf_byteio_getWLE(data + 4); - guid->v3 = asf_byteio_getWLE(data + 6); - memcpy(guid->v4, data + 8, 8); -} - -void -asf_byteio_get_string(uint16_t *string, uint16_t strlen, uint8_t *data) -{ - int i; - - for (i=0; i<strlen; i++) { - string[i] = asf_byteio_getWLE(data + i*2); - } -} - int -asf_byteio_read(uint8_t *data, int size, asf_iostream_t *iostream) +asf_byteio_read(asf_iostream_t *iostream, uint8_t *data, int size) { int read = 0, tmp; @@ -91,12 +32,14 @@ while ((tmp = iostream->read(iostream->opaque, data+read, size-read)) > 0) { read += tmp; - if (read == size) { return read; } } + /* FIXME: should return tmp if any bytes were read, but the + rest of the code needs to be fixed before that */ + return (tmp == 0) ? ASF_ERROR_EOF : ASF_ERROR_IO; } Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.h 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/byteio.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,12 +22,6 @@ #include "asf.h" #include "guid.h" -uint16_t asf_byteio_getWLE(uint8_t *data); -uint32_t asf_byteio_getDWLE(uint8_t *data); -uint64_t asf_byteio_getQWLE(uint8_t *data); -void asf_byteio_getGUID(asf_guid_t *guid, uint8_t *data); -void asf_byteio_get_string(uint16_t *string, uint16_t strlen, uint8_t *data); +int asf_byteio_read(asf_iostream_t *iostream, uint8_t *data, int size); -int asf_byteio_read(uint8_t *data, int size, asf_iostream_t *iostream); - #endif Added: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/compat.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/compat.h (rev 0) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/compat.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -0,0 +1,60 @@ +/* libasf - An Advanced Systems Format media file parser + * Copyright (C) 2006-2010 Juho Vähä-Herttua + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef __GNUC__ +# define INLINE __inline__ +#else +# define INLINE +#endif + +static INLINE uint16_t +GetWLE(const void *pointer) +{ + const uint8_t *data = pointer; + return ((uint16_t)data[1] << 8) | + ((uint16_t)data[0]); +} + +static INLINE uint32_t +GetDWLE(const void *pointer) +{ + const uint8_t *data = pointer; + return ((uint32_t)data[3] << 24) | + ((uint32_t)data[2] << 16) | + ((uint32_t)data[1] << 8) | + ((uint32_t)data[0]); +} + +static INLINE uint64_t +GetQWLE(const void *pointer) +{ + const uint8_t *data = pointer; + return ((uint64_t)data[7] << 56) | + ((uint64_t)data[6] << 48) | + ((uint64_t)data[5] << 40) | + ((uint64_t)data[4] << 32) | + ((uint64_t)data[3] << 24) | + ((uint64_t)data[2] << 16) | + ((uint64_t)data[1] << 8) | + ((uint64_t)data[0]); +} + +#endif Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.c 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.c 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,22 +19,15 @@ #include <stdlib.h> #include <string.h> -#include "asf.h" #include "asfint.h" #include "byteio.h" #include "data.h" #include "parse.h" #include "debug.h" -#define GETLEN2b(bits) (((bits) == 0x03) ? 4 : bits) - -#define GETVALUE2b(bits, data) \ - (((bits) != 0x03) ? ((bits) != 0x02) ? ((bits) != 0x01) ? \ - 0 : *(data) : asf_byteio_getWLE(data) : asf_byteio_getDWLE(data)) - static int -asf_data_read_packet_data(asf_packet_t *packet, uint8_t flags, - uint8_t *data, uint32_t len) +asf_data_read_packet_fields(asf_packet_t *packet, uint8_t flags, + uint8_t *data, uint32_t len) { uint8_t datalen; @@ -48,21 +41,20 @@ packet->length = GETVALUE2b((flags >> 5) & 0x03, data); data += GETLEN2b((flags >> 5) & 0x03); - /* sequence value should be never used anywhere */ - GETVALUE2b((flags >> 1) & 0x03, data); + packet->sequence = GETVALUE2b((flags >> 1) & 0x03, data); data += GETLEN2b((flags >> 1) & 0x03); packet->padding_length = GETVALUE2b((flags >> 3) & 0x03, data); data += GETLEN2b((flags >> 3) & 0x03); - packet->send_time = asf_byteio_getDWLE(data); + packet->send_time = GetDWLE(data); data += 4; - packet->duration = asf_byteio_getWLE(data); + packet->duration = GetWLE(data); data += 2; return datalen; } static int -asf_data_read_payload_data(asf_payload_t *payload, uint8_t flags, uint8_t *data, int size) +asf_data_read_payload_fields(asf_payload_t *payload, uint8_t flags, uint8_t *data, int size) { uint8_t datalen; @@ -88,24 +80,27 @@ asf_data_read_payloads(asf_packet_t *packet, uint64_t preroll, uint8_t multiple, - uint8_t type, uint8_t flags, uint8_t *data, uint32_t datalen) { asf_payload_t pl; - int i, tmp, skip; + uint32_t skip; + int i, tmp; skip = 0, i = 0; while (i < packet->payload_count) { uint8_t pts_delta = 0; int compressed = 0; + if (skip+1 > datalen) { + return ASF_ERROR_INVALID_LENGTH; + } pl.stream_number = data[skip] & 0x7f; pl.key_frame = !!(data[skip] & 0x80); skip++; - tmp = asf_data_read_payload_data(&pl, flags, data + skip, datalen - skip); + tmp = asf_data_read_payload_fields(&pl, flags, data + skip, datalen - skip); if (tmp < 0) { return tmp; } @@ -119,9 +114,9 @@ pl.replicated_data = data + skip; skip += pl.replicated_length; - pl.pts = asf_byteio_getDWLE(pl.replicated_data + 4); + pl.pts = GetDWLE(pl.replicated_data + 4); } else if (pl.replicated_length == 1) { - if (skip >= datalen) { + if (skip+1 > datalen) { /* not enough data */ return ASF_ERROR_INVALID_LENGTH; } @@ -142,29 +137,26 @@ } /* substract preroll value from pts since it's counted in */ - pl.pts -= preroll; - /* FIXME: check that pts is positive */ + if (pl.pts > preroll) { + pl.pts -= preroll; + } else { + pl.pts = 0; + } if (multiple) { - tmp = GETLEN2b(type); - - if (tmp != 2) { - /* in multiple payloads datalen should be a word */ - return ASF_ERROR_INVALID_VALUE; - } - if (skip + tmp > datalen) { + if (skip + 2 > datalen) { /* not enough data */ return ASF_ERROR_INVALID_LENGTH; } - - pl.datalen = GETVALUE2b(type, data + skip); - skip += tmp; + pl.datalen = GetWLE(data + skip); + skip += 2; } else { pl.datalen = datalen - skip; } if (compressed) { - int payloads, start = skip, used = 0; + uint32_t start = skip, used = 0; + int payloads, idx; /* count how many compressed payloads this payload includes */ for (payloads=0; used < pl.datalen; payloads++) { @@ -190,20 +182,22 @@ packet->payloads_size = packet->payload_count; } - while (skip < start + used) { + for (idx = 0; idx < payloads; idx++) { pl.datalen = data[skip]; skip++; + /* Set data correctly */ pl.data = data + skip; skip += pl.datalen; - pl.pts += pts_delta; + /* Copy the final payload and update the PTS */ memcpy(&packet->payloads[i], &pl, sizeof(asf_payload_t)); + packet->payloads[i].pts = pl.pts + idx * pts_delta; i++; debug_printf("payload(%d/%d) stream: %d, key frame: %d, object: %d, offset: %d, pts: %d, datalen: %d", i, packet->payload_count, pl.stream_number, (int) pl.key_frame, pl.media_object_number, - pl.media_object_offset, pl.pts, pl.datalen); + pl.media_object_offset, pl.pts + idx * pts_delta, pl.datalen); } } else { pl.data = data + skip; @@ -249,7 +243,7 @@ { asf_iostream_t *iostream; uint32_t read = 0; - int packet_flags, packet_property, payload_length_type; + int packet_flags, packet_property; void *tmpptr; int tmp; @@ -268,9 +262,7 @@ packet->data_size = file->packet_size; } - tmp = asf_byteio_read(packet->data, - file->packet_size, - iostream); + tmp = asf_byteio_read(iostream, packet->data, file->packet_size); if (tmp < 0) { /* Error reading packet data */ return tmp; @@ -298,6 +290,7 @@ read += packet->ec_length; } else { packet->ec_length = 0; + packet->ec_data = NULL; } if (read+2 > file->packet_size) { @@ -306,10 +299,9 @@ packet_flags = packet->data[read++]; packet_property = packet->data[read++]; - tmp = asf_data_read_packet_data(packet, - packet_flags, - &packet->data[read], - file->packet_size - read); + tmp = asf_data_read_packet_fields(packet, packet_flags, + packet->data + read, + file->packet_size - read); if (tmp < 0) { return tmp; } @@ -318,13 +310,13 @@ /* this is really idiotic, packet length can (and often will) be * undefined and we just have to use the header packet size as the size * value */ - if (!((packet_flags >> 5) & 0x03)) { + if (((packet_flags >> 5) & 0x03) == 0) { packet->length = file->packet_size; } /* this is also really idiotic, if packet length is smaller than packet * size, we need to manually add the additional bytes into padding length - */ + * because the padding bytes only count up to packet length value */ if (packet->length < file->packet_size) { packet->padding_length += file->packet_size - packet->length; packet->length = file->packet_size; @@ -337,6 +329,8 @@ /* check if we have multiple payloads */ if (packet_flags & 0x01) { + int payload_length_type; + if (read+1 > packet->length) { return ASF_ERROR_INVALID_LENGTH; } @@ -344,11 +338,19 @@ packet->payload_count = tmp & 0x3f; payload_length_type = (tmp >> 6) & 0x03; + + if (packet->payload_count == 0) { + /* there should always be at least one payload */ + return ASF_ERROR_INVALID_VALUE; + } + + if (payload_length_type != 0x02) { + /* in multiple payloads datalen should always be a word */ + return ASF_ERROR_INVALID_VALUE; + } } else { packet->payload_count = 1; - payload_length_type = 0x02; /* not used */ } - packet->payload_data_len = packet->length - read; if (packet->payload_count > packet->payloads_size) { @@ -363,11 +365,10 @@ packet->payload_data = &packet->data[read]; read += packet->payload_data_len; - + /* The return value will be consumed bytes, not including the padding */ tmp = asf_data_read_payloads(packet, file->preroll, packet_flags & 0x01, - payload_length_type, packet_property, - packet->payload_data, + packet_property, packet->payload_data, packet->payload_data_len - packet->padding_length); if (tmp < 0) { return tmp; Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.h 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/data.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser - * Copyright (C) 2006-2007 Juho Vähä-Herttua + * Copyright (C) 2006-2010 Juho Vähä-Herttua * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public Modified: haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/debug.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/debug.h 2010-07-03 06:11:39 UTC (rev 37362) +++ haiku/trunk/src/add-ons/media/plugins/asf_reader/libasf/debug.h 2010-07-03 06:12:56 UTC (rev 37363) @@ -1,5 +1,5 @@ /* libasf - An Advanced Systems Format media file parser [... truncated: 906 lines follow ...]