Author: fejj
Date: 2008-01-23 15:48:55 -0500 (Wed, 23 Jan 2008)
New Revision: 93711
Modified:
trunk/moon/src/asf/ChangeLog
trunk/moon/src/asf/asf-test.cpp
trunk/moon/src/asf/asf.cpp
trunk/moon/src/asf/asf.h
Log:
2008-01-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
* asf-test.cpp (test_file): use a FileSource so that we can get
rid of ASFFileSource.
* asf.cpp|h: Get rid of ASFFileSource.
Modified: trunk/moon/src/asf/ChangeLog
===================================================================
--- trunk/moon/src/asf/ChangeLog 2008-01-23 20:41:12 UTC (rev 93710)
+++ trunk/moon/src/asf/ChangeLog 2008-01-23 20:48:55 UTC (rev 93711)
@@ -1,5 +1,12 @@
2008-01-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
+ * asf-test.cpp (test_file): use a FileSource so that we can get
+ rid of ASFFileSource.
+
+ * asf.cpp|h: Get rid of ASFFileSource.
+
+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).
Modified: trunk/moon/src/asf/asf-test.cpp
===================================================================
--- trunk/moon/src/asf/asf-test.cpp 2008-01-23 20:41:12 UTC (rev 93710)
+++ trunk/moon/src/asf/asf-test.cpp 2008-01-23 20:48:55 UTC (rev 93711)
@@ -17,93 +17,8 @@
#include "asf-test.h"
#include "asf.h"
-char*
-create_new_file_name (const char* prefix, const char* number_format, const
char* suffix);
-int
-main (int argc, char *argv [])
-{
- if (argc < 2) {
- printf ("ASF tester.\n");
- printf ("-test\n");
- printf (" -test:<filename>\n");
- printf ("-corrupt\n");
- printf (" -in:<filename>\n");
- printf (" -out:<filename>\n");
- printf (" -test:<filename>\n");
- printf (" -corruption:<number>\n");
- printf (" -replay\n");
- return 0;
- }
-
- char *in = NULL, *out = NULL, *log = NULL, *test = NULL;
- int corruption = 20000;
- bool replay = false;
- bool do_test = false, do_corrupt = false;
- int result = 1;
-
- for (int i = 1; i < argc; i++) {
- char* arg = argv [i];
-
- if (strcmp (arg, "-test") == 0) {
- do_test = true;
- } else if (strcmp (arg, "-corrupt") == 0) {
- do_corrupt = true;
- } else if (g_str_has_prefix (arg, "-in:")) { // required for
corrupt
- in = arg + 4;
- } else if (g_str_has_prefix (arg, "-out:")) { // for corrupt
- out = g_strdup (arg + 5);
- } else if (g_str_has_prefix (arg, "-log:")) { // for corrupt
- log = g_strdup (arg + 5);
- } else if (g_str_has_prefix (arg, "-test:")) { // required for
test (automatically tests)
- test = arg + 6;
- do_test = true;
- } else if (g_str_has_prefix (arg, "-corruption:")) { // for
corrupt (automatically corrupts)
- corruption = atoi (arg + 12);
- do_corrupt = true;
- } else if (g_str_has_prefix (arg, "-replay")) { // for corrupt
- replay = true;
- } else {
- fprintf (stderr, "Unknown option: %s\n", arg);
- return 1;
- }
- }
-
- if (do_corrupt) {
- if (out == NULL) {
- out = create_new_file_name (in, "%.3i", ".wmv");
- }
-
- if (log == NULL) {
- log = g_strdup_printf ("%s.log", out);
- }
-
- if (!corrupt_file (in, out, log, replay, corruption)) {
- goto cleanup;
- }
-
- if (test == NULL) {
- test = out;
- }
- }
-
- if (do_test && !test_file (test)) {
- goto cleanup;
- }
-
- result = 0;
-
-cleanup:
- g_free (out);
- g_free (log);
-
- out = NULL;
- log = NULL;
-
- return result;
-}
-
-char*
+static char*
create_new_file_name (const char* prefix, const char* number_format, const
char* suffix)
{
char* result = NULL;
@@ -125,7 +40,7 @@
return result;
}
-bool
+static bool
corrupt_file (const char* input_filename, const char* output_filename, const
char* log_filename, bool replay, double corruption)
{
printf ("corrupt_file (%s, %s, %s, %s, %f)\n", input_filename,
output_filename, log_filename, replay ? "true" : "false", corruption);
@@ -273,7 +188,7 @@
return result;
}
-bool
+static bool
test_file (const char* filename)
{
printf ("test_file (%s)\n", filename);
@@ -282,8 +197,15 @@
ASFParser* parser = NULL;
ASFPacket* packet = NULL;
ASFFrameReader* reader = NULL;
+ ASFSource *asf_src;
+ FileSource *fs;
- parser = new ASFParser (filename);
+ fs = new FileSource (NULL, filename);
+ fs->Initialize ();
+
+ asf_src = new ASFMediaSource (NULL, fs);
+
+ parser = new ASFParser (asf_src);
if (!parser->ReadHeader ()) {
printf ("test_file (%s): read header failed.\n", filename);
goto end;
@@ -325,3 +247,86 @@
}
+int
+main (int argc, char *argv [])
+{
+ if (argc < 2) {
+ printf ("ASF tester.\n");
+ printf ("-test\n");
+ printf (" -test:<filename>\n");
+ printf ("-corrupt\n");
+ printf (" -in:<filename>\n");
+ printf (" -out:<filename>\n");
+ printf (" -test:<filename>\n");
+ printf (" -corruption:<number>\n");
+ printf (" -replay\n");
+ return 0;
+ }
+
+ char *in = NULL, *out = NULL, *log = NULL, *test = NULL;
+ int corruption = 20000;
+ bool replay = false;
+ bool do_test = false, do_corrupt = false;
+ int result = 1;
+
+ for (int i = 1; i < argc; i++) {
+ char* arg = argv [i];
+
+ if (strcmp (arg, "-test") == 0) {
+ do_test = true;
+ } else if (strcmp (arg, "-corrupt") == 0) {
+ do_corrupt = true;
+ } else if (g_str_has_prefix (arg, "-in:")) { // required for
corrupt
+ in = arg + 4;
+ } else if (g_str_has_prefix (arg, "-out:")) { // for corrupt
+ out = g_strdup (arg + 5);
+ } else if (g_str_has_prefix (arg, "-log:")) { // for corrupt
+ log = g_strdup (arg + 5);
+ } else if (g_str_has_prefix (arg, "-test:")) { // required for
test (automatically tests)
+ test = arg + 6;
+ do_test = true;
+ } else if (g_str_has_prefix (arg, "-corruption:")) { // for
corrupt (automatically corrupts)
+ corruption = atoi (arg + 12);
+ do_corrupt = true;
+ } else if (g_str_has_prefix (arg, "-replay")) { // for corrupt
+ replay = true;
+ } else {
+ fprintf (stderr, "Unknown option: %s\n", arg);
+ return 1;
+ }
+ }
+
+ if (do_corrupt) {
+ if (out == NULL) {
+ out = create_new_file_name (in, "%.3i", ".wmv");
+ }
+
+ if (log == NULL) {
+ log = g_strdup_printf ("%s.log", out);
+ }
+
+ if (!corrupt_file (in, out, log, replay, corruption)) {
+ goto cleanup;
+ }
+
+ if (test == NULL) {
+ test = out;
+ }
+ }
+
+ if (do_test && !test_file (test)) {
+ goto cleanup;
+ }
+
+ result = 0;
+
+cleanup:
+ g_free (out);
+ g_free (log);
+
+ out = NULL;
+ log = NULL;
+
+ return result;
+}
+
Modified: trunk/moon/src/asf/asf.cpp
===================================================================
--- trunk/moon/src/asf/asf.cpp 2008-01-23 20:41:12 UTC (rev 93710)
+++ trunk/moon/src/asf/asf.cpp 2008-01-23 20:48:55 UTC (rev 93711)
@@ -55,13 +55,6 @@
ASFParser
*/
-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)
{
ASF_LOG ("ASFParser::ASFParser ('%p'), this: %p.\n", src, this);
@@ -560,70 +553,6 @@
/*
- ASFFileSource
-*/
-
-ASFFileSource::ASFFileSource (ASFParser *parser, const char *filename) :
ASFSource (parser)
-{
- this->filename = g_strdup (filename);
- fd = NULL;
-}
-
-ASFFileSource::~ASFFileSource ()
-{
- g_free (filename);
- if (fd)
- fclose (fd);
-}
-
-bool
-ASFFileSource::SeekInternal (int64_t offset, int mode)
-{
- if (fseek (fd, offset, mode) != 0) {
- 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;
- }
-
- return true;
-}
-
-bool
-ASFFileSource::ReadInternal (void *dest, uint32_t bytes)
-{
- size_t bytes_read;
-
- if (dest == NULL) {
- parser->AddError ("Out of memory.\n");
- return false;
- }
-
- if (!fd) {
- fd = fopen (filename, "rb");
- if (!fd) {
- parser->AddError (g_strdup_printf ("Could not open the
file '%s': %s.\n",
- filename, strerror
(errno)));
- return false;
- }
- }
-
- bytes_read = fread (dest, 1, bytes, fd);
-
- if (bytes_read != bytes) {
- if (ferror (fd) != 0) {
- parser->AddError (g_strdup_printf ("Could not read from
the file '%s': %s.\n", filename, strerror (errno)));
- } else if (feof (fd) != 0) {
- parser->AddError (g_strdup_printf ("Reached end of file
prematurely of the file '%s'.\n", filename));
- } else {
- parser->AddError (g_strdup_printf ("Unspecified error
while reading the file '%s'.\n", filename));
- }
- return false;
- }
-
- return true;
-}
-
-/*
ASFSource
*/
Modified: trunk/moon/src/asf/asf.h
===================================================================
--- trunk/moon/src/asf/asf.h 2008-01-23 20:41:12 UTC (rev 93710)
+++ trunk/moon/src/asf/asf.h 2008-01-23 20:48:55 UTC (rev 93711)
@@ -96,25 +96,6 @@
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);
- virtual ~ASFFileSource ();
-
- 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; }
-};
-
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.
@@ -247,8 +228,8 @@
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.
+ // The parser takes ownership of the source and will delete it when the
parser is deleted.
+ ASFParser (ASFSource *source);
virtual ~ASFParser ();
bool ReadHeader ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches