Beispiel #1
0
void as3_init(const char *i_format_name, const char *i_codec_name, int i_sample_rate,
              int i_channels, const char *o_format_name, const char *o_codec_name,
              int o_sample_rate, int o_channels, int o_bit_rate, int o_buffer_max_seconds)
{
    AS3_MallocString(i_format_name, inputFormat);
    AS3_MallocString(i_codec_name, inputCodec);
    AS3_GetScalarFromVar(i_sample_rate, inputSampleRate);
    AS3_GetScalarFromVar(i_channels, inputChannels);
    AS3_MallocString(o_format_name, outputFormat);
    AS3_MallocString(o_codec_name, outputCodec);
    AS3_GetScalarFromVar(o_sample_rate, outputSampleRate);
    AS3_GetScalarFromVar(o_channels, outputChannels);
    AS3_GetScalarFromVar(o_bit_rate, outputBitRate);
    AS3_GetScalarFromVar(o_buffer_max_seconds, outputBufferMaxSeconds);

    int status = init(i_format_name, i_codec_name, i_sample_rate, i_channels, o_format_name,
         o_codec_name, o_sample_rate, o_channels, o_bit_rate, o_buffer_max_seconds);

    free((char*)i_format_name);
    free((char*)i_codec_name);
    free((char*)o_format_name);
    free((char*)o_codec_name);

    AS3_Return(status);
}
Beispiel #2
0
/**
 * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
 * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
 * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
 * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
 * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
 * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
 * d174ab98d277d9f5a5611c2c9f419d9f
 * MD5 ("123456789012345678901234567890123456789012345678901234567890123456
 * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
 */
void md5String(){
    const char *src = NULL;
    AS3_MallocString(src, input);

    std::string srcString(src);

    const char *result;

    hashwrapper *wrapper;

    wrapper = new md5wrapper();
    std::string md5 = wrapper->getHashFromString(srcString);

    result = md5.c_str();

    delete wrapper;

    // We can't just call AS3_Return(s) because s is not a scalar.
    // Instead we need to marshall the C string into AS3 and use
    // AS3_ReturnAS3Var().

    AS3_DeclareVar(myString, String);
    AS3_CopyCStringToVar(myString, result, 32);
    AS3_ReturnAS3Var(myString);
}
Beispiel #3
0
void scws_send_text_AS3()
{
	char *text = NULL;
	AS3_MallocString(text, inputString);
	scws_send_text(s, text, strlen(text));
	AS3_DeclareVar(myString, String);

	//char *result;
	//result[0] = '\0';   // ensures the memory is an empty string
	char result[5000]={"0"};
    char temp[1000]={'\0'};
	printf("%s",result);
	while (res = cur = scws_get_result(s))
	{
		while (cur != NULL)
		{
			printf("WORD: %.*s/%s (IDF = %4.2f)\n", cur->len, text+cur->off, cur->attr, cur->idf);
			//if((result = malloc(strlen(result)+ cur->len +1)) != NULL){
			//if((result = (char*) realloc(strlen(result)+ (cur->len) +1)) != NULL)
            strncpy(temp, text+cur->off, cur->len);
			temp[(cur->len)+1]='\0';
			strcat(result, temp);
			strcat(result, ' ');
			strcat(result, '\0');
            //strncpy(new_str,str2);
            //} else {
            //printf("malloc failed!\n");
            // exit?
            //}
			cur = cur->next;
		}
		scws_free_result(res);
	}
	strcat(result, '\0');
	
	printf("%s",result);
	AS3_CopyCStringToVar(myString, result, strlen(result));
	scws_free(s);
	//scws_free(result);
	AS3_Trace(myString);
	
	AS3_Return("212");
}
Beispiel #4
0
void MurmurHash3()
{
    // Copy the AS3 string to the C heap (must be free'd later)
    char *key = NULL;
    AS3_MallocString(key, keystr);

    int keylen = 0;
    AS3_StringLength(keylen, keystr);
    
    // Call hash function
    int result;
    uint32_t seed = 42;
    MurmurHash3_x86_32(key, keylen, seed, &result);
    
    // don't forget to free the string we allocated with malloc previously
    free(key);
    
    // return the result (using an AS3 return rather than a C/C++ return)
    AS3_Return(result);
}
Beispiel #5
0
extern "C" void compileShader()
{
   // Copy the AS3 string to the C heap (must be free'd later)
   char *src = NULL;
   AS3_MallocString(src, src);

   bool gles = false;
   AS3_CopyScalarToVar(gles, gles);

   glslopt_ctx* gContext = glslopt_initialize(gles);

   int mode;
   AS3_GetScalarFromVar(mode, mode);
   const glslopt_shader_type type = mode == 0 ? kGlslOptShaderVertex : kGlslOptShaderFragment;

   glslopt_shader* shader = glslopt_optimize(gContext, type, src, 0);

   const char* optimizedShader = glslopt_get_output(shader);
   AS3_DeclareVar(outputstr, String);
   AS3_CopyCStringToVar(outputstr, optimizedShader, strlen(optimizedShader));

   glslopt_cleanup(gContext);

   //optimize shader and/or turn sampler instructions into easily
   //replaceable aliases (for generating sampler variations at runtime)
   inline_as3(
      "import com.adobe.AGALOptimiser.translator.transformations.Utils;\n"
      "var shader:Object = null;\n"
      "try { shader = JSON.parse(outputstr) } catch(e:*) { }\n"
      "if(shader != null && shader[\"agalasm\"] != null) {\n"
      "    if(optimize)\n"
      "        shader = Utils.optimizeShader(shader, mode == 0)\n"
      "    shader[\"agalasm\"] = Utils.processSamplers(shader[\"agalasm\"]);\n"
      "    outputstr = JSON.stringify(shader, null, 1)\n"
      "}\n"
   );

   AS3_ReturnAS3Var(outputstr);
}
Beispiel #6
0
extern "C" void compileShader()
{
   // Copy the AS3 string to the C heap (must be free'd later)
   char *src = NULL;
   AS3_MallocString(src, src);

   bool gles = false;
   AS3_CopyScalarToVar(gles, gles);


   glslopt_ctx* gContext = glslopt_initialize(gles);

   int mode;
   AS3_GetScalarFromVar(mode, mode);
   const glslopt_shader_type type = mode == 0 ? kGlslOptShaderVertex : kGlslOptShaderFragment;

   glslopt_shader* shader = glslopt_optimize(gContext, type, src, 0);

   const char* optimizedShader = glslopt_get_output(shader);
   AS3_DeclareVar(outputstr, String);
   AS3_CopyCStringToVar(outputstr, optimizedShader, strlen(optimizedShader));

   glslopt_cleanup(gContext);

   inline_as3(
      "import com.adobe.AGALOptimiser.translator.transformations.Utils;\n"
      "if(optimize) {\n"
      "    var shader:Object = JSON.parse(outputstr)\n"
      "    if(shader[\"agalasm\"] != null) {\n"
      "        shader = Utils.optimizeShader(shader, mode == 0)\n"
      "        outputstr = JSON.stringify(shader)\n"
      "    }\n"
      "}\n"
   );

   AS3_ReturnAS3Var(outputstr);
}
Beispiel #7
0
int
main(int argc, char **argv)
{
   #if CMDLINE

   bool vertexShader = false, freename = false, optimize = false, gles = false;
   const char* source = 0;
   char* dest = 0;

   for( int i=1; i < argc; i++ )
   {
      if( argv[i][0] == '-' )
      {
         if( 0 == strcmp("-e", argv[i]) )
            gles = true;
         if( 0 == strcmp("-d", argv[i]) )
            glslOptimizerVerbose = true;
         if( 0 == strcmp("-v", argv[i]) )
            vertexShader = true;
         if( 0 == strcmp("-f", argv[i]) )
            vertexShader = false;
         if( 0 == strcmp("-optimize", argv[i]) )
            optimize = true;
      }
      else
      {
         if( source == 0 )
            source = argv[i];
         else if( dest == 0 )
            dest = argv[i];
      }
   }

   if( !source )
      abort();

   if ( !dest ) {
      dest = (char *) calloc(strlen(source)+5, sizeof(char));
      snprintf(dest, strlen(source)+5, "%s.out", source);
      freename = true;
   }

   const char* originalShader = loadFile(source);
   if( !originalShader )
      abort();

   AS3_DeclareVar(srcstr, String);
   AS3_CopyCStringToVar(srcstr, originalShader, strlen(originalShader));

   inline_as3(
      "srcstr = compileShader(srcstr, %0, %1, %2)\n"
      : : "r"(vertexShader ? 0 : 1), "r"(optimize), "r"(gles)
   );

   char *optimizedShader;
   AS3_MallocString(optimizedShader, srcstr);

   if( !saveFile(dest, optimizedShader) )
      abort();

   return 0;

   #endif

   AS3_GoAsync();
}