Thursday, February 24, 2011

Popcornjs - bug #127... again

Remember how I said I finished my bug? Well... I lied, lol. Upon receiving a "review-needs-work" status, and gaining a better understanding of javascript from class, I looked over my code and found that I needed to do it again.

My Example
Let's say you've got two subtitles: one starts at 3 seconds and has no end specified, the other starts at 10 and ends at 15. Now, if you set the first subtitle's end to the end of the video, the second subtitle will never disappear. I had to somehow arrange that an endless subtitle has it's end set to the end of the video ONLY if there isn't another subtitle coming up. Seeing as I don't have access to the next subtitle while I'm creating them (naturally), I had to do a little bit of backwards work.

Solution
(from popcorn.js):

if ( currentSubtitle ) {
previousSubtitle = currentSubtitle;
}
currentSubtitle = options;

if ( previousSubtitle && previousSubtitle.noEnd ) {
previousSubtitle.noEnd = false;
previousSubtitle.end = currentSubtitle.start;
Popcorn.removeTrackEvent( this, Popcorn.getLastTrackEventId( this ) );
Popcorn.addTrackEvent( this, previousSubtitle );
}
setup._setup.call( this, currentSubtitle );
Popcorn.addTrackEvent( this, currentSubtitle );

Confused? Here's what's happening:
This chunk of code is run once for each subtitle. Earlier, if it doesn't find an end options.noEnd is set which allows the end to be the end of the video (in popcorn.subtitle.js). So the first time through, (creating the endless one) the subtitle will be continuous and added to the list of track events.

...Follow me so far? Good.

The second time it runs through, it will see that there is a previous subtitle with noEnd set. It will remove the previous subtitle from the track list, change it's end to the start time of the current subtitle, and re-add it to the track list. Then business continues as usual for the current subtitle.

Wanna see my genious for yourself?
https://github.com/DanVentura/popcorn-js/tree/bug127/plugins/subtitle
Have fun ;)

Thursday, February 10, 2011

Popcorn.js - bug # 127

I finally finished my first bug for popcorn.js. The bug I was assigned was to make it easier to specify subtitles, found here: https://webmademovies.lighthouseapp.com/projects/63272-popcorn-js/tickets/bins/261878

Basically, when making subtitles you have to specify an 'in' and an 'out' so it knows what time in the video to show up and disappear. They wanted to be able to make a subtitle continuous by not specifying an 'out'. For example, if a subtitle immediately follows another subtitle, it would be redundant to specify the 'out' as the next subtitle's 'in'.

Now, this seems easy... just get the 'in' from the next subtitle, right? HA! Too bad I didn't find a way to access the next subtitle within the first subtitle. Fortunately I found a workaround: if you set the 'out' to a greater value than the next subtitle's 'out' (even if you set it to 1000000), it should seamlessly go into the next subtitle without any problems.

As I mentioned before, I don't have access to the next subtitle (cause it doesn't exist when you're creating the first). I figured that the fix would be to set the missing 'out' element to the maximum value available... the video duration.

options.out = this.video.duration

Yet another problem... fantastic. For some odd reason, if you call this statement for the very first subtitle in the video, this.video.duration is 0. This is because this.video.readyState is not 4. In other words, the video isn't ready yet. I have discovered the folly of Javascript, it's too fast for itself LOL.

Fortunately I found a "start:" function, which is called when the subtitle is put into the video. By the time this function is called, the readyState is 4 and video.duration returns as expected. There was also some other problems but if you're interested check out my branch.

I liked this bug. It taught me a lot about Popcorn.js and JavaScript :D

Sunday, February 6, 2011

Processing.js - Bug# 946

This had to have been the easiest bug to fix. Yay. You can find it here: https://processing-js.lighthouseapp.com/projects/41284/tickets/946-unexpected-result-when-converting-char-to-str

Basically there's a function that takes data and outputs it as a string. The problem was that when you passed it a char, it returned the ASCII value. After going on IRC and learning how to get started, the "bazaar" discovered that one of the tests for this function had been commented out by the person who worked on it last (no wonder it passed).

So basically what I did was uncomment that, add another test that looks exactly the same as the one in the sketchpad link above, and my fix. my fix was exactly this:


--arr.push(val[i] + "");
++arr.push(val[i].toString() + "");
##return arr;
##}
##}
##else
##{
--return (val + "");
++return (val.toString() + "");


... pretty much. It's up for review. If you're reading this, feel free to review it. I put the link to my branch in the comments for the lighthouse link provided (not sure if thats what i was supposed to do).

Friday, January 21, 2011

OSD600 - Building Firefox 4 (Minefield)

Okay, I got this to work but I'm not sure if it works correctly. I mean, it runs but it runs weird. Let me explain: (*Note: If you use this as a guide to try this yourself, don't follow it step by step. In fact, follow this blog or the official Simple ff build. Also, I am running Windows 7 x86*)

What You Will Need

I followed someone else's blog through most of this (). Basically you will need the Mozilla Build tools and TortoiseHg (the one that suits your OS).

Let's Get Started

Allow the build tools to install to it's default directory: C:/mozilla-build. Next, make a directory in your C:/ directory for the source code (mine is C:/OSD600. It is important to not include spaces in this path name!). For this directory, we will use TortoiseHg to clone the source code from this url: http://hg.mozilla.org/mozilla-central/. This takes a while...

Now we must make a mozconfig file. Seeing as Windows 7 won't allow you to make files without an extension, open the command line and execute these commands (this is what's in my mozconfig. Here is Mozilla's help page for mozconfig files):

echo ". $topsrcdir/browser/config/mozconfig" > mozconfig
echo "mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-debug" >> mozconfig
echo "ac_add_options --enable-debug"
>> mozconfig
echo "ac_add_options --disable-optimize" >> mozconfig

You'll also want to open it in notepad and remove the quotes. Better yet, just do echo "d" > mozconfig to make the file and do the rest in notepad. When you're done, this file should be placed in the root folder (in my case, C:/OSD600).

Now for the fun part (this is the part where the problems arise, naturally). Go to C:/mozilla-build and run one of the start-msvc.bat files. If you has Visual Studio 2010, run start-msvc10.bat. And yes, I am assuming you have Visual Studio and the required Microsoft SDKs. This .bat file should open a command window.

Now execute these commands:
cd /c/osd600 make -f client.mk build

If it works, it will build for about an hour.











When it finishes building the executable can be found in the following directory:
Depending on what directory you put in your mozconfig (at this line : mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-debug) it can be found at C:/OSD600/objdir-ff-debug/dist/bin/firefox.exe.













P
roblems

What, you think it's THAT easy? HA! This took me days!

The first error I got was this one:
--enable-application=APP was not specified

I looked online for a fix to this error but now I'm thinking that the fix was unnecessary. I think if I specified an additional option in the mozconfig, I would have fixed this error. Anyways, the fix I found was to do this:
-Make a new directory
- Go to that directory
- execute these commands:
../configure --enable-application=browser
make -f ../client.mk

This however caused more problems. So the next day I went to the original directory (OSD600) and ran the regular command: "make -f client.mk build" and for some reason it worked! ... Or so I thought. It works but I get this error message.













When I run the firefox.exe, a command line window pops up, it write a bunch of warnings, and this error window appears. If you choose "Abort" and try again or "Ignore", the error message doesn't pop up. It's just odd.

Monday, March 22, 2010

OOP344 - who needs default constructors anyway?

i always had a feeling that default constructors were pointless. I don't know, something about making a function that sets everything to null seems... meaningless? Fortunately, I've learned an alternative! Let's say we have a class called, for instance, Poop (lol). Inside Poop, we want to keep color (char*) and size (int). If we were to use a default constructor AND an argument constructor, our prototypes would look like this:

Poop();
Poop(char* color, int size);

This method would leave us having to write the same constructor twice, except the argument constructor would assign values other than 0.
In order to avoid the redundancy, we can write 1 arguement constructor with this little tweek:

Poop(char* color = 0, int size = 0);

If Poop() is called without arguments, the constructor will automatically use the default values provided in the declaration! Genius, I know!

Monday, February 8, 2010

OOP344 - fardad, i accept your putint() challenge!

this function was harder than i expected. In order to convert a number to a character, all you have to do is add 48 (this is because 0 on the ascii table is 48, 1 is 49, etc.). So as long as you are sending the putint function a 1 digit number, this will work. However, for the keys that are 4 digits long (i.e: RIGHT_KEY = 1077), it gets a little more complicated.

This took me a while to figure out and i must say, it's genius :). First what you have to do is: seperate the digits. This is where being good with numbers really helps.
(i'm not going to write code, instead I'll give you a mathematical view point)

if you divide a number by 10, the decimal moves one point to the left:
1077 / 10 = 107.7
In order to get the decimal point i used a float, however that caused problems because float are never exact. So, i made two temporary int variables and did this:

1. temp = 1077 <- this is the integer being sent to the function
temp / 10 = 107 <- integers truncate decimal points
temp * 10 = 1070
2. temp2 = 1077 - temp
= 7
Hooray, i got the first digit separated. Now, just do char = temp2 + 48; and your first digit is successfully converted. Repeat this process for x amount of times and your string contains a 4 digit number. BUT WAIT, how do i determine x? dividing by 10 again.
make a while loop where you divide temp by 10 while temp > 0 and do an i++ to get how many digits are in the number. you can now use i for a for loop.

There you have it, a putint function that converts an integer into a string without using extra libraries (there is no atoi() or sprintf()).

Monday, January 11, 2010

Welcome!

Welcome to Dan's Programming blog!