3 /// Display a regularly updated video of the BlackBerry screen
7 Copyright (C) 2011, Alberto Mattea
8 Copyright (C) 2011, Net Direct Inc. (http://www.netdirect.ca/)
10 Some parts are inspired from bjavaloader
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU General Public License in the COPYING file at the
22 root directory of this project for more details.
26 #include <barry/barry.h>
37 using namespace Barry
;
41 int logical
, major
, minor
;
42 const char *Version
= Barry::Version(logical
, major
, minor
);
45 << "bwatch - View video of BlackBerry screenshots\n"
46 << " Copyright 2011, Alberto Mattea\n"
47 << " Copyright 2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
48 << " Using: " << Version
<< "\n"
50 << " -d delay Delay interval between screenshots, in milliseconds.\n"
51 << " The lower the value, the higher the load on the device.\n"
52 << " Default is 500ms.\n"
53 << " -p pin PIN of device to talk with\n"
54 << " If only one device is plugged in, this flag is optional\n"
55 << " -P pass Simplistic method to specify device password\n"
56 << " -v Dump protocol data during operation\n"
60 int main(int argc
, char *argv
[])
64 cout
.sync_with_stdio(true); // leave this on, since libusb uses stdio for debug messages
67 bool data_dump
= false;
69 int delay
= 500; // default delay of 500 ms
71 // process command line options
73 int cmd
= getopt(argc
, argv
, "d:hp:P:v");
79 case 'd': // delay interval in milliseconds
82 cerr
<< "Invalid interval value of '" << optarg
<< "'. Defaulting to 500ms." << endl
;
87 case 'p': // Blackberry PIN
88 pin
= strtoul(optarg
, NULL
, 16);
91 case 'P': // Device password
95 case 'v': // data dump on
107 int sdl_width
= -1, sdl_height
= -1;
108 SDL_Surface
*screen
= NULL
;
111 if( SDL_Init(SDL_INIT_VIDEO
) < 0 )
114 // Initialize the barry library. Must be called before
116 Barry::Init(data_dump
);
121 // Probe the USB bus for Blackberry devices and display.
122 // If user has specified a PIN, search for it in the
123 // available device list here as well
125 int activeDevice
= probe
.FindActive(pin
);
126 if( activeDevice
== -1 ) {
127 cerr
<< "No device selected, or PIN not found" << endl
;
132 cout
<< "Press a key to exit..." << endl
;
134 // Put this inside it's own block to avoid blocking the handheld
136 // Create our controller object
137 Barry::Controller
con(probe
.Get(activeDevice
));
138 Barry::Mode::JavaLoader
javaloader(con
);
139 javaloader
.Open(password
.c_str());
140 javaloader
.StartStream();
142 // - info object contains the screenshot properties
143 // (width, height...)
144 // - image will be filled with the raw pixel
146 javaloader
.GetScreenshot(info
, image
);
147 javaloader
.StopStream();
150 // Set the video mode according to the screenshot data
151 if( sdl_width
!= info
.width
|| sdl_height
!= info
.height
) {
152 sdl_width
= info
.width
;
153 sdl_height
= info
.height
;
154 if( !(screen
= SDL_SetVideoMode(info
.width
, info
.height
, 0, SDL_HWSURFACE
)) ) {
158 SDL_WM_SetCaption("Blackberry", 0);
161 // May want to tune this between 100 and 1000
164 // Convert to 24-bit RGB
165 ScreenshotToRGB(info
, image
, bitmap
, 0, 24, false);
169 tmp
= SDL_CreateRGBSurfaceFrom((char*)bitmap
.GetData(), info
.width
, info
.height
, 24, info
.width
*3, 0, 0, 0, 0);
170 SDL_BlitSurface(tmp
, 0, screen
, 0);
172 while(SDL_PollEvent(&event
)) {
173 switch (event
.type
) {
190 catch( Usb::Error
&ue
) {
191 std::cout
<< endl
; // flush any normal output first
192 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
195 catch( Barry::Error
&se
) {
197 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
200 catch( std::exception
&e
) {
202 std::cerr
<< "std::exception caught: " << e
.what() << endl
;