Imported source code from DVB TV application.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17020 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
97fc4c13e6
commit
8063479445
20
src/add-ons/media/media-add-ons/videowindow/VideoAddOn.cpp
Normal file
20
src/add-ons/media/media-add-ons/videowindow/VideoAddOn.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* VideoAddOn.cpp - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#include "VideoAddOn.h"
|
34
src/add-ons/media/media-add-ons/videowindow/VideoAddOn.h
Normal file
34
src/add-ons/media/media-add-ons/videowindow/VideoAddOn.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* VideoAddOn.h - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef __VIDEO_ADD_ON_H
|
||||
#define __VIDEO_ADD_ON_H
|
||||
|
||||
#include <MediaAddOn.h>
|
||||
|
||||
class MediaAddOn : public BMediaAddOn
|
||||
{
|
||||
public:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
extern "C" BMediaAddOn *make_media_addon(image_id id);
|
||||
|
||||
#endif
|
380
src/add-ons/media/media-add-ons/videowindow/VideoNode.cpp
Normal file
380
src/add-ons/media/media-add-ons/videowindow/VideoNode.cpp
Normal file
@ -0,0 +1,380 @@
|
||||
/*
|
||||
* VideoNode.cpp - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Window.h>
|
||||
#include <TimeSource.h>
|
||||
#include <MediaRoster.h>
|
||||
#include <BufferGroup.h>
|
||||
#include <Buffer.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Locker.h>
|
||||
#include <Debug.h>
|
||||
|
||||
#include "VideoNode.h"
|
||||
#include "VideoView.h"
|
||||
|
||||
|
||||
VideoNode::VideoNode(const char *name, VideoView *view)
|
||||
: BMediaNode(name)
|
||||
, BMediaEventLooper()
|
||||
, BBufferConsumer(B_MEDIA_RAW_VIDEO)
|
||||
, fVideoView(view)
|
||||
, fInput()
|
||||
, fOverlayEnabled(true)
|
||||
, fOverlayActive(false)
|
||||
, fDirectOverlayBuffer(false)
|
||||
, fBitmap(0)
|
||||
, fBitmapLocker(new BLocker("Video Node Locker"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VideoNode::~VideoNode()
|
||||
{
|
||||
Quit();
|
||||
DeleteBuffers();
|
||||
delete fBitmapLocker;
|
||||
}
|
||||
|
||||
|
||||
BMediaAddOn *
|
||||
VideoNode::AddOn(int32 *internal_id) const
|
||||
{
|
||||
*internal_id = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::NodeRegistered()
|
||||
{
|
||||
fInput.node = Node();
|
||||
fInput.source = media_source::null;
|
||||
fInput.destination.port = ControlPort();
|
||||
fInput.destination.id = 0;
|
||||
fInput.format.type = B_MEDIA_RAW_VIDEO;
|
||||
fInput.format.u.raw_video = media_raw_video_format::wildcard;
|
||||
strcpy(fInput.name, "video in");
|
||||
|
||||
SetPriority(B_DISPLAY_PRIORITY);
|
||||
Run();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::BufferReceived(BBuffer * buffer)
|
||||
{
|
||||
if (RunState() != B_STARTED) {
|
||||
buffer->Recycle();
|
||||
return;
|
||||
}
|
||||
if (fOverlayActive && fDirectOverlayBuffer) {
|
||||
HandleBuffer(buffer);
|
||||
} else {
|
||||
media_timed_event event(buffer->Header()->start_time,
|
||||
BTimedEventQueue::B_HANDLE_BUFFER,
|
||||
buffer,
|
||||
BTimedEventQueue::B_RECYCLE_BUFFER);
|
||||
EventQueue()->AddEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode::GetNextInput(int32 *cookie, media_input *out_input)
|
||||
{
|
||||
if (*cookie < 1) {
|
||||
*out_input = fInput;
|
||||
*cookie += 1;
|
||||
return B_OK;
|
||||
}
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::DisposeInputCookie(int32 cookie)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode:: HandleMessage(int32 message,
|
||||
const void *data,
|
||||
size_t size)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::HandleEvent(const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent)
|
||||
{
|
||||
switch (event->type) {
|
||||
case BTimedEventQueue::B_START:
|
||||
break;
|
||||
case BTimedEventQueue::B_STOP:
|
||||
EventQueue()->FlushEvents(event->event_time, BTimedEventQueue::B_ALWAYS, true, BTimedEventQueue::B_HANDLE_BUFFER);
|
||||
break;
|
||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||
HandleBuffer((BBuffer *)event->pointer);
|
||||
break;
|
||||
default:
|
||||
printf("VideoNode::HandleEvent unknown event");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::ProducerDataStatus(const media_destination &dst,
|
||||
int32 status,
|
||||
bigtime_t at_media_time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode::GetLatencyFor(const media_destination &dst,
|
||||
bigtime_t *out_latency,
|
||||
media_node_id *out_id)
|
||||
{
|
||||
if (dst != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
*out_latency = 10000;
|
||||
*out_id = TimeSource()->ID();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
VideoNode::AcceptFormat(const media_destination &dst,
|
||||
media_format *format)
|
||||
{
|
||||
/* The connection process:
|
||||
* BBufferProducer::FormatProposal
|
||||
* we are here => BBufferConsumer::AcceptFormat
|
||||
* BBufferProducer::PrepareToConnect
|
||||
* BBufferConsumer::Connected
|
||||
* BBufferProducer::Connect
|
||||
*/
|
||||
|
||||
if (dst != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
if (format->type == B_MEDIA_NO_TYPE)
|
||||
format->type = B_MEDIA_RAW_VIDEO;
|
||||
|
||||
if (format->type != B_MEDIA_RAW_VIDEO)
|
||||
return B_MEDIA_BAD_FORMAT;
|
||||
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode::Connected(const media_source &src,
|
||||
const media_destination &dst,
|
||||
const media_format &format,
|
||||
media_input *out_input)
|
||||
{
|
||||
/* The connection process:
|
||||
* BBufferProducer::FormatProposal
|
||||
* BBufferConsumer::AcceptFormat
|
||||
* BBufferProducer::PrepareToConnect
|
||||
* we are here => BBufferConsumer::Connected
|
||||
* BBufferProducer::Connect
|
||||
*/
|
||||
|
||||
if (dst != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
fInput.source = src;
|
||||
fInput.format = format;
|
||||
|
||||
if (fInput.format.u.raw_video.field_rate < 1.0)
|
||||
fInput.format.u.raw_video.field_rate = 25.0;
|
||||
|
||||
color_space colorspace = format.u.raw_video.display.format;
|
||||
BRect frame(0, 0, format.u.raw_video.display.line_width - 1, format.u.raw_video.display.line_count - 1);
|
||||
status_t err;
|
||||
|
||||
DeleteBuffers();
|
||||
err = CreateBuffers(frame, colorspace, fOverlayEnabled);
|
||||
if (err) {
|
||||
printf("VideoNode::Connected failed, fOverlayEnabled = %d\n", fOverlayEnabled);
|
||||
return err;
|
||||
}
|
||||
|
||||
*out_input = fInput;
|
||||
|
||||
return B_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::Disconnected(const media_source &src,
|
||||
const media_destination &dst)
|
||||
{
|
||||
if (src != fInput.source)
|
||||
return;
|
||||
if (dst != fInput.destination)
|
||||
return;
|
||||
|
||||
DeleteBuffers();
|
||||
|
||||
// disconnect the connection
|
||||
fInput.source = media_source::null;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode::FormatChanged(const media_source &src,
|
||||
const media_destination &dst,
|
||||
int32 from_change_count,
|
||||
const media_format &format)
|
||||
{
|
||||
printf("VideoNode::FormatChanged enter\n");
|
||||
if (src != fInput.source)
|
||||
return B_MEDIA_BAD_SOURCE;
|
||||
if (dst != fInput.destination)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
color_space colorspace = format.u.raw_video.display.format;
|
||||
BRect frame(0, 0, format.u.raw_video.display.line_width - 1, format.u.raw_video.display.line_count - 1);
|
||||
status_t err;
|
||||
|
||||
DeleteBuffers();
|
||||
if (fOverlayEnabled) {
|
||||
fVideoView->RemoveOverlay();
|
||||
err = CreateBuffers(frame, colorspace, true); // try overlay
|
||||
if (err) {
|
||||
printf("VideoNode::FormatChanged creating overlay buffer failed\n");
|
||||
err = CreateBuffers(frame, colorspace, false); // no overlay
|
||||
}
|
||||
} else {
|
||||
err = CreateBuffers(frame, colorspace, false); // no overlay
|
||||
}
|
||||
if (err) {
|
||||
printf("VideoNode::FormatChanged failed (lost buffer group!)\n");
|
||||
return B_MEDIA_BAD_FORMAT;
|
||||
}
|
||||
|
||||
fInput.format = format;
|
||||
|
||||
printf("VideoNode::FormatChanged leave\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::HandleBuffer(BBuffer *buffer)
|
||||
{
|
||||
// printf("VideoNode::HandleBuffer\n");
|
||||
|
||||
LockBitmap();
|
||||
if (fBitmap) {
|
||||
// bigtime_t start = system_time();
|
||||
memcpy(fBitmap->Bits(), buffer->Data(), fBitmap->BitsLength());
|
||||
// printf("overlay copy: %Ld usec\n", system_time() - start);
|
||||
}
|
||||
UnlockBitmap();
|
||||
|
||||
buffer->Recycle();
|
||||
|
||||
fVideoView->DrawFrame();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::SetOverlayEnabled(bool yesno)
|
||||
{
|
||||
fOverlayEnabled = yesno;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::LockBitmap()
|
||||
{
|
||||
fBitmapLocker->Lock();
|
||||
}
|
||||
|
||||
|
||||
BBitmap *
|
||||
VideoNode::Bitmap()
|
||||
{
|
||||
return fBitmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::UnlockBitmap()
|
||||
{
|
||||
fBitmapLocker->Unlock();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
VideoNode::IsOverlayActive()
|
||||
{
|
||||
return fOverlayActive;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
VideoNode::CreateBuffers(BRect frame, color_space cspace, bool overlay)
|
||||
{
|
||||
printf("VideoNode::CreateBuffers: frame %d,%d,%d,%d colorspace 0x%08x, overlay %d\n",
|
||||
int(frame.left), int(frame.top), int(frame.right), int(frame.bottom), int(cspace), overlay);
|
||||
|
||||
LockBitmap();
|
||||
ASSERT(fBitmap == 0);
|
||||
uint32 flags = overlay ? (B_BITMAP_WILL_OVERLAY | B_BITMAP_RESERVE_OVERLAY_CHANNEL) : 0;
|
||||
fBitmap = new BBitmap(frame, flags, cspace);
|
||||
if (!(fBitmap && fBitmap->InitCheck() == B_OK && fBitmap->IsValid())) {
|
||||
delete fBitmap;
|
||||
fBitmap = 0;
|
||||
fOverlayActive = false;
|
||||
UnlockBitmap();
|
||||
printf("VideoNode::CreateBuffers failed\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
fOverlayActive = overlay;
|
||||
UnlockBitmap();
|
||||
printf("VideoNode::CreateBuffers success\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoNode::DeleteBuffers()
|
||||
{
|
||||
LockBitmap();
|
||||
delete fBitmap;
|
||||
fBitmap = NULL;
|
||||
UnlockBitmap();
|
||||
}
|
106
src/add-ons/media/media-add-ons/videowindow/VideoNode.h
Normal file
106
src/add-ons/media/media-add-ons/videowindow/VideoNode.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* VideoNode.h - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef __VIDEO_NODE_H_
|
||||
#define __VIDEO_NODE_H_
|
||||
|
||||
#include <BufferConsumer.h>
|
||||
#include <MediaEventLooper.h>
|
||||
|
||||
class VideoView;
|
||||
|
||||
class VideoNode : public BMediaEventLooper, public BBufferConsumer
|
||||
{
|
||||
public:
|
||||
VideoNode(const char *name, VideoView *view);
|
||||
~VideoNode();
|
||||
|
||||
void SetOverlayEnabled(bool yesno);
|
||||
bool IsOverlayActive();
|
||||
|
||||
void LockBitmap();
|
||||
BBitmap * Bitmap();
|
||||
void UnlockBitmap();
|
||||
|
||||
protected:
|
||||
BMediaAddOn * AddOn(int32 *internal_id) const;
|
||||
|
||||
void NodeRegistered();
|
||||
|
||||
void BufferReceived(BBuffer * buffer);
|
||||
|
||||
status_t GetNextInput(int32 *cookie, media_input *out_input);
|
||||
void DisposeInputCookie(int32 cookie);
|
||||
|
||||
status_t HandleMessage(
|
||||
int32 message,
|
||||
const void *data,
|
||||
size_t size);
|
||||
|
||||
void HandleEvent(
|
||||
const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent);
|
||||
|
||||
status_t AcceptFormat(
|
||||
const media_destination &dst,
|
||||
media_format *format);
|
||||
|
||||
void ProducerDataStatus(
|
||||
const media_destination &dst,
|
||||
int32 status,
|
||||
bigtime_t at_media_time);
|
||||
|
||||
status_t GetLatencyFor(
|
||||
const media_destination &dst,
|
||||
bigtime_t *out_latency,
|
||||
media_node_id *out_id);
|
||||
|
||||
status_t Connected(
|
||||
const media_source &src,
|
||||
const media_destination &dst,
|
||||
const media_format &format,
|
||||
media_input *out_input);
|
||||
|
||||
void Disconnected(
|
||||
const media_source &src,
|
||||
const media_destination &dst);
|
||||
|
||||
status_t FormatChanged(
|
||||
const media_source &src,
|
||||
const media_destination &dst,
|
||||
int32 from_change_count,
|
||||
const media_format &format);
|
||||
|
||||
protected:
|
||||
void HandleBuffer(BBuffer *buffer);
|
||||
status_t CreateBuffers(BRect frame, color_space cspace, bool overlay);
|
||||
void DeleteBuffers();
|
||||
|
||||
protected:
|
||||
VideoView * fVideoView;
|
||||
media_input fInput;
|
||||
bool fOverlayEnabled;
|
||||
bool fOverlayActive;
|
||||
bool fDirectOverlayBuffer; // If the overlay memory is directly written by the producer node.
|
||||
BBitmap * fBitmap;
|
||||
BLocker * fBitmapLocker;
|
||||
};
|
||||
|
||||
#endif
|
264
src/add-ons/media/media-add-ons/videowindow/VideoView.cpp
Normal file
264
src/add-ons/media/media-add-ons/videowindow/VideoView.cpp
Normal file
@ -0,0 +1,264 @@
|
||||
/*
|
||||
* VideoView.cpp - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#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)
|
||||
, 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::AttachedToWindow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VideoNode *
|
||||
VideoView::Node()
|
||||
{
|
||||
return fVideoNode;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::OverlayLockAcquire()
|
||||
{
|
||||
printf("VideoView::OverlayLockAcquire\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::OverlayLockRelease()
|
||||
{
|
||||
printf("VideoView::OverlayLockRelease\n");
|
||||
// overlaybitmap->UnlockBits
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::OverlayScreenshotPrepare()
|
||||
{
|
||||
printf("OverlayScreenshotPrepare enter\n");
|
||||
/*
|
||||
fVideoNode->LockBitmap();
|
||||
if (fOverlayActive) {
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
if (bmp) {
|
||||
// Window()->UpdateIfNeeded();
|
||||
// Sync();
|
||||
BBitmap *tmp = new BBitmap(bmp->Bounds(), 0, B_RGB32);
|
||||
// ConvertBitmap(tmp, bmp);
|
||||
ClearViewOverlay();
|
||||
DrawBitmap(tmp, Bounds());
|
||||
delete tmp;
|
||||
// Sync();
|
||||
}
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
*/
|
||||
printf("OverlayScreenshotPrepare leave\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::OverlayScreenshotCleanup()
|
||||
{
|
||||
printf("OverlayScreenshotCleanup enter\n");
|
||||
/*
|
||||
snooze(50000); // give app server some time to take the screenshot
|
||||
fVideoNode->LockBitmap();
|
||||
if (fOverlayActive) {
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
if (bmp) {
|
||||
DrawBitmap(bmp, Bounds());
|
||||
SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor,
|
||||
B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
*/
|
||||
printf("OverlayScreenshotCleanup leave\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::RemoveVideoDisplay()
|
||||
{
|
||||
printf("VideoView::RemoveVideoDisplay\n");
|
||||
|
||||
if (fOverlayActive) {
|
||||
ClearViewOverlay();
|
||||
fOverlayActive = false;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::RemoveOverlay()
|
||||
{
|
||||
printf("VideoView::RemoveOverlay\n");
|
||||
if (LockLooperWithTimeout(50000) == B_OK) {
|
||||
ClearViewOverlay();
|
||||
fOverlayActive = false;
|
||||
UnlockLooper();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::Draw(BRect updateRect)
|
||||
{
|
||||
if (fOverlayActive) {
|
||||
SetHighColor(fOverlayKeyColor);
|
||||
FillRect(updateRect);
|
||||
} else {
|
||||
fVideoNode->LockBitmap();
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
if (bmp)
|
||||
DrawBitmap(bmp, Bounds());
|
||||
fVideoNode->UnlockBitmap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::DrawFrame()
|
||||
{
|
||||
// printf("VideoView::DrawFrame\n");
|
||||
|
||||
bool want_overlay = fVideoNode->IsOverlayActive();
|
||||
|
||||
if (!want_overlay && fOverlayActive) {
|
||||
if (LockLooperWithTimeout(50000) == B_OK) {
|
||||
ClearViewOverlay();
|
||||
UnlockLooper();
|
||||
fOverlayActive = false;
|
||||
} else {
|
||||
printf("can't ClearViewOverlay, as LockLooperWithTimeout failed\n");
|
||||
}
|
||||
}
|
||||
if (want_overlay && !fOverlayActive) {
|
||||
fVideoNode->LockBitmap();
|
||||
BBitmap *bmp = fVideoNode->Bitmap();
|
||||
if (bmp && LockLooperWithTimeout(50000) == B_OK) {
|
||||
SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor,
|
||||
B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL);
|
||||
fOverlayActive = true;
|
||||
|
||||
Invalidate();
|
||||
UnlockLooper();
|
||||
}
|
||||
fVideoNode->UnlockBitmap();
|
||||
}
|
||||
if (!fOverlayActive) {
|
||||
if (LockLooperWithTimeout(50000) != B_OK)
|
||||
return;
|
||||
Invalidate();
|
||||
UnlockLooper();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
VideoView::IsOverlaySupported()
|
||||
{
|
||||
struct colorcombo {
|
||||
color_space colspace;
|
||||
const char *name;
|
||||
} colspace[] = {
|
||||
{ B_RGB32, "B_RGB32"},
|
||||
{ B_RGBA32, "B_RGBA32"},
|
||||
{ B_RGB24, "B_RGB24"},
|
||||
{ B_RGB16, "B_RGB16"},
|
||||
{ B_RGB15, "B_RGB15"},
|
||||
{ B_RGBA15, "B_RGBA15"},
|
||||
{ B_RGB32_BIG, "B_RGB32_BIG"},
|
||||
{ B_RGBA32_BIG, "B_RGBA32_BIG "},
|
||||
{ B_RGB24_BIG, "B_RGB24_BIG "},
|
||||
{ B_RGB16_BIG, "B_RGB16_BIG "},
|
||||
{ B_RGB15_BIG, "B_RGB15_BIG "},
|
||||
{ B_RGBA15_BIG, "B_RGBA15_BIG "},
|
||||
{ B_YCbCr422, "B_YCbCr422"},
|
||||
{ B_YCbCr411, "B_YCbCr411"},
|
||||
{ B_YCbCr444, "B_YCbCr444"},
|
||||
{ B_YCbCr420, "B_YCbCr420"},
|
||||
{ B_YUV422, "B_YUV422"},
|
||||
{ B_YUV411, "B_YUV411"},
|
||||
{ B_YUV444, "B_YUV444"},
|
||||
{ B_YUV420, "B_YUV420"},
|
||||
{ B_NO_COLOR_SPACE, NULL}
|
||||
};
|
||||
|
||||
bool supported = false;
|
||||
for (int i = 0; colspace[i].name; i++) {
|
||||
BBitmap *test = new BBitmap(BRect(0,0,320,240), B_BITMAP_WILL_OVERLAY | B_BITMAP_RESERVE_OVERLAY_CHANNEL, colspace[i].colspace);
|
||||
if (test->InitCheck() == B_OK) {
|
||||
printf("Display supports %s (0x%08x) overlay\n", colspace[i].name, colspace[i].colspace);
|
||||
supported = true;
|
||||
}
|
||||
delete test;
|
||||
// if (supported)
|
||||
// break;
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
59
src/add-ons/media/media-add-ons/videowindow/VideoView.h
Normal file
59
src/add-ons/media/media-add-ons/videowindow/VideoView.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* VideoView.h - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef __VIDEO_VIEW_H
|
||||
#define __VIDEO_VIEW_H
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class VideoNode;
|
||||
|
||||
class VideoView : public BView
|
||||
{
|
||||
public:
|
||||
VideoView(BRect frame, const char *name, uint32 resizeMask, uint32 flags);
|
||||
~VideoView();
|
||||
|
||||
void RemoveVideoDisplay();
|
||||
void RemoveOverlay();
|
||||
|
||||
VideoNode * Node();
|
||||
|
||||
bool IsOverlaySupported();
|
||||
|
||||
void OverlayLockAcquire();
|
||||
void OverlayLockRelease();
|
||||
|
||||
void OverlayScreenshotPrepare();
|
||||
void OverlayScreenshotCleanup();
|
||||
|
||||
void DrawFrame();
|
||||
|
||||
private:
|
||||
void AttachedToWindow();
|
||||
void MessageReceived(BMessage *msg);
|
||||
void Draw(BRect updateRect);
|
||||
|
||||
private:
|
||||
VideoNode * fVideoNode;
|
||||
bool fOverlayActive;
|
||||
rgb_color fOverlayKeyColor;
|
||||
};
|
||||
|
||||
#endif
|
25
src/add-ons/media/media-add-ons/videowindow/VideoWindow.cpp
Normal file
25
src/add-ons/media/media-add-ons/videowindow/VideoWindow.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* VideoWindow.cpp - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#include "VideoView.h"
|
||||
#include "VideoNode.h"
|
||||
#include "VideoWindow.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
39
src/add-ons/media/media-add-ons/videowindow/VideoWindow.h
Normal file
39
src/add-ons/media/media-add-ons/videowindow/VideoWindow.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* VideoWindow.h - "Video Window" media add-on.
|
||||
*
|
||||
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef __VIDEO_WINDOW_H
|
||||
#define __VIDEO_WINDOW_H
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
class VideoNode;
|
||||
class VideoView;
|
||||
|
||||
class VideoWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
VideoNode * fVideoNode;
|
||||
VideoView * fVideoView;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user