XNA Content Loading - xna

Anybody know how i can stream load Model data in XNA 4 Content Loader ?
And not have to specify a farken filename ...
Was hoping somehow get a stream running as the model data resides on a db.
And no, im not interested in temp files :p
Regards

If you really want to use the Content Pipeline for this, you can subclass ContentManager and override OpenStream. This would assume that the built XNB files reside in the database and you can provide the stream to them when requested :)

Content.Load<Model>() requires a string parameter, so I don't think that you'll be able to stream a Model in. I should mention that the string parameter that is required is a filePath, so you wouldn't be able to convert a stream to a string and pass that in.

I believe that this should help. If I remember correctly, I can't check because I'm at work, it lets you run the content importer on a stream dynamically. So you should be able to dump your file in a MemeoryStream and load it so long as its any of the file types XNA supports.
Be warned though this is pretty slow because you have to compile every file when you load it.
Curious of why you need to load from a database. I assume its from a remote server? In which case the download time + compile time might be a bit much. since it sounds like you would have to do it every time the game is loaded.
http://create.msdn.com/en-US/education/catalog/sample/winforms_series_2

Related

Transform big file in ASP.NET MVC Controller without saving on disc

Is it possible to transform big file just posted to controller and start download of transformed file without saving files to disc? I would like to read big .CSV file, do some changes in fields and return transformed .CSV as a stream to user who upload initial file. Main problem is that I should not save file to disc. Is is possible to do with help of or I need to do ajax call?
Of course. So long as the file is not so huge it will cause memory problems on the server side. Even then, you're OK so long as you can transform the file line by line. In fact, most server file transformations are probably done in memory without writing anything to disk. This has nothing to do with "ajax" BTW, which is purely a term which relates to how the user interface is rendered.

Checking that a file on an HTTP server is different than a local copy

I'm sure that this must have been figured out a million times already, which is why I'm asking.
I fetch files (JSON, PNG, XML, plist) from an HTTP server and save them locally. Then these files are read, processed and displayed. My issue is that I want to know if there is a newer file on the server when I am about to proceed to a screen that will be displaying the downloaded data. In that case, I'd like to get the file, store it and use that info.
Thanks in advance.
Looks like there are good answers out there already. Just took some creative thinking on how to find them!
http://iphoneincubator.com/blog/server-communication/how-to-download-a-file-only-if-it-has-been-updated
Great stuff.

Watch video in the time they are uploaded

It is possible to implement a feature that allows users to watch videos as they are uploaded to server by others. Is html 5 suitable for this task? But flash? Are there any read to go solutions, don't want to reinvent the wheel. The application will be hosted on a dedicated server.
Thanks.
Of course it is possible, the data is there isnt it?
However it will be very hard to implement.
Also I am not so into python and I am not aware of a library or service suiting your requirements, but I can cover the basics of video streaming.
I assume you are talking about video files that are uploaded and not streams. Because, for that, there are obviously thousands of solutions out there...
In the most simple case the video being uploaded is already ready to be served to your clients and has a so called "faststart atom". They are container format specific and there are sometimes a bunch of them. The most common is the moov-atom. It contains a lot of data and is very complex, however in our use case, in a nutshell, it holds the data that enables the client to begin playing the video right away using the data available from the beginning.
You need that if you have progressive download videos (youtube...), meaning where a file is served from a Webserver. You obviously have not downloaded the full file and the player already can start playing.
If the fastastart atom was not present, that would not be possible.
Sometimes it is, but the player for example cannot display a progress bar, because it doesnt know how long the file is.
Having that covered the file could be uploaded. You will need an upload solution that writes the data directly to a buffer or a file. (file will be easier...).
This is almost always the case, for example PHP creates a file in the tmp_dir. You can also specify it if you want to find the video while its being uploaded.
Well, now you can start reading that file byte by byte and print that data to a connection to another client. Just be sure not to go ahead of what has already been recieved and written. You would probaby initiate your upload with a metadata set in memory that holds the current recieved byte position and location of the file.
Anyone who requests the file after the uploaded has started can just recieve the entire file, or if the upload is not yet finished, get it from your application.
You will have to throttle the data delivery or pause it when the data becomes short. This will appear to the client almost as a "slow connection". However you will have to echo some data from time to time to prevent the connection from closing. But if your upload doesnt stall, and why shoud it?, that shouldnt be a problem.
Now if you want to have someting like on the fly transcoding of various input formats into your desired output format, things get interesting.
AFAIK ffmpeg has neat apis which lets you directly deal with datasterams.
Also handbrake is a very good tool, however you would need to take the long road using external executeables.
I am not really aware of your requirements, however if your clients are already tuned in, for example on a red 5 streaming server, feeding data into a stream should also work fine.
Yes, take a look at Qik, http://qik.com/
"Instant Video Sharing ... Videos can be viewed live (right as they are being recorded) or anytime later."
Qik provides developer APIs, including ones like these:
qik.stream.subscribe_public_recent -- Subscribe to the videos (live and recorded)
qik.user.following -- Provides the list of people the user is following
qik.stream.public_info -- Get public information for a specific video
It is most certainly to do this, but it won't be trivial. And no, I don't think that you will find an "out of the box" solution that will require little effort on your behalf.
You say you want to let:
users watch videos as they are uploaded to server by others
Well, this could be interpreted two different ways:
Do you mean that you don't want a user to have to refresh the page before seeing new videos that other users have just finished uploading?
Or do you mean that you want one user to be able to watch a partially uploaded video (aka another user is still in the process of uploading it and right now the server only contains a partial upload of the video)?
Implementing #1 wouldn't be hard at all whatsoever. You would just need an AJAX script to check for newly uploaded videos, and those videos could then be served to the user in whatever way you choose. HTML5 vs. Flash isn't really a consideration here.
The second scenario, on the other hand, would require quite a bit of effort. I am guessing that HTML5 might not be mature enough to handle this type of situation. If you are not looking
to reinvent the wheel and don't have a lot of time to dedicate to this feature than I would say that you would be out of luck. You may be able to use ffmpeg to parse partial video files and feed them to a Flash player, but I would think of this as a large task.

Loading leveldb from stream

Is there a way to load a leveldb store from a data stream?
If I were to take the stream of a leveldb instance and tuck it in a DLL as a manifest resource stream, will I have a way to just load that db from that stream later when I retrieve the manifest resource from my DLL? Essentially, I am looking for a way to build, save, and later load a leveldb without ever writing to a physical file on disk.
Thanks in advance for any useful info.
Raja.
You might have already figured this out since it's been a long time since you asked.
leveldb allows you to override the "Environment" such that reads and writes don't need to access a physical file.
You might want to look at this file:
http://code.google.com/p/leveldb/source/browse/helpers/memenv/memenv_test.cc
in particular the DBTest, for an example.

How are you mapping database records to physical files such as image uploads

37 signals suggests id partitioning to accomplish this thing..
http://37signals.com/svn/archives2/id_partitioning.php
Any suggestions would be more than welcome.
Thanks.
We use Paperclip for storing our files. It can do what you want pretty easily.
We use partitioning by date so an image uploaded today would end up in 2009/12/10/image_12345.jpg. The path is stored in the db for reference and the path to the image folder (the parent of 2009) is placed in some config file. If we need to change things later it makes it very easy.
You can map by virtually everything. We use mapping by user on our designs, but it's a HR system so it makes sense (there's no way the user will have 32k file entries) and the files are clearly connected with user. On Media Library parts of the system dividing by date or ID will be more useful.
The catch is, you should store some part of file path in database table (as suggested before). Will it be date, or user hash/name (often also divided, eg u/user j/john j/jo/john etc). Then you don't have to worry about changing division system, as this will only require database update.

Resources