TW68xx Driver for Linux

[Added May 2012]


I get a steady (if thin) stream of people coming here searching for Linux drivers for the Techwell 68xx video chip family. If you are one of these people, I have added this section for your benefit. Here are the details:





Possum TV Live Server - Hardware


The original idea was to install a video input card into an old computer and set this up as a simple webcam server. This was one of those ideas that are good in theory but don't work out in practice. The problem with this was that the old computer I had available had very little RAM and it used the 440BX chipset. It turns out that this chipset is very fussy about the type of RAM modules it will accept, and for less than the cost of upgrading it to its maximum capacity of 768 MB of RAM, I could get not only a new (albeit entry-level) motherboard, but also a new CPU and 2 GB of RAM. An additional reason to build from new parts is that much of the new equipment available is considerably less power-hungry than the older stuff. Power consumption is a particular concern with a server that's running continuously; quite apart from any environmental considerations, the extra cost of a new motherboard could easily pay for itself in terms of power used over the period of a few years. [Consider this: if your server draws 100 W and you pay 20c/kWHr for power, it'll cost you $175/yr; you can get a new motherboard for less than half of that.]


Once I decided to go with new equipment, a sort of feature creep set in. Why go with a $50 motherboard and a $100 Celeron when with a $150 motherboard and a $200 Core-2 processor you could get the latest (at the time) 45 nm technology that's not only majorly fast but also much more energy efficient? And why go for a small hard disk? In terms of $/GB, the bigger the disk, the more economical it is and I might well want to record video to disk, which means the more storage space the better. And if we're going to build a good system, why not put it in a nice case?


I ended up going with the hardware described below:




Gigabyte GA-EG45M-DS2H Motherboard Item: Motherboard

Manufacturer: Gigabyte

Part Number: GA-EG45M-DS2H

Details: micro-ATX form factor, LGA775 socket, G45 northbridge, ICH10R southbridge, 2 x PCI 2.2, 1 x PCIe X4, 1 x PCIe X1 slots, Gigabit NIC, etc.


I chose Gigabyte mainly on account of the "dynamic energy saver" feature, but also Gigabyte generally has a good reputation for quality. This specific motherboard was chosen because it has a recent chipset, was relatively inexpensive and features an integrated video controller. Integrated video means lower power consumption because you don't need to run a separate video card. The only issue I had with this motherboard is that it required the very latest version of the Linux kernel to support the ethernet and video controllers. This can hardly be said to be a defect, but it did make my life a little more difficult at the time. Other than that, I've had no problems with the board and I'm very happy with it.


Recommendations: I would still personally choose Gigabyte motherboard, although I have nothing against any other brands. What you need to look for is the following:


  1. Choose as late a model board as you can (generally more efficient and better features).

  2. Ensure it has the right slots to fit whatever video input board(s) you get.

  3. A smaller motherboard will generally use less power than a larger one, so don't get one any bigger than you need. Micro-ATX is usually a good size, however it would be possible to go down to a mini-ITX with care.

  4. Getting the most expensive board will generally get you a gaming board, which means you're paying for features you don't need. Generally, if it supports overclocking, it's a gaming board, and you would usually be better choosing something else. OTOH it's not actually harmful to use such a board.

  5. Check the CPU socket corresponds with whatever CPU you've chosen. They change these damn things seemingly every six months, so take care.

To save power, and reduce compatibility problems, go through the BIOS settings of the board and turn off everything you don't need.




Intel E7200 CPU Item: CPU

Manufacturer: Intel

Part Number: E7200

Details: 2.53 GHz Core 2 Duo, with active cooling


This is a dual-core 45 nm chip and is significantly more energy efficient than the older 65 nm processors. It was chosen on a value for money basis; there are steeply diminishing returns, in terms of speed per cost, in going to a more powerful CPU.


I've had no problems with the CPU. Under normal operation, CPU usage is 4-5% (i.e. 8-10% of one CPU), rising to a maximum of a bit under 25% when streaming video for six boxes simultaneously. No need for overclocking or turbo cooling fans with disco lights here since this is a web server and not a means of compensating for personal inadequacies. ;)


Recommendations: I personally prefer Intel CPUs, because they're generally more power efficient than the equivalent AMD CPU (however these things change over time and this statement may not be true indefinitely).


With a system of this type, the CPU requirements aren't especially heavy (unless you're going for a lot of high resolution cameras), and you're better going for a small, energy-efficient, CPU than a more powerful one. With Intel processors, this would be an i3, and, if possible get one with a T suffix; this means it's purpose designed for low power consumption.


Always choose a CPU with the most modern fabrication process. Check for the number of nm (nanometres), and choose the smallest. Currently (as at 2015) the best available is 14 nm.




Kingston KVR800D2N5K2/4G RAM Item: RAM

Manufacturer: Kingston

Part Number: KVR800D2N5K2/4G

Details: 2 x 2 GB 800 MHz DDR2


Kingston RAM has a good reputation and is not too expensive. I chose 4 GB because I was going to use 32 bit Linux, so installing any more would mean enabling PAE (Physical Address Extension). Not that this is a big deal, but it involves a slight (<1%) performance hit and you have to draw the line somewhere and this seemed to be a logical place to do it. Currently, the server has never used all of this RAM.


Recommendations: The latest CPUs (as at 2015) use DDR4, which is more power efficient than DDR3 (which is in turn more efficient than DDR2). I would get RAM that has a speed rating equal to the highest (non-over-clocked) speed supported by the motherboard. I still think that 4GB is an appropriate quantity of RAM to have, however you may need to go to 8GB, because you will usually want to install two separate RAM modules to get the highest speed, and it can be difficult to find RAM modules smaller than 4GB in DDR4.


Double-check with the motherboard documentation to ensure the RAM modules you choose are suitable for it.




Seagate ST31000340SV Hard Disk Drive Item: Hard Disk 1

Manufacturer: Seagate

Part Number: ST31000340SV

Details: 1 TB SATA II 7200 RPM 32 MB Cache


The SV suffix means this disk is supposedly optimised for Streaming Video applications (although it's not obvious to me what this involves). This was a comparatively expensive item and 1 TB was more memory than I thought I needed at the time, but my justification was that a) hard disk space is the first limitation you always seem to run into on a PC and b) on a $/GB basis the drive was cheaper than lower capacity ones. Seagate also produce a 1.5 TB disk, but I was swayed by the fact the SV disk is (supposedly) specifically designed for the purpose I intended to use it for.


Western Digital RE4-GP Hard Disk Drive Item: Hard Disk 2

Manufacturer: Western Digital

Part Number: WD2002FYPS

Details: 2 TB SATA II 7200 RPM 64 MB Cache, IntelliPower


In February 2010, when I upgraded the server, I decided to install a new hard disk. This was partly to simplify the upgrade process, partly to get more storage space and partly because the new drive is an energy-saving model which uses considerably less power than the previous one. I chose a Western Digital RE4-GP. On paper, this is a pretty good drive: high reliability (1.2 M hrs MTBF), low power consumption (6.8 W versus 9.8 W for the Seagate, which is already a fairly energy-efficient drive) and high capacity.


Recommendations: I would recommend at least a 2 TB disk; my cameras can easily generate over 1 GB of files per day even with just a couple of boxes in use and you won't regret getting a large disk. Be aware that there may be issues in using a hard disk greater than 2 TB in size. Apparently a partition greater than 2 TB can't use a standard MBR (Master Boot Record), but instead needs a GPT (GUID Partition Table). This in turns requires a motherboard which uses UEFI (Unified Extensible Firmware Interface) BIOS, as well as a bootloader which supports a GPT. Also, you have to choose a file system that supports partitions this large, which means (if you are using Linux) it's probably better to use ext4 or XFS rather than the more common ext3.


Pretty much all modern motherboards should support UEFI, but check for this anyway if you're going for a disk over 2TB.


There's a bit of dilemma with choosing a hard disk. On one hand, you'll want a power-efficient one, because it will be spinning almost constantly. On the other hand, you'll want one that's reliable, because obviously you won't want to lose your recordings, and even if you back them up, reinstalling everything will be a huge pain. The trouble is that high-reliability disks tend to have particularly high power consumption (the RE4-GP disk I currently have was an exception to this, but these are no longer available anywhere). You can use RAID to increase reliability, but this immediately doubles your power consumption.


At this stage (2015), I would probably go with a Western Digital "Purple" disk. These are intended for video recording and have moderately good power consumption. The reliability figures aren't as good as the top-of-the-range drives, so I'd suggest frequently backing up recordings, and ensuring you have a disaster-recovery plan ready in case the disk fails (but you should do this anyway, because even the best disk can fail).


Don't be too hung up on brand name when buying a hard disk. There are people who have experienced a bad batch of disks from one manufacturer and will vocally preach that that brand is no good. This is not a valid conclusion—it's like saying that all people with brown hair are obnoxious because once someone with brown hair was rude to you. All major manufacturers (Seagate, WD, Hitachi, IBM etc.) make good disks. Occasionally one batch, or even entire model, of disks has problems and should be avoided, but this happens to all manufacturers. None are significantly worse than the others. The moral is to look at the specs (and if possible reputation) of the individual model of disk you are considering, and ignore the manufacturer.




IEI IVC-268G Video Input Card Item: Video Input Card 1

Manufacturer: IEI

Part Number: IVC-268G

Details: PCI bus, 4 x composite video + 4 x audio in + 4 x GPIO, 1 x TW6802 video chip per channel.


The video input card was the biggest problem I had with the system. I first purchased an IVC-268G video input card from IEI. On paper this is a really good card. It has 4 A/V channels each with its own TW6802 decoder chip, as well as GPIO. However it suffered a couple of unfortunate problems. Firstly, there was an undocumented set of jumpers on the board which would shut down the PC power supply on overload (!) when left at their default settings. When I contacted the manufacturer, they told me the card was PCI 2.1 only, and wouldn't work in a PCI 2.2 slot, which is plainly nonsense. I managed to find the right jumper settings by trial and error. A more annoying problem was that the card lacked a usable Linux driver. It was advertised as coming with a Linux kernel 2.6 driver, but what they didn't make clear is that it only worked with kernel version 2.6.18. This made it useless in my case as my hardware required at least 2.6.25 kernel.


Fortunately, the open source community came to my rescue, saving me from having to rewrite the driver myself (which, although possible, would have been a major exercise given my limited knowledge of Linux). It appears that TW680x chips are used in quite a few different video input cards, and there are a number of people around the place working on drivers. Eventually I was very generously sent a preliminary copy of a driver someone was working on - although it was only what you would call an alpha release of a generic TW6800 driver, it ran reliably for over a year before I upgraded to a later version.


Osprey 100 Video Input Card Item: Video Input Card 2

Manufacturer: ViewCast

Part Number: Osprey 100

Details: PCI bus, 3 x composite video + 1 x S-video inputs, BT878 video chip.


As a stop-gap measure while I was looking into drivers for the IEI card, I purchased an ViewCast Osprey 100 card. This is a very basic video input card and comparatively old technology, but in consequence it's proven technology and has been supported by Linux for a long time. The only problem with the Osprey stems from the fact that all of the video inputs are multiplexed into a single BT878 video chip. This means that it works well with a single camera, but with two cameras the frame rate is halved and you get jerky, jumpy movies. Also, the brightness pulsates, presumably due to the AGC in the chip not being able to keep up with the rapid switching between cameras. When I added a third camera (which, to make matters worse, was a different type with different video signal levels) it became effectively unusable. The brightness strobed strongly enough to trigger motion detection.


I need to add that I'm not criticising the Osprey card here. It's the bottom-end of the ViewCast range and it works great with a single camera and would be OK with multiple cameras if used for low frame rate time-lapse films. It only misbehaves when it's pushed beyond what it's designed to do.


PV-987-4 Video Input Card Item: Video Input Card 3

Manufacturer: Provideo

Part Number: PV-987-4

Details: PCIex1 bus, 4 x composite video + 4 x audio in, 1 x TW6805A video chip per channel.


A third video input card was added in February 2010 to cope with the expanding number of boxes. I decided to try out a different manufacturer because of the annoyances I'd experienced before. Unfortunately, it wasn't a case of "third time lucky"; this card didn't work with the TW680x driver I had installed at the time. I had to upgrade the driver, but the new driver used 4VL2 API elements that only been introduced in kernel version 2.6.28 and, as Murphy would have it, I was using 2.6.27.


The end result is that I had to rebuild the whole Linux system, which took around 3 days of work, but overall it was worth it because it gave me the opportunity to clean up and upgrade a lot of other things.


Recommendations: If you are from Australia, the video input card will be your biggest problem; in this country there is a much more restricted range of cards available than in other countries, and they are much more expensive. Although the cards I have all work OK, I wouldn't specifically recommend them over anything else, and I'd suggest you shop around. I would definitely consider buying from overseas via eBay. Things I would suggest:





Lite-On IHAS120 CD/DVD Read/Write Item: CD/DVD Drive

Manufacturer: Lite-On

Part Number: IHAS120

Details: SATA II CD/DVD Read/Write.


You need something to boot the off for the initial setup and also for recovery purposes. It wasn't strictly necessary to have write capability on this drive, but the extra cost was minimal. A very superficial, but still somewhat annoying, issue was that this drive came with black and beige front plates only and both of these looked out of place on the otherwise very stylish aluminium front panel of the case. As the server initially lived in our living room, I had to apply a little silver spray paint (which sounds cheap and nasty but it actually came out quite well) to make it presentable.


Recommendations: I would probably just get a USB CD Drive and plug it in when needed.




Antec NSK2480 Case Item: Case/Power Supply

Manufacturer: Antec

Part Number: NSK2480

Details: micro-ATX case with earthwatts 380 W power supply.


This case is intended for HTPC (Home Theatre PC) applications. It's fairly low cost and looks good; it's intended to sit alongside stereo equipment in your living room. The power supply is fairly efficient (supposedly around 83%+).


A couple of minor annoyances: Firstly the power supply has only two SATA power connectors, and these are both on the same cable and too close together to connect to both the hard drive and CD ROM at the same time. Secondly, despite the provision of air flow directors and a plate for blanking off fan outlet holes, it wasn't possible to set up the case air flow to work in what I would consider a logical and efficient manner (this is quite a common problem that I've also seen on very much more expensive cases). The first issue was fixed by purchasing an extra SATA power cable. The second issue is only a theoretical problem since the system doesn't put out much heat anyway.


Recommendations: As far as the case goes, a bigger one is generally better since they run cooler and there's more room to route cables. Also bear in mind that some video input cards use up extra slots on the back panel for extra connectors. The IVC-268G card, for instance, takes up 3 slots on the back panel if you use the audio and GPIO options. If you've got more than one video card of this type, a full ATX case, which has seven slot covers is much preferable to a micro-ATX which only has four.


Regarding the power supply, there have been considerable advances since the server was built. At that point you were lucky to be able to get an 80+ power supply of any type. These days not only are there a large number of 80+ supplies available, but they are officially graded according to efficiency, as per the following table. (You will notice that "80+ Green" is not officially defined. If you see a power supply with this label, it is likely to be an inferior unit and you should not buy it.)


ColourMinimum Efficiency at 50% load
(none)80%
Bronze85%
Silver88%
Gold90%
Platinum92%
Titanium96%

At the present time (2015), 80+ Gold and Platinum supplies are readily available at a reasonable price, however, there's a problem: most of these have high power ratings. Power supplies reach their peak efficiency at around of 50% load and can drop off in efficiency quite sharply below about 20%. Your system might only draw 40 W, so an 800 W power supply would be running a 5% load. The 80+ certification doesn't specify any particular efficiency at these levels. For instance, the Antec EA-550, which is an 80+ Platinum supply, was measured at 83.2% efficiency at 10% load.


Really, it's very annoying. It's difficult to get a power supply below 300 W in capacity and with these you'd be lucky to find one with even a Bronze rating, and you're still going to running it at under 20% load. At this stage, I'd suggest a Seasonic 400W 80Plus Platinum Fanless or an Antec EA-550 (550W, 80+ Platinum) as the least bad options.




Network


Bandwidth


The Achilles heel of the system is the uplink. Internet access is via a standard cable plan. The downlink speed is good, but the uplink is much slower. Currently the uplink works at up to 1 Mb/sec, which is a great improvement over the 128 kb/sec I was getting when the I first set up the system, however it doesn't always achieve this speed and the bandwidth is shared with whatever else I'm doing on line at the same time. With the current setup, video streams at perhaps 800 kb/sec, i.e. a single user viewing a possum box uses perhaps 80% of my upload bandwidth.


There is limited scope for reducing the bandwidth usage. Streaming is done using "multipart jpeg" format, because that's all my software supports. This format has the advantage of simplicity and is well supported by most browsers, but it isn't as efficient as a proper video format. It's not clear to me the extent to which a proper video format can actually be used for live streaming video anyway; for example, you can't do stuff like two-pass encoding because that would require access to video that hasn't been recorded yet.


Initially, I allowed streaming video on the local network, but blocked it at the firewall. However, when Kiki brought her baby into box 7 in August 2013, I decided this was being unfair to my viewers and opened up full streaming video to the world. So far, this hasn't caused any problems.


As a fall-back position if the steaming video isn't working properly (i.e. too many people watching or bad network conditions), I also have available an old-fashioned webcam interface, with a JPEG that gets updated every couple of seconds. This means you miss out on the action but at least you get relatively good-quality live pictures and only use about a tenth of the bandwidth.


Domain Name


Another issue is that the cable modem has a dynamic IP address. This means that in theory I should be using a Dynamic DNS, however I am not currently doing this. Currently I have the domain possum.tv hosted by VentraIP (who I recommend), and I update the IP address semi-manually. That is to say, I have a script that periodically checks the site external IP address and sends me an email when it changes. I then log in to my domain hosting and change the DNS records.


When I first set up this site, I tried to do things the right way by getting a free account with DynDNS and using the domain possum.dyndns.tv. This worked but was never satisfactory. There was a problem with the DDNS update client in my router (I believe there was a race condition with the cable modem) which would occasionally cause the wrong IP address to be sent to DynDNS after a power outage. This lead to the site going off-air until I discovered there was a problem and fixed it. This actually happened more often than changes to the IP address, so I actually would have been better off not using a Dynamic DNS.


Over the subsequent years, DynDNS became more and more unfriendly to its free account holders. First they eliminated wild-card domains, then they forced you to log in monthly, finally they eliminated free accounts altogether. It was obviously possible to move to a paid account with DynDNS, however, firstly I don't want to support a company that has acted in an arguably deceptive manner (essentially like the stereotypical drug dealer giving out free samples, then charging through the nose when the user is hooked), and secondly a Dynamic DNS is (in my case) more of a hindrance than a help anyway.