Sunday, October 30, 2016

Protect your streaming video from being stolen


Let's start with the “The Golden Rule”:
Anyone who can watch your video, can steal your video.
The best way to deal with it, is to minimize the number of times the video is stolen.

The most simple method of stealing, is to use a video capture technique.
video capture is an application that captures whatever is displayed on screen. It is possible to define a certain area or window (i.e. the video screen), play the video and tell the utility to capture it.

What can be done ?
An effective way to deal with that, is to apply watermarks, for example a graphical logo with a link to the author domain. Even if someone uses such video content, it will only advertise the author. Be aware, that it is simple to cut out logo of such type using any program for video editing, that's why, a good solution is to use a dynamic watermark which appear in different places, be shown during some period of time and faded.

Beside that, the best and most practical way to stop theft is to use a streaming server as follows :

1. First of all, use an encrypted streaming method( SSl streaming, RTMPE, etc.. ).
2. Secondly, use the following mechanism:
1)  Client create an ID token, Update the server DB and send it to the streaming server.
2)  Based on the ID token, streaming server find out the appropriate media file(Use a server that support plugins) and remove token from DB (If you want to be more secure , those ID tokens could have a limited time of use).


Advantages :

1. Your true streaming link is not exposed in the client.
2. Its not possible to use any software to download the media.


Please feel free to contact me if you have any questions.

Good Luck.

Moris Oz
Caapi Technologies



Tuesday, April 28, 2015

Fullscreen video streaming via www for Unity iOS


Unity is a flexible and powerful development platform for creating multiplatform 3D and 2D games and interactive experiences, It's goal is to create a fluid and fun to use cross platform apps. Unity is made to empower you to create the best interactive entertainment or multimedia experience that you can.

In this article we will be discussing one of the most interesting feature of Unity, Which is "Video streaming"

Based on the unity manual, in order to stream a Video in fullscreen mode for mobile devices, we should use the "Handheld.PlayFullScreenMovie"  function, but unfortunately, its not really helping us in our case, because this function can only stream movies from a local storage, and not from the web media server. Loading a movie from an asset bundle is painful because the bundle takes so long to load especially if you have few movies that are very large.

The way to overcome this problem is to use a method called Plugin. In Unity, you normally use scripts to create functionality but you can also include code created outside Unity in the form of a Plugin.

Before we begin, we should be aware that The Mono Runtime (Unity engine's scripting is built on Mono, Which is an open source development platform based on the .NET framework, allows developers to build cross-platform applications ) makes calls into native code using C standards. Any language that follows the C calling convention can be called. Unfortunately Objective-C does not follow this convention. We will have to wrap Objective-C APIs with C code to make it available to Unity. This is done by putting our calls inside C functions and using a C compiler to compile it. Our file will contain calls into C++ so we need to use a .mm file with Extern "C" { at the top and } at the bottom to avoid name mangling issues.

The first phase, should be to write a wrapper with a C named ( Unity needs the plugins to be C named. That's why, we need to wrap it in an extern “C”.), and from that wrapper we can call to the video class.

So, Let's begin :

1) In your Unity project, create a folder Assets/Plugin/iOS. Files in that folder (can’t be in a subfolder) automatically get added to your iOS project when you have Unity create an iOS build.

First, we create the iOS wrapper plugin file. In that file, we put the code for the iOS side of the plugin. Unity needs the plugins to be c named. So, we wrap it in an extern “C”.

Here is an example plugin:

videopluginwrapper.mm:

#import "videoplugin.h"
extern "C"
{
    bool videoIosPlay( const char* url)
    {
            return [videoPlayerHelper play:[NSString stringWithUTF8String:url]];
    }
}


2) Second, we create the actual iOS video class.

videoplugin.h:

#import <MediaPlayer/MediaPlayer.h>

@interface VideoPlayerHelper : NSObject {
@private
        // Native playback
    MPMoviePlayerController* _moviePlayer;
   
     }

- (BOOL)play:(NSString*)url;

@end


videoplugin.m:

#import "videoplugin.h"
#import <AVFoundation/AVAudioSession.h>

@implementation VideoPlayer

////////////////////////////////////////////////////////////////////////////////

// Play the asset
- (BOOL)play:(NSString*)url
{
    BOOL ret = YES;
   
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    NSURL *urlMovie = [NSURL URLWithString:url];
    _moviePlayer = [[MPMoviePlayerController alloc]
                                       initWithContentURL:urlMovie];

    _moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    _moviePlayer.shouldAutoplay = YES;
    _moviePlayer.view.transform = CGAffineTransformConcat

(_moviePlayer.view.transform,CGAffineTransformMakeRotation(M_PI_2));
   
    UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
   
    [_moviePlayer.view setFrame:backgroundWindow.frame];
    [backgroundWindow addSubview:_moviePlayer.view];
    [_moviePlayer prepareToPlay];
    [_moviePlayer play];
   
    return ret;
}

@end


3) Now that we’ve built the plugin, we are ready to call it from Unity code. first, we need to declare the native functions that will be using in managed code(we put this file in the Assets folder) :

VideoPlayer.cs :

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class VideoPlayer{

    /* Interface to native implementation */
   
    [DllImport ("__Internal")]
    private static extern void videoIosPlay(string strUrl);
     
    // play movie
    public static void PlayVideo(string strUrl)
    {
        // Call plugin only when running on real device
        if (Application.platform != RuntimePlatform.OSXEditor)
            videoIosPlay(strUrl);
    }

}


*** Note that the “__Internal” name is used for iOS plugins.


4) Finally, we create a Unity script to use it.

TestPlugin.cs :

using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
   
    private float    _buttonX = 30f;
    private float    _buttonY = 30f;
    private float    _buttonWidth = 30f;
    private float    _buttonHeight = 30f;
   
    void OnGUI ()
   {
        if(GUI.Button(new Rect(buttonX ,  _buttonY, _buttonWidth, _buttonHeight), "Play"))
        {
            VideoPlayer.PlayVideo("Movie WWW Link);
        }
    }

}


That's all for now.
please feel free to contact me If you have any questions.

Good Luck.

Moris Oz






Wednesday, March 28, 2012

The Art of Memory optimization in android frame animation.

I remember when I was a child, we have made drawings on papers which acted as animation. We draw numerous slides one by one and arrange them and flip them speedily. Flip books are low-tech fun that still appeal to kids today, especially if they are creating them themselves. Back then , there was not any problem with memory ( in the worse case we add more papers and expend the Flip book ).
Implementing animation on android is a totally different story. Each application has very limited amounts of memory, and it’s based on the specific firmware running on each device. Assume that your animation frame images are compressed (PNG or JPG). The compressed size is not useful for calculating how much memory is needed to display them. For that, you need to think about the uncompressed size. This will be the number of pixels multiplied by the number of bytes per pixel, which is typically 4 (32 bits).So let’s say , you have an animated cannon with 9 position ( Each position contain 8 frames of 130x130).It will require a total of 4,867,200 bytes to hold the raw bitmap data for all the frames , and this is only for one character animation. Within a regular game you have many characters and many animations. That's bring us to "Out Of memory error - Bitmap exceeds VM budget" error message, which is one of the most annoying (and common ) errors when dealing with bitmaps and Android ( you will find plenty of other posts related to this issue), and its caused due to limited virtual memory heap size.
To summarize the subject, you need to find a way to draw your animation using less memory. There are many options, but it depends a lot on how your animation needs to look.   One solution is to re-sample and scale your bitmaps prior to inserting them into the cache, by checking the image size and then down sample it by appropriate factor. Changing the sample size reduces the amount of memory used, but it will come on the cost of image quality. The other solutions is mainly determined by the animation style and an "out of the box" solutions. For example, if we go back to the cannon example. I can optimize the memory, by loading only one direction of the cannon positions, and mirror the other side when needed. The way to do it,without creating a new bitmap, is as followed :

//Load the Cannon drawable ( with only one direction of the cannon positions frames)
Bitmap sprite = BitmapFactory.decodeResource(this.getResources(), R.drawable.spritegfx );

//Create a matrix to be used to transform the bitmap
Matrix mirrorMatrix = new Matrix();

//Set the matrix to mirror the image in the x direction
mirrorMatrix.setScale(-1.0f, 1.0f);

//The image will draw flipped in X, but it will also appear to the left of the Y axis, which defaults to the left edge of the view. post-translate everything to the right by at least the width of the bitmap, to make it appear on screen.
mirrorMatrix.postTranslate(bitmap.getWidth(), 0)

// Save the default matrix state
canvas.save(Canvas.MATRIX_SAVE_FLAG);

// Apply your matrix on the current canvas                        
canvas.concat(mirrorMatrix);

// Draw bitmap on canvas. source Rectangle is created based on the current animation frame.
canvas.drawBitmap(sprite ,sourceRect,destRect,null);

// Restore original state
canvas.restore();

please feel free to contact me If you have any questions.

Good Luck.

Moris Oz
Caapi Technologies

Sunday, December 18, 2011

IB SDK/API review

This article reflects my experience developing an automated equity trading platforms using the IB SDK/API. I have written this article as an individual, not representing IB (Interactive brokers) in ANY way.

The IB Application Program Interface (API) connects through the Trader Workstation (often known as TWS) or the IB Gateway. TWS is programmed in Java, which is platform-independent and can be very useful( but, it is not as fast as it would be if it was programmed in C or C++ ). In order to connect to IB, the TWS (Trading Work Station ) application must be running in the background. The connection takes place via a network connection. If the TWS and the API application run on the same system this network connection will be through localhost ( which is a bit awkward, since trading program execution requires TWS to be run first to establish a session).

The good news is that, TWS provides a great API ( application programming interface ) in several programming languages, which including Java,C++, ActiveX and DDE for Excel ( there is also a possibility to get an interface in C# ), and this can be used to access almost all of the TWS' features via other programs. The API code makes a TCP/IP or local host connection to the TWS software( usually to port 7496 on the local host). There are two sides to the communication: the request and the response. This means that the process of reading from the socket and writing to the call back methods, is asynchronous and it takes place in separate threads. IB transaction either go through the TWS (trading software),or through CTCI FIX. When using The IB API, A single account (user name and password) is limited to 50 messages a second. Using the CTCI FIX interface the limit is150 messages a second. If you have the possibility, I would suggest to avoid using the CTCI FIX since its complex and sample applications are not provided.

Beside that, this are some of the issues that I had to deal with :
1) Opening an account with IB takes a long time. Application forms are the largest I have seen.
2) The API Chat is usually empty ( Which mean that I am the only person in the room ). Only Registered clients ( customers who paid money ), will get a full customer support by mail.
3) There were several technical issues, which forced me to find a creative solution inorder to make my trading platform work as I needed. For Eg: I placed a limit BUY at $60 for a stock at $30, IB rejected the order as too far outside the NBBO. Well, IB allows you to override TWS order price percentage constraints ( which are applied to orders that TWS sees as deviating too much from the NBBO` of the contract ). Unfortunately, setting this param ( from TWS or the API ) had no effect, and my only alternative was to place a market order. I guess, That this param exist there as a restriction created by the exchange in order to "protect" me. But, If I'm responsible enough for my own trades and want to make some more money, why this feature is not working ? Maybe if enough people will complain to IB , they will fix it.
4) Limits to data requests : 60 requests in 10 mins (almost) without pacing violations, But also this issue can be handled by implementing a smart mechanism ( Or you can just get real time data from Yahoo! Finance )

Despite of the problems I've described above, My main impression is good. The very best advantage that IB offers for developers is that there is a discussion forum, which serves as a serviceable message board where traders read and share information or even post programming code, also a very good API reference guide is presented, and you get code samples which,ship with the IB's API package.(Code samples :Cpp, Java, VB6, VB.NET, C#.NET).

IB support ( Only Registered clients ), a paper trading account which allows traders to test the full range of IB trading facilities in a simulated environment using real market conditions. Its especially beneficial to traders that want a special strategy implemented for them by a developer, without using there real account (paper trading account works just like the production account, but has different username/password). as well, Users can test new strategies and ideas risk-free or learn about order execution of global products they've never traded in the past. Last but not least, IB allows very sophisticated, advanced order specification and routing. They allow you to trade just about every kind of tradable security.

Moris oz
Algorithmic trading Consulting and development
www.caapitech.com

Sunday, July 3, 2011

Artificial Intelligence Goes to Wall Street: Trading Platforms Get Smarter

Press Release

It is no secret that for many years global banks have used artificial intelligence to make better trades. Now that technology might be coming to your local independent investment advisory service.
Caapi Technologies just announced that it signed a deal to use artificial intelligence technology to build custom trading systems for small to mid-size investment firms. Caapi will build applications with software development kits (SDKs) from ai-one that enable computers to understand human language to find undervalued stocks, bonds and derivatives.
The partnership makes Caapi one of the first consulting firms to use ai-one’s machine learning technology to build trading algorithms and platforms for traders, banks and hedge funds.
Building custom trading algorithms is a huge industry propelled by the success of high-frequency trading across global markets. Originally, these algorithms were designed to find and exploit pricing differences between stocks, commodities and derivatives. Now trading algorithms are so widespread and so sophisticated that they have completely reshaped markets to the point where pricing is often driven more by speculation than it is by the underlying value of the asset class.
The challenge now is to find underpriced opportunities that generate returns based on actual performance rather than market volatility. This requires that investors sort through vast amounts of unstructured data to find undervalued assets before they are identified by the rest of the market. Often this means reading text that can’t be processed by search engines like Google. Traditional algorithmic approaches, such as Google’s, fail as they only know what they are programmed to know or programmed to find. They miss finding unexpected results that don’t fit into an equation.
ai-one’s technology is described as “biologically inspired intelligence.” It is modeled after the human brain and does not depend on algorithms. Rather, it automatically sees the inherent patterns within data and forms associations between each data element. This enables machines to learn without any human intervention. More importantly, it enables people to ask the questions they wouldn’t normally know to ask.
The CEO of Caapi, Mr. Moris Oz, sees machine learning as the key to discovering hidden investment opportunities. “a-one’s technology enables us to build semantic associative search engines for our clients that understand how the price of any given investment is related to the unstructured data found on the internet.”
Caapi’s approach is to combine proven techniques using sophisticated algorithms with machine learning that understands words.  “Language is not math,” adds Olin Hyde, VP of Business Development at ai-one. “Algorithms are fantastic at processing structured data. But human behaviors and communications are inherently unstructured and complex. We learn through words not equations. So why not enable computers to do the same?”
According to Moris Oz, CEO of Caapi, “ai-one’s SDK for machine learning could be the answer for understanding and correlating soft data driving price moves in the markets.  I’m looking forward to applying this to new applications.” The market will soon tell if it works or not.
About Caapi TechnologiesCaapi Technologies is a small, dynamic and friendly software-development company, capable of providing quick solutions for a variety of systems. Caapi Technologies was founded by Moris Oz, a skilled software developer with vast experience in various technologies, who leads all software projects. The company offer solutions for the many various stages of development, and services such as software development, web applications development and algorithmic trading solutions. Caapi Technologies's expertise spans the most common technologies such as C, C++, C#, .NET, Java, Jscript, PHP, ASP, VBscript, GWT, Flex, PHP, CSS, XML, Facebook SDK and more. They designed, programmed and delivered some very challenging and rewarding projects in the US and abroad
For more information see http://www.caapitech.com
Contact Moris Oz, Ph +972-9-8656875 email moris@caapitech.com
About ai-one inc., ai-one provides an “API for building learning machines”.  Based in San Diego, Zurich and Berlin, ai-one’s software technology is an adaptive holosemantic data space with semiotic capabilities (“biologically inspired intelligence”).  The Topic-Mapper™ SDK for text enables developers to create intelligent applications that deliver better sense-making capabilities for semantic discovery, lightweight ontologies, knowledge collaboration, sentiment analysis, artificial intelligence and data mining.
For more information see http://www.ai-one.com
Contact: Olin Hyde, Ph: 1-858-531-0674, email: oh@ai-one.com, web: www.ai-one.com

Wednesday, June 22, 2011

Troubleshoot - Android Platform Sooner Single ADB Interface error

When installing The Android ADB Interface drivers , There are situations where the system complain that the driver is not found , or the driver installation has failed. I was researching the web and found many solution , but neither of them really worked for me.
Anyway , This is my solution : 

1) Using a free tool called USBDeview you should first spot your ADB Interface driver (Using the USBDeview You can try uninstalling devices until you see in the DeviceManager that the ADB Interface is not there anymore) 
2) Now, unplug-plug your mobile device and spot the ADB Interface in the USBDeview,   look at the vid info of that interface , Over my place it looks like that :
Description =  Android Composite ADB Interface , Instance ID = USB\VID_1004&PID_618E_ADBInterface\6&34ef9180&5&0000 )
2) You need to download Google's android_usb_windows.zip package that contains the
driver.  Then unpack the zip file.
3) In the android USB windows folder ( C:\Program Files\Android\android-sdk\extras\google\usb_driver ) , edit the android_usb.inf file and add the specific Instance ID As followed :
"%CompositeAdbInterface%     = USB_Install, USB\{Your Vid Info}" 
Over my place the row Looks like that --> 
"%CompositeAdbInterface%     = USB_Install, USB\VID_1004&PID_618E&ADB.DeviceDescRelease%=androidusb.Dev, USB\VID_1004&PID_618E_ADBInterface"
4) Now , Try again to Update the ADB driver from the android USB folder, and make sure the ADB Interface driver has been installed without error in Device Manager.

If you still have problems , please let me know.

Good Luck.

Moris Oz
Caapi Technologies

Monday, June 13, 2011

Web Applications Development services

Hello All,

I'm pleased to announce the availability of Caapi Technlogies's new web applications development services. With all of the emails and questions we’ve been getting from our customers about providing custom web applications development services that are easier to use, attractive to look at, and serve the purpose of the clients, we’ve decided to start. So head on over to the Services page to get a full range of web site application development services, from requirements gathering and definition, through the delivery and deployment of web solutions. Our expertise spans the most common technology platforms such as Java, .NET, GWT, Flex, PHP, CSS , JS ,Facebook SDK etc., for building scalable, feature-rich Web applications. As part of our web development services we provide customized, secure and advanced Facebook Application development services. We build Facebook applications with unique, fresh concepts and stylish designs; and provide all the ongoing support needed thereafter.

Best Regards,

Moris Oz
Founder and CEO
Caapi Technologies