implemented some file handling related functionality
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17211 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
621a832488
commit
e1d8d7d6b4
@ -20,26 +20,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Debug.h>
|
||||
#include <ParameterWeb.h>
|
||||
#include <TimeSource.h>
|
||||
|
||||
#include "Controller.h"
|
||||
#include "DeviceRoster.h"
|
||||
#include "VideoView.h"
|
||||
#include "VideoNode.h"
|
||||
|
||||
|
||||
media_node dvb_node;
|
||||
media_node audio_mixer_node;
|
||||
media_node video_window_node;
|
||||
media_node time_node;
|
||||
|
||||
media_input audio_input;
|
||||
media_output audio_output;
|
||||
media_input video_input;
|
||||
media_output video_output;
|
||||
|
||||
BMediaRoster *gMediaRoster;
|
||||
|
||||
void
|
||||
HandleError(const char *text, status_t err)
|
||||
@ -53,23 +36,13 @@ HandleError(const char *text, status_t err)
|
||||
|
||||
|
||||
Controller::Controller()
|
||||
: fCurrentInterface(-1)
|
||||
, fCurrentChannel(-1)
|
||||
, fVideoView(NULL)
|
||||
, fVideoNode(NULL)
|
||||
, fWeb(NULL)
|
||||
, fChannelParam(NULL)
|
||||
, fConnected(false)
|
||||
, fInput()
|
||||
, fOutput()
|
||||
: fVideoView(NULL)
|
||||
{
|
||||
gMediaRoster = BMediaRoster::Roster();
|
||||
}
|
||||
|
||||
|
||||
Controller::~Controller()
|
||||
{
|
||||
delete fWeb;
|
||||
}
|
||||
|
||||
|
||||
@ -80,10 +53,24 @@ Controller::SetVideoView(VideoView *view)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Controller::SetVideoNode(VideoNode *node)
|
||||
status_t
|
||||
Controller::SetTo(const entry_ref &ref)
|
||||
{
|
||||
fVideoNode = node;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Controller::VideoTrackCount()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Controller::AudioTrackCount()
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
@ -99,180 +86,29 @@ Controller::VolumeDown()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Controller::ConnectNodes()
|
||||
bool
|
||||
Controller::IsOverlayActive()
|
||||
{
|
||||
status_t err;
|
||||
|
||||
// dvb_node = gDeviceRoster->DeviceNode(fCurrentInterface);
|
||||
|
||||
err = gMediaRoster->GetNodeFor(gDeviceRoster->DeviceNode(fCurrentInterface).node, &dvb_node);
|
||||
HandleError("GetNodeFor failed", err);
|
||||
|
||||
video_window_node = fVideoNode->Node();
|
||||
|
||||
err = gMediaRoster->GetAudioMixer(&audio_mixer_node);
|
||||
HandleError("GetAudioMixer failed", err);
|
||||
|
||||
media_input input;
|
||||
media_output output;
|
||||
media_format fmt;
|
||||
int32 count;
|
||||
|
||||
// Connect audio
|
||||
|
||||
err = gMediaRoster->GetFreeOutputsFor(dvb_node, &output, 1, &count, B_MEDIA_RAW_AUDIO);
|
||||
HandleError("Can't find free audio output", err);
|
||||
if (count < 1)
|
||||
HandleError("No free audio output", -1);
|
||||
|
||||
err = gMediaRoster->GetFreeInputsFor(audio_mixer_node, &input, 1, &count, B_MEDIA_RAW_AUDIO);
|
||||
HandleError("Can't find free audio input", err);
|
||||
if (count < 1)
|
||||
HandleError("No free audio input", -1);
|
||||
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
err = gMediaRoster->Connect(output.source, input.destination, &fmt, &audio_output, &audio_input);
|
||||
HandleError("Can't connect audio", err);
|
||||
|
||||
// Connect video
|
||||
|
||||
err = gMediaRoster->GetFreeOutputsFor(dvb_node, &output, 1, &count, B_MEDIA_RAW_VIDEO);
|
||||
HandleError("Can't find free video output", err);
|
||||
if (count < 1)
|
||||
HandleError("No free video output", -1);
|
||||
|
||||
err = gMediaRoster->GetFreeInputsFor(video_window_node, &input, 1, &count, B_MEDIA_RAW_VIDEO);
|
||||
HandleError("Can't find free video input", err);
|
||||
if (count < 1)
|
||||
HandleError("No free video input", -1);
|
||||
|
||||
color_space cspaces_overlay[] = { B_YCbCr422, B_RGB32, B_NO_COLOR_SPACE };
|
||||
color_space cspaces_bitmap[] = { B_RGB32, B_NO_COLOR_SPACE };
|
||||
|
||||
fVideoNode->SetOverlayEnabled(true);
|
||||
for (int i = 0; cspaces_overlay[i] != B_NO_COLOR_SPACE; i++) {
|
||||
printf("trying connect with colorspace 0x%08x\n", cspaces_overlay[i]);
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
fmt.type = B_MEDIA_RAW_VIDEO;
|
||||
fmt.u.raw_video.display.format = cspaces_overlay[i];
|
||||
err = gMediaRoster->Connect(output.source, input.destination, &fmt, &video_output, &video_input);
|
||||
if (err == B_OK)
|
||||
break;
|
||||
}
|
||||
if (err) {
|
||||
fVideoNode->SetOverlayEnabled(false);
|
||||
for (int i = 0; cspaces_bitmap[i] != B_NO_COLOR_SPACE; i++) {
|
||||
printf("trying connect with colorspace 0x%08x\n", cspaces_bitmap[i]);
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
fmt.type = B_MEDIA_RAW_VIDEO;
|
||||
fmt.u.raw_video.display.format = cspaces_bitmap[i];
|
||||
err = gMediaRoster->Connect(output.source, input.destination, &fmt, &video_output, &video_input);
|
||||
if (err == B_OK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
HandleError("Can't connect video", err);
|
||||
|
||||
// set time sources
|
||||
|
||||
err = gMediaRoster->GetTimeSource(&time_node);
|
||||
HandleError("Can't get time source", err);
|
||||
|
||||
BTimeSource *ts = gMediaRoster->MakeTimeSourceFor(time_node);
|
||||
|
||||
err = gMediaRoster->SetTimeSourceFor(dvb_node.node, time_node.node);
|
||||
HandleError("Can't set dvb time source", err);
|
||||
|
||||
err = gMediaRoster->SetTimeSourceFor(audio_mixer_node.node, time_node.node);
|
||||
HandleError("Can't set audio mixer time source", err);
|
||||
|
||||
err = gMediaRoster->SetTimeSourceFor(video_window_node.node, time_node.node);
|
||||
HandleError("Can't set video window time source", err);
|
||||
|
||||
// Add a delay of (2 video frames) to the buffers send by the DVB node,
|
||||
// because as a capture device in B_RECORDING run mode it's supposed to
|
||||
// deliver buffers that were captured in the past (and does so).
|
||||
// It is important that the audio buffer size used by the connection with
|
||||
// the DVB node is smaller than this, optimum is the same length as one
|
||||
// video frame (40 ms). However, this is not yet guaranteed.
|
||||
err = gMediaRoster->SetProducerRunModeDelay(dvb_node, 80000);
|
||||
HandleError("Can't set DVB producer delay", err);
|
||||
|
||||
bigtime_t start_time = ts->Now() + 50000;
|
||||
|
||||
ts->Release();
|
||||
|
||||
// start nodes
|
||||
|
||||
err = gMediaRoster->StartNode(dvb_node, start_time);
|
||||
HandleError("Can't start dvb node", err);
|
||||
|
||||
err = gMediaRoster->StartNode(audio_mixer_node, start_time);
|
||||
HandleError("Can't start audio mixer node", err);
|
||||
|
||||
err = gMediaRoster->StartNode(video_window_node, start_time);
|
||||
HandleError("Can't start video window node", err);
|
||||
|
||||
printf("running...\n");
|
||||
|
||||
fConnected = true;
|
||||
|
||||
return B_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Controller::DisconnectNodes()
|
||||
void
|
||||
Controller::LockBitmap()
|
||||
{
|
||||
printf("stopping...\n");
|
||||
|
||||
if (!fConnected)
|
||||
return B_OK;
|
||||
|
||||
status_t err;
|
||||
|
||||
// stop nodes
|
||||
|
||||
err = gMediaRoster->StopNode(dvb_node, 0, true);
|
||||
HandleError("Can't stop dvb node", err);
|
||||
|
||||
err = gMediaRoster->StopNode(audio_mixer_node, 0, true);
|
||||
HandleError("Can't stop audio mixer node", err);
|
||||
|
||||
err = gMediaRoster->StopNode(video_window_node, 0, true);
|
||||
HandleError("Can't stop video window node", err);
|
||||
|
||||
// disconnect nodes
|
||||
|
||||
err = MediaRoster_Disconnect(video_output, video_input);
|
||||
HandleError("Can't disconnect video", err);
|
||||
|
||||
err = MediaRoster_Disconnect(audio_output, audio_input);
|
||||
HandleError("Can't disconnect audio", err);
|
||||
|
||||
// disable overlay, or erase image
|
||||
|
||||
fVideoView->RemoveVideoDisplay();
|
||||
|
||||
// release other nodes
|
||||
|
||||
err = gMediaRoster->ReleaseNode(audio_mixer_node);
|
||||
HandleError("Can't release audio mixer node", err);
|
||||
|
||||
// err = gMediaRoster->ReleaseNode(video_window_node);
|
||||
// HandleError("Can't release video window node", err);
|
||||
|
||||
// err = gMediaRoster->ReleaseNode(time_node);
|
||||
// HandleError("Can't release time source node", err);
|
||||
|
||||
// release dvb
|
||||
|
||||
err = gMediaRoster->ReleaseNode(dvb_node);
|
||||
HandleError("Can't release DVB node", err);
|
||||
|
||||
fConnected = false;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Controller::UnlockBitmap()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BBitmap *
|
||||
Controller::Bitmap()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,34 +24,33 @@
|
||||
#include <MediaNode.h>
|
||||
|
||||
class VideoView;
|
||||
class VideoNode;
|
||||
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
status_t SetTo(const entry_ref &ref);
|
||||
|
||||
void SetVideoView(VideoView *view);
|
||||
void SetVideoNode(VideoNode *node);
|
||||
|
||||
bool IsOverlayActive();
|
||||
|
||||
void LockBitmap();
|
||||
void UnlockBitmap();
|
||||
BBitmap * Bitmap();
|
||||
|
||||
void VolumeUp();
|
||||
void VolumeDown();
|
||||
|
||||
int VideoTrackCount();
|
||||
int AudioTrackCount();
|
||||
|
||||
private:
|
||||
status_t ConnectNodes();
|
||||
status_t DisconnectNodes();
|
||||
|
||||
private:
|
||||
int fCurrentInterface;
|
||||
int fCurrentChannel;
|
||||
VideoView * fVideoView;
|
||||
VideoNode * fVideoNode;
|
||||
BParameterWeb * fWeb;
|
||||
BDiscreteParameter * fChannelParam;
|
||||
bool fConnected;
|
||||
media_input fInput;
|
||||
media_output fOutput;
|
||||
};
|
||||
|
||||
|
||||
|
41
src/apps/mediaplayer/ControllerView.cpp
Normal file
41
src/apps/mediaplayer/ControllerView.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <Message.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ControllerView.h"
|
||||
|
||||
ControllerView::ControllerView(BRect frame, Controller *ctrl)
|
||||
: BView(frame, "controller", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
|
||||
, fController(ctrl)
|
||||
{
|
||||
SetViewColor(128,0,0);
|
||||
}
|
||||
|
||||
|
||||
ControllerView::~ControllerView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ControllerView::AttachedToWindow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ControllerView::Draw(BRect updateRect)
|
||||
{
|
||||
BView::Draw(updateRect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ControllerView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
23
src/apps/mediaplayer/ControllerView.h
Normal file
23
src/apps/mediaplayer/ControllerView.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __CONTROLLER_VIEW_H
|
||||
#define __CONTROLLER_VIEW_H
|
||||
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class Controller;
|
||||
|
||||
class ControllerView : public BView
|
||||
{
|
||||
public:
|
||||
ControllerView(BRect frame, Controller *ctrl);
|
||||
~ControllerView();
|
||||
private:
|
||||
void AttachedToWindow();
|
||||
void MessageReceived(BMessage *msg);
|
||||
void Draw(BRect updateRect);
|
||||
|
||||
private:
|
||||
Controller * fController;
|
||||
};
|
||||
|
||||
#endif
|
@ -22,48 +22,82 @@
|
||||
#include <Alert.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "MainApp.h"
|
||||
#include "config.h"
|
||||
#include "DeviceRoster.h"
|
||||
|
||||
MainApp *gMainApp;
|
||||
|
||||
MainApp::MainApp()
|
||||
: BApplication(APP_SIG)
|
||||
: BApplication("application/x-vnd.Haiku-MediaPlayer")
|
||||
, fFirstWindow(NewWindow())
|
||||
{
|
||||
InitPrefs();
|
||||
|
||||
gDeviceRoster = new DeviceRoster;
|
||||
|
||||
fMainWindow = NewWindow();
|
||||
}
|
||||
|
||||
|
||||
MainApp::~MainApp()
|
||||
{
|
||||
delete gDeviceRoster;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MainApp::InitPrefs()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
BWindow *
|
||||
MainApp::NewWindow()
|
||||
{
|
||||
static int i = 0;
|
||||
BRect rect(200, 200, 750, 300);
|
||||
rect.OffsetBy(i * 25, i * 25);
|
||||
i = (i + 1) % 15;
|
||||
BWindow *win = new MainWin(rect);
|
||||
win->Show();
|
||||
return win;
|
||||
return new MainWin();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainApp::RefsReceived(BMessage *msg)
|
||||
{
|
||||
// The user dropped a file (or files) on this app's icon,
|
||||
// or double clicked a file that's handled by this app.
|
||||
// Command line arguments are also redirected to here by
|
||||
// ArgvReceived() but without MIME type check.
|
||||
// For each file we create a new window and send it a
|
||||
// B_REFS_RECEIVED message with a single file.
|
||||
// If IsLaunching() is true, we use fFirstWindow as first
|
||||
// window.
|
||||
printf("MainApp::RefsReceived\n");
|
||||
|
||||
entry_ref ref;
|
||||
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
|
||||
BWindow *win;
|
||||
win = (i == 0 && IsLaunching()) ? fFirstWindow : NewWindow();
|
||||
BMessage m(B_REFS_RECEIVED);
|
||||
m.AddRef("refs", &ref);
|
||||
win->PostMessage(&m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainApp::ArgvReceived(int32 argc, char **argv)
|
||||
{
|
||||
char cwd[B_PATH_NAME_LENGTH];
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
|
||||
BMessage m(B_REFS_RECEIVED);
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
printf("MainApp::ArgvReceived %s\n", argv[i]);
|
||||
BPath path;
|
||||
if (argv[i][0] != '/')
|
||||
path.SetTo(cwd, argv[i]);
|
||||
else
|
||||
path.SetTo(argv[i]);
|
||||
BEntry entry(path.Path(), true);
|
||||
if (!entry.Exists() || !entry.IsFile())
|
||||
continue;
|
||||
|
||||
entry_ref ref;
|
||||
if (B_OK == entry.GetRef(&ref))
|
||||
m.AddRef("refs", &ref);
|
||||
}
|
||||
|
||||
if (m.HasRef("refs")) {
|
||||
printf("MainApp::ArgvReceived calling RefsReceived\n");
|
||||
RefsReceived(&m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -72,6 +106,5 @@ main()
|
||||
{
|
||||
gMainApp = new MainApp;
|
||||
gMainApp->Run();
|
||||
delete gMainApp;
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,11 +28,15 @@ class MainApp : public BApplication
|
||||
public:
|
||||
MainApp();
|
||||
~MainApp();
|
||||
status_t InitPrefs();
|
||||
|
||||
BWindow * NewWindow();
|
||||
|
||||
private:
|
||||
BWindow * fMainWindow;
|
||||
private:
|
||||
void RefsReceived(BMessage *msg);
|
||||
void ArgvReceived(int32 argc, char **argv);
|
||||
|
||||
private:
|
||||
BWindow * fFirstWindow;
|
||||
};
|
||||
|
||||
extern MainApp *gMainApp;
|
||||
|
@ -19,9 +19,6 @@
|
||||
*/
|
||||
#include "MainWin.h"
|
||||
#include "MainApp.h"
|
||||
#include "Controller.h"
|
||||
#include "config.h"
|
||||
#include "DeviceRoster.h"
|
||||
|
||||
#include <View.h>
|
||||
#include <Screen.h>
|
||||
@ -36,12 +33,22 @@
|
||||
#include <PopUpMenu.h>
|
||||
#include <String.h>
|
||||
|
||||
#define NAME "MediaPlayer"
|
||||
|
||||
enum
|
||||
{
|
||||
M_DUMMY = 0x100,
|
||||
M_CHECK_TB,
|
||||
M_FILE_OPEN = 0x1000,
|
||||
M_FILE_NEWPLAYER,
|
||||
M_FILE_INFO,
|
||||
M_FILE_ABOUT,
|
||||
M_FILE_CLOSE,
|
||||
M_FILE_QUIT,
|
||||
M_VIEW_50,
|
||||
M_VIEW_100,
|
||||
M_VIEW_200,
|
||||
M_VIEW_300,
|
||||
M_VIEW_400,
|
||||
M_SCALE_TO_NATIVE_SIZE,
|
||||
M_TOGGLE_FULLSCREEN,
|
||||
M_TOGGLE_NO_BORDER,
|
||||
@ -50,10 +57,10 @@ enum
|
||||
M_TOGGLE_ALWAYS_ON_TOP,
|
||||
M_TOGGLE_KEEP_ASPECT_RATIO,
|
||||
M_PREFERENCES,
|
||||
M_CHANNEL_NEXT,
|
||||
M_CHANNEL_PREV,
|
||||
M_VOLUME_UP,
|
||||
M_VOLUME_DOWN,
|
||||
M_CHANNEL_NEXT,
|
||||
M_CHANNEL_PREV,
|
||||
M_ASPECT_100000_1,
|
||||
M_ASPECT_106666_1,
|
||||
M_ASPECT_109091_1,
|
||||
@ -61,17 +68,20 @@ enum
|
||||
M_ASPECT_720_576,
|
||||
M_ASPECT_704_576,
|
||||
M_ASPECT_544_576,
|
||||
M_SELECT_INTERFACE = 0x00000800,
|
||||
M_SELECT_INTERFACE_END = 0x00000fff,
|
||||
M_SELECT_CHANNEL = 0x00010000,
|
||||
M_SELECT_CHANNEL_END = 0x000fffff, // this limits possible channel count to 0xeffff = 983039
|
||||
M_SELECT_AUDIO_TRACK = 0x00000800,
|
||||
M_SELECT_AUDIO_TRACK_END = 0x00000fff,
|
||||
M_SELECT_VIDEO_TRACK = 0x00010000,
|
||||
M_SELECT_VIDEO_TRACK_END = 0x000fffff,
|
||||
};
|
||||
|
||||
//#define printf(a...)
|
||||
|
||||
|
||||
MainWin::MainWin(BRect frame_rect)
|
||||
: BWindow(frame_rect, NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
|
||||
MainWin::MainWin()
|
||||
: BWindow(BRect(200,200,0,0), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
|
||||
, fFilePanel(NULL)
|
||||
, fHasFile(false)
|
||||
, fHasVideo(false)
|
||||
, fController(new Controller)
|
||||
, fIsFullscreen(false)
|
||||
, fKeepAspectRatio(true)
|
||||
@ -117,25 +127,59 @@ MainWin::MainWin(BRect frame_rect)
|
||||
SetSizeLimits(0, 32767, fMenuBarHeight - 1, 32767);
|
||||
|
||||
fController->SetVideoView(fVideoView);
|
||||
fController->SetVideoNode(fVideoView->Node());
|
||||
|
||||
fVideoView->IsOverlaySupported();
|
||||
|
||||
SetupInterfaceMenu();
|
||||
SelectInitialInterface();
|
||||
SetInterfaceMenuMarker();
|
||||
SetupChannelMenu();
|
||||
SetChannelMenuMarker();
|
||||
|
||||
VideoFormatChange(fSourceWidth, fSourceHeight, fWidthScale, fHeightScale);
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
MainWin::~MainWin()
|
||||
{
|
||||
printf("MainWin::~MainWin\n");
|
||||
fController->DisconnectInterface();
|
||||
delete fController;
|
||||
delete fFilePanel;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::OpenFile(const entry_ref &ref)
|
||||
{
|
||||
printf("MainWin::OpenFile\n");
|
||||
|
||||
status_t err = fController->SetTo(ref);
|
||||
if (err != B_OK) {
|
||||
char s[300];
|
||||
sprintf(s, "Can't open file\n\n%s\n\nError 0x%08lx\n(%s)\n",
|
||||
ref.name, err, strerror(err));
|
||||
(new BAlert("error", s, "OK"))->Go();
|
||||
fHasFile = false;
|
||||
fHasVideo = false;
|
||||
SetTitle(NAME);
|
||||
} else {
|
||||
fHasFile = true;
|
||||
fHasVideo = fController->VideoTrackCount() != 0;
|
||||
SetTitle(ref.name);
|
||||
}
|
||||
SetupWindow();
|
||||
}
|
||||
|
||||
void
|
||||
MainWin::SetupWindow()
|
||||
{
|
||||
printf("MainWin::SetupWindow\n");
|
||||
|
||||
// Pupulate the track menus
|
||||
SetupTrackMenus();
|
||||
// Enable both if a file was loaded
|
||||
fAudioMenu->SetEnabled(fHasFile);
|
||||
fVideoMenu->SetEnabled(fHasFile);
|
||||
// Select first track (might be "none") in both
|
||||
fAudioMenu->ItemAt(0)->SetMarked(true);
|
||||
fVideoMenu->ItemAt(0)->SetMarked(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -143,22 +187,39 @@ void
|
||||
MainWin::CreateMenu()
|
||||
{
|
||||
fFileMenu = new BMenu(NAME);
|
||||
fChannelMenu = new BMenu("Channel");
|
||||
fInterfaceMenu = new BMenu("Interface");
|
||||
fViewMenu = new BMenu("View");
|
||||
fSettingsMenu = new BMenu("Settings");
|
||||
fAudioMenu = new BMenu("Audio Track");
|
||||
fVideoMenu = new BMenu("Video Track");
|
||||
fDebugMenu = new BMenu("Debug");
|
||||
|
||||
fMenuBar->AddItem(fFileMenu);
|
||||
fMenuBar->AddItem(fChannelMenu);
|
||||
fMenuBar->AddItem(fInterfaceMenu);
|
||||
fMenuBar->AddItem(fViewMenu);
|
||||
fMenuBar->AddItem(fSettingsMenu);
|
||||
fMenuBar->AddItem(fDebugMenu);
|
||||
|
||||
fFileMenu->AddItem(new BMenuItem("New Player", new BMessage(M_FILE_NEWPLAYER), 'N', B_COMMAND_KEY));
|
||||
fFileMenu->AddSeparatorItem();
|
||||
fFileMenu->AddItem(new BMenuItem("Open File"B_UTF8_ELLIPSIS, new BMessage(M_FILE_OPEN), 'O', B_COMMAND_KEY));
|
||||
fFileMenu->AddItem(new BMenuItem("File Info"B_UTF8_ELLIPSIS, new BMessage(M_FILE_INFO), 'I', B_COMMAND_KEY));
|
||||
fFileMenu->AddSeparatorItem();
|
||||
fFileMenu->AddItem(new BMenuItem("About", new BMessage(M_FILE_ABOUT), 'A', B_COMMAND_KEY));
|
||||
fFileMenu->AddSeparatorItem();
|
||||
fFileMenu->AddItem(new BMenuItem("Close", new BMessage(M_FILE_CLOSE), 'W', B_COMMAND_KEY));
|
||||
fFileMenu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY));
|
||||
|
||||
fViewMenu->AddItem(new BMenuItem("50% scale", new BMessage(M_VIEW_50), '0', B_COMMAND_KEY));
|
||||
fViewMenu->AddItem(new BMenuItem("100% scale", new BMessage(M_VIEW_100), '1', B_COMMAND_KEY));
|
||||
fViewMenu->AddItem(new BMenuItem("200% scale", new BMessage(M_VIEW_200), '2', B_COMMAND_KEY));
|
||||
fViewMenu->AddItem(new BMenuItem("300% scale", new BMessage(M_VIEW_300), '3', B_COMMAND_KEY));
|
||||
fViewMenu->AddItem(new BMenuItem("400% scale", new BMessage(M_VIEW_400), '4', B_COMMAND_KEY));
|
||||
fViewMenu->AddItem(new BMenuItem("Full Screen", new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY));
|
||||
fViewMenu->SetRadioMode(true);
|
||||
fViewMenu->AddSeparatorItem();
|
||||
fViewMenu->AddItem(new BMenuItem("Always on Top", new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T', B_COMMAND_KEY));
|
||||
|
||||
fSettingsMenu->AddItem(fAudioMenu);
|
||||
fSettingsMenu->AddItem(fVideoMenu);
|
||||
fSettingsMenu->AddItem(new BMenuItem("Scale to native size", new BMessage(M_SCALE_TO_NATIVE_SIZE), 'N', B_COMMAND_KEY));
|
||||
fSettingsMenu->AddItem(new BMenuItem("Full Screen", new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY));
|
||||
fSettingsMenu->AddSeparatorItem();
|
||||
@ -177,15 +238,44 @@ MainWin::CreateMenu()
|
||||
fDebugMenu->AddItem(new BMenuItem("force 704 x 576, display aspect 4:3", new BMessage(M_ASPECT_704_576)));
|
||||
fDebugMenu->AddItem(new BMenuItem("force 544 x 576, display aspect 4:3", new BMessage(M_ASPECT_544_576)));
|
||||
|
||||
fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
|
||||
fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
|
||||
fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
|
||||
fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
|
||||
fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
|
||||
fSettingsMenu->ItemAt(8)->SetEnabled(false); // XXX disable unused preference menu
|
||||
fAudioMenu->SetRadioMode(true);
|
||||
fVideoMenu->SetRadioMode(true);
|
||||
|
||||
fSettingsMenu->ItemAt(3)->SetMarked(fIsFullscreen);
|
||||
fSettingsMenu->ItemAt(5)->SetMarked(fNoMenu);
|
||||
fSettingsMenu->ItemAt(6)->SetMarked(fNoBorder);
|
||||
fSettingsMenu->ItemAt(7)->SetMarked(fAlwaysOnTop);
|
||||
fSettingsMenu->ItemAt(8)->SetMarked(fKeepAspectRatio);
|
||||
fSettingsMenu->ItemAt(10)->SetEnabled(false); // XXX disable unused preference menu
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::SetupTrackMenus()
|
||||
{
|
||||
fAudioMenu->RemoveItems(0, fAudioMenu->CountItems(), true);
|
||||
fVideoMenu->RemoveItems(0, fVideoMenu->CountItems(), true);
|
||||
|
||||
int c, i;
|
||||
char s[100];
|
||||
|
||||
c = fController->AudioTrackCount();
|
||||
for (i = 0; i < c; i++) {
|
||||
sprintf(s, "Track %d", i + 1);
|
||||
fAudioMenu->AddItem(new BMenuItem(s, new BMessage(M_SELECT_AUDIO_TRACK + i)));
|
||||
}
|
||||
if (!c)
|
||||
fAudioMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY)));
|
||||
|
||||
c = fController->VideoTrackCount();
|
||||
for (i = 0; i < c; i++) {
|
||||
sprintf(s, "Track %d", i + 1);
|
||||
fVideoMenu->AddItem(new BMenuItem(s, new BMessage(M_SELECT_VIDEO_TRACK + i)));
|
||||
}
|
||||
if (!c)
|
||||
fVideoMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY)));
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
MainWin::QuitRequested()
|
||||
@ -666,6 +756,32 @@ MainWin::ToggleKeepAspectRatio()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::RefsReceived(BMessage *msg)
|
||||
{
|
||||
printf("MainWin::RefsReceived\n");
|
||||
// the first file is played in this window,
|
||||
// if additional files (refs) are included,
|
||||
// more windows are launched
|
||||
|
||||
entry_ref ref;
|
||||
int n = 0;
|
||||
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
|
||||
BEntry entry(&ref, true);
|
||||
if (!entry.Exists() || !entry.IsFile())
|
||||
continue;
|
||||
if (n == 0) {
|
||||
OpenFile(ref);
|
||||
} else {
|
||||
BMessage m(B_REFS_RECEIVED);
|
||||
m.AddRef("refs", &ref);
|
||||
gMainApp->NewWindow()->PostMessage(&m);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Trap keys that are about to be send to background or renderer view.
|
||||
* Return B_OK if it shouldn't be passed to the view
|
||||
*/
|
||||
@ -824,6 +940,27 @@ void
|
||||
MainWin::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case B_REFS_RECEIVED:
|
||||
printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
|
||||
RefsReceived(msg);
|
||||
break;
|
||||
case B_SIMPLE_DATA:
|
||||
printf("MainWin::MessageReceived: B_SIMPLE_DATA\n");
|
||||
if (msg->HasRef("refs"))
|
||||
RefsReceived(msg);
|
||||
break;
|
||||
case M_FILE_OPEN:
|
||||
{
|
||||
if (!fFilePanel) {
|
||||
fFilePanel = new BFilePanel();
|
||||
fFilePanel->SetTarget(BMessenger(0, this));
|
||||
fFilePanel->SetPanelDirectory("/boot/home/");
|
||||
}
|
||||
fFilePanel->Show();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
|
||||
case B_ACQUIRE_OVERLAY_LOCK:
|
||||
printf("B_ACQUIRE_OVERLAY_LOCK\n");
|
||||
fVideoView->OverlayLockAcquire();
|
||||
@ -990,5 +1127,6 @@ MainWin::MessageReceived(BMessage *msg)
|
||||
SelectInterface(msg->what - M_SELECT_INTERFACE - 1);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -24,17 +24,20 @@
|
||||
#include <Menu.h>
|
||||
#include <Button.h>
|
||||
#include <Slider.h>
|
||||
#include <FilePanel.h>
|
||||
#include "Controller.h"
|
||||
#include "ControllerView.h"
|
||||
#include "VideoView.h"
|
||||
|
||||
class MainWin : public BWindow
|
||||
{
|
||||
public:
|
||||
MainWin(BRect rect);
|
||||
MainWin();
|
||||
~MainWin();
|
||||
|
||||
void FrameResized(float new_width, float new_height);
|
||||
void Zoom(BPoint rec_position, float rec_width, float rec_height);
|
||||
void RefsReceived(BMessage *msg);
|
||||
void DispatchMessage(BMessage *message, BHandler *handler);
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool QuitRequested();
|
||||
@ -45,6 +48,9 @@ public:
|
||||
status_t KeyDown(BMessage *msg);
|
||||
|
||||
void CreateMenu();
|
||||
void OpenFile(const entry_ref &ref);
|
||||
void SetupWindow();
|
||||
void SetupTrackMenus();
|
||||
|
||||
void VideoFormatChange(int width, int height, float width_scale, float height_scale);
|
||||
|
||||
@ -65,12 +71,18 @@ public:
|
||||
BMenuBar * fMenuBar;
|
||||
BView * fBackground;
|
||||
VideoView * fVideoView;
|
||||
BFilePanel * fFilePanel;
|
||||
ControllerView * fControllerView;
|
||||
|
||||
BMenu * fFileMenu;
|
||||
BMenu * fChannelMenu;
|
||||
BMenu * fInterfaceMenu;
|
||||
BMenu * fViewMenu;
|
||||
BMenu * fAudioMenu;
|
||||
BMenu * fVideoMenu;
|
||||
BMenu * fSettingsMenu;
|
||||
BMenu * fDebugMenu;
|
||||
|
||||
bool fHasFile;
|
||||
bool fHasVideo;
|
||||
|
||||
Controller * fController;
|
||||
volatile bool fIsFullscreen;
|
||||
|
@ -17,39 +17,24 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#include <Message.h>
|
||||
#include <Bitmap.h>
|
||||
#include <MediaRoster.h>
|
||||
#include "VideoView.h"
|
||||
#include "VideoNode.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
VideoView::VideoView(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
|
||||
: BView(frame, name, resizeMask, flags)
|
||||
, fVideoNode(0)
|
||||
, fController(NULL)
|
||||
, fOverlayActive(false)
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
|
||||
status_t err = B_OK;
|
||||
BMediaRoster *mroster = BMediaRoster::Roster(&err);
|
||||
if (!mroster || err) {
|
||||
printf("VideoView::VideoView: media_server is dead\n");
|
||||
exit(1);
|
||||
} else {
|
||||
fVideoNode = new VideoNode("video in", this);
|
||||
err = mroster->RegisterNode(fVideoNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VideoView::~VideoView()
|
||||
{
|
||||
if (fVideoNode) {
|
||||
BMediaRoster::Roster()->UnregisterNode(fVideoNode);
|
||||
delete fVideoNode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -58,14 +43,6 @@ VideoView::AttachedToWindow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VideoNode *
|
||||
VideoView::Node()
|
||||
{
|
||||
return fVideoNode;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::OverlayLockAcquire()
|
||||
{
|
||||
@ -86,9 +63,9 @@ VideoView::OverlayScreenshotPrepare()
|
||||
{
|
||||
printf("OverlayScreenshotPrepare enter\n");
|
||||
/*
|
||||
fVideoNode->LockBitmap();
|
||||
fController->LockBitmap();
|
||||
if (fOverlayActive) {
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
BBitmap *bmp = fController->Bitmap();
|
||||
if (bmp) {
|
||||
// Window()->UpdateIfNeeded();
|
||||
// Sync();
|
||||
@ -100,7 +77,7 @@ VideoView::OverlayScreenshotPrepare()
|
||||
// Sync();
|
||||
}
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
fController->UnlockBitmap();
|
||||
*/
|
||||
printf("OverlayScreenshotPrepare leave\n");
|
||||
}
|
||||
@ -112,9 +89,9 @@ VideoView::OverlayScreenshotCleanup()
|
||||
printf("OverlayScreenshotCleanup enter\n");
|
||||
/*
|
||||
snooze(50000); // give app server some time to take the screenshot
|
||||
fVideoNode->LockBitmap();
|
||||
fController->LockBitmap();
|
||||
if (fOverlayActive) {
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
BBitmap *bmp = fController->Bitmap();
|
||||
if (bmp) {
|
||||
DrawBitmap(bmp, Bounds());
|
||||
SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor,
|
||||
@ -122,7 +99,7 @@ VideoView::OverlayScreenshotCleanup()
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
fController->UnlockBitmap();
|
||||
*/
|
||||
printf("OverlayScreenshotCleanup leave\n");
|
||||
}
|
||||
@ -160,11 +137,11 @@ VideoView::Draw(BRect updateRect)
|
||||
SetHighColor(fOverlayKeyColor);
|
||||
FillRect(updateRect);
|
||||
} else {
|
||||
fVideoNode->LockBitmap();
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
fController->LockBitmap();
|
||||
BBitmap *bmp = fController->Bitmap();
|
||||
if (bmp)
|
||||
DrawBitmap(bmp, Bounds());
|
||||
fVideoNode->UnlockBitmap();
|
||||
fController->UnlockBitmap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +151,7 @@ VideoView::DrawFrame()
|
||||
{
|
||||
// printf("VideoView::DrawFrame\n");
|
||||
|
||||
bool want_overlay = fVideoNode->IsOverlayActive();
|
||||
bool want_overlay = fController->IsOverlayActive();
|
||||
|
||||
if (!want_overlay && fOverlayActive) {
|
||||
if (LockLooperWithTimeout(50000) == B_OK) {
|
||||
@ -186,8 +163,8 @@ VideoView::DrawFrame()
|
||||
}
|
||||
}
|
||||
if (want_overlay && !fOverlayActive) {
|
||||
fVideoNode->LockBitmap();
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
fController->LockBitmap();
|
||||
BBitmap *bmp = 0; // fController->Bitmap();
|
||||
if (bmp && LockLooperWithTimeout(50000) == B_OK) {
|
||||
SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor,
|
||||
B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL);
|
||||
@ -196,7 +173,7 @@ VideoView::DrawFrame()
|
||||
Invalidate();
|
||||
UnlockLooper();
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
fController->UnlockBitmap();
|
||||
}
|
||||
if (!fOverlayActive) {
|
||||
if (LockLooperWithTimeout(50000) != B_OK)
|
||||
|
@ -21,8 +21,7 @@
|
||||
#define __VIDEO_VIEW_H
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class VideoNode;
|
||||
#include "Controller.h"
|
||||
|
||||
class VideoView : public BView
|
||||
{
|
||||
@ -33,8 +32,6 @@ public:
|
||||
void RemoveVideoDisplay();
|
||||
void RemoveOverlay();
|
||||
|
||||
VideoNode * Node();
|
||||
|
||||
bool IsOverlaySupported();
|
||||
|
||||
void OverlayLockAcquire();
|
||||
@ -51,7 +48,7 @@ private:
|
||||
void Draw(BRect updateRect);
|
||||
|
||||
private:
|
||||
VideoNode * fVideoNode;
|
||||
Controller * fController;
|
||||
bool fOverlayActive;
|
||||
rgb_color fOverlayKeyColor;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user