Sunday 16 December 2018

Videos not playing in opera on linux


So, it's no secret i've loved opera since the day i first installed it, I think i joined the opera revolution around the 3.62 mark in 1999 apparently! (man i'm old). Anyhow - read up more about the opera history here https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser

Since i'm this fancy new software developer type person,  i have it installed as my browser of choice at work, but we run linux here since the platforms we use are linux as well. I'm not complaining mind you, i like linux too!

But the support for playing videos is lacking :( (wuh waaahhh), I believe this is due to the license with Mpeg's and not being able to distribute the codec with the program.
From this post it appears that Opera doesn't have the rights to distribute the codec with the program. however! Google does (cos they probably have deeper pockets right?)

Anyhow - very easy to fix, we simply copy over the top of the libffmpeg.so that we have in our opera directory with one from the google chromium browser :)

sudo cp /usr/lib/chromium-browser/libffmpeg.so /usr/lib/x86_64-linux-gnu/opera/


Restart the browser and things should be all good again :)


Tuesday 4 December 2018

Measuring function time in linux using C


Measuring Time 

So in my job recently i had to time how long it took for a module to be plugged in before that module became "ready" ... the answer was 46 seconds.. but some careful polling changes and a change how firmware was loaded mean't that got chopped in half almost to 26 seconds!

But that's not the point, the point was how did i do such timing.

The original way i found was to use to use clock(). Clock returns an approximation of the processor time used by the program.
Using the following code..

#include <time.h>
#include <stdio.h> 
int main() 
{ 
   clock_t start, stop, length; 
   start = clock(); 
   
   function_to_be_time(parameters); 
   
   stop = clock(); 

   length = (double) stop - start / CLOCKS_PER_SEC; 

   printf("Time for your function was %ld\n", length); 
   
   return; 
} 

Now, this works mind you! but there's a gotchya here, oh yes, you saw that coming didn't you.. go on - admit it..
I probably didn't read the manual (RTFM!) for clock properly.... because the times i was getting back for my function calling didn't make sense compared to time stamped outputs!?
Clock() is returning time used by the program... i know - that didn't make sense, but it does if you mention the word threading.
See i was in a multi-threaded enviroment. So while this was timing my function in this "program" (ie thread!) my "program" had been running differently (in time) from other functions (ie threads!) that made up the entired module "ready" process.

Take 2. 

So instead, i used clock_gettime() with CLOCK_MONOTONIC.
This gave me a much better accuracy across my module insertion process, and started giving me numbers that made sense with other time stamped debug statements.

So.. using the following code,
#include <time.h>
#include <stdio.h>

/* Convert the timespec struct into a seconds value
static double TimeToSeconds(struct timespec* ts)
{
   return (double)ts->tv_sec + (double)ts->tv_nsec / 1000000000.0;
}

int main()
{
    struct timespec start, stop;
    double time_spent = 0;
    clock_gettime(CLOCK_MONOTONIC, &start);

    <YOUR FUNCTION GOES HERE>

    clock_gettime(CLOCK_MONOTONIC, &stop);
    time_spent = TimeToSeconds(&stop) - TimeToSeconds(&start);
    
    printf("your function time was %ld\n", time_spent);

    return;
}

Hopefully that helps someone with timing issues in threads etc.. lemme know if it works for you :)

Lastly - so i don't forget (possibly)... time stamping..
I'm just gonna post the code

time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf("Time Stamp is [%d:%d:%d]\n", 
        timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

All good fun :)



Graduated!.... now what.


So you've graduated.... now what.

So that time came and went where i finished up my degree and paraded in front of my family across the stage to shake the mans hand that had never met me and get that piece of paper that now says what i always wanted to say... I'm qualified

Qualified.. I find it strange term. Its a term that says to people you know what we want you to know. But when push comes to shove..... do you?
I think the answer to that is much like the exam post, you go to an interview, the interviewer asks you the questions that we all know the answers too. So i guess... Rope interviewing? hah...

So now i've been released into the real world, to find my place, to make my 'mark' as the educators have instructed us. We have given you all the tools... we have given you the best possible start.
Sometimes it feels like i got shown to the boat, given some wood, nails, hammer and saw, and pushed off while waving goodbye i look down to find all the holes in the bottom now appearing.