// 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 VideoView::DrawFrame() { // printf("VideoView::DrawFrame\n"); if (!fVideoActive) { fVideoActive = true; if (LockLooperWithTimeout(50000) != B_OK) return; Invalidate(); UnlockLooper(); } fLastFrame = system_time(); 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(); } }
status_t MediaView::SetVideoTrack( BDataIO *data, BMediaTrack *track, media_format *format) { if (fVideoTrack != NULL) // is it possible to have multiple video tracks? return (B_ERROR); fVideoTrack = track; BRect bitmapBounds(0.0, 0.0, format->u.encoded_video.output.display.line_width - 1.0, format->u.encoded_video.output.display.line_count - 1.0); fBitmap = new BBitmap(bitmapBounds,B_BITMAP_WILL_OVERLAY|B_BITMAP_RESERVE_OVERLAY_CHANNEL,B_YCbCr422); fUsingOverlay = true; if (fBitmap->InitCheck() != B_OK) { delete fBitmap; fBitmap = new BBitmap(bitmapBounds, fBitmapDepth); fUsingOverlay = false; }; /* loop, asking the track for a format we can deal with */ for(;;) { media_format mf, old_mf; BuildMediaFormat(fBitmap, &mf); old_mf = mf; fVideoTrack->DecodedFormat(&mf); if (old_mf.u.raw_video.display.format == mf.u.raw_video.display.format) { break; } printf("wanted cspace 0x%x, but it was reset to 0x%x\n", fBitmapDepth, mf.u.raw_video.display.format); fBitmapDepth = mf.u.raw_video.display.format; delete fBitmap; fUsingOverlay = false; fBitmap = new BBitmap(bitmapBounds, fBitmapDepth); } media_header mh; bigtime_t time = fCurTime; fVideoTrack->SeekToTime(&time); int64 dummyNumFrames = 0; fVideoTrack->ReadFrames((char *)fBitmap->Bits(), &dummyNumFrames, &mh); time = fCurTime; fVideoTrack->SeekToTime(&time); if (fUsingOverlay) { overlay_restrictions r; fBitmap->GetOverlayRestrictions(&r); printf("Overlay limits:\n"); printf(" Src horiz alignment : %08x\n",r.source.horizontal_alignment); printf(" Src vert alignment : %08x\n",r.source.vertical_alignment); printf(" Src width alignment : %08x\n",r.source.width_alignment); printf(" Src height alignment : %08x\n",r.source.height_alignment); printf(" Src min/max : (%d,%d)/(%d,%d)\n",r.source.min_width,r.source.min_height, r.source.max_width,r.source.max_height); printf(" Dst horiz alignment : %08x\n",r.destination.horizontal_alignment); printf(" Dst vert alignment : %08x\n",r.destination.vertical_alignment); printf(" Dst width alignment : %08x\n",r.destination.width_alignment); printf(" Dst height alignment : %08x\n",r.destination.height_alignment); printf(" Dst min/max : (%d,%d)/(%d,%d)\n",r.destination.min_width,r.destination.min_height, r.destination.max_width,r.destination.max_height); printf(" Min/max scaling : (%f,%f)/(%f,%f)\n",r.min_width_scale,r.min_height_scale, r.max_width_scale,r.max_height_scale); rgb_color key; SetViewOverlay(fBitmap,bitmapBounds,VideoBounds(),&key,B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL); SetViewColor(key); }; return (B_NO_ERROR); }