Watch ANY Online Videos/TV (PPStream, PPLive etc) on TV via DLNA

Sometimes, we can’t get the streaming source for online videos, TV shows, and Live TV so as to send it to TV via DLNA using a DLNA server such as TVersity.

For online TV like PPStream, PPLive, these popular Chinese online TV software, there were some methods introduced using VLC: Link 1Link 2, and Link 3. The idea is this. VLC captures the online streaming, and generates a secondary streaming, which is taken by TVersity and shared on the local network. But it seems none of these works for me for uusee, pplive and ppstream, since I can’t find the streaming source for these software.

Streaming the whole screen will be an ultimate method that can work with any media source via DLNA streaming.

More details about VLC and TVersity can be found here: https://alenblog.wordpress.com/2011/04/21/stream-computer-desktop-to-tv-using-dlna-tversity-and-vlc/ and https://alenblog.wordpress.com/2011/04/07/tversity-dlna-for-samsung-tv/.

Here is how it’s done.

VLC can capture the screen using screen://. But it turns out it can’t capture audio simultaneously using input-slave: dshow://. The workaround would be to use DirecShow with a directshow filter, such as VH Screen Capture.

VH screen captures video or audio only in MP4. But both captured, video is not shown, even though MediaInfo shows video data is stored. For DIV3+MP3 (asf), VH can’t see video at all, even though video data was also stored. Without transcoding, output .asf file is fine. But the data file is so big, and VLC crashes soon. The picture captured in MP4 are really great. It’s the best picture I’ve got compared to other ways mentioned here.

UScreenCapture works fine with DIV3+mp3(asf) and MP4. But the picture quality is a lot worse, even if using larger BitRate and generate big data file. Anyway, for the time being, by using directshow (UScreenCapture), video and audio can be both captured.

Another problem is my SoundMax HD audio sound card doesn’t have Stereo Mix. So I use a stereo audio cable to connect my speaker and mic ports, sending sound from the speaker to mic directly. VLC captures the audio from the microphone.

If you can see your screen, but not the video, you may need disable the hardware accelaration, which can be found at the property of your graphics.

I make the streaming using the VLC GUI. I select the video and audio sources, transcode it to DIV3+MP3, 25fps, 4096 kbps, and then stream it to mms://127.0.0.1:1234 or http://127.0.0.1:1234, which is further shared by TVersity. Then I can watch on my Samsung HDTV anything on PC. It works great, particular for PPStream that I use it very often.

This way, I don’t need worry about that the media type for TVersity or Samsung TV any more. Whatever I can see on PC, I can see it on TV.

** When using VLC, try to transcode with some codecs that are natively supported by your TV. Then TVersity doesn’t need do another transcoding. That will work much better.

Advertisements

Run two Matlab functions simutaneously in parallel

My friend gave me a project: run two matlab loops (can be put in two functions) simultaneously. They have to be synchronized. They have to start at the same time, and they have to synchronize every step in loop. The problem was simplified because the two loops with run with a fairly stable step size. So what I need do is to start the two functions at the same time with error less than 0.1ms.

To run two matlab functions, we need parallel computing, or simply use two matlab sessions. For two matlab sessions, we need make a feedback in one session to trigger the other session. There are different ways to make the trigger.

1. Use hard drive to communite between two session is one way. Basically, we need first initialize a start.ini file with -1:

fid=fopen('start.ini','w');
fprintf(fid,'%d',-1);
fclose(fid);

Then one session start function 1 and write 1 to the ini file:

fid=fopen('start.ini','w');
fprintf(fid,'%d',1);
fclose(fid);

In the other session, it keeps checking the ini file, it starts once it reads 1.

while 1
    fid=fopen('start.ini','r');
    k=fscanf(fid,'%d',1);
    fclose(fid);
    if k==1
    %-------- reset start.ini to -1 start ---------------%
        fid=fopen('start.ini','w');
        fprintf(fid,'%d',-1);
        fclose(fid);
    %-------- reset start.ini to -1 end ---------------%
        break
    end
end

This works in a lot of scenarios. Here the problem with this is it takes a few milliseconds, and it fluctuates. So this is not a good solution.

2. Use a shared memory. Ram should be faster than Hard Drive. Basically, we can have one session write a variable to the memory, and have the other session read it, just like writing and reading from hard drive, but faster. The problem is two matlab sessions use two separate workspaces residing in different memory locations, not shared.

Actually, if we could, creating a shared variable in CPU cache (register) is the fastest way to read and write a variable for a computer. But I can’t find anything in matlab about that.

There is method called DDE (Dynamic Data Exchange) that makes different applications communicate.  But I didn’t find anything that can make DDE work between two matlab session.

Then I found a matlab program sharedmatrix on mathworks: http://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix. This program creates a memory block that will be shared by two matlab sessions. I managed to compile it in Matlab 2010a and Ubuntu. But I can’t make it work. This program seems very unstable. When the second session read the shared memory, matlab crashes. So I gave up this method.

There are other methods to make the feedback, but I can’t think of a way that can really solve my problem.

3. Use parallel computing

Another method to make the synchronization is to use parallel computing. A more detailed post can be found here about parallel computing in matlab: https://alenblog.wordpress.com/2011/03/31/parallel-computing-in-matlab/.

Basically, we can have two threads that can call two functions simultaneously. The traditional multithreading is actually through time division. So the time actually not synchronized for the two functions. But I’m not sure what the time difference is. I found a post here, where basically some codes were written in c++ for multithreading, it can be compiled in matlab to MEX file, and then be called. But like in the comment, I got same errors when compiling:

mex mythreadprog.cpp

Error mythreadprog.cpp: 11 syntax error; found `MyThread’ expecting `;’
Error mythreadprog.cpp: 19 redeclaration of `mexFunction’ previously declared at .\mex.h 135
Warning mythreadprog.cpp: 23 assignment of pointer to void function(pointer to void) to pointer to int function(pointer to void)
Error mythreadprog.cpp: 33 syntax error; found `MyThread’ expecting `;’
Warning mythreadprog.cpp: 58 missing return value
Error mythreadprog.cpp: 33 undefined size for `void cdecl’
4 errors, 2 warnings

C:\PROGRA~1\MATLAB\R2007B\BIN\MEX.PL: Error: Compile of ‘mythreadprog.cpp’ failed.

The new multithreading parallel computing using multi-core computer is built in recent matlab versions and can really do the job.

I found different ways to do parallel computing in matlab. The way posted here is using parallel computing, but it doesn’t make the synchronization. The code is shown below:

 
funList = {@fun1,@fun2,@fun3};
dataList = {data1,data2,data3}; %# or pass file names 

parfor i=1:length(funList)
    %# call the function
    funList{i}(dataList{i});
end

Finally, I got a way using matlabpool open two labs, and use spmd to run two functions in two labs separately. labBarrier is used to synchronize the two labs. The code is shown below.

function data = main

struct data1 data2;
data1.x = 1;
data2.x = 2;
funList = {@fun1,@fun2};
dataList = {data1,data2}; % or pass file names 

matlabpool open 2
spmd
    labBarrier
	funList{labindex}(dataList{labindex})
end
matlabpool close

function y = fun1(data1)
time1=clock;
fprintf('%02d : %02d : %02f\n',time1(4),time1(5),time1(6))
labindex
pause(5)
disp('run f1');

function y = fun2(data2)
time2=clock;
fprintf('%02d : %02d : %02f\n',time2(4),time2(5),time2(6))
labindex
pause(5);
disp('run f2')

We can see the two functions are starts at the same time. But the clock command only shows to the accuracy of 1ms.

Stream computer desktop to TV using DLNA, TVersity and VLC

1. What’s going on with TV?

People want their TV with more features, like internet ready, apps, web browser etc. All these extra features are basically already there on computers. Now they want a combination. Basically they want a computerized TV or a TV = TV + PC + Internet.

This is exactly what happened in the handset/phone field, Phone = game player = Handset/PDA = GPS = MP3 player = Video player = Camera/Camcorder = Book reader = Photo frame = web browser = Email browser = … = Computer! This is revolution. One is everything. Basically one thing is a PC that can of course install a lot of apps and has WIFI with extra physically dedicated features such as phone, camera, gps.

This is what’s happening now in TV field. TV companies put a dedicated board (a computer) inside their TVs to make theirs TV = TV + PC. Apple, google make some dedicated box (a computer) sitting beside the TV. Question is why bother making new things, why not just buy a netbook or any cheap desktop PC and connected to TV? The reason is this. A dedicated unit is fancier, and it can be made small, fast, and even put inside TV. It can be made so because it is only used for TV, so it doesn’t need that good quality/much cost to include all those redundant hardware/software.

2. PC to TV

For the time being, TV is not as powerful as PC yet. So sometimes, we want to stream signal from PC to TV. The specific purpose of streaming desktop to TV can be varied for people. One common reason is basically you want to see something  on TV that you can see on PC. This is the exact reason why Internet-ready/connected TV is so popular, Apple TV and google TV are so popular.

For the time being, I don’t have such a powerful TV. I have a samsung LN40c650 LCD HDTV that is internet-ready, with apps and DLNA certified. It is a nice TV, but still not as powerful as computer.

Now I want to see online TV on my TV. What can I do?

There are a variety of ways to send signal from PC to TV.

1) Connect with Video/Audio cables directly, e.g. VGA,DVI,HDMI etc. This is the simplest way. It makes good video/audio quality. But I have to move my PC and make the connection every time. It is not very convenient.

2) Connect wirelessly with PC to TV video/audio transmitters. This is good. But the devices are over $100, which is expensive to me.

3) DLNA, through network. This is compromised way, but doable. DLNA is more and more popular due to its convenience to share media within various devices. But through network, the quality is not that great. The speed is also an issue. There is a tradeoff between media quality and speed. It varies with the hardware.

In my case, I want to try DLNA, since the source media online is not great already. Using TVersity, I can get photos, audios, and videos on my computer, and online such as youtube, and even live TV such as Justin.tv. For more details about this, please refer to another post: https://alenblog.wordpress.com/2011/04/07/tversity-dlna-for-samsung-tv/.

The question is: can I watch online TV like PPStream, PPLive etc (Chinese) on TV, which are not natively supported by DLNA?

There are some methods introduced using VLC: Link 1, Link 2, and Link 3. But it seems none of these works for me for uusee, pplive and ppstream, since I can’t find the streaming source for these software.

3. Stream Desktop to TV

Now I moved to this method that streams desktop to TV, which is universal.

The new VLC version has a feasture to live stream desktop: screen://.

You can create a desktop streaming using VLC to localhost, such as mms://127.0.0.1:1234. Then you can add this live streaming media into TVersity library.

Now you can just watch this “video” on your TV through DLNA (samsung Media Player).

Of course you could also use another live streaming software if available. In principle, this can do the work. The quality and speed might be an issue. It is an issue to me for the time beining. But as least, this provides a possibility.

p.s. screen:// doesn’t actually work for video+audio YET. Please check another post here https://alenblog.wordpress.com/2011/04/24/watch-online-tv-ppstream-pplive-etc-on-tv-via-dlna/ to see how to make it.

TVersity DLNA for Samsung HDTV

Using DLNA, you can stream media (pictures, music and videos) from a DLNA server (such as PC using some DLNA media server, or phone such as Droid X etc) to a DLNA certified device, such as HDTV, PS3 and Xbox 360 etc. Here is an introduction about Droid X DLNA Application: https://motorola-global-portal.custhelp.com/app/answers/detail/a_id/50756/~/droid-x—dlna-application, and a youtube video showing DLNA for Samsung TV and Droid: http://www.youtube.com/watch?v=-QglzQmPpqM. This post is to show how to setup DLNA server for Samsung HDTV.

Some HDTV companies also provide DLNA server software, such as Samsung PC Share. For third party software, on PC, windows media player can set up a DLNA server. And there are a few popular ones with a lot of nice features, such as TVersity (has free version), Mezzmo, Serviio (free) etc.

There’s comparison on Mezzmo’s website: http://www.conceiva.com/products/mezzmo/faqs.asp#Competitors.

But my favorite is TVersity because it does URL streaming. Once you set it up, you can stream youtube videos and all other kinds of online media, even online live TV streaming. Isn’t this cool? Even though Samsung already have apps for youtube. But TVersity’s youtube streaming has much more features. But of course, due to the network capability, the picture quality may not be as good as you want.

I personally have a Samsung LN40C650 LCD HDTV. Samsung HDTVs are not officially supported by TVersity. According to what they said, Samsung seems not interested to give them support. Anyway. We already made it work.

Since Samsung HDTV is not officially supported, it’s not in the default device list of TVersity. I installed the lastest version of TVersity 1.9.3. When I first made all connections, my TV can sees all shared folder and even files. But it can play anything, not even music and pictures. After some research and getting some help the TVersity forum: http://forums.tversity.com/viewtopic.php?f=2&t=10992&st=0&sk=t&sd=a&start=60, it figured it out.

For my TVersity version, in the profiles.xml, there’s already a profile for Samsung HDTV 40A750 as follows.

<profile id=”28300414-0f77-48b3-bc6d-2361dcfcfe23″><!– SamsungTV –>
<friendlyName>Samsung TV</friendlyName>
<manufacturerName>Samsung</manufacturerName>
<modelName>LN46A750</modelName>

<HTTPHeader outServerUA=”Samsung HTTP streaming server contentFeatures.dlna.org: DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000 ” inUASubstr=”SamsungWiselinkPro”/>

<!– The Name of the media server device description file that should be used in conjunction with a player that corresponds to this profile –>
<deviceDescription name=”UPNP_AV_MediaServer_1.0.allservices.xml”/>

<!– The container identifier media players of this profile expect
–>
<contentDirectory shortUrl=”true” friendlyFilename=”false”/>

<!– When transcoding is needed to which format should we transcode –>
<transcodeTarget audio=”audio/mp3″ video=”video/mpeg” photo=”image/jpeg”
onlineAudio=”audio/mp3″ onlineVideo=”video/mpeg” onlinePhoto=”image/jpeg” />

<maxVideoInfo width=”1920″ height=”1080″ bitrate=”20000000″ fps=”60000/1001″></maxVideoInfo>
<minVideoInfo width=”0″ height=”0″ bitrate=”0″ fps=”15″></minVideoInfo>

<maxImageInfo width=”1920″ height=”1080″></maxImageInfo>
<minImageInfo width=”0″ height=”0″></minImageInfo>

<maxAudioInfo sampleRate=”48000″ bitsperSample=”16″ nchannels=”6″ bitrate=”1536000″></maxAudioInfo>
<minAudioInfo sampleRate=”44100″ bitsperSample=”8″ nchannels=”1″ bitrate=”20000″></minAudioInfo>

<fileInfo maxSize=”2147483647″/>

<mimetypeList>
<mimetype value=”audio/L16″/><!–PCM audio format–>
<mimetype value=”audio/wav”/><!– WAV audio format–>
<mimetype value=”audio/x-wav” rename=”audio/wav”/><!– Another mume type used for WAV audio format–>
<mimetype value=”audio/wave” rename=”audio/wav”/><!– Another mume type used for WAV audio format–>
<mimetype value=”audio/x-pn-wav” rename=”audio/wav”/><!– Another mume type used for WAV audio format–>

<mimetype value=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mpeg” rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/mp3″ rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mp3″ rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/mpeg3″ rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mpeg3″ rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/mpg” rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mpg” rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mpegaudio” rename=”audio/mpeg”/><!– MP3 audio format–>

<mimetype value=”image/jpeg”/><!– jpeg image format–>
<mimetype value=”image/jp2″/><!–JPEG2000 image format–>
<mimetype value=”image/bmp”/><!– BMP image format–>
<mimetype value=”image/png”/><!– PNG image format–>
<mimetype value=”image/gif”/><!– GIF image format–>

<mimetype value=”video/mpeg”/><!– MPEG (1 or 2 program or transport stream) video format–>
<mimetype value=”video/mpeg2″ rename=”video/mpeg”/><!– MPEG2 (program or transport stream) video format–>
<mimetype value=”video/mp2p” rename=”video/mpeg”/><!– MPEG2 program stream (VOB) video format–>
<mimetype value=”video/dvd” rename=”video/mpeg”/><!– MPEG2 program stream (VOB) video format–>
<mimetype value=”video/mp2t”/><!– MPEG2 transport stream video format–>

<mimetype value=”audio/aac” rename=”audio/mp4″/><!–MPEG4 audio format–>
<mimetype value=”audio/x-aac” rename=”audio/aac”/><!–MPEG4 audio format–>
<mimetype value=”audio/x-mpg” rename=”audio/mpeg”/><!– MP3 audio format–>
<mimetype value=”audio/x-mpegaudio” rename=”audio/mpeg”/><!– MP3 audio format–>

<mimetype value=”video/avi”><!– AVI video format–>
<codec name=”MPEG4″/><!– XVID, h263, DIVX version 4/5 and any mpeg4 ASP (layer 5) compliant stream (H264, AKA MPEG4 layer 10, is not included here)–>
<codec name=”MSMPEG4V3″/><!– MSMPEG4v3 which is also DIVX version 3 (fourcc DIV3)and AngelPotion (fourcc AP41)–>
<codec name=”H264″/><!– H264, AKA MPEG4 AVC or MPEG4 layer 10 or MPEG4.10 –>
<codec name=”MP2″ maxBitrate=”320000″/><!– MPEG2 Audio–><!– never tested in AVI–>
<codec name=”PCM_S16LE”/><!– Uncompressed PCM Audio–>
<codec name=”PCM_S16BE”/><!– Uncompressed DVD PCM Audio–><!– never tested–>
<codec name=”MP3″ maxBitrate=”320000″/><!– MPEG1 Layer 3 Audio–>
<codec name=”AC3″/><!– Dolby Digital AC3 Audio–>
</mimetype>
<mimetype value=”video/x-msvideo” rename=”video/avi”/>
<mimetype value=”video/x-divx” rename=”video/avi”/>

<mimetype value=”video/MP4V-ES”><!– MPEG4 video format–>
<codec name=”MPEG4″/><!– XVID, h263, DIVX version 4/5 and any mpeg4 ASP (layer 5) compliant stream (H264, AKA MPEG4 AVC or MPEG4 layer 10 or MPEG4.10, is not included here)–>
<codec name=”H263″/><!– h263–>
<codec name=”H264″/><!– H264, AKA MPEG4 AVC or MPEG4 layer 10 or MPEG4.10 –>
<codec name=”MP2″ maxBitrate=”320000″/><!– MPEG2 Audio–><!– never tested–>
<codec name=”PCM_S16LE”/><!– Uncompressed PCM Audio–>
<codec name=”PCM_S16BE”/><!– Uncompressed DVD PCM Audio–><!– never tested–>
<codec name=”AC3″/><!– Dolby Digital AC3 Audio–>
<codec name=”MP3″ maxBitrate=”320000″/><!– MPEG1 Layer 3 Audio–>
</mimetype>
<mimetype value=”video/mp4v” rename=”video/MP4V-ES”/>
<mimetype value=”video/mp4″ rename=”video/MP4V-ES”/><!– MPEG4 video format–>
<mimetype value=”video/h264″ rename=”video/avi”/><!– MPEG4 video format–>

</mimetypeList>
</profile>

But obviously that didn’t work for me at the beginning. The post above shows another profile, which is similar to what I have. It actually turn out that the TVersity cannot use the these profile ids to recognize my LN40C650. So then based on the info here: http://forums.tversity.com/viewtopic.php?f=2&t=10992&st=0&sk=t&sd=a&start=150#p108875, I added another line to the profile:

<devicesIP value = “x.x.x.x”/>, where xxx is your TV’s ip address. So then the top lines in the profile will be like following:

<profile id=”anything”><!– SamsungTV –>
<friendlyName>Samsung TV</friendlyName>
<manufacturerName>Samsung</manufacturerName>
<modelName>Samsung Model (LN40C650</modelName>
<icon>/images/device_icon_dtv.png</icon>
<devicesIP value=”x.x.x.x”/>

Then everything works great.

Here is my conclusion:

If we don’t have profile id of Samusng TV or another device, then basically, we can set profile id as anything. Then we put in devicesIP value. Then TVeristy will recognize Samsung TV without a problem.

Once it recognize it, we should be able to play at least some media. Whether or not we can play a media file, that’ll a matter of picking the right file format/codec and transcoding method. The whole profiles.xml specs are explained here: http://wiki.tversity.com/index.php/A_Technical_Specification_of_a_Device_Profile.

Here is the file formats and codecs supported by Samsung LN40C650 from the user manual.

Enjoy!