void MainWindow::OnTimelineClicked(wxMouseEvent& event) { wxSize size = mainWindow->timeline->GetSize(); float position = (float) event.GetX() / (float) size.GetWidth(); libvlc_media_player_set_position(mainWindow->media_player, position); mainWindow->setTimeline(position); event.Skip(); }
void AudioOutput::seek( qint64 milliseconds ) { tDebug() << Q_FUNC_INFO; switch ( m_currentState ) { case Playing: case Paused: case Loading: case Buffering: break; default: return; } if ( m_seekable ) { // tDebug() << Q_FUNC_INFO << "AudioOutput:: seeking" << milliseconds << "msec"; libvlc_media_player_set_time( m_vlcPlayer, milliseconds ); setCurrentTime( milliseconds ); } else { qint64 duration = AudioEngine::instance()->currentTrackTotalTime(); float position = float(float(milliseconds) / duration); libvlc_media_player_set_position(m_vlcPlayer, position); tDebug() << Q_FUNC_INFO << "AudioOutput:: seeking via position" << position << "pos"; } m_justSeeked = true; }
void NPlaybackEngineVlc::setPosition(qreal pos) { if (!hasMedia() || pos < 0) return; libvlc_media_player_set_position(m_mediaPlayer, qBound(0.0, pos, 1.0)); }
STDMETHODIMP VLCInput::put_position(double position) { libvlc_media_player_t *p_md; HRESULT hr = getMD(&p_md); if( SUCCEEDED(hr) ) { libvlc_media_player_set_position(p_md, position); } return hr; };
static void set_position(libvlc_media_player_t *mp) { libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp); assert(em); libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, callback, NULL); done = false; libvlc_media_player_set_position(mp, VLC_THUMBNAIL_POSITION); event_wait("Couldn't set position"); libvlc_event_detach(em, libvlc_MediaPlayerPositionChanged, callback, NULL); }
void Java_org_videolan_libvlc_MediaPlayer_setPosition(JNIEnv *env, jobject thiz, jfloat pos) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz); if (!p_obj) return; libvlc_media_player_set_position(p_obj->u.p_mp, pos); }
void CAVPlayer::SeekTo(int iPos) { if (iPos < 0 || iPos > 1000) { return; } if (m_pVLC_Player) { libvlc_media_player_set_position(m_pVLC_Player, iPos/(float)1000.0); } }
void MediaPlayer::_evt_playing() { if (seeknext) { qDebug() << "Seek:" << (float)libvlc_media_get_duration(vlcMedia) / seekloc << (float)libvlc_media_get_duration(vlcMedia) << seekloc; seeknext = false; libvlc_media_player_set_position(vlcMediaPlayer,(float)seekloc / libvlc_media_get_duration(vlcMedia)); seekloc = 0; } emit playing(); //qDebug() << "New Time:" << libvlc_media_player_get_length(vlcMediaPlayer); //qDebug() << "New New time:" << libvlc_media_get_duration(vlcMedia); }
void Player::changePosition(int newPosition) { //libvlc_exception_clear(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. // It's possible that the vlc doesn't play anything // so check before libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp); //libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. //libvlc_exception_clear(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. if (curMedia == NULL) return; float pos=(float)(newPosition)/(float)POSITION_RESOLUTION; libvlc_media_player_set_position (_mp, pos); //libvlc_media_player_set_position (_mp, pos, &_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. //raise(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. }
static void clutter_vlc_set_progress(ClutterVlcVideoTexture* video_texture, gdouble progress) { ClutterVlcVideoTexturePrivate* priv; priv = video_texture->priv; if (priv->vlc_media_player == NULL) return; libvlc_media_player_set_position(priv->vlc_media_player, (float)progress, &priv->vlc_exception); clutter_vlc_catch(&priv->vlc_exception); g_object_notify(G_OBJECT(video_texture), "progress"); }
RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value) { /* is plugin still running */ if( isPluginRunning() ) { VlcPlugin* p_plugin = getPrivate<VlcPlugin>(); libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = p_plugin->getMD(&ex); RETURN_ON_EXCEPTION(this,ex); switch( index ) { case ID_input_position: { if( ! NPVARIANT_IS_DOUBLE(value) ) { return INVOKERESULT_INVALID_VALUE; } float val = (float)NPVARIANT_TO_DOUBLE(value); libvlc_media_player_set_position(p_md, val, &ex); RETURN_ON_EXCEPTION(this,ex); return INVOKERESULT_NO_ERROR; } case ID_input_time: { int64_t val; if( NPVARIANT_IS_INT32(value) ) val = (int64_t)NPVARIANT_TO_INT32(value); else if( NPVARIANT_IS_DOUBLE(value) ) val = (int64_t)NPVARIANT_TO_DOUBLE(value); else { return INVOKERESULT_INVALID_VALUE; } libvlc_media_player_set_time(p_md, val, &ex); RETURN_ON_EXCEPTION(this,ex); return INVOKERESULT_NO_ERROR; } case ID_input_rate: { float val; if( NPVARIANT_IS_INT32(value) ) val = (float)NPVARIANT_TO_INT32(value); else if( NPVARIANT_IS_DOUBLE(value) ) val = (float)NPVARIANT_TO_DOUBLE(value); else { return INVOKERESULT_INVALID_VALUE; } libvlc_media_player_set_rate(p_md, val, &ex); RETURN_ON_EXCEPTION(this,ex); return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR; }
void Java_org_videolan_libvlc_LibVLC_setPosition(JNIEnv *env, jobject thiz, jfloat pos) { libvlc_media_player_t *mp = getMediaPlayer(env, thiz); if (mp) libvlc_media_player_set_position(mp, pos); }
void PlayerEngine_vlc::seekState(double position){ if (vlcPlayer) libvlc_media_player_set_position(vlcPlayer, (float)position/100.0); }
void VlcVideoPlayer::navigate(double pos) { libvlc_media_player_set_position(vlcPlayer, float(pos)); }
void VlcVideoPlayer::forward() { // @todo Fix audio click (if we have time!) libvlc_media_player_set_position(vlcPlayer, libvlc_media_player_get_position (vlcPlayer) + 0.1); // Forward 10% }
// Control Buttons void VlcVideoPlayer::backward() { // @todo Fix audio click (if we have time!). libvlc_media_player_set_position(vlcPlayer, libvlc_media_player_get_position (vlcPlayer) - 0.1); // Backward 10% }
void MainWindow::OnPositionChanged_USR(wxCommandEvent& event) { libvlc_media_player_set_position(media_player, (float) event.GetInt() / (float) TIMELINE_MAX); }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_libvlc_util_VLCUtil_nativeGetThumbnail(JNIEnv *env, jobject thiz, jobject jmedia, const jint frameWidth, const jint frameHeight) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, jmedia); jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Could not create the thumbnailer data structure!"); return NULL; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ libvlc_media_player_t *mp = libvlc_media_player_new_from_media(p_obj->u.p_m); if (!mp) goto end; libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0); sys->frameWidth = frameWidth; sys->frameHeight = frameHeight; /* Set the video format and the callbacks. */ libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock, thumbnailer_display, (void*)sys); libvlc_video_set_format_callbacks(mp, thumbnailer_setup, NULL); libvlc_event_attach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); /* Play the media. */ libvlc_media_player_play(mp); libvlc_media_player_set_position(mp, THUMBNAIL_POSITION); /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 3; /* Wait for a VOUT for 3 seconds, some input format like *.TS make some time * to initialize a VOUT */ int ret = 0; while (!(sys->state & THUMB_VOUT) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); if (sys->state & THUMB_VOUT) { ret = 0; /* Wait an additional 7 seconds for a frame */ deadline.tv_sec += 7; while (!(sys->state & THUMB_DONE) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); } else LOGE("media has not VOUT"); pthread_mutex_unlock(&sys->doneMutex); /* Stop and release the media player. */ libvlc_media_player_stop(mp); libvlc_event_detach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); libvlc_media_player_release(mp); if ((sys->state & THUMB_DONE) && sys->frameData) { /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, sys->frameSize); if (byteArray == NULL) { LOGE("Could not allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, sys->frameSize, (jbyte *)sys->frameData); } end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->frameData); free(sys->thumbData); free(sys); return byteArray; }
void Mwindow::changePosition(int pos) { /* Called on position slider change */ if (vlcPlayer) libvlc_media_player_set_position(vlcPlayer, (float)pos/1000.0); }
void qtVlc::setPosition(int pos, int max) { float newPos = (float)pos / (float)max; //qDebug() << "newPosition" << newPos << (float)max; libvlc_media_player_set_position(mp, newPos); }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_vlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz, jlong instance, jstring filePath, const jint frameWidth, const jint frameHeight) { libvlc_instance_t *libvlc = (libvlc_instance_t *)(intptr_t)instance; jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Could not create the thumbnailer data structure!"); return NULL; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ libvlc_media_player_t *mp = libvlc_media_player_new(libvlc); libvlc_media_t *m = new_media(instance, env, thiz, filePath, true, false); if (m == NULL) { LOGE("Could not create the media to play!"); goto end; } /* Fast and no options */ libvlc_media_add_option( m, ":no-audio" ); libvlc_media_add_option( m, ":no-spu" ); libvlc_media_add_option( m, ":no-osd" ); libvlc_media_player_set_media(mp, m); /* Get the size of the video with the tracks information of the media. */ libvlc_media_track_info_t *tracks; libvlc_media_parse(m); int nbTracks = libvlc_media_get_tracks_info(m, &tracks); libvlc_media_release(m); /* Parse the results */ unsigned videoWidth, videoHeight; bool hasVideoTrack = false; for (unsigned i = 0; i < nbTracks; ++i) if (tracks[i].i_type == libvlc_track_video) { videoWidth = tracks[i].u.video.i_width; videoHeight = tracks[i].u.video.i_height; hasVideoTrack = true; break; } free(tracks); /* Abort if we have not found a video track. */ if (!hasVideoTrack) { LOGE("Could not find any video track in this file.\n"); goto end; } /* VLC could not tell us the size */ if( videoWidth == 0 || videoHeight == 0 ) { LOGE("Could not find the video dimensions.\n"); goto end; } /* Compute the size parameters of the frame to generate. */ unsigned thumbWidth = frameWidth; unsigned thumbHeight = frameHeight; const float inputAR = (float)videoWidth / videoHeight; const float screenAR = (float)frameWidth / frameHeight; /* Most of the cases, video is wider than tall */ if (screenAR < inputAR) { thumbHeight = (float)frameWidth / inputAR + 1; sys->blackBorders = ( (frameHeight - thumbHeight) / 2 ) * frameWidth; } else { LOGD("Weird aspect Ratio.\n"); thumbWidth = (float)frameHeight * inputAR; sys->blackBorders = (frameWidth - thumbWidth) / 2; } sys->thumbPitch = thumbWidth * PIXEL_SIZE; sys->thumbHeight = thumbHeight; sys->frameWidth = frameWidth; /* Allocate the memory to store the frames. */ size_t thumbSize = sys->thumbPitch * (sys->thumbHeight+1); sys->thumbData = malloc(thumbSize); if (sys->thumbData == NULL) { LOGE("Could not allocate the memory to store the frame!"); goto end; } /* Allocate the memory to store the thumbnail. */ unsigned frameSize = frameWidth * frameHeight * PIXEL_SIZE; sys->frameData = calloc(frameSize, 1); if (sys->frameData == NULL) { LOGE("Could not allocate the memory to store the thumbnail!"); goto end; } /* Set the video format and the callbacks. */ libvlc_video_set_format(mp, "RGBA", thumbWidth, thumbHeight, sys->thumbPitch); libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock, NULL, (void*)sys); sys->state = THUMB_SEEKING; /* Play the media. */ libvlc_media_player_play(mp); libvlc_media_player_set_position(mp, THUMBNAIL_POSITION); int loops = 100; for (;;) { float pos = libvlc_media_player_get_position(mp); if (pos > THUMBNAIL_POSITION || !loops--) break; usleep(50000); } /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); sys->state = THUMB_SEEKED; struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 10; /* amount of seconds before we abort thumbnailer */ do { int ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); if (ret == ETIMEDOUT) break; } while (sys->state != THUMB_DONE); pthread_mutex_unlock(&sys->doneMutex); /* Stop and release the media player. */ libvlc_media_player_stop(mp); libvlc_media_player_release(mp); if (sys->state == THUMB_DONE) { /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, frameSize); if (byteArray == NULL) { LOGE("Could not allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, frameSize, (jbyte *)sys->frameData); } end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->frameData); free(sys->thumbData); free(sys); return byteArray; }
bool VLCVideoWrapper::open(const std::string& ThePath, Window* const TheWindow) { bool errorOpening(false); //BoostPath PluginsDirPath("/Applications/VLC.app/Contents/MacOS/modules"); BoostPath PluginsDirPath("/Applications/VLC-1.1.7.app/Contents/MacOS/modules"); std::vector<std::string> VLCArguments; VLCArguments.push_back("-I"); VLCArguments.push_back("dummy"); /* no interface */ VLCArguments.push_back(std::string("--plugin-path=") + PluginsDirPath.string()); //VLCArguments.push_back("--no-audio"); [> we don't want audio <] VLCArguments.push_back("--verbose=0"); /* show only errors */ VLCArguments.push_back("--no-media-library");/* don't want that */ VLCArguments.push_back("--services-discovery=");/* don't want that */ VLCArguments.push_back("--no-video-title-show");/* don't want that */ VLCArguments.push_back("--no-stats");/* don't want that */ VLCArguments.push_back("--ignore-config"); /* don't use/overwrite the config */ VLCArguments.push_back("--no-sub-autodetect");/* don't want subtitles */ VLCArguments.push_back("--control=");/* don't want interface (again) */ VLCArguments.push_back("--no-disable-screensaver");/* don't want that */ // libvlc settings const char** args = new const char*[VLCArguments.size()]; for(UInt32 i(0) ; i<VLCArguments.size() ; ++i) { args[i] = VLCArguments[i].c_str(); } /* * Initialise libVLC */ UInt32 nargs = VLCArguments.size(); _VLCInstance = libvlc_new( nargs, args ); if(_VLCInstance == NULL) { checkVLCError("creating new vlc instance"); return false; } delete [] args; // creates vlc struct holding data to the video file libvlc_media_t *TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() ); checkVLCError("initializing media file"); // initialize a temporary media player so we can get height and width before // adding the vmem options to TheMedia libvlc_media_player_t * tempMediaPlayer = libvlc_media_player_new_from_media( TheMedia ); unsigned Width(200), Height(200); libvlc_video_set_callbacks(tempMediaPlayer, lock, unlock, display, &_VideoMemContext); _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) ) * Width * Height ) * 4 ); libvlc_video_set_format(tempMediaPlayer, "RV24", Width, Height, Width * 3); //Release the media file libvlc_media_release( TheMedia ); libvlc_media_player_play( tempMediaPlayer ); checkVLCError("playing the media"); libvlc_state_t currentState; do { currentState = libvlc_media_player_get_state(tempMediaPlayer); checkVLCError("getting state"); } while(currentState != libvlc_Playing); int VLCResult; do { VLCResult = libvlc_video_get_size(tempMediaPlayer, 0, &Width, &Height); } while(VLCResult != 0); checkVLCError("getting size"); libvlc_media_player_stop( tempMediaPlayer ); libvlc_media_player_release(tempMediaPlayer);// releases media currently in use //Now that we have the size initialize the media again TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() ); checkVLCError("initializing media file"); // initialize the media player _MediaPlayer = libvlc_media_player_new_from_media( TheMedia ); checkVLCError("initializing media player"); //Release the media file libvlc_media_release( TheMedia ); #ifdef __APPLE__ //set agl handle (if TheWindow is pointing to a carbon window) if (TheWindow->getType().isDerivedFrom(CarbonWindow::getClassType())) { HIWindowRef windowRef = aglGetWindowRef(dynamic_cast<CarbonWindow* const>(TheWindow)->getContext()); HIViewRef contentView = 0; GetRootControl(windowRef, &contentView); //uint32_t aglHandler = CarbonWindowPtr::dcast(TheWindow)->winId(); libvlc_media_player_set_agl (_MediaPlayer, reinterpret_cast<uint32_t>(contentView) ); checkVLCError("attaching media player to carbon window"); } #endif #ifdef WIN32 if (TheWindow->getType().isDerivedFrom(WIN32Window::getClassType())) { libvlc_media_player_set_hwnd (_MediaPlayer, dynamic_cast<WIN32Window* const>(TheWindow)->getHwnd() ); checkVLCError("attaching media player to WIN32 window"); } #endif #ifdef __linux if (TheWindow->getType().isDerivedFrom(XWindow::getClassType())) { libvlc_media_player_set_xwindow (_MediaPlayer, dynamic_cast<XWindow* const>(TheWindow)->getDisplay() ); checkVLCError("attaching media player to Xwindow"); } #endif libvlc_video_set_callbacks(_MediaPlayer, lock, unlock, display, &_VideoMemContext); _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) ) * Width * Height ) * 4 ); libvlc_video_set_format(_MediaPlayer, "RV24", Width, Height, Width * 3); //Start playing the video libvlc_media_player_play( _MediaPlayer ); checkVLCError("playing the media"); do { currentState = libvlc_media_player_get_state(_MediaPlayer); checkVLCError("getting state"); } while(currentState != libvlc_Playing); clock_t endwait; endwait = clock () + 2 * CLOCKS_PER_SEC ; while (clock() < endwait) {} _Initialized = true; // check if the player can be paused if(libvlc_media_player_can_pause(_MediaPlayer)) { // can pause it? do it libvlc_media_player_pause(_MediaPlayer); // error checking of course checkVLCError("pausing media player"); libvlc_media_player_set_position( _MediaPlayer, 0.0f ); checkVLCError("setting position during player initialization"); } return errorOpening; }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_vlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz, jint instance, jstring filePath, jint width, jint height) { libvlc_instance_t *libvlc = (libvlc_instance_t *)instance; jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Couldn't create the thumbnailer data structure!"); return NULL; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ sys->mp = libvlc_media_player_new(libvlc); libvlc_media_t *m = new_media(instance, env, thiz, filePath); if (m == NULL) { LOGE("Couldn't create the media to play!"); goto end; } libvlc_media_add_option( m, ":no-audio" ); libvlc_media_player_set_media(sys->mp, m); libvlc_media_release(m); /* Get the size of the video with the tracks information of the media. */ libvlc_media_track_info_t *tracks; libvlc_media_parse(m); int nbTracks = libvlc_media_get_tracks_info(m, &tracks); unsigned i, videoWidth, videoHeight; bool hasVideoTrack = false; for (i = 0; i < nbTracks; ++i) if (tracks[i].i_type == libvlc_track_video) { videoWidth = tracks[i].u.video.i_width; videoHeight = tracks[i].u.video.i_height; hasVideoTrack = true; break; } free(tracks); /* Abord if we have not found a video track. */ if (!hasVideoTrack) { LOGE("Could not find a video track in this file.\n"); goto end; } /* Compute the size parameters of the frame to generate. */ unsigned picWidth = width; unsigned picHeight = height; float videoAR = (float)videoWidth / videoHeight; float screenAR = (float)width / height; if (screenAR < videoAR) { picHeight = (float)width / videoAR; sys->thumbnailOffset = (height - picHeight) / 2 * width * PIXEL_SIZE; } else { picWidth = (float)height * videoAR; sys->thumbnailOffset = (width - picWidth) / 2 * PIXEL_SIZE; } sys->picPitch = picWidth * PIXEL_SIZE; sys->lineSize = width * PIXEL_SIZE; sys->nbLines = picHeight; /* Allocate the memory to store the frames. */ unsigned picSize = sys->picPitch * picHeight; sys->frameData = malloc(picSize); if (sys->frameData == NULL) { LOGE("Couldn't allocate the memory to store the frame!"); goto end; } /* Allocate the memory to store the thumbnail. */ unsigned thumbnailSize = width * height * PIXEL_SIZE; sys->thumbnail = calloc(thumbnailSize, 1); if (sys->thumbnail == NULL) { LOGE("Couldn't allocate the memory to store the thumbnail!"); goto end; } /* Set the video format and the callbacks. */ libvlc_video_set_format(sys->mp, "RGBA", picWidth, picHeight, sys->picPitch); libvlc_video_set_callbacks(sys->mp, thumbnailer_lock, thumbnailer_unlock, NULL, (void*)sys); /* Play the media. */ libvlc_media_player_play(sys->mp); libvlc_media_player_set_position(sys->mp, THUMBNAIL_POSITION); /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); while (!sys->hasThumb) pthread_cond_wait(&sys->doneCondVar, &sys->doneMutex); pthread_mutex_unlock(&sys->doneMutex); /* Stop and realease the media player. */ libvlc_media_player_stop(sys->mp); libvlc_media_player_release(sys->mp); /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, thumbnailSize); if (byteArray == NULL) { LOGE("Couldn't allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, thumbnailSize, (jbyte *)sys->thumbnail); (*env)->DeleteLocalRef(env, byteArray); end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->thumbnail); free(sys->frameData); free(sys); return byteArray; }
void player::changePosition(int pos) { /* Called on position slider change */ if (mp) // if player is initialize set position of the media libvlc_media_player_set_position(mp, (float) pos / 1000.0); }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_libvlc_util_VLCUtil_nativeGetThumbnail(JNIEnv *env, jobject thiz, jobject jmedia, const jint frameWidth, const jint frameHeight) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, jmedia); jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Could not create the thumbnailer data structure!"); goto enomem; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ libvlc_media_player_t *mp = libvlc_media_player_new_from_media(p_obj->u.p_m); libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0); /* Get the size of the video with the tracks information of the media. */ libvlc_media_track_t **tracks; libvlc_media_parse(p_obj->u.p_m); int nbTracks = libvlc_media_tracks_get(p_obj->u.p_m, &tracks); /* Parse the results */ unsigned videoWidth = 0, videoHeight = 0; bool hasVideoTrack = false; for (unsigned i = 0; i < nbTracks; ++i) if (tracks[i]->i_type == libvlc_track_video) { videoWidth = tracks[i]->video->i_width; videoHeight = tracks[i]->video->i_height; hasVideoTrack = true; break; } libvlc_media_tracks_release(tracks, nbTracks); /* Abort if we have not found a video track. */ if (!hasVideoTrack) { LOGE("Could not find any video track in this file.\n"); goto end; } LOGD("Video dimensions: %ix%i.\n", videoWidth, videoHeight ); /* VLC could not tell us the size */ if( videoWidth == 0 || videoHeight == 0 ) { LOGE("Could not find the video dimensions.\n"); goto end; } if( videoWidth < THUMBNAIL_MIN_WIDTH || videoHeight < THUMBNAIL_MIN_HEIGHT || videoWidth > THUMBNAIL_MAX_WIDTH || videoHeight > THUMBNAIL_MAX_HEIGHT ) { LOGE("Wrong video dimensions.\n"); goto end; } /* Compute the size parameters of the frame to generate. */ unsigned thumbWidth = frameWidth; unsigned thumbHeight = frameHeight; const float inputAR = (float)videoWidth / videoHeight; const float screenAR = (float)frameWidth / frameHeight; /* Most of the cases, video is wider than tall */ if (screenAR < inputAR) { thumbHeight = (float)frameWidth / inputAR + 1; sys->blackBorders = ( (frameHeight - thumbHeight) / 2 ) * frameWidth; } else { LOGD("Weird aspect Ratio.\n"); thumbWidth = (float)frameHeight * inputAR; sys->blackBorders = (frameWidth - thumbWidth) / 2; } sys->thumbPitch = thumbWidth * PIXEL_SIZE; sys->thumbHeight = thumbHeight; sys->frameWidth = frameWidth; /* Allocate the memory to store the frames. */ size_t thumbSize = sys->thumbPitch * (sys->thumbHeight+1); sys->thumbData = malloc(thumbSize); if (sys->thumbData == NULL) { LOGE("Could not allocate the memory to store the frame!"); goto end; } /* Allocate the memory to store the thumbnail. */ unsigned frameSize = frameWidth * frameHeight * PIXEL_SIZE; sys->frameData = calloc(frameSize, 1); if (sys->frameData == NULL) { LOGE("Could not allocate the memory to store the thumbnail!"); goto end; } /* Set the video format and the callbacks. */ libvlc_video_set_format(mp, "RGBA", thumbWidth, thumbHeight, sys->thumbPitch); libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock, NULL, (void*)sys); sys->state = THUMB_SEEKING; /* Play the media. */ libvlc_media_player_play(mp); libvlc_media_player_set_position(mp, THUMBNAIL_POSITION); const int wait_time = 50000; const int max_attempts = 100; for (int i = 0; i < max_attempts; ++i) { if (libvlc_media_player_is_playing(mp) && libvlc_media_player_get_position(mp) >= THUMBNAIL_POSITION) break; usleep(wait_time); } /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); sys->state = THUMB_SEEKED; struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 10; /* amount of seconds before we abort thumbnailer */ do { int ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); if (ret == ETIMEDOUT) break; } while (sys->state != THUMB_DONE); pthread_mutex_unlock(&sys->doneMutex); /* Stop and release the media player. */ libvlc_media_player_stop(mp); libvlc_media_player_release(mp); if (sys->state == THUMB_DONE) { /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, frameSize); if (byteArray == NULL) { LOGE("Could not allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, frameSize, (jbyte *)sys->frameData); } end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->frameData); free(sys->thumbData); free(sys); enomem: return byteArray; }
void VLCMainwindow::changePosition(int pos) { //Called if you change the position slider if(vlcPlayer) //It segfault if vlcPlayer don't exist libvlc_media_player_set_position(vlcPlayer,(float)pos/(float)1000); }
void VLCWrapper::setPosition (float pos) { libvlc_media_player_set_position (Player_.get (), pos); }
void seek_media(float fpos) { if(mediaplay != NULL) libvlc_media_player_set_position(mediaplay,fpos); else ; }