Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Sunday, March 2, 2014

CS50x

Late last year I signed up for CS50x from Harvardx on EDUx.

So far it's an interesting course. When I signed up I thought we only had 12 weeks to complete it, but it turns out we have an entire year. Which is great because I started a full-time job three days after CS50x started! I've been putting off writing about it, but I want to get started. My progress is slow, as I'm working 50+hrs/week and trying to keep up with everything else (car broke down the first week, then the truck, you get the picture).

I'm going to do a post on each Problem Set, and try to describe and explain the issues I ran into and how I solved them, without violating the cs50x policy of course (no complete solutions will be available here). Remember, I'm new at this, so my solution may not be the most efficient nor elegant by any means. But it should work.

Overview

The lectures have a lively feel to them and are available in many formats, I have been streaming the videos from the courseware page and occasionally downloading the mp3's to listen to on the way to work.

The shorts are really cool 5-10min explanations of things related to the course. Did you know that in ASCII to change from capital to lower case (and vise versa) only one bit changes? Yep, it was in a short.

The appliance is a virtual machine running Linux with a selection of tools to help you. I used virtualbox under Arch Linux, but it runs on Windows, Linux and Mac. It could be really slow on old or low-powered systems. it's a bit slow on my HTPC, but OK on my laptop. It took a while to get everything running smoothly, but that was mostly vitrualbox issues rather than appliance problems.

The problem sets start easy (scratch) and get harder really fast, but it's supposed to be a challenge right? There is a standard edition and a hacker edition, only the standard counts toward completing the course, so I've concentrated on them. I'll go back and do the hackers as time permits (or when I'm procrastinating on the final project).

The final project is a dilemma for me, so far all the ideas I've had fit one of these categories: too simple, too complicated, already been done, or not sufficiently interesting to me. Hopefully I'll come up with a good idea before I'm through with problem sets.

Links

http://www.reddit.com/r/cs50/
https://www.edx.org/course/harvardx/harvardx-cs50x-introduction-computer-1022

Saturday, September 14, 2013

Intel Hardware Video Decoding on Linux! VDPAU, VA-API, and Flash!

My laptop has a Core 2 Duo 2.4ghz CPU with an integrated Intel video chipset (GM45). It plays flash fine, but I wondered if I could get some HW decoding like the ATI. Here goes:

Intel supports va-api, not vdpau (required by flash) I'm running Arch on my laptop, so it may require some modifications to use on other distros (or it may not work at all).

Requirements

  • xf86-video-intel
  • libva
  • libvdpau
  • libva-intel-driver (only does mpeg2)
  • libvdpau-va-gl

Optional

  • libva-driver-intel-g45-h264 - replaces libva-intel-driver (in the AUR, it does h.264 on specific chipsets, but may be worse than software decoding)
  • vainfo
  • vdpauinfo

Setup

After the required software is installed "vainfo" should return the supported decoders. vdpauinfo will return an error. Create a file (as root) /etc/profile.d/vdpau_vaapi.sh containing:

#!/bin/sh
export VDPAU_DRIVER=va_gl

Save and add execute permissions (chmod +x vdpau_vaapi.sh). Log off and back on or execute the export command above and vdpauinfo should return the supported codecs. Then modify /etc/adobe/mms.cfg and uncomment or add 

EnableLinuxHWVideoDecode=1

Next in chrome://flags enable 

Override software rendering list

Now it should work!

Notes:

  1. This works with flashplugin (11.2). I haven't played with it much, but it doesn't seem to work with pepper-flash (11.8). It has lower cpu usage than 11.2 with EnableLinuxHWVideoDecode commented out in /etc/adobe/mms.cfg, but uncommenting it has no effect. Either it's looking somewhere else for that config or it doesn't support it. 11.2 drops way below 11.8 with it enabled.
  2. Obviously different chipsets support different codecs, some may not support any at all. The VA-API Wiki page linked below has some info to that end.
  3. The Chrome flag may improve overall performance or it may break things / slow things down. you'll have to try it and see.
  4. You can check chrome://flash and chrome://gpu before and after to see what changes.

Links

Thursday, September 12, 2013

ATI Hardware Video Decoding on Linux! VDPAU, VA-API, and Flash!

XKCD - Supported Features
I love that XKCD. Anyway, I built a HTPC / home server around a Biostar Deluxe A681-350. It is powered by a AMD E-350 APU that combines a dual core 1.6ghz cpu and an ATI Radeon HD 6310 gpu on one chip. It's a low end system, but I don't need a lot of power here. It handles full screen 1080i video from an ATSC tuner beautifully. It won't play 360p flash smooth at 1/2 screen, and it's a slide show at full screen (1920x1200). It just doesn't have the CPU to decode and scale video. Mythtv uses hardware scaling, so it only has to decode on the cpu, and ffmpeg's software decoders are well optimized.

Today I installed Arch Linux on it. This post was going to cover that, but I discovered hardware acceleration for flash on ATI chipsets works!

Comparison

  • With software decoding and rendering flash takes 60-75% of my total cpu time (windowed, scaled as large as smooth playback allows).
  • With hardware decoding and (possibly?) rendering it takes 10-25% and plays smoothly full-screen.

 Requirements

  • A very up-to date system. (Arch hasn't supported it long, most distro's will probably take some time to, but you may find a ppa or can always compile from source)
  • kernel 3.10+
  • mesa 9.2+
  • libvdpau
  • ati-dri
  • xf86-video-ati
  • flashplugin

Optional

  • vdpauinfo (print info about VDPAU (and show's it's working)
  • vainfo (same as above, but for VA-API)
  • libva-vdpau-driver (allows va-api enabled apps to be accelerated)
  • libva

Setup

Assuming you have installed all these packages vdpauinfo should spit out a bunch of information on what's supported. If it doesn't you may need to specify the driver. I didn't need to, but you might (shouldn't) need to add something like this to your environment variables:

VDPAU_DRIVER=

Flash probably won't work until you edit /etc/adobe/mms.cfg and uncomment the line:

EnableLinuxHWVideoDecode=1

I haven't tried it in anything but chromium, so I'll stick to that for now. In chrome://flags I had to enable

Override software rendering list

Now Flash should have hardware decoding! MythTV can be configured to use vdpau decoding and it works nicely too.

VA-API

(I haven't messed with VA-API much, so this may or may not work.) For VA-API it may be necessary to add the following to your environment variables setup. (you don't need this for flash, it only supports vdpau)

LIBVA_DRIVER_NAME=vdpau

One way to do this is create a file (as root) /etc/profile.d/vaapi_vdpau.sh containing:

#!/bin/sh
export LIBVA_DRIVER_NAME=vdpau

Save and add execute permissions (chmod +x vaapi_vdpau.sh . Log off and back on or execute the export command above and vainfo should return the supported codecs.

Notes

  1. It only works with the open source driver, though there is a way to get it in fglrx. (see https://bbs.archlinux.org/viewtopic.php?id=166593&p=1)
  2. Before "top" shows flash using 120-150% cpu. After "top" shows  20-50% (dual core = 200% max)
  3. This works with flashplugin (11.2). I haven't played with it much, but it doesn't seem to work with pepper-flash (11.8). It has lower cpu usage than 11.2 with EnableLinuxHWVideoDecode commented out in /etc/adobe/mms.cfg, but uncommenting it has no effect. Either it's looking somewhere else for that config or it doesn't support it. CPU usage under 11.2 drops way below 11.8 with it enabled.
  4. Obviously different chipsets support different codecs, some may not support any at all. The VA-API Wiki page linked below has some info to that end.
  5. The Chrome flag may improve overall performance or it may break things / slow things down. you'll have to try it and see.
  6. You can check chrome://flash and chrome://gpu before and after to see what changes.

        Links:



        Tuesday, September 10, 2013

        Arch Linux Fun

        I just installed Arch Linux on my laptop, because I apparently have nothing better to do. OK, that's not true, there are lots of things I "Should" be doing, but today I'm messing with Linux instead.

        Arch Linux with Cinnamon and an Awesome Wolf Background

        Live USB Boot 

        I hit a snags right off the bat. I installed the arch iso to a thumbdrive with unetbootin and it seemed unable to locate the media. Just sat there saying "Mounting '/dev/disk/by-label' to '/run/archiso/bootmnt'" and "Waiting 30 seconds for device /dev/disk/bylabel". After a brief search I discovered this was a common problem and the simple solution was to "dd" the image over your thumbdrive. Uh, what about the other files on there? Arch needs to work on this. I know Ubuntu and Parted Magic both fine from a unetbooting usb. So I hunted a bit more and found you can specify the right device as "archisodevice=/dev/sdb1" for example. Ha! too easy, if I specified it as sdb1 it would detect the usb drive as sda. Change it to sda and it's detected as sdb. WTF! Finally I set it to sdb1 and pulled the drive as soon as the kernel had loaded, plugged it back in and it booted right up. Whew, what a PITA just to boot a live USB!

        Installation

        The installation was complicated compared to Ubuntu or Mint, but I just followed the beginners guide and it went smoothly. Wifi worked and everything. I highly recommend a second computer / tablet / etc. on hand if you decide to install Arch. One reason I wanted Arch was the lack of junk cluttering up my system, things updating in the background, etc.I admit I install a bunch of junk myself, but at least I have some control. It took a couple hours, but I have a usable OS on my laptop. Lots more tweaking to do yet. Seriously, it took longer to get the usb to boot than install the system.

        Things I Like

        There are a lot of really nice features that appeal to me.
        • Boots unbelievably fast.
        • I'd eventually like to have a single distro on all my computers. With Arch you can do a headless server, a media center, a desktop workstation or a portable laptop. The base is the same, just install the packages you need for your application.
        • A local package cache / repository on my HTPC / Server would be cool. Most distro's can do that, so I don't know that this is a major plus, but it's availible.
        • I don't mind the pacman / apt-get / emerge command line tools, but synaptic is slow, and the "linux app store" doesn't appeal to me. So far I love yaourt when used with yaourt-gui, a bash gui for yaourt. It take a little fiddling to get installed, but it will manage pacman, AUR, etc. quickly and beautifully.
        • The AUR, it's huge! if you can't get an official package, it's probably in the AUR.
        • Arch doesn't hold your hand with tons of helper scripts to make everything "just work". While that can be good or bad, I'm counting it a good, as you get a better understanding of what's going on right from the start. That (hopefully) makes problems easier to solve later.
        • It's more up to date. I loved this about Gentoo, that you had recent packages. I installed MyPaint, because it works nicely with my laptop's Wacom penabled screen, and there are all kinds of buttons and options that weren't there on Ubuntu! Ubuntu has 1.0.0-1, Arch has 1.1.0-2.
        • Rolling release. In theory once installed I should never need to re-install. just update the system when I feel like it.
        • No "Update Manager" nagging me to update all the time. I hate windows for it's constant updates (always at inconvenient times) and some Linux distros seems to want that "functionality" too. It's running in the background without my knowledge too, I don't like that.
        • No "error reporting" pop-ups I get too many of these for a supposedly stable system, I understand the need for error reports, but I'm watching a movie and have to get up to get that dumb window out of the way.

        Things I Don't Like

        • Arch is MUCH more complicated to install as opposed to Mint or Ubuntu. It didn't take me that long to have a working system, but I wouldn't recommend it to a beginner or at least not as an introduction to Linux. I used to use Gentoo, which I feel is even more complicated, but just didn't have the ambition to keep it working.
        • The installation ISO really sucked for me, YMMV.
        • I have a working system, but it's not nearly as pretty or complete as Mint 15 yet (I installed Cinnamon). I foresee a lot of tweak time to get it just the way I want. This may lead to frustration, like Gentoo years ago. I dropped Gentoo because, at the time, it took a ~3 days of compiling to install the base system and get X running with the basics (Firefox, Fluxbox, file manger, etc.) and the better part of a week for a full desktop environment (KDE at the time).

        Conclusion

        So far I like what I see. The install was a bit aggravating, but I shouldn’t have to do that too often. I love yaourt-gui, it really makes package management quick and easy.
        I think I'm going to swap my HTPC / Server over to Arch eventually. I have some performance issues with Mint 15 and haven't been able to track them down. I don't know if it's Mint or just the my hardware. Either way I hope I can squeeze a little more out of Arch.
        If you have an excess of free time try it, it's easier than Gentoo and you end up with a distro that's tailored to you. All the stuff you want with none of the stuff you don't.

        Links:

        Arch Linux - https://www.archlinux.org/
        Yaourt - https://wiki.archlinux.org/index.php/Yaourt
        Awesome Wolf Art Source - http://www.deviantart.com/art/wolf-324819837

        Wednesday, June 5, 2013

        Linux Mint 15 and Amazon Video (This also affects other video sites)

        I just bought a new drive for my HTPC, A 3tb WD Red, but that's for another post. I had Amazon video working on Mythbuntu (just had to install HAL) but installing HAL on my (fairly) fresh new Linux Mint 15 install didn't work. I finally figured it out, with some help of course

        What I've found:
        1. Amazon's error is completely useless. It makes you think that you have the wrong version of flash.
        2. If you haven't already, you need to install hal and libhal1 "sudo apt-get install hal libhal1"
        3. Adobe has a guide for sorting out these problems once you figure out it's DRM related. Here the test page was the most helpful.
        4. The test page gave me the cryptic error 3322 - device binding failed. 
        5. I tried the solution found here, "rm -r ~.adobe/Flash_Player" it didn't work, but was needed later, after I actually fixed the problem
        6. It turns out HAL wasn't starting, I ran "sudo hald --daemon=no --verbose=yes" it spat out a bunch of errors and died. I found the solution here, I'm not sure it's a perfect solution, but I ran "sudo rm -r /etc/hal" then "sudo ln -sn /usr/share/hal /etc/hal" and HAL runs! I think I will copy rather than link it at some point, but that's what I did.
        7. I rebooted and the test page still doesn't work, I had to do step 5 again, now it works.
        Whew, only took me half the night to figure that one out.

        Notes:
        I tried this on Linux Mint 14.1 and just installing HAL worked, I couldn't reproduce the problem on 15 by removing the /etc/hal directory. It's possible I corrupted something at some point, I'll try on a clean Mint 15 install sometime and report back.

        I also got a 3323 error while HAL was broke, also fixed with #5.


        Update: Only steps 2, 5, and 6 are necessary to solve the problem, the others are either diagnostics or irrelevant. (Thanks Douglas Roberts!)

        Update 2: This affects other sites (Thanks NikAmi!), I don't really have the time to determine which ones myself, so I'll do a list and update it if anyone finds one that needs it (Post it in the comments). It may help someone else.
        Known Sites Also Affected:
        NBC Sports

        Update 3: There is a package available (at least in Arch Linux's AUR) called HAL-Flash that lets you play DRM Flash content without needing the HAL package / daemon. I'm using it on both my laptop and HTPC and it seems to work fine.

        Update 4: Chromium no longer supports NPAPI (netscape plugin API), pepper-flash doesn't work with protected files. Firefox still uses NPAPI and works with Amazon Prime Video. HD doesn't seem to work for me, but SD works fine. I'm not sure why.