3 /// Display a regularly updated video of the BlackBerry screen
7 Copyright (C) 2011, Alberto Mattea
8 Copyright (C) 2011-2012, 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>
38 using namespace Barry
;
42 int logical
, major
, minor
;
43 const char *Version
= Barry::Version(logical
, major
, minor
);
46 << "bwatch - View video of BlackBerry screenshots\n"
47 << " Copyright 2011, Alberto Mattea\n"
48 << " Copyright 2011-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
49 << " Using: " << Version
<< "\n"
51 << " -d delay Delay interval between screenshots, in milliseconds.\n"
52 << " The lower the value, the higher the load on the device.\n"
53 << " Default is 500ms.\n"
54 << " -p pin PIN of device to talk with\n"
55 << " If only one device is plugged in, this flag is optional\n"
56 << " -P pass Simplistic method to specify device password\n"
57 << " -v Dump protocol data during operation\n"
61 int main(int argc
, char *argv
[])
65 cout
.sync_with_stdio(true); // leave this on, since libusb uses stdio for debug messages
68 bool data_dump
= false;
70 int delay
= 500; // default delay of 500 ms
72 // process command line options
74 int cmd
= getopt(argc
, argv
, "d:hp:P:v");
80 case 'd': // delay interval in milliseconds
83 cerr
<< "Invalid interval value of '" << optarg
<< "'. Defaulting to 500ms." << endl
;
88 case 'p': // Blackberry PIN
89 pin
= strtoul(optarg
, NULL
, 16);
92 case 'P': // Device password
96 case 'v': // data dump on
108 int sdl_width
= -1, sdl_height
= -1;
109 SDL_Surface
*screen
= NULL
;
112 if( SDL_Init(SDL_INIT_VIDEO
) < 0 )
115 // Initialize the barry library. Must be called before
117 Barry::Init(data_dump
);
122 // Probe the USB bus for Blackberry devices and display.
123 // If user has specified a PIN, search for it in the
124 // available device list here as well
126 int activeDevice
= probe
.FindActive(pin
);
127 if( activeDevice
== -1 ) {
128 cerr
<< "No device selected, or PIN not found" << endl
;
133 cout
<< "Press a key to exit..." << endl
;
135 // Put this inside it's own block to avoid blocking the handheld
137 // Create our controller object
138 Barry::Controller
con(probe
.Get(activeDevice
));
139 Barry::Mode::JavaLoader
javaloader(con
);
140 javaloader
.Open(password
.c_str());
141 javaloader
.StartStream();
143 // - info object contains the screenshot properties
144 // (width, height...)
145 // - image will be filled with the raw pixel
147 javaloader
.GetScreenshot(info
, image
);
148 javaloader
.StopStream();
151 // Set the video mode according to the screenshot data
152 if( sdl_width
!= info
.width
|| sdl_height
!= info
.height
) {
153 sdl_width
= info
.width
;
154 sdl_height
= info
.height
;
155 if( !(screen
= SDL_SetVideoMode(info
.width
, info
.height
, 0, SDL_HWSURFACE
)) ) {
159 SDL_WM_SetCaption("Blackberry", 0);
162 // May want to tune this between 100 and 1000
165 // Convert to 24-bit RGB
166 ScreenshotToRGB(info
, image
, bitmap
, 0, 24, false);
170 tmp
= SDL_CreateRGBSurfaceFrom((char*)bitmap
.GetData(), info
.width
, info
.height
, 24, info
.width
*3, 0, 0, 0, 0);
171 SDL_BlitSurface(tmp
, 0, screen
, 0);
173 while(SDL_PollEvent(&event
)) {
174 switch (event
.type
) {
191 catch( Usb::Error
&ue
) {
192 std::cout
<< endl
; // flush any normal output first
193 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
196 catch( Barry::Error
&se
) {
198 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
201 catch( std::exception
&e
) {
203 std::cerr
<< "std::exception caught: " << e
.what() << endl
;