CodyCam: show fatal errors in the video view

... instead of using an alert.

Also add a fancy border and some style fixes.

Fixes #3320.
This commit is contained in:
Adrien Destugues
2014-11-05 15:42:46 +01:00
parent f98814b714
commit b3b96925f5
2 changed files with 47 additions and 38 deletions
+44 -37
View File
@@ -56,14 +56,11 @@ const int32 kSliderViewRectHeight = 40;
namespace { namespace {
void void
ErrorAlert(const char* message, status_t err, BWindow *window = NULL) VideoWindow::ErrorAlert(const char* message, status_t err)
{ {
BAlert *alert = new BAlert(B_TRANSLATE_SYSTEM_NAME("CodyCam"), message, Lock();
B_TRANSLATE("OK")); fVideoView->SetText(message);
if (window != NULL) Unlock();
alert->CenterIn(window->Frame());
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
printf("%s\n%s [%" B_PRIx32 "]", message, strerror(err), err); printf("%s\n%s [%" B_PRIx32 "]", message, strerror(err), err);
} }
@@ -151,14 +148,13 @@ CodyCam::ReadyToRun()
(const char*) B_TRANSLATE_SYSTEM_NAME("CodyCam"), B_TITLED_WINDOW, (const char*) B_TRANSLATE_SYSTEM_NAME("CodyCam"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort); B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort);
if(_SetUpNodes() != B_OK) if (_SetUpNodes() != B_OK)
fWindow->ToggleMenuOnOff(); fWindow->ToggleMenuOnOff();
((VideoWindow*)fWindow)->ApplyControls(); ((VideoWindow*)fWindow)->ApplyControls();
} }
bool bool
CodyCam::QuitRequested() CodyCam::QuitRequested()
{ {
@@ -234,15 +230,15 @@ CodyCam::_SetUpNodes()
/* find the media roster */ /* find the media roster */
fMediaRoster = BMediaRoster::Roster(&status); fMediaRoster = BMediaRoster::Roster(&status);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot find the media roster"), status, fWindow->ErrorAlert(B_TRANSLATE("Cannot find the media roster"),
fWindow); status);
return status; return status;
} }
/* find the time source */ /* find the time source */
status = fMediaRoster->GetTimeSource(&fTimeSourceNode); status = fMediaRoster->GetTimeSource(&fTimeSourceNode);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot get a time source"), status, fWindow); fWindow->ErrorAlert(B_TRANSLATE("Cannot get a time source"), status);
return status; return status;
} }
@@ -250,8 +246,8 @@ CodyCam::_SetUpNodes()
INFO("CodyCam acquiring VideoInput node\n"); INFO("CodyCam acquiring VideoInput node\n");
status = fMediaRoster->GetVideoInput(&fProducerNode); status = fMediaRoster->GetVideoInput(&fProducerNode);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot find a video source. You need a webcam " fWindow->ErrorAlert(B_TRANSLATE("Cannot find a video source. You need "
"to use CodyCam."), status, fWindow); "a webcam to use CodyCam."), status);
return status; return status;
} }
@@ -260,16 +256,16 @@ CodyCam::_SetUpNodes()
((VideoWindow*)fWindow)->VideoView(), ((VideoWindow*)fWindow)->VideoView(),
((VideoWindow*)fWindow)->StatusLine(), NULL, 0); ((VideoWindow*)fWindow)->StatusLine(), NULL, 0);
if (!fVideoConsumer) { if (!fVideoConsumer) {
ErrorAlert(B_TRANSLATE("Cannot create a video window"), B_ERROR, fWindow->ErrorAlert(B_TRANSLATE("Cannot create a video window"),
fWindow); B_ERROR);
return B_ERROR; return B_ERROR;
} }
/* register the node */ /* register the node */
status = fMediaRoster->RegisterNode(fVideoConsumer); status = fMediaRoster->RegisterNode(fVideoConsumer);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot register the video window"), status, fWindow->ErrorAlert(B_TRANSLATE("Cannot register the video window"),
fWindow); status);
return status; return status;
} }
fPort = fVideoConsumer->ControlPort(); fPort = fVideoConsumer->ControlPort();
@@ -280,8 +276,8 @@ CodyCam::_SetUpNodes()
&cnt, B_MEDIA_RAW_VIDEO); &cnt, B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert(B_TRANSLATE("Cannot find an available video stream"), fWindow->ErrorAlert(B_TRANSLATE("Cannot find an available video stream"),
status, fWindow); status);
return status; return status;
} }
@@ -291,8 +287,8 @@ CodyCam::_SetUpNodes()
&fConsumerIn, 1, &cnt, B_MEDIA_RAW_VIDEO); &fConsumerIn, 1, &cnt, B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert(B_TRANSLATE("Can't find an available connection to the " fWindow->ErrorAlert(B_TRANSLATE("Can't find an available connection to "
"video window"), status, fWindow); "the video window"), status);
return status; return status;
} }
@@ -307,8 +303,8 @@ CodyCam::_SetUpNodes()
status = fMediaRoster->Connect(fProducerOut.source, status = fMediaRoster->Connect(fProducerOut.source,
fConsumerIn.destination, &format, &fProducerOut, &fConsumerIn); fConsumerIn.destination, &format, &fProducerOut, &fConsumerIn);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot connect the video source to the video " fWindow->ErrorAlert(B_TRANSLATE("Cannot connect the video source to "
"window"), status); "the video window"), status);
return status; return status;
} }
@@ -317,16 +313,16 @@ CodyCam::_SetUpNodes()
status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, status = fMediaRoster->SetTimeSourceFor(fProducerNode.node,
fTimeSourceNode.node); fTimeSourceNode.node);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot set the time source for the video " fWindow->ErrorAlert(B_TRANSLATE("Cannot set the time source for the "
"source"), status); "video source"), status);
return status; return status;
} }
status = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(), status = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(),
fTimeSourceNode.node); fTimeSourceNode.node);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot set the time source for the video " fWindow->ErrorAlert(B_TRANSLATE("Cannot set the time source for the "
"window"), status); "video window"), status);
return status; return status;
} }
@@ -339,8 +335,8 @@ CodyCam::_SetUpNodes()
bigtime_t initLatency = 0; bigtime_t initLatency = 0;
status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency); status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency);
if (status < B_OK) { if (status < B_OK) {
ErrorAlert(B_TRANSLATE("Error getting initial latency for the capture " fWindow->ErrorAlert(B_TRANSLATE("Error getting initial latency for the "
"node"), status); "capture node"), status);
return status; return status;
} }
@@ -356,13 +352,15 @@ CodyCam::_SetUpNodes()
status = fMediaRoster->StartTimeSource(fTimeSourceNode, real); status = fMediaRoster->StartTimeSource(fTimeSourceNode, real);
if (status != B_OK) { if (status != B_OK) {
timeSource->Release(); timeSource->Release();
ErrorAlert(B_TRANSLATE("Cannot start time source!"), status); fWindow->ErrorAlert(B_TRANSLATE("Cannot start time source!"),
status);
return status; return status;
} }
status = fMediaRoster->SeekTimeSource(fTimeSourceNode, 0, real); status = fMediaRoster->SeekTimeSource(fTimeSourceNode, 0, real);
if (status != B_OK) { if (status != B_OK) {
timeSource->Release(); timeSource->Release();
ErrorAlert(B_TRANSLATE("Cannot seek time source!"), status); fWindow->ErrorAlert(B_TRANSLATE("Cannot seek time source!"),
status);
return status; return status;
} }
} }
@@ -374,12 +372,14 @@ CodyCam::_SetUpNodes()
/* start the nodes */ /* start the nodes */
status = fMediaRoster->StartNode(fProducerNode, perf); status = fMediaRoster->StartNode(fProducerNode, perf);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot start the video source"), status); fWindow->ErrorAlert(B_TRANSLATE("Cannot start the video source"),
status);
return status; return status;
} }
status = fMediaRoster->StartNode(fVideoConsumer->Node(), perf); status = fMediaRoster->StartNode(fVideoConsumer->Node(), perf);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert(B_TRANSLATE("Cannot start the video window"), status); fWindow->ErrorAlert(B_TRANSLATE("Cannot start the video window"),
status);
return status; return status;
} }
@@ -473,12 +473,15 @@ VideoWindow::VideoWindow(BRect frame, const char* title, window_type type,
/* add some controls */ /* add some controls */
_BuildCaptureControls(); _BuildCaptureControls();
BBox* box = new BBox("box");
box->AddChild(fVideoView);
BLayoutBuilder::Group<>(this, B_VERTICAL, 0) BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(0, 0, 0, 0) .SetInsets(0, 0, 0, 0)
.Add(menuBar) .Add(menuBar)
.AddGroup(B_VERTICAL, kYBuffer) .AddGroup(B_VERTICAL, kYBuffer)
.SetInsets(kXBuffer, kYBuffer, kXBuffer, kYBuffer) .SetInsets(kXBuffer, kYBuffer, kXBuffer, kYBuffer)
.Add(fVideoView) .Add(box)
.AddGroup(B_HORIZONTAL, kXBuffer) .AddGroup(B_HORIZONTAL, kXBuffer)
.SetInsets(0, 0, 0, 0) .SetInsets(0, 0, 0, 0)
.Add(fCaptureSetupBox) .Add(fCaptureSetupBox)
@@ -497,7 +500,6 @@ VideoWindow::~VideoWindow()
} }
bool bool
VideoWindow::QuitRequested() VideoWindow::QuitRequested()
{ {
@@ -614,9 +616,14 @@ void
VideoWindow::_BuildCaptureControls() VideoWindow::_BuildCaptureControls()
{ {
// a view to hold the video image // a view to hold the video image
fVideoView = new BView("Video View", B_WILL_DRAW); fVideoView = new BTextView("");
fVideoView->SetExplicitMinSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y)); fVideoView->SetExplicitMinSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y));
fVideoView->SetExplicitMaxSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y)); fVideoView->SetExplicitMaxSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y));
fVideoView->MakeEditable(false);
fVideoView->MakeResizable(false);
fVideoView->MakeSelectable(false);
fVideoView->SetAlignment(B_ALIGN_CENTER);
fVideoView->SetInsets(0, VIDEO_SIZE_Y / 3, 0 , 0);
// Capture controls // Capture controls
fCaptureSetupBox = new BBox("Capture Controls", B_WILL_DRAW); fCaptureSetupBox = new BBox("Capture Controls", B_WILL_DRAW);
+3 -1
View File
@@ -128,6 +128,8 @@ public:
BStringView* StatusLine(); BStringView* StatusLine();
void ToggleMenuOnOff(); void ToggleMenuOnOff();
void ErrorAlert(const char*, status_t);
private: private:
void _BuildCaptureControls(); void _BuildCaptureControls();
@@ -140,7 +142,7 @@ private:
media_node* fProducer; media_node* fProducer;
port_id* fPortPtr; port_id* fPortPtr;
BView* fVideoView; BTextView* fVideoView;
BTextControl* fFileName; BTextControl* fFileName;
BBox* fCaptureSetupBox; BBox* fCaptureSetupBox;