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); // int32 bytesPerRow = B_ANY_BYTES_PER_ROW; // if (cspace == B_YCbCr422) // bytesPerRow = (int(frame.Width()) + 1) * 2; // printf("overlay bitmap: requesting: bytes per row: %d\n", bytesPerRow); LockBitmap(); ASSERT(fBitmap == 0); uint32 flags = overlay ? (B_BITMAP_WILL_OVERLAY | B_BITMAP_RESERVE_OVERLAY_CHANNEL) : 0; // fBitmap = new BBitmap(frame, flags, cspace, bytesPerRow); 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; } printf("overlay bitmap: got: bytes per row: %ld\n", fBitmap->BytesPerRow()); fOverlayActive = overlay; UnlockBitmap(); printf("VideoNode::CreateBuffers success\n"); return B_OK; }
void VideoNode::DeleteBuffers() { LockBitmap(); delete fBitmap; fBitmap = NULL; UnlockBitmap(); }
// Draw void VideoView::Draw(BRect updateRect) { if (LockBitmap()) { BRect r(Bounds()); if (const BBitmap* bitmap = GetBitmap()) { if (!fOverlayMode) { DrawBitmap(bitmap, bitmap->Bounds(), r); } } UnlockBitmap(); } }
// SetBitmap void VideoView::SetBitmap(const BBitmap* bitmap) { VCTarget::SetBitmap(bitmap); // Attention: Don't lock the window, if the bitmap is NULL. Otherwise // we're going to deadlock when the window tells the node manager to // stop the nodes (Window -> NodeManager -> VideoConsumer -> VideoView // -> Window). if (bitmap && LockLooperWithTimeout(10000) == B_OK) { if (LockBitmap()) { // if (fOverlayMode || bitmap->Flags() & B_BITMAP_WILL_OVERLAY) { if (fOverlayMode || bitmap->ColorSpace() == B_YCbCr422) { if (!fOverlayMode) { // init overlay rgb_color key; SetViewOverlay(bitmap, bitmap->Bounds(), Bounds(), &key, B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL); SetViewColor(key); Invalidate(); // use overlay from here on fOverlayMode = true; } else { // transfer overlay channel rgb_color key; SetViewOverlay(bitmap, bitmap->Bounds(), Bounds(), &key, B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL | B_OVERLAY_TRANSFER_CHANNEL); } } else { DrawBitmap(bitmap, bitmap->Bounds(), Bounds()); } UnlockBitmap(); } UnlockLooper(); } }
void VideoNode::HandleBuffer(BBuffer *buffer) { // printf("VideoNode::HandleBuffer\n"); LockBitmap(); if (fBitmap) { // bigtime_t start = system_time(); if (fOverlayActive) { if (B_OK == fBitmap->LockBits()) { // memcpy(fBitmap->Bits(), buffer->Data(), fBitmap->BitsLength()); // fBitmap->SetBits(buffer->Data(), fBitmap->BitsLength(), 0, fInput.format.u.raw_video.display.format); overlay_copy(fBitmap->Bounds().IntegerHeight() + 1, fBitmap->Bits(), fBitmap->BytesPerRow(), buffer->Data(), fInput.format.u.raw_video.display.bytes_per_row); fBitmap->UnlockBits(); } } else { // memcpy(fBitmap->Bits(), buffer->Data(), fBitmap->BitsLength()); overlay_copy(fBitmap->Bounds().IntegerHeight() + 1, fBitmap->Bits(), fBitmap->BytesPerRow(), buffer->Data(), fInput.format.u.raw_video.display.bytes_per_row); } // printf("overlay copy: %Ld usec\n", system_time() - start); } UnlockBitmap(); buffer->Recycle(); fVideoView->DrawFrame(); }