Wednesday, October 22, 2014

Is it English?

After recently changing jobs, I was given a major project to redo their website, written in Php, picking up where a contractor had left off.  I had warned them that my Php knowledge was all but nonexistent, but I was tasked to it anyhow, successfully deploying in about 100 days.

The experience taught me something--so long as the programming language is founded in English, there is no problem in learning it.  Php has similarities to C, so was pretty easy.

Tuesday, January 14, 2014

Windows 7 Streaming Media--resolution

Okay--I think I jumped the gun a bit.

Researching things, it looked like I should be able to run Windows Media Center and stream the TV data pretty easily.

But I couldn't get it to work, because I couldn't get that stupid "Turn on Media Streaming" button to work.  I tried everything recommended in all the Google search, and nothing worked.

But I finally found the solution, and it was about as stupid as it gets.  Why no one thought to recommend trying this first, I'll never know.

Solution: Run Windows Media Player as an Administrator.  Then select the "Streaming" and "Turn on streaming" selections.  Make sure you had the Network and Sharing Center closed before you started.  The button should work now.

All the other recommendations sounded crazy and nuts--like WMC and WMP simply got hosed up somehow.  But starting as an administrator makes sense--but it would have been nice if Microsoft was smart enough to have realized this necessity, or that their code was bugged and not properly identifying the need to run as administrator.  Yes--this is a bug that seems relatively common and yes--this is Microsoft's screw-up.

Okay--unless something new pops up--then my media streaming project is complete--I didn't really want to do this anyhow as it felt like I was reinventing the wheel.

TV Tuner Card to Media Streaming project, part 1

Okay, I don't use this blog much, and I probably should.  I originally intended this blog as a place to put great tidbits I learn--to make it easier for me to find in the future. If someone else finds this useful, then great--but otherwise, I really don't care.

So, in the interest of keeping track of things I find useful, I've got a new personal project I'm starting.  Maybe it'll come out to something useful, maybe not, and maybe it'll take forever for me to complete.  But here it is.  I've got other projects I've done for personal benefit that I haven't put any notice in my blog--I might start documenting my efforts in those in other blog posts.

Problem

I have a number of computers.  I have one high-end PC I built myself and one low-end laptop, both running Windows 7 64-bit.  My friend was kind enough to sell me his old PC and laptop for pretty cheap, both running Windows Vista.  I don't know much yet about their processing power, but I can already tell they are not any better than my low-end laptop.  But that's okay, and I am considering using the old PC for Linux.

On the high-end PC I have installed a TV Tuner PCI card.  Brand is irrelevant as there is no API for it.  I want to stream live TV from this tuner to any other PC or laptop on my network, and control the channels from the client PC.

Windows Media Center offered promise of being able to do this, but it does not look hopeful--and possibly overly complicated to get to work (although if someone knows a simple solution, I'm all ears).  I've tried enabling network media streaming, but the stupid button Microsoft offers doesn't do anything, and I've tried everything I've found in Google searches (deleting WMP libraries, uninstalling/reinstalling WMP and WMC, messing with the Windows Firewall)--nothing works.  A simple error message would speak volumes, but apparently MS didn't have the time to provide error messages here--better to simply draw users to a button that does nothing.  I found plenty of others experiencing the same problem--but no solution that works for me.

Anyway, that is the problem--stream live TV from the PCI tuner to another PC and control the tuner from the remote PC.

Solution

Doing this all through Windows Media Center would be great.  I found WMC to be a really nice application.  Easy to schedule recording, pleasing user interface, easy to pause (this was nice on live TV--neat new function for me to experience).  All these features are desirable to have on a remote PC.

What gets me is that the technology is all possible--it isn't even that complex compared to other features that are already available.

In fact, had I been smart, I could have purchased a network-based tuner instead of a PCI tuner and not had anything else to do.  But alas--I wasn't aware of the network-based tuners until it was too late, and I'm cheap--I don't spend any more than I have to.  Heck, I don't even have any premium TV service--it's a waste of money.  My TV is all over-the-air broadcast.

But nothing seems premade to do what I want.

And why even do this when there's Netflix and other internet solutions?  Well for one thing--I'm cheap.  I don't use any subscription services.  I'm so cheap that my internet access is limited--I have a good high-speed access, but cannot use more than 10GB a month--and I regularly run out on the last few days of every month.  Video over internet is simply not an option to me.

Maybe I am alone in this need, which would explain why I have not been able to find a pre-made solution.

So, to solve this problem, the best way is to break it up into parts.

Part 1 is the server, the PC with the tuner.  The Tuner video stream needs converted to a network stream.  Simple TCP/IP is easy.  But the true network solution will depend on the client, so the protocol used might not be so simple.

Part 2 is the client on the remote PC.  Ideally, Windows Media Center would be used, but that would mean being able to use a protocol that WMC understood--and at this stage I have no idea what protocols WMC or any other video streaming client uses or is capable of using.  Alternatives to WMC include VLC, or even building one from the ground-up.  I really don't like the idea of this last one, since WMC has such a good user-interface.  I hate building user-interfaces.  They're all grunt-work.  Don't take any brains--just artistic talent (of which I have none, nor any patience for).  I like building the engines.

For part 1, I found this DirectShow.Net library, which has samples for getting to the video stream of a tuner card and for changing channels.  It also has samples of video players that I should be able to build from, it WMC and VLC don't work out.  It doesn't matter if I can't control the card from WMC or VLC if those options work--I can always build a simple client that connects to the DirectShow.net library application I build on the server PC to control the tuner (I'd just invent a simple proprietary protocol for handling that--maybe use WCF, or just use standard System.Net stuff).

All the features that I need include being able to change channels and pausing the live stream.  Recording is moot--I can just use WMC directly on the server PC for that--the remote capability for this is irrelevant (except in the case of an ad hoc decision).  If I can use WMC or VLC on the client, they automatically have the capability of pausing, but they might not have the capability to change channels (which is where a special control client will come in).  If I have to spin my own client, adding pause might not be straight-forward.  To make this possible, then going from network stream to video stream, I really need to cache the network stream first, and a question is, can I cache to disk fast enough for the video stream to not have a problem.  The cache will need opened for read and write.  This will be a bit of new territory--I've only worked with full file streams over FTP protocol--I've never started a read on a stream while it is still being written to.  An additional complexity is to consider when the cache elements should be deleted.  In a worst case scenario, if I am watching one stream for hours--do I keep that stream untouched on disk the entire time (giving me the ability to restart from the beginning), or do I delete viewed parts of the stream after a period of time?  Since it would be easier to not deal with it, and since disk space is not really of concern, I would probably only purge the cache when the channel is changed or the client is closed, or the stream is stopped.  If recording is desired to be added to this custom client, scheduling should not be implemented, since it can be handled better in 
WMC.  Recording can be simply a matter of marking start and stop points in the cache and copying out the parts of the cache between those points.

Okay--a bit of rambling as my brain spills out.  My next task will be to drop the DirectShow library into a C# project and examine the samples.  After that, I need to figure out what the protocol is that WMC can use.  I already know that VLC can use a few different protocols, including HTTP, but its interface wasn't as pleasing, and it seemed a bit more difficult to configure for the stream.  Of course, I am the kind of person the firmly believes that if a manual is needed for basic functionality, then the product was not designed correctly.  You shouldn't have to use a manual to know how to plug a TV into the power outlet and where to put the video cable in and start watching your TV--a manual is okay for more advanced functions, but if the TV were so complex that you had to pull out the manual just to figure out how to give it A/C power, then the designer should face an execution squad.

But anyway, I'll post updates as I make progress on this project.  The updates may come quickly or they may be few and far between--it all depends on my success and how much time I devote to this.