[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ./ChangeLog server/MovieClipLoader.cpp se...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ./ChangeLog server/MovieClipLoader.cpp se... |
Date: |
Tue, 16 May 2006 09:09:24 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: Sandro Santilli <address@hidden> 06/05/16 09:09:24
Modified files:
. : ChangeLog
server : MovieClipLoader.cpp gnash.h impl.cpp
Log message:
* server/MovieClipLoader.cpp, server/gnash.h,
server/impl.cpp: create_movie() split to
create_swf_movie() and create_jpeg_movie().
The former will call one of the latters based
on input stream magic number.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.330&tr2=1.331&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/MovieClipLoader.cpp.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/gnash.h.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/impl.cpp.diff?tr1=1.38&tr2=1.39&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.330 gnash/ChangeLog:1.331
--- gnash/ChangeLog:1.330 Tue May 16 08:22:00 2006
+++ gnash/ChangeLog Tue May 16 09:09:24 2006
@@ -1,5 +1,10 @@
2006-05-16 Sandro Santilli <address@hidden>
+ * server/MovieClipLoader.cpp, server/gnash.h,
+ server/impl.cpp: create_movie() split to
+ create_swf_movie() and create_jpeg_movie().
+ The former will call one of the latters based
+ on input stream magic number.
* server/MovieClipLoader.cpp: fixed relative url resolution
to use target's parent url, not target url.
* server/gnash.h, server/impl.cpp: changed definition
Index: gnash/server/MovieClipLoader.cpp
diff -u gnash/server/MovieClipLoader.cpp:1.20
gnash/server/MovieClipLoader.cpp:1.21
--- gnash/server/MovieClipLoader.cpp:1.20 Tue May 16 08:22:00 2006
+++ gnash/server/MovieClipLoader.cpp Tue May 16 09:09:24 2006
@@ -214,8 +214,6 @@
void moviecliploader_loadclip(const fn_call& fn)
{
as_value val, method;
- struct stat stats;
- int fd;
log_msg("%s: nargs = %d\n", __FUNCTION__, fn.nargs);
@@ -298,12 +296,6 @@
log_error("error in call_method(): method is not a
function\n");
}
}
-#if 0 // why would this be an error ?
- else
- {
- log_error("Couldn't find onLoadStart!\n");
- }
-#endif
// Call the callback since we've started loading the file
if (fn.this_ptr->get_member("onLoadStart", &method))
@@ -328,225 +320,74 @@
log_error("error in call_method(): method is not a
function\n");
}
}
-#if 0 // why would this be an error ?
- else
- {
- log_error("Couldn't find onLoadStart!\n");
- }
-#endif
-
std::string path = url.path();
std::string suffix = path.substr(path.size() - 4);
log_msg("File suffix to load is: %s\n", suffix.c_str());
- if (suffix == ".swf")
- {
- movie_definition* md = create_library_movie(url);
- if (md == NULL) {
- log_error("can't create movie_definition for %s\n",
- url.str().c_str());
- fn.result->set_bool(false);
- return;
- }
-
- log_msg("movie definition created\n");
-
- gnash::movie_interface* extern_movie;
- extern_movie = md->create_instance();
- if (extern_movie == NULL) {
- log_error("can't create extern movie_interface "
- "for %s\n", url.str().c_str());
- fn.result->set_bool(false);
- return;
- }
-
- log_msg("movie instance created\n");
-
- save_extern_movie(extern_movie);
-
- character* tar = (character*)target;
- const char* name = tar->get_name().c_str();
- uint16_t depth = tar->get_depth();
- bool use_cxform = false;
- cxform color_transform = tar->get_cxform();
- bool use_matrix = false;
- matrix mat = tar->get_matrix();
- float ratio = tar->get_ratio();
- uint16_t clip_depth = tar->get_clip_depth();
-
- //movie* parent = tar->get_parent();
- movie* new_movie =
static_cast<movie*>(extern_movie)->get_root_movie();
-
- assert(parent != NULL);
-
- ((character*)new_movie)->set_parent(parent);
-
- parent->replace_display_object(
- (character*) new_movie,
- name,
- depth,
- use_cxform,
- color_transform,
- use_matrix,
- mat,
- ratio,
- clip_depth);
+ movie_definition* md = create_library_movie(url);
+ if (md == NULL) {
+ log_error("can't create movie_definition for %s\n",
+ url.str().c_str());
+ fn.result->set_bool(false);
+ return;
}
- else if (suffix == ".jpg")
- {
-
- // FIXME: temporarly disabled
- log_msg("Loading of jpegs unsupported");
- fn.result->set_bool(false);
- return;
-
- // WRONG: we must open it and check if it's a jpeg.
- std::string filespec = url.path();
+ log_msg("movie definition created\n");
+ gnash::movie_interface* extern_movie;
+ extern_movie = md->create_instance();
+ if (extern_movie == NULL) {
+ log_error("can't create extern movie_interface "
+ "for %s\n", url.str().c_str());
+ fn.result->set_bool(false);
+ return;
+ }
- // Just case the filespec suffix claims it's a jpeg,
- // we have to check, since when grabbing an image from a
- // web server that doesn't exist, we don't get an error,
- // we get a short HTML page containing a 404.
- if ((fd=open(filespec.c_str(), O_RDONLY)) < 0)
- {
- log_error("can't open image!\n");
- fn.result->set_bool(false);
- return;
- }
+ log_msg("movie instance created\n");
- unsigned char buf[5];
- memset(buf, 0, 5);
- if (!read(fd, buf, 4))
- {
- log_error("Can't read image header!\n");
- fn.result->set_bool(false);
- return;
- }
-
- close(fd); // we don't need this anymore
+ save_extern_movie(extern_movie);
- // This is the magic number for any JPEG format file
- if ((buf[0] == 0xff) && (buf[1] == 0xd8) && (buf[2] != 0xff))
- {
- log_error("File is not a JPEG!\n");
- fn.result->set_bool(false);
- return;
- }
-
- //log_msg("File is a JPEG!\n");
-
-
- bitmap_info* bi = NULL;
- image::rgb* im = image::read_jpeg(filespec.c_str());
- if (im != NULL) {
- bi = render::create_bitmap_info_rgb(im);
- delete im;
- } else {
- log_error("Can't read jpeg: %s\n", filespec.c_str());
- }
-
- //bitmap_character* ch = new bitmap_character(bi);
-
- movie *mov = target->to_movie();
- //movie_definition *def = mov->get_movie_definition();
- //movie_definition *m = (movie_definition *)mov;
- //target->add_bitmap_info(bi);
-
- character* tar = (character*)mov;
- const char* name = tar->get_name().c_str();
- uint16_t id = tar->get_id();
- //log_msg("Target name is: %s, ID: %d\n", name, id);
-
- // FIXME: none of this works yet
-
- //movie_definition *md = create_library_movie(filespec.c_str());
- // add image to movie, under character id.
- //m->add_bitmap_character(666, ch);
-
- std::string swfm = filespec.substr(0, filespec.length() - 3);
- swfm += "swf";
-
- movie_definition *ms = create_movie(URL(swfm.c_str()));
- // The file may not exist.
- if (ms) {
- //movie_interface* extern_movie =
- // create_library_movie_inst(ms);
- //character * newchar =
- // ms->create_character_instance(tar->get_parent(),
- // id);
- }
-
- //save_extern_movie(extern_movie);
- //movie* new_movie =
static_cast<movie*>(extern_movie)->get_root_movie();
-
-// #else
-// movie_definition*ms;
-// ms->add_bitmap_info(bi);
-// #endif
- //movie* m = mov->get_root_movie();
- //set_current_root(extern_movie);
- //movie* m =
static_cast<movie*>(extern_movie)->get_root_movie();
- mov->on_event(event_id::LOAD);
- //add_display_object();
-
- //uint16_t depth = tar->get_depth();
- bool use_cxform = false;
- //cxform color_transform = tar->get_cxform();
- bool use_matrix = false;
- matrix mat = tar->get_matrix();
- //float ratio = tar->get_ratio();
- //uint16_t clip_depth = tar->get_clip_depth();
- std::vector<swf_event*> dummy_event_handlers;
- movie* parent = tar->get_parent();
-
- character *newch = new character(parent, id);
-
-#if 0
- parent->clone_display_object(name, "album_image", depth);
- parent->add_display_object((uint16_t)id,
- name,
- dummy_event_handlers,
- tar->get_depth(),
- true,
- tar->get_cxform(),
- tar->get_matrix(),
- tar->get_ratio(),
- tar->get_clip_depth());
-#endif // 0
-
- parent->replace_display_object(newch,
- name,
- tar->get_depth(),
- use_cxform,
- tar->get_cxform(),
- use_matrix,
- tar->get_matrix(),
- tar->get_ratio(),
- tar->get_clip_depth());
- }
+ character* tar = (character*)target;
+ const char* name = tar->get_name().c_str();
+ uint16_t depth = tar->get_depth();
+ bool use_cxform = false;
+ cxform color_transform = tar->get_cxform();
+ bool use_matrix = false;
+ matrix mat = tar->get_matrix();
+ float ratio = tar->get_ratio();
+ uint16_t clip_depth = tar->get_clip_depth();
+
+ movie* new_movie = static_cast<movie*>(extern_movie)->get_root_movie();
+
+ ((character*)new_movie)->set_parent(parent);
+
+ parent->replace_display_object(
+ (character*) new_movie,
+ name,
+ depth,
+ use_cxform,
+ color_transform,
+ use_matrix,
+ mat,
+ ratio,
+ clip_depth);
struct mcl *mcl_data = ptr->mov_obj.getProgress(target);
// the callback since we're done loading the file
// FIXME: these both probably shouldn't be set to the same value
- mcl_data->bytes_loaded = stats.st_size;
- mcl_data->bytes_total = stats.st_size;
+ //mcl_data->bytes_loaded = stats.st_size;
+ //mcl_data->bytes_total = stats.st_size;
+ mcl_data->bytes_loaded = 666; // fake values for now
+ mcl_data->bytes_total = 666;
fn.env->set_member("target_mc", target);
- //env->push(as_value(target));
- //moviecliploader_onload_complete(result, this_ptr, env, 0, 0);
moviecliploader_onload_complete(fn);
//env->pop();
fn.result->set_bool(true);
- //unlink(filespec.c_str());
-
- //xmlNanoHTTPCleanup();
-
}
void
Index: gnash/server/gnash.h
diff -u gnash/server/gnash.h:1.23 gnash/server/gnash.h:1.24
--- gnash/server/gnash.h:1.23 Tue May 16 08:05:13 2006
+++ gnash/server/gnash.h Tue May 16 09:09:24 2006
@@ -209,6 +209,8 @@
/// Create a gnash::movie_definition from the given URL.
//
+/// The URL can correspond to either a JPEG or SWF file.
+///
/// Normally, will also try to load any cached data file
/// (".gsc") that corresponds to the given movie file. This
/// will still work even if there is no cache file. You can
@@ -265,6 +267,8 @@
/// \brief
/// Create a gnash::movie_definition from the given URL
+//
+/// The URL can correspond to either a JPEG or SWF file.
///
/// This is just like create_movie(), except that it checks the
/// "library" to see if a movie of this name has already been
Index: gnash/server/impl.cpp
diff -u gnash/server/impl.cpp:1.38 gnash/server/impl.cpp:1.39
--- gnash/server/impl.cpp:1.38 Tue May 16 08:05:13 2006
+++ gnash/server/impl.cpp Tue May 16 09:09:24 2006
@@ -379,13 +379,87 @@
delete original_in;
}
-movie_definition* create_movie(const URL& url)
+// Create a movie_definition from a jpeg stream
+// NOTE: this method assumes this *is* a jpeg stream
+static movie_definition*
+create_jpeg_movie(tu_file* in, const char* url)
+{
+ // FIXME: temporarly disabled
+ log_msg("Loading of jpegs unsupported");
+ return NULL;
+
+
+ bitmap_info* bi = NULL;
+ image::rgb* im = image::read_jpeg(in);
+ if (im != NULL) {
+ bi = render::create_bitmap_info_rgb(im);
+ delete im;
+ } else {
+ log_error("Can't read jpeg\n");
+ return NULL;
+ }
+
+ // FIXME: create a movie_definition from a jpeg
+ //bitmap_character* ch = new bitmap_character(bi);
+
+}
+
+// Get type of file looking at first bytes
+// return 'jpeg', 'swf' or 'unknown'
+//
+static std::string
+get_file_type(tu_file* in)
+{
+ in->set_position(0);
+
+ unsigned char buf[5];
+ memset(buf, 0, 5);
+ if ( 4 < in->read_bytes(buf, 4) )
+ {
+ log_error("Can't read file header!\n");
+ return "unknown";
+ }
+
+ // This is the magic number for any JPEG format file
+ if ((buf[0] == 0xff) && (buf[1] == 0xd8) && (buf[2] == 0xff))
+ {
+ return "jpeg";
+ }
+
+ // This is for SWF (FWS or CWS)
+ if ( (buf[0] == 'F' || buf[0] == 'C') &&
+ (buf[1] == 'W') &&
+ (buf[2] == 'S') )
+ {
+ return "swf";
+ }
+
+ return "unknown";
+}
+
+// Create a movie_definition from an SWF stream
+// NOTE: this method assumes this *is* an SWF stream
+static movie_definition*
+create_swf_movie(tu_file* in, const char* url)
+{
+
+ in->set_position(0);
+
+ movie_def_impl* m = new movie_def_impl(DO_LOAD_BITMAPS,
+ DO_LOAD_FONT_SHAPES);
+ if ( ! m->read(in, url) ) return NULL;
+
+ return m;
+}
+
+movie_definition*
+create_movie(const URL& url)
{
const char* c_url = url.str().c_str();
- printf("%s: url is %s\n", __PRETTY_FUNCTION__, c_url);
+ printf("%s: url is %s\n", __PRETTY_FUNCTION__, c_url);
- if (s_opener_function == NULL)
+ if (s_opener_function == NULL)
{
// Don't even have a way to open the file.
log_error("error: no file opener function; can't create movie. "
@@ -393,54 +467,78 @@
return NULL;
}
- tu_file* in = s_opener_function(url);
- if (in == NULL)
+ tu_file* in = s_opener_function(url);
+ if (in == NULL)
{
log_error("failed to open '%s'; can't create movie.\n", c_url);
return NULL;
}
- else if (in->get_error())
+ else if (in->get_error())
{
log_error("error: file opener can't open '%s'\n", c_url);
return NULL;
}
- ensure_loaders_registered();
+ ensure_loaders_registered();
- movie_def_impl* m = new movie_def_impl(DO_LOAD_BITMAPS,
- DO_LOAD_FONT_SHAPES);
- if ( ! m->read(in, c_url) ) return NULL;
+ // see if it's a jpeg or an swf
+ std::string type = get_file_type(in);
- delete in;
+ movie_definition* ret = NULL;
- if (m && s_use_cache_files)
+ if ( type == "jpeg" )
+ {
+ ret = create_jpeg_movie(in, c_url);
+ }
+ else if ( type == "swf" )
+ {
+ ret = create_swf_movie(in, c_url);
+ }
+ else
+ {
+ log_error("unknown file type\n");
+ ret = NULL;
+ }
+
+ if ( ! ret )
+ {
+ delete in;
+ return NULL;
+ }
+
+ ret->add_ref();
+
+ if (s_use_cache_files)
{
// Try to load a .gsc file.
// WILL NOT WORK FOR NETWORK URLS, would need an hash
- tu_string cache_filename(c_url);
- cache_filename += ".gsc";
- //tu_file* cache_in = s_opener_function(cache_filename.c_str());
- tu_file* cache_in = new tu_file(cache_filename.c_str(), "rb");
- if (cache_in == NULL
- || cache_in->get_error() != TU_FILE_NO_ERROR)
+ tu_string cache_filename(c_url);
+ cache_filename += ".gsc";
+ tu_file* cache_in = new tu_file(cache_filename.c_str(), "rb");
+ if (cache_in == NULL
+ || cache_in->get_error() != TU_FILE_NO_ERROR)
{
- // Can't open cache file; don't sweat it.
- IF_VERBOSE_PARSE(log_msg("note: couldn't open cache file
'%s'\n", cache_filename.c_str()));
+ // Can't open cache file; don't sweat it.
+ IF_VERBOSE_PARSE(
+ log_msg("note: couldn't open cache file '%s'\n",
+ cache_filename.c_str())
+ );
- m->generate_font_bitmaps(); // can't read cache, so
generate font texture data.
+ // can't read cache, so generate font texture data.
+ ret->generate_font_bitmaps();
}
- else
+ else
{
- log_msg("Loading cache file %s",
cache_filename.c_str());
- // Load the cached data.
- m->input_cached_data(cache_in);
+ log_msg("Loading cache file %s",
+ cache_filename.c_str());
+ // Load the cached data.
+ ret->input_cached_data(cache_in);
}
- delete cache_in;
+ delete cache_in;
}
- m->add_ref();
- return m;
+ return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ./ChangeLog server/MovieClipLoader.cpp se...,
Sandro Santilli <=