gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11376: Implement the AS interface o


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11376: Implement the AS interface of Microphone and Camera correctly. This
Date: Thu, 06 Aug 2009 13:35:27 +0200
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11376 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2009-08-06 13:35:27 +0200
message:
  Implement the AS interface of Microphone and Camera correctly. This
  does not change any of the Audio or Video input code, just the way the
  class works in ActionScript. It now passes all the actionscript.all tests
  and the swfdec properties tests.
  
  Test Camera properties better in our own tests.
  
  Run Camera and Microphone tests with ffmpeg again. There is only one
  media-handler-dependent test, and it can be handled individually.
  
  The classes.all/Microphone_as test fails 6 tests in Gnash, but fails 10
  in the Adobe player. It needs fixing...
  
  Add notes on implementation.
modified:
  libcore/asobj/Globals.cpp
  libcore/asobj/flash/media/Camera_as.cpp
  libcore/asobj/flash/media/Microphone_as.cpp
  testsuite/actionscript.all/Camera.as
  testsuite/actionscript.all/Makefile.am
  testsuite/actionscript.all/Microphone.as
  testsuite/swfdec/PASSING
=== modified file 'libcore/asobj/Globals.cpp'
--- a/libcore/asobj/Globals.cpp 2009-07-30 11:33:29 +0000
+++ b/libcore/asobj/Globals.cpp 2009-08-06 11:02:25 +0000
@@ -443,9 +443,9 @@
            NS_GLOBAL, 5))
         (N(video_class_init, NSV::CLASS_VIDEO, NSV::CLASS_OBJECT, NS_GLOBAL, 
6))
         (N(camera_class_init, NSV::CLASS_CAMERA, NSV::CLASS_OBJECT,
-           NS_GLOBAL, 6))
+           NS_GLOBAL, 5))
         (N(microphone_class_init, NSV::CLASS_MICROPHONE, NSV::CLASS_OBJECT,
-           NS_GLOBAL, 6))
+           NS_GLOBAL, 5))
         (N(sharedobject_class_init, NSV::CLASS_SHARED_OBJECT,
            NSV::CLASS_OBJECT, NS_GLOBAL, 5))
         (N(loadvars_class_init, NSV::CLASS_LOAD_VARS, NSV::CLASS_OBJECT,

=== modified file 'libcore/asobj/flash/media/Camera_as.cpp'
--- a/libcore/asobj/flash/media/Camera_as.cpp   2009-08-04 17:46:54 +0000
+++ b/libcore/asobj/flash/media/Camera_as.cpp   2009-08-06 11:00:20 +0000
@@ -46,6 +46,9 @@
 as_value camera_setmode(const fn_call& fn);
 as_value camera_setmotionlevel(const fn_call& fn);
 as_value camera_setquality(const fn_call& fn);
+as_value camera_setLoopback(const fn_call& fn);
+as_value camera_setCursor(const fn_call& fn);
+as_value camera_setKeyFrameInterval(const fn_call& fn);
 
 as_value camera_activitylevel(const fn_call& fn);
 as_value camera_bandwidth(const fn_call& fn);
@@ -62,25 +65,59 @@
 as_value camera_quality(const fn_call& fn);
 as_value camera_width(const fn_call& fn);
 
+
+void
+attachCameraStaticInterface(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+    
+    const int flags = 0;
+
+    // get() is a function with an Object() as prototype.
+    as_object* proto = gl->createObject(getObjectInterface());
+
+    // TODO: avoid the creative abuse of createClass.
+       o.init_member("get", gl->createClass(camera_get, proto), flags);
+
+    boost::intrusive_ptr<builtin_function> getset =
+        gl->createFunction(camera_names);
+    o.init_property("names", *getset, *getset);
+
+}
+
+void
+attachCameraAS3StaticInterface(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+    o.init_member("getCamera", gl->createFunction(camera_getCamera));
+}
+
 static void
 attachCameraInterface(as_object& o)
 {
     Global_as* gl = getGlobal(o);
-    boost::intrusive_ptr<builtin_function> getset;
     
-    o.init_member("get", gl->createFunction(camera_get));
-    o.init_member("getCamera", gl->createFunction(camera_getCamera));
     o.init_member("setMode", gl->createFunction(camera_setmode));
     o.init_member("setMotionLevel", gl->createFunction(camera_setmotionlevel));
     o.init_member("setQuality", gl->createFunction(camera_setquality));
-
+    o.init_member("setCursor", gl->createFunction(camera_setCursor));
+    o.init_member("setLoopback", gl->createFunction(camera_setLoopback));
+    o.init_member("setKeyFrameInterval",
+            gl->createFunction(camera_setKeyFrameInterval));
+
+}
+
+// Properties attached to the prototype when Camera.get() is called
+void
+attachCameraProperties(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+    boost::intrusive_ptr<builtin_function> getset;
 
     getset = gl->createFunction(camera_activitylevel);
     o.init_property("activityLevel", *getset, *getset);
     getset = gl->createFunction(camera_bandwidth);
     o.init_property("bandwidth", *getset, *getset);
-    getset = gl->createFunction(camera_currentFPS);
-    o.init_property("currentFPS", *getset, *getset);
     getset = gl->createFunction(camera_currentFps);
     o.init_property("currentFps", *getset, *getset);
     getset = gl->createFunction(camera_fps);
@@ -97,8 +134,6 @@
     o.init_property("muted", *getset, *getset);
     getset = gl->createFunction(camera_name);
     o.init_property("name", *getset, *getset);
-    getset = gl->createFunction(camera_names);
-    o.init_property("names", *getset, *getset);
     getset = gl->createFunction(camera_quality);
     o.init_property("quality", *getset, *getset);
     getset = gl->createFunction(camera_width);
@@ -128,11 +163,6 @@
         as_object(getCameraInterface())
     {}
 
-    // override from as_object ?
-    //const char* get_text_value() const { return "Camera"; }
-
-    // override from as_object ?
-    //double get_numeric_value() const { return 0; }
 };
 #endif
 
@@ -147,29 +177,39 @@
         as_object(getCameraInterface())
     {}
 
-    // override from as_object ?
-    //const char* get_text_value() const { return "Camera"; }
-
-    // override from as_object ?
-    //double get_numeric_value() const { return 0; }
 };
 #endif
 
-// AS2 ctor
+// AS2 static accessor.
 as_value
-camera_get(const fn_call& fn) {
-    boost::intrusive_ptr<as_object> obj = new camera_as_object;  
+camera_get(const fn_call& fn)
+{
+
+    // Properties are attached to the prototype when get() is called.
+    as_object* proto = getCameraInterface();
+
+    // This is an AS2-only function, so don't worry about VM version.
+    attachCameraProperties(*proto);
+
+    // TODO: this should return the same object when the same device is
+    // meant, not a new object each time. It will be necessary to query
+    // the MediaHandler for this, and possibly to store the as_objects
+    // somewhere.
+    boost::intrusive_ptr<as_object> obj = new camera_as_object; 
+     
 
     int numargs = fn.nargs;
     if (numargs > 0) {
-        log_debug("%s: the camera is automatically chosen from gnashrc", 
__FUNCTION__);
+        log_debug("%s: the camera is automatically chosen from gnashrc",
+                __FUNCTION__);
     }
     return as_value(obj.get()); // will keep alive
 }
 
-// AS3 ctor
+// AS3 static accessor.
 as_value
-camera_getCamera(const fn_call& fn) {
+camera_getCamera(const fn_call& fn)
+{
     boost::intrusive_ptr<as_object> obj = new camera_as_object;
     
     int numargs = fn.nargs;
@@ -180,7 +220,8 @@
 }
 
 as_value
-camera_setmode(const fn_call& fn) {
+camera_setmode(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
     
     int numargs = fn.nargs;
@@ -243,8 +284,10 @@
     
     return as_value();
 }
+
 as_value
-camera_setmotionlevel(const fn_call& fn) {
+camera_setmotionlevel(const fn_call& fn)
+{
     log_unimpl ("Camera::motionLevel can be set, but it's not implemented");
     boost::intrusive_ptr<camera_as_object> ptr = ensureType<camera_as_object>
         (fn.this_ptr);
@@ -292,8 +335,10 @@
     return as_value();
 }
 
+
 as_value
-camera_setquality(const fn_call& fn) {
+camera_setquality(const fn_call& fn)
+{
     log_unimpl ("Camera::quality can be set, but it's not implemented");
     boost::intrusive_ptr<camera_as_object> ptr = ensureType<camera_as_object>
         (fn.this_ptr);
@@ -333,8 +378,11 @@
     }
     return as_value();
 }
+
+
 as_value
-camera_activitylevel(const fn_call& fn) {
+camera_activitylevel(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -351,8 +399,10 @@
 
     return as_value();
 }
+
 as_value
-camera_bandwidth(const fn_call& fn) {
+camera_bandwidth(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -369,46 +419,50 @@
 
     return as_value();
 }
-//as3 capitalization
-as_value
-camera_currentFPS(const fn_call& fn) {
-    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
-
-    if ( fn.nargs == 0 ) // getter
-    {
-        return as_value(ptr->get_currentFPS());
-    }
-    else // setter
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Attempt to set currentFPS property of Camera"));
-        );
-    }
-
-    return as_value();
-}
-
-//as3 capitalization
-as_value
-camera_currentFps(const fn_call& fn) {
-    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
-
-    if ( fn.nargs == 0 ) // getter
-    {
-        return as_value(ptr->get_currentFPS());
-    }
-    else // setter
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Attempt to set currentFPS property of Camera"));
-        );
-    }
-
-    return as_value();
-}
-
-as_value
-camera_fps(const fn_call& fn) {
+
+//as3 capitalization
+as_value
+camera_currentFPS(const fn_call& fn)
+{
+    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
+
+    if ( fn.nargs == 0 ) // getter
+    {
+        return as_value(ptr->get_currentFPS());
+    }
+    else // setter
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+        log_aserror(_("Attempt to set currentFPS property of Camera"));
+        );
+    }
+
+    return as_value();
+}
+
+//as3 capitalization
+as_value
+camera_currentFps(const fn_call& fn)
+{
+    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
+
+    if ( fn.nargs == 0 ) // getter
+    {
+        return as_value(ptr->get_currentFPS());
+    }
+    else // setter
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+        log_aserror(_("Attempt to set currentFPS property of Camera"));
+        );
+    }
+
+    return as_value();
+}
+
+as_value
+camera_fps(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -426,7 +480,8 @@
 }
 
 as_value
-camera_height(const fn_call& fn) {
+camera_height(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -444,7 +499,8 @@
 }
 
 as_value
-camera_index(const fn_call& fn) {
+camera_index(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -462,7 +518,8 @@
 }
 
 as_value
-camera_motionLevel(const fn_call& fn) {
+camera_motionLevel(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -481,7 +538,8 @@
 }
 
 as_value
-camera_motionTimeout(const fn_call& fn) {
+camera_motionTimeout(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -519,7 +577,8 @@
 }
 
 as_value
-camera_name(const fn_call& fn) {
+camera_name(const fn_call& fn)
+{
     boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
@@ -537,41 +596,43 @@
 }
 
 as_value
-camera_names(const fn_call& fn) {
-    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
+camera_names(const fn_call& fn)
+{
+    if (fn.nargs) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("Attempt to set names property of Camera"));
+        );
+        return as_value();
+    }
+
+    // TODO: this is a static function, not a member function. Because there
+    // is no this pointer, it cannot use camera_as_object to get the
+    // names. It will have to query the MediaHandler directly (much of the
+    // rest of the code should do this too).
+    boost::intrusive_ptr<camera_as_object> ptr =
+        ensureType<camera_as_object>(fn.this_ptr);
     
     //transfer from vector to an array
     std::vector<std::string> vect;
     vect = ptr->get_names();
     
-    int size = vect.size();
+    const size_t size = vect.size();
     
     boost::intrusive_ptr<Array_as> data = new Array_as;
 
-    //std::string data[size];
-    int i;
-    for (i = 0; i < size; ++i) {
+    for (size_t i = 0; i < size; ++i) {
         data->push(vect[i]);
     }
     
-    if ( fn.nargs == 0 ) // getter
-    {
-        return as_value(data.get());
-    }
-    else // setter
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Attempt to set names property of Camera"));
-        );
-    }
-
-    return as_value();
+    return as_value(data.get());
 } 
 
 
 as_value
-camera_quality(const fn_call& fn) {
-    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
+camera_quality(const fn_call& fn)
+{
+    boost::intrusive_ptr<camera_as_object> ptr =
+        ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
     {
@@ -589,8 +650,38 @@
 }
 
 as_value
-camera_width(const fn_call& fn) {
-    boost::intrusive_ptr<camera_as_object> ptr = 
ensureType<camera_as_object>(fn.this_ptr);
+camera_new(const fn_call& fn)
+{
+    as_object* proto = getCameraInterface();
+    Global_as* gl = getGlobal(fn);
+    return gl->createObject(proto);
+}
+
+as_value
+camera_setLoopback(const fn_call&)
+{
+    LOG_ONCE(log_unimpl("Camera.setLoopback"));
+    return as_value();
+}
+
+as_value camera_setCursor(const fn_call&)
+{
+    LOG_ONCE(log_unimpl("Camera.setCursor"));
+    return as_value();
+}
+
+as_value
+camera_setKeyFrameInterval(const fn_call&)
+{
+    LOG_ONCE(log_unimpl("Camera.setKeyFrameInterval"));
+    return as_value();
+}
+
+as_value
+camera_width(const fn_call& fn)
+{
+    boost::intrusive_ptr<camera_as_object> ptr =
+        ensureType<camera_as_object>(fn.this_ptr);
 
     if ( fn.nargs == 0 ) // getter
     {
@@ -608,29 +699,29 @@
 
 
 // extern (used by Global.cpp)
-void camera_class_init(as_object& where, const ObjectURI& uri)
+void
+camera_class_init(as_object& where, const ObjectURI& uri)
 {
+
+    Global_as* gl = getGlobal(where);
+    
+    as_object* proto = getCameraInterface();
+    
     // This is going to be the global Camera "class"/"function"
-    static boost::intrusive_ptr<as_object> cl;
+    as_object* cl;
 
-    if ( cl == NULL )
-    {
-        VM& vm = getVM(where);
-        Global_as* gl = getGlobal(where);
-        
-        //for versions lower than 8, the ctor call was get(), for 9 and higher
-        //the ctor was getCamera()
-        if (isAS3(getVM(where))) {
-            cl = gl->createClass(&camera_getCamera, getCameraInterface());
-        } else {
-            cl = gl->createClass(&camera_get, getCameraInterface());
-        }
-        
-        attachCameraInterface(*cl);
+    //for versions lower than 8, the ctor call was get(), for 9 and higher
+    //the ctor was getCamera()
+    if (isAS3(getVM(where))) {
+        cl = gl->createClass(&camera_new, proto);
+        attachCameraAS3StaticInterface(*cl);
+    } else {
+        cl = gl->createClass(&camera_new, proto);
+        attachCameraStaticInterface(*cl);
     }
-
+    
     // Register _global.Camera
-    where.init_member(getName(uri), cl.get(), as_object::DefaultFlags,
+    where.init_member(getName(uri), cl, as_object::DefaultFlags,
             getNamespace(uri));
 
 }

=== modified file 'libcore/asobj/flash/media/Microphone_as.cpp'
--- a/libcore/asobj/flash/media/Microphone_as.cpp       2009-08-05 20:31:25 
+0000
+++ b/libcore/asobj/flash/media/Microphone_as.cpp       2009-08-06 11:35:27 
+0000
@@ -42,6 +42,7 @@
 
 namespace gnash {
 
+as_value microphone_new(const fn_call& fn);
 as_value microphone_get(const fn_call& fn);
 as_value microphone_getMicrophone(const fn_call& fn);
 as_value microphone_setgain(const fn_call& fn);
@@ -59,19 +60,43 @@
 as_value microphone_silenceTimeout(const fn_call& fn);
 as_value microphone_useEchoSuppression(const fn_call& fn);
 
-static void
-attachMicrophoneInterface(as_object& o)
-{
-    Global_as* gl = getGlobal(o);
+
+// get() and names are static properties in AS2.
+void
+attachMicrophoneStaticInterface(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+
+    const int flags = 0;
+
+    // get() is a function with an Object() as prototype.
+    as_object* proto = gl->createObject(getObjectInterface());
+
+    // TODO: avoid the creative abuse of createClass.
+       o.init_member("get", gl->createClass(microphone_get, proto), flags);
+
+    boost::intrusive_ptr<builtin_function> getset =
+        gl->createFunction(microphone_names);
+    o.init_property("names", *getset, *getset);
+}
+
+// getMicrophone is a static property in AS3.
+void
+attachMicrophoneAS3StaticInterface(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+
+    o.init_member("getMicrophone",
+            gl->createFunction(microphone_getMicrophone));
+}
+
+// These are added to the AS2 prototype when get() is called.
+void
+attachMicrophoneProperties(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+
     boost::intrusive_ptr<builtin_function> getset;
-
-       o.init_member("get", gl->createFunction(microphone_get));
-    o.init_member("getMicrophone", 
gl->createFunction(microphone_getMicrophone));
-       o.init_member("setGain", gl->createFunction(microphone_setgain));
-       o.init_member("setRate", gl->createFunction(microphone_setrate));
-       o.init_member("setSilenceLevel", 
gl->createFunction(microphone_setsilencelevel));
-       o.init_member("setUseEchoSuppression", 
gl->createFunction(microphone_setuseechosuppression));
-    
     getset = gl->createFunction(microphone_activityLevel);
     o.init_property("activityLevel", *getset, *getset);
     getset = gl->createFunction(microphone_gain);
@@ -82,18 +107,30 @@
     o.init_property("muted", *getset, *getset);
     getset = gl->createFunction(microphone_name);
     o.init_property("name", *getset, *getset);
-    getset = gl->createFunction(microphone_names);
-    o.init_property("names", *getset, *getset);
     getset = gl->createFunction(microphone_rate);
     o.init_property("rate", *getset, *getset);
     getset = gl->createFunction(microphone_silenceLevel);
     o.init_property("silenceLevel", *getset, *getset);
     getset = gl->createFunction(microphone_silenceTimeout);
-    o.init_property("silenceTimeOut", *getset, *getset);
+    o.init_property("silenceTimeout", *getset, *getset);
     getset = gl->createFunction(microphone_useEchoSuppression);
     o.init_property("useEchoSuppression", *getset, *getset);
 }
 
+static void
+attachMicrophoneInterface(as_object& o)
+{
+    Global_as* gl = getGlobal(o);
+
+       o.init_member("setGain", gl->createFunction(microphone_setgain));
+       o.init_member("setRate", gl->createFunction(microphone_setrate));
+       o.init_member("setSilenceLevel",
+            gl->createFunction(microphone_setsilencelevel));
+       o.init_member("setUseEchoSuppression",
+            gl->createFunction(microphone_setuseechosuppression));
+    
+}
+
 static as_object*
 getMicrophoneInterface()
 {
@@ -115,13 +152,10 @@
        microphone_as_object()
                :
                as_object(getMicrophoneInterface())
-       {}
-
-       // override from as_object ?
-       //std::string get_text_value() const { return "Microphone"; }
-
-       // override from as_object ?
-       //double get_numeric_value() const { return 0; }
+       {
+        attachMicrophoneProperties(*get_prototype());
+    }
+
 };
 #endif
 
@@ -134,31 +168,45 @@
        microphone_as_object()
                :
                as_object(getMicrophoneInterface())
-       {}
-
-       // override from as_object ?
-       //std::string get_text_value() const { return "Microphone"; }
-
-       // override from as_object ?
-       //double get_numeric_value() const { return 0; }
+       {
+        attachMicrophoneProperties(*get_prototype());
+    }
+
 };
 #endif
 
-//as2 ctor
-as_value
-microphone_get(const fn_call& fn) {
+// There is a constructor for Microphone that returns an object with
+// the correct properties, but it is not usable.
+as_value
+microphone_new(const fn_call& fn)
+{
+    Global_as* gl = getGlobal(fn);
+    as_object* proto = getMicrophoneInterface();
+    return gl->createObject(proto);
+}
+
+// AS2 static accessor.
+as_value
+microphone_get(const fn_call& fn)
+{
+
+    // TODO: this should return the *same* object when the same device
+    // is returned, not a new object.
+    // TODO: check what the function returns when there is no microphone.
     boost::intrusive_ptr<as_object> obj = new microphone_as_object;
     
     int numargs = fn.nargs;
     if (numargs > 0) {
-        log_debug("%s: the mic is automatically chosen from gnashrc", 
__FUNCTION__);
+        log_debug("%s: the mic is automatically chosen from gnashrc",
+                __FUNCTION__);
     }
     return as_value(obj.get()); //will keep alive
 }
 
-//as3 ctor
+// AS3 static accessor.
 as_value
-microphone_getMicrophone(const fn_call& fn) {
+microphone_getMicrophone(const fn_call& fn)
+{
     boost::intrusive_ptr<as_object> obj = new microphone_as_object;
     
     int numargs = fn.nargs;
@@ -170,7 +218,8 @@
 
 
 as_value 
-microphone_setgain(const fn_call& fn) {
+microphone_setgain(const fn_call& fn)
+{
     boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
         (fn.this_ptr);
     
@@ -181,16 +230,19 @@
         const int32_t argument = fn.arg(0).to_int();
         if (argument >= 0 && argument <= 100) { 
 #ifdef USE_GST
-            //gstreamer's gain values can be between -60 and 60, whereas 
actionscript
-            //uses values between 0 and 100. this conversion is made here and 
the proper
-            //value is passed to gstreamer. so, plug the argument into this 
equation
-            //and then send the new value for use with gstreamer
+            // gstreamer's gain values can be between -60 and 60,
+            // whereas actionscript uses values between 0 and 100.
+            // this conversion is made here and the proper
+            // value is passed to gstreamer. so, plug the argument
+            // into this equation
+            // and then send the new value for use with gstreamer
             ptr->set_gain((argument - 50) * 1.2);
             ptr->audioChangeSourceBin(ptr->getGlobalAudio());
 #endif
 #ifdef USE_FFMPEG
-            //haven't yet implemented FFMPEG support for this, so we might 
need to do
-            //a conversion similar to the one above for Gstreamer
+            // haven't yet implemented FFMPEG support for this, so we
+            // might need to do a conversion similar to the one above
+            // for Gstreamer
             ptr->set_gain(argument);
 #endif
         } else {
@@ -208,7 +260,8 @@
 
 
 as_value
-microphone_setrate(const fn_call& fn) {
+microphone_setrate(const fn_call& fn)
+{
     boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
         (fn.this_ptr);
     
@@ -269,8 +322,8 @@
         return as_value(gain);
     }
 #endif
-        log_unimpl("FFMPEG not implemented");
-        return as_value();
+        log_unimpl("FFMPEG not implemented. Returning a number");
+        return as_value(0.0);
     }
     else // setter
     {
@@ -302,9 +355,10 @@
 }
 
 as_value
-microphone_muted(const fn_call& fn) {
-    boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
-        (fn.this_ptr);
+microphone_muted(const fn_call& fn)
+{
+    boost::intrusive_ptr<microphone_as_object> ptr =
+        ensureType<microphone_as_object>(fn.this_ptr);
         
     if ( fn.nargs == 0 ) // getter
     {
@@ -321,10 +375,9 @@
     return as_value();
 }
 
-//i don't know why this is throwing errors, i believe my code is correct, but
-//for some reason it can't get the intrusive this_ptr...
 as_value
-microphone_name(const fn_call& fn) {
+microphone_name(const fn_call& fn)
+{
     log_unimpl("Microphone::names: There's some problem with this function");
     boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
         (fn.this_ptr);
@@ -345,20 +398,24 @@
 
 
 as_value
-microphone_names(const fn_call& fn) {
-    boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
-        (fn.this_ptr);
+microphone_names(const fn_call& fn)
+{
+    // TODO: this is a static function, not a member function. Because there
+    // is no this pointer, it cannot use microphone_as_object to get the
+    // names. It will have to query the MediaHandler directly (much of the
+    // rest of the code should do this too).
+    boost::intrusive_ptr<microphone_as_object> ptr =
+        ensureType<microphone_as_object>(fn.this_ptr);
     
     //transfer from internal vector to AS array
     std::vector<std::string> vect;
     vect = ptr->get_names();
     
-    int size = vect.size();
+    size_t size = vect.size();
     
     boost::intrusive_ptr<Array_as> data = new Array_as;
     
-    int i;
-    for (i=0; i < size; ++i) {
+    for (size_t i=0; i < size; ++i) {
         data->push(vect[i]);
     }
         
@@ -378,7 +435,8 @@
 
 
 as_value
-microphone_rate(const fn_call& fn) {
+microphone_rate(const fn_call& fn)
+{
     boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
         (fn.this_ptr);
         
@@ -417,9 +475,10 @@
 }
 
 as_value
-microphone_silenceTimeout(const fn_call& fn) {
-    boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
-        (fn.this_ptr);
+microphone_silenceTimeout(const fn_call& fn)
+{
+    boost::intrusive_ptr<microphone_as_object> ptr =
+        ensureType<microphone_as_object>(fn.this_ptr);
         
     if ( fn.nargs == 0 ) // getter
     {
@@ -436,15 +495,19 @@
     return as_value();
 }
 
+// This is documented to return a Boolean (which would be sensible), but in
+// fact returns a Number.
 as_value
-microphone_useEchoSuppression(const fn_call& fn) {
-    boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
-        (fn.this_ptr);
+microphone_useEchoSuppression(const fn_call& fn)
+{
+    boost::intrusive_ptr<microphone_as_object> ptr =
+        ensureType<microphone_as_object>(fn.this_ptr);
         
     if ( fn.nargs == 0 ) // getter
     {
-        log_unimpl("Microphone::useEchoSuppression can be set, but is 
unimplemented");
-        return as_value(ptr->get_useEchoSuppression());
+        log_unimpl("Microphone::useEchoSuppression can be set, but is "
+                "unimplemented");
+        return as_value(static_cast<double>(ptr->get_useEchoSuppression()));
     }
     else // setter
     {
@@ -495,7 +558,8 @@
 }
 
 as_value 
-microphone_setuseechosuppression(const fn_call& fn) {
+microphone_setuseechosuppression(const fn_call& fn)
+{
     log_unimpl ("Microphone::setUseEchoSuppression can be set, but it's not 
implemented");
     boost::intrusive_ptr<microphone_as_object> ptr = 
ensureType<microphone_as_object>
         (fn.this_ptr);
@@ -510,29 +574,25 @@
 }
 
 // extern (used by Global.cpp)
-void microphone_class_init(as_object& where, const ObjectURI& uri)
+void
+microphone_class_init(as_object& where, const ObjectURI& uri)
 {
-       // This is going to be the global Microphone "class"/"function"
-       static boost::intrusive_ptr<as_object> cl;
-
-       if ( cl == NULL )
-       {
-        Global_as* gl = getGlobal(where);
-        as_object* proto = getMicrophoneInterface();
-        
-        if (isAS3(getVM(where))) {
-            cl = gl->createClass(&microphone_getMicrophone, proto);
-        } else {
-            cl = gl->createClass(&microphone_get, proto);
-        }
-        
-        // replicate all interface to class, to be able to access
-               // all methods as static functions
-               attachMicrophoneInterface(*cl);
-       }
-
+
+    Global_as* gl = getGlobal(where);
+    
+    as_object* proto = getMicrophoneInterface();
+    as_object* cl;
+
+    if (isAS3(getVM(where))) {
+        cl = gl->createClass(microphone_new, proto);
+        attachMicrophoneAS3StaticInterface(*cl);
+    } else {
+        cl = gl->createClass(microphone_new, proto);
+        attachMicrophoneStaticInterface(*cl);
+    }
+        
        // Register _global.Microphone
-       where.init_member(getName(uri), cl.get(), as_object::DefaultFlags,
+       where.init_member(getName(uri), cl, as_object::DefaultFlags,
             getNamespace(uri));
 
 }

=== modified file 'testsuite/actionscript.all/Camera.as'
--- a/testsuite/actionscript.all/Camera.as      2009-08-06 08:38:19 +0000
+++ b/testsuite/actionscript.all/Camera.as      2009-08-06 11:35:27 +0000
@@ -26,7 +26,7 @@
 
 #if OUTPUT_VERSION < 6
 
-xcheck_equals(typeof(Camera), 'function');
+check_equals(typeof(Camera), 'function');
 
 #else // OUTPUT_VERSION >= 6
 
@@ -42,27 +42,76 @@
 check(cameraObj != cameraObj2);
 check_equals(typeof(cameraObj), 'object');
 
+// These properties are never present before Camera.get() is called.
+check(!Camera.prototype.hasOwnProperty("activityLevel"));
+check(!Camera.prototype.hasOwnProperty("bandwidth"));
+check(!Camera.prototype.hasOwnProperty("currentFps"));
+check(!Camera.prototype.hasOwnProperty("fps"));
+check(!Camera.prototype.hasOwnProperty("height"));
+check(!Camera.prototype.hasOwnProperty("index"));
+check(!Camera.prototype.hasOwnProperty("width"));
+check(!Camera.prototype.hasOwnProperty("motionLevel"));
+check(!Camera.prototype.hasOwnProperty("motionTimeout"));
+check(!Camera.prototype.hasOwnProperty("muted"));
+check(!Camera.prototype.hasOwnProperty("name"));
+check(!Camera.prototype.hasOwnProperty("quality"));
+
+
 // The .get() method is a class method, not exported
 // to instances.
 check(Camera.get);
-xcheck_equals(cameraObj.get, undefined); 
-
-trace("Camera.get() returns: "+Camera.get());
+check_equals(cameraObj.get, undefined); 
+
+var cam = Camera.get();
+
+trace("Camera.get() returns: " + cam);
+
+// Static properties
+check(!Camera.prototype.hasOwnProperty("names"));
+check(!Camera.prototype.hasOwnProperty("get"));
+
+// These properties are added to the prototype if a camera is present
+// after get is called.
+if (cam) {
+    check(Camera.prototype.hasOwnProperty("activityLevel"));
+    check(Camera.prototype.hasOwnProperty("bandwidth"));
+    check(Camera.prototype.hasOwnProperty("currentFps"));
+    check(Camera.prototype.hasOwnProperty("fps"));
+    check(Camera.prototype.hasOwnProperty("height"));
+    check(Camera.prototype.hasOwnProperty("index"));
+    check(Camera.prototype.hasOwnProperty("width"));
+    check(Camera.prototype.hasOwnProperty("motionLevel"));
+    check(Camera.prototype.hasOwnProperty("motionTimeout"));
+    check(Camera.prototype.hasOwnProperty("muted"));
+    check(Camera.prototype.hasOwnProperty("name"));
+    check(Camera.prototype.hasOwnProperty("quality"));
+}
+else {
+    check(!Camera.prototype.hasOwnProperty("activityLevel"));
+    check(!Camera.prototype.hasOwnProperty("bandwidth"));
+    check(!Camera.prototype.hasOwnProperty("currentFps"));
+    check(!Camera.prototype.hasOwnProperty("fps"));
+    check(!Camera.prototype.hasOwnProperty("height"));
+    check(!Camera.prototype.hasOwnProperty("index"));
+    check(!Camera.prototype.hasOwnProperty("width"));
+    check(!Camera.prototype.hasOwnProperty("motionLevel"));
+    check(!Camera.prototype.hasOwnProperty("motionTimeout"));
+    check(!Camera.prototype.hasOwnProperty("muted"));
+    check(!Camera.prototype.hasOwnProperty("name"));
+    check(!Camera.prototype.hasOwnProperty("quality"));
+}
 
 // test that the methods do not exist in the class
-xcheck_equals(Camera.setmode, undefined);
-xcheck_equals(Camera.setmotionlevel, undefined);
-xcheck_equals(Camera.setquality, undefined);
+check_equals(Camera.setMode, undefined);
+check_equals(Camera.setMotionLevel, undefined);
+check_equals(Camera.setQuality, undefined);
 
-#if OUTPUT_VERSION < 7
-check (cameraObj.setmode); 
-check (cameraObj.setmotionlevel);
-check (cameraObj.setquality);
-#else
-xcheck_equals (cameraObj.setmode, undefined); 
-xcheck_equals (cameraObj.setmotionlevel, undefined);
-xcheck_equals (cameraObj.setquality, undefined);
-#endif
+check(cameraObj.setMode); 
+check(cameraObj.setMotionLevel);
+check(cameraObj.setQuality);
+check_equals(typeof(cameraObj.setMode), "function");
+check_equals(typeof(cameraObj.setMotionLevel), "function");
+check_equals(typeof(cameraObj.setQuality), "function");
 
 #endif // OUTPUT_VERSION >= 6
 totals();

=== modified file 'testsuite/actionscript.all/Makefile.am'
--- a/testsuite/actionscript.all/Makefile.am    2009-08-05 20:51:03 +0000
+++ b/testsuite/actionscript.all/Makefile.am    2009-08-06 11:35:27 +0000
@@ -28,7 +28,6 @@
 swfdir = `cd $(top_builddir)/testsuite/actionscript.all; pwd`
 DEF_MAKESWF_FLAGS=-DMING_VERSION_CODE=$(MING_VERSION_CODE) 
-DMEDIADIR='\"$(abs_mediadir)\"' -DSWFDIR='\"$(swfdir)\"'
 
-
 quickcheck_RUNNERS = \
        alltests-v5-Runner \
        alltests-v6-Runner \
@@ -82,6 +81,7 @@
        setProperty.as          \
        targetPath.as           \
        Boolean.as              \
+       Camera.as               \
        Color.as                \
        ColorTransform.as       \
        ContextMenu.as          \
@@ -98,6 +98,7 @@
        Key.as                  \
        LoadVars.as             \
        Math.as                 \
+       Microphone.as           \
        Mouse.as                \
        MovieClip.as            \
        MovieClipLoader.as      \
@@ -134,12 +135,6 @@
        Rectangle.as            \
        $(NULL)
 
-if USE_GST_ENGINE
-ASTESTS += \
-       Camera.as \
-       Microphone.as
-endif
-
 if HAVE_PERL
 if ENABLE_HAXE
 HAXETESTS = \

=== modified file 'testsuite/actionscript.all/Microphone.as'
--- a/testsuite/actionscript.all/Microphone.as  2009-08-06 08:38:19 +0000
+++ b/testsuite/actionscript.all/Microphone.as  2009-08-06 11:35:27 +0000
@@ -41,7 +41,7 @@
 check(Microphone.prototype.hasOwnProperty("setUseEchoSuppression"));
 
 // These aren't present yet.
-xcheck(!Microphone.prototype.hasOwnProperty("get"));
+check(!Microphone.prototype.hasOwnProperty("get"));
 check(!Microphone.prototype.hasOwnProperty("activityLevel"));
 check(!Microphone.prototype.hasOwnProperty("gain"));
 check(!Microphone.prototype.hasOwnProperty("index"));
@@ -65,7 +65,7 @@
 check_equals(typeof(f.rate), 'undefined')
 
 // Still not present
-xcheck(!Microphone.prototype.hasOwnProperty("get"));
+check(!Microphone.prototype.hasOwnProperty("get"));
 check(!Microphone.prototype.hasOwnProperty("activityLevel"));
 check(!Microphone.prototype.hasOwnProperty("gain"));
 check(!Microphone.prototype.hasOwnProperty("index"));
@@ -80,72 +80,76 @@
 check(!Microphone.prototype.hasOwnProperty("useEchoSuppression"));
 
 // Documented to be an array.
-xcheck ( Microphone.hasOwnProperty("names"));
+check ( Microphone.hasOwnProperty("names"));
 xcheck_equals (typeof (Microphone.names), 'object');
 
 // test the Microphone constuctor
 var microphoneObj = Microphone.get();
-xcheck_equals (typeof(microphoneObj), 'object');
+check_equals (typeof(microphoneObj), 'object');
 
 // Microphone.get() adds these properties.
 // Other properties are probably dependent on whether a microphone
 // is present or not.
-xcheck(!Microphone.prototype.hasOwnProperty("get"));
-xcheck(Microphone.prototype.hasOwnProperty("activityLevel"));
-xcheck(Microphone.prototype.hasOwnProperty("gain"));
-xcheck(Microphone.prototype.hasOwnProperty("index"));
-xcheck(Microphone.prototype.hasOwnProperty("muted"));
-xcheck(Microphone.prototype.hasOwnProperty("name"));
-xcheck(Microphone.prototype.hasOwnProperty("rate"));
-xcheck(Microphone.prototype.hasOwnProperty("silenceLevel"));
-xcheck(Microphone.prototype.hasOwnProperty("useEchoSuppression"));
+check(!Microphone.prototype.hasOwnProperty("get"));
+check(Microphone.prototype.hasOwnProperty("activityLevel"));
+check(Microphone.prototype.hasOwnProperty("gain"));
+check(Microphone.prototype.hasOwnProperty("index"));
+check(Microphone.prototype.hasOwnProperty("muted"));
+check(Microphone.prototype.hasOwnProperty("name"));
+check(Microphone.prototype.hasOwnProperty("rate"));
+check(Microphone.prototype.hasOwnProperty("silenceLevel"));
+check(Microphone.prototype.hasOwnProperty("useEchoSuppression"));
 
-// test that Microphone.get() returns a singleton
-check_equals(microphoneObj, Microphone.get());
+// test that Microphone.get() returns the same object.
+xcheck_equals(microphoneObj, Microphone.get());
 
 // test that get() method is NOT exported to instances
 check_equals (typeof(microphoneObj.get), 'undefined');
 
 // test the Microphone::setGain method
-xcheck_equals ( typeof(microphoneObj.setGain), 'function' );
+check_equals ( typeof(microphoneObj.setGain), 'function' );
 
 // test the Microphone::setRate method
-xcheck_equals ( typeof(microphoneObj.setRate), 'function' );
+check_equals ( typeof(microphoneObj.setRate), 'function' );
 
 // test the Microphone::setSilenceLevel method
-xcheck_equals ( typeof(microphoneObj.setSilenceLevel), 'function' );
+check_equals ( typeof(microphoneObj.setSilenceLevel), 'function' );
 
 // test the Microphone::setUseEchoSuppression method
-xcheck_equals ( typeof(microphoneObj.setUseEchoSuppression), 'function' );
+check_equals ( typeof(microphoneObj.setUseEchoSuppression), 'function' );
 
 /// Microphone properties
 
-xcheck_equals ( typeof(microphoneObj.activityLevel), 'number' );
-xcheck_equals ( typeof(microphoneObj.gain), 'number' );
-xcheck_equals ( typeof(microphoneObj.index), 'number' );
-xcheck_equals ( typeof(microphoneObj.muted), 'boolean' );
-xcheck_equals ( typeof(microphoneObj.name), 'string' );
-xcheck_equals ( typeof(microphoneObj.rate), 'number' );
-xcheck_equals ( typeof(microphoneObj.silenceTimeout), 'number' );
+check_equals ( typeof(microphoneObj.activityLevel), 'number' );
+check_equals ( typeof(microphoneObj.gain), 'number' );
+check_equals ( typeof(microphoneObj.index), 'number' );
+check_equals ( typeof(microphoneObj.muted), 'boolean' );
+check_equals ( typeof(microphoneObj.name), 'string' );
+check_equals ( typeof(microphoneObj.rate), 'number' );
+check_equals ( typeof(microphoneObj.silenceTimeout), 'number' );
 // Documented to be boolean
-xcheck_equals ( typeof(microphoneObj.useEchoSuppression), 'number' );
+check_equals ( typeof(microphoneObj.useEchoSuppression), 'number' );
 
 // Starting values // values before microphone is activated
-xcheck_equals ( microphoneObj.activityLevel, -1 );
+check_equals ( microphoneObj.activityLevel, -1 );
 xcheck_equals ( microphoneObj.gain, 50 );
-xcheck_equals ( microphoneObj.index, 0 );
+check_equals ( microphoneObj.index, 0 );
 xcheck_equals ( microphoneObj.muted, true );
-xcheck_equals ( microphoneObj.rate, 8 );
-xcheck_equals ( microphoneObj.silenceTimeout, 2000 );
+check_equals ( microphoneObj.rate, 8 );
+check_equals ( microphoneObj.silenceTimeout, 2000 );
 
 
 // Setting and getting
 
+// This only currently works with GST. It would be trivial to implement
+// a simple ffmpeg AudioInput class.
+#if USE_GST
 microphoneObj.setGain(5);
-xcheck_equals (microphoneObj.gain, 5);
+check_equals (microphoneObj.gain, 5);
+#endif
 
 microphoneObj.setSilenceLevel(16);
-xcheck_equals (microphoneObj.silenceLevel, 16);
+check_equals (microphoneObj.silenceLevel, 16);
 
 
 // 5, 8, 11, 22, or 44 documented...
@@ -154,7 +158,7 @@
 microphoneObj.setRate(7);
 xcheck_equals (microphoneObj.rate, 8);
 microphoneObj.setRate(10);
-xcheck_equals (microphoneObj.rate, 11);
+check_equals (microphoneObj.rate, 11);
 microphoneObj.setRate(15);
 xcheck_equals (microphoneObj.rate, 16);
 microphoneObj.setRate(17);
@@ -169,10 +173,10 @@
 
 /// It's still a number, though.
 microphoneObj.setUseEchoSuppression(false);
-xcheck_equals (microphoneObj.useEchoSuppression, false);
+check_equals (microphoneObj.useEchoSuppression, false);
 
 microphoneObj.setUseEchoSuppression(16);
-xcheck_equals (microphoneObj.useEchoSuppression, true);
+check_equals (microphoneObj.useEchoSuppression, true);
 
 // listen to the microphone.
 _root.attachAudio(microphoneObj);

=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING  2009-07-30 13:51:21 +0000
+++ b/testsuite/swfdec/PASSING  2009-08-06 11:05:32 +0000
@@ -128,6 +128,10 @@
 builtin-construction-5.swf:c3bcb8608999fa7a42a04b22e9e4929a
 call-arguments-5.swf:422c391a2abd3e864eb8ed8a1e05ad31
 callfunction-stack.swf:21d0c957f4caf0eb0ccd0dcadaf17500
+camera-properties-5.swf:495e39b641f89aa49a927cf0a8413028
+camera-properties-6.swf:3eb69243268f61cb8e130b661b6eac1a
+camera-properties-7.swf:ec270af18a3930560841e04ae4c8d952
+camera-properties-8.swf:aec47432bc6f450341ee256511379b91
 case1-6.swf:ba805f628a3a2d1bbd292ec1e56d1708
 case1-7.swf:ad4cfa4c3df86421237239167414fb40
 cast-5.swf:9b7fb2315d1ca5dbc7476ce29037bb19
@@ -606,6 +610,10 @@
 matrix-properties-5.swf:a80d726dfde5b460add76a7532e7ee01
 matrix-properties-6.swf:a7934cc5476219b199a40c4feb627dfe
 matrix-properties-7.swf:144e6c666febf556bec9864ee234a54a
+microphone-properties-5.swf:26a2019cc8d42c41630cac3eaf435412
+microphone-properties-6.swf:0463204be0bb721bac2e642cc2c0696d
+microphone-properties-7.swf:111e7119fcf0b3e270503e4df247b27f
+microphone-properties-8.swf:44ae9957bde22d3a948d4ee3e83a3b1c
 mouse-addProperty-relevant-5.swf:1bfc494379c8192d0b410ab431efbebd
 mouse-movie-below-movie-5.swf:c7d97de8768c341a64df75dca2686c0b
 mouse-movie-below-nonevent-movie-5.swf:9027280bdb516e12f2e4255776c079a1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]