Monday, November 24, 2008

Applying forward-locking to videos for mobile devices

Forward locking is a form of Digital Rights Management (DRM) which can be applied to mobile content. There are 3 forms of DRM which can be applied to mobile content i.e.
  • Forward Locking (Basic form whereby the content cannot be forwarded via bluetooth/mms to another handset).
  • Combined Delivery (Can be used to apply further constraints to the content e.g. number of times the content can be accessed or the number of days the content is available for).
  • Separate Delivery (Most secure form of DRM, whereby the content is unlocked by a key sent to the handset via SMS).
Below is an example (in java) of how to apply basic forward locking to a video item:

//get video file - getVideoFile() returns the actual binary file as a byte array
byte[] videoData = getVideoFile();

//get content length including the length of the additional DRM headers
//i.e. "--foo\r\nContent-Type ...."
int contentlength = getContentLength();

//binary forward locked content is sent to the handset
ServletOutputStream sos = response.getOutputStream();

//sending the content length
response.setIntHeader("Content-length", contentlength);

//sending the drm header
response.setHeader("Content-Type","application/vnd.oma.drm.message; boundary=foo");
sos.println("--foo");
sos.println("Content-Type: video/3gpp");
sos.println("Content-Transfer-Encoding: binary");
sos.println("");
//sending the actual video file
sos.write(videoData);
sos.println();
sos.println("--foo--");
sos.flush();


The methods getVideoFile() and getContentLength() need to be written before this code can be executed. The code segment above is from the doGet(HttpServletRequest request, HttpServletResponse response) method in a java servlet.

Monday, October 20, 2008

Finding all files containing a specific string in unix

find [directory_name] -exec grep -li "[search_string]" {} \;

e.g. find . -exec grep -li "xxxx" {} \;

which searches for files containing the string "xxxx" within the current directory.

Resizing animated gifs using Imagemagick

convert [filename] -coalesce temp
convert temp -resize %25 resized_image.gif

Sunday, September 28, 2008

Getting a single DB connection in Java

Connection conn = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@[ip_address]:[port]:[SID]", "[username]", "[password]");

Tuesday, September 23, 2008

Changing the Date/Time on Linux

Changing the timezone to Johannesburg:
$ ln -s /usr/shar/zoneinfo/Africa/Johannesburg /etc/localtime

Changing the date/time:
To change the date/time use the following syntax:
$ date MMDDhhmmYYYY
where MM is the month, DD is the day, hh is the hour, mm is the minute and YYYY is the year.

Updating the hw clock:
$ hwclock --systohc

Checking the hw clock:
$ hwclock --show

To maintain the timezone through a restart you may need to change the /etc/sysconfig/clock file.

Binary Tree Traversals

One of the important features of Genetic Programming is the tree structure which is the primary method of representing an individual. Understanding binary tree traversals is therefore required. The 3 methods of traversing a binary tree are Preorder, Postorder and Inorder traversal.

Preorder Traversal:
begin
   if tree=null return;
   print(tree.root)
   preorder(tree.leftsubtree)
   preorder(tree.rightsubtree)
end

Postorder Traversal
begin
   if tree=null return
   postorder(tree.leftsubtree)
   postorder(tree.rightsubtree)
   print tree.root
end

Inorder Traversal
begin
   if tree=null return
   inorder(tree.leftsubtree)
   print(tree.root)
   inorder(tree.rightsubtree)
end

JSESSIONID on URL causes an issue for the SE P1 handset

A JsessionID on the end of a download URL to a piece of content seems to cause a problem for the Sony Ericsson P1 handset e.g. file.3gp;jsessionid=xxxxx. The handset doesn't seem to recognise the format of the file and gives an error "There is a problem opening the file. Try Again?". The installation message sent back to the handset though is a 900 Successful Installation. Oddly if DRM is applied to the content (which will then be a .dm or .dcf file), the JsessionID is not really a problem. Removing the jsessionid from the URL to the content fixes the problem described above.

952 device aborted error

SE K750i gives a 952 device aborted error when downloading content if there is not enough space on the memory card. The handset shows the message "Operation Failed". This error is not very intuitave as, if it is a space issue the handset is supposed to send a 901 error. The handset had enough space on the handset itself so this is probably why a 901 error isn't the installation message. So identifying the actual problem was quite difficult. Deleting some of the items on the memory card solved the issue.

Monday, September 22, 2008

Installing Imagemagick on Red Hat

Download the latest ImageMagick. If you need to manipulate jpegs the jpeg libraries may not be installed on your OS by default so you will need to download the jpeg source.

Uninstall the current ImageMagick (if installed):
$ make uninstall
$ make clean

To install the jpeg source:
$ tar -xzvf jpegsrc.vb6.tar.gz
$ cd jpeg-6b
$ ./configure --enable-shared=yes
$ make
$ make install

To install ImageMagick (in this case v 6.4.1 is being used):
$ tar -xzvf ImageMagick-6.4.1-0.tar.gz
$ cd ImageMagic-6.4.1
$ ./configure --enable-shared=yes --disable-static --without-perl
$ make
$ make install

Testing the installation:
$ convert test.jpg -resize 50% half_sized_image.jpg

Going through a file "line by line" with a shell script

cat $FILENAME | while read i
do
#do something here with each line e.g.
echo $i
done

Running Unix Commands from java

Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec(new String[] {"/bin/sh","-c","sh myScript.sh"});
child.waitFor();
int return_code = child.exitValue();

Using a script to get files via FTP

(echo "user username password
binary
prompt
cd /where_the_file_is
mget $FILENAME
bye" | ftp -n $systemID)


where $systemID is the IP address of the system.

Oracle SQL - String replace

Updating String fields using the replace function:

update [table_name] set [field_being_updated]=replace([field_being_updated], '[string_to_be_replaced]', '[replacement_string]')