
Recherche avancée
Médias (1)
-
Revolution of Open-source and film making towards open film making
6 octobre 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (103)
-
List of compatible distributions
26 avril 2011, parThe table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...) -
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...) -
Submit enhancements and plugins
13 avril 2011If you have developed a new extension to add one or more useful features to MediaSPIP, let us know and its integration into the core MedisSPIP functionality will be considered.
You can use the development discussion list to request for help with creating a plugin. As MediaSPIP is based on SPIP - or you can use the SPIP discussion list SPIP-Zone.
Sur d’autres sites (4299)
-
Crash at sws_scale when converting AVFrame to RGB32
1er mars 2017, par WLGfxCrashing at sws_scale when converting an AVPicture
At first I was using sws_scale to actually scale the frames up but the cpu overhead was too high, so I decided to just convert the frames and adjust the QImage size instead. Before it was working and I was getting the video displaying when rendered, but now it crashes at sws_scale.
This is written in Qt for Android and using FFMpeg 3.1.4.
Also, is there another way around not using the deprecated functions ?
Does anybody know why I am getting the crash at sws_scale ?
The class for the VideoFrameCopy
class VideoFrameCopy {
public:
VideoFrameCopy() {}
VideoFrameCopy(AVFrame *frame) { copyAVFrame(frame); }
~VideoFrameCopy();
void copyAVFrame(AVFrame *frame); // copy essential data from AVFrame
AVPicture picture;
int64_t pkt_pts = -1; // show it hasn't been initialised
int64_t best_pts;
int interlaced_frame;
int width = 0, height = 0;
int format = -1;
};The code that converts the frame to RGBA8888 QImage
if (frame) {
if (image->width() != vid_ctx->width || image->height() != vid_ctx->height) {
QSize old_size(image->size());
// block until renderer has finished with it
while (parent->buffer_ready) {
QThread::yieldCurrentThread();
}
delete image;
image = new QImage(vid_ctx->width, vid_ctx->height, QImage::Format_RGBA8888);
parent->image = image;
if (scale_context) sws_freeContext(scale_context);
scale_context = nullptr;
qDebug() << "Video image size" << image->size() << "old" << old_size;
}
// the src width and height may need to change to use the context info instead
if (!scale_context) { // create the scale context
int src_width = vid_ctx->width;
int src_height = vid_ctx->height;
AVPixelFormat src_format = vid_ctx->pix_fmt;//(AVPixelFormat)frame->format;
int dst_width = vid_ctx->width;
int dst_height = vid_ctx->height;
AVPixelFormat dst_format = AV_PIX_FMT_RGBA;
scale_context = sws_getContext(src_width, src_height, src_format,
dst_width, dst_height, dst_format,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
av_image_fill_linesizes(scale_linesizes, dst_format, vid_ctx->width);
qDebug() << "Created scale context" << scale_context;
}
if (scale_context) { // valid
scale_data[0] = image->bits();
sws_scale(scale_context,
frame->picture.data, // deprecated
frame->picture.linesize, // deprecated
0, image->height(),
scale_data,
scale_linesizes);
qDebug() << "Frame converted";
}
//av_frame_unref(frame);
//vid_frames_mutex.lock();
//if (quit) av_frame_free(&frame);
if (quit) delete frame;
else vid_frames_unused.push_back(frame);
//vid_frames_mutex.unlock();
//qDebug() << "got frame" << clock_current_frame_last << "clock" << clock_current_time;
}
vid_frames_mutex.unlock();
return frame != nullptr;Functions from the VideoFrameCopy class
void VideoFrameCopy::copyAVFrame(AVFrame *frame) {
if (pkt_pts != -1 &&
(width != frame->width ||
height != frame->height ||
format != frame->format)
) { // picture changed?
avpicture_free(&picture); // deprecated
pkt_pts = -1;
}
width = frame->width;
height = frame->height;
format = frame->format;
interlaced_frame = frame->interlaced_frame;
if (pkt_pts == -1) { // alloc picture
if (avpicture_alloc(&picture, (AVPixelFormat)format, width, height) < 0) return; // deprecated
int size = avpicture_get_size((AVPixelFormat)format, width, height); // deprecated
uint8_t *picture_data = (uint8_t*)av_malloc(size);
avpicture_fill(&picture, picture_data, (AVPixelFormat)format, width, height); // deprecated
qDebug() << "New frame" << width << "x" << height << format;
}
pkt_pts = frame->pkt_pts;
best_pts = av_frame_get_best_effort_timestamp(frame);
av_picture_copy(&picture, (AVPicture*)frame, (AVPixelFormat)format, width, height); // deprecated
qDebug() << "picture" << picture.linesize[0] << picture.linesize[1]; // deprecated
}
VideoFrameCopy::~VideoFrameCopy() {
if (pkt_pts != -1) {
/*if (picture.data) {
av_free(picture.data);
picture.data = nullptr;
}*/
avpicture_free(&picture); // deprecated
}
}Sample output from the logcat
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:659 (void VideoFrameCopy::copyAVFrame(AVFrame*)): New frame 640 x 358 0
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:667 (void VideoFrameCopy::copyAVFrame(AVFrame*)): picture 640 320
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:586 (bool FFMpegFile::getVideoFrame()): Video image size QSize(640, 358) old QSize(500, 320)
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:659 (void VideoFrameCopy::copyAVFrame(AVFrame*)): New frame 640 x 358 0
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:606 (bool FFMpegFile::getVideoFrame()): Created scale context 0x4bb49060
D/libcwengage2.so(20157): ../cwengage2/ffmpegfile.cpp:667 (void VideoFrameCopy::copyAVFrame(AVFrame*)): picture 640 320
F/libc (20157): Fatal signal 7 (SIGBUS) at 0x4e065008 (code=1), thread 20335 (QThread)
I/DEBUG ( 116): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 116): Build fingerprint: 'ODROID/odroidc/odroidc:4.4.2/KOT49H/odroidc-eng-s805_4.4.2_master-410:eng/test-keys'
I/DEBUG ( 116): Revision: '10'
I/DEBUG ( 116): pid: 20157, tid: 20335, name: QThread >>> org.qtproject.example <<<
I/DEBUG ( 116): signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 4e065008
I/DEBUG ( 116): r0 00000280 r1 00000166 r2 4e065008 r3 00000a00
I/DEBUG ( 116): r4 4d9bd030 r5 00000280 r6 4d9f4f28 r7 00000140
I/DEBUG ( 116): r8 00000280 r9 00000010 sl 4da02ee8 fp 4e065a08
I/DEBUG ( 116): ip 4d9bd2a0 sp 4c1948f8 lr 4a8f1d2c pc 4a8f4dc0 cpsr 280f0010
I/DEBUG ( 116): d0 004a004a004a004a d1 0081ffccffe70066
I/DEBUG ( 116): d2 004a004a004a004a d3 0000000000000000
I/DEBUG ( 116): d4 0000000000000000 d5 0000000000000000
I/DEBUG ( 116): d6 0000000001010101 d7 0000000001010101
I/DEBUG ( 116): d8 0000000001010101 d9 ffffffffffffffff
I/DEBUG ( 116): d10 0000000000000000 d11 0000000000000000
I/DEBUG ( 116): d12 0000000000000000 d13 ffffffffffffffff
I/DEBUG ( 116): d14 004a004a004a004a d15 004a004a004a004a
I/DEBUG ( 116): d16 0000000000000000 d17 0000000000000000
I/DEBUG ( 116): d18 0000000000000000 d19 0000000000000000
I/DEBUG ( 116): d20 0000000000000000 d21 0000000000000000
I/DEBUG ( 116): d22 0000000000000000 d23 0000000000000000
I/DEBUG ( 116): d24 0000000000000000 d25 0000000000000000
I/DEBUG ( 116): d26 0000000000000000 d27 0000000000000000
I/DEBUG ( 116): d28 004a004a004a004a d29 0000000000000000
I/DEBUG ( 116): d30 0000000000000000 d31 0000000000000000
I/DEBUG ( 116): scr 20000010
I/DEBUG ( 116):
I/DEBUG ( 116): backtrace:
I/DEBUG ( 116): #00 pc 0000edc0 /data/app-lib/org.qtproject.example-1/libswscale-4.so
I/DEBUG ( 116): #01 pc 0000bd28 /data/app-lib/org.qtproject.example-1/libswscale-4.so
I/DEBUG ( 116):
I/DEBUG ( 116): stack:
I/DEBUG ( 116): 4c1948b8 0000004b
I/DEBUG ( 116): 4c1948bc 4bb2d270
I/DEBUG ( 116): 4c1948c0 0000013c
I/DEBUG ( 116): 4c1948c4 4011edbc /system/lib/libc.so (dlmalloc+480)
I/DEBUG ( 116): 4c1948c8 4c19494a [stack:20335]
I/DEBUG ( 116): 4c1948cc 4015e384
I/DEBUG ( 116): 4c1948d0 00000010
I/DEBUG ( 116): 4c1948d4 489033ef /data/app-lib/org.qtproject.example-1/libQt5Core.so
I/DEBUG ( 116): 4c1948d8 00001000
I/DEBUG ( 116): 4c1948dc 00000000
I/DEBUG ( 116): 4c1948e0 4bb2d470
I/DEBUG ( 116): 4c1948e4 4bb2d478
I/DEBUG ( 116): 4c1948e8 4bb2d478
I/DEBUG ( 116): 4c1948ec 4bb2d470
I/DEBUG ( 116): 4c1948f0 00000002
I/DEBUG ( 116): 4c1948f4 4012109c /system/lib/libc.so (dlfree+996)
I/DEBUG ( 116): #00 4c1948f8 11111111
I/DEBUG ( 116): ........ ........
I/DEBUG ( 116): #01 4c1948f8 11111111
I/DEBUG ( 116): 4c1948fc 3fa11111
I/DEBUG ( 116): 4c194900 40000000
I/DEBUG ( 116): 4c194904 40640d79 /system/lib/libskia.so
I/DEBUG ( 116): 4c194908 00000000
I/DEBUG ( 116): 4c19490c 3ff00000
I/DEBUG ( 116): 4c194910 00000000
I/DEBUG ( 116): 4c194914 3ff00000
I/DEBUG ( 116): 4c194918 00000000
I/DEBUG ( 116): 4c19491c 3ff00000
I/DEBUG ( 116): 4c194920 00000000
I/DEBUG ( 116): 4c194924 3f800000
I/DEBUG ( 116): 4c194928 00000000
I/DEBUG ( 116): 4c19492c 00000000
I/DEBUG ( 116): 4c194930 00000000
I/DEBUG ( 116): 4c194934 00000000
I/DEBUG ( 116):
I/DEBUG ( 116): memory near r2:
I/DEBUG ( 116): 4e064fe8 00000000 00000000 00000000 00000007
...
I/DEBUG ( 116): memory map around fault addr 4e065008:
I/DEBUG ( 116): 4dd15000-4df15000 rw- /dev/mali
I/DEBUG ( 116): 4df15000-4e199000 rw-
I/DEBUG ( 116): 4e676000-4e876000 rw- /dev/mali
I/BootReceiver( 479): Copying /data/tombstones/tombstone_07 to DropBox (SYSTEM_TOMBSTONE)
W/ActivityManager( 479): Force finishing activity org.qtproject.example/org.qtproject.qt5.android.bindings.QtActivity
I/WindowState( 479): WIN DEATH: Window{64cf3a40 u0 org.qtproject.example/org.qtproject.qt5.android.bindings.QtActivity}
I/WindowState( 479): WIN DEATH: Window{64d0f6e0 u0 SurfaceView}
I/UsageStats( 479): No package stats for pkg:org.qtproject.example
I/art ( 118): Process 20157 terminated by signal (7)
W/ActivityManager( 479): Exception thrown during pause
W/ActivityManager( 479): android.os.DeadObjectException
W/ActivityManager( 479): at android.os.BinderProxy.transact(Native Method)
W/ActivityManager( 479): at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:660)
W/ActivityManager( 479): at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:778)
W/ActivityManager( 479): at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:2614)
W/ActivityManager( 479): at com.android.server.am.ActivityStack.finishTopRunningActivityLocked(ActivityStack.java:2488)
W/ActivityManager( 479): at com.android.server.am.ActivityStackSupervisor.finishTopRunningActivityLocked(ActivityStackSupervisor.java:2196)
W/ActivityManager( 479): at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:9705)
W/ActivityManager( 479): at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:9598)
W/ActivityManager( 479): at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:10243)
W/ActivityManager( 479): at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:9794)
W/ActivityManager( 479): at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
D/ActivityManager( 479): resumeClassName is com.android.launcher2.Launcher
D/ActivityManager( 479): resumePackageName is com.android.launcher
I/ActivityManager( 479): Process org.qtproject.example (pid 20157) has died.
D/ActivityManager( 479): send app_CRASH broadcast, packageName:org.qtproject.exampleMuch appreciated if anyone can help...
-
How to broadcast a stream of Buffered Images to another computer over LAN network by using Java Core
12 janvier 2017, par Trung Thanh NgoI am working with raspberry pi 3 acting as a server which controls a Sony camera (HX400V model). I am able to use Sony Remote API to control the Pi to extract buffered images in the Sony camera’s liveview stream.
I want to create and broadcast a stream of those buffered images to another computer over LAN network.
I succeeded in sending those buffered images by using java socket but there was a delay of 2 seconds which is not good. The Pi acts as a socket client and the other computer acts as a socket server.
Is there any way to create a stream and broadcast smoothly to another computer by using Java or anything else ?
-
Things I Have Learned About Emscripten
1er septembre 2015, par Multimedia Mike — Cirrus Retro3 years ago, I released my Game Music Appreciation project, a website with a ludicrously uninspired title which allowed users a relatively frictionless method to experience a range of specialized music files related to old video games. However, the site required use of a special Chrome plugin. Ever since that initial release, my #1 most requested feature has been for a pure JavaScript version of the music player.
“Impossible !” I exclaimed. “There’s no way JS could ever run fast enough to run these CPU emulators and audio synthesizers in real time, and allow for the visualization that I demand !” Well, I’m pleased to report that I have proved me wrong. I recently quietly launched a new site with what I hope is a catchier title, meant to evoke a cloud-based retro-music-as-a-service product : Cirrus Retro. Right now, it’s basically the same as the old site, but without the wonky Chrome-specific technology.
Along the way, I’ve learned a few things about using Emscripten that I thought might be useful to share with other people who wish to embark on a similar journey. This is geared more towards someone who has a stronger low-level background (such as C/C++) vs. high-level (like JavaScript).
General Goals
Do you want to cross-compile an entire desktop application, one that relies on an extensive GUI toolkit ? That might be difficult (though I believe there is a path for porting qt code directly with Emscripten). Your better wager might be to abstract out the core logic and processes of the program and then create a new web UI to access them.Do you want to compile a game that basically just paints stuff to a 2D canvas ? You’re in luck ! Emscripten has a porting path for SDL. Make a version of your C/C++ software that targets SDL (generally not a tall order) and then compile that with Emscripten.
Do you just want to cross-compile some functionality that lives in a library ? That’s what I’ve done with the Cirrus Retro project. For this, plan to compile the library into a JS file that exports some public functions that other, higher-level, native JS (i.e., JS written by a human and not a computer) will invoke.
Memory Levels
When porting C/C++ software to JavaScript using Emscripten, you have to think on 2 different levels. Or perhaps you need to force JavaScript into a low level C lens, especially if you want to write native JS code that will interact with Emscripten-compiled code. This often means somehow allocating chunks of memory via JS and passing them to the Emscripten-compiled functions. And you wouldn’t believe the type of gymnastics you need to execute to get native JS and Emscripten-compiled JS to cooperate.
“Emscripten : Pointers and Pointers” is the best (and, really, ONLY) explanation I could find for understanding the basic mechanics of this process, at least when I started this journey. However, there’s a mistake in the explanation that left me confused for a little while, and I’m at a loss to contact the author (doesn’t anyone post a simple email address anymore ?).
Per the best of my understanding, Emscripten allocates a large JS array and calls that the memory space that the compiled C/C++ code is allowed to operate in. A pointer in C/C++ code will just be an index into that mighty array. Really, that’s not too far off from how a low-level program process is supposed to view memory– as a flat array.
Eventually, I just learned to cargo-cult my way through the memory allocation process. Here’s the JS code for allocating an Emscripten-compatible byte buffer, taken from my test harness (more on that later) :
var musicBuffer = fs.readFileSync(testSpec[’filename’]) ; var musicBufferBytes = new Uint8Array(musicBuffer) ; var bytesMalloc = player._malloc(musicBufferBytes.length) ; var bytes = new Uint8Array(player.HEAPU8.buffer, bytesMalloc, musicBufferBytes.length) ; bytes.set(new Uint8Array(musicBufferBytes.buffer)) ;
So, read the array of bytes from some input source, create a Uint8Array from the bytes, use the Emscripten _malloc() function to allocate enough bytes from the Emscripten memory array for the input bytes, then create a new array… then copy the bytes…
You know what ? It’s late and I can’t remember how it works exactly, but it does. It has been a few months since I touched that code (been fighting with front-end website tech since then). You write that memory allocation code enough times and it begins to make sense, and then you hope you don’t have to write it too many more times.
Multithreading
You can’t port multithreaded code to JS via Emscripten. JavaScript has no notion of threads ! If you don’t understand the computer science behind this limitation, a more thorough explanation is beyond the scope of this post. But trust me, I’ve thought about it a lot. In fact, the official Emscripten literature states that you should be able to port most any C/C++ code as long as 1) none of the code is proprietary (i.e., all the raw source is available) ; and 2) there are no threads.Yes, I read about the experimental pthreads support added to Emscripten recently. Don’t get too excited ; that won’t be ready and widespread for a long time to come as it relies on a new browser API. In the meantime, figure out how to make your multithreaded C/C++ code run in a single thread if you want it to run in a browser.
Printing Facility
Eventually, getting software to work boils down to debugging, and the most primitive tool in many a programmer’s toolbox is the humble print statement. A print statement allows you to inspect a piece of a program’s state at key junctures. Eventually, when you try to cross-compile C/C++ code to JS using Emscripten, something is not going to work correctly in the generated JS “object code” and you need to understand what. You’ll be pleading for a method of just inspecting one variable deep in the original C/C++ code.I came up with this simple printf-workalike called emprintf() :
#ifndef EMPRINTF_H #define EMPRINTF_H
#include <stdio .h>
#include <stdarg .h>
#include <emscripten .h>#define MAX_MSG_LEN 1000
/* NOTE : Don’t pass format strings that contain single quote (’) or newline
* characters. */
static void emprintf(const char *format, ...)
char msg[MAX_MSG_LEN] ;
char consoleMsg[MAX_MSG_LEN + 16] ;
va_list args ;/* create the string */
va_start(args, format) ;
vsnprintf(msg, MAX_MSG_LEN, format, args) ;
va_end(args) ;/* wrap the string in a console.log(’’) statement */
snprintf(consoleMsg, MAX_MSG_LEN + 16, "console.log(’%s’)", msg) ;/* send the final string to the JavaScript console */
emscripten_run_script(consoleMsg) ;
#endif /* EMPRINTF_H */
Put it in a file called “emprint.h”. Include it into any C/C++ file where you need debugging visibility, use emprintf() as a replacement for printf() and the output will magically show up on the browser’s JavaScript debug console. Heed the comments and don’t put any single quotes or newlines in strings, and keep it under 1000 characters. I didn’t say it was perfect, but it has helped me a lot in my Emscripten adventures.
Optimization Levels
Remember to turn on optimization when compiling. I have empirically found that optimizing for size (-Os) leads to the best performance all around, in addition to having the smallest size. Just be sure to specify some optimization level. If you don’t, the default is -O0 which offers horrible performance when running in JS.Static Compression For HTTP Delivery
JavaScript code compresses pretty efficiently, even after it has been optimized for size using -Os. I routinely see compression ratios between 3.5:1 and 5:1 using gzip.Web servers in this day and age are supposed to be smart enough to detect when a requesting web browser can accept gzip-compressed data and do the compression on the fly. They’re even supposed to be smart enough to cache compressed output so the same content is not recompressed for each request. I would have to set up a series of tests to establish whether either of the foregoing assertions are correct and I can’t be bothered. Instead, I took it into my own hands. The trick is to pre-compress the JS files and then instruct the webserver to serve these files with a ‘Content-Type’ of ‘application/javascript’ and a ‘Content-Encoding’ of ‘gzip’.
- Compress your large Emscripten-build JS files with ‘gzip’ : ‘gzip compiled-code.js’
- Rename them from extension .js.gz to .jsgz
- Tell the webserver to deliver .jsgz files with the correct Content-Type and Content-Encoding headers
To do that last step with Apache, specify these lines :
AddType application/javascript jsgz AddEncoding gzip jsgz
They belong in either a directory’s .htaccess file or in the sitewide configuration (/etc/apache2/mods-available/mime.conf works on my setup).
Build System and Build Time Optimization
Oh goodie, build systems ! I had a very specific manner in which I wanted to build my JS modules using Emscripten. Can I possibly coerce any of the many popular build systems to do this ? It has been a few months since I worked on this problem specifically but I seem to recall that the build systems I tried to used would freak out at the prospect of compiling stuff to a final binary target of .js.I had high hopes for Bazel, which Google released while I was developing Cirrus Retro. Surely, this is software that has been battle-tested in the harshest conditions of one of the most prominent software-developing companies in the world, needing to take into account the most bizarre corner cases and still build efficiently and correctly every time. And I have little doubt that it fulfills the order. Similarly, I’m confident that Google also has a team of no fewer than 100 or so people dedicated to developing and supporting the project within the organization. When you only have, at best, 1-2 hours per night to work on projects like this, you prefer not to fight with such cutting edge technology and after losing 2 or 3 nights trying to make a go of Bazel, I eventually put it aside.
I also tried to use Autotools. It failed horribly for me, mostly for my own carelessness and lack of early-project source control.
After that, it was strictly vanilla makefiles with no real dependency management. But you know what helps in these cases ? ccache ! Or at least, it would if it didn’t fail with Emscripten.
Quick tip : ccache has trouble with LLVM unless you set the CCACHE_CPP2 environment variable (e.g. : “export CCACHE_CPP2=1”). I don’t remember the specifics, but it magically fixes things. Then, the lazy build process becomes “make clean && make”.
Testing
If you have never used Node.js, testing Emscripten-compiled JS code might be a good opportunity to start. I was able to use Node.js to great effect for testing the individually-compiled music player modules, wiring up a series of invocations using Python for a broader test suite (wouldn’t want to go too deep down the JS rabbit hole, after all).Be advised that Node.js doesn’t enjoy the same kind of JIT optimizations that the browser engines leverage. Thus, in the case of time critical code like, say, an audio synthesis library, the code might not run in real time. But as long as it produces the correct bitwise waveform, that’s good enough for continuous integration.
Also, if you have largely been a low-level programmer for your whole career and are generally unfamiliar with the world of single-threaded, event-driven, callback-oriented programming, you might be in for a bit of a shock. When I wanted to learn how to read the contents of a file in Node.js, this is the first tutorial I found on the matter. I thought the code presented was a parody of bad coding style :
var fs = require("fs") ; var fileName = "foo.txt" ;
fs.exists(fileName, function(exists)
if (exists)
fs.stat(fileName, function(error, stats)
fs.open(fileName, "r", function(error, fd)
var buffer = new Buffer(stats.size) ;fs.read(fd, buffer, 0, buffer.length, null, function(error, bytesRead, buffer)
var data = buffer.toString("utf8", 0, buffer.length) ;console.log(data) ;
fs.close(fd) ;
) ;
) ;
) ;
) ;Apparently, this kind of thing doesn’t raise an eyebrow in the JS world.
Now, I understand and respect the JS programming model. But this was seriously frustrating when I first encountered it because a simple script like the one I was trying to write just has an ordered list of tasks to complete. When it asks for bytes from a file, it really has nothing better to do than to wait for the answer.
Thankfully, it turns out that Node’s fs module includes synchronous versions of the various file access functions. So it’s all good.
Conclusion
I’m sure I missed or underexplained some things. But if other brave souls are interested in dipping their toes in the waters of Emscripten, I hope these tips will come in handy.The post Things I Have Learned About Emscripten first appeared on Breaking Eggs And Making Omelettes.