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>
39 using namespace Barry
;
43 int logical
, major
, minor
;
44 const char *Version
= Barry::Version(logical
, major
, minor
);
46 cerr
<< string_vprintf(
47 _("bwatch - View video of BlackBerry screenshots\n"
48 " Copyright 2011, Alberto Mattea\n"
49 " Copyright 2011-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
52 " -d delay Delay interval between screenshots, in milliseconds.\n"
53 " The lower the value, the higher the load on the device.\n"
54 " Default is 500ms.\n"
55 " -p pin PIN of device to talk with\n"
56 " If only one device is plugged in, this flag is optional\n"
57 " -P pass Simplistic method to specify device password\n"
58 " -v Dump protocol data during operation\n"),
63 int main(int argc
, char *argv
[])
69 cout
.sync_with_stdio(true); // leave this on, since libusb uses stdio for debug messages
72 bool data_dump
= false;
74 int delay
= 500; // default delay of 500 ms
76 // process command line options
78 int cmd
= getopt(argc
, argv
, "d:hp:P:v");
84 case 'd': // delay interval in milliseconds
87 cerr
<< _("Invalid interval value of: ") << optarg
<< ". " << _("Defaulting to 500ms.") << endl
;
92 case 'p': // Blackberry PIN
93 pin
= strtoul(optarg
, NULL
, 16);
96 case 'P': // Device password
100 case 'v': // data dump on
112 int sdl_width
= -1, sdl_height
= -1;
113 SDL_Surface
*screen
= NULL
;
116 if( SDL_Init(SDL_INIT_VIDEO
) < 0 )
119 // Initialize the barry library. Must be called before
121 Barry::Init(data_dump
);
126 // Probe the USB bus for Blackberry devices and display.
127 // If user has specified a PIN, search for it in the
128 // available device list here as well
130 int activeDevice
= probe
.FindActive(pin
);
131 if( activeDevice
== -1 ) {
132 cerr
<< _("No device selected, or PIN not found") << endl
;
137 cout
<< _("Press a key to exit...") << endl
;
139 // Put this inside it's own block to avoid blocking the handheld
141 // Create our controller object
142 Barry::Controller
con(probe
.Get(activeDevice
));
143 Barry::Mode::JavaLoader
javaloader(con
);
144 javaloader
.Open(password
.c_str());
145 javaloader
.StartStream();
147 // - info object contains the screenshot properties
148 // (width, height...)
149 // - image will be filled with the raw pixel
151 javaloader
.GetScreenshot(info
, image
);
152 javaloader
.StopStream();
155 // Set the video mode according to the screenshot data
156 if( sdl_width
!= info
.width
|| sdl_height
!= info
.height
) {
157 sdl_width
= info
.width
;
158 sdl_height
= info
.height
;
159 if( !(screen
= SDL_SetVideoMode(info
.width
, info
.height
, 0, SDL_HWSURFACE
)) ) {
163 SDL_WM_SetCaption("Blackberry", 0);
166 // May want to tune this between 100 and 1000
169 // Convert to 24-bit RGB
170 ScreenshotToRGB(info
, image
, bitmap
, 0, 24, false);
174 tmp
= SDL_CreateRGBSurfaceFrom((char*)bitmap
.GetData(), info
.width
, info
.height
, 24, info
.width
*3, 0, 0, 0, 0);
175 SDL_BlitSurface(tmp
, 0, screen
, 0);
177 while(SDL_PollEvent(&event
)) {
178 switch (event
.type
) {
195 catch( Usb::Error
&ue
) {
196 std::cout
<< endl
; // flush any normal output first
197 std::cerr
<< _("Usb::Error caught: ") << ue
.what() << endl
;
200 catch( Barry::Error
&se
) {
202 std::cerr
<< _("Barry::Error caught: ") << se
.what() << endl
;
205 catch( std::exception
&e
) {
207 std::cerr
<< _("std::exception caught: ") << e
.what() << endl
;