diff --git a/src/apps/codycam/CodyCam.cpp b/src/apps/codycam/CodyCam.cpp index d9978bf559..f423d9904b 100644 --- a/src/apps/codycam/CodyCam.cpp +++ b/src/apps/codycam/CodyCam.cpp @@ -1,3 +1,10 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + #include "CodyCam.h" #include @@ -23,6 +30,7 @@ #include #include #include +#include #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "CodyCam" @@ -147,7 +155,7 @@ CodyCam::QuitRequested() void -CodyCam::MessageReceived(BMessage *message) +CodyCam::MessageReceived(BMessage* message) { switch (message->what) { case msg_start: @@ -233,7 +241,7 @@ CodyCam::_SetUpNodes() fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(), ((VideoWindow*)fWindow)->StatusLine(), NULL, 0); - if (!fVideoConsumer) { + if (fVideoConsumer == NULL) { fWindow->ErrorAlert(B_TRANSLATE("Cannot create a video window"), B_ERROR); return B_ERROR; @@ -254,8 +262,8 @@ CodyCam::_SetUpNodes() &cnt, B_MEDIA_RAW_VIDEO); if (status != B_OK || cnt < 1) { status = B_RESOURCE_UNAVAILABLE; - fWindow->ErrorAlert(B_TRANSLATE("Cannot find an available video stream"), - status); + fWindow->ErrorAlert( + B_TRANSLATE("Cannot find an available video stream"), status); return status; } @@ -369,7 +377,7 @@ void CodyCam::_TearDownNodes() { CALL("CodyCam::_TearDownNodes\n"); - if (!fMediaRoster) + if (fMediaRoster == NULL) return; if (fVideoConsumer) { @@ -497,7 +505,7 @@ void VideoWindow::MessageReceived(BMessage* message) { BControl* control = NULL; - message->FindPointer((const char*)"source", (void **)&control); + message->FindPointer((const char*)"source", (void**)&control); switch (message->what) { case msg_filename: @@ -515,7 +523,7 @@ VideoWindow::MessageReceived(BMessage* message) FTPINFO("never\n"); fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT); } else { - FTPINFO("%ld seconds\n", (long)seconds); + FTPINFO("%" B_PRId32 " seconds\n", seconds); fFtpInfo.rate = (bigtime_t)(seconds * 1000000LL); } break; @@ -609,7 +617,7 @@ VideoWindow::_BuildCaptureControls() fErrorView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // Capture controls - BGridLayout *controlsLayout = new BGridLayout(B_USE_DEFAULT_SPACING, + BGridLayout* controlsLayout = new BGridLayout(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING); controlsLayout->SetInsets(B_USE_SMALL_SPACING); @@ -627,7 +635,8 @@ VideoWindow::_BuildCaptureControls() // format menu fImageFormatMenu = new BPopUpMenu(B_TRANSLATE("Image Format Menu")); - BTranslationUtils::AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); + BTranslationUtils::AddTranslationItems(fImageFormatMenu, + B_TRANSLATOR_BITMAP); fImageFormatMenu->SetTargetForItems(this); if (fImageFormatSettings->Value() @@ -679,7 +688,7 @@ VideoWindow::_BuildCaptureControls() fUploadClientMenu = new BPopUpMenu(B_TRANSLATE("Send to" B_UTF8_ELLIPSIS)); for (int i = 0; i < kUploadClientsCount; i++) { - BMessage *m = new BMessage(msg_upl_client); + BMessage* m = new BMessage(msg_upl_client); m->AddInt32("client", i); fUploadClientMenu->AddItem(new BMenuItem(kUploadClients[i], m)); } @@ -843,7 +852,8 @@ VideoWindow::_QuitSettings() fFilenameSetting->ValueChanged(fFileName->Text()); fImageFormatSettings->ValueChanged(fImageFormatMenu->FindMarked()->Label()); fCaptureRateSetting->ValueChanged(fCaptureRateMenu->FindMarked()->Label()); - fUploadClientSetting->ValueChanged(fUploadClientMenu->FindMarked()->Label()); + fUploadClientSetting->ValueChanged( + fUploadClientMenu->FindMarked()->Label()); fSettings->SaveSettings(); delete fSettings; @@ -933,9 +943,9 @@ ControlWindow::QuitRequested() // #pragma mark - -int main() { +int main() +{ CodyCam app; app.Run(); return 0; } - diff --git a/src/apps/codycam/CodyCam.h b/src/apps/codycam/CodyCam.h index b54c734adb..742d9d51ad 100644 --- a/src/apps/codycam/CodyCam.h +++ b/src/apps/codycam/CodyCam.h @@ -1,10 +1,12 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef CODYCAM_H #define CODYCAM_H -#include "Settings.h" -#include "VideoConsumer.h" - #include #include @@ -18,6 +20,9 @@ #include #include +#include "Settings.h" +#include "VideoConsumer.h" + class BMediaRoster; @@ -143,7 +148,7 @@ private: port_id* fPortPtr; BView* fVideoView; - BTextView* fErrorView; + BTextView* fErrorView; BTextControl* fFileName; BBox* fCaptureSetupBox; @@ -194,4 +199,3 @@ private: }; #endif // CODYCAM_H - diff --git a/src/apps/codycam/CodyCam.rdef b/src/apps/codycam/CodyCam.rdef index ca4360f8d7..751f68c616 100644 --- a/src/apps/codycam/CodyCam.rdef +++ b/src/apps/codycam/CodyCam.rdef @@ -1,7 +1,7 @@ -resource(1, "BEOS:FILE_TYPES") message; +resource file_types message; -resource vector_icon { +resource vector_icon array { $"6E6369660B03010000020002023A00000000000000004000004BC00000000000" $"010000FFFF01000000020006023CC0000000000000003D000048000048800040" $"010101FFC1ACAC040168020106023A26EC38CA29B828213953DB48968D4B2BC6" @@ -27,31 +27,16 @@ resource app_signature "application/x-vnd.Haiku-CodyCam"; resource app_name_catalog_entry "x-vnd.Haiku-CodyCam:System name:CodyCam"; -resource(1, "BEOS:APP_VERSION") #'APPV' array -{ - $"0100000000000000000000000000000001000000312E30643100000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"000000000000000000000000000000000000000052342E3520C2A9313939312D" - $"3139393920426520496E636F72706F7261746564000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000000000000000000000000000000000000000000000000000" - $"0000000000000000" +resource app_version { + major = 1, + middle = 0, + minor = 0, + + variety = B_APPV_DEVELOPMENT, + internal = 1, + + short_info = "1.0d1", + long_info = "©1991-1999 Be, Inc., ©2003-2019 Haiku, Inc." }; -resource(1, "BEOS:APP_FLAGS") #'APPF' $"00000000"; - +resource app_flags B_SINGLE_LAUNCH; diff --git a/src/apps/codycam/FileUploadClient.cpp b/src/apps/codycam/FileUploadClient.cpp index 0a0426947c..8c265860d9 100644 --- a/src/apps/codycam/FileUploadClient.cpp +++ b/src/apps/codycam/FileUploadClient.cpp @@ -1,5 +1,13 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + #include "FileUploadClient.h" + FileUploadClient::FileUploadClient() { } @@ -13,48 +21,45 @@ FileUploadClient::~FileUploadClient() bool FileUploadClient::ChangeDir(const string& dir) { - bool rc = false; - return rc; + return false; } bool FileUploadClient::ListDirContents(string& listing) { - bool rc = false; - return rc; + return false; } bool FileUploadClient::PrintWorkingDir(string& dir) { - bool rc = false; - return rc; + return false; } bool -FileUploadClient::Connect(const string& server, const string& login, const string& passwd) +FileUploadClient::Connect(const string& server, const string& login, + const string& passwd) { - bool rc = false; - return rc; + return false; } bool -FileUploadClient::PutFile(const string& local, const string& remote, ftp_mode mode) +FileUploadClient::PutFile(const string& local, const string& remote, + ftp_mode mode) { - bool rc = false; - return rc; + return false; } bool -FileUploadClient::GetFile(const string& remote, const string& local, ftp_mode mode) +FileUploadClient::GetFile(const string& remote, const string& local, + ftp_mode mode) { - bool rc = false; - return rc; + return false; } @@ -63,16 +68,14 @@ FileUploadClient::GetFile(const string& remote, const string& local, ftp_mode mo bool FileUploadClient::MoveFile(const string& oldPath, const string& newPath) { - bool rc = false; - return rc; + return false; } bool FileUploadClient::Chmod(const string& path, const string& mod) { - bool rc = false; - return rc; + return false; } @@ -80,5 +83,3 @@ void FileUploadClient::SetPassive(bool on) { } - - diff --git a/src/apps/codycam/FileUploadClient.h b/src/apps/codycam/FileUploadClient.h index 7c0d82bfc6..0aea7bc8e5 100644 --- a/src/apps/codycam/FileUploadClient.h +++ b/src/apps/codycam/FileUploadClient.h @@ -1,3 +1,8 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef FILE_UPLOAD_CLIENT_H #define FILE_UPLOAD_CLIENT_H @@ -9,31 +14,35 @@ using std::string; class FileUploadClient { - public: - FileUploadClient(); -virtual ~FileUploadClient(); +public: + FileUploadClient(); + virtual ~FileUploadClient(); - enum ftp_mode { + enum ftp_mode { binary_mode, ascii_mode - }; + }; -virtual bool Connect(const string& server, const string& login, - const string& passwd); + virtual bool Connect(const string& server, + const string& login, + const string& passwd); -virtual bool PutFile(const string& local, const string& remote, - ftp_mode mode = binary_mode); + virtual bool PutFile(const string& local, + const string& remote, + ftp_mode mode = binary_mode); -virtual bool GetFile(const string& remote, const string& local, - ftp_mode mode = binary_mode); + virtual bool GetFile(const string& remote, + const string& local, + ftp_mode mode = binary_mode); -virtual bool MoveFile(const string& oldPath, const string& newPath); -virtual bool ChangeDir(const string& dir); -virtual bool PrintWorkingDir(string& dir); -virtual bool ListDirContents(string& listing); -virtual bool Chmod(const string& path, const string& mod); + virtual bool MoveFile(const string& oldPath, + const string& newPath); + virtual bool ChangeDir(const string& dir); + virtual bool PrintWorkingDir(string& dir); + virtual bool ListDirContents(string& listing); + virtual bool Chmod(const string& path, const string& mod); -virtual void SetPassive(bool on); + virtual void SetPassive(bool on); }; #endif // FILE_UPLOAD_CLIENT_H diff --git a/src/apps/codycam/FtpClient.cpp b/src/apps/codycam/FtpClient.cpp index 3939ab046e..8ae26c945a 100644 --- a/src/apps/codycam/FtpClient.cpp +++ b/src/apps/codycam/FtpClient.cpp @@ -1,3 +1,10 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + #include "FtpClient.h" #include @@ -12,7 +19,8 @@ FtpClient::FtpClient() - : FileUploadClient(), + : + FileUploadClient(), fState(0), fControl(NULL), fData(NULL) @@ -32,7 +40,8 @@ FtpClient::ChangeDir(const string& dir) { bool rc = false; int code, codeType; - string cmd = "CWD ", replyString; + string cmd = "CWD "; + string replyString; cmd += dir; @@ -87,7 +96,7 @@ FtpClient::ListDirContents(string& listing) } delete fData; - fData = 0; + fData = NULL; return rc; } @@ -98,7 +107,8 @@ FtpClient::PrintWorkingDir(string& dir) { bool rc = false; int code, codeType; - string cmd = "PWD", replyString; + string cmd = "PWD"; + string replyString; long i; if (_SendRequest(cmd) == true) { @@ -119,7 +129,8 @@ FtpClient::PrintWorkingDir(string& dir) bool -FtpClient::Connect(const string& server, const string& login, const string& passwd) +FtpClient::Connect(const string& server, const string& login, + const string& passwd) { bool rc = false; int code, codeType; @@ -129,7 +140,7 @@ FtpClient::Connect(const string& server, const string& login, const string& pass delete fControl; delete fData; - fControl = new BNetEndpoint; + fControl = new BNetEndpoint(); if (fControl->InitCheck() != B_NO_ERROR) return false; @@ -174,7 +185,7 @@ FtpClient::Connect(const string& server, const string& login, const string& pass _SetState(ftp_connected); else { delete fControl; - fControl = 0; + fControl = NULL; } return rc; @@ -188,7 +199,9 @@ FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode) string cmd, replyString; int code, codeType, rlen, slen, i; BFile infile(local.c_str(), B_READ_ONLY); - char buf[8192], sbuf[16384], *stmp; + char buf[8192]; + char sbuf[16384]; + char* stmp; if (infile.InitCheck() != B_NO_ERROR) return false; @@ -251,7 +264,7 @@ FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode) } delete fData; - fData = 0; + fData = NULL; if (rc) { _GetReply(replyString, code, codeType); @@ -269,7 +282,9 @@ FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode) string cmd, replyString; int code, codeType, rlen, slen, i; BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE); - char buf[8192], sbuf[16384], *stmp; + char buf[8192]; + char sbuf[16384]; + char* stmp; bool writeError = false; if (outfile.InitCheck() != B_NO_ERROR) @@ -328,7 +343,7 @@ FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode) } delete fData; - fData = 0; + fData = NULL; if (rc) { _GetReply(replyString, code, codeType); @@ -373,7 +388,8 @@ FtpClient::Chmod(const string& path, const string& mod) { bool rc = false; int code, codeType; - string cmd = "SITE CHMOD ", replyString; + string cmd = "SITE CHMOD "; + string replyString; cmd += mod; cmd += " "; @@ -381,10 +397,11 @@ FtpClient::Chmod(const string& path, const string& mod) if (path.length() == 0) cmd += '/'; -printf(B_TRANSLATE("cmd: '%s'\n"), cmd.c_str()); + printf(B_TRANSLATE("cmd: '%s'\n"), cmd.c_str()); + if (_SendRequest(cmd) == true) { if (_GetReply(replyString, code, codeType) == true) { -printf(B_TRANSLATE("reply: %d, %d\n"), code, codeType); + printf(B_TRANSLATE("reply: %d, %d\n"), code, codeType); if (codeType == 2) rc = true; } @@ -452,9 +469,10 @@ FtpClient::_GetReplyLine(string& line) int c = 0; bool done = false; - line = ""; // Thanks to Stephen van Egmond for catching a bug here + line = ""; + // Thanks to Stephen van Egmond for catching a bug here - if (fControl != 0) { + if (fControl != NULL) { rc = true; while (done == false && fControl->Receive(&c, 1) > 0) { if (c == EOF || c == xEOF || c == '\n') { @@ -528,7 +546,8 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType) * 123 The last line */ - if ((rc = _GetReplyLine(line)) == true) { + rc = _GetReplyLine(line); + if (rc == true) { outString = line; outString += '\n'; printf(outString.c_str()); @@ -536,13 +555,16 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType) outCode = atoi(tempString.c_str()); if (line[3] == '-') { - while ((rc = _GetReplyLine(line)) == true) { + rc = _GetReplyLine(line); + while (rc == true) { outString += line; outString += '\n'; printf(outString.c_str()); // we're done with nnn when we get to a "nnn blahblahblah" if ((line.find(tempString) == 0) && line[3] == ' ') break; + + rc = _GetReplyLine(line); } } } @@ -554,7 +576,7 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType) if (outCode == 421) { delete fControl; - fControl = 0; + fControl = NULL; _ClearState(ftp_connected); } @@ -575,9 +597,9 @@ FtpClient::_OpenDataConnection() struct sockaddr_in sa; delete fData; - fData = 0; + fData = NULL; - fData = new BNetEndpoint; + fData = new BNetEndpoint(); if (_TestState(ftp_passive)) { // Here we send a "pasv" command and connect to the remote server @@ -595,13 +617,15 @@ FtpClient::_OpenDataConnection() i = replyString.find('('); i++; - replyString = replyString.substr(i, replyString.find(')') - i); + replyString = replyString.substr(i, + replyString.find(')') - i); if (sscanf(replyString.c_str(), "%d,%d,%d,%d,%d,%d", &paddr[0], &paddr[1], &paddr[2], &paddr[3], &paddr[4], &paddr[5]) != 6) { - // cannot do passive. Do a little harmless rercursion here - _ClearState(ftp_passive); - return _OpenDataConnection(); + // Cannot do passive. + // Do a little harmless rercursion here. + _ClearState(ftp_passive); + return _OpenDataConnection(); } for (i = 0; i < 6; i++) @@ -661,9 +685,9 @@ FtpClient::_AcceptDataConnection() bool rc = false; if (_TestState(ftp_passive) == false) { - if (fData != 0) { + if (fData != NULL) { endPoint = fData->Accept(); - if (endPoint != 0) { + if (endPoint != NULL) { delete fData; fData = endPoint; rc = true; diff --git a/src/apps/codycam/FtpClient.h b/src/apps/codycam/FtpClient.h index 0536d5e5f0..faffc2816c 100644 --- a/src/apps/codycam/FtpClient.h +++ b/src/apps/codycam/FtpClient.h @@ -1,3 +1,8 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef FTP_CLIENT_H #define FTP_CLIENT_H @@ -6,7 +11,9 @@ #include #include -#include +#include +#include + #include "FileUploadClient.h" using std::string; @@ -24,47 +31,52 @@ using std::string; class FtpClient : public FileUploadClient { - public: - FtpClient(); - ~FtpClient(); +public: + FtpClient(); + ~FtpClient(); - bool Connect(const string& server, const string& login, - const string& passwd); + bool Connect(const string& server, + const string& login, + const string& passwd); - bool PutFile(const string& local, const string& remote, - ftp_mode mode = binary_mode); + bool PutFile(const string& local, + const string& remote, + ftp_mode mode = binary_mode); - bool GetFile(const string& remote, const string& local, - ftp_mode mode = binary_mode); + bool GetFile(const string& remote, + const string& local, + ftp_mode mode = binary_mode); - bool MoveFile(const string& oldPath, const string& newPath); - bool ChangeDir(const string& dir); - bool PrintWorkingDir(string& dir); - bool ListDirContents(string& listing); - bool Chmod(const string& path, const string& mod); + bool MoveFile(const string& oldPath, + const string& newPath); + bool ChangeDir(const string& dir); + bool PrintWorkingDir(string& dir); + bool ListDirContents(string& listing); + bool Chmod(const string& path, const string& mod); - void SetPassive(bool on); + void SetPassive(bool on); - protected: - enum { - ftp_complete = 1UL, - ftp_connected = 2, - ftp_passive = 4 - }; +protected: + enum { + ftp_complete = 1UL, + ftp_connected = 2, + ftp_passive = 4 + }; - bool _TestState(unsigned long state); - void _SetState(unsigned long state); - void _ClearState(unsigned long state); + bool _TestState(unsigned long state); + void _SetState(unsigned long state); + void _ClearState(unsigned long state); - bool _SendRequest(const string& cmd); - bool _GetReply(string& outString, int& outCode, int& codeType); - bool _GetReplyLine(string& line); - bool _OpenDataConnection(); - bool _AcceptDataConnection(); + bool _SendRequest(const string& cmd); + bool _GetReply(string& outString, int& outCode, + int& codeType); + bool _GetReplyLine(string& line); + bool _OpenDataConnection(); + bool _AcceptDataConnection(); - unsigned long fState; - BNetEndpoint* fControl; - BNetEndpoint* fData; + unsigned long fState; + BNetEndpoint* fControl; + BNetEndpoint* fData; }; diff --git a/src/apps/codycam/Settings.cpp b/src/apps/codycam/Settings.cpp index 537d0bf1f9..869d7d7581 100644 --- a/src/apps/codycam/Settings.cpp +++ b/src/apps/codycam/Settings.cpp @@ -1,3 +1,10 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + #include "Settings.h" #include @@ -71,9 +78,9 @@ StringValueSetting::NeedsSaving() const const char* -StringValueSetting::Handle(const char *const *argv) +StringValueSetting::Handle(const char* const *argv) { - if (!*++argv) + if (*++argv == NULL) return fValueExpectedErrorString; ValueChanged(*argv); @@ -108,9 +115,9 @@ EnumeratedStringValueSetting::ValueChanged(const char* newValue) const char* -EnumeratedStringValueSetting::Handle(const char *const *argv) +EnumeratedStringValueSetting::Handle(const char* const *argv) { - if (!*++argv) + if (*++argv == NULL) return fValueExpectedErrorString; printf("---EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv); @@ -127,7 +134,7 @@ EnumeratedStringValueSetting::_ValidateString(const char* string) { for (int32 i = 0;; i++) { const char* enumString = fEnumerator(i); - if (!enumString) + if (enumString == NULL) return false; if (strcmp(enumString, string) == 0) return true; @@ -142,7 +149,8 @@ EnumeratedStringValueSetting::_ValidateString(const char* string) ScalarValueSetting::ScalarValueSetting(const char* name, int32 defaultValue, const char* valueExpectedErrorString, const char* wrongValueErrorString, int32 min, int32 max) - : SettingsArgvDispatcher(name), + : + SettingsArgvDispatcher(name), fDefaultValue(defaultValue), fValue(defaultValue), fMax(max), @@ -182,9 +190,9 @@ ScalarValueSetting::GetValueAsString(char* buffer) const const char* -ScalarValueSetting::Handle(const char *const *argv) +ScalarValueSetting::Handle(const char* const *argv) { - if (!*++argv) + if (*++argv == NULL) return fValueExpectedErrorString; int32 newValue = atoi(*argv); @@ -199,7 +207,7 @@ ScalarValueSetting::Handle(const char *const *argv) void ScalarValueSetting::SaveSettingValue(Settings* settings) { - settings->Write("%d", fValue); + settings->Write("%" B_PRId32, fValue); } @@ -214,7 +222,8 @@ ScalarValueSetting::NeedsSaving() const BooleanValueSetting::BooleanValueSetting(const char* name, bool defaultValue) - : ScalarValueSetting(name, defaultValue, 0, 0) + : + ScalarValueSetting(name, defaultValue, 0, 0) { } @@ -232,9 +241,9 @@ BooleanValueSetting::Value() const const char* -BooleanValueSetting::Handle(const char *const *argv) +BooleanValueSetting::Handle(const char* const *argv) { - if (!*++argv) { + if (*++argv == NULL) { return B_TRANSLATE_COMMENT("on or off expected","Do not translate " "'on' and 'off'"); } diff --git a/src/apps/codycam/Settings.h b/src/apps/codycam/Settings.h index cde0f821ba..7b280ed0ef 100644 --- a/src/apps/codycam/Settings.h +++ b/src/apps/codycam/Settings.h @@ -1,3 +1,8 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef SETTINGS_H #define SETTINGS_H @@ -18,7 +23,7 @@ public: void ValueChanged(const char* newValue); const char* Value() const; - virtual const char* Handle(const char *const *argv); + virtual const char* Handle(const char* const *argv); protected: virtual void SaveSettingValue(Settings*); @@ -46,7 +51,7 @@ public: const char* wrongValueErrorString); void ValueChanged(const char* newValue); - virtual const char* Handle(const char *const *argv); + virtual const char* Handle(const char* const *argv); private: bool _ValidateString(const char* string); @@ -61,13 +66,14 @@ public: int32 defaultValue, const char* valueExpectedErrorString, const char* wrongValueErrorString, - int32 min = INT32_MIN, int32 max = INT32_MAX); + int32 min = INT32_MIN, + int32 max = INT32_MAX); virtual ~ScalarValueSetting(); void ValueChanged(int32 newValue); int32 Value() const; void GetValueAsString(char*) const; - virtual const char* Handle(const char *const *argv); + virtual const char* Handle(const char* const *argv); protected: virtual void SaveSettingValue(Settings*); @@ -89,10 +95,10 @@ public: virtual ~BooleanValueSetting(); bool Value() const; - virtual const char* Handle(const char *const *argv); + virtual const char* Handle(const char* const *argv); protected: - virtual void SaveSettingValue(Settings *); + virtual void SaveSettingValue(Settings*); }; #endif // SETTINGS_H diff --git a/src/apps/codycam/SftpClient.cpp b/src/apps/codycam/SftpClient.cpp index 387ff9a8e5..bc0cc60eff 100644 --- a/src/apps/codycam/SftpClient.cpp +++ b/src/apps/codycam/SftpClient.cpp @@ -1,10 +1,20 @@ -#include -#include +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + #include "SftpClient.h" +#include + +#include + + SftpClient::SftpClient() - : SpawningUploadClient() + : + SpawningUploadClient() { } @@ -19,33 +29,37 @@ SftpClient::~SftpClient() bool SftpClient::ChangeDir(const string& dir) { - bool rc = false; int len; BString cmd("cd"); BString reply; + cmd << " " << dir.c_str() << "\n"; SendCommand(cmd.String()); - if ((len = ReadReply(&reply)) < 0) { + + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; - rc = true; - return rc; + + return true; } bool SftpClient::ListDirContents(string& listing) { - bool rc = false; int len; - SendCommand("ls\n"); BString reply; + + SendCommand("ls\n"); do { - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } @@ -54,17 +68,16 @@ SftpClient::ListDirContents(string& listing) if (reply.FindFirst("sftp>") == 0) return true; } while (true); - return rc; + + return false; } bool SftpClient::PrintWorkingDir(string& dir) { - bool rc = false; SendCommand("pwd\n"); - BString reply; - return rc; + return false; } @@ -72,24 +85,30 @@ bool SftpClient::Connect(const string& server, const string& login, const string& passwd) { - bool rc = false; BString cmd("sftp "); BString host(server.c_str()); BString port; + if (host.FindFirst(':')) host.MoveInto(port, host.FindFirst(':'), host.Length()); port.RemoveAll(":"); + if (port.Length()) cmd << "-oPort=" << port << " "; + cmd << login.c_str(); cmd << "@" << host.String(); printf("COMMAND: '%s'\n", cmd.String()); SetCommandLine(cmd.String()); - rc = SpawningUploadClient::Connect(server, login, passwd); + + if (!SpawningUploadClient::Connect(server, login, passwd)) + return false; + BString reply; ssize_t len; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetLongReadText(), len); return false; } @@ -97,10 +116,12 @@ SftpClient::Connect(const string& server, const string& login, if (reply.FindFirst("Connecting to ") != 0) return false; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetLongReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst(/*[pP]*/"assword:") < 0) return false; @@ -108,63 +129,70 @@ SftpClient::Connect(const string& server, const string& login, write(OutputPipe(), passwd.c_str(), strlen(passwd.c_str())); write(OutputPipe(), "\n", 1); - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetLongReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply != "\n") return false; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetLongReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; - return rc; + + return true; } bool SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode) { - bool rc = false; int len; //XXX: handle mode ? BString cmd("put"); cmd << " " << local.c_str() << " " << remote.c_str() << "\n"; SendCommand(cmd.String()); + BString reply; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("Uploading") < 0) return false; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; - rc = true; - return rc; + return true; } bool SftpClient::GetFile(const string& remote, const string& local, ftp_mode mode) { - bool rc = false; //XXX - return rc; + return false; } @@ -173,7 +201,6 @@ SftpClient::GetFile(const string& remote, const string& local, ftp_mode mode) bool SftpClient::MoveFile(const string& oldPath, const string& newPath) { - bool rc = false; int len; // sftpd can't rename to an existing file... @@ -183,19 +210,23 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath) SendCommand(cmd.String()); BString reply; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); // we don't care if it worked or not. //if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") ) // return false; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; @@ -203,47 +234,53 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath) cmd = "rename"; cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n"; SendCommand(cmd.String()); - if ((len = ReadReply(&reply)) < 0) { + + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; - rc = true; - return rc; + + return true; } bool SftpClient::Chmod(const string& path, const string& mod) { - bool rc = false; int len; //XXX: handle mode ? BString cmd("chmod"); cmd << " " << mod.c_str() << " " << path.c_str() << "\n"; SendCommand(cmd.String()); + BString reply; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("Changing") < 0) return false; - if ((len = ReadReply(&reply)) < 0) { + len = ReadReply(&reply); + if (len < 0) { fprintf(stderr, _GetReadText(), len); return false; } + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; - rc = true; - return rc; + return true; } @@ -272,5 +309,3 @@ SftpClient::_GetReplyText() const { return B_TRANSLATE("reply: '%s'\n"); } - - diff --git a/src/apps/codycam/SftpClient.h b/src/apps/codycam/SftpClient.h index d9b17ead80..c0fec49734 100644 --- a/src/apps/codycam/SftpClient.h +++ b/src/apps/codycam/SftpClient.h @@ -1,3 +1,8 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef SFTP_CLIENT_H #define SFTP_CLIENT_H diff --git a/src/apps/codycam/SpawningUploadClient.cpp b/src/apps/codycam/SpawningUploadClient.cpp index 8651394c7c..2fa93adfde 100644 --- a/src/apps/codycam/SpawningUploadClient.cpp +++ b/src/apps/codycam/SpawningUploadClient.cpp @@ -1,18 +1,27 @@ -#include -#include -#include -#include -#include +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ -#include #include "SpawningUploadClient.h" +#include +#include +#include +#include + +#include +#include + + SpawningUploadClient::SpawningUploadClient() - : FileUploadClient() - , fCommand() - , fCommandPid(-1) - , fPty(-1) + : + FileUploadClient(), + fCommand(), + fCommandPid(-1), + fPty(-1) { } @@ -22,18 +31,21 @@ SpawningUploadClient::~SpawningUploadClient() close(fPty); kill(fCommandPid, SIGTERM); kill(fCommandPid, SIGKILL); + status_t ret; wait_for_thread(fCommandPid, &ret); } bool -SpawningUploadClient::Connect(const string& server, const string& login, const string& passwd) +SpawningUploadClient::Connect(const string& server, const string& login, + const string& passwd) { bool rc = false; // fCommand += " "; // fCommand += server; rc = SpawnCommand(); + return rc; } @@ -58,18 +70,19 @@ SpawningUploadClient::SpawnCommand() shellcmd << "export LC_ALL=C; export LANG=C; "; shellcmd << "exec "; shellcmd << fCommand.c_str(); -printf("spawning: '%s'\n", shellcmd.String()); + printf("spawning: '%s'\n", shellcmd.String()); args[2] = shellcmd.String(); - fCommandPid = load_image(3, args, (const char **)environ); + fCommandPid = load_image(3, args, (const char**)environ); if (fCommandPid < 0) return false; resume_thread(fCommandPid); + return true; } status_t -SpawningUploadClient::SetCommandLine(const char *command) +SpawningUploadClient::SetCommandLine(const char* command) { fCommand = command; return B_OK; @@ -77,22 +90,24 @@ SpawningUploadClient::SetCommandLine(const char *command) ssize_t -SpawningUploadClient::SendCommand(const char *cmd) +SpawningUploadClient::SendCommand(const char* cmd) { return write(InputPipe(), cmd, strlen(cmd)); } ssize_t -SpawningUploadClient::ReadReply(BString *to) +SpawningUploadClient::ReadReply(BString* to) { char buff[1024]; ssize_t len; + to->Truncate(0); len = read(OutputPipe(), buff, 1024); if (len < 0) return errno; to->Append(buff, len); + return len; } @@ -105,7 +120,7 @@ SpawningUploadClient::ParseReply() int -SpawningUploadClient::getpty(char *pty, char *tty) +SpawningUploadClient::getpty(char* pty, char* tty) { static const char major[] = "pqrs"; static const char minor[] = "0123456789abcdef"; @@ -120,9 +135,7 @@ SpawningUploadClient::getpty(char *pty, char *tty) sprintf(tty, "/dev/tt/%c%c", major[i], minor[j]); fd = open(pty, O_RDWR|O_NOCTTY); if (fd >= 0) - { return fd; - } } } @@ -136,40 +149,37 @@ SpawningUploadClient::getpty(char *pty, char *tty) bool SpawningUploadClient::ChangeDir(const string& dir) { - bool rc = false; - return rc; + return false; } bool SpawningUploadClient::ListDirContents(string& listing) { - bool rc = false; - return rc; + return false; } bool SpawningUploadClient::PrintWorkingDir(string& dir) { - bool rc = false; - return rc; + return false; } bool -SpawningUploadClient::PutFile(const string& local, const string& remote, ftp_mode mode) +SpawningUploadClient::PutFile(const string& local, const string& remote, + ftp_mode mode) { - bool rc = false; - return rc; + return false; } bool -SpawningUploadClient::GetFile(const string& remote, const string& local, ftp_mode mode) +SpawningUploadClient::GetFile(const string& remote, const string& local, + ftp_mode mode) { - bool rc = false; - return rc; + return false; } @@ -178,16 +188,14 @@ SpawningUploadClient::GetFile(const string& remote, const string& local, ftp_mod bool SpawningUploadClient::MoveFile(const string& oldPath, const string& newPath) { - bool rc = false; - return rc; + return false; } bool SpawningUploadClient::Chmod(const string& path, const string& mod) { - bool rc = false; - return rc; + return false; } @@ -195,5 +203,3 @@ void SpawningUploadClient::SetPassive(bool on) { } - - diff --git a/src/apps/codycam/SpawningUploadClient.h b/src/apps/codycam/SpawningUploadClient.h index b2e1c60785..74a95e6935 100644 --- a/src/apps/codycam/SpawningUploadClient.h +++ b/src/apps/codycam/SpawningUploadClient.h @@ -1,50 +1,63 @@ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef SPAWNING_UPLOAD_CLIENT_H #define SPAWNING_UPLOAD_CLIENT_H #include "FileUploadClient.h" -#include #include -#include +#include + +#include +#include class SpawningUploadClient : public FileUploadClient { - public: - SpawningUploadClient(); -virtual ~SpawningUploadClient(); +public: + SpawningUploadClient(); + virtual ~SpawningUploadClient(); -virtual bool Connect(const string& server, const string& login, - const string& passwd); + virtual bool Connect(const string& server, + const string& login, + const string& passwd); -virtual bool PutFile(const string& local, const string& remote, - ftp_mode mode = binary_mode); + virtual bool PutFile(const string& local, + const string& remote, + ftp_mode mode = binary_mode); -virtual bool GetFile(const string& remote, const string& local, - ftp_mode mode = binary_mode); + virtual bool GetFile(const string& remote, + const string& local, + ftp_mode mode = binary_mode); -virtual bool MoveFile(const string& oldPath, const string& newPath); -virtual bool ChangeDir(const string& dir); -virtual bool PrintWorkingDir(string& dir); -virtual bool ListDirContents(string& listing); -virtual bool Chmod(const string& path, const string& mod); + virtual bool MoveFile(const string& oldPath, + const string& newPath); + virtual bool ChangeDir(const string& dir); + virtual bool PrintWorkingDir(string& dir); + virtual bool ListDirContents(string& listing); + virtual bool Chmod(const string& path, const string& mod); -virtual void SetPassive(bool on); + virtual void SetPassive(bool on); protected: -status_t SetCommandLine(const char *command); -ssize_t SendCommand(const char *cmd); -ssize_t ReadReply(BString *to); -virtual status_t ParseReply(); -int getpty(char *pty, char *tty); + status_t SetCommandLine(const char* command); + ssize_t SendCommand(const char* cmd); + ssize_t ReadReply(BString* to); + virtual status_t ParseReply(); + int getpty(char* pty, char* tty); -int InputPipe() const { return fPty; }; -int OutputPipe() const { return fPty; }; + int InputPipe() const { return fPty; }; + int OutputPipe() const { return fPty; }; private: -bool SpawnCommand(); -string fCommand; -pid_t fCommandPid; -int fPty; + bool SpawnCommand(); + +private: + string fCommand; + pid_t fCommandPid; + int fPty; }; #endif // SPAWNING_UPLOAD_CLIENT_H diff --git a/src/apps/codycam/VideoConsumer.cpp b/src/apps/codycam/VideoConsumer.cpp index 736a22c1ca..1c6c942bd1 100644 --- a/src/apps/codycam/VideoConsumer.cpp +++ b/src/apps/codycam/VideoConsumer.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved. -// SMS -// VideoConsumer.cpp +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ -#include "FileUploadClient.h" -#include "FtpClient.h" -#include "SftpClient.h" #include "VideoConsumer.h" #include #include -#include #include +#include #include +#include #include #include #include @@ -25,10 +25,15 @@ #include #include +#include "FileUploadClient.h" +#include "FtpClient.h" +#include "SftpClient.h" + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "VideoConsumer.cpp" + #define M1 ((double)1000000.0) #define JITTER 20000 @@ -38,7 +43,7 @@ #define LOOP printf -static status_t SetFileType(BFile* file, int32 translator, uint32 type); +static status_t SetFileType(BFile* file, int32 translator, uint32 type); const media_raw_video_format vid_format = {29.97, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB16, 320, 240, 320 * 4, 0, 0}}; @@ -47,7 +52,8 @@ const media_raw_video_format vid_format = {29.97, 1, 0, 239, VideoConsumer::VideoConsumer(const char* name, BView* view, BStringView* statusLine, BMediaAddOn* addon, const uint32 internalId) - : BMediaNode(name), + : + BMediaNode(name), BMediaEventLooper(), BBufferConsumer(B_MEDIA_RAW_VIDEO), fStatusLine(statusLine), @@ -75,7 +81,7 @@ VideoConsumer::VideoConsumer(const char* name, BView* view, for (uint32 j = 0; j < 3; j++) { fBitmap[j] = NULL; - fBufferMap[j] = 0; + fBufferMap[j] = NULL; } strcpy(fFileNameText, ""); @@ -99,7 +105,7 @@ VideoConsumer::~VideoConsumer() if (fWindow->Lock()) { puts(B_TRANSLATE("Closing the window")); fWindow->Close(); - fWindow = 0; + fWindow = NULL; } } @@ -115,7 +121,6 @@ VideoConsumer::~VideoConsumer() kill_thread(fFtpThread); DeleteBuffers(); - } /******************************** @@ -192,13 +197,15 @@ VideoConsumer::RequestCompleted(const media_request_info& info) switch (info.what) { case media_request_info::B_SET_OUTPUT_BUFFERS_FOR: if (info.status != B_OK) - ERROR("VideoConsumer::RequestCompleted: Not using our buffers!\n"); + ERROR("VideoConsumer::RequestCompleted: " + "Not using our buffers!\n"); break; default: ERROR("VideoConsumer::RequestCompleted: Invalid argument\n"); break; } + return B_OK; } @@ -208,7 +215,6 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size) { //FUNCTION("VideoConsumer::HandleMessage\n"); ftp_msg_info* info = (ftp_msg_info*)data; - status_t status = B_OK; switch (message) { case FTP_INFO: @@ -224,8 +230,9 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size) strcpy(fPasswordText, info->passwordText); strcpy(fDirectoryText, info->directoryText); // remove old user events - EventQueue()->FlushEvents(TimeSource()->Now(), BTimedEventQueue::B_ALWAYS, - true, BTimedEventQueue::B_USER_EVENT); + EventQueue()->FlushEvents(TimeSource()->Now(), + BTimedEventQueue::B_ALWAYS, true, + BTimedEventQueue::B_USER_EVENT); if (fRate != B_INFINITE_TIMEOUT) { // if rate is not "Never," push an event // to restart captures 5 seconds from now @@ -236,30 +243,31 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size) break; } - return status; + return B_OK; } void VideoConsumer::BufferReceived(BBuffer* buffer) { - LOOP("VideoConsumer::Buffer #%" B_PRId32 " received, start_time %" B_PRIdBIGTIME - "\n", buffer->ID(), buffer->Header()->start_time); + LOOP("VideoConsumer::Buffer #%" B_PRId32 " received, start_time %" + B_PRIdBIGTIME "\n", buffer->ID(), buffer->Header()->start_time); if (RunState() == B_STOPPED) { buffer->Recycle(); return; } - media_timed_event event(buffer->Header()->start_time, BTimedEventQueue::B_HANDLE_BUFFER, - buffer, BTimedEventQueue::B_RECYCLE_BUFFER); + media_timed_event event(buffer->Header()->start_time, + BTimedEventQueue::B_HANDLE_BUFFER, buffer, + BTimedEventQueue::B_RECYCLE_BUFFER); EventQueue()->AddEvent(event); } void -VideoConsumer::ProducerDataStatus(const media_destination& forWhom, int32 status, - bigtime_t atMediaTime) +VideoConsumer::ProducerDataStatus(const media_destination& forWhom, + int32 status, bigtime_t atMediaTime) { FUNCTION("VideoConsumer::ProducerDataStatus\n"); @@ -292,8 +300,8 @@ VideoConsumer::CreateBuffers(const media_format& withFormat) } // and attach the bitmaps to the buffer group for (uint32 j = 0; j < 3; j++) { - fBitmap[j] = new BBitmap(BRect(0, 0, (xSize - 1), (ySize - 1)), colorspace, - false, true); + fBitmap[j] = new BBitmap(BRect(0, 0, (xSize - 1), (ySize - 1)), + colorspace, false, true); if (fBitmap[j]->IsValid()) { buffer_clone_info info; if ((info.area = area_for(fBitmap[j]->Bits())) == B_ERROR) @@ -304,11 +312,13 @@ VideoConsumer::CreateBuffers(const media_format& withFormat) info.buffer = 0; if ((status = fBuffers->AddBuffer(info)) != B_OK) { - ERROR("VideoConsumer::CreateBuffers - ERROR ADDING BUFFER TO GROUP\n"); + ERROR("VideoConsumer::CreateBuffers - " + "ERROR ADDING BUFFER TO GROUP\n"); return status; } else - PROGRESS("VideoConsumer::CreateBuffers - SUCCESSFUL ADD BUFFER TO GROUP\n"); + PROGRESS("VideoConsumer::CreateBuffers - " + "SUCCESSFUL ADD BUFFER TO GROUP\n"); } else { ERROR("VideoConsumer::CreateBuffers - ERROR CREATING VIDEO RING " "BUFFER: %08" B_PRIx32 "\n", status); @@ -320,19 +330,22 @@ VideoConsumer::CreateBuffers(const media_format& withFormat) for (int j = 0; j < 3; j++) buffList[j] = NULL; - if ((status = fBuffers->GetBufferList(3, buffList)) == B_OK) + status = fBuffers->GetBufferList(3, buffList); + if (status == B_OK) for (int j = 0; j < 3; j++) if (buffList[j] != NULL) { fBufferMap[j] = buffList[j]; PROGRESS(" j = %d buffer = %p\n", j, fBufferMap[j]); } else { - ERROR("VideoConsumer::CreateBuffers ERROR MAPPING RING BUFFER\n"); + ERROR("VideoConsumer::CreateBuffers " + "ERROR MAPPING RING BUFFER\n"); return B_ERROR; } else ERROR("VideoConsumer::CreateBuffers ERROR IN GET BUFFER LIST\n"); - fFtpBitmap = new BBitmap(BRect(0, 0, xSize - 1, ySize - 1), B_RGB32, false, false); + fFtpBitmap = new BBitmap(BRect(0, 0, xSize - 1, ySize - 1), B_RGB32, false, + false); FUNCTION("VideoConsumer::CreateBuffers - EXIT\n"); return status; @@ -354,13 +367,15 @@ VideoConsumer::DeleteBuffers() fBitmap[j] = NULL; } } + FUNCTION("VideoConsumer::DeleteBuffers - EXIT\n"); } status_t -VideoConsumer::Connected(const media_source& producer, const media_destination& where, - const media_format& withFormat, media_input* outInput) +VideoConsumer::Connected(const media_source& producer, + const media_destination& where, const media_format& withFormat, + media_input* outInput) { FUNCTION("VideoConsumer::Connected\n"); @@ -374,7 +389,7 @@ VideoConsumer::Connected(const media_source& producer, const media_destination& int32 changeTag = 1; if (CreateBuffers(withFormat) == B_OK) BBufferConsumer::SetOutputBuffersFor(producer, fDestination, - fBuffers, (void *)&userData, &changeTag, true); + fBuffers, (void*)&userData, &changeTag, true); else { ERROR("VideoConsumer::Connected - COULDN'T CREATE BUFFERS\n"); return B_ERROR; @@ -388,7 +403,8 @@ VideoConsumer::Connected(const media_source& producer, const media_destination& void -VideoConsumer::Disconnected(const media_source& producer, const media_destination& where) +VideoConsumer::Disconnected(const media_source& producer, + const media_destination& where) { FUNCTION("VideoConsumer::Disconnected\n"); @@ -425,12 +441,14 @@ VideoConsumer::AcceptFormat(const media_destination& dest, media_format* format) && format->u.raw_video.display.format != B_RGB15 && format->u.raw_video.display.format != B_GRAY8 && - format->u.raw_video.display.format != media_raw_video_format::wildcard.display.format) { + format->u.raw_video.display.format + != media_raw_video_format::wildcard.display.format) { ERROR("AcceptFormat - not a format we know about!\n"); return B_MEDIA_BAD_FORMAT; } - if (format->u.raw_video.display.format == media_raw_video_format::wildcard.display.format) { + if (format->u.raw_video.display.format + == media_raw_video_format::wildcard.display.format) { format->u.raw_video.display.format = B_RGB16; } @@ -456,11 +474,12 @@ VideoConsumer::GetNextInput(int32* cookie, media_input* outInput) sprintf(fIn.name, "Video Consumer"); *outInput = fIn; (*cookie)++; + return B_OK; - } else { - ERROR("VideoConsumer::GetNextInput - - BAD INDEX\n"); - return B_MEDIA_BAD_DESTINATION; } + + ERROR("VideoConsumer::GetNextInput - - BAD INDEX\n"); + return B_MEDIA_BAD_DESTINATION; } @@ -471,8 +490,8 @@ VideoConsumer::DisposeInputCookie(int32 /*cookie*/) status_t -VideoConsumer::GetLatencyFor(const media_destination& forWhom, bigtime_t* outLatency, - media_node_id* out_timesource) +VideoConsumer::GetLatencyFor(const media_destination& forWhom, + bigtime_t* outLatency, media_node_id* out_timesource) { FUNCTION("VideoConsumer::GetLatencyFor\n"); @@ -486,8 +505,9 @@ VideoConsumer::GetLatencyFor(const media_destination& forWhom, bigtime_t* outLat status_t -VideoConsumer::FormatChanged(const media_source& producer, const media_destination& consumer, - int32 fromChangeCount, const media_format& format) +VideoConsumer::FormatChanged(const media_source& producer, + const media_destination& consumer, int32 fromChangeCount, + const media_format& format) { FUNCTION("VideoConsumer::FormatChanged\n"); @@ -518,8 +538,9 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness, case BTimedEventQueue::B_STOP: PROGRESS("VideoConsumer::HandleEvent - STOP\n"); - EventQueue()->FlushEvents(event->event_time, BTimedEventQueue::B_ALWAYS, - true, BTimedEventQueue::B_HANDLE_BUFFER); + EventQueue()->FlushEvents(event->event_time, + BTimedEventQueue::B_ALWAYS, true, + BTimedEventQueue::B_HANDLE_BUFFER); break; case BTimedEventQueue::B_USER_EVENT: @@ -537,7 +558,7 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness, case BTimedEventQueue::B_HANDLE_BUFFER: { LOOP("VideoConsumer::HandleEvent - HANDLE BUFFER\n"); - buffer = (BBuffer *)event->pointer; + buffer = (BBuffer*)event->pointer; if (RunState() == B_STARTED && fConnectionActive) { // see if this is one of our buffers uint32 index = 0; @@ -555,26 +576,34 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness, } if (fFtpComplete && fTimeToFtp) { - PROGRESS("VidConsumer::HandleEvent - SPAWNING FTP THREAD\n"); + PROGRESS("VidConsumer::HandleEvent - " + "SPAWNING FTP THREAD\n"); fTimeToFtp = false; fFtpComplete = false; - memcpy(fFtpBitmap->Bits(), buffer->Data(), fFtpBitmap->BitsLength()); - fFtpThread = spawn_thread(FtpRun, "Video Window Ftp", B_NORMAL_PRIORITY, this); + memcpy(fFtpBitmap->Bits(), buffer->Data(), + fFtpBitmap->BitsLength()); + fFtpThread = spawn_thread(FtpRun, "Video Window Ftp", + B_NORMAL_PRIORITY, this); resume_thread(fFtpThread); } if ((RunMode() == B_OFFLINE) - || ((TimeSource()->Now() > (buffer->Header()->start_time - JITTER)) - && (TimeSource()->Now() < (buffer->Header()->start_time + JITTER)))) { + || ((TimeSource()->Now() > + (buffer->Header()->start_time - JITTER)) + && (TimeSource()->Now() < + (buffer->Header()->start_time + JITTER)))) { if (!fOurBuffers) // not our buffers, so we need to copy - memcpy(fBitmap[index]->Bits(), buffer->Data(), fBitmap[index]->BitsLength()); + memcpy(fBitmap[index]->Bits(), buffer->Data(), + fBitmap[index]->BitsLength()); if (fWindow->Lock()) { uint32 flags; if ((fBitmap[index]->ColorSpace() == B_GRAY8) && - !bitmaps_support_space(fBitmap[index]->ColorSpace(), &flags)) { - // handle mapping of GRAY8 until app server knows how + !bitmaps_support_space(fBitmap[index]->ColorSpace(), + &flags)) { + // handle mapping of GRAY8 until app server + // knows how uint32* start = (uint32*)fBitmap[index]->Bits(); int32 size = fBitmap[index]->BitsLength(); uint32* end = start + size / 4; @@ -607,7 +636,7 @@ VideoConsumer::FtpRun(void* data) { FUNCTION("VideoConsumer::FtpRun\n"); - ((VideoConsumer *)data)->FtpThread(); + ((VideoConsumer*)data)->FtpThread(); return 0; } @@ -620,7 +649,8 @@ VideoConsumer::FtpThread() FUNCTION("VideoConsumer::FtpThread\n"); if (fUploadClient == 2) { // 64 + 64 = 128 max - snprintf(fullPath, B_PATH_NAME_LENGTH, "%s/%s", fDirectoryText, fFileNameText); + snprintf(fullPath, B_PATH_NAME_LENGTH, "%s/%s", fDirectoryText, + fFileNameText); LocalSave(fullPath, fFtpBitmap); } else if (LocalSave(fFileNameText, fFtpBitmap) == B_OK) FtpSave(fFileNameText); @@ -666,14 +696,16 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap) /* save a local copy of the image in the requested format */ output = new BFile(); - if (output->SetTo(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) == B_NO_ERROR) { + if (output->SetTo(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) + == B_NO_ERROR) { BBitmapStream input(bitmap); - status_t err = BTranslatorRoster::Default()->Translate(&input, NULL, NULL, - output, fImageFormat); + status_t err = BTranslatorRoster::Default()->Translate(&input, NULL, + NULL, output, fImageFormat); if (err == B_OK) { err = SetFileType(output, fTranslator, fImageFormat); if (err != B_OK) - UpdateFtpStatus(B_TRANSLATE("Error setting type of output file")); + UpdateFtpStatus( + B_TRANSLATE("Error setting type of output file")); } else UpdateFtpStatus(B_TRANSLATE("Error writing output file")); @@ -681,18 +713,19 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap) input.DetachBitmap(&bitmap); output->Unset(); delete output; + return B_OK; - } else { - UpdateFtpStatus(B_TRANSLATE("Error creating output file")); - return B_ERROR; } + + UpdateFtpStatus(B_TRANSLATE("Error creating output file")); + return B_ERROR; } status_t VideoConsumer::FtpSave(char* filename) { - FileUploadClient *ftp; + FileUploadClient* ftp; //XXX: make that cleaner switch (fUploadClient) { @@ -764,7 +797,7 @@ SetFileType(BFile* file, int32 translator, uint32 type) int32 count; status_t err = BTranslatorRoster::Default()->GetOutputFormats(translator, - (const translation_format **)&formats, &count); + (const translation_format**)&formats, &count); if (err < B_OK) return err; diff --git a/src/apps/codycam/VideoConsumer.h b/src/apps/codycam/VideoConsumer.h index af3e640a47..0416e1cd4e 100644 --- a/src/apps/codycam/VideoConsumer.h +++ b/src/apps/codycam/VideoConsumer.h @@ -1,6 +1,8 @@ -// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved. -// SMS -/* VideoConsumer.h */ +/* + * Copyright 1998-1999 Be, Inc. All Rights Reserved. + * Copyright 2003-2019 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef VIDEO_CONSUMER_H #define VIDEO_CONSUMER_H @@ -10,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -36,115 +38,123 @@ class BStringView; class VideoConsumer : public BMediaEventLooper, public BBufferConsumer { - public: - VideoConsumer(const char* name, BView* view, BStringView* statusLine, - BMediaAddOn *addon, const uint32 internalId); - ~VideoConsumer(); +public: + VideoConsumer(const char* name, BView* view, + BStringView* statusLine, BMediaAddOn *addon, + const uint32 internalId); + ~VideoConsumer(); - /* BMediaNode */ - public: - virtual BMediaAddOn* AddOn(int32* cookie) const; +/* BMediaNode */ +public: + virtual BMediaAddOn* AddOn(int32* cookie) const; - protected: - virtual void Start(bigtime_t performanceTime); - virtual void Stop(bigtime_t performanceTime, bool immediate); - virtual void Seek(bigtime_t mediaTime, bigtime_t performanceTime); - virtual void TimeWarp(bigtime_t atRealTime, - bigtime_t toPerformanceTime); +protected: + virtual void Start(bigtime_t performanceTime); + virtual void Stop(bigtime_t performanceTime, bool immediate); + virtual void Seek(bigtime_t mediaTime, + bigtime_t performanceTime); + virtual void TimeWarp(bigtime_t atRealTime, + bigtime_t toPerformanceTime); - virtual void NodeRegistered(); - virtual status_t RequestCompleted(const media_request_info& info); + virtual void NodeRegistered(); + virtual status_t RequestCompleted( + const media_request_info& info); - virtual status_t HandleMessage(int32 message, const void* data, - size_t size); + virtual status_t HandleMessage(int32 message, const void* data, + size_t size); - virtual status_t DeleteHook(BMediaNode* node); + virtual status_t DeleteHook(BMediaNode* node); - /* BMediaEventLooper */ - protected: - virtual void HandleEvent(const media_timed_event* event, - bigtime_t lateness, bool realTimeEvent); +/* BMediaEventLooper */ +protected: + virtual void HandleEvent(const media_timed_event* event, + bigtime_t lateness, bool realTimeEvent); - /* BBufferConsumer */ - public: - virtual status_t AcceptFormat(const media_destination& dest, - media_format* format); +/* BBufferConsumer */ +public: + virtual status_t AcceptFormat(const media_destination& dest, + media_format* format); - virtual status_t GetNextInput(int32* cookie, media_input* outInput); + virtual status_t GetNextInput(int32* cookie, + media_input* outInput); - virtual void DisposeInputCookie(int32 cookie); + virtual void DisposeInputCookie(int32 cookie); - protected: - virtual void BufferReceived(BBuffer* buffer); +protected: + virtual void BufferReceived(BBuffer* buffer); - private: - virtual void ProducerDataStatus(const media_destination &forWhom, - int32 status, bigtime_t atMediaTime); +private: + virtual void ProducerDataStatus( + const media_destination &forWhom, + int32 status, bigtime_t atMediaTime); - virtual status_t GetLatencyFor(const media_destination& forWhom, - bigtime_t* outLatency, media_node_id* outId); + virtual status_t GetLatencyFor(const media_destination& forWhom, + bigtime_t* outLatency, + media_node_id* outId); - virtual status_t Connected(const media_source& producer, - const media_destination& where, const media_format& withFormat, - media_input* outInput); + virtual status_t Connected(const media_source& producer, + const media_destination& where, + const media_format& withFormat, + media_input* outInput); - virtual void Disconnected(const media_source& producer, - const media_destination& where); + virtual void Disconnected(const media_source& producer, + const media_destination& where); - virtual status_t FormatChanged(const media_source& producer, - const media_destination& consumer, int32 fromChangeCount, - const media_format& format); + virtual status_t FormatChanged(const media_source& producer, + const media_destination& consumer, + int32 fromChangeCount, + const media_format& format); - /* implementation */ +/* implementation */ - public: - status_t CreateBuffers(const media_format& withFormat); +public: + status_t CreateBuffers(const media_format& withFormat); - void DeleteBuffers(); + void DeleteBuffers(); - static status_t FtpRun(void* data); + static status_t FtpRun(void* data); - void FtpThread(); + void FtpThread(); - void UpdateFtpStatus(const char* status); + void UpdateFtpStatus(const char* status); - status_t LocalSave(char* filename, BBitmap* bitmap); + status_t LocalSave(char* filename, BBitmap* bitmap); - status_t FtpSave(char* filename); + status_t FtpSave(char* filename); - private: - BStringView* fStatusLine; - int32 fInternalID; - BMediaAddOn* fAddOn; +private: + BStringView* fStatusLine; + int32 fInternalID; + BMediaAddOn* fAddOn; - thread_id fFtpThread; + thread_id fFtpThread; - bool fConnectionActive; - media_input fIn; - media_destination fDestination; - bigtime_t fMyLatency; + bool fConnectionActive; + media_input fIn; + media_destination fDestination; + bigtime_t fMyLatency; - BWindow* fWindow; - BView* fView; - BBitmap* fBitmap[3]; - bool fOurBuffers; - BBufferGroup* fBuffers; - BBuffer* fBufferMap[3]; + BWindow* fWindow; + BView* fView; + BBitmap* fBitmap[3]; + bool fOurBuffers; + BBufferGroup* fBuffers; + BBuffer* fBufferMap[3]; - BBitmap* fFtpBitmap; - volatile bool fTimeToFtp; - volatile bool fFtpComplete; + BBitmap* fFtpBitmap; + volatile bool fTimeToFtp; + volatile bool fFtpComplete; - bigtime_t fRate; - uint32 fImageFormat; - int32 fTranslator; - int32 fUploadClient; - bool fPassiveFtp; - char fFileNameText[64]; - char fServerText[64]; - char fLoginText[64]; - char fPasswordText[64]; - char fDirectoryText[64]; + bigtime_t fRate; + uint32 fImageFormat; + int32 fTranslator; + int32 fUploadClient; + bool fPassiveFtp; + char fFileNameText[64]; + char fServerText[64]; + char fLoginText[64]; + char fPasswordText[64]; + char fDirectoryText[64]; }; #endif // VIDEO_CONSUMER_H