Perfect Forwarding: std::forward and std::move


Based on the source code below, here is the forwarding result:
Input parameter                    Forwarded to
int intNonConst:                     (int&)
const int intConst:                  (const int&)
6(just a literal):                        (int&&) or if (int&&) doesn’t exist, to (const int& i)
std::move(intNonConst)):      (int&&)
int IntTemp():                          (int&&)
Why std::forward: otherwise, when a rvalue is passed, e.g. 6, std::move or IntTemp(), it gets forwarded to &, instead of &&.
Why std::move: so that a lvalue such as intNonConst can be treated as rvalue, and therefore be forwarded to &&
Summary: std::forward is to deal with rvalue forwarding, and it does not affect rvalue reference, regardless of constness

int IntTemp() { return 0; }
void TestForwardingFuncCalled(const int& i)
{
	cout << "const &" << endl;
};
void TestForwardingFuncCalled(int& i)
{
	cout << "&" << endl;
};
void TestForwardingFuncCalled(int&& i)
{
	cout << "&& " << endl;
};

template  void TestForwardingTemplateFunc(T&& t)
{
	cout << "Results with std::forward" << endl;
	TestForwardingFuncCalled(std::forward(t));
	cout << "Results without std::forward" << endl;
	TestForwardingFuncCalled(t);
}

void TestForwarding()
{
	int intNonConst = 2;
	const int intConst = 3;
	TestForwardingTemplateFunc(intNonConst); //with std::forward: (int&)", without std::forward: same
	TestForwardingTemplateFunc(intConst); //with std::forward: (const int&)", without std::forward: same
	TestForwardingTemplateFunc(6); //with std::forward: (int&&) or if (int&&) doesn't exist, to (const int& i), without std::forward: (int&)
	TestForwardingTemplateFunc(std::move(intNonConst)); //with std::forward: (int&&), without std::forward: (int&)
	TestForwardingTemplateFunc(IntTemp());  //with std::forward: (int&&), without std::forward: (int&)
}
void main()
{
	TestForwarding();
}

 

Advertisements

AI Assistant Mica


Augmented Reality: Magic Leap’s AI Assistant Mica
The idea is that as soon as you put on the Magic Leap One AR headset, Mica appears in your room.
Mica’s gender looks vague though.
https://youtu.be/8-oHdR_-l6o

Live Streaming Options


HLS/DASH:
HTTP segmentation based, high latency
As static HTTP content, well received by players, whether web or native based, and efficient on CDN
distributed by standard HTTP server.
RTSP:
Standard protocol for IP camera video output. Weak browser play support.
Requires router configuration when video source if behind NAT since streaming server have to pull video from video source.
Low latency
RTMP:
Popular with video source since source pushes to streaming server, and therefore no router work is needed when video source is behind NAT.
Low latency
WebRTC:
I believe this will be the protocol to deliver low latency video to browser.
supported by Chrome and Firefox. I don’t include IE/Safari plugin as it requires installation.
Support both VP8/VP9 and H.264 through OpenH264 and ffmpeg
Here is a little page that renders the laptop camera:
http://riowing.net/local/webRTC.htm tested on Edge (Chrome requires https or localhost)

Reference:
https://www.3cx.com/webrtc/which-browsers-support-webrtc
https://www.chromestatus.com/feature/6417796455989248

Adaptive Bitrate HLS Generation


MaxxSports has two variant streams for each camera, high and low resolution, generated by ffmpeg. Player can switch between the two resolutions based on bandwidth.

There are three playlists in this sample setup; master.m3u8 has two variant playlists:
var_0.m3u8: 426×240, with original resolution from input mp4 file
var_1.m3u8: 128×86, transcoded with parameter -s:v:1 128×86

Command used to generate the three playlists:
set FF=2018\bin\ffmpeg.exe
set MEDIA=Gym2017bshort.mp4    : to be replaced by rtsp://… for live camera feed.
%FF% -i %MEDIA% -s:v:1 128×86 -map 0:v -map 0:a -map 0:v -map 0:a -f hls -master_pl_name master.m3u8 -var_stream_map “v:0,a:0 v:1,a:1” var_%v.m3u8

Play URL: http://riowing.net/ABR/master.m3u8 or http://riowing.net/ABR/var_0.m3u8 or var_1.m3u8

This feature, var_stream_map, was added to ffmpeg in November 2017.
ffmpeg version is ffmpeg-20180925-a7429d8-win64-static 4.02, downloaded from ffmpeg.zeranoe.com