// helper func to compute size of media data bool LLMediaImplLLMozLib::recomputeSizes() { int new_width = mMediaRequestedWidth; int new_height = mMediaRequestedHeight; if (new_width < 0) new_width = 512; if (new_height < 0) new_height = 512; if (mAutoScaled) { new_width = LLMediaManager::textureWidthFromMediaWidth( new_width ); new_height = LLMediaManager::textureHeightFromMediaHeight( new_height ); } bool status = LLMozLib::getInstance()->setSize( mWindowId, new_width, new_height ); if (status) setMediaSize(new_width, new_height); return status; }
/////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplGStreamer::updateMedia() { //LL_DEBUGS("MediaImpl") << "updating media..." << LL_ENDL; // sanity check if (mPump == NULL || mPlaybin == NULL) { #ifdef LL_GST_REPORT_STATE_CHANGES LL_DEBUGS("MediaImpl") << "dead media..." << LL_ENDL; #endif mState = GST_STATE_NULL; setStatus(LLMediaBase::STATUS_DEAD); return false; } if (mState == GST_STATE_VOID_PENDING || mState == GST_STATE_NULL) return false; // process next outstanding command switch (nextCommand()) { case LLMediaBase::COMMAND_START: LL_DEBUGS("MediaImpl") << "COMMAND_START" << LL_ENDL; if (getStatus() == LLMediaBase::STATUS_PAUSED || getStatus() == LLMediaBase::STATUS_NAVIGATING || getStatus() == LLMediaBase::STATUS_STOPPED) { play(); setStatus(LLMediaBase::STATUS_STARTED); clearCommand(); } break; case LLMediaBase::COMMAND_STOP: LL_DEBUGS("MediaImpl") << "COMMAND_STOP" << LL_ENDL; stop(); setStatus(LLMediaBase::STATUS_STOPPED); clearCommand(); break; case LLMediaBase::COMMAND_PAUSE: LL_DEBUGS("MediaImpl") << "COMMAND_PAUSE" << LL_ENDL; if (getStatus() == LLMediaBase::STATUS_STARTED) { pause(); setStatus(LLMediaBase::STATUS_PAUSED); clearCommand(); } break; default: LL_INFOS("MediaImpl") << "Unknown command" << LL_ENDL; clearCommand(); break; case LLMediaBase::COMMAND_NONE: break; } // deal with results if (g_main_context_pending(g_main_loop_get_context(mPump))) { g_main_context_iteration(g_main_loop_get_context(mPump), FALSE); } if (mVideoSink) { GST_OBJECT_LOCK(mVideoSink); if (mVideoSink->retained_frame_ready) { #ifdef LL_GST_REPORT_STATE_CHANGES LL_DEBUGS("MediaImpl") <<"NEW FRAME " << LL_ENDL; #endif if (mVideoSink->retained_frame_width != getMediaWidth() || mVideoSink->retained_frame_height != getMediaHeight()) // *TODO: also check for change in format { // just resize containe int neww = mVideoSink->retained_frame_width; int newh = mVideoSink->retained_frame_height; int newd = SLVPixelFormatBytes[mVideoSink->retained_frame_format]; if (SLV_PF_RGBX == mVideoSink->retained_frame_format) { mTextureFormatPrimary = LL_MEDIA_RGBA; mTextureFormatType = LL_MEDIA_UNSIGNED_INT_8_8_8_8_REV; } else { mTextureFormatPrimary = LL_MEDIA_BGRA; mTextureFormatType = LL_MEDIA_UNSIGNED_INT_8_8_8_8_REV; } mMediaRowbytes = neww * newd; LL_DEBUGS("MediaImpl") << "video container resized to " << neww <<"x"<< newh << LL_ENDL; delete[] mediaData; mediaData = new unsigned char[mMediaRowbytes * newh]; GST_OBJECT_UNLOCK(mVideoSink); setMediaDepth(newd); setMediaSize(neww, newh); return true; } // we're gonna totally consume this frame - reset 'ready' flag mVideoSink->retained_frame_ready = FALSE; memcpy(mediaData, mVideoSink->retained_frame_data, mMediaRowbytes * getMediaHeight()); GST_OBJECT_UNLOCK(mVideoSink); LLMediaEvent event( this ); mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event ); return true; } else { // nothing to do yet. GST_OBJECT_UNLOCK(mVideoSink); return true; } } return true; }
//////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplQuickTime::sizeChanged() { if ( ! mMovieHandle ) return false; // sanitize size of movie Rect movie_rect; setMovieBoxEnhanced( &movie_rect ); // we need this later int width = ( movie_rect.right - movie_rect.left ); int height = ( movie_rect.bottom - movie_rect.top ); std::cout << "LLMEDIA> size changed to " << width << " x " << height << std::endl; setMediaSize( width, height ); // media depth won't change int depth_bits = getMediaDepth() * 8; GWorldPtr old_gworld_handle = mGWorldHandle; if (old_gworld_handle) { GWorldFlags result = UpdateGWorld( &mGWorldHandle, depth_bits, &movie_rect, NULL, NULL, 0 ); if ( gwFlagErr == result ) { // TODO: unrecoverable?? throw exception? return something? return false; } } else { OSErr result = NewGWorld( &mGWorldHandle, depth_bits, &movie_rect, NULL, NULL, keepLocal | pixelsLocked ); if ( noErr != result ) { // ATODO: unrecoverable?? throw exception? return something? return false; } // clear memory in GWorld to avoid random screen visual fuzz from uninitialized texture data if ( mGWorldHandle ) { PixMapHandle pix_map_handle = GetGWorldPixMap( mGWorldHandle ); unsigned char* ptr = ( unsigned char* )GetPixBaseAddr( pix_map_handle ); memset( ptr, 0x00, height * QTGetPixMapHandleRowBytes( pix_map_handle ) ); } } // point movie at GWorld if it's new if ( mMovieHandle && ! old_gworld_handle ) { SetMovieGWorld( mMovieHandle, mGWorldHandle, GetGWorldDevice ( mGWorldHandle ) ); } // update movie controller if ( mMovieController ) { MCSetControllerPort( mMovieController, mGWorldHandle ); MCPositionController( mMovieController, &movie_rect, &movie_rect, mcTopLeftMovie | mcPositionDontInvalidate ); MCMovieChanged( mMovieController, mMovieHandle ); } // Emit event with size change so the calling app knows about it too LLMediaEvent event( this ); mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event ); return true; }
//////////////////////////////////////////////////////////////////////////////// // private bool LLMediaImplQuickTime::load( const std::string url ) { if ( url.empty() ) return false; //In case std::string::c_str() makes a copy of the url data, //make sure there is memory to hold it before allocating memory for handle. //if fails, NewHandleClear(...) should return NULL. const char* url_string = url.c_str() ; Handle handle = NewHandleClear( ( Size )( url.length() + 1 ) ); if ( NULL == handle ) return false; if(noErr != MemError() || NULL == *handle) { return false ; } BlockMove( url_string, *handle, ( Size )( url.length() + 1 ) ); //std::cout << "LLMediaImplQuickTime::load( " << url << " )" << std::endl; // TODO: supposed to use NewMovieFromDataParams now OSErr err = NewMovieFromDataRef( &mMovieHandle, newMovieActive | newMovieDontInteractWithUser | newMovieAsyncOK | newMovieIdleImportOK, nil, handle, URLDataHandlerSubType ); DisposeHandle( handle ); if ( noErr != err ) return false; // do pre-roll actions (typically fired for streaming movies but not always) PrePrerollMovie( mMovieHandle, 0, GetMoviePreferredRate( mMovieHandle ), moviePrePrerollCompleteCallback, ( void * )this ); // get movie rect (and check for min/max) Rect movie_rect; setMovieBoxEnhanced( &movie_rect ); // make a new movie controller mMovieController = NewMovieController( mMovieHandle, &movie_rect, mcNotVisible | mcTopLeftMovie ); #if defined(__APPLE__) || defined(MACOSX) setMediaDepth( 4 ); #else setMediaDepth( 3 ); #endif // tell manager about the media size setMediaSize( movie_rect.right - movie_rect.left, movie_rect.bottom - movie_rect.top); // movie controller MCSetActionFilterWithRefCon( mMovieController, mcActionFilterCallBack, ( long )this ); SetMoviePlayHints( mMovieHandle, hintsAllowDynamicResize, hintsAllowDynamicResize ); // function that gets called when a frame is drawn SetMovieDrawingCompleteProc( mMovieHandle, movieDrawingCallWhenChanged, movieDrawingCompleteCallback, ( long )this ); // emit an event to say that a media source was loaded LLMediaEvent event( this ); mEventEmitter.update( &LLMediaObserver::onMediaLoaded, event ); // set up inital state sizeChanged(); return true; }
void PosterPreview::setMediaSize(int s) { setMediaSize(pageSizeToPageName((KPrinter::PageSize)s)); }
/////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplGStreamer:: updateMedia () { DEBUGMSG("updating media..."); // sanity check if (NULL == mPump #ifdef LL_GST_SOUNDSINK || NULL == mAudioSink #endif || NULL == mPlaybin) { DEBUGMSG("dead media..."); return false; } // process next outstanding command switch (nextCommand()) { case LLMediaBase::COMMAND_START: DEBUGMSG("COMMAND_START"); if (getStatus() == LLMediaBase::STATUS_PAUSED || getStatus() == LLMediaBase::STATUS_NAVIGATING || getStatus() == LLMediaBase::STATUS_STOPPED) { DEBUGMSG("doing COMMAND_START"); play(); setStatus(LLMediaBase::STATUS_STARTED); clearCommand(); } break; case LLMediaBase::COMMAND_STOP: DEBUGMSG("COMMAND_STOP"); DEBUGMSG("doing COMMAND_STOP"); stop(); setStatus(LLMediaBase::STATUS_STOPPED); clearCommand(); break; case LLMediaBase::COMMAND_PAUSE: DEBUGMSG("COMMAND_PAUSE"); if (getStatus() == LLMediaBase::STATUS_STARTED) { DEBUGMSG("doing COMMAND_PAUSE"); pause(); setStatus(LLMediaBase::STATUS_PAUSED); clearCommand(); } break; default: DEBUGMSG("COMMAND_?"); clearCommand(); break; case LLMediaBase::COMMAND_NONE: break; } // deal with results if (g_main_context_pending(g_main_loop_get_context(mPump))) { g_main_context_iteration(g_main_loop_get_context(mPump), FALSE); } if (mVideoSink) { GST_OBJECT_LOCK(mVideoSink); if (mVideoSink->retained_frame_ready) { DEBUGMSG("NEW FRAME "); if (mVideoSink->retained_frame_width != getMediaWidth() || mVideoSink->retained_frame_height != getMediaHeight()) // *TODO: also check for change in format { // just resize containe int neww = mVideoSink->retained_frame_width; int newh = mVideoSink->retained_frame_height; int newd = SLVPixelFormatBytes[mVideoSink->retained_frame_format]; if (SLV_PF_RGBX == mVideoSink->retained_frame_format) { mTextureFormatPrimary = LL_MEDIA_RGBA; mTextureFormatType = LL_MEDIA_UNSIGNED_INT_8_8_8_8_REV; } else { mTextureFormatPrimary = LL_MEDIA_BGRA; mTextureFormatType = LL_MEDIA_UNSIGNED_INT_8_8_8_8_REV; } mMediaRowbytes = neww * newd; DEBUGMSG("video container resized to %dx%d", neww, newh); delete[] mediaData; mediaData = new unsigned char[mMediaRowbytes * newh]; GST_OBJECT_UNLOCK(mVideoSink); setMediaDepth(newd); setMediaSize(neww, newh); return true; } // we're gonna totally consume this frame - reset 'ready' flag mVideoSink->retained_frame_ready = FALSE; memcpy(mediaData, mVideoSink->retained_frame_data, mMediaRowbytes * getMediaHeight()); GST_OBJECT_UNLOCK(mVideoSink); LLMediaEvent event( this ); mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event ); return true; } else { // nothing to do yet. GST_OBJECT_UNLOCK(mVideoSink); return true; } } return true; }
//////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplExample1::setRequestedMediaSize( int width, int height ) { // we accept any size: return setMediaSize(width, height); }