1. Trang chủ
  2. » Công Nghệ Thông Tin

Apress - Smart Home Automation with Linux (2010)- P25 doc

5 161 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 216,88 KB

Nội dung

CHAPTER 3 ■ MEDIA SYSTEMS 98 ■ Note On first glance it appears wasteful for NAS1 to connect to Node0, only to be connected back to NAS1, but to scale up effectively, provide all media in a unified environment, and support dynamic changes in the media architecture, this is the best way to do it. The directory structure I use pulls together all the Samba shares like this: /net/homenet/slug1/media_tv and local disks like this: /net/homenet/mediapc1/usb2/media/movies into a hierarchy underneath /net/homenet as a number of links or Samba mounts. This is becomes a self-documenting report for the media server layout of home. I then create a series of links under the /net/media directory to hide the structure: ln -s /net/homenet/mediapc1/usb1/media/tv /net/media/tv ln -s /net/homenet/mediapc1/usb2/media/movies /net/media/movies ln -s /net/homenet/itx1/usb1/media/mp3 /net/media/music ln -s /net/homenet/slug1/usb1/media/videos /net/media/videos It’s then a simple matter of adding Samba shares for each directory: [media_tv] comment = Media (TV) path = /net/media/tv browseable = yes public = yes writable = no read only = yes guest ok = yes As in Chapter 1, I create basic Samba shares that are read-only for the family and create separate ones for me that are password-protected and read-write. Note also that I have used my home’s subdomain (homenet) as a delimiter from the rest of the directory, instead of placing everything in /net. It allows me, as a software developer, to create my own subnet that isn’t part of the general home automation network in case I need to do something risky or experimental! Media Extenders Once you have a file server providing access to your media, you then need some way of rendering the media, aurally or visually, to the world. This can involve stand-alone hardware, a Linux-based machine, or a combination of the two. CHAPTER 3 ■ MEDIA SYSTEMS 99 Stand-Alone Hardware To fit into this category, the hardware must connect the network, use DHCP to determine its IP address, and then stream the data from a file server to a physically connected TV or speakers. These devices invariably use Samba as a file server, since the installation of specific drivers (such as ZFS) is not a real- world possibility. Hauppauge MediaMVP This device, despite dating from 2002, can stream music, standard-definition video, and pictures across the network and display them on a TV. The retail unit is fairly cheap, small, and silent, making it an ideal head unit. It comes with just three sockets: power, RJ-45 Ethernet, and SCART. (The U.S. version expands this last socket to S-Video, composite video, and stereo audio.) To work, the MediaMVP needs three separate services: 6 DHCP, TFTP for the bootup procedure, and Samba for data since it has no storage facilities of its own. Out of the box, these services are provided by a piece of Windows software, which has a number of limitations such as a slow menu system. The machine also prevents you from viewing any video that isn’t MPEG1 or MPEG2 encoded. This is because the video signal is decoded by a custom chip inside the MediaMVP that only supports these earlier codecs. Fortunately, the protocols used by the MediaMVP to boot up are standard, enabling you to use Linux as a server. You can then take this a stage further by replacing the firmware that runs on the actual device, allowing it to connect to VLC to transcode your files to MPEG2 in real time. Creating a Server The bootup procedure of the MediaMVP is twofold. First, it sends a DHCP request asking for an IP address of its own and the address of a TFTP server. Second, it uses this TFTP server to download the firmware, which is what ultimately runs on the MediaMVP to become a media device. You begin by adding the configuration to /etc/dhcpd.conf: group { next-server 192.168.1.2; # IP address of your TFTP server host mvp { hardware ethernet 00:0d:fe:00:15:8D; # of the MediaMVP fixed-address 192.168.1.98; filename "dongle.bin"; } } 6 The word server is used in this context to denote a physical piece of hardware, whereas a service is for elements of software that provide access to data or resources on a server. Confusingly, the most common name for these services are things like e-mail server, web server, and so on. CHAPTER 3 ■ MEDIA SYSTEMS 100 The address need not be fixed; however, I’ve adopted a convention on my network indicating that any machine on my subnet with an address under 100 is a “house device,” such as a server or embedded hardware, and is not liable to change or move and therefore is always available. Everything 100 or greater is a computer that might be removed from the network or switched off at any time. From here, control is passed to the TFTP server, so the MediaMVP can request the firmware, given by the filename dongle.bin. TFTP stands for Trivial File Transfer Protocol, which is a very much simplified version of the usual FTP often used to copy files between machines. It’s installed as normal: apt-get install atftpd This will add the appropriate lines to /etc/inetd.conf and /etc/default/atftp, indicating the directory for file transfers (usually /var/lib/tftpboot). The primary distinction with TFTP from my point of view is that no username and passwords can be employed with TFTP. Although this might have made the programmer’s original job very much simpler, it was at the expense of security, meaning you should not open the TFTP port (UDP 69) to the world. You can then copy the dongle.bin file to the /tftpboot folder and switch on the MediaMVP. From here, it is a simple matter to replace dongle.bin with one of the other firmwares available to the MediaMVP, such as MVPMC, to provide improved functionality, such as real-time video transcoding or connecting with MythTV. MediaMVP Media Center This is probably the most fully featured alternate firmware currently available; it’s downloadable from http://www.mvpmc.org. It comprises a replacement dongle.bin and a configuration file. Since MediaMVP itself is running a small version of Linux, this configuration file is, conveniently, simply a script containing shell commands, which makes it very simple to make amendments to the firmware image without rebuilding it. At a bare minimum, it should contain commands to mount directories into the filesystem and invoke the main mvpmc program: mkdir /media mount.cifs "//192.168.1.110/media" /media -o user=mvp,pass=mvppass,rsize=34000; mvpmc & You can then add arguments to this command according to the extra functionality you want to introduce. I’ll now cover some of them. ■ Note It is not also possible to use anonymous logins from the mount.cifs command within MediaMVP, so create a separate Linux account on the computer running the file server (192.168.1.110 in this example). Since this username/password is visible in the configuration file and this configuration file is visible to anyone with TFTP access, you should make doubly sure it’s not visible outside your network. CHAPTER 3 ■ MEDIA SYSTEMS 101 Weather Reports This data is downloaded from the Yahoo! weather service and is rendered, with graphics, from one of the menu options on-screen. It needs to know where in the world you are located and that you have access to the Internet. For me, in London, this requires the following alternative line: mvpmc weather-location UKXX0085 & You can determine this code by visiting http://weather.yahoo.com, searching for your town or city, and grabbing the RSS feed. This will direct you to a URL such as the following: http://weather.yahooapis.com/forecastrss?p=UKXX0085&u=c where you will notice the city code (p=UKXX0085) and the units (u=c), allowing you to present the data in either Celsius or Fahrenheit. Video Transcoding The biggest problem with hardware solutions is their lack of upgrade path. Although MediaMVP provided a means of changing the firmware, the MVP hardware didn’t use a powerful enough processor to allow firmware that could decompress video in real time. Instead of converting all your past DVD rips into a suitable format, it is instead possible to convert the format on the fly (known as transcoding) while you’re watching them. This requires configuration of the MediaMVPMC and a transcoding server running VLC. In the first instance, you need to add the appropriate arguments that tell MVPMC the address of the transcoding server. mvpmc vlc 192.168.1.110 vlc-vopts dvd & Naturally, like every other server we’ve seen, the server involves only software and can exist on the same physical machine as the DHCP or TFTP server. However, because of the increased processing power necessary, you might want to run the transcoding software on a separate machine or your desktop. This allows you to have a small, low-power server running the main systems in your house, with the “big iron” being used only when necessary. ■ Tip The transcoding server only needs a CPU with reasonable specs, meaning an old stripped-down P3 or P4 can be fast enough. Making use of your desktop is often a good idea, because the transcoding won’t slow your work down since you’ll be watching a film at that time! CHAPTER 3 ■ MEDIA SYSTEMS 102 Depending on the speed of your transcoding server, you might not be able to manage the highest- quality images. By amending the –vlc-vopts to either SVCD or VCD, you can reduce the resultant quality to that of the Super Video CD format, or standard Video CD format, respectively. ■ Note The MediaMVP device itself only has hardware to output a standard-definition image. If you’ve been ripping your Blu-ray discs as HD files, then you will need to use VLC to transcode them into SD. It is also recommended that you use the use-mplayer command-line switch, which will switch to mplayer transcoding if VLC doesn’t understand the file format properly. The biggest caveat about using a transcoding server is that the filename being played by the MVPMC client software must be exactly the same as it appears to VLC running on the server. This can be arranged by the careful use of symlinks, since my media is mounted elsewhere on the disk and I have no desire to change it. I have therefore created a special folder in the root of my server with suitable links: mkdir /mvpmc_media ln -s /media/mp3 /mvpmc_media/mp3 ln -s /media/movies /mvpmc_media/movies ln -s /media/videos /mvpmc_media/videos I then replicated these on the MediaMVPMC by creating its own mvpmc_media directory and mounting the folders across the network: mkdir /mediamount mkdir /mvpmc_media mount.cifs "//192.168.1.110/media" /mediamount -o user=mvp,pass=mvppass,rsize=34000; ln -s /mediamount/videos /mvpmc_media/mp3 ln -s /mediamount/videos /mvpmc_media/movies ln -s /mediamount/videos /mvpmc_media/videos If you like, you can test your mount instructions by applying them dynamically while the MVPMC is running, since you can telnet into the MediaMVP hardware (username: root, no password) and issue commands directly. This process has another benefit since the filesystem browser on the MVPMC is very literal; whereas a directory entitled vids might be good enough for the geek who created it, a more descriptive title like Music Videos, replete with capitalization and spaces, would be appreciated by other home dwellers. Consequently, you can repeat the previous process using full names to achieve that goal without offending the sensibilities of your Linux naming conventions. ■ Note Although DVD VOB files can be played on this system, the DVD menus are not supported. . /net/homenet/mediapc1/usb1/media/tv /net/media/tv ln -s /net/homenet/mediapc1/usb2/media/movies /net/media/movies ln -s /net/homenet/itx1/usb1/media/mp3 /net/media/music ln -s /net/homenet/slug1/usb1/media/videos. is becomes a self-documenting report for the media server layout of home. I then create a series of links under the /net/media directory to hide the structure: ln -s /net/homenet/mediapc1/usb1/media/tv. Samba shares that are read-only for the family and create separate ones for me that are password-protected and read-write. Note also that I have used my home s subdomain (homenet) as a delimiter

Ngày đăng: 03/07/2014, 20:20